Adds style cop (#109)

This commit is contained in:
Kamron Batman 2020-04-26 00:16:02 -07:00 committed by GitHub
parent 3e715bcb60
commit 556a17aba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1725 changed files with 33831 additions and 38046 deletions

View file

@ -12,22 +12,22 @@ namespace Server.Commands.Generic
public abstract class BaseCommand
{
private List<MessageEntry> m_Responses = new List<MessageEntry>();
private List<MessageEntry> m_Failures = new List<MessageEntry>();
private readonly List<MessageEntry> m_Responses = new List<MessageEntry>();
private readonly List<MessageEntry> m_Failures = new List<MessageEntry>();
public bool ListOptimized{ get; set; }
public bool ListOptimized { get; set; }
public string[] Commands{ get; set; }
public string[] Commands { get; set; }
public string Usage{ get; set; }
public string Usage { get; set; }
public string Description{ get; set; }
public string Description { get; set; }
public AccessLevel AccessLevel{ get; set; }
public AccessLevel AccessLevel { get; set; }
public ObjectTypes ObjectTypes{ get; set; }
public ObjectTypes ObjectTypes { get; set; }
public CommandSupport Supports{ get; set; }
public CommandSupport Supports { get; set; }
public static bool IsAccessible(Mobile from, object obj)
{
@ -117,7 +117,7 @@ namespace Server.Commands.Generic
private class MessageEntry
{
public int m_Count;
public string m_Message;
public readonly string m_Message;
public MessageEntry(string message)
{

View file

@ -14,7 +14,7 @@ namespace Server.Commands.Generic
{
public class TargetCommands
{
public static List<BaseCommand> AllCommands{ get; } = new List<BaseCommand>();
public static List<BaseCommand> AllCommands { get; } = new List<BaseCommand>();
public static void Initialize()
{
@ -348,7 +348,7 @@ namespace Server.Commands.Generic
public class TellCommand : BaseCommand
{
private bool m_InGump;
private readonly bool m_InGump;
public TellCommand(bool inGump)
{
@ -511,7 +511,7 @@ namespace Server.Commands.Generic
SpellHelper.GetSurfaceTop(ref p);
//CommandLogging.WriteLine( from, "{0} {1} teleporting to {2}", from.AccessLevel, CommandLogging.Format( from ), new Point3D( p ) );
// CommandLogging.WriteLine( from, "{0} {1} teleporting to {2}", from.AccessLevel, CommandLogging.Format( from ), new Point3D( p ) );
Point3D fromLoc = from.Location;
Point3D toLoc = new Point3D(p);
@ -683,8 +683,8 @@ namespace Server.Commands.Generic
public class AliasedSetCommand : BaseCommand
{
private string m_Name;
private string m_Value;
private readonly string m_Name;
private readonly string m_Value;
public AliasedSetCommand(AccessLevel level, string command, string name, string value, ObjectTypes objects)
{
@ -830,7 +830,7 @@ namespace Server.Commands.Generic
public class KillCommand : BaseCommand
{
private bool m_Value;
private readonly bool m_Value;
public KillCommand(bool value)
{
@ -916,7 +916,7 @@ namespace Server.Commands.Generic
public class HideCommand : BaseCommand
{
private bool m_Value;
private readonly bool m_Value;
public HideCommand(bool value)
{
@ -1011,7 +1011,7 @@ namespace Server.Commands.Generic
public class KickCommand : BaseCommand
{
private bool m_Ban;
private readonly bool m_Ban;
public KickCommand(bool ban)
{

View file

@ -35,7 +35,7 @@ namespace Server.Commands.Generic
{
house = null;
if (item == null || item is BaseMulti || item is HouseSign || staticsOnly && !(item is Static))
if (item == null || item is BaseMulti || item is HouseSign || (staticsOnly && !(item is Static)))
return DesignInsertResult.InvalidItem;
house = BaseHouse.FindHouseAt(item) as HouseFoundation;
@ -69,8 +69,6 @@ namespace Server.Commands.Generic
return true;
}
#region Single targeting mode
public override void Execute(CommandEventArgs e, object obj)
{
Target t = new DesignInsertTarget(new List<HouseFoundation>(), e.Length < 1 || !e.GetBoolean(0));
@ -79,8 +77,8 @@ namespace Server.Commands.Generic
private class DesignInsertTarget : Target
{
private List<HouseFoundation> m_Foundations;
private bool m_StaticsOnly;
private readonly List<HouseFoundation> m_Foundations;
private readonly bool m_StaticsOnly;
public DesignInsertTarget(List<HouseFoundation> foundations, bool staticsOnly)
: base(-1, false, TargetFlags.None)
@ -107,39 +105,35 @@ namespace Server.Commands.Generic
switch (result)
{
case DesignInsertResult.Valid:
{
if (m_Foundations.Count == 0)
from.SendMessage(
"The item has been inserted into the house design. Press ESC when you are finished.");
else
from.SendMessage("The item has been inserted into the house design.");
{
if (m_Foundations.Count == 0)
from.SendMessage(
"The item has been inserted into the house design. Press ESC when you are finished.");
else
from.SendMessage("The item has been inserted into the house design.");
if (!m_Foundations.Contains(house))
m_Foundations.Add(house);
if (!m_Foundations.Contains(house))
m_Foundations.Add(house);
break;
}
break;
}
case DesignInsertResult.InvalidItem:
{
from.SendMessage("That cannot be inserted. Try again.");
break;
}
{
from.SendMessage("That cannot be inserted. Try again.");
break;
}
case DesignInsertResult.NotInHouse:
case DesignInsertResult.OutsideHouseBounds:
{
from.SendMessage("That item is not inside a customizable house. Try again.");
break;
}
{
from.SendMessage("That item is not inside a customizable house. Try again.");
break;
}
}
from.Target = new DesignInsertTarget(m_Foundations, m_StaticsOnly);
}
}
#endregion
#region Area targeting mode
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
Mobile from = e.Mobile;
@ -165,25 +159,25 @@ namespace Server.Commands.Generic
switch (result)
{
case DesignInsertResult.Valid:
{
AddResponse("The item has been inserted into the house design.");
{
AddResponse("The item has been inserted into the house design.");
if (!foundations.Contains(house))
foundations.Add(house);
if (!foundations.Contains(house))
foundations.Add(house);
break;
}
break;
}
case DesignInsertResult.InvalidItem:
{
LogFailure("That cannot be inserted.");
break;
}
{
LogFailure("That cannot be inserted.");
break;
}
case DesignInsertResult.NotInHouse:
case DesignInsertResult.OutsideHouseBounds:
{
LogFailure("That item is not inside a customizable house.");
break;
}
{
LogFailure("That item is not inside a customizable house.");
break;
}
}
}
@ -197,7 +191,5 @@ namespace Server.Commands.Generic
Flush(from, flushToLog);
}
#endregion
}
}

View file

@ -25,7 +25,6 @@ namespace Server.Commands.Generic
{
List<string> columns = new List<string> { "Object" };
if (e.Length > 0)
{
int offset = 0;
@ -50,13 +49,13 @@ namespace Server.Commands.Generic
{
private const int EntriesPerPage = 15;
private string[] m_Columns;
private Mobile m_From;
private readonly string[] m_Columns;
private readonly Mobile m_From;
private List<object> m_List;
private int m_Page;
private readonly List<object> m_List;
private readonly int m_Page;
private object m_Select;
private readonly object m_Select;
public InterfaceGump(Mobile from, string[] columns, List<object> list, int page, object select) : base(30, 30)
{
@ -197,57 +196,57 @@ namespace Server.Commands.Generic
switch (info.ButtonID)
{
case 1:
{
if (m_Page > 0)
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page - 1, m_Select));
break;
}
case 2:
{
if ((m_Page + 1) * EntriesPerPage < m_List.Count)
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page + 1, m_Select));
break;
}
default:
{
int v = info.ButtonID - 3;
if (v >= 0 && v < m_List.Count)
{
object obj = m_List[v];
if (m_Page > 0)
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page - 1, m_Select));
if (!BaseCommand.IsAccessible(m_From, obj))
break;
}
case 2:
{
if ((m_Page + 1) * EntriesPerPage < m_List.Count)
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page + 1, m_Select));
break;
}
default:
{
int v = info.ButtonID - 3;
if (v >= 0 && v < m_List.Count)
{
m_From.SendLocalizedMessage(500447); // That is not accessible.
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Select));
break;
object obj = m_List[v];
if (!BaseCommand.IsAccessible(m_From, obj))
{
m_From.SendLocalizedMessage(500447); // That is not accessible.
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Select));
break;
}
if (obj is Item item && !item.Deleted)
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, item));
else if (obj is Mobile mobile && !mobile.Deleted)
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, mobile));
else
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Select));
}
if (obj is Item item && !item.Deleted)
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, item));
else if (obj is Mobile mobile && !mobile.Deleted)
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, mobile));
else
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Select));
break;
}
break;
}
}
}
}
public class InterfaceItemGump : BaseGridGump
{
private string[] m_Columns;
private Mobile m_From;
private readonly string[] m_Columns;
private readonly Mobile m_From;
private Item m_Item;
private readonly Item m_Item;
private List<object> m_List;
private int m_Page;
private readonly List<object> m_List;
private readonly int m_Page;
public InterfaceItemGump(Mobile from, string[] columns, List<object> list, int page, Item item) : base(30, 30)
{
@ -318,71 +317,71 @@ namespace Server.Commands.Generic
{
case 0:
case 1:
{
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Item));
break;
}
{
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Item));
break;
}
case 2: // Properties
{
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, m_Item));
m_From.SendGump(new PropertiesGump(m_From, m_Item));
break;
}
case 3: // Delete
{
CommandLogging.WriteLine(m_From, "{0} {1} deleting {2}", m_From.AccessLevel,
CommandLogging.Format(m_From), CommandLogging.Format(m_Item));
m_Item.Delete();
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Item));
break;
}
case 4: // Go there
{
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, m_Item));
InvokeCommand($"Go {m_Item.Serial.Value}");
break;
}
case 5: // Move to target
{
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, m_Item));
m_From.Target = new MoveTarget(m_Item);
break;
}
case 6: // Bring to pack
{
Mobile owner = m_Item.RootParent as Mobile;
if (owner?.Map != null && owner.Map != Map.Internal &&
!BaseCommand.IsAccessible(m_From, owner) /* !m_From.CanSee( owner )*/)
{
m_From.SendMessage("You can not get what you can not see.");
}
else if (owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden &&
owner.AccessLevel >= m_From.AccessLevel)
{
m_From.SendMessage("You can not get what you can not see.");
}
else
{
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, m_Item));
m_From.AddToBackpack(m_Item);
m_From.SendGump(new PropertiesGump(m_From, m_Item));
break;
}
case 3: // Delete
{
CommandLogging.WriteLine(m_From, "{0} {1} deleting {2}", m_From.AccessLevel,
CommandLogging.Format(m_From), CommandLogging.Format(m_Item));
m_Item.Delete();
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Item));
break;
}
case 4: // Go there
{
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, m_Item));
InvokeCommand($"Go {m_Item.Serial.Value}");
break;
}
case 5: // Move to target
{
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, m_Item));
m_From.Target = new MoveTarget(m_Item);
break;
}
case 6: // Bring to pack
{
Mobile owner = m_Item.RootParent as Mobile;
break;
}
if (owner?.Map != null && owner.Map != Map.Internal &&
!BaseCommand.IsAccessible(m_From, owner) /* !m_From.CanSee( owner )*/)
{
m_From.SendMessage("You can not get what you can not see.");
}
else if (owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden &&
owner.AccessLevel >= m_From.AccessLevel)
{
m_From.SendMessage("You can not get what you can not see.");
}
else
{
m_From.SendGump(new InterfaceItemGump(m_From, m_Columns, m_List, m_Page, m_Item));
m_From.AddToBackpack(m_Item);
}
break;
}
}
}
}
public class InterfaceMobileGump : BaseGridGump
{
private string[] m_Columns;
private Mobile m_From;
private readonly string[] m_Columns;
private readonly Mobile m_From;
private List<object> m_List;
private readonly List<object> m_List;
private Mobile m_Mobile;
private int m_Page;
private readonly Mobile m_Mobile;
private readonly int m_Page;
public InterfaceMobileGump(Mobile from, string[] columns, List<object> list, int page, Mobile mob)
: base(30, 30)
@ -482,86 +481,86 @@ namespace Server.Commands.Generic
{
case 0:
case 1:
{
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
break;
}
case 2: // Properties
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
m_From.SendGump(new PropertiesGump(m_From, m_Mobile));
break;
}
case 3: // Delete
{
if (!m_Mobile.Player)
{
CommandLogging.WriteLine(m_From, "{0} {1} deleting {2}", m_From.AccessLevel,
CommandLogging.Format(m_From), CommandLogging.Format(m_Mobile));
m_Mobile.Delete();
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
break;
}
break;
}
case 4: // Go there
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
InvokeCommand($"Go {m_Mobile.Serial.Value}");
break;
}
case 5: // Bring them here
{
if (m_From.Map == null || m_From.Map == Map.Internal)
{
m_From.SendMessage("You cannot bring that person here.");
}
else
case 2: // Properties
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
m_Mobile.MoveToWorld(m_From.Location, m_From.Map);
m_From.SendGump(new PropertiesGump(m_From, m_Mobile));
break;
}
break;
}
case 6: // Move to target
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
m_From.Target = new MoveTarget(m_Mobile);
break;
}
case 7: // Kill
{
if (m_From == m_Mobile || m_From.AccessLevel > m_Mobile.AccessLevel)
m_Mobile.Kill();
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
break;
}
case 8: // Res
{
if (m_From == m_Mobile || m_From.AccessLevel > m_Mobile.AccessLevel)
case 3: // Delete
{
m_Mobile.PlaySound(0x214);
m_Mobile.FixedEffect(0x376A, 10, 16);
if (!m_Mobile.Player)
{
CommandLogging.WriteLine(m_From, "{0} {1} deleting {2}", m_From.AccessLevel,
CommandLogging.Format(m_From), CommandLogging.Format(m_Mobile));
m_Mobile.Delete();
m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
}
m_Mobile.Resurrect();
break;
}
case 4: // Go there
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
InvokeCommand($"Go {m_Mobile.Serial.Value}");
break;
}
case 5: // Bring them here
{
if (m_From.Map == null || m_From.Map == Map.Internal)
{
m_From.SendMessage("You cannot bring that person here.");
}
else
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
m_Mobile.MoveToWorld(m_From.Location, m_From.Map);
}
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
break;
}
case 6: // Move to target
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
m_From.Target = new MoveTarget(m_Mobile);
break;
}
case 7: // Kill
{
if (m_From == m_Mobile || m_From.AccessLevel > m_Mobile.AccessLevel)
m_Mobile.Kill();
break;
}
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
break;
}
case 8: // Res
{
if (m_From == m_Mobile || m_From.AccessLevel > m_Mobile.AccessLevel)
{
m_Mobile.PlaySound(0x214);
m_Mobile.FixedEffect(0x376A, 10, 16);
m_Mobile.Resurrect();
}
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
break;
}
case 9: // Client
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
{
m_From.SendGump(new InterfaceMobileGump(m_From, m_Columns, m_List, m_Page, m_Mobile));
if (m_Mobile.NetState != null)
m_From.SendGump(new ClientGump(m_From, m_Mobile.NetState));
if (m_Mobile.NetState != null)
m_From.SendGump(new ClientGump(m_From, m_Mobile.NetState));
break;
}
break;
}
}
}
}

View file

@ -17,18 +17,18 @@ namespace Server.Commands.Generic
Constructor = constructor;
}
public static Dictionary<string, ExtensionInfo> Table{ get; } =
public static Dictionary<string, ExtensionInfo> Table { get; } =
new Dictionary<string, ExtensionInfo>(StringComparer.InvariantCultureIgnoreCase);
public int Order{ get; }
public int Order { get; }
public string Name{ get; }
public string Name { get; }
public int Size{ get; }
public int Size { get; }
public bool IsFixedSize => Size >= 0;
public ExtensionConstructor Constructor{ get; }
public ExtensionConstructor Constructor { get; }
public static void Register(ExtensionInfo ext)
{
@ -103,7 +103,7 @@ namespace Server.Commands.Generic
public abstract class BaseExtension
{
public abstract ExtensionInfo Info{ get; }
public abstract ExtensionInfo Info { get; }
public string Name => Info.Name;

View file

@ -1,8 +1,8 @@
using Server.Utilities;
using System;
using System.Globalization;
using System.Reflection;
using System.Reflection.Emit;
using Server.Utilities;
namespace Server.Commands.Generic
{
@ -47,11 +47,11 @@ namespace Server.Commands.Generic
Value = value;
}
public Type Type{ get; }
public Type Type { get; }
public object Value{ get; private set; }
public object Value { get; private set; }
public FieldInfo Field{ get; private set; }
public FieldInfo Field { get; private set; }
public bool HasField => Field != null;
@ -119,8 +119,7 @@ namespace Server.Commands.Generic
BindingFlags.Public | BindingFlags.Static,
null,
new[] { typeof(string), typeof(NumberStyles) },
null
);
null);
if (parseNumber != null)
{
@ -142,8 +141,7 @@ namespace Server.Commands.Generic
BindingFlags.Public | BindingFlags.Static,
null,
new[] { typeof(string) },
null
);
null);
parseMethod = parseGeneral;
parseArgs = new object[] { toParse };
@ -158,13 +156,11 @@ namespace Server.Commands.Generic
Field = typeBuilder.DefineField(
fieldName,
Type,
FieldAttributes.Private | FieldAttributes.InitOnly
);
FieldAttributes.Private | FieldAttributes.InitOnly);
// parseMethod.Invoke(null,
// parseMethod.Invoke(null,
// parseArgs.Length == 2 ? new object[] {toParse, (int) parseArgs[1]} : new object[] {toParse});
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldstr, toParse);
@ -179,8 +175,7 @@ namespace Server.Commands.Generic
else
{
throw new InvalidOperationException(
$"Unable to convert string \"{Value}\" into type '{Type}'."
);
$"Unable to convert string \"{Value}\" into type '{Type}'.");
}
}
}
@ -215,9 +210,9 @@ namespace Server.Commands.Generic
public sealed class StringCondition : PropertyCondition
{
private bool m_IgnoreCase;
private StringOperator m_Operator;
private PropertyValue m_Value;
private readonly bool m_IgnoreCase;
private readonly StringOperator m_Operator;
private readonly PropertyValue m_Value;
public StringCondition(Property property, bool not, StringOperator op, object value, bool ignoreCase)
: base(property, not)
@ -280,9 +275,7 @@ namespace Server.Commands.Generic
typeof(string),
typeof(string)
},
null
)
);
null));
emitter.Chain(m_Property);
m_Value.Load(emitter);
@ -319,9 +312,7 @@ namespace Server.Commands.Generic
{
typeof(string)
},
null
)
);
null));
m_Value.Load(emitter);
@ -347,8 +338,8 @@ namespace Server.Commands.Generic
public sealed class ComparisonCondition : PropertyCondition
{
private ComparisonOperator m_Operator;
private PropertyValue m_Value;
private readonly ComparisonOperator m_Operator;
private readonly PropertyValue m_Value;
public ComparisonCondition(Property property, bool not, ComparisonOperator op, object value)
: base(property, not)
@ -369,7 +360,7 @@ namespace Server.Commands.Generic
bool inverse = false;
bool couldCompare =
emitter.CompareTo(1, delegate { m_Value.Load(emitter); });
emitter.CompareTo(1, () => { m_Value.Load(emitter); });
if (couldCompare)
{
@ -449,17 +440,12 @@ namespace Server.Commands.Generic
TypeBuilder typeBuilder = assembly.DefineType(
$"__conditional{index}",
TypeAttributes.Public,
typeof(object)
);
#region Constructor
typeof(object));
{
ConstructorBuilder ctor = typeBuilder.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes
);
Type.EmptyTypes);
ILGenerator il = ctor.GetILGenerator();
@ -474,16 +460,9 @@ namespace Server.Commands.Generic
il.Emit(OpCodes.Ret);
}
#endregion
#region IComparer
typeBuilder.AddInterfaceImplementation(typeof(IConditional));
MethodBuilder compareMethod;
#region Compare
{
MethodEmitter emitter = new MethodEmitter(typeBuilder);
@ -531,17 +510,11 @@ namespace Server.Commands.Generic
new[]
{
typeof(object)
}
)
);
}));
compareMethod = emitter.Method;
}
#endregion
#endregion
Type conditionalType = typeBuilder.CreateType();
return (IConditional)ActivatorUtil.CreateInstance(conditionalType);

View file

@ -1,8 +1,8 @@
using Server.Utilities;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using Server.Utilities;
namespace Server.Commands.Generic
{
@ -13,17 +13,12 @@ namespace Server.Commands.Generic
TypeBuilder typeBuilder = assembly.DefineType(
"__distinct",
TypeAttributes.Public,
typeof(object)
);
#region Constructor
typeof(object));
{
ConstructorBuilder ctor = typeBuilder.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes
);
Type.EmptyTypes);
ILGenerator il = ctor.GetILGenerator();
@ -36,16 +31,9 @@ namespace Server.Commands.Generic
il.Emit(OpCodes.Ret);
}
#endregion
#region IComparer
typeBuilder.AddInterfaceImplementation(typeof(IComparer<T>));
MethodBuilder compareMethod;
#region Compare
{
MethodEmitter emitter = new MethodEmitter(typeBuilder);
@ -78,7 +66,7 @@ namespace Server.Commands.Generic
if (i > 0)
{
emitter.LoadLocal(v);
emitter.BranchIfTrue(end); // if ( v != 0 ) return v;
emitter.BranchIfTrue(end);
}
Property prop = props[i];
@ -87,7 +75,7 @@ namespace Server.Commands.Generic
emitter.Chain(prop);
bool couldCompare =
emitter.CompareTo(1, delegate
emitter.CompareTo(1, () =>
{
emitter.LoadLocal(b);
emitter.Chain(prop);
@ -112,23 +100,12 @@ namespace Server.Commands.Generic
{
typeof(T),
typeof(T)
}
) ?? throw new Exception($"No Compare method found for type {typeof(T).FullName}")
);
}) ?? throw new Exception($"No Compare method found for type {typeof(T).FullName}"));
compareMethod = emitter.Method;
}
#endregion
#endregion
#region IEqualityComparer
typeBuilder.AddInterfaceImplementation(typeof(IEqualityComparer<T>));
#region Equals
{
MethodEmitter emitter = new MethodEmitter(typeBuilder);
@ -158,15 +135,9 @@ namespace Server.Commands.Generic
{
typeof(T),
typeof(T)
}
) ?? throw new Exception($"No Equals method found for type {typeof(T).FullName}")
);
}) ?? throw new Exception($"No Equals method found for type {typeof(T).FullName}"));
}
#endregion
#region GetHashCode
{
MethodEmitter emitter = new MethodEmitter(typeBuilder);
@ -242,15 +213,9 @@ namespace Server.Commands.Generic
new[]
{
typeof(T)
}
) ?? throw new Exception($"No GetHashCode method found for type {typeof(T).FullName}")
);
}) ?? throw new Exception($"No GetHashCode method found for type {typeof(T).FullName}"));
}
#endregion
#endregion
Type comparerType = typeBuilder.CreateType();
return (IComparer<T>)ActivatorUtil.CreateInstance(comparerType);

View file

@ -1,8 +1,8 @@
using Server.Utilities;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using Server.Utilities;
namespace Server.Commands.Generic
{
@ -17,7 +17,7 @@ namespace Server.Commands.Generic
IsAscending = isAscending;
}
public Property Property{ get; set; }
public Property Property { get; set; }
public bool IsAscending
{
@ -51,17 +51,12 @@ namespace Server.Commands.Generic
TypeBuilder typeBuilder = assembly.DefineType(
"__sort",
TypeAttributes.Public,
typeof(T)
);
#region Constructor
typeof(T));
{
ConstructorBuilder ctor = typeBuilder.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes
);
Type.EmptyTypes);
ILGenerator il = ctor.GetILGenerator();
@ -74,13 +69,7 @@ namespace Server.Commands.Generic
il.Emit(OpCodes.Ret);
}
#endregion
#region IComparer
typeBuilder.AddInterfaceImplementation(typeof(IComparer<T>));
#region Compare
{
MethodEmitter emitter = new MethodEmitter(typeBuilder);
@ -113,7 +102,7 @@ namespace Server.Commands.Generic
if (i > 0)
{
emitter.LoadLocal(v);
emitter.BranchIfTrue(end); // if ( v != 0 ) return v;
emitter.BranchIfTrue(end);
}
OrderInfo orderInfo = orders[i];
@ -125,7 +114,7 @@ namespace Server.Commands.Generic
emitter.Chain(prop);
bool couldCompare =
emitter.CompareTo(sign, delegate
emitter.CompareTo(sign, () =>
{
emitter.LoadLocal(b);
emitter.Chain(prop);
@ -150,15 +139,9 @@ namespace Server.Commands.Generic
{
typeof(T),
typeof(T)
}
) ?? throw new Exception($"No Compare method found for type {typeof(T).FullName}")
);
}) ?? throw new Exception($"No Compare method found for type {typeof(T).FullName}"));
}
#endregion
#endregion
Type comparerType = typeBuilder.CreateType();
return (IComparer<T>)ActivatorUtil.CreateInstance(comparerType);
}

View file

@ -10,7 +10,7 @@ namespace Server.Commands.Generic
private IComparer<object> m_Comparer;
private List<Property> m_Properties;
private readonly List<Property> m_Properties;
public DistinctExtension() => m_Properties = new List<Property>();

View file

@ -9,7 +9,7 @@ namespace Server.Commands.Generic
public override ExtensionInfo Info => ExtInfo;
public int Limit{ get; private set; }
public int Limit { get; private set; }
public static void Initialize()
{

View file

@ -9,7 +9,7 @@ namespace Server.Commands.Generic
private IComparer<object> m_Comparer;
private List<OrderInfo> m_Orders;
private readonly List<OrderInfo> m_Orders;
public SortExtension() => m_Orders = new List<OrderInfo>();

View file

@ -8,7 +8,7 @@ namespace Server.Commands.Generic
public override ExtensionInfo Info => ExtInfo;
public ObjectConditional Conditional{ get; private set; }
public ObjectConditional Conditional { get; private set; }
public static void Initialize()
{

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Server.Commands.Generic
{
@ -19,7 +18,7 @@ namespace Server.Commands.Generic
Instance = this;
}
public static AreaCommandImplementor Instance{ get; private set; }
public static AreaCommandImplementor Instance { get; private set; }
public override void Process(Mobile from, BaseCommand command, string[] args)
{
@ -48,7 +47,6 @@ namespace Server.Commands.Generic
if ((!mobiles || obj is Mobile) && BaseCommand.IsAccessible(from, obj) && ext.IsValid(obj))
objs.Add(obj);
eable.Free();
ext.Filter(objs);

View file

@ -32,19 +32,19 @@ namespace Server.Commands.Generic
public BaseCommandImplementor() => Commands = new Dictionary<string, BaseCommand>(StringComparer.OrdinalIgnoreCase);
public bool SupportsConditionals{ get; set; }
public bool SupportsConditionals { get; set; }
public string[] Accessors{ get; set; }
public string[] Accessors { get; set; }
public string Usage{ get; set; }
public string Usage { get; set; }
public string Description{ get; set; }
public string Description { get; set; }
public AccessLevel AccessLevel{ get; set; }
public AccessLevel AccessLevel { get; set; }
public CommandSupport SupportRequirement{ get; set; }
public CommandSupport SupportRequirement { get; set; }
public Dictionary<string, BaseCommand> Commands{ get; }
public Dictionary<string, BaseCommand> Commands { get; }
public static List<BaseCommandImplementor> Implementors
{
@ -110,43 +110,43 @@ namespace Server.Commands.Generic
{
case ObjectTypes.All:
case ObjectTypes.Both:
{
if (condIsItem)
items = true;
{
if (condIsItem)
items = true;
if (condIsMobile)
mobiles = true;
if (condIsMobile)
mobiles = true;
break;
}
break;
}
case ObjectTypes.Items:
{
if (condIsItem)
{
items = true;
}
else if (condIsMobile)
{
from.SendMessage("You may not use a mobile type condition for this command.");
return false;
}
if (condIsItem)
{
items = true;
}
else if (condIsMobile)
{
from.SendMessage("You may not use a mobile type condition for this command.");
return false;
}
break;
}
break;
}
case ObjectTypes.Mobiles:
{
if (condIsMobile)
{
mobiles = true;
}
else if (condIsItem)
{
from.SendMessage("You may not use an item type condition for this command.");
return false;
}
if (condIsMobile)
{
mobiles = true;
}
else if (condIsItem)
{
from.SendMessage("You may not use an item type condition for this command.");
return false;
}
break;
}
break;
}
}
return true;
@ -199,8 +199,8 @@ namespace Server.Commands.Generic
public void RunCommand(Mobile from, object obj, BaseCommand command, string[] args)
{
// try
// {
// try
// {
CommandEventArgs e = new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args);
if (!command.ValidateArgs(this, e))
@ -226,17 +226,17 @@ namespace Server.Commands.Generic
else if (obj != null)
{
if (command.ListOptimized)
command.ExecuteList(e, new List<object>{ obj });
command.ExecuteList(e, new List<object> { obj });
else
command.Execute(e, obj);
}
command.Flush(from, flushToLog);
// }
// catch ( Exception ex )
// {
// from.SendMessage( ex.Message );
// }
// }
// catch ( Exception ex )
// {
// from.SendMessage( ex.Message );
// }
}
public virtual void Process(Mobile from, BaseCommand command, string[] args)

View file

@ -40,7 +40,7 @@ namespace Server.Commands.Generic
from.SendMessage("That is not a container.");
return;
}
try
{
Extensions ext = Extensions.Parse(from, ref args);

View file

@ -33,35 +33,35 @@ namespace Server.Commands.Generic
switch (command.ObjectTypes)
{
case ObjectTypes.Both:
{
if (!(targeted is Item || targeted is Mobile))
{
from.SendMessage("This command does not work on that.");
return;
}
if (!(targeted is Item || targeted is Mobile))
{
from.SendMessage("This command does not work on that.");
return;
}
break;
}
break;
}
case ObjectTypes.Items:
{
if (!(targeted is Item))
{
from.SendMessage("This command only works on items.");
return;
}
if (!(targeted is Item))
{
from.SendMessage("This command only works on items.");
return;
}
break;
}
break;
}
case ObjectTypes.Mobiles:
{
if (!(targeted is Mobile))
{
from.SendMessage("This command only works on mobiles.");
return;
}
if (!(targeted is Mobile))
{
from.SendMessage("This command only works on mobiles.");
return;
}
break;
}
break;
}
}
RunCommand(from, targeted, command, args);

View file

@ -12,7 +12,7 @@ namespace Server.Commands.Generic
private IConditional[] m_Conditionals;
private ICondition[][] m_Conditions;
private readonly ICondition[][] m_Conditions;
public ObjectConditional(Type objectType, ICondition[][] conditions)
{
@ -20,7 +20,7 @@ namespace Server.Commands.Generic
m_Conditions = conditions;
}
public Type Type{ get; }
public Type Type { get; }
public bool IsItem => Type == null || Type == typeofItem || Type.IsSubclassOf(typeofItem);

View file

@ -15,7 +15,7 @@ namespace Server.Commands.Generic
Instance = this;
}
public static RangeCommandImplementor Instance{ get; private set; }
public static RangeCommandImplementor Instance { get; private set; }
public override void Execute(CommandEventArgs e)
{

View file

@ -46,25 +46,25 @@ namespace Server.Commands.Generic
switch (command.ObjectTypes)
{
case ObjectTypes.Items:
{
if (!(obj is Item))
{
e.Mobile.SendMessage("This command only works on items.");
return;
}
if (!(obj is Item))
{
e.Mobile.SendMessage("This command only works on items.");
return;
}
break;
}
break;
}
case ObjectTypes.Mobiles:
{
if (!(obj is Mobile))
{
e.Mobile.SendMessage("This command only works on mobiles.");
return;
}
if (!(obj is Mobile))
{
e.Mobile.SendMessage("This command only works on mobiles.");
return;
}
break;
}
break;
}
}
string[] oldArgs = e.Arguments;

View file

@ -52,35 +52,35 @@ namespace Server.Commands.Generic
switch (command.ObjectTypes)
{
case ObjectTypes.Both:
{
if (!(targeted is Item) && !(targeted is Mobile))
{
from.SendMessage("This command does not work on that.");
return;
}
if (!(targeted is Item) && !(targeted is Mobile))
{
from.SendMessage("This command does not work on that.");
return;
}
break;
}
break;
}
case ObjectTypes.Items:
{
if (!(targeted is Item))
{
from.SendMessage("This command only works on items.");
return;
}
if (!(targeted is Item))
{
from.SendMessage("This command only works on items.");
return;
}
break;
}
break;
}
case ObjectTypes.Mobiles:
{
if (!(targeted is Mobile))
{
from.SendMessage("This command only works on mobiles.");
return;
}
if (!(targeted is Mobile))
{
from.SendMessage("This command only works on mobiles.");
return;
}
break;
}
break;
}
}
RunCommand(from, targeted, command, args);