modernuo/Projects/UOContent/Commands/Generic/Implementors/SingleCommandImplementor.cs

105 lines
3.4 KiB
C#
Raw Permalink Normal View History

2020-08-27 18:30:38 -07:00
using Server.Targeting;
namespace Server.Commands.Generic
{
public class SingleCommandImplementor : BaseCommandImplementor
{
public SingleCommandImplementor()
{
Accessors = new[] { "Single" };
SupportRequirement = CommandSupport.Single;
AccessLevel = AccessLevel.Counselor;
Usage = "Single <command>";
Description =
"Invokes the command on a single targeted object. This is the same as just invoking the command directly.";
}
public override void Register(BaseCommand command)
{
base.Register(command);
for (var i = 0; i < command.Commands.Length; ++i)
2020-09-13 21:49:46 -07:00
{
2020-08-27 18:30:38 -07:00
CommandSystem.Register(command.Commands[i], command.AccessLevel, Redirect);
2020-09-13 21:49:46 -07:00
}
2020-08-27 18:30:38 -07:00
}
public void Redirect(CommandEventArgs e)
{
Commands.TryGetValue(e.Command, out var command);
if (command == null)
2020-09-13 21:49:46 -07:00
{
2020-08-27 18:30:38 -07:00
e.Mobile.SendMessage("That is either an invalid command name or one that does not support this modifier.");
2020-09-13 21:49:46 -07:00
}
2020-08-27 18:30:38 -07:00
else if (e.Mobile.AccessLevel < command.AccessLevel)
2020-09-13 21:49:46 -07:00
{
2020-08-27 18:30:38 -07:00
e.Mobile.SendMessage("You do not have access to that command.");
2020-09-13 21:49:46 -07:00
}
2020-08-27 18:30:38 -07:00
else if (command.ValidateArgs(this, e))
2020-09-13 21:49:46 -07:00
{
2020-08-27 18:30:38 -07:00
Process(e.Mobile, command, e.Arguments);
2020-09-13 21:49:46 -07:00
}
2020-08-27 18:30:38 -07:00
}
public override void Process(Mobile from, BaseCommand command, string[] args)
{
if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args)))
2020-09-13 21:49:46 -07:00
{
2020-09-18 18:41:26 -07:00
from.BeginTarget(
2020-08-27 18:30:38 -07:00
-1,
command.ObjectTypes == ObjectTypes.All,
TargetFlags.None,
(m, targeted, a) => OnTarget(m, targeted, command, a),
args
);
2020-09-13 21:49:46 -07:00
}
2020-08-27 18:30:38 -07:00
}
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)
{
if (!BaseCommand.IsAccessible(from, targeted))
{
from.SendLocalizedMessage(500447); // That is not accessible.
return;
}
switch (command.ObjectTypes)
{
case ObjectTypes.Both:
{
if (targeted is not Item && targeted is not Mobile)
2020-08-27 18:30:38 -07:00
{
from.SendMessage("This command does not work on that.");
return;
}
break;
}
case ObjectTypes.Items:
{
if (targeted is not Item)
2020-08-27 18:30:38 -07:00
{
from.SendMessage("This command only works on items.");
return;
}
break;
}
case ObjectTypes.Mobiles:
{
if (targeted is not Mobile)
2020-08-27 18:30:38 -07:00
{
from.SendMessage("This command only works on mobiles.");
return;
}
break;
}
}
RunCommand(from, targeted, command, args);
}
}
}