Modernization Fixes & Updates to Default Values (#3)

This commit is contained in:
Kamron Batman 2018-10-28 00:33:16 -07:00 • committed by GitHub
parent 445eddff68
commit dcf64091b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
768 changed files with 10507 additions and 14196 deletions

View file

@ -1,5 +1,4 @@
using System.Collections;
using Server.Gumps;
using System.Collections.Generic;
namespace Server.Commands.Generic
{
@ -13,13 +12,8 @@ namespace Server.Commands.Generic
public abstract class BaseCommand
{
private ArrayList m_Responses, m_Failures;
public BaseCommand()
{
m_Responses = new ArrayList();
m_Failures = new ArrayList();
}
private List<MessageEntry> m_Responses = new List<MessageEntry>();
private List<MessageEntry> m_Failures = new List<MessageEntry>();
public bool ListOptimized{ get; set; }
@ -50,7 +44,7 @@ namespace Server.Commands.Generic
return mob == null || mob == from || from.AccessLevel > mob.AccessLevel;
}
public virtual void ExecuteList(CommandEventArgs e, ArrayList list)
public virtual void ExecuteList(CommandEventArgs e, List<object> list)
{
for (int i = 0; i < list.Count; ++i)
Execute(e, list[i]);
@ -69,7 +63,7 @@ namespace Server.Commands.Generic
{
for (int i = 0; i < m_Responses.Count; ++i)
{
MessageEntry entry = (MessageEntry)m_Responses[i];
MessageEntry entry = m_Responses[i];
if (entry.m_Message == message)
{
@ -84,16 +78,11 @@ namespace Server.Commands.Generic
m_Responses.Add(new MessageEntry(message));
}
public void AddResponse(Gump gump)
{
m_Responses.Add(gump);
}
public void LogFailure(string message)
{
for (int i = 0; i < m_Failures.Count; ++i)
{
MessageEntry entry = (MessageEntry)m_Failures[i];
MessageEntry entry = m_Failures[i];
if (entry.m_Message == message)
{
@ -113,23 +102,16 @@ namespace Server.Commands.Generic
if (m_Responses.Count > 0)
for (int i = 0; i < m_Responses.Count; ++i)
{
object obj = m_Responses[i];
MessageEntry entry = m_Responses[i];
if (obj is MessageEntry entry)
{
from.SendMessage(entry.ToString());
from.SendMessage(entry.ToString());
if (flushToLog)
CommandLogging.WriteLine(from, entry.ToString());
}
else if (obj is Gump gump)
{
from.SendGump(gump);
}
if (flushToLog)
CommandLogging.WriteLine(from, entry.ToString());
}
else
for (int i = 0; i < m_Failures.Count; ++i)
from.SendMessage(((MessageEntry)m_Failures[i]).ToString());
from.SendMessage(m_Failures[i].ToString());
m_Responses.Clear();
m_Failures.Clear();
@ -148,10 +130,7 @@ namespace Server.Commands.Generic
public override string ToString()
{
if (m_Count > 1)
return $"{m_Message} ({m_Count})";
return m_Message;
return m_Count > 1 ? $"{m_Message} ({m_Count})" : m_Message;
}
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Accounting;
using Server.Engines.Help;
@ -91,7 +90,7 @@ namespace Server.Commands.Generic
ListOptimized = true;
}
public override void ExecuteList(CommandEventArgs e, ArrayList list)
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
try
{
@ -184,7 +183,7 @@ namespace Server.Commands.Generic
ListOptimized = true;
}
public override void ExecuteList(CommandEventArgs e, ArrayList list)
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
if (list.Count == 1)
AddResponse("There is one matching object.");
@ -205,13 +204,8 @@ namespace Server.Commands.Generic
Description = "Opens the web browser of a targeted player to a specified url.";
}
public static void OpenBrowser_Callback(Mobile from, bool okay, object state)
public static void OpenBrowser_Callback(Mobile from, bool okay, Mobile gm, string url, bool echo)
{
object[] states = (object[])state;
Mobile gm = (Mobile)states[0];
string url = (string)states[1];
bool echo = (bool)states[2];
if (okay)
{
if (echo)
@ -257,7 +251,7 @@ namespace Server.Commands.Generic
mob.SendGump(new WarningGump(1060637, 30720,
$"A game master is requesting to open your web browser to the following URL:<br>{url}", 0xFFC000,
320, 240, OpenBrowser_Callback, new object[] { from, url, echo }));
320, 240, okay => OpenBrowser_Callback(mob, okay, from, url, echo)));
}
}
else
@ -276,7 +270,7 @@ namespace Server.Commands.Generic
Execute(e, obj, true);
}
public override void ExecuteList(CommandEventArgs e, ArrayList list)
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
for (int i = 0; i < list.Count; ++i)
Execute(e, list[i], false);
@ -406,7 +400,7 @@ namespace Server.Commands.Generic
"Adds an item by name to the backpack of a targeted player or npc, or a targeted container. Optional constructor parameters. Optional set property list.";
}
public override void ExecuteList(CommandEventArgs e, ArrayList list)
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
if (e.Arguments.Length == 0)
return;
@ -763,12 +757,8 @@ namespace Server.Commands.Generic
Description = "Deletes a targeted item or mobile. Does not delete players.";
}
private void OnConfirmCallback(Mobile from, bool okay, object state)
private void OnConfirmCallback(Mobile from, bool okay, CommandEventArgs e, List<object> list)
{
object[] states = (object[])state;
CommandEventArgs e = (CommandEventArgs)states[0];
ArrayList list = (ArrayList)states[1];
bool flushToLog = false;
if (okay)
@ -798,13 +788,14 @@ namespace Server.Commands.Generic
Flush(from, flushToLog);
}
public override void ExecuteList(CommandEventArgs e, ArrayList list)
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
if (list.Count > 1)
{
e.Mobile.SendGump(new WarningGump(1060637, 30720,
Mobile from = e.Mobile;
from.SendGump(new WarningGump(1060637, 30720,
$"You are about to delete {list.Count} objects. This cannot be undone without a full server revert.<br><br>Continue?",
0xFFC000, 420, 280, OnConfirmCallback, new object[] { e, list }));
0xFFC000, 420, 280, okay => OnConfirmCallback(from, okay, e, list)));
AddResponse("Awaiting confirmation...");
}
else

View file

@ -1,4 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using Server.Gumps;
using Server.Items;
@ -103,8 +102,7 @@ namespace Server.Commands.Generic
protected override void OnTarget(Mobile from, object obj)
{
HouseFoundation house;
DesignInsertResult result = ProcessInsert(obj as Item, m_StaticsOnly, out house);
DesignInsertResult result = ProcessInsert(obj as Item, m_StaticsOnly, out HouseFoundation house);
switch (result)
{
@ -142,21 +140,17 @@ namespace Server.Commands.Generic
#region Area targeting mode
public override void ExecuteList(CommandEventArgs e, ArrayList list)
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
e.Mobile.SendGump(new WarningGump(1060637, 30720,
Mobile from = e.Mobile;
from.SendGump(new WarningGump(1060637, 30720,
$"You are about to insert {list.Count} objects. This cannot be undone without a full server revert.<br><br>Continue?",
0xFFC000, 420, 280, OnConfirmCallback, new object[] { e, list, e.Length < 1 || !e.GetBoolean(0) }));
0xFFC000, 420, 280, okay => OnConfirmCallback(from, okay, list, e.Length < 1 || !e.GetBoolean(0))));
AddResponse("Awaiting confirmation...");
}
private void OnConfirmCallback(Mobile from, bool okay, object state)
private void OnConfirmCallback(Mobile from, bool okay, List<object> list, bool staticsOnly)
{
object[] states = (object[])state;
CommandEventArgs e = (CommandEventArgs)states[0];
ArrayList list = (ArrayList)states[1];
bool staticsOnly = (bool)states[2];
bool flushToLog = false;
if (okay)
@ -166,8 +160,7 @@ namespace Server.Commands.Generic
for (int i = 0; i < list.Count; ++i)
{
HouseFoundation house;
DesignInsertResult result = ProcessInsert(list[i] as Item, staticsOnly, out house);
DesignInsertResult result = ProcessInsert(list[i] as Item, staticsOnly, out HouseFoundation house);
switch (result)
{

View file

@ -1,4 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Server.Gumps;
@ -20,13 +19,12 @@ namespace Server.Commands.Generic
ListOptimized = true;
}
public override void ExecuteList(CommandEventArgs e, ArrayList list)
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
if (list.Count > 0)
{
List<string> columns = new List<string>();
List<string> columns = new List<string> { "Object" };
columns.Add("Object");
if (e.Length > 0)
{
@ -55,12 +53,12 @@ namespace Server.Commands.Generic
private string[] m_Columns;
private Mobile m_From;
private ArrayList m_List;
private List<object> m_List;
private int m_Page;
private object m_Select;
public InterfaceGump(Mobile from, string[] columns, ArrayList list, int page, object select) : base(30, 30)
public InterfaceGump(Mobile from, string[] columns, List<object> list, int page, object select) : base(30, 30)
{
m_From = from;
@ -222,7 +220,7 @@ namespace Server.Commands.Generic
if (!BaseCommand.IsAccessible(m_From, obj))
{
m_From.SendMessage("That is not accessible.");
m_From.SendLocalizedMessage(500447); // That is not accessible.
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Select));
break;
}
@ -248,10 +246,10 @@ namespace Server.Commands.Generic
private Item m_Item;
private ArrayList m_List;
private List<object> m_List;
private int m_Page;
public InterfaceItemGump(Mobile from, string[] columns, ArrayList list, int page, Item item) : base(30, 30)
public InterfaceItemGump(Mobile from, string[] columns, List<object> list, int page, Item item) : base(30, 30)
{
m_From = from;
@ -381,12 +379,12 @@ namespace Server.Commands.Generic
private string[] m_Columns;
private Mobile m_From;
private ArrayList m_List;
private List<object> m_List;
private Mobile m_Mobile;
private int m_Page;
public InterfaceMobileGump(Mobile from, string[] columns, ArrayList list, int page, Mobile mob)
public InterfaceMobileGump(Mobile from, string[] columns, List<object> list, int page, Mobile mob)
: base(30, 30)
{
m_From = from;

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Commands.Generic
@ -48,7 +47,7 @@ namespace Server.Commands.Generic
return true;
}
public void Filter(ArrayList list)
public void Filter(List<object> list)
{
for (int i = 0; i < Count; ++i)
this[i].Filter(list);
@ -127,7 +126,7 @@ namespace Server.Commands.Generic
return true;
}
public virtual void Filter(ArrayList list)
public virtual void Filter(List<object> list)
{
}
}

View file

@ -109,8 +109,8 @@ namespace Server.Commands.Generic
}
else
{
MethodInfo parseMethod = null;
object[] parseArgs = null;
MethodInfo parseMethod;
object[] parseArgs;
MethodInfo parseNumber = Type.GetMethod(
"Parse",

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
@ -8,7 +7,7 @@ namespace Server.Commands.Generic
{
public static class DistinctCompiler
{
public static IComparer Compile(AssemblyEmitter assembly, Type objectType, Property[] props)
public static IComparer<T> Compile<T>(AssemblyEmitter assembly, Type objectType, Property[] props)
{
TypeBuilder typeBuilder = assembly.DefineType(
"__distinct",
@ -29,7 +28,8 @@ namespace Server.Commands.Generic
// : base()
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes));
il.Emit(OpCodes.Call, typeof(T).GetConstructor(Type.EmptyTypes) ??
throw new Exception($"Could not find empty constructor for type {typeof(T).FullName}"));
// return;
il.Emit(OpCodes.Ret);
@ -39,7 +39,7 @@ namespace Server.Commands.Generic
#region IComparer
typeBuilder.AddInterfaceImplementation(typeof(IComparer));
typeBuilder.AddInterfaceImplementation(typeof(IComparer<T>));
MethodBuilder compareMethod;
@ -52,7 +52,7 @@ namespace Server.Commands.Generic
/* name */ "Compare",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof(int),
/* params */ new[] { typeof(object), typeof(object) });
/* params */ new[] { typeof(T), typeof(T) });
LocalBuilder a = emitter.CreateLocal(objectType);
LocalBuilder b = emitter.CreateLocal(objectType);
@ -105,14 +105,14 @@ namespace Server.Commands.Generic
typeBuilder.DefineMethodOverride(
emitter.Method,
typeof(IComparer).GetMethod(
typeof(IComparer<T>).GetMethod(
"Compare",
new[]
{
typeof(object),
typeof(object)
typeof(T),
typeof(T)
}
)
) ?? throw new Exception($"No Compare method found for type {typeof(T).FullName}")
);
compareMethod = emitter.Method;
@ -124,7 +124,7 @@ namespace Server.Commands.Generic
#region IEqualityComparer
typeBuilder.AddInterfaceImplementation(typeof(IEqualityComparer<object>));
typeBuilder.AddInterfaceImplementation(typeof(IEqualityComparer<T>));
#region Equals
@ -135,7 +135,7 @@ namespace Server.Commands.Generic
/* name */ "Equals",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof(bool),
/* params */ new[] { typeof(object), typeof(object) });
/* params */ new[] { typeof(T), typeof(T) });
emitter.Generator.Emit(OpCodes.Ldarg_0);
emitter.Generator.Emit(OpCodes.Ldarg_1);
@ -151,14 +151,14 @@ namespace Server.Commands.Generic
typeBuilder.DefineMethodOverride(
emitter.Method,
typeof(IEqualityComparer<object>).GetMethod(
typeof(IEqualityComparer<T>).GetMethod(
"Equals",
new[]
{
typeof(object),
typeof(object)
typeof(T),
typeof(T)
}
)
) ?? throw new Exception($"No Equals method found for type {typeof(T).FullName}")
);
}
@ -173,7 +173,7 @@ namespace Server.Commands.Generic
/* name */ "GetHashCode",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof(int),
/* params */ new[] { typeof(object) });
/* params */ new[] { typeof(T) });
LocalBuilder obj = emitter.CreateLocal(objectType);
@ -193,7 +193,7 @@ namespace Server.Commands.Generic
MethodInfo getHashCode = active.GetMethod("GetHashCode", Type.EmptyTypes);
if (getHashCode == null)
getHashCode = typeof(object).GetMethod("GetHashCode", Type.EmptyTypes);
getHashCode = typeof(T).GetMethod("GetHashCode", Type.EmptyTypes);
if (active != typeof(int))
{
@ -237,13 +237,13 @@ namespace Server.Commands.Generic
typeBuilder.DefineMethodOverride(
emitter.Method,
typeof(IEqualityComparer<object>).GetMethod(
typeof(IEqualityComparer<T>).GetMethod(
"GetHashCode",
new[]
{
typeof(object)
typeof(T)
}
)
) ?? throw new Exception($"No GetHashCode method found for type {typeof(T).FullName}")
);
}
@ -253,7 +253,7 @@ namespace Server.Commands.Generic
Type comparerType = typeBuilder.CreateType();
return (IComparer)Activator.CreateInstance(comparerType);
return (IComparer<T>)Activator.CreateInstance(comparerType);
}
}
}

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
@ -45,12 +45,12 @@ namespace Server.Commands.Generic
public static class SortCompiler
{
public static IComparer Compile(AssemblyEmitter assembly, Type objectType, OrderInfo[] orders)
public static IComparer<T> Compile<T>(AssemblyEmitter assembly, Type objectType, OrderInfo[] orders)
{
TypeBuilder typeBuilder = assembly.DefineType(
"__sort",
TypeAttributes.Public,
typeof(object)
typeof(T)
);
#region Constructor
@ -66,7 +66,8 @@ namespace Server.Commands.Generic
// : base()
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes));
il.Emit(OpCodes.Call, typeof(T).GetConstructor(Type.EmptyTypes) ??
throw new Exception($"Could not find empty constructor for type {typeof(T).FullName}"));
// return;
il.Emit(OpCodes.Ret);
@ -76,12 +77,9 @@ namespace Server.Commands.Generic
#region IComparer
typeBuilder.AddInterfaceImplementation(typeof(IComparer));
MethodBuilder compareMethod;
typeBuilder.AddInterfaceImplementation(typeof(IComparer<T>));
#region Compare
{
MethodEmitter emitter = new MethodEmitter(typeBuilder);
@ -89,7 +87,7 @@ namespace Server.Commands.Generic
/* name */ "Compare",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof(int),
/* params */ new[] { typeof(object), typeof(object) });
/* params */ new[] { typeof(T), typeof(T) });
LocalBuilder a = emitter.CreateLocal(objectType);
LocalBuilder b = emitter.CreateLocal(objectType);
@ -145,17 +143,15 @@ namespace Server.Commands.Generic
typeBuilder.DefineMethodOverride(
emitter.Method,
typeof(IComparer).GetMethod(
typeof(IComparer<T>).GetMethod(
"Compare",
new[]
{
typeof(object),
typeof(object)
typeof(T),
typeof(T)
}
)
) ?? throw new Exception($"No Compare method found for type {typeof(T).FullName}")
);
compareMethod = emitter.Method;
}
#endregion
@ -163,8 +159,7 @@ namespace Server.Commands.Generic
#endregion
Type comparerType = typeBuilder.CreateType();
return (IComparer)Activator.CreateInstance(comparerType);
return (IComparer<T>)Activator.CreateInstance(comparerType);
}
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Commands.Generic
@ -9,7 +8,7 @@ namespace Server.Commands.Generic
public static ExtensionInfo ExtInfo =
new ExtensionInfo(30, "Distinct", -1, delegate { return new DistinctExtension(); });
private IComparer m_Comparer;
private IComparer<object> m_Comparer;
private List<Property> m_Properties;
@ -39,7 +38,7 @@ namespace Server.Commands.Generic
if (assembly == null)
assembly = new AssemblyEmitter("__dynamic", false);
m_Comparer = DistinctCompiler.Compile(assembly, baseType, m_Properties.ToArray());
m_Comparer = DistinctCompiler.Compile<object>(assembly, baseType, m_Properties.ToArray());
}
public override void Parse(Mobile from, string[] arguments, int offset, int size)
@ -57,12 +56,12 @@ namespace Server.Commands.Generic
}
}
public override void Filter(ArrayList list)
public override void Filter(List<object> list)
{
if (m_Comparer == null)
throw new InvalidOperationException("The extension must first be optimized.");
ArrayList copy = new ArrayList(list);
List<object> copy = new List<object>(list);
copy.Sort(m_Comparer);

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Commands.Generic
{
@ -24,7 +24,7 @@ namespace Server.Commands.Generic
throw new Exception("Limit cannot be less than zero.");
}
public override void Filter(ArrayList list)
public override void Filter(List<object> list)
{
if (list.Count > Limit)
list.RemoveRange(Limit, list.Count - Limit);

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Commands.Generic
@ -8,7 +7,7 @@ namespace Server.Commands.Generic
{
public static ExtensionInfo ExtInfo = new ExtensionInfo(40, "Order", -1, () => new SortExtension());
private IComparer m_Comparer;
private IComparer<object> m_Comparer;
private List<OrderInfo> m_Orders;
@ -38,7 +37,7 @@ namespace Server.Commands.Generic
if (assembly == null)
assembly = new AssemblyEmitter("__dynamic", false);
m_Comparer = SortCompiler.Compile(assembly, baseType, m_Orders.ToArray());
m_Comparer = SortCompiler.Compile<object>(assembly, baseType, m_Orders.ToArray());
}
public override void Parse(Mobile from, string[] arguments, int offset, int size)
@ -93,7 +92,7 @@ namespace Server.Commands.Generic
}
}
public override void Filter(ArrayList list)
public override void Filter(List<object> list)
{
if (m_Comparer == null)
throw new InvalidOperationException("The extension must first be optimized.");

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Commands.Generic
{
@ -22,24 +22,18 @@ namespace Server.Commands.Generic
public override void Process(Mobile from, BaseCommand command, string[] args)
{
BoundingBoxPicker.Begin(from, OnTarget, new object[] { command, args });
BoundingBoxPicker.Begin(from, (map, start, end) => OnTarget(from, map, start, end, command, args));
}
public void OnTarget(Mobile from, Map map, Point3D start, Point3D end, object state)
public void OnTarget(Mobile from, Map map, Point3D start, Point3D end, BaseCommand command, string[] args)
{
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;
if (!CheckObjectTypes(from, command, ext, out items, out mobiles))
if (!CheckObjectTypes(from, command, ext, out bool items, out bool mobiles))
return;
IPooledEnumerable<IEntity> eable;
@ -49,7 +43,9 @@ namespace Server.Commands.Generic
else
return;
ArrayList objs = new ArrayList();
eable.Free();
List<object> objs = new List<object>();
foreach (IEntity obj in eable)
{

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
@ -212,7 +211,7 @@ namespace Server.Commands.Generic
bool flushToLog = false;
if (obj is ArrayList list)
if (obj is List<object> list)
{
if (list.Count > 20)
CommandLogging.Enabled = false;
@ -230,7 +229,7 @@ namespace Server.Commands.Generic
else if (obj != null)
{
if (command.ListOptimized)
command.ExecuteList(e, new ArrayList { obj });
command.ExecuteList(e, new List<object>{ obj });
else
command.Execute(e, obj);
}

View file

@ -1,7 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Targeting;
@ -23,21 +21,17 @@ namespace Server.Commands.Generic
{
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 });
(m, targeted) => OnTarget(m, targeted, command, args));
}
public void OnTarget(Mobile from, object targeted, object state)
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)
{
if (!BaseCommand.IsAccessible(from, targeted))
{
from.SendMessage("That is not accessible.");
from.SendLocalizedMessage(500447); // 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
@ -60,10 +54,15 @@ namespace Server.Commands.Generic
return;
}
List<Item> list = cont.FindItemsByType<Item>().Where(item => ext.IsValid(item)).ToList();
List<object> list = new List<object>();
// TODO: Is there a way to avoid using ArrayList?
ext.Filter(new ArrayList(list));
foreach (Item item in cont.FindItemsByType<Item>())
{
if (ext.IsValid(item))
list.Add(item);
}
ext.Filter(list);
RunCommand(from, list, command, args);
}

View file

@ -25,8 +25,7 @@ namespace Server.Commands.Generic
if (map == null || map == Map.Internal)
return;
impl.OnTarget(from, map, Point3D.Zero, new Point3D(map.Width - 1, map.Height - 1, 0),
new object[] { command, args });
impl.OnTarget(from, map, Point3D.Zero, new Point3D(map.Width - 1, map.Height - 1, 0), command, args);
}
}
}

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Commands.Generic
{
@ -22,12 +22,10 @@ namespace Server.Commands.Generic
{
Extensions ext = Extensions.Parse(from, ref args);
bool items, mobiles;
if (!CheckObjectTypes(from, command, ext, out items, out mobiles))
if (!CheckObjectTypes(from, command, ext, out bool items, out bool mobiles))
return;
ArrayList list = new ArrayList();
List<object> list = new List<object>();
if (items)
foreach (Item item in World.Items.Values)

View file

@ -1,6 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using Server.Network;
namespace Server.Commands.Generic
@ -24,9 +24,7 @@ namespace Server.Commands.Generic
{
Extensions ext = Extensions.Parse(from, ref args);
bool items, mobiles;
if (!CheckObjectTypes(from, command, ext, out items, out mobiles))
if (!CheckObjectTypes(from, command, ext, out bool _, out bool mobiles))
return;
if (!mobiles) // sanity check
@ -35,8 +33,8 @@ namespace Server.Commands.Generic
return;
}
ArrayList list = new ArrayList();
ArrayList addresses = new ArrayList();
List<object> list = new List<object>();
List<IPAddress> addresses = new List<IPAddress>();
List<NetState> states = NetState.Instances;

View file

@ -17,20 +17,16 @@ namespace Server.Commands.Generic
{
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 });
(m, targeted) => OnTarget(m, targeted, command, args));
}
public void OnTarget(Mobile from, object targeted, object state)
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)
{
object[] states = (object[])state;
BaseCommand command = (BaseCommand)states[0];
string[] args = (string[])states[1];
if (!BaseCommand.IsAccessible(from, targeted))
{
from.SendMessage("That is not accessible.");
from.SendLocalizedMessage(500447); // That is not accessible.
from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None,
new TargetStateCallback(OnTarget), new object[] { command, args });
(m, t) => OnTarget(m, t, command, args));
return;
}
@ -38,7 +34,7 @@ namespace Server.Commands.Generic
{
case ObjectTypes.Both:
{
if (!(targeted is Item) && !(targeted is Mobile))
if (!(targeted is Item || targeted is Mobile))
{
from.SendMessage("This command does not work on that.");
return;
@ -70,8 +66,8 @@ namespace Server.Commands.Generic
RunCommand(from, targeted, command, args);
from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, new TargetStateCallback(OnTarget),
new object[] { command, args });
from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None,
(m, t) => OnTarget(m, t, command, args));
}
}
}

View file

@ -81,7 +81,7 @@ namespace Server.Commands.Generic
break;
}
return ParseDirect(from, conditionArgs, 0, conditionArgs.Length);
return ParseDirect(from, conditionArgs, 0, conditionArgs?.Length ?? 0);
}
public static ObjectConditional ParseDirect(Mobile from, string[] args, int offset, int size)

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Network;
@ -24,9 +23,7 @@ namespace Server.Commands.Generic
{
Extensions ext = Extensions.Parse(from, ref args);
bool items, mobiles;
if (!CheckObjectTypes(from, command, ext, out items, out mobiles))
if (!CheckObjectTypes(from, command, ext, out bool _, out bool mobiles))
return;
if (!mobiles) // sanity check
@ -35,7 +32,7 @@ namespace Server.Commands.Generic
return;
}
ArrayList list = new ArrayList();
List<object> list = new List<object>();
List<NetState> states = NetState.Instances;

View file

@ -73,7 +73,7 @@ namespace Server.Commands.Generic
Point3D start = new Point3D(from.X - range, from.Y - range, from.Z);
Point3D end = new Point3D(from.X + range, from.Y + range, from.Z);
impl.OnTarget(from, map, start, end, new object[] { command, args });
impl.OnTarget(from, map, start, end, command, args);
}
}
}

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Commands.Generic
{
@ -22,14 +22,12 @@ namespace Server.Commands.Generic
{
Extensions ext = Extensions.Parse(from, ref args);
bool items, mobiles;
if (!CheckObjectTypes(from, command, ext, out items, out mobiles))
if (!CheckObjectTypes(from, command, ext, out bool _, out bool mobiles))
return;
Region reg = from.Region;
ArrayList list = new ArrayList();
List<object> list = new List<object>();
if (mobiles)
{

View file

@ -15,7 +15,7 @@ namespace Server.Commands.Generic
{
if (e.Length >= 2)
{
Serial serial = e.GetInt32(0);
Serial serial = e.GetUInt32(0);
object obj = null;

View file

@ -38,21 +38,17 @@ namespace Server.Commands.Generic
{
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 });
(m, targeted) => OnTarget(m, targeted, command, args));
}
public void OnTarget(Mobile from, object targeted, object state)
public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args)
{
if (!BaseCommand.IsAccessible(from, targeted))
{
from.SendMessage("That is not accessible.");
from.SendLocalizedMessage(500447); // That is not accessible.
return;
}
object[] states = (object[])state;
BaseCommand command = (BaseCommand)states[0];
string[] args = (string[])states[1];
switch (command.ObjectTypes)
{
case ObjectTypes.Both: