2013-10-28 07:09:42 +00:00
using System ;
using System.Collections ;
namespace Server.Commands.Generic
{
public class AreaCommandImplementor : BaseCommandImplementor
{
private static AreaCommandImplementor m_Instance ;
public AreaCommandImplementor ( )
{
2020-04-16 21:29:55 -04:00
Accessors = new string [ ] { "Area" , "Group" } ;
SupportRequirement = CommandSupport . Area ;
SupportsConditionals = true ;
AccessLevel = AccessLevel . GameMaster ;
Usage = "Area <command> [condition]" ;
Description = "Invokes the command on all appropriate objects in a targeted area. Optional condition arguments can further restrict the set of objects." ;
2013-10-28 07:09:42 +00:00
m_Instance = this ;
}
2020-04-16 20:21:33 -04:00
public static AreaCommandImplementor Instance = > m_Instance ;
2013-10-28 07:09:42 +00:00
public override void Process ( Mobile from , BaseCommand command , string [ ] args )
{
2020-04-21 20:25:24 -04:00
BoundingBoxPicker . Begin ( from , OnTarget , new object [ ] { command , args } ) ;
2013-10-28 07:09:42 +00:00
}
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 ;
2020-04-16 21:29:55 -04:00
if ( ! CheckObjectTypes ( from , command , ext , out items , out mobiles ) )
2013-10-28 07:09:42 +00:00
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 ) ;
2020-04-16 21:29:55 -04:00
RunCommand ( from , objs , command , args ) ;
2013-10-28 07:09:42 +00:00
}
catch ( Exception ex )
{
from . SendMessage ( ex . Message ) ;
2020-09-16 10:43:44 -04:00
Diagnostics . ExceptionLogging . LogException ( ex ) ;
2013-10-28 07:09:42 +00:00
}
}
}
2020-04-21 20:25:24 -04:00
}