runuo/Scripts/Commands/Generic/Implementors/ContainedCommandImplementor.cs
eos 99b0ad9de5 - Fixed the Palace of Paroxysmus region bounds.
- Fixed a typo in the Huntsman's Forest region name.
- Added the Bravehorn's drinking pool and Huntsman's Forest quest regions to Felucca.
- Fixed CheckObjectTypes not sending invalid condition replies, because the commands are not always flushed after checking this.
- When using an item condition with [online or [ipaddress, the command will now correctly say it does not support items.
- The [Go menu now handles comments in the XML location files correctly.
- Added the Increased Karma Loss attribute.
- Renamed DummyTheif to DummyThief.
2012-05-20 02:35:53 +00:00

85 lines
No EOL
2.3 KiB
C#

using System;
using System.Collections;
using Server;
using Server.Items;
using Server.Targeting;
namespace Server.Commands.Generic
{
public class ContainedCommandImplementor : BaseCommandImplementor
{
public ContainedCommandImplementor()
{
Accessors = new string[]{ "Contained" };
SupportRequirement = CommandSupport.Contained;
AccessLevel = AccessLevel.GameMaster;
Usage = "Contained <command> [condition]";
Description = "Invokes the command on all child items in a targeted container. Optional condition arguments can further restrict the set of objects.";
}
public override void Process( Mobile from, BaseCommand command, string[] args )
{
if ( command.ValidateArgs( this, new CommandEventArgs( from, command.Commands[0], GenerateArgString( args ), args ) ) )
from.BeginTarget( -1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, new TargetStateCallback( OnTarget ), new object[]{ command, args } );
}
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( from, 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 );
}
}
}
}
}