Ejemplo n.º 1
0
        private static void Condition_OnTarget(Mobile from, object obj, object state)
        {
            string[]          args = (string[])state;
            ObjectConditional cond = Parse(from, ref args);

            from.SendMessage(cond.CheckCondition(obj).ToString());
        }
Ejemplo n.º 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];

                ObjectConditional cond = ObjectConditional.Parse(from, ref args);

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

                bool items, mobiles;

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

                IEnumerable <object> 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 (cond.CheckCondition(obj))
                    {
                        objs.Add(obj);
                    }
                }

                RunCommand(from, objs, command, args);
            }
            catch (Exception ex)
            {
                from.SendMessage(ex.Message);
            }
        }
        public bool CheckObjectTypes(BaseCommand command, ObjectConditional cond, out bool items, out bool mobiles)
        {
            items = mobiles = false;

            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)
                {
                    command.LogFailure("You may not use an mobile type condition for this command.");
                    return(false);
                }

                break;
            }

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

                break;
            }
            }

            return(true);
        }
Ejemplo n.º 4
0
        public override void Compile(Mobile from, BaseCommand command, ref string[] args, ref object obj)
        {
            try
            {
                ObjectConditional cond = ObjectConditional.Parse(from, ref args);

                bool items, mobiles;

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

                ArrayList list = new ArrayList();

                if (items)
                {
                    foreach (Item item in World.Items.Values)
                    {
                        if (cond.CheckCondition(item))
                        {
                            list.Add(item);
                        }
                    }
                }

                if (mobiles)
                {
                    foreach (Mobile mob in World.Mobiles.Values)
                    {
                        if (cond.CheckCondition(mob))
                        {
                            list.Add(mob);
                        }
                    }
                }

                obj = list;
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                from.SendMessage(ex.Message);
            }
        }
Ejemplo n.º 5
0
        public override void Compile(Mobile from, BaseCommand command, ref string[] args, ref object obj)
        {
            try
            {
                ObjectConditional cond = ObjectConditional.Parse(from, ref args);

                bool items, mobiles;

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

                if (!mobiles)                 // sanity check
                {
                    command.LogFailure("This command does not support mobiles.");
                    return;
                }

                ArrayList list = new ArrayList();

                //ArrayList states = NetState.Instances;
                List <NetState> states = NetState.Instances;

                for (int i = 0; i < states.Count; ++i)
                {
                    NetState ns  = states[i];
                    Mobile   mob = ns.Mobile;

                    if (mob != null && cond.CheckCondition(mob))
                    {
                        list.Add(mob);
                    }
                }

                obj = list;
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                from.SendMessage(ex.Message);
            }
        }
        public override void Compile(Mobile from, BaseCommand command, ref string[] args, ref object obj)
        {
            try
            {
                ObjectConditional cond = ObjectConditional.Parse(from, ref args);

                bool items, mobiles;

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

                Region reg = from.Region;

                ArrayList list = new ArrayList();

                if (mobiles)
                {
                    foreach (Mobile mob in reg.Mobiles.Values)
                    {
                        if (cond.CheckCondition(mob))
                        {
                            list.Add(mob);
                        }
                    }
                }
                else
                {
                    command.LogFailure("This command does not support mobiles.");
                    return;
                }

                obj = list;
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                from.SendMessage(ex.Message);
            }
        }
Ejemplo n.º 7
0
        public override void Compile(Mobile from, BaseCommand command, ref string[] args, ref object obj)
        {
            try
            {
                ObjectConditional cond = ObjectConditional.Parse(from, ref args);

                bool items, mobiles;

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

                if (!mobiles)                   // sanity check
                {
                    command.LogFailure("This command does not support mobiles.");
                    return;
                }

                ArrayList list = new ArrayList();

                foreach (Mobile mob in GameServer.Instance.Clients.Select(ns => ns.Mobile))
                {
                    if (mob != null && cond.CheckCondition(mob))
                    {
                        list.Add(mob);
                    }
                }

                obj = list;
            }
            catch (Exception ex)
            {
                from.SendMessage(ex.Message);
            }
        }
Ejemplo n.º 8
0
        public override void ExecuteList(CommandEventArgs e, ArrayList list)
        {
            try
            {
                string[]          args      = e.Arguments;
                ObjectConditional condition = ObjectConditional.Parse(e.Mobile, ref args);

                for (int i = 0; i < list.Count; ++i)
                {
                    if (condition.CheckCondition(list[i]))
                    {
                        AddResponse("True - that object matches the condition.");
                    }
                    else
                    {
                        AddResponse("False - that object does not match the condition.");
                    }
                }
            }
            catch (Exception ex)
            {
                e.Mobile.SendMessage(ex.Message);
            }
        }
        public bool CheckObjectTypes( BaseCommand command, ObjectConditional cond, out bool items, out bool mobiles )
        {
            items = mobiles = false;

            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 )
                    {
                        command.LogFailure( "You may not use an mobile type condition for this command." );
                        return false;
                    }

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

                    break;
                }
            }

            return true;
        }
        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
                {
                    ObjectConditional cond = ObjectConditional.Parse(from, ref args);

                    bool items, mobiles;

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

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

                    Container cont = (Container)targeted;

                    Item[] found;

                    if (cond.Type == null)
                    {
                        found = cont.FindItemsByType(typeof(Item), true);
                    }
                    else
                    {
                        found = cont.FindItemsByType(cond.Type, true);
                    }

                    ArrayList list = new ArrayList();

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

                    RunCommand(from, list, command, args);
                }
                catch (Exception e)
                {
                    from.SendMessage(e.Message);
                }
            }
        }