GetValue() public static method

public static GetValue ( Mobile from, object o, string name ) : string
from Mobile
o object
name string
return string
        public override void Execute(CommandEventArgs e, object obj)
        {
            if (e.Length == 1)
            {
                string result = Properties.GetValue(e.Mobile, obj, e.GetString(0));

                if (result == "Property not found." || result == "Property is write only." || result.StartsWith("Getting this property"))
                {
                    LogFailure(result);
                }
                else
                {
                    AddResponse(result);
                }
            }
            else
            {
                LogFailure("Format: Get <propertyName>");
            }
        }
Example #2
0
        public static void FindMobile_OnCommand(CommandEventArgs e)
        {
            if (e.Length > 1)
            {
                LogHelper Logger = new LogHelper("findMobile.log", e.Mobile, false);

                // Extract property & value from command parameters

                string sProp = e.GetString(0);
                string sVal  = "";

                if (e.Length > 2)
                {
                    sVal = e.GetString(1);

                    // Concatenate the strings
                    for (int argi = 2; argi < e.Length; argi++)
                    {
                        sVal += " " + e.GetString(argi);
                    }
                }
                else
                {
                    sVal = e.GetString(1);
                }

                Regex PattMatch = new Regex("= \"*" + sVal, RegexOptions.IgnoreCase);

                // Loop through assemblies and add type if has property

                Type[]     types;
                Assembly[] asms = ScriptCompiler.Assemblies;

                ArrayList MatchTypes = new ArrayList();

                for (int i = 0; i < asms.Length; ++i)
                {
                    types = ScriptCompiler.GetTypeCache(asms[i]).Types;

                    foreach (Type t in types)
                    {
                        if (typeof(Mobile).IsAssignableFrom(t))
                        {
                            // Reflect type
                            PropertyInfo[] allProps = t.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                            foreach (PropertyInfo prop in allProps)
                            {
                                if (prop.Name.ToLower() == sProp.ToLower())
                                {
                                    MatchTypes.Add(t);
                                }
                            }
                        }
                    }
                }

                // Loop items and check vs. types

                foreach (Mobile m in World.Mobiles.Values)
                {
                    Type t     = m.GetType();
                    bool match = false;

                    foreach (Type MatchType in MatchTypes)
                    {
                        if (t == MatchType)
                        {
                            match = true;
                            break;
                        }
                    }

                    if (match == false)
                    {
                        continue;
                    }

                    // Reflect instance of type (matched)

                    if (PattMatch.IsMatch(Properties.GetValue(e.Mobile, m, sProp)))
                    {
                        Logger.Log(LogType.Mobile, m);
                    }
                }

                Logger.Finish();
            }
            else
            {
                // Badly formatted
                e.Mobile.SendMessage("Format: FindMobile <property> <value>");
            }
        }
        public static void FindItemByType_OnCommand(CommandEventArgs e)
        {
            try
            {
                if (e == null || e.Mobile == null || e.Mobile is PlayerMobile == false)
                {
                    return;
                }

                string sProp = null;
                string sVal  = null;
                string name  = null;

                if (e.Length >= 1)
                {
                    name = e.GetString(0);

                    if (e.Length >= 2)
                    {
                        sProp = e.GetString(1);
                    }

                    if (e.Length >= 3)
                    {
                        sVal = e.GetString(2);
                    }

                    // if you are a GM the world needs to be in 'Build' mode to access this comand
                    if (e.Mobile.AccessLevel < AccessLevel.Administrator && Core.Building == false)
                    {
                        e.Mobile.SendMessage("The server must be in build mode for you to access this command.");
                        return;
                    }

                    PlayerMobile pm     = e.Mobile as PlayerMobile;
                    LogHelper    Logger = new LogHelper("FindItemByType.log", e.Mobile, false);

                    // reset jump table
                    pm.JumpIndex = 0;
                    pm.JumpList  = new ArrayList();
                    Type tx = ScriptCompiler.FindTypeByName(name);

                    if (tx != null)
                    {
                        foreach (Item item in World.Items.Values)
                        {
                            if (item != null && !item.Deleted && tx.IsAssignableFrom(item.GetType()))
                            {
                                // read the properties
                                PropertyInfo[] allProps = item.GetType().GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                                if (sProp != null)
                                {
                                    foreach (PropertyInfo prop in allProps)
                                    {
                                        if (prop.Name.ToLower() == sProp.ToLower())
                                        {
                                            bool   ok  = false;
                                            string val = Properties.GetValue(e.Mobile, item, sProp);

                                            // match a null value
                                            if ((val == null || val.Length == 0 || val.EndsWith("(-null-)", StringComparison.CurrentCultureIgnoreCase)) && (sVal == null || sVal.Length == 0))
                                            {
                                                ok = true;
                                            }

                                            // see if the property matches
                                            else if (val != null && sVal != null)
                                            {
                                                string[] toks = val.Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                                                if (toks.Length >= 3 && toks[2].Equals(sVal, StringComparison.CurrentCultureIgnoreCase))
                                                {
                                                    ok = true;
                                                }
                                                else
                                                {
                                                    break;
                                                }
                                            }

                                            if (ok)
                                            {
                                                pm.JumpList.Add(item);
                                                Logger.Log(LogType.Item, item);
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {                                       // no prop to check, everything matches
                                    pm.JumpList.Add(item);
                                    Logger.Log(LogType.Item, item);
                                }
                            }
                        }
                    }
                    else
                    {
                        e.Mobile.SendMessage("{0} is not a recognized type.", name);
                    }
                    Logger.Finish();
                }
                else
                {
                    e.Mobile.SendMessage("Format: FindItemByType <type>");
                }
            }
            catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
        }
        private static void AddInv(object o)
        {
            // Handle contained objects (iterative ;)

            if (o is BaseContainer)
            {
                foreach (Item item in ((BaseContainer)o).Items)
                {
                    if (m_ItemType == null)
                    {
                        AddInv(item);
                        continue;
                    }

                    Type it = item.GetType();

                    if (it.IsSubclassOf(m_ItemType) || it == m_ItemType || item is BaseContainer)
                    {
                        AddInv(item);
                    }
                }

                // Do we want to inventory this container, or return?
                Type ct = o.GetType();

                if (!(m_ItemType == null) && !ct.IsSubclassOf(m_ItemType) && ct != m_ItemType)
                {
                    return;
                }
            }

            // Handle this object

            InvItem ir = new InvItem(o.GetType());

            // Determine and set inv item properties

            if (o is BaseWeapon)
            {
                BaseWeapon bw = (BaseWeapon)o;

                ir.m_accuracy   = bw.AccuracyLevel.ToString();
                ir.m_damage     = bw.DamageLevel.ToString();
                ir.m_durability = bw.DurabilityLevel.ToString();
                ir.m_slayer     = bw.Slayer.ToString();
            }
            else if (o is BaseArmor)
            {
                BaseArmor ba = (BaseArmor)o;

                ir.m_durability = ba.Durability.ToString();
                ir.m_damage     = ba.ProtectionLevel.ToString();
            }
            else if (o is EnchantedScroll)
            {
                EnchantedItem ei = (EnchantedItem)o;

                // ProtectionLevel, Durability

                if (ei.ItemType.IsSubclassOf(typeof(BaseArmor)))
                {
                    ir.m_durability = ((ArmorDurabilityLevel)ei.iProps[1]).ToString();
                    ir.m_damage     = ((ArmorProtectionLevel)(ei.iProps[0])).ToString();
                }
                else if (ei.ItemType.IsSubclassOf(typeof(BaseWeapon)))
                {
                    ir.m_accuracy   = ((WeaponAccuracyLevel)ei.iProps[2]).ToString();
                    ir.m_damage     = ((WeaponDamageLevel)ei.iProps[0]).ToString();
                    ir.m_durability = ((WeaponDurabilityLevel)ei.iProps[1]).ToString();
                    ir.m_slayer     = ((SlayerName)ei.iProps[3]).ToString();
                }
            }

            if (o is Item)
            {
                Item it = (Item)o;

                if (it.PlayerCrafted == true)
                {
                    // It's playercrafted, so check for 'Quality' property
                    string strVal = Properties.GetValue(m_from, o, "Quality");

                    if (strVal == "Quality = Exceptional")
                    {
                        ir.m_quality = "Exceptional";
                    }
                }

                if (it.Amount > 0)
                {
                    ir.m_count = it.Amount;
                }

                ir.m_serial = it.Serial;

                // adam: Find the best name we can
                if (o is EnchantedScroll)
                {
                    EnchantedItem ei = (EnchantedItem)o;
                    ir.m_description = ei.ItemType.Name + ".scroll";
                }
                else
                {
                    if (valid(it.Name))
                    {
                        ir.m_description = it.Name;
                    }
                    else if (valid(it.ItemData.Name) && (it.GetType().Name == null || it.GetType().Name == "Item" || it.GetType().Name == "Static"))
                    {
                        ir.m_description = it.ItemData.Name;
                    }
                    else
                    {
                        ir.m_description = it.GetType().Name;
                    }
                }
            }

            // Make sure there are no others like this

            foreach (InvItem ii in m_Inv)
            {
                if (ii.m_type == ir.m_type &&
                    ii.m_accuracy == ir.m_accuracy &&
                    ii.m_damage == ir.m_damage &&
                    ii.m_quality == ir.m_quality &&
                    ii.m_durability == ir.m_durability &&
                    ii.m_slayer == ir.m_slayer &&
                    ii.m_description == ir.m_description)                     //pla: include new field in this check
                {
                    // It exists, so increment and return
                    ii.m_count += ir.m_count;

                    return;
                }
            }

            // It doesn't exist, so add it
            m_Inv.Add(ir);
        }