From dd2933a9ef8a4baf2b3731010a3505fc25f4a037 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Wed, 14 Apr 2021 22:58:56 -0700 Subject: [PATCH] fix(cleanup): Consolidate the duplicate code in Properties, PropsGump, and PropsConfig (#540) --- .../Generic/Implementors/ObjectConditional.cs | 9 +- .../UOContent/Commands/Object Creation/Add.cs | 75 +------- .../Object Creation/CategorizedAddGump.cs | 51 +----- Projects/UOContent/Commands/Properties.cs | 166 +----------------- .../UOContent/Engines/Spawners/BaseSpawner.cs | 8 +- .../Engines/Spawners/EditSpawnCommand.cs | 5 +- .../Engines/Spawners/SpawnPropsCommand.cs | 10 +- Projects/UOContent/Gumps/Go/GoGump.cs | 42 +---- Projects/UOContent/Gumps/Props/Exceptions.cs | 109 ++++++++++++ Projects/UOContent/Gumps/Props/PropsConfig.cs | 3 + Projects/UOContent/Gumps/Props/PropsGump.cs | 145 +++------------ Projects/UOContent/Gumps/Props/SetGump.cs | 36 +--- .../Gumps/Props/SetListOptionGump.cs | 36 +--- .../UOContent/Gumps/Props/SetObjectGump.cs | 36 +--- .../UOContent/Gumps/Props/SetPoint2DGump.cs | 36 +--- .../UOContent/Gumps/Props/SetPoint3DGump.cs | 37 +--- .../UOContent/Gumps/Props/SetTimeSpanGump.cs | 36 +--- Projects/UOContent/Gumps/SkillsGump.cs | 77 +------- Projects/UOContent/Gumps/WhoGump.cs | 42 +---- .../UOContent/Utilities/TypeAttributes.cs | 30 ++++ Projects/UOContent/Utilities/Types.cs | 107 +++++++++++ 21 files changed, 335 insertions(+), 761 deletions(-) create mode 100644 Projects/UOContent/Gumps/Props/Exceptions.cs create mode 100644 Projects/UOContent/Utilities/TypeAttributes.cs create mode 100644 Projects/UOContent/Utilities/Types.cs diff --git a/Projects/UOContent/Commands/Generic/Implementors/ObjectConditional.cs b/Projects/UOContent/Commands/Generic/Implementors/ObjectConditional.cs index 9778da75b..acf79a09a 100644 --- a/Projects/UOContent/Commands/Generic/Implementors/ObjectConditional.cs +++ b/Projects/UOContent/Commands/Generic/Implementors/ObjectConditional.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; +using static Server.Types; + namespace Server.Commands.Generic { public sealed class ObjectConditional { - private static readonly Type typeofItem = typeof(Item); - private static readonly Type typeofMobile = typeof(Mobile); - public static readonly ObjectConditional Empty = new(null, null); private readonly ICondition[][] m_Conditions; @@ -22,9 +21,9 @@ namespace Server.Commands.Generic public Type Type { get; } - public bool IsItem => Type == null || Type == typeofItem || Type.IsSubclassOf(typeofItem); + public bool IsItem => Type == null || Type.IsAssignableTo(OfItem); - public bool IsMobile => Type == null || Type == typeofMobile || Type.IsSubclassOf(typeofMobile); + public bool IsMobile => Type == null || Type.IsAssignableTo(OfMobile); public bool HasCompiled => m_Conditionals != null; diff --git a/Projects/UOContent/Commands/Object Creation/Add.cs b/Projects/UOContent/Commands/Object Creation/Add.cs index e844015cf..59c091698 100644 --- a/Projects/UOContent/Commands/Object Creation/Add.cs +++ b/Projects/UOContent/Commands/Object Creation/Add.cs @@ -6,39 +6,15 @@ using System.Text; using Server.Items; using CPA = Server.CommandPropertyAttribute; +using static Server.Attributes; +using static Server.Types; + namespace Server.Commands { public static class Add { - private static readonly Type m_EntityType = typeof(IEntity); - - private static readonly Type m_ConstructibleType = typeof(ConstructibleAttribute); - - private static readonly Type m_EnumType = typeof(Enum); - - private static readonly Type m_TypeType = typeof(Type); - - private static readonly Type m_ParsableType = typeof(ParsableAttribute); - - private static readonly Type[] m_ParseTypes = { typeof(string) }; private static readonly object[] m_ParseArgs = new object[1]; - private static readonly Type[] m_SignedNumerics = - { - typeof(long), - typeof(int), - typeof(short), - typeof(sbyte) - }; - - private static readonly Type[] m_UnsignedNumerics = - { - typeof(ulong), - typeof(uint), - typeof(ushort), - typeof(byte) - }; - public static void Initialize() { CommandSystem.Register("Tile", AccessLevel.GameMaster, Tile_OnCommand); @@ -193,7 +169,7 @@ namespace Server.Commands } else { - var attr = Properties.GetCPA(thisProp); + var attr = GetCPA(thisProp); if (attr == null) { @@ -759,56 +735,21 @@ namespace Server.Commands InternalAvg_OnCommand(e, true); } - public static bool IsEntity(Type t) => m_EntityType.IsAssignableFrom(t); + public static bool IsEnum(Type type) => type.IsSubclassOf(OfEnum); - public static bool IsConstructible(ConstructorInfo ctor, AccessLevel accessLevel) - { - var attrs = ctor.GetCustomAttributes(m_ConstructibleType, false); + public static bool IsType(Type type) => type == OfType || type.IsSubclassOf(OfType); - return attrs.Length != 0 && accessLevel >= ((ConstructibleAttribute)attrs[0]).AccessLevel; - } - - public static bool IsEnum(Type type) => type.IsSubclassOf(m_EnumType); - - public static bool IsType(Type type) => type == m_TypeType || type.IsSubclassOf(m_TypeType); - - public static bool IsParsable(Type type) => type.IsDefined(m_ParsableType, false); + public static bool IsParsable(Type type) => type.IsDefined(OfParsable, false); public static object ParseParsable(Type type, string value) { - var method = type.GetMethod("Parse", m_ParseTypes); + var method = type.GetMethod("Parse", ParseTypes); m_ParseArgs[0] = value; return method?.Invoke(null, m_ParseArgs); } - public static bool IsSignedNumeric(Type type) - { - for (var i = 0; i < m_SignedNumerics.Length; ++i) - { - if (type == m_SignedNumerics[i]) - { - return true; - } - } - - return false; - } - - public static bool IsUnsignedNumeric(Type type) - { - for (var i = 0; i < m_UnsignedNumerics.Length; ++i) - { - if (type == m_UnsignedNumerics[i]) - { - return true; - } - } - - return false; - } - private enum TileZType { Start, diff --git a/Projects/UOContent/Commands/Object Creation/CategorizedAddGump.cs b/Projects/UOContent/Commands/Object Creation/CategorizedAddGump.cs index 6383fa5bf..6234169fb 100644 --- a/Projects/UOContent/Commands/Object Creation/CategorizedAddGump.cs +++ b/Projects/UOContent/Commands/Object Creation/CategorizedAddGump.cs @@ -2,55 +2,19 @@ using System; using Server.Commands; using Server.Network; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class CategorizedAddGump : Gump { - public static bool OldStyle = PropsConfig.OldStyle; + private static readonly int EntryHeight = PropsConfig.EntryHeight + 4; - public static readonly int EntryHeight = 24; // PropsConfig.EntryHeight; + private static readonly int SetOffsetY = PropsConfig.SetOffsetY + (EntryHeight - 20) / 2 / 2; - public static readonly int OffsetSize = PropsConfig.OffsetSize; - public static readonly int BorderSize = PropsConfig.BorderSize; + private static readonly int PrevOffsetY = PropsConfig.PrevOffsetY + (EntryHeight - 20) / 2 / 2; - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, - SetOffsetY = PropsConfig.SetOffsetY + (EntryHeight - 20) / 2 / 2; - - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, - PrevOffsetY = PropsConfig.PrevOffsetY + (EntryHeight - 20) / 2 / 2; - - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, - NextOffsetY = PropsConfig.NextOffsetY + (EntryHeight - 20) / 2 / 2; - - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - private static readonly bool PrevLabel = false; - private static readonly bool NextLabel = false; + private static readonly int NextOffsetY = PropsConfig.NextOffsetY + (EntryHeight - 20) / 2 / 2; private static readonly int PrevLabelOffsetX = PrevWidth + 1; private static readonly int PrevLabelOffsetY = 0; @@ -62,10 +26,9 @@ namespace Server.Gumps private static readonly int EntryCount = 15; private static readonly int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize; - private static readonly int TotalHeight = OffsetSize + (EntryHeight + OffsetSize) * (EntryCount + 1); private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; - private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; + private readonly CAGCategory m_Category; private readonly Mobile m_Owner; diff --git a/Projects/UOContent/Commands/Properties.cs b/Projects/UOContent/Commands/Properties.cs index 187cba09a..5fc33d304 100644 --- a/Projects/UOContent/Commands/Properties.cs +++ b/Projects/UOContent/Commands/Properties.cs @@ -6,6 +6,9 @@ using Server.Gumps; using Server.Targeting; using CPA = Server.CommandPropertyAttribute; +using static Server.Attributes; +using static Server.Types; + namespace Server.Commands { [Flags] @@ -18,32 +21,8 @@ namespace Server.Commands public static class Properties { - private static readonly Type typeofCPA = typeof(CPA); - - private static readonly Type typeofSerial = typeof(Serial); - - private static readonly Type typeofType = typeof(Type); - - private static readonly Type typeofChar = typeof(char); - - private static readonly Type typeofString = typeof(string); - - private static readonly Type typeofText = typeof(TextDefinition); - - private static readonly Type typeofTimeSpan = typeof(TimeSpan); - private static readonly Type typeofParsable = typeof(ParsableAttribute); - - private static readonly Type[] m_ParseTypes = { typeof(string) }; private static readonly object[] m_ParseParams = new object[1]; - private static readonly Type[] m_NumericTypes = - { - typeof(byte), typeof(sbyte), - typeof(short), typeof(ushort), - typeof(int), typeof(uint), - typeof(long), typeof(ulong) - }; - public static void Initialize() { CommandSystem.Register("Props", AccessLevel.Counselor, Props_OnCommand); @@ -78,18 +57,6 @@ namespace Server.Commands private static bool CIEqual(string l, string r) => l.InsensitiveEquals(r); - public static CPA GetCPA(PropertyInfo p) - { - var attrs = p.GetCustomAttributes(typeofCPA, false); - - if (attrs.Length == 0) - { - return null; - } - - return attrs[0] as CPA; - } - public static PropertyInfo[] GetPropertyInfoChain( Mobile from, Type type, string propertyString, PropertyAccess endAccess, ref string failReason @@ -401,31 +368,15 @@ namespace Server.Commands return p == null ? failReason : InternalSetValue(from, logObject, o, p, name, value, true); } - private static bool IsSerial(Type t) => t == typeofSerial; - - private static bool IsType(Type t) => t == typeofType; - - private static bool IsChar(Type t) => t == typeofChar; - - private static bool IsString(Type t) => t == typeofString; - - private static bool IsText(Type t) => t == typeofText; - - private static bool IsEnum(Type t) => t.IsEnum; - - private static bool IsParsable(Type t) => t == typeofTimeSpan || t.IsDefined(typeofParsable, false); - private static object Parse(object o, Type t, string value) { - var method = t.GetMethod("Parse", m_ParseTypes); + var method = t.GetMethod("Parse", ParseTypes); m_ParseParams[0] = value; return method?.Invoke(o, m_ParseParams); } - private static bool IsNumeric(Type t) => Array.IndexOf(m_NumericTypes, t) >= 0; - public static string ConstructFromString(Type type, object obj, string value, ref object constructed) { object toSet; @@ -433,7 +384,7 @@ namespace Server.Commands if (isSerial) // mutate into int32 { - type = m_NumericTypes[4]; + type = OfInt; } if (value == "(-null-)" && !type.IsValueType) @@ -621,111 +572,6 @@ namespace Server.Commands namespace Server { - public abstract class PropertyException : Exception - { - protected Property m_Property; - - public PropertyException(Property property, string message) - : base(message) => - m_Property = property; - - public Property Property => m_Property; - } - - public abstract class BindingException : PropertyException - { - public BindingException(Property property, string message) - : base(property, message) - { - } - } - - public sealed class NotYetBoundException : BindingException - { - public NotYetBoundException(Property property) - : base(property, "Property has not yet been bound.") - { - } - } - - public sealed class AlreadyBoundException : BindingException - { - public AlreadyBoundException(Property property) - : base(property, "Property has already been bound.") - { - } - } - - public sealed class UnknownPropertyException : BindingException - { - public UnknownPropertyException(Property property, string current) - : base(property, $"Property '{current}' not found.") - { - } - } - - public sealed class ReadOnlyException : BindingException - { - public ReadOnlyException(Property property) - : base(property, "Property is read-only.") - { - } - } - - public sealed class WriteOnlyException : BindingException - { - public WriteOnlyException(Property property) - : base(property, "Property is write-only.") - { - } - } - - public abstract class AccessException : PropertyException - { - public AccessException(Property property, string message) - : base(property, message) - { - } - } - - public sealed class InternalAccessException : AccessException - { - public InternalAccessException(Property property) - : base(property, "Property is internal.") - { - } - } - - public abstract class ClearanceException : AccessException - { - public ClearanceException(Property property, AccessLevel playerAccess, AccessLevel neededAccess, string accessType) - : base( - property, - $"You must be at least {Mobile.GetAccessLevelName(neededAccess)} to {accessType} this property." - ) - { - } - - public AccessLevel PlayerAccess { get; set; } - public AccessLevel NeededAccess { get; set; } - } - - public sealed class ReadAccessException : ClearanceException - { - public ReadAccessException(Property property, AccessLevel playerAccess, AccessLevel neededAccess) - : base(property, playerAccess, neededAccess, "read") - { - } - } - - public sealed class WriteAccessException : ClearanceException - { - public WriteAccessException(Property property, AccessLevel playerAccess, AccessLevel neededAccess) - : base(property, playerAccess, neededAccess, "write") - { - } - } - public sealed class Property { private PropertyInfo[] m_Chain; @@ -788,7 +634,7 @@ namespace Server access |= PropertyAccess.Read; } - var security = Properties.GetCPA(prop); + var security = GetCPA(prop); if (security == null) { diff --git a/Projects/UOContent/Engines/Spawners/BaseSpawner.cs b/Projects/UOContent/Engines/Spawners/BaseSpawner.cs index 37801d92c..4917f04ca 100644 --- a/Projects/UOContent/Engines/Spawners/BaseSpawner.cs +++ b/Projects/UOContent/Engines/Spawners/BaseSpawner.cs @@ -10,6 +10,8 @@ using Server.Mobiles; using Server.Utilities; using CPA = Server.CommandPropertyAttribute; +using static Server.Attributes; + namespace Server.Engines.Spawners { public abstract class BaseSpawner : Item, ISpawner @@ -529,7 +531,7 @@ namespace Server.Engines.Spawners return null; } - var attr = Properties.GetCPA(thisProp); + var attr = GetCPA(thisProp); if (attr == null || attr.WriteLevel > AccessLevel.Developer || !thisProp.CanWrite || attr.ReadOnly) { @@ -600,7 +602,7 @@ namespace Server.Engines.Spawners if (paramargs.Length == 0) { entity = type.CreateInstance( - ci => Add.IsConstructible(ci, AccessLevel.Developer) + ci => IsConstructible(ci, AccessLevel.Developer) ); } else @@ -611,7 +613,7 @@ namespace Server.Engines.Spawners { var ctor = ctors[i]; - if (Add.IsConstructible(ctor, AccessLevel.Developer)) + if (IsConstructible(ctor, AccessLevel.Developer)) { var paramList = ctor.GetParameters(); diff --git a/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs b/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs index 4f78f053d..5a0c9e620 100644 --- a/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs +++ b/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs @@ -15,10 +15,11 @@ using System; using System.Collections.Generic; -using Server.Commands; using Server.Commands.Generic; using Server.Network; +using static Server.Types; + namespace Server.Engines.Spawners { public class EditSpawnCommand : BaseCommand @@ -59,7 +60,7 @@ namespace Server.Engines.Spawners var type = AssemblyHandler.FindTypeByName(name); - if (!Add.IsEntity(type)) + if (!IsEntity(type)) { LogFailure("No type with that name was found."); return; diff --git a/Projects/UOContent/Engines/Spawners/SpawnPropsCommand.cs b/Projects/UOContent/Engines/Spawners/SpawnPropsCommand.cs index 1f3c0200a..76076d6a8 100644 --- a/Projects/UOContent/Engines/Spawners/SpawnPropsCommand.cs +++ b/Projects/UOContent/Engines/Spawners/SpawnPropsCommand.cs @@ -14,11 +14,12 @@ *************************************************************************/ using System.Collections.Generic; -using Server.Commands; using Server.Commands.Generic; using Server.Gumps; using Server.Targeting; +using static Server.Types; + namespace Server.Engines.Spawners { public class SpawnPropsCommand : BaseCommand @@ -53,15 +54,14 @@ namespace Server.Engines.Spawners private class InternalTarget : Target { - private List _list; + private readonly List _list; - public InternalTarget(List list) : base(-1, false, TargetFlags.None) => - _list = list; + public InternalTarget(List list) : base(-1, false, TargetFlags.None) => _list = list; protected override void OnTarget(Mobile from, object targeted) { var type = targeted.GetType(); - if (!Add.IsEntity(type)) + if (!IsEntity(type)) { from.SendMessage("No type with that name was found."); } diff --git a/Projects/UOContent/Gumps/Go/GoGump.cs b/Projects/UOContent/Gumps/Go/GoGump.cs index 2cdf41f5d..61db1a9e9 100644 --- a/Projects/UOContent/Gumps/Go/GoGump.cs +++ b/Projects/UOContent/Gumps/Go/GoGump.cs @@ -1,6 +1,8 @@ using System; using Server.Network; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class GoGump : Gump @@ -12,43 +14,6 @@ namespace Server.Gumps private static LocationTree Tokuno; private static LocationTree TerMur; - public static bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - - private static readonly bool PrevLabel = false; - private static readonly bool NextLabel = false; - private static readonly int PrevLabelOffsetX = PrevWidth + 1; private static readonly int PrevLabelOffsetY = 0; @@ -59,10 +24,9 @@ namespace Server.Gumps private static readonly int EntryCount = 15; private static readonly int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize; - private static readonly int TotalHeight = OffsetSize + (EntryHeight + OffsetSize) * (EntryCount + 1); private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; - private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; + private readonly GoCategory m_Node; private readonly int m_Page; diff --git a/Projects/UOContent/Gumps/Props/Exceptions.cs b/Projects/UOContent/Gumps/Props/Exceptions.cs new file mode 100644 index 000000000..d1eccab10 --- /dev/null +++ b/Projects/UOContent/Gumps/Props/Exceptions.cs @@ -0,0 +1,109 @@ +using System; + +namespace Server.Gumps +{ + public abstract class PropertyException : Exception + { + protected Property m_Property; + + public PropertyException(Property property, string message) + : base(message) => + m_Property = property; + + public Property Property => m_Property; + } + + public abstract class BindingException : PropertyException + { + public BindingException(Property property, string message) + : base(property, message) + { + } + } + + public sealed class NotYetBoundException : BindingException + { + public NotYetBoundException(Property property) + : base(property, "Property has not yet been bound.") + { + } + } + + public sealed class AlreadyBoundException : BindingException + { + public AlreadyBoundException(Property property) + : base(property, "Property has already been bound.") + { + } + } + + public sealed class UnknownPropertyException : BindingException + { + public UnknownPropertyException(Property property, string current) + : base(property, $"Property '{current}' not found.") + { + } + } + + public sealed class ReadOnlyException : BindingException + { + public ReadOnlyException(Property property) + : base(property, "Property is read-only.") + { + } + } + + public sealed class WriteOnlyException : BindingException + { + public WriteOnlyException(Property property) + : base(property, "Property is write-only.") + { + } + } + + public abstract class AccessException : PropertyException + { + public AccessException(Property property, string message) + : base(property, message) + { + } + } + + public sealed class InternalAccessException : AccessException + { + public InternalAccessException(Property property) + : base(property, "Property is internal.") + { + } + } + + public abstract class ClearanceException : AccessException + { + public ClearanceException(Property property, AccessLevel playerAccess, AccessLevel neededAccess, string accessType) + : base( + property, + $"You must be at least {Mobile.GetAccessLevelName(neededAccess)} to {accessType} this property." + ) + { + } + + public AccessLevel PlayerAccess { get; set; } + public AccessLevel NeededAccess { get; set; } + } + + public sealed class ReadAccessException : ClearanceException + { + public ReadAccessException(Property property, AccessLevel playerAccess, AccessLevel neededAccess) + : base(property, playerAccess, neededAccess, "read") + { + } + } + + public sealed class WriteAccessException : ClearanceException + { + public WriteAccessException(Property property, AccessLevel playerAccess, AccessLevel neededAccess) + : base(property, playerAccess, neededAccess, "write") + { + } + } +} diff --git a/Projects/UOContent/Gumps/Props/PropsConfig.cs b/Projects/UOContent/Gumps/Props/PropsConfig.cs index bf1cdad0e..e0a2ec815 100644 --- a/Projects/UOContent/Gumps/Props/PropsConfig.cs +++ b/Projects/UOContent/Gumps/Props/PropsConfig.cs @@ -39,5 +39,8 @@ namespace Server.Gumps public static readonly int EntryHeight = 20; public static readonly int BorderSize = 10; public static readonly int ApplySize = 30; + + public static readonly bool PrevLabel = false; + public static readonly bool NextLabel = false; } } diff --git a/Projects/UOContent/Gumps/Props/PropsGump.cs b/Projects/UOContent/Gumps/Props/PropsGump.cs index 83ded0010..5a1b327b0 100644 --- a/Projects/UOContent/Gumps/Props/PropsGump.cs +++ b/Projects/UOContent/Gumps/Props/PropsGump.cs @@ -6,6 +6,10 @@ using Server.Commands.Generic; using Server.Network; using CPA = Server.CommandPropertyAttribute; +using static Server.Types; +using static Server.Attributes; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class StackEntry @@ -22,40 +26,6 @@ namespace Server.Gumps public class PropertiesGump : Gump { - public static readonly bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - private static readonly bool PrevLabel = OldStyle; private static readonly bool NextLabel = OldStyle; private static readonly bool TypeLabel = !OldStyle; @@ -76,56 +46,7 @@ namespace Server.Gumps private static readonly int TotalWidth = OffsetSize + NameWidth + OffsetSize + ValueWidth + OffsetSize + SetWidth + OffsetSize; - private static readonly int MaxHeight = OffsetSize + (EntryHeight + OffsetSize) * (MaxEntriesPerPage + 1); - protected static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; - protected static readonly int BackHeight = BorderSize + MaxHeight + BorderSize; - - public static readonly string[] BoolNames = { "True", "False" }; - public static readonly object[] BoolValues = { true, false }; - - public static readonly string[] PoisonNames = { "None", "Lesser", "Regular", "Greater", "Deadly", "Lethal" }; - - public static readonly object[] PoisonValues = - { null, Poison.Lesser, Poison.Regular, Poison.Greater, Poison.Deadly, Poison.Lethal }; - - public static readonly Type TypeofMobile = typeof(Mobile); - public static readonly Type TypeofItem = typeof(Item); - public static readonly Type TypeofType = typeof(Type); - public static readonly Type TypeofPoint3D = typeof(Point3D); - public static readonly Type TypeofPoint2D = typeof(Point2D); - public static readonly Type TypeofTimeSpan = typeof(TimeSpan); - public static readonly Type TypeofCustomEnum = typeof(CustomEnumAttribute); - public static readonly Type TypeofEnum = typeof(Enum); - public static readonly Type TypeofBool = typeof(bool); - public static readonly Type TypeofString = typeof(string); - public static readonly Type TypeofText = typeof(TextDefinition); - public static readonly Type TypeofPoison = typeof(Poison); - public static readonly Type TypeofMap = typeof(Map); - public static readonly Type TypeofSkills = typeof(Skills); - public static readonly Type TypeofPropertyObject = typeof(PropertyObjectAttribute); - public static readonly Type TypeofNoSort = typeof(NoSortAttribute); - - public static readonly Type[] DecimalTypes = - { - typeof(float), - typeof(double) - }; - - public static readonly Type[] NumericTypes = - { - typeof(byte), - typeof(short), - typeof(int), - typeof(long), - typeof(sbyte), - typeof(ushort), - typeof(uint), - typeof(ulong) - }; - - private static readonly Type TypeofCPA = typeof(CPA); - private static readonly Type TypeofObject = typeof(object); protected readonly List m_List; protected readonly Mobile m_Mobile; @@ -383,23 +304,23 @@ namespace Server.Gumps var type = prop.PropertyType; - if (IsType(type, TypeofMobile) || IsType(type, TypeofItem)) + if (IsType(type, OfMobile) || IsType(type, OfItem)) { from.SendGump(new SetObjectGump(prop, from, m_Object, type, this)); } - else if (IsType(type, TypeofType)) + else if (IsType(type, OfType)) { from.Target = new SetObjectTarget(prop, from, m_Object, type, this); } - else if (IsType(type, TypeofPoint3D)) + else if (IsType(type, OfPoint3D)) { from.SendGump(new SetPoint3DGump(prop, from, m_Object, this)); } - else if (IsType(type, TypeofPoint2D)) + else if (IsType(type, OfPoint2D)) { from.SendGump(new SetPoint2DGump(prop, from, m_Object, this)); } - else if (IsType(type, TypeofTimeSpan)) + else if (IsType(type, OfTimeSpan)) { from.SendGump(new SetTimeSpanGump(prop, from, m_Object, this)); } @@ -415,7 +336,7 @@ namespace Server.Gumps ) ); } - else if (IsType(type, TypeofEnum)) + else if (IsType(type, OfEnum)) { from.SendGump( new SetListOptionGump( @@ -428,7 +349,7 @@ namespace Server.Gumps ) ); } - else if (IsType(type, TypeofBool)) + else if (IsType(type, OfBool)) { from.SendGump( new SetListOptionGump( @@ -441,13 +362,13 @@ namespace Server.Gumps ) ); } - else if (IsType(type, TypeofString) || IsType(type, DecimalTypes) || + else if (IsType(type, OfString) || IsType(type, DecimalTypes) || IsType(type, NumericTypes) || - IsType(type, TypeofText)) + IsType(type, OfText)) { from.SendGump(new SetGump(prop, from, m_Object, this)); } - else if (IsType(type, TypeofPoison)) + else if (IsType(type, OfPoison)) { from.SendGump( new SetListOptionGump( @@ -460,7 +381,7 @@ namespace Server.Gumps ) ); } - else if (IsType(type, TypeofMap)) + else if (IsType(type, OfMap)) { from.SendGump( new SetListOptionGump( @@ -473,12 +394,12 @@ namespace Server.Gumps ) ); } - else if (IsType(type, TypeofSkills) && m_Object is Mobile mobile) + else if (IsType(type, OfSkills) && m_Object is Mobile mobile) { from.SendGump(new PropertiesGump(from, mobile, m_Stack, m_List, m_Page)); from.SendGump(new SkillsGump(from, mobile)); } - else if (HasAttribute(type, TypeofPropertyObject, true)) + else if (HasAttribute(type, OfPropertyObject, true)) { var obj = prop.GetValue(m_Object, null); @@ -512,7 +433,7 @@ namespace Server.Gumps return list; } - private static bool IsCustomEnum(Type type) => type.IsDefined(TypeofCustomEnum, false); + private static bool IsCustomEnum(Type type) => type.IsDefined(OfCustomEnum, false); public void OnValueChanged(object obj, PropertyInfo prop) { @@ -536,7 +457,7 @@ namespace Server.Gumps private static string[] GetCustomEnumNames(Type type) { - var attrs = type.GetCustomAttributes(TypeofCustomEnum, false); + var attrs = type.GetCustomAttributes(OfCustomEnum, false); if (attrs.Length == 0) { @@ -551,12 +472,12 @@ namespace Server.Gumps return ce.Names; } - public static bool HasAttribute(Type type, Type check, bool inherit) => + private static bool HasAttribute(Type type, Type check, bool inherit) => type.GetCustomAttributes(check, inherit).Length > 0; - public static bool IsType(Type type, Type check) => type == check || type.IsSubclassOf(check); + private static bool IsType(Type type, Type check) => type == check || type.IsSubclassOf(check); - public static bool IsType(Type type, Type[] check) + private static bool IsType(Type type, Type[] check) { for (var i = 0; i < check.Length; ++i) { @@ -569,7 +490,7 @@ namespace Server.Gumps return false; } - public string ValueToString(PropertyInfo prop) => ValueToString(m_Object, prop); + private string ValueToString(PropertyInfo prop) => ValueToString(m_Object, prop); public static string ValueToString(object obj, PropertyInfo prop) { @@ -583,7 +504,7 @@ namespace Server.Gumps } } - public static string ValueToString(object o) + private static string ValueToString(object o) { if (o == null) { @@ -668,7 +589,7 @@ namespace Server.Gumps { var kvp = groups[i]; - if (!HasAttribute(kvp.Key, TypeofNoSort, false)) + if (!HasAttribute(kvp.Key, OfNoSort, false)) { kvp.Value.Sort(PropertySorter.Instance); } @@ -694,18 +615,6 @@ namespace Server.Gumps protected virtual bool ShowAttribute(string name) => true; - public static CPA GetCPA(PropertyInfo prop) - { - var attrs = prop.GetCustomAttributes(TypeofCPA, false); - - if (attrs.Length > 0) - { - return attrs[0] as CPA; - } - - return null; - } - private List>> GetGroups(Type objectType, PropertyInfo[] props) { var groups = new Dictionary>(); @@ -726,7 +635,7 @@ namespace Server.Gumps { var baseType = type?.BaseType; - if (baseType == TypeofObject || baseType?.GetProperty(prop.Name, prop.PropertyType) == null) + if (baseType == OfObject || baseType?.GetProperty(prop.Name, prop.PropertyType) == null) { break; } @@ -895,7 +804,7 @@ namespace Server.Gumps int dist; - for (dist = 0; current != null && current != TypeofObject && current != type; ++dist) + for (dist = 0; current != null && current != OfObject && current != type; ++dist) { current = current.BaseType; } diff --git a/Projects/UOContent/Gumps/Props/SetGump.cs b/Projects/UOContent/Gumps/Props/SetGump.cs index 15501de37..3a2e98172 100644 --- a/Projects/UOContent/Gumps/Props/SetGump.cs +++ b/Projects/UOContent/Gumps/Props/SetGump.cs @@ -3,44 +3,12 @@ using Server.Commands; using Server.HuePickers; using Server.Network; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class SetGump : Gump { - public static readonly bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - private static readonly int EntryWidth = 212; private static readonly int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize; diff --git a/Projects/UOContent/Gumps/Props/SetListOptionGump.cs b/Projects/UOContent/Gumps/Props/SetListOptionGump.cs index 6dcc2611c..f123bb613 100644 --- a/Projects/UOContent/Gumps/Props/SetListOptionGump.cs +++ b/Projects/UOContent/Gumps/Props/SetListOptionGump.cs @@ -2,44 +2,12 @@ using System.Reflection; using Server.Commands; using Server.Network; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class SetListOptionGump : Gump { - public static readonly bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - private static readonly int EntryWidth = 212; private static readonly int EntryCount = 13; diff --git a/Projects/UOContent/Gumps/Props/SetObjectGump.cs b/Projects/UOContent/Gumps/Props/SetObjectGump.cs index 5979fdd2d..bf41934fe 100644 --- a/Projects/UOContent/Gumps/Props/SetObjectGump.cs +++ b/Projects/UOContent/Gumps/Props/SetObjectGump.cs @@ -5,44 +5,12 @@ using Server.Commands.Generic; using Server.Network; using Server.Prompts; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class SetObjectGump : Gump { - public static readonly bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - private static readonly int EntryWidth = 212; private static readonly int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize; diff --git a/Projects/UOContent/Gumps/Props/SetPoint2DGump.cs b/Projects/UOContent/Gumps/Props/SetPoint2DGump.cs index 89ca174dc..0e82aedf4 100644 --- a/Projects/UOContent/Gumps/Props/SetPoint2DGump.cs +++ b/Projects/UOContent/Gumps/Props/SetPoint2DGump.cs @@ -3,44 +3,12 @@ using Server.Commands; using Server.Network; using Server.Targeting; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class SetPoint2DGump : Gump { - public static readonly bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - private static readonly int CoordWidth = 105; private static readonly int EntryWidth = CoordWidth + OffsetSize + CoordWidth; diff --git a/Projects/UOContent/Gumps/Props/SetPoint3DGump.cs b/Projects/UOContent/Gumps/Props/SetPoint3DGump.cs index 19f76df74..616cf0b6b 100644 --- a/Projects/UOContent/Gumps/Props/SetPoint3DGump.cs +++ b/Projects/UOContent/Gumps/Props/SetPoint3DGump.cs @@ -3,44 +3,12 @@ using Server.Commands; using Server.Network; using Server.Targeting; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class SetPoint3DGump : Gump { - public static readonly bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - private static readonly int CoordWidth = 70; private static readonly int EntryWidth = CoordWidth + OffsetSize + CoordWidth + OffsetSize + CoordWidth; @@ -49,6 +17,7 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; + private readonly Mobile m_Mobile; private readonly object m_Object; private readonly PropertyInfo m_Property; diff --git a/Projects/UOContent/Gumps/Props/SetTimeSpanGump.cs b/Projects/UOContent/Gumps/Props/SetTimeSpanGump.cs index 23538da83..22ed96189 100644 --- a/Projects/UOContent/Gumps/Props/SetTimeSpanGump.cs +++ b/Projects/UOContent/Gumps/Props/SetTimeSpanGump.cs @@ -3,44 +3,12 @@ using System.Reflection; using Server.Commands; using Server.Network; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class SetTimeSpanGump : Gump { - public static readonly bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - private static readonly int EntryWidth = 212; private static readonly int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize; diff --git a/Projects/UOContent/Gumps/SkillsGump.cs b/Projects/UOContent/Gumps/SkillsGump.cs index 1afdec16e..9a9610da3 100644 --- a/Projects/UOContent/Gumps/SkillsGump.cs +++ b/Projects/UOContent/Gumps/SkillsGump.cs @@ -3,44 +3,12 @@ using System.Collections.Generic; using Server.Commands; using Server.Network; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class EditSkillGump : Gump { - public static readonly bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - private static readonly int EntryWidth = 160; private static readonly int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize; @@ -143,40 +111,6 @@ namespace Server.Gumps public class SkillsGump : Gump { - public static bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - /* private static bool PrevLabel = OldStyle, NextLabel = OldStyle; @@ -191,17 +125,10 @@ namespace Server.Gumps private static readonly int NameWidth = 107; private static readonly int ValueWidth = 128; - private static readonly int EntryCount = 15; - - private static readonly int TypeWidth = NameWidth + OffsetSize + ValueWidth; - private static readonly int TotalWidth = OffsetSize + NameWidth + OffsetSize + ValueWidth + OffsetSize + SetWidth + OffsetSize; - private static readonly int TotalHeight = OffsetSize + (EntryHeight + OffsetSize) * (EntryCount + 1); - private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; - private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; private static readonly int IndentWidth = 12; diff --git a/Projects/UOContent/Gumps/WhoGump.cs b/Projects/UOContent/Gumps/WhoGump.cs index 37451ccf9..8f925474c 100644 --- a/Projects/UOContent/Gumps/WhoGump.cs +++ b/Projects/UOContent/Gumps/WhoGump.cs @@ -3,47 +3,12 @@ using System.Collections.Generic; using Server.Mobiles; using Server.Network; +using static Server.Gumps.PropsConfig; + namespace Server.Gumps { public class WhoGump : Gump { - public static bool OldStyle = PropsConfig.OldStyle; - - public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX; - public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY; - - public static readonly int TextHue = PropsConfig.TextHue; - public static readonly int TextOffsetX = PropsConfig.TextOffsetX; - - public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID; - public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID; - public static readonly int EntryGumpID = PropsConfig.EntryGumpID; - public static readonly int BackGumpID = PropsConfig.BackGumpID; - public static readonly int SetGumpID = PropsConfig.SetGumpID; - - public static readonly int SetWidth = PropsConfig.SetWidth; - public static readonly int SetOffsetX = PropsConfig.SetOffsetX, SetOffsetY = PropsConfig.SetOffsetY; - public static readonly int SetButtonID1 = PropsConfig.SetButtonID1; - public static readonly int SetButtonID2 = PropsConfig.SetButtonID2; - - public static readonly int PrevWidth = PropsConfig.PrevWidth; - public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX, PrevOffsetY = PropsConfig.PrevOffsetY; - public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1; - public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2; - - public static readonly int NextWidth = PropsConfig.NextWidth; - public static readonly int NextOffsetX = PropsConfig.NextOffsetX, NextOffsetY = PropsConfig.NextOffsetY; - public static readonly int NextButtonID1 = PropsConfig.NextButtonID1; - public static readonly int NextButtonID2 = PropsConfig.NextButtonID2; - - public static readonly int OffsetSize = PropsConfig.OffsetSize; - - public static readonly int EntryHeight = PropsConfig.EntryHeight; - public static readonly int BorderSize = PropsConfig.BorderSize; - - private static readonly bool PrevLabel = false; - private static readonly bool NextLabel = false; - private static readonly int PrevLabelOffsetX = PrevWidth + 1; private static readonly int PrevLabelOffsetY = 0; @@ -54,10 +19,9 @@ namespace Server.Gumps private static readonly int EntryCount = 15; private static readonly int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize; - private static readonly int TotalHeight = OffsetSize + (EntryHeight + OffsetSize) * (EntryCount + 1); private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; - private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; + private readonly List m_Mobiles; private Mobile m_Owner; diff --git a/Projects/UOContent/Utilities/TypeAttributes.cs b/Projects/UOContent/Utilities/TypeAttributes.cs new file mode 100644 index 000000000..dff2946e5 --- /dev/null +++ b/Projects/UOContent/Utilities/TypeAttributes.cs @@ -0,0 +1,30 @@ +using System; +using System.Reflection; +using static Server.Types; + +namespace Server +{ + public static class Attributes + { + public static bool IsConstructible(ConstructorInfo ctor, AccessLevel accessLevel) + { + var attrs = ctor.GetCustomAttributes(OfConstructible, false); + + return attrs.Length != 0 && accessLevel >= ((ConstructibleAttribute)attrs[0]).AccessLevel; + } + + public static CommandPropertyAttribute GetCPA(PropertyInfo p) + { + var attrs = p.GetCustomAttributes(OfCPA, false); + + if (attrs.Length == 0) + { + return null; + } + + return attrs[0] as CommandPropertyAttribute; + } + public static bool HasAttribute(Type type, Type check, bool inherit) => + type.GetCustomAttributes(check, inherit).Length > 0; + } +} diff --git a/Projects/UOContent/Utilities/Types.cs b/Projects/UOContent/Utilities/Types.cs new file mode 100644 index 000000000..5caa4a4a8 --- /dev/null +++ b/Projects/UOContent/Utilities/Types.cs @@ -0,0 +1,107 @@ +using System; + +namespace Server +{ + public static class Types + { + public static readonly Type OfByte = typeof(byte); + public static readonly Type OfSByte = typeof(sbyte); + public static readonly Type OfShort = typeof(short); + public static readonly Type OfUShort = typeof(ushort); + public static readonly Type OfInt = typeof(int); + public static readonly Type OfUInt = typeof(uint); + public static readonly Type OfLong = typeof(long); + public static readonly Type OfULong = typeof(ulong); + public static readonly Type OfObject = typeof(object); + public static readonly Type OfBool = typeof(bool); + public static readonly Type OfChar = typeof(char); + public static readonly Type OfString = typeof(string); + + public static readonly Type OfSerial = typeof(Serial); + public static readonly Type OfTimeSpan = typeof(TimeSpan); + public static readonly Type OfPoint3D = typeof(Point3D); + public static readonly Type OfPoint2D = typeof(Point2D); + public static readonly Type OfEnum = typeof(Enum); + public static readonly Type OfType = typeof(Type); + + public static readonly Type OfCPA = typeof(CommandPropertyAttribute); + public static readonly Type OfText = typeof(TextDefinition); + public static readonly Type OfParsable = typeof(ParsableAttribute); + public static readonly Type OfMobile = typeof(Mobile); + public static readonly Type OfItem = typeof(Item); + public static readonly Type OfCustomEnum = typeof(CustomEnumAttribute); + public static readonly Type OfPoison = typeof(Poison); + public static readonly Type OfMap = typeof(Map); + public static readonly Type OfSkills = typeof(Skills); + public static readonly Type OfPropertyObject = typeof(PropertyObjectAttribute); + public static readonly Type OfNoSort = typeof(NoSortAttribute); + public static readonly Type OfEntity = typeof(IEntity); + public static readonly Type OfConstructible = typeof(ConstructibleAttribute); + + public static readonly string[] BoolNames = { "True", "False" }; + public static readonly object[] BoolValues = { true, false }; + + public static readonly string[] PoisonNames = { "None", "Lesser", "Regular", "Greater", "Deadly", "Lethal" }; + public static readonly object[] PoisonValues = + { null, Poison.Lesser, Poison.Regular, Poison.Greater, Poison.Deadly, Poison.Lethal }; + + public static readonly Type[] DecimalTypes = + { + typeof(float), + typeof(double) + }; + + public static readonly Type[] NumericTypes = + { + OfByte, + OfShort, + OfInt, + OfLong, + OfSByte, + OfUShort, + OfUInt, + OfULong + }; + + private static readonly Type[] SignedNumerics = + { + OfLong, + OfInt, + OfShort, + OfSByte + }; + + private static readonly Type[] UnsignedNumerics = + { + OfULong, + OfUInt, + OfUShort, + OfByte + }; + + + public static readonly Type[] ParseTypes = { OfString }; + + public static bool IsSerial(Type t) => t == OfSerial; + + public static bool IsType(Type t) => t == OfType; + + public static bool IsChar(Type t) => t == OfChar; + + public static bool IsString(Type t) => t == OfString; + + public static bool IsText(Type t) => t == OfText; + + public static bool IsEnum(Type t) => t.IsEnum; + + public static bool IsParsable(Type t) => t == OfTimeSpan || t.IsDefined(OfParsable, false); + + public static bool IsNumeric(Type t) => Array.IndexOf(NumericTypes, t) >= 0; + + public static bool IsSignedNumeric(Type t) => Array.IndexOf(SignedNumerics, t) >= 0; + + public static bool IsUnsignedNumeric(Type t) => Array.IndexOf(UnsignedNumerics, t) >= 0; + + public static bool IsEntity(Type t) => OfEntity.IsAssignableFrom(t); + } +}