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 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 );
            }
        }
        public void RunCommand(Mobile from, object obj, BaseCommand command, string[] args)
        {
            try
            {
                CommandEventArgs e = new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args);

                if (!command.ValidateArgs(this, e))
                {
                    return;
                }

                bool flushToLog = false;

                if (obj is ArrayList)
                {
                    ArrayList list = (ArrayList)obj;

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = false;
                    }
                    else if (list.Count == 0)
                    {
                        command.LogFailure("Nothing was found to use this command on.");
                    }

                    command.ExecuteList(e, list);

                    if (list.Count > 20)
                    {
                        flushToLog             = true;
                        CommandLogging.Enabled = true;
                    }
                }
                else if (obj != null)
                {
                    if (command.ListOptimized)
                    {
                        ArrayList list = new ArrayList();
                        list.Add(obj);
                        command.ExecuteList(e, list);
                    }
                    else
                    {
                        command.Execute(e, obj);
                    }
                }

                command.Flush(from, flushToLog);
            }
            catch (Exception ex)
            {
                from.SendMessage(ex.Message);
            }
        }
Esempio 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;
                }

                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);
            }
        }
        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.GetMobiles() )
                    {
                        if ( cond.CheckCondition( mob ) )
                        {
                            list.Add( mob );
                        }
                    }
                }
                else
                {
                    command.LogFailure( "This command does not support items." );
                    return;
                }

                obj = list;
            }
            catch ( Exception 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;

				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);
			}
		}
Esempio n. 8
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);
            }
        }
        public void RunCommand( Mobile from, object obj, BaseCommand command, string[] args )
        {
            try
            {
                Server.Commands.CommandEventArgs e = new Server.Commands.CommandEventArgs( from, command.Commands[0], GenerateArgString( args ), args );

                if ( !command.ValidateArgs( this, e ) )
                    return;

                bool flushToLog = false;

                if ( obj is ArrayList )
                {
                    ArrayList list = (ArrayList)obj;

                    if ( list.Count > 20 )
                        CommandLogging.Enabled = false;
                    else if ( list.Count == 0 )
                        command.LogFailure( "Nothing was found to use this command on." );

                    command.ExecuteList( e, list );

                    if ( list.Count > 20 )
                    {
                        flushToLog = true;
                        CommandLogging.Enabled = true;
                    }
                }
                else if ( obj != null )
                {
                    if ( command.ListOptimized )
                    {
                        ArrayList list = new ArrayList();
                        list.Add( obj );
                        command.ExecuteList( e, list );
                    }
                    else
                    {
                        command.Execute( e, obj );
                    }
                }

                command.Flush( from, flushToLog );
            }
            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;
        }