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

94 lines
3.2 KiB
C#
Raw Permalink Normal View History

2020-08-27 18:30:38 -07:00
namespace Server.Commands.Generic
{
public class SerialCommandImplementor : BaseCommandImplementor
{
public SerialCommandImplementor()
{
Accessors = new[] { "Serial" };
SupportRequirement = CommandSupport.Single;
AccessLevel = AccessLevel.Counselor;
Usage = "Serial <serial> <command>";
Description = "Invokes the command on a single object by serial.";
}
public override void Execute(CommandEventArgs e)
{
if (e.Length >= 2)
{
Serial serial = (Serial)e.GetUInt32(0);
2020-08-27 18:30:38 -07:00
object obj = null;
if (serial.IsItem)
2020-09-13 21:49:46 -07:00
{
2020-08-27 18:30:38 -07:00
obj = World.FindItem(serial);
2020-09-13 21:49:46 -07:00
}
2020-08-27 18:30:38 -07:00
else if (serial.IsMobile)
2020-09-13 21:49:46 -07:00
{
2020-08-27 18:30:38 -07:00
obj = World.FindMobile(serial);
2020-09-13 21:49:46 -07:00
}
2020-08-27 18:30:38 -07:00
if (obj == null)
{
e.Mobile.SendMessage("That is not a valid serial.");
}
else
{
Commands.TryGetValue(e.GetString(1), out var command);
if (command == null)
{
e.Mobile.SendMessage(
"That is either an invalid command name or one that does not support this modifier."
);
}
else if (e.Mobile.AccessLevel < command.AccessLevel)
{
e.Mobile.SendMessage("You do not have access to that command.");
}
else
{
switch (command.ObjectTypes)
{
case ObjectTypes.Items:
{
if (obj is not Item)
2020-08-27 18:30:38 -07:00
{
e.Mobile.SendMessage("This command only works on items.");
return;
}
break;
}
case ObjectTypes.Mobiles:
{
if (obj is not Mobile)
2020-08-27 18:30:38 -07:00
{
e.Mobile.SendMessage("This command only works on mobiles.");
return;
}
break;
}
}
var oldArgs = e.Arguments;
var args = new string[oldArgs.Length - 2];
for (var i = 0; i < args.Length; ++i)
2020-09-13 21:49:46 -07:00
{
2020-08-27 18:30:38 -07:00
args[i] = oldArgs[i + 2];
2020-09-13 21:49:46 -07:00
}
2020-08-27 18:30:38 -07:00
RunCommand(e.Mobile, obj, command, args);
}
}
}
else
{
e.Mobile.SendMessage("You must supply an object serial and a command name.");
}
}
}
}