Пример #1
0
        public bool CheckObjectTypes(Mobile from, BaseCommand command, Extensions ext, out bool items, out bool mobiles)
        {
            items = mobiles = false;

            ObjectConditional cond = ObjectConditional.Empty;

            foreach (BaseExtension check in ext)
            {
                if (check is WhereExtension)
                {
                    cond = (check as WhereExtension).Conditional;

                    break;
                }
            }

            bool condIsItem   = cond.IsItem;
            bool condIsMobile = cond.IsMobile;

            switch (command.ObjectTypes)
            {
            case ObjectTypes.All:
            case ObjectTypes.Both:
            {
                if (condIsItem)
                {
                    items = true;
                }

                if (condIsMobile)
                {
                    mobiles = true;
                }

                break;
            }

            case ObjectTypes.Items:
            {
                if (condIsItem)
                {
                    items = true;
                }
                else if (condIsMobile)
                {
                    from.SendMessage("You may not use a mobile type condition for this command.");
                    return(false);
                }

                break;
            }

            case ObjectTypes.Mobiles:
            {
                if (condIsMobile)
                {
                    mobiles = true;
                }
                else if (condIsItem)
                {
                    from.SendMessage("You may not use an item type condition for this command.");
                    return(false);
                }

                break;
            }
            }

            return(true);
        }
Пример #2
0
        public void OnTarget(Mobile from, Map map, Point3D start, Point3D end, object state)
        {
            try
            {
                object[]    states  = (object[])state;
                BaseCommand command = (BaseCommand)states[0];
                string[]    args    = (string[])states[1];

                Rectangle2D rect = new Rectangle2D(start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1);

                Extensions ext = Extensions.Parse(from, ref args);

                bool items, mobiles;

                if (!CheckObjectTypes(from, command, ext, out items, out mobiles))
                {
                    return;
                }

                IPooledEnumerable eable;

                if (items && mobiles)
                {
                    eable = map.GetObjectsInBounds(rect);
                }
                else if (items)
                {
                    eable = map.GetItemsInBounds(rect);
                }
                else if (mobiles)
                {
                    eable = map.GetMobilesInBounds(rect);
                }
                else
                {
                    return;
                }

                ArrayList objs = new ArrayList();

                foreach (object obj in eable)
                {
                    if (mobiles && obj is Mobile && !BaseCommand.IsAccessible(from, obj))
                    {
                        continue;
                    }

                    if (ext.IsValid(obj))
                    {
                        objs.Add(obj);
                    }
                }

                eable.Free();

                ext.Filter(objs);

                RunCommand(from, objs, command, args);
            }
            catch (Exception ex)
            {
                from.SendMessage(ex.Message);
            }
        }
        public void OnTarget(Mobile from, object targeted, object state)
        {
            if (!BaseCommand.IsAccessible(from, targeted))
            {
                from.SendMessage("That is not accessible.");
                return;
            }

            object[]    states  = (object[])state;
            BaseCommand command = (BaseCommand)states[0];

            string[] args = (string[])states[1];

            if (command.ObjectTypes == ObjectTypes.Mobiles)
            {
                return;                 // sanity check
            }
            if (!(targeted is Container))
            {
                from.SendMessage("That is not a container.");
            }
            else
            {
                try
                {
                    Extensions ext = Extensions.Parse(from, ref args);

                    bool items, mobiles;

                    if (!CheckObjectTypes(command, ext, out items, out mobiles))
                    {
                        return;
                    }

                    if (!items)
                    {
                        from.SendMessage("This command only works on items.");
                        return;
                    }

                    Container cont = (Container)targeted;

                    Item[] found = cont.FindItemsByType(typeof(Item), true);

                    ArrayList list = new ArrayList();

                    for (int i = 0; i < found.Length; ++i)
                    {
                        if (ext.IsValid(found[i]))
                        {
                            list.Add(found[i]);
                        }
                    }

                    ext.Filter(list);

                    RunCommand(from, list, command, args);
                }
                catch (Exception e)
                {
                    from.SendMessage(e.Message);
                }
            }
        }
Пример #4
0
        public static Extensions Parse(Mobile from, ref string[] args)
        {
            Extensions parsed = new Extensions();

            int size = args.Length;

            Type baseType = null;

            for (int i = args.Length - 1; i >= 0; --i)
            {
                ExtensionInfo extInfo = null;

                if (!ExtensionInfo.Table.TryGetValue(args[i], out extInfo))
                {
                    continue;
                }

                if (extInfo.IsFixedSize && i != (size - extInfo.Size - 1))
                {
                    throw new Exception("Invalid extended argument count.");
                }

                BaseExtension ext = extInfo.Constructor();

                ext.Parse(from, args, i + 1, size - i - 1);

                if (ext is WhereExtension)
                {
                    baseType = (ext as WhereExtension).Conditional.Type;
                }

                parsed.Add(ext);

                size = i;
            }

            parsed.Sort(delegate(BaseExtension a, BaseExtension b)
            {
                return(a.Order - b.Order);
            });

            AssemblyEmitter emitter = null;

            foreach (BaseExtension update in parsed)
            {
                update.Optimize(from, baseType, ref emitter);
            }

            if (size != args.Length)
            {
                string[] old = args;
                args = new string[size];

                for (int i = 0; i < args.Length; ++i)
                {
                    args[i] = old[i];
                }
            }

            return(parsed);
        }