コード例 #1
0
        public static int BuildObjects(Mobile from, Type type, Point3D start, Point3D end, string[] args, string[,] props, List <Container> packs, bool outline, bool mapAvg)
        {
            Utility.FixPoints(ref start, ref end);

            PropertyInfo[] realProps = null;

            if (props != null)
            {
                realProps = new PropertyInfo[props.GetLength(0)];

                PropertyInfo[] allProps = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                for (int i = 0; i < realProps.Length; ++i)
                {
                    PropertyInfo thisProp = null;

                    string propName = props[i, 0];

                    for (int j = 0; thisProp == null && j < allProps.Length; ++j)
                    {
                        if (Insensitive.Equals(propName, allProps[j].Name))
                        {
                            thisProp = allProps[j];
                        }
                    }

                    if (thisProp == null)
                    {
                        from.SendMessage("Property not found: {0}", propName);
                    }
                    else
                    {
                        CPA attr = Properties.GetCPA(thisProp);

                        if (attr == null)
                        {
                            from.SendMessage("Property ({0}) not found.", propName);
                        }
                        else if (from.AccessLevel < attr.WriteLevel)
                        {
                            from.SendMessage("Setting this property ({0}) requires at least {1} access level.", propName, Mobile.GetAccessLevelName(attr.WriteLevel));
                        }
                        else if (!thisProp.CanWrite || attr.ReadOnly)
                        {
                            from.SendMessage("Property ({0}) is read only.", propName);
                        }
                        else
                        {
                            realProps[i] = thisProp;
                        }
                    }
                }
            }

            ConstructorInfo[] ctors = type.GetConstructors();

            for (int i = 0; i < ctors.Length; ++i)
            {
                ConstructorInfo ctor = ctors[i];

                if (!IsConstructable(ctor, from.AccessLevel))
                {
                    continue;
                }

                ParameterInfo[] paramList = ctor.GetParameters();

                if (args.Length == paramList.Length)
                {
                    object[] paramValues = ParseValues(paramList, args);

                    if (paramValues == null)
                    {
                        continue;
                    }

                    int built = Build(from, start, end, ctor, paramValues, props, realProps, packs, outline, mapAvg);

                    if (built > 0)
                    {
                        return(built);
                    }
                }
            }

            return(0);
        }
コード例 #2
0
        public override void ExecuteList(CommandEventArgs e, ArrayList list)
        {
            if (list.Count == 0)
            {
                LogFailure("Nothing was found to use this command on.");
                return;
            }

            try
            {
                BaseCommand[]      commands  = new BaseCommand[m_BatchCommands.Count];
                CommandEventArgs[] eventArgs = new CommandEventArgs[m_BatchCommands.Count];

                for (int i = 0; i < m_BatchCommands.Count; ++i)
                {
                    BatchCommand bc = (BatchCommand)m_BatchCommands[i];

                    string   commandString, argString;
                    string[] args;

                    bc.GetDetails(out commandString, out argString, out args);

                    BaseCommand command = m_Scope.Commands[commandString];

                    commands[i]  = command;
                    eventArgs[i] = new CommandEventArgs(e.Mobile, commandString, argString, args);

                    if (command == null)
                    {
                        e.Mobile.SendMessage("That is either an invalid command name or one that does not support this modifier: {0}.", commandString);
                        return;
                    }
                    else if (e.Mobile.AccessLevel < command.AccessLevel)
                    {
                        e.Mobile.SendMessage("You do not have access to that command: {0}.", commandString);
                        return;
                    }
                    else if (!command.ValidateArgs(m_Scope, eventArgs[i]))
                    {
                        return;
                    }
                }

                for (int i = 0; i < commands.Length; ++i)
                {
                    BaseCommand  command = commands[i];
                    BatchCommand bc      = (BatchCommand)m_BatchCommands[i];

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = false;
                    }

                    ArrayList usedList;

                    if (Utility.InsensitiveCompare(bc.Object, "Current") == 0)
                    {
                        usedList = list;
                    }
                    else
                    {
                        Hashtable propertyChains = new Hashtable();

                        usedList = new ArrayList(list.Count);

                        for (int j = 0; j < list.Count; ++j)
                        {
                            object obj = list[j];

                            if (obj == null)
                            {
                                continue;
                            }

                            Type type = obj.GetType();

                            PropertyInfo[] chain = (PropertyInfo[])propertyChains[type];

                            string failReason = "";

                            if (chain == null && !propertyChains.Contains(type))
                            {
                                propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object, PropertyAccess.Read, ref failReason);
                            }

                            if (chain == null)
                            {
                                continue;
                            }

                            PropertyInfo endProp = Properties.GetPropertyInfo(ref obj, chain, ref failReason);

                            if (endProp == null)
                            {
                                continue;
                            }

                            try
                            {
                                obj = endProp.GetValue(obj, null);

                                if (obj != null)
                                {
                                    usedList.Add(obj);
                                }
                            }
                            catch
                            {
                            }
                        }
                    }

                    command.ExecuteList(eventArgs[i], usedList);

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = true;
                    }

                    command.Flush(e.Mobile, list.Count > 20);
                }
            }
            catch (Exception ex)
            {
                e.Mobile.SendMessage(ex.Message);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public static void DeleteItemByType_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("DeleteItemByType.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 && item.GetType() == tx /* 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);
                                }
                            }
                        }
                    }

                    // since we already have the items in our jump list, just reuse it for the to-delete list
                    if (pm.JumpList.Count > 0)
                    {
                        foreach (Item ix in pm.JumpList)
                        {
                            if (ix != null)
                            {
                                Console.WriteLine("Deleting object {0}.", ix);
                                ix.Delete();
                            }
                        }
                    }

                    Logger.Finish();
                }
                else
                {
                    e.Mobile.SendMessage("Format: DeleteItemByType <type>");
                }
            }
            catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
        }