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>"); } }
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>"); } }
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); }