diff --git a/Scripts/Accounting/Account.cs b/Scripts/Accounting/Account.cs index e1705c929..042081ad7 100644 --- a/Scripts/Accounting/Account.cs +++ b/Scripts/Accounting/Account.cs @@ -752,13 +752,14 @@ namespace Server.Accounting try { int index = Utility.GetXMLInt32( Utility.GetAttribute( ele, "index", "0" ), 0 ); - int serial = Utility.GetXMLInt32( Utility.GetText( ele, "0" ), 0 ); + uint serial = Utility.GetXMLUInt32( Utility.GetText( ele, "0" ), 0 ); if ( index >= 0 && index < list.Length ) list[index] = World.FindMobile( serial ); } catch { + // ignored } } } @@ -783,7 +784,10 @@ namespace Server.Accounting foreach ( XmlElement comment in comments.GetElementsByTagName( "comment" ) ) { try { list.Add( new AccountComment( comment ) ); } - catch { } + catch + { + // ignored + } } } @@ -807,7 +811,10 @@ namespace Server.Accounting foreach ( XmlElement tag in tags.GetElementsByTagName( "tag" ) ) { try { list.Add( new AccountTag( tag ) ); } - catch { } + catch + { + // ignored + } } } @@ -1180,8 +1187,7 @@ namespace Server.Accounting { if (amount <= 0) { return false; } - int gold; - int plat = Math.DivRem(amount, AccountGold.CurrencyThreshold, out gold); + int plat = Math.DivRem(amount, AccountGold.CurrencyThreshold, out int gold); TotalPlat += plat; TotalGold += gold; diff --git a/Scripts/Accounting/AccountAttackLimiter.cs b/Scripts/Accounting/AccountAttackLimiter.cs index 34df86f4e..cc516295c 100644 --- a/Scripts/Accounting/AccountAttackLimiter.cs +++ b/Scripts/Accounting/AccountAttackLimiter.cs @@ -80,6 +80,7 @@ namespace Server.Accounting } catch { + // ignored } } diff --git a/Scripts/Accounting/AccountHandler.cs b/Scripts/Accounting/AccountHandler.cs index 76eaf1d5f..a81976dd8 100644 --- a/Scripts/Accounting/AccountHandler.cs +++ b/Scripts/Accounting/AccountHandler.cs @@ -192,6 +192,7 @@ namespace Server.Misc } catch { + // ignored } } @@ -229,7 +230,7 @@ namespace Server.Misc state.Send(new CharacterListUpdate(acct)); } else if (m.AccessLevel == AccessLevel.Player && - Region.Find(m.LogoutLocation, m.LogoutMap).GetRegion(typeof(Jail)) != null + Region.Find(m.LogoutLocation, m.LogoutMap).IsPartOf() ) //Don't need to check current location, if netstate is null, they're logged out { state.Send(new DeleteResult(DeleteResultType.BadRequest)); diff --git a/Scripts/Accounting/Accounts.cs b/Scripts/Accounting/Accounts.cs index 0374fa1d0..8acf522a9 100644 --- a/Scripts/Accounting/Accounts.cs +++ b/Scripts/Accounting/Accounts.cs @@ -60,7 +60,7 @@ namespace Server.Accounting foreach (XmlElement account in root.GetElementsByTagName("account")) try { - Account acct = new Account(account); + new Account(account); } catch { @@ -77,11 +77,8 @@ namespace Server.Accounting using (StreamWriter op = new StreamWriter(filePath)) { - XmlTextWriter xml = new XmlTextWriter(op); + XmlTextWriter xml = new XmlTextWriter(op) { Formatting = Formatting.Indented, IndentChar = '\t', Indentation = 1 }; - xml.Formatting = Formatting.Indented; - xml.IndentChar = '\t'; - xml.Indentation = 1; xml.WriteStartDocument(true); diff --git a/Scripts/Accounting/Firewall.cs b/Scripts/Accounting/Firewall.cs index 86e28014e..572728c02 100644 --- a/Scripts/Accounting/Firewall.cs +++ b/Scripts/Accounting/Firewall.cs @@ -194,7 +194,8 @@ namespace Server public override bool Equals(object obj) { - if (obj is IPAddress) return obj.Equals(m_Address); + if (obj is IPAddress) + return obj.Equals(m_Address); if (obj is string s) { if (IPAddress.TryParse(s, out IPAddress otherAddress)) @@ -264,7 +265,7 @@ namespace Server { private string m_Entry; - private bool m_Valid = true; + private bool m_Valid; public WildcardIPFirewallEntry(string entry) { @@ -276,7 +277,9 @@ namespace Server if (!m_Valid) return false; //Why process if it's invalid? it'll return false anyway after processing it. - return Utility.IPMatch(m_Entry, address, ref m_Valid); + bool matched = Utility.IPMatch(m_Entry, address, out bool valid); + m_Valid = valid; + return matched; } public override string ToString() diff --git a/Scripts/Commands/Add.cs b/Scripts/Commands/Add.cs index eca389a5d..29af1f94c 100644 --- a/Scripts/Commands/Add.cs +++ b/Scripts/Commands/Add.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Text; using Server.Items; -using Server.Targeting; using CPA = Server.CommandPropertyAttribute; namespace Server.Commands @@ -54,18 +54,8 @@ namespace Server.Commands CommandSystem.Register("OutlineAvg", AccessLevel.GameMaster, OutlineAvg_OnCommand); } - public static void Invoke(Mobile from, Point3D start, Point3D end, string[] args) - { - Invoke(from, start, end, args, null, false, false); - } - - public static void Invoke(Mobile from, Point3D start, Point3D end, string[] args, List packs) - { - Invoke(from, start, end, args, packs, false, false); - } - - public static void Invoke(Mobile from, Point3D start, Point3D end, string[] args, List packs, - bool outline, bool mapAvg) + public static void Invoke(Mobile from, Point3D start, Point3D end, string[] args, List packs = null, + bool outline = false, bool mapAvg = false) { StringBuilder sb = new StringBuilder(); @@ -148,13 +138,7 @@ namespace Server.Commands } public static int BuildObjects(Mobile from, Type type, Point3D start, Point3D end, string[] args, string[,] props, - List packs) - { - return BuildObjects(from, type, start, end, args, props, packs, false, false); - } - - public static int BuildObjects(Mobile from, Type type, Point3D start, Point3D end, string[] args, string[,] props, - List packs, bool outline, bool mapAvg) + List packs, bool outline = false, bool mapAvg = false) { Utility.FixPoints(ref start, ref end); @@ -206,10 +190,19 @@ namespace Server.Commands if (!IsConstructible(ctor, from.AccessLevel)) continue; + + int totalParams = 0; - ParameterInfo[] paramList = ctor.GetParameters(); + // Handle optional constructors + ParameterInfo[] paramList = ctor.GetParameters().Select(param => + { + if (param.DefaultValue is DBNull) + totalParams += 1; - if (args.Length == paramList.Length) + return param; + }).ToArray(); + + if (args.Length == totalParams) { object[] paramValues = ParseValues(paramList, args); @@ -228,27 +221,31 @@ namespace Server.Commands public static object[] ParseValues(ParameterInfo[] paramList, string[] args) { - object[] values = new object[args.Length]; + object[] values = new object[paramList.Length]; - for (int i = 0; i < args.Length; ++i) + for (int i = 0, a = 0; i < paramList.Length; ++i) { - object value = ParseValue(paramList[i].ParameterType, args[i]); + ParameterInfo param = paramList[i]; + if (param.DefaultValue is DBNull) + { + object value = ParseValue(param.ParameterType, args[a++], param.DefaultValue); + if (value == null) + return null; - if (value != null) values[i] = value; + } else - return null; + values[i] = Type.Missing; } return values; } - public static object ParseValue(Type type, string value) + public static object ParseValue(Type type, string value, object defaultValue) { try { if (IsEnum(type)) return Enum.Parse(type, value, true); - if (IsType(type)) return ScriptCompiler.FindTypeByName(value); if (IsParsable(type)) return ParseParsable(type, value); object obj = value; @@ -259,12 +256,13 @@ namespace Server.Commands obj = Convert.ToInt64(value.Substring(2), 16); else if (IsUnsignedNumeric(type)) obj = Convert.ToUInt64(value.Substring(2), 16); - - obj = Convert.ToInt32(value.Substring(2), 16); + else + obj = Convert.ToInt32(value.Substring(2), 16); } if (obj == null && !type.IsValueType) return null; + return Convert.ChangeType(obj, type); } catch @@ -307,13 +305,7 @@ namespace Server.Commands } public static int Build(Mobile from, Point3D start, Point3D end, ConstructorInfo ctor, object[] values, - string[,] props, PropertyInfo[] realProps, List packs) - { - return Build(from, start, end, ctor, values, props, realProps, packs, false, false); - } - - public static int Build(Mobile from, Point3D start, Point3D end, ConstructorInfo ctor, object[] values, - string[,] props, PropertyInfo[] realProps, List packs, bool outline, bool mapAvg) + string[,] props, PropertyInfo[] realProps, List packs, bool outline = false, bool mapAvg = false) { try { @@ -352,7 +344,8 @@ namespace Server.Commands if (built is Item item) packs[i].DropItem(item); - else if (built is Mobile m) m.MoveToWorld(new Point3D(start.X, start.Y, start.Z), map); + else if (built is Mobile m) + m.MoveToWorld(new Point3D(start.X, start.Y, start.Z), map); } } else @@ -374,7 +367,8 @@ namespace Server.Commands if (built is Item item) item.MoveToWorld(new Point3D(x, y, z), map); - else if (built is Mobile m) m.MoveToWorld(new Point3D(x, y, z), map); + else if (built is Mobile m) + m.MoveToWorld(new Point3D(x, y, z), map); } } @@ -437,9 +431,8 @@ namespace Server.Commands from.SendMessage(sb.ToString()); } - private static void TileBox_Callback(Mobile from, Map map, Point3D start, Point3D end, object state) + private static void TileBox_Callback(Mobile from, Map map, Point3D start, Point3D end, TileState ts) { - TileState ts = (TileState)state; bool mapAvg = false; switch (ts.m_ZType) @@ -461,10 +454,13 @@ namespace Server.Commands private static void Internal_OnCommand(CommandEventArgs e, bool outline) { + Mobile from = e.Mobile; + if (e.Length >= 1) - BoundingBoxPicker.Begin(e.Mobile, TileBox_Callback, new TileState(TileZType.Start, 0, e.Arguments, outline)); + BoundingBoxPicker.Begin(from, (map, start, end) => + TileBox_Callback(from, map, start, end, new TileState(TileZType.Start, 0, e.Arguments, outline))); else - e.Mobile.SendMessage("Format: {0} [params] [set {{ ...}}]", + from.SendMessage("Format: {0} [params] [set {{ ...}}]", outline ? "Outline" : "Tile"); } @@ -480,7 +476,7 @@ namespace Server.Commands for (int i = 0; i < subArgs.Length; ++i) subArgs[i] = e.Arguments[i + 5]; - Invoke(e.Mobile, p, p2, subArgs, null, outline, false); + Invoke(e.Mobile, p, p2, subArgs, null, outline); } else { @@ -502,7 +498,7 @@ namespace Server.Commands for (int i = 0; i < subArgs.Length; ++i) subArgs[i] = e.Arguments[i + 5]; - Invoke(e.Mobile, p, p2, subArgs, null, outline, false); + Invoke(e.Mobile, p, p2, subArgs, null, outline); } else { @@ -514,6 +510,8 @@ namespace Server.Commands private static void InternalZ_OnCommand(CommandEventArgs e, bool outline) { + Mobile from = e.Mobile; + if (e.Length >= 2) { string[] subArgs = new string[e.Length - 1]; @@ -521,23 +519,25 @@ namespace Server.Commands for (int i = 0; i < subArgs.Length; ++i) subArgs[i] = e.Arguments[i + 1]; - BoundingBoxPicker.Begin(e.Mobile, TileBox_Callback, - new TileState(TileZType.Fixed, e.GetInt32(0), subArgs, outline)); + BoundingBoxPicker.Begin(from, (map, start, end) => + TileBox_Callback(from, map, start, end, new TileState(TileZType.Fixed, e.GetInt32(0), subArgs, outline))); } else { - e.Mobile.SendMessage("Format: {0}Z [params] [set {{ ...}}]", + from.SendMessage("Format: {0}Z [params] [set {{ ...}}]", outline ? "Outline" : "Tile"); } } private static void InternalAvg_OnCommand(CommandEventArgs e, bool outline) { + Mobile from = e.Mobile; + if (e.Length >= 1) - BoundingBoxPicker.Begin(e.Mobile, TileBox_Callback, - new TileState(TileZType.MapAverage, 0, e.Arguments, outline)); + BoundingBoxPicker.Begin(from, (map, start, end) => + TileBox_Callback(from, map, start, end, new TileState(TileZType.MapAverage, 0, e.Arguments, outline))); else - e.Mobile.SendMessage("Format: {0}Avg [params] [set {{ ...}}]", + from.SendMessage("Format: {0}Avg [params] [set {{ ...}}]", outline ? "Outline" : "Tile"); } @@ -657,7 +657,7 @@ namespace Server.Commands m_ParseArgs[0] = value; - return method.Invoke(null, m_ParseArgs); + return method?.Invoke(null, m_ParseArgs); } public static bool IsSignedNumeric(Type type) @@ -678,30 +678,6 @@ namespace Server.Commands return false; } - public class AddTarget : Target - { - private string[] m_Args; - - public AddTarget(string[] args) : base(-1, true, TargetFlags.None) - { - m_Args = args; - } - - protected override void OnTarget(Mobile from, object o) - { - if (o is IPoint3D p) - { - if (p is Item item) - p = item.GetWorldTop(); - else if (p is Mobile m) - p = m.Location; - - Point3D point = new Point3D(p); - Add.Invoke(from, point, point, m_Args); - } - } - } - private enum TileZType { Start, diff --git a/Scripts/Commands/Batch.cs b/Scripts/Commands/Batch.cs index 3a24772ad..155587495 100644 --- a/Scripts/Commands/Batch.cs +++ b/Scripts/Commands/Batch.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Reflection; using Server.Commands.Generic; using Server.Gumps; @@ -13,18 +14,15 @@ namespace Server.Commands { Commands = new[] { "Batch" }; ListOptimized = true; - - BatchCommands = new ArrayList(); - Condition = ""; } public BaseCommandImplementor Scope{ get; set; } - public string Condition{ get; set; } + public string Condition{ get; set; } = ""; - public ArrayList BatchCommands{ get; } + public List BatchCommands{ get; } = new List(); - public override void ExecuteList(CommandEventArgs e, ArrayList list) + public override void ExecuteList(CommandEventArgs e, List list) { if (list.Count == 0) { @@ -39,7 +37,7 @@ namespace Server.Commands for (int i = 0; i < BatchCommands.Count; ++i) { - BatchCommand bc = (BatchCommand)BatchCommands[i]; + BatchCommand bc = BatchCommands[i]; bc.GetDetails(out string commandString, out string argString, out string[] args); @@ -68,12 +66,12 @@ namespace Server.Commands for (int i = 0; i < commands.Length; ++i) { BaseCommand command = commands[i]; - BatchCommand bc = (BatchCommand)BatchCommands[i]; + BatchCommand bc = BatchCommands[i]; if (list.Count > 20) CommandLogging.Enabled = false; - ArrayList usedList; + List usedList; if (Utility.InsensitiveCompare(bc.Object, "Current") == 0) { @@ -81,9 +79,9 @@ namespace Server.Commands } else { - Hashtable propertyChains = new Hashtable(); + Dictionary propertyChains = new Dictionary(); - usedList = new ArrayList(list.Count); + usedList = new List(list.Count); for (int j = 0; j < list.Count; ++j) { @@ -94,11 +92,11 @@ namespace Server.Commands Type type = obj.GetType(); - PropertyInfo[] chain = (PropertyInfo[])propertyChains[type]; + PropertyInfo[] chain = propertyChains[type]; string failReason = ""; - if (chain == null && !propertyChains.Contains(type)) + if (chain == null) propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object, PropertyAccess.Read, ref failReason); @@ -119,6 +117,7 @@ namespace Server.Commands } catch { + // ignored } } } @@ -272,7 +271,7 @@ namespace Server.Commands for (int i = 0; i < m_Batch.BatchCommands.Count; ++i) { - BatchCommand bc = (BatchCommand)m_Batch.BatchCommands[i]; + BatchCommand bc = m_Batch.BatchCommands[i]; AddNewLine(); @@ -420,4 +419,4 @@ namespace Server.Commands m_From.SendGump(new BatchGump(m_From, m_Batch)); } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/BoundingBoxPicker.cs b/Scripts/Commands/BoundingBoxPicker.cs index 83db542d8..d95156919 100644 --- a/Scripts/Commands/BoundingBoxPicker.cs +++ b/Scripts/Commands/BoundingBoxPicker.cs @@ -2,14 +2,14 @@ using Server.Targeting; namespace Server { - public delegate void BoundingBoxCallback(Mobile from, Map map, Point3D start, Point3D end, object state); + public delegate void BoundingBoxCallback(Map map, Point3D start, Point3D end); - public class BoundingBoxPicker + public static class BoundingBoxPicker { - public static void Begin(Mobile from, BoundingBoxCallback callback, object state) + public static void Begin(Mobile from, BoundingBoxCallback callback) { from.SendMessage("Target the first location of the bounding box."); - from.Target = new PickTarget(callback, state); + from.Target = new PickTarget(callback); } private class PickTarget : Target @@ -17,21 +17,18 @@ namespace Server private BoundingBoxCallback m_Callback; private bool m_First; private Map m_Map; - private object m_State; private Point3D m_Store; - public PickTarget(BoundingBoxCallback callback, object state) : this(Point3D.Zero, true, null, callback, state) + public PickTarget(BoundingBoxCallback callback) : this(Point3D.Zero, true, null, callback) { } - public PickTarget(Point3D store, bool first, Map map, BoundingBoxCallback callback, object state) : base(-1, - true, TargetFlags.None) + public PickTarget(Point3D store, bool first, Map map, BoundingBoxCallback callback) : base(-1, true, TargetFlags.None) { m_Store = store; m_First = first; m_Map = map; m_Callback = callback; - m_State = state; } protected override void OnTarget(Mobile from, object targeted) @@ -45,7 +42,7 @@ namespace Server if (m_First) { from.SendMessage("Target another location to complete the bounding box."); - from.Target = new PickTarget(new Point3D(p), false, from.Map, m_Callback, m_State); + from.Target = new PickTarget(new Point3D(p), false, from.Map, m_Callback); } else if (from.Map != m_Map) { @@ -58,7 +55,7 @@ namespace Server Utility.FixPoints(ref start, ref end); - m_Callback(from, m_Map, start, end, m_State); + m_Callback(m_Map, start, end); } } } diff --git a/Scripts/Commands/ConvertPlayers.cs b/Scripts/Commands/ConvertPlayers.cs index faddf9fb3..22ffae98d 100644 --- a/Scripts/Commands/ConvertPlayers.cs +++ b/Scripts/Commands/ConvertPlayers.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using Server.Mobiles; using Server.Network; @@ -63,24 +64,22 @@ namespace Server.Commands } } + private static PropertyInfo[] _mobProps = + typeof(Mobile).GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Where(prop => prop.CanRead && prop.CanWrite).ToArray(); + private static void CopyProps(Mobile to, Mobile from) { - Type type = typeof(Mobile); - - PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); - - for (int p = 0; p < props.Length; p++) + foreach (PropertyInfo prop in _mobProps) { - PropertyInfo prop = props[p]; - - if (prop.CanRead && prop.CanWrite) - try - { - prop.SetValue(to, prop.GetValue(from, null), null); - } - catch - { - } + try + { + prop.SetValue(to, prop.GetValue(from, null), null); + } + catch + { + // ignored + } } } } diff --git a/Scripts/Commands/Decorate.cs b/Scripts/Commands/Decorate.cs index fe7b937d5..8faf09bdd 100644 --- a/Scripts/Commands/Decorate.cs +++ b/Scripts/Commands/Decorate.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.IO; using Server.Engines.Quests.Haven; @@ -47,10 +46,10 @@ namespace Server.Commands for (int i = 0; i < files.Length; ++i) { - ArrayList list = DecorationList.ReadAll(files[i]); + List list = DecorationList.ReadAll(files[i]); for (int j = 0; j < list.Count; ++j) - m_Count += ((DecorationList)list[j]).Generate(maps); + m_Count += list[j].Generate(maps); } } } @@ -70,10 +69,10 @@ namespace Server.Commands private static Type typeofCannon = typeof(Cannon); private static Type typeofSerpentPillar = typeof(SerpentPillar); - private static Queue m_DeleteQueue = new Queue(); + private static Queue m_DeleteQueue = new Queue(); private static string[] m_EmptyParams = new string[0]; - private ArrayList m_Entries; + private List m_Entries; private int m_ItemID; private string[] m_Params; private Type m_Type; @@ -913,7 +912,7 @@ namespace Server.Commands eable.Free(); while (m_DeleteQueue.Count > 0) - ((Item)m_DeleteQueue.Dequeue()).Delete(); + m_DeleteQueue.Dequeue().Delete(); return res; } @@ -926,7 +925,7 @@ namespace Server.Commands for (int i = 0; i < m_Entries.Count; ++i) { - DecorationEntry entry = (DecorationEntry)m_Entries[i]; + DecorationEntry entry = m_Entries[i]; Point3D loc = entry.Location; string extra = entry.Extra; @@ -970,6 +969,7 @@ namespace Server.Commands } catch { + // ignored } } @@ -983,13 +983,14 @@ namespace Server.Commands return count; } - public static ArrayList ReadAll(string path) + public static List ReadAll(string path) { using (StreamReader ip = new StreamReader(path)) { - ArrayList list = new ArrayList(); - - for (DecorationList v = Read(ip); v != null; v = Read(ip)) + List list = new List(); + DecorationList v; + + while ((v = Read(ip)) != null) list.Add(v); return list; @@ -1042,7 +1043,7 @@ namespace Server.Commands list.m_Params = m_EmptyParams; } - list.m_Entries = new ArrayList(); + list.m_Entries = new List(); while ((line = ip.ReadLine()) != null) { diff --git a/Scripts/Commands/DecorateMag.cs b/Scripts/Commands/DecorateMag.cs index 1695cafe4..893be8414 100644 --- a/Scripts/Commands/DecorateMag.cs +++ b/Scripts/Commands/DecorateMag.cs @@ -44,10 +44,10 @@ namespace Server.Commands for (int i = 0; i < files.Length; ++i) { - ArrayList list = DecorationListMag.ReadAll(files[i]); + List list = DecorationListMag.ReadAll(files[i]); for (int j = 0; j < list.Count; ++j) - m_Count += ((DecorationListMag)list[j]).Generate(maps); + m_Count += list[j].Generate(maps); } } } @@ -70,7 +70,7 @@ namespace Server.Commands private static Queue m_DeleteQueue = new Queue(); private static string[] m_EmptyParams = new string[0]; - private ArrayList m_Entries; + private List m_Entries; private int m_ItemID; private string[] m_Params; private Type m_Type; @@ -923,7 +923,7 @@ namespace Server.Commands for (int i = 0; i < m_Entries.Count; ++i) { - DecorationEntryMag entry = (DecorationEntryMag)m_Entries[i]; + DecorationEntryMag entry = m_Entries[i]; Point3D loc = entry.Location; string extra = entry.Extra; @@ -967,6 +967,7 @@ namespace Server.Commands } catch { + // ignored } } @@ -980,13 +981,14 @@ namespace Server.Commands return count; } - public static ArrayList ReadAll(string path) + public static List ReadAll(string path) { using (StreamReader ip = new StreamReader(path)) { - ArrayList list = new ArrayList(); + List list = new List(); - for (DecorationListMag v = Read(ip); v != null; v = Read(ip)) + DecorationListMag v; + while ((v = Read(ip)) != null) list.Add(v); return list; @@ -1039,7 +1041,7 @@ namespace Server.Commands list.m_Params = m_EmptyParams; } - list.m_Entries = new ArrayList(); + list.m_Entries = new List(); while ((line = ip.ReadLine()) != null) { diff --git a/Scripts/Commands/Docs.cs b/Scripts/Commands/Docs.cs index 0b4b355a2..e86e6f779 100644 --- a/Scripts/Commands/Docs.cs +++ b/Scripts/Commands/Docs.cs @@ -214,7 +214,7 @@ namespace Server.Commands } } - public static void FormatGeneric(Type type, ref string typeName, ref string fileName, ref string linkName) + public static void FormatGeneric(Type type, out string typeName, out string fileName, out string linkName) { string name = null; string fnam = null; @@ -274,8 +274,10 @@ namespace Server.Commands } } - if (name == null) typeName = type.Name; - else typeName = name; + if (name == null) + typeName = type.Name; + else + typeName = name; if (fnam == null) fileName = "docs/types/" + SanitizeType(type.Name) + ".html"; else fileName = fnam + ".html"; @@ -466,12 +468,7 @@ namespace Server.Commands m_Declaring = type.DeclaringType; m_Interfaces = type.GetInterfaces(); - FormatGeneric(m_Type, ref m_TypeName, ref m_FileName, ref m_LinkName); - - // Console.WriteLine( ">> inline typeinfo: "+m_TypeName ); - // m_TypeName = GetGenericTypeName( m_Type ); - // m_FileName = Docs.GetFileName( "docs/types/", GetGenericTypeName( m_Type, "-", "-" ), ".html" ); - // m_Writer = Docs.GetWriter( "docs/types/", m_FileName ); + FormatGeneric(m_Type, out m_TypeName, out m_FileName, out m_LinkName); } public string FileName => m_FileName; @@ -601,7 +598,7 @@ namespace Server.Commands append.Append(" *"); } } - else if (realType.IsArray) + else if (realType?.IsArray == true) { do { @@ -625,30 +622,16 @@ namespace Server.Commands string fullName = realType?.FullName ?? "(-null-)"; string aliased = null; // = realType.Name; - TypeInfo info = null; - - if (realType != null) + if (realType != null && m_Types.TryGetValue(realType, out TypeInfo info)) { - m_Types.TryGetValue(realType, out info); - } - - if (info != null) - { - aliased = "" + info.LinkName(null); - //aliased = String.Format( "{1}", info.m_FileName, info.m_TypeName ); + aliased = $"{info.LinkName(null)}"; } else { - //FormatGeneric( ); if (realType?.IsGenericType == true) { - string typeName = ""; - string fileName = ""; - string linkName = ""; - - FormatGeneric(realType, ref typeName, ref fileName, ref linkName); - linkName = linkName.Replace("@directory@", null); - aliased = linkName; + FormatGeneric(realType, out _, out _, out string linkName); + aliased = linkName.Replace("@directory@", null); } else { @@ -768,7 +751,7 @@ namespace Server.Commands AddIndexLink(html, "commands.html", "Commands", "Every available command. This contains command name, usage, aliases, and description."); AddIndexLink(html, "objects.html", "Constructible Objects", - "Every constructable item or npc. This contains object name and usage. Hover mouse over parameters to see type description."); + "Every constructible item or npc. This contains object name and usage. Hover mouse over parameters to see type description."); AddIndexLink(html, "keywords.html", "Speech Keywords", "Lists speech keyword numbers and associated match patterns. These are used in some scripts for multi-language matching of client speech."); AddIndexLink(html, "bodies.html", "Body List", @@ -1861,7 +1844,8 @@ namespace Server.Commands { public int Compare(SpeechEntry x, SpeechEntry y) { - return x.Index.CompareTo(y.Index); + if (x == null && y == null) return 0; + return x?.Index.CompareTo(y?.Index) ?? 1; } } @@ -1940,12 +1924,14 @@ namespace Server.Commands { public int Compare(DocCommandEntry a, DocCommandEntry b) { - int v = b.AccessLevel.CompareTo(a.AccessLevel); + if (a == null && b == null) return 0; + + int v = b?.AccessLevel.CompareTo(a?.AccessLevel) ?? 1; - if (v == 0) - v = a.Name.CompareTo(b.Name); - - return v; + if (v != 0) + return v; + + return a?.Name.CompareTo(b?.Name) ?? 1; } } @@ -2198,10 +2184,7 @@ namespace Server.Commands private static bool IsConstructible(Type t, out bool isItem) { - if (isItem = typeofItem.IsAssignableFrom(t)) - return true; - - return typeofMobile.IsAssignableFrom(t); + return (isItem = typeofItem.IsAssignableFrom(t)) || typeofMobile.IsAssignableFrom(t); } private static bool IsConstructible(ConstructorInfo ctor) @@ -2214,14 +2197,14 @@ namespace Server.Commands List types = new List(m_Types.Values); types.Sort(new TypeComparer()); - ArrayList items = new ArrayList(), mobiles = new ArrayList(); + List<(Type, ConstructorInfo[])> items = new List<(Type, ConstructorInfo[])>(); + List<(Type, ConstructorInfo[])> mobiles = new List<(Type, ConstructorInfo[])>(); for (int i = 0; i < types.Count; ++i) { Type t = types[i].m_Type; - bool isItem; - if (t.IsAbstract || !IsConstructible(t, out isItem)) + if (t.IsAbstract || !IsConstructible(t, out bool isItem)) continue; ConstructorInfo[] ctors = t.GetConstructors(); @@ -2232,8 +2215,7 @@ namespace Server.Commands if (anyConstructible) { - (isItem ? items : mobiles).Add(t); - (isItem ? items : mobiles).Add(ctors); + (isItem ? items : mobiles).Add((t, ctors)); } } @@ -2255,8 +2237,11 @@ namespace Server.Commands html.WriteLine(" "); html.WriteLine(" "); - for (int i = 0; i < items.Count; i += 2) - DocumentConstructibleObject(html, (Type)items[i], (ConstructorInfo[])items[i + 1]); + items.ForEach(tuple => + { + var (type, constructors) = tuple; + DocumentConstructibleObject(html, type, constructors); + }); html.WriteLine("
Item NameUsage


"); @@ -2266,8 +2251,11 @@ namespace Server.Commands html.WriteLine(" "); html.WriteLine(" "); - for (int i = 0; i < mobiles.Count; i += 2) - DocumentConstructibleObject(html, (Type)mobiles[i], (ConstructorInfo[])mobiles[i + 1]); + mobiles.ForEach(tuple => + { + var (type, constructors) = tuple; + DocumentConstructibleObject(html, type, constructors); + }); html.WriteLine("
Mobile NameUsage
"); @@ -2513,12 +2501,8 @@ namespace Server.Commands if (ifaceInfo == null) { - string typeName = ""; - string fileName = ""; - string linkName = ""; - FormatGeneric(iface, ref typeName, ref fileName, ref linkName); - linkName = linkName.Replace("@directory@", null); - typeHtml.Write("" + linkName); + FormatGeneric(iface, out _, out _, out string linkName); + typeHtml.Write($"{linkName.Replace("@directory@", null)}"); } else { @@ -2725,9 +2709,9 @@ namespace Server.Commands public override bool Equals(object obj) { - BodyEntry e = (BodyEntry)obj; + BodyEntry e = obj as BodyEntry; - return Body == e.Body && BodyType == e.BodyType && Name == e.Name; + return Body == e?.Body && BodyType == e.BodyType && Name == e.Name; } public override int GetHashCode() @@ -2740,15 +2724,16 @@ namespace Server.Commands { public int Compare(BodyEntry a, BodyEntry b) { - int v = a.BodyType.CompareTo(b.BodyType); + if (a == null && b == null) return 0; + int v = a?.BodyType.CompareTo(b?.BodyType) ?? 1; if (v == 0) - v = a.Body.BodyID.CompareTo(b.Body.BodyID); + v = a?.Body.BodyID.CompareTo(b?.Body.BodyID) ?? 1; - if (v == 0) - v = a.Name.CompareTo(b.Name); - - return v; + if (v != 0) + return v; + + return a?.Name.CompareTo(b?.Name) ?? 1; } } diff --git a/Scripts/Commands/ExportWSC.cs b/Scripts/Commands/ExportWSC.cs index 0f743d4a2..3633e02a1 100644 --- a/Scripts/Commands/ExportWSC.cs +++ b/Scripts/Commands/ExportWSC.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; using System.IO; using Server.Items; @@ -16,7 +16,7 @@ namespace Server.Commands public static void Export_OnCommand(CommandEventArgs e) { StreamWriter w = new StreamWriter(ExportFile); - ArrayList remove = new ArrayList(); + List remove = new List(); int count = 0; e.Mobile.SendMessage("Exporting all static items to \"{0}\"...", ExportFile); diff --git a/Scripts/Commands/GenCategorization.cs b/Scripts/Commands/GenCategorization.cs index cc94c8d78..74a025c9d 100644 --- a/Scripts/Commands/GenCategorization.cs +++ b/Scripts/Commands/GenCategorization.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using System.Reflection; using System.Text; @@ -54,14 +54,6 @@ namespace Server.Commands e.Mobile.SendMessage("Categorization menu rebuilt."); } - public static void RecurseFindCategories(CategoryEntry ce, ArrayList list) - { - list.Add(ce); - - for (int i = 0; i < ce.SubCategories.Length; ++i) - RecurseFindCategories(ce.SubCategories[i], list); - } - public static void Export(CategoryEntry ce, string fileName, string title) { XmlTextWriter xml = new XmlTextWriter(fileName, Encoding.UTF8); @@ -84,18 +76,18 @@ namespace Server.Commands xml.WriteAttributeString("title", ce.Title); - ArrayList subCats = new ArrayList(ce.SubCategories); + List subCats = new List(ce.SubCategories); subCats.Sort(new CategorySorter()); for (int i = 0; i < subCats.Count; ++i) - RecurseExport(xml, (CategoryEntry)subCats[i]); + RecurseExport(xml, subCats[i]); - ce.Matched.Sort(new CategorySorter()); + ce.Matched.Sort(new CategoryTypeSorter()); for (int i = 0; i < ce.Matched.Count; ++i) { - CategoryTypeEntry cte = (CategoryTypeEntry)ce.Matched[i]; + CategoryTypeEntry cte = ce.Matched[i]; xml.WriteStartElement("object"); @@ -148,7 +140,7 @@ namespace Server.Commands public static void Load() { - ArrayList types = new ArrayList(); + List types = new List(); AddTypes(Core.Assembly, types); @@ -159,7 +151,7 @@ namespace Server.Commands m_RootMobiles = Load(types, "Data/mobiles.cfg"); } - private static CategoryEntry Load(ArrayList types, string config) + private static CategoryEntry Load(List types, string config) { CategoryLine[] lines = CategoryLine.Load(config); @@ -186,7 +178,7 @@ namespace Server.Commands return ctor != null && ctor.IsDefined(typeofConstructible, false); } - private static void AddTypes(Assembly asm, ArrayList types) + private static void AddTypes(Assembly asm, List types) { Type[] allTypes = asm.GetTypes(); @@ -202,11 +194,11 @@ namespace Server.Commands } } - private static void Fill(CategoryEntry root, ArrayList list) + private static void Fill(CategoryEntry root, List list) { for (int i = 0; i < list.Count; ++i) { - Type type = (Type)list[i]; + Type type = list[i]; CategoryEntry match = GetDeepestMatch(root, type); if (match == null) @@ -218,6 +210,7 @@ namespace Server.Commands } catch { + // ignored } } } @@ -239,21 +232,12 @@ namespace Server.Commands } } - public class CategorySorter : IComparer + public class CategorySorter : IComparer { - public int Compare(object x, object y) + public int Compare(CategoryEntry x, CategoryEntry y) { - string a = null, b = null; - - if (x is CategoryEntry entry) - a = entry.Title; - else if (x is CategoryTypeEntry xTypeEntry) - a = xTypeEntry.Type.Name; - - if (y is CategoryEntry categoryEntry) - b = categoryEntry.Title; - else if (y is CategoryTypeEntry yTypeEntry) - b = yTypeEntry.Type.Name; + string a = x?.Title; + string b = y?.Title; if (a == null && b == null) return 0; @@ -261,13 +245,27 @@ namespace Server.Commands if (a == null) return 1; - if (b == null) - return -1; - return a.CompareTo(b); } } + public class CategoryTypeSorter : IComparer + { + public int Compare(CategoryTypeEntry x, CategoryTypeEntry y) + { + string a = x?.Type.Name; + string b = y?.Type.Name; + + if (a == null && b == null) + return 0; + + if (a == null) + return 1; + + return a.CompareTo(b); + } + } + public class CategoryTypeEntry { public CategoryTypeEntry(Type type) @@ -283,21 +281,13 @@ namespace Server.Commands public class CategoryEntry { - public CategoryEntry() - { - Title = "(empty)"; - Matches = new Type[0]; - SubCategories = new CategoryEntry[0]; - Matched = new ArrayList(); - } - - public CategoryEntry(CategoryEntry parent, string title, CategoryEntry[] subCats) + public CategoryEntry(CategoryEntry parent = null, string title = "(empty)", CategoryEntry[] subCats = null) { Parent = parent; Title = title; - SubCategories = subCats; + SubCategories = subCats ?? new CategoryEntry[0]; Matches = new Type[0]; - Matched = new ArrayList(); + Matched = new List(); } public CategoryEntry(CategoryEntry parent, CategoryLine[] lines, ref int index) @@ -321,7 +311,7 @@ namespace Server.Commands text = text.Substring(start, end - start); string[] split = text.Split(';'); - ArrayList list = new ArrayList(); + List list = new List(); for (int i = 0; i < split.Length; ++i) { @@ -333,20 +323,22 @@ namespace Server.Commands list.Add(type); } - Matches = (Type[])list.ToArray(typeof(Type)); + Matches = list.ToArray(); list.Clear(); int ourIndentation = lines[index].Indentation; ++index; + List entryList = new List(); + while (index < lines.Length && lines[index].Indentation > ourIndentation) - list.Add(new CategoryEntry(this, lines, ref index)); + entryList.Add(new CategoryEntry(this, lines, ref index)); - SubCategories = (CategoryEntry[])list.ToArray(typeof(CategoryEntry)); - list.Clear(); + SubCategories = entryList.ToArray(); + entryList.Clear(); - Matched = list; + Matched = new List(); } public string Title{ get; } @@ -357,7 +349,7 @@ namespace Server.Commands public CategoryEntry[] SubCategories{ get; } - public ArrayList Matched{ get; } + public List Matched{ get; } public bool IsMatch(Type type) { @@ -393,7 +385,7 @@ namespace Server.Commands public static CategoryLine[] Load(string path) { - ArrayList list = new ArrayList(); + List list = new List(); if (File.Exists(path)) using (StreamReader ip = new StreamReader(path)) @@ -404,7 +396,7 @@ namespace Server.Commands list.Add(new CategoryLine(line)); } - return (CategoryLine[])list.ToArray(typeof(CategoryLine)); + return list.ToArray(); } } } \ No newline at end of file diff --git a/Scripts/Commands/Generic/Commands/BaseCommand.cs b/Scripts/Commands/Generic/Commands/BaseCommand.cs index b8808f782..328afbe6d 100644 --- a/Scripts/Commands/Generic/Commands/BaseCommand.cs +++ b/Scripts/Commands/Generic/Commands/BaseCommand.cs @@ -1,5 +1,4 @@ -using System.Collections; -using Server.Gumps; +using System.Collections.Generic; namespace Server.Commands.Generic { @@ -13,13 +12,8 @@ namespace Server.Commands.Generic public abstract class BaseCommand { - private ArrayList m_Responses, m_Failures; - - public BaseCommand() - { - m_Responses = new ArrayList(); - m_Failures = new ArrayList(); - } + private List m_Responses = new List(); + private List m_Failures = new List(); public bool ListOptimized{ get; set; } @@ -50,7 +44,7 @@ namespace Server.Commands.Generic return mob == null || mob == from || from.AccessLevel > mob.AccessLevel; } - public virtual void ExecuteList(CommandEventArgs e, ArrayList list) + public virtual void ExecuteList(CommandEventArgs e, List list) { for (int i = 0; i < list.Count; ++i) Execute(e, list[i]); @@ -69,7 +63,7 @@ namespace Server.Commands.Generic { for (int i = 0; i < m_Responses.Count; ++i) { - MessageEntry entry = (MessageEntry)m_Responses[i]; + MessageEntry entry = m_Responses[i]; if (entry.m_Message == message) { @@ -84,16 +78,11 @@ namespace Server.Commands.Generic m_Responses.Add(new MessageEntry(message)); } - public void AddResponse(Gump gump) - { - m_Responses.Add(gump); - } - public void LogFailure(string message) { for (int i = 0; i < m_Failures.Count; ++i) { - MessageEntry entry = (MessageEntry)m_Failures[i]; + MessageEntry entry = m_Failures[i]; if (entry.m_Message == message) { @@ -113,23 +102,16 @@ namespace Server.Commands.Generic if (m_Responses.Count > 0) for (int i = 0; i < m_Responses.Count; ++i) { - object obj = m_Responses[i]; + MessageEntry entry = m_Responses[i]; - if (obj is MessageEntry entry) - { - from.SendMessage(entry.ToString()); + from.SendMessage(entry.ToString()); - if (flushToLog) - CommandLogging.WriteLine(from, entry.ToString()); - } - else if (obj is Gump gump) - { - from.SendGump(gump); - } + if (flushToLog) + CommandLogging.WriteLine(from, entry.ToString()); } else for (int i = 0; i < m_Failures.Count; ++i) - from.SendMessage(((MessageEntry)m_Failures[i]).ToString()); + from.SendMessage(m_Failures[i].ToString()); m_Responses.Clear(); m_Failures.Clear(); @@ -148,10 +130,7 @@ namespace Server.Commands.Generic public override string ToString() { - if (m_Count > 1) - return $"{m_Message} ({m_Count})"; - - return m_Message; + return m_Count > 1 ? $"{m_Message} ({m_Count})" : m_Message; } } } diff --git a/Scripts/Commands/Generic/Commands/Commands.cs b/Scripts/Commands/Generic/Commands/Commands.cs index 6e008d91d..c69a1eea2 100644 --- a/Scripts/Commands/Generic/Commands/Commands.cs +++ b/Scripts/Commands/Generic/Commands/Commands.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using Server.Accounting; using Server.Engines.Help; @@ -91,7 +90,7 @@ namespace Server.Commands.Generic ListOptimized = true; } - public override void ExecuteList(CommandEventArgs e, ArrayList list) + public override void ExecuteList(CommandEventArgs e, List list) { try { @@ -184,7 +183,7 @@ namespace Server.Commands.Generic ListOptimized = true; } - public override void ExecuteList(CommandEventArgs e, ArrayList list) + public override void ExecuteList(CommandEventArgs e, List list) { if (list.Count == 1) AddResponse("There is one matching object."); @@ -205,13 +204,8 @@ namespace Server.Commands.Generic Description = "Opens the web browser of a targeted player to a specified url."; } - public static void OpenBrowser_Callback(Mobile from, bool okay, object state) + public static void OpenBrowser_Callback(Mobile from, bool okay, Mobile gm, string url, bool echo) { - object[] states = (object[])state; - Mobile gm = (Mobile)states[0]; - string url = (string)states[1]; - bool echo = (bool)states[2]; - if (okay) { if (echo) @@ -257,7 +251,7 @@ namespace Server.Commands.Generic mob.SendGump(new WarningGump(1060637, 30720, $"A game master is requesting to open your web browser to the following URL:
{url}", 0xFFC000, - 320, 240, OpenBrowser_Callback, new object[] { from, url, echo })); + 320, 240, okay => OpenBrowser_Callback(mob, okay, from, url, echo))); } } else @@ -276,7 +270,7 @@ namespace Server.Commands.Generic Execute(e, obj, true); } - public override void ExecuteList(CommandEventArgs e, ArrayList list) + public override void ExecuteList(CommandEventArgs e, List list) { for (int i = 0; i < list.Count; ++i) Execute(e, list[i], false); @@ -406,7 +400,7 @@ namespace Server.Commands.Generic "Adds an item by name to the backpack of a targeted player or npc, or a targeted container. Optional constructor parameters. Optional set property list."; } - public override void ExecuteList(CommandEventArgs e, ArrayList list) + public override void ExecuteList(CommandEventArgs e, List list) { if (e.Arguments.Length == 0) return; @@ -763,12 +757,8 @@ namespace Server.Commands.Generic Description = "Deletes a targeted item or mobile. Does not delete players."; } - private void OnConfirmCallback(Mobile from, bool okay, object state) + private void OnConfirmCallback(Mobile from, bool okay, CommandEventArgs e, List list) { - object[] states = (object[])state; - CommandEventArgs e = (CommandEventArgs)states[0]; - ArrayList list = (ArrayList)states[1]; - bool flushToLog = false; if (okay) @@ -798,13 +788,14 @@ namespace Server.Commands.Generic Flush(from, flushToLog); } - public override void ExecuteList(CommandEventArgs e, ArrayList list) + public override void ExecuteList(CommandEventArgs e, List list) { if (list.Count > 1) { - e.Mobile.SendGump(new WarningGump(1060637, 30720, + Mobile from = e.Mobile; + from.SendGump(new WarningGump(1060637, 30720, $"You are about to delete {list.Count} objects. This cannot be undone without a full server revert.

Continue?", - 0xFFC000, 420, 280, OnConfirmCallback, new object[] { e, list })); + 0xFFC000, 420, 280, okay => OnConfirmCallback(from, okay, e, list))); AddResponse("Awaiting confirmation..."); } else diff --git a/Scripts/Commands/Generic/Commands/DesignInsert.cs b/Scripts/Commands/Generic/Commands/DesignInsert.cs index 3111fd727..cae91d825 100644 --- a/Scripts/Commands/Generic/Commands/DesignInsert.cs +++ b/Scripts/Commands/Generic/Commands/DesignInsert.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using Server.Gumps; using Server.Items; @@ -103,8 +102,7 @@ namespace Server.Commands.Generic protected override void OnTarget(Mobile from, object obj) { - HouseFoundation house; - DesignInsertResult result = ProcessInsert(obj as Item, m_StaticsOnly, out house); + DesignInsertResult result = ProcessInsert(obj as Item, m_StaticsOnly, out HouseFoundation house); switch (result) { @@ -142,21 +140,17 @@ namespace Server.Commands.Generic #region Area targeting mode - public override void ExecuteList(CommandEventArgs e, ArrayList list) + public override void ExecuteList(CommandEventArgs e, List list) { - e.Mobile.SendGump(new WarningGump(1060637, 30720, + Mobile from = e.Mobile; + from.SendGump(new WarningGump(1060637, 30720, $"You are about to insert {list.Count} objects. This cannot be undone without a full server revert.

Continue?", - 0xFFC000, 420, 280, OnConfirmCallback, new object[] { e, list, e.Length < 1 || !e.GetBoolean(0) })); + 0xFFC000, 420, 280, okay => OnConfirmCallback(from, okay, list, e.Length < 1 || !e.GetBoolean(0)))); AddResponse("Awaiting confirmation..."); } - private void OnConfirmCallback(Mobile from, bool okay, object state) + private void OnConfirmCallback(Mobile from, bool okay, List list, bool staticsOnly) { - object[] states = (object[])state; - CommandEventArgs e = (CommandEventArgs)states[0]; - ArrayList list = (ArrayList)states[1]; - bool staticsOnly = (bool)states[2]; - bool flushToLog = false; if (okay) @@ -166,8 +160,7 @@ namespace Server.Commands.Generic for (int i = 0; i < list.Count; ++i) { - HouseFoundation house; - DesignInsertResult result = ProcessInsert(list[i] as Item, staticsOnly, out house); + DesignInsertResult result = ProcessInsert(list[i] as Item, staticsOnly, out HouseFoundation house); switch (result) { diff --git a/Scripts/Commands/Generic/Commands/Interface.cs b/Scripts/Commands/Generic/Commands/Interface.cs index 0969d3301..e602be9ae 100644 --- a/Scripts/Commands/Generic/Commands/Interface.cs +++ b/Scripts/Commands/Generic/Commands/Interface.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Gumps; @@ -20,13 +19,12 @@ namespace Server.Commands.Generic ListOptimized = true; } - public override void ExecuteList(CommandEventArgs e, ArrayList list) + public override void ExecuteList(CommandEventArgs e, List list) { if (list.Count > 0) { - List columns = new List(); + List columns = new List { "Object" }; - columns.Add("Object"); if (e.Length > 0) { @@ -55,12 +53,12 @@ namespace Server.Commands.Generic private string[] m_Columns; private Mobile m_From; - private ArrayList m_List; + private List m_List; private int m_Page; private object m_Select; - public InterfaceGump(Mobile from, string[] columns, ArrayList list, int page, object select) : base(30, 30) + public InterfaceGump(Mobile from, string[] columns, List list, int page, object select) : base(30, 30) { m_From = from; @@ -222,7 +220,7 @@ namespace Server.Commands.Generic if (!BaseCommand.IsAccessible(m_From, obj)) { - m_From.SendMessage("That is not accessible."); + m_From.SendLocalizedMessage(500447); // That is not accessible. m_From.SendGump(new InterfaceGump(m_From, m_Columns, m_List, m_Page, m_Select)); break; } @@ -248,10 +246,10 @@ namespace Server.Commands.Generic private Item m_Item; - private ArrayList m_List; + private List m_List; private int m_Page; - public InterfaceItemGump(Mobile from, string[] columns, ArrayList list, int page, Item item) : base(30, 30) + public InterfaceItemGump(Mobile from, string[] columns, List list, int page, Item item) : base(30, 30) { m_From = from; @@ -381,12 +379,12 @@ namespace Server.Commands.Generic private string[] m_Columns; private Mobile m_From; - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private int m_Page; - public InterfaceMobileGump(Mobile from, string[] columns, ArrayList list, int page, Mobile mob) + public InterfaceMobileGump(Mobile from, string[] columns, List list, int page, Mobile mob) : base(30, 30) { m_From = from; diff --git a/Scripts/Commands/Generic/Extensions/BaseExtension.cs b/Scripts/Commands/Generic/Extensions/BaseExtension.cs index ab1a40976..cb135e5a7 100644 --- a/Scripts/Commands/Generic/Extensions/BaseExtension.cs +++ b/Scripts/Commands/Generic/Extensions/BaseExtension.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; namespace Server.Commands.Generic @@ -48,7 +47,7 @@ namespace Server.Commands.Generic return true; } - public void Filter(ArrayList list) + public void Filter(List list) { for (int i = 0; i < Count; ++i) this[i].Filter(list); @@ -127,7 +126,7 @@ namespace Server.Commands.Generic return true; } - public virtual void Filter(ArrayList list) + public virtual void Filter(List list) { } } diff --git a/Scripts/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs b/Scripts/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs index d3fffe364..558bf3ef0 100644 --- a/Scripts/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs +++ b/Scripts/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs @@ -109,8 +109,8 @@ namespace Server.Commands.Generic } else { - MethodInfo parseMethod = null; - object[] parseArgs = null; + MethodInfo parseMethod; + object[] parseArgs; MethodInfo parseNumber = Type.GetMethod( "Parse", diff --git a/Scripts/Commands/Generic/Extensions/Compilers/DistinctCompiler.cs b/Scripts/Commands/Generic/Extensions/Compilers/DistinctCompiler.cs index 4c312e58a..b12cfac41 100644 --- a/Scripts/Commands/Generic/Extensions/Compilers/DistinctCompiler.cs +++ b/Scripts/Commands/Generic/Extensions/Compilers/DistinctCompiler.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; @@ -8,7 +7,7 @@ namespace Server.Commands.Generic { public static class DistinctCompiler { - public static IComparer Compile(AssemblyEmitter assembly, Type objectType, Property[] props) + public static IComparer Compile(AssemblyEmitter assembly, Type objectType, Property[] props) { TypeBuilder typeBuilder = assembly.DefineType( "__distinct", @@ -29,7 +28,8 @@ namespace Server.Commands.Generic // : base() il.Emit(OpCodes.Ldarg_0); - il.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes)); + il.Emit(OpCodes.Call, typeof(T).GetConstructor(Type.EmptyTypes) ?? + throw new Exception($"Could not find empty constructor for type {typeof(T).FullName}")); // return; il.Emit(OpCodes.Ret); @@ -39,7 +39,7 @@ namespace Server.Commands.Generic #region IComparer - typeBuilder.AddInterfaceImplementation(typeof(IComparer)); + typeBuilder.AddInterfaceImplementation(typeof(IComparer)); MethodBuilder compareMethod; @@ -52,7 +52,7 @@ namespace Server.Commands.Generic /* name */ "Compare", /* attr */ MethodAttributes.Public | MethodAttributes.Virtual, /* return */ typeof(int), - /* params */ new[] { typeof(object), typeof(object) }); + /* params */ new[] { typeof(T), typeof(T) }); LocalBuilder a = emitter.CreateLocal(objectType); LocalBuilder b = emitter.CreateLocal(objectType); @@ -105,14 +105,14 @@ namespace Server.Commands.Generic typeBuilder.DefineMethodOverride( emitter.Method, - typeof(IComparer).GetMethod( + typeof(IComparer).GetMethod( "Compare", new[] { - typeof(object), - typeof(object) + typeof(T), + typeof(T) } - ) + ) ?? throw new Exception($"No Compare method found for type {typeof(T).FullName}") ); compareMethod = emitter.Method; @@ -124,7 +124,7 @@ namespace Server.Commands.Generic #region IEqualityComparer - typeBuilder.AddInterfaceImplementation(typeof(IEqualityComparer)); + typeBuilder.AddInterfaceImplementation(typeof(IEqualityComparer)); #region Equals @@ -135,7 +135,7 @@ namespace Server.Commands.Generic /* name */ "Equals", /* attr */ MethodAttributes.Public | MethodAttributes.Virtual, /* return */ typeof(bool), - /* params */ new[] { typeof(object), typeof(object) }); + /* params */ new[] { typeof(T), typeof(T) }); emitter.Generator.Emit(OpCodes.Ldarg_0); emitter.Generator.Emit(OpCodes.Ldarg_1); @@ -151,14 +151,14 @@ namespace Server.Commands.Generic typeBuilder.DefineMethodOverride( emitter.Method, - typeof(IEqualityComparer).GetMethod( + typeof(IEqualityComparer).GetMethod( "Equals", new[] { - typeof(object), - typeof(object) + typeof(T), + typeof(T) } - ) + ) ?? throw new Exception($"No Equals method found for type {typeof(T).FullName}") ); } @@ -173,7 +173,7 @@ namespace Server.Commands.Generic /* name */ "GetHashCode", /* attr */ MethodAttributes.Public | MethodAttributes.Virtual, /* return */ typeof(int), - /* params */ new[] { typeof(object) }); + /* params */ new[] { typeof(T) }); LocalBuilder obj = emitter.CreateLocal(objectType); @@ -193,7 +193,7 @@ namespace Server.Commands.Generic MethodInfo getHashCode = active.GetMethod("GetHashCode", Type.EmptyTypes); if (getHashCode == null) - getHashCode = typeof(object).GetMethod("GetHashCode", Type.EmptyTypes); + getHashCode = typeof(T).GetMethod("GetHashCode", Type.EmptyTypes); if (active != typeof(int)) { @@ -237,13 +237,13 @@ namespace Server.Commands.Generic typeBuilder.DefineMethodOverride( emitter.Method, - typeof(IEqualityComparer).GetMethod( + typeof(IEqualityComparer).GetMethod( "GetHashCode", new[] { - typeof(object) + typeof(T) } - ) + ) ?? throw new Exception($"No GetHashCode method found for type {typeof(T).FullName}") ); } @@ -253,7 +253,7 @@ namespace Server.Commands.Generic Type comparerType = typeBuilder.CreateType(); - return (IComparer)Activator.CreateInstance(comparerType); + return (IComparer)Activator.CreateInstance(comparerType); } } } \ No newline at end of file diff --git a/Scripts/Commands/Generic/Extensions/Compilers/SortCompiler.cs b/Scripts/Commands/Generic/Extensions/Compilers/SortCompiler.cs index a21c055b5..d3dbaddec 100644 --- a/Scripts/Commands/Generic/Extensions/Compilers/SortCompiler.cs +++ b/Scripts/Commands/Generic/Extensions/Compilers/SortCompiler.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; @@ -45,12 +45,12 @@ namespace Server.Commands.Generic public static class SortCompiler { - public static IComparer Compile(AssemblyEmitter assembly, Type objectType, OrderInfo[] orders) + public static IComparer Compile(AssemblyEmitter assembly, Type objectType, OrderInfo[] orders) { TypeBuilder typeBuilder = assembly.DefineType( "__sort", TypeAttributes.Public, - typeof(object) + typeof(T) ); #region Constructor @@ -66,7 +66,8 @@ namespace Server.Commands.Generic // : base() il.Emit(OpCodes.Ldarg_0); - il.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes)); + il.Emit(OpCodes.Call, typeof(T).GetConstructor(Type.EmptyTypes) ?? + throw new Exception($"Could not find empty constructor for type {typeof(T).FullName}")); // return; il.Emit(OpCodes.Ret); @@ -76,12 +77,9 @@ namespace Server.Commands.Generic #region IComparer - typeBuilder.AddInterfaceImplementation(typeof(IComparer)); - - MethodBuilder compareMethod; + typeBuilder.AddInterfaceImplementation(typeof(IComparer)); #region Compare - { MethodEmitter emitter = new MethodEmitter(typeBuilder); @@ -89,7 +87,7 @@ namespace Server.Commands.Generic /* name */ "Compare", /* attr */ MethodAttributes.Public | MethodAttributes.Virtual, /* return */ typeof(int), - /* params */ new[] { typeof(object), typeof(object) }); + /* params */ new[] { typeof(T), typeof(T) }); LocalBuilder a = emitter.CreateLocal(objectType); LocalBuilder b = emitter.CreateLocal(objectType); @@ -145,17 +143,15 @@ namespace Server.Commands.Generic typeBuilder.DefineMethodOverride( emitter.Method, - typeof(IComparer).GetMethod( + typeof(IComparer).GetMethod( "Compare", new[] { - typeof(object), - typeof(object) + typeof(T), + typeof(T) } - ) + ) ?? throw new Exception($"No Compare method found for type {typeof(T).FullName}") ); - - compareMethod = emitter.Method; } #endregion @@ -163,8 +159,7 @@ namespace Server.Commands.Generic #endregion Type comparerType = typeBuilder.CreateType(); - - return (IComparer)Activator.CreateInstance(comparerType); + return (IComparer)Activator.CreateInstance(comparerType); } } } \ No newline at end of file diff --git a/Scripts/Commands/Generic/Extensions/DistinctExtension.cs b/Scripts/Commands/Generic/Extensions/DistinctExtension.cs index 263cc96b2..bc976c286 100644 --- a/Scripts/Commands/Generic/Extensions/DistinctExtension.cs +++ b/Scripts/Commands/Generic/Extensions/DistinctExtension.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; namespace Server.Commands.Generic @@ -9,7 +8,7 @@ namespace Server.Commands.Generic public static ExtensionInfo ExtInfo = new ExtensionInfo(30, "Distinct", -1, delegate { return new DistinctExtension(); }); - private IComparer m_Comparer; + private IComparer m_Comparer; private List m_Properties; @@ -39,7 +38,7 @@ namespace Server.Commands.Generic if (assembly == null) assembly = new AssemblyEmitter("__dynamic", false); - m_Comparer = DistinctCompiler.Compile(assembly, baseType, m_Properties.ToArray()); + m_Comparer = DistinctCompiler.Compile(assembly, baseType, m_Properties.ToArray()); } public override void Parse(Mobile from, string[] arguments, int offset, int size) @@ -57,12 +56,12 @@ namespace Server.Commands.Generic } } - public override void Filter(ArrayList list) + public override void Filter(List list) { if (m_Comparer == null) throw new InvalidOperationException("The extension must first be optimized."); - ArrayList copy = new ArrayList(list); + List copy = new List(list); copy.Sort(m_Comparer); diff --git a/Scripts/Commands/Generic/Extensions/LimitExtension.cs b/Scripts/Commands/Generic/Extensions/LimitExtension.cs index 37c88bc34..055c19689 100644 --- a/Scripts/Commands/Generic/Extensions/LimitExtension.cs +++ b/Scripts/Commands/Generic/Extensions/LimitExtension.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Commands.Generic { @@ -24,7 +24,7 @@ namespace Server.Commands.Generic throw new Exception("Limit cannot be less than zero."); } - public override void Filter(ArrayList list) + public override void Filter(List list) { if (list.Count > Limit) list.RemoveRange(Limit, list.Count - Limit); diff --git a/Scripts/Commands/Generic/Extensions/SortExtension.cs b/Scripts/Commands/Generic/Extensions/SortExtension.cs index 1652f652f..4988421cf 100644 --- a/Scripts/Commands/Generic/Extensions/SortExtension.cs +++ b/Scripts/Commands/Generic/Extensions/SortExtension.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; namespace Server.Commands.Generic @@ -8,7 +7,7 @@ namespace Server.Commands.Generic { public static ExtensionInfo ExtInfo = new ExtensionInfo(40, "Order", -1, () => new SortExtension()); - private IComparer m_Comparer; + private IComparer m_Comparer; private List m_Orders; @@ -38,7 +37,7 @@ namespace Server.Commands.Generic if (assembly == null) assembly = new AssemblyEmitter("__dynamic", false); - m_Comparer = SortCompiler.Compile(assembly, baseType, m_Orders.ToArray()); + m_Comparer = SortCompiler.Compile(assembly, baseType, m_Orders.ToArray()); } public override void Parse(Mobile from, string[] arguments, int offset, int size) @@ -93,7 +92,7 @@ namespace Server.Commands.Generic } } - public override void Filter(ArrayList list) + public override void Filter(List list) { if (m_Comparer == null) throw new InvalidOperationException("The extension must first be optimized."); diff --git a/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs index 850301e26..b4bcbc917 100644 --- a/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Commands.Generic { @@ -22,24 +22,18 @@ namespace Server.Commands.Generic public override void Process(Mobile from, BaseCommand command, string[] args) { - BoundingBoxPicker.Begin(from, OnTarget, new object[] { command, args }); + BoundingBoxPicker.Begin(from, (map, start, end) => OnTarget(from, map, start, end, command, args)); } - public void OnTarget(Mobile from, Map map, Point3D start, Point3D end, object state) + public void OnTarget(Mobile from, Map map, Point3D start, Point3D end, BaseCommand command, string[] args) { try { - object[] states = (object[])state; - BaseCommand command = (BaseCommand)states[0]; - string[] args = (string[])states[1]; - Rectangle2D rect = new Rectangle2D(start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1); Extensions ext = Extensions.Parse(from, ref args); - bool items, mobiles; - - if (!CheckObjectTypes(from, command, ext, out items, out mobiles)) + if (!CheckObjectTypes(from, command, ext, out bool items, out bool mobiles)) return; IPooledEnumerable eable; @@ -49,7 +43,9 @@ namespace Server.Commands.Generic else return; - ArrayList objs = new ArrayList(); + eable.Free(); + + List objs = new List(); foreach (IEntity obj in eable) { diff --git a/Scripts/Commands/Generic/Implementors/BaseCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/BaseCommandImplementor.cs index f7a68e580..13998b8cd 100644 --- a/Scripts/Commands/Generic/Implementors/BaseCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/BaseCommandImplementor.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Text; @@ -212,7 +211,7 @@ namespace Server.Commands.Generic bool flushToLog = false; - if (obj is ArrayList list) + if (obj is List list) { if (list.Count > 20) CommandLogging.Enabled = false; @@ -230,7 +229,7 @@ namespace Server.Commands.Generic else if (obj != null) { if (command.ListOptimized) - command.ExecuteList(e, new ArrayList { obj }); + command.ExecuteList(e, new List{ obj }); else command.Execute(e, obj); } diff --git a/Scripts/Commands/Generic/Implementors/ContainedCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/ContainedCommandImplementor.cs index 234d12236..e71bce6e5 100644 --- a/Scripts/Commands/Generic/Implementors/ContainedCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/ContainedCommandImplementor.cs @@ -1,7 +1,5 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; using Server.Items; using Server.Targeting; @@ -23,21 +21,17 @@ namespace Server.Commands.Generic { if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args))) from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, - new TargetStateCallback(OnTarget), new object[] { command, args }); + (m, targeted) => OnTarget(m, targeted, command, args)); } - public void OnTarget(Mobile from, object targeted, object state) + public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args) { if (!BaseCommand.IsAccessible(from, targeted)) { - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. return; } - object[] states = (object[])state; - BaseCommand command = (BaseCommand)states[0]; - string[] args = (string[])states[1]; - if (command.ObjectTypes == ObjectTypes.Mobiles) return; // sanity check @@ -60,10 +54,15 @@ namespace Server.Commands.Generic return; } - List list = cont.FindItemsByType().Where(item => ext.IsValid(item)).ToList(); + List list = new List(); - // TODO: Is there a way to avoid using ArrayList? - ext.Filter(new ArrayList(list)); + foreach (Item item in cont.FindItemsByType()) + { + if (ext.IsValid(item)) + list.Add(item); + } + + ext.Filter(list); RunCommand(from, list, command, args); } diff --git a/Scripts/Commands/Generic/Implementors/FacetCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/FacetCommandImplementor.cs index fca6cef90..b27f6184f 100644 --- a/Scripts/Commands/Generic/Implementors/FacetCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/FacetCommandImplementor.cs @@ -25,8 +25,7 @@ namespace Server.Commands.Generic if (map == null || map == Map.Internal) return; - impl.OnTarget(from, map, Point3D.Zero, new Point3D(map.Width - 1, map.Height - 1, 0), - new object[] { command, args }); + impl.OnTarget(from, map, Point3D.Zero, new Point3D(map.Width - 1, map.Height - 1, 0), command, args); } } } \ No newline at end of file diff --git a/Scripts/Commands/Generic/Implementors/GlobalCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/GlobalCommandImplementor.cs index 813b132cf..e68726237 100644 --- a/Scripts/Commands/Generic/Implementors/GlobalCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/GlobalCommandImplementor.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Commands.Generic { @@ -22,12 +22,10 @@ namespace Server.Commands.Generic { Extensions ext = Extensions.Parse(from, ref args); - bool items, mobiles; - - if (!CheckObjectTypes(from, command, ext, out items, out mobiles)) + if (!CheckObjectTypes(from, command, ext, out bool items, out bool mobiles)) return; - ArrayList list = new ArrayList(); + List list = new List(); if (items) foreach (Item item in World.Items.Values) diff --git a/Scripts/Commands/Generic/Implementors/IPAddressCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/IPAddressCommandImplementor.cs index 119f56450..d0d6f1bbe 100644 --- a/Scripts/Commands/Generic/Implementors/IPAddressCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/IPAddressCommandImplementor.cs @@ -1,6 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Net; using Server.Network; namespace Server.Commands.Generic @@ -24,9 +24,7 @@ namespace Server.Commands.Generic { Extensions ext = Extensions.Parse(from, ref args); - bool items, mobiles; - - if (!CheckObjectTypes(from, command, ext, out items, out mobiles)) + if (!CheckObjectTypes(from, command, ext, out bool _, out bool mobiles)) return; if (!mobiles) // sanity check @@ -35,8 +33,8 @@ namespace Server.Commands.Generic return; } - ArrayList list = new ArrayList(); - ArrayList addresses = new ArrayList(); + List list = new List(); + List addresses = new List(); List states = NetState.Instances; diff --git a/Scripts/Commands/Generic/Implementors/MultiCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/MultiCommandImplementor.cs index 8e40ecd6e..b3ac04af2 100644 --- a/Scripts/Commands/Generic/Implementors/MultiCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/MultiCommandImplementor.cs @@ -17,20 +17,16 @@ namespace Server.Commands.Generic { if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args))) from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, - new TargetStateCallback(OnTarget), new object[] { command, args }); + (m, targeted) => OnTarget(m, targeted, command, args)); } - public void OnTarget(Mobile from, object targeted, object state) + public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args) { - object[] states = (object[])state; - BaseCommand command = (BaseCommand)states[0]; - string[] args = (string[])states[1]; - if (!BaseCommand.IsAccessible(from, targeted)) { - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, - new TargetStateCallback(OnTarget), new object[] { command, args }); + (m, t) => OnTarget(m, t, command, args)); return; } @@ -38,7 +34,7 @@ namespace Server.Commands.Generic { case ObjectTypes.Both: { - if (!(targeted is Item) && !(targeted is Mobile)) + if (!(targeted is Item || targeted is Mobile)) { from.SendMessage("This command does not work on that."); return; @@ -70,8 +66,8 @@ namespace Server.Commands.Generic RunCommand(from, targeted, command, args); - from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, new TargetStateCallback(OnTarget), - new object[] { command, args }); + from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, + (m, t) => OnTarget(m, t, command, args)); } } } \ No newline at end of file diff --git a/Scripts/Commands/Generic/Implementors/ObjectConditional.cs b/Scripts/Commands/Generic/Implementors/ObjectConditional.cs index 1f587b8d9..f5fe4be24 100644 --- a/Scripts/Commands/Generic/Implementors/ObjectConditional.cs +++ b/Scripts/Commands/Generic/Implementors/ObjectConditional.cs @@ -81,7 +81,7 @@ namespace Server.Commands.Generic break; } - return ParseDirect(from, conditionArgs, 0, conditionArgs.Length); + return ParseDirect(from, conditionArgs, 0, conditionArgs?.Length ?? 0); } public static ObjectConditional ParseDirect(Mobile from, string[] args, int offset, int size) diff --git a/Scripts/Commands/Generic/Implementors/OnlineCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/OnlineCommandImplementor.cs index f07cf8dba..4d538f36e 100644 --- a/Scripts/Commands/Generic/Implementors/OnlineCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/OnlineCommandImplementor.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using Server.Network; @@ -24,9 +23,7 @@ namespace Server.Commands.Generic { Extensions ext = Extensions.Parse(from, ref args); - bool items, mobiles; - - if (!CheckObjectTypes(from, command, ext, out items, out mobiles)) + if (!CheckObjectTypes(from, command, ext, out bool _, out bool mobiles)) return; if (!mobiles) // sanity check @@ -35,7 +32,7 @@ namespace Server.Commands.Generic return; } - ArrayList list = new ArrayList(); + List list = new List(); List states = NetState.Instances; diff --git a/Scripts/Commands/Generic/Implementors/RangeCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/RangeCommandImplementor.cs index 1e7257817..a87999209 100644 --- a/Scripts/Commands/Generic/Implementors/RangeCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/RangeCommandImplementor.cs @@ -73,7 +73,7 @@ namespace Server.Commands.Generic Point3D start = new Point3D(from.X - range, from.Y - range, from.Z); Point3D end = new Point3D(from.X + range, from.Y + range, from.Z); - impl.OnTarget(from, map, start, end, new object[] { command, args }); + impl.OnTarget(from, map, start, end, command, args); } } } \ No newline at end of file diff --git a/Scripts/Commands/Generic/Implementors/RegionCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/RegionCommandImplementor.cs index 657072758..5739236f9 100644 --- a/Scripts/Commands/Generic/Implementors/RegionCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/RegionCommandImplementor.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Commands.Generic { @@ -22,14 +22,12 @@ namespace Server.Commands.Generic { Extensions ext = Extensions.Parse(from, ref args); - bool items, mobiles; - - if (!CheckObjectTypes(from, command, ext, out items, out mobiles)) + if (!CheckObjectTypes(from, command, ext, out bool _, out bool mobiles)) return; Region reg = from.Region; - ArrayList list = new ArrayList(); + List list = new List(); if (mobiles) { diff --git a/Scripts/Commands/Generic/Implementors/SerialCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/SerialCommandImplementor.cs index b300dd679..3a2bec21b 100644 --- a/Scripts/Commands/Generic/Implementors/SerialCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/SerialCommandImplementor.cs @@ -15,7 +15,7 @@ namespace Server.Commands.Generic { if (e.Length >= 2) { - Serial serial = e.GetInt32(0); + Serial serial = e.GetUInt32(0); object obj = null; diff --git a/Scripts/Commands/Generic/Implementors/SingleCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/SingleCommandImplementor.cs index 20342ca9a..bf8439168 100644 --- a/Scripts/Commands/Generic/Implementors/SingleCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/SingleCommandImplementor.cs @@ -38,21 +38,17 @@ namespace Server.Commands.Generic { if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args))) from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, - new TargetStateCallback(OnTarget), new object[] { command, args }); + (m, targeted) => OnTarget(m, targeted, command, args)); } - public void OnTarget(Mobile from, object targeted, object state) + public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args) { if (!BaseCommand.IsAccessible(from, targeted)) { - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. return; } - object[] states = (object[])state; - BaseCommand command = (BaseCommand)states[0]; - string[] args = (string[])states[1]; - switch (command.ObjectTypes) { case ObjectTypes.Both: diff --git a/Scripts/Commands/Handlers.cs b/Scripts/Commands/Handlers.cs index 9753f70d0..403e6a85e 100644 --- a/Scripts/Commands/Handlers.cs +++ b/Scripts/Commands/Handlers.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using System.Text; using Server.Commands.Generic; @@ -185,12 +184,10 @@ namespace Server.Commands } } - public static void DeleteList_Callback(Mobile from, bool okay, object state) + public static void DeleteList_Callback(Mobile from, bool okay, List list) { if (okay) { - List list = (List)state; - CommandLogging.WriteLine(from, "{0} {1} deleting {2} object{3}", from.AccessLevel, CommandLogging.Format(from), list.Count, list.Count == 1 ? "" : "s"); @@ -213,11 +210,12 @@ namespace Server.Commands [Description("Deletes all items and mobiles in your facet. Players and their inventory will not be deleted.")] public static void ClearFacet_OnCommand(CommandEventArgs e) { - Map map = e.Mobile.Map; + Mobile from = e.Mobile; + Map map = from.Map; if (map == null || map == Map.Internal) { - e.Mobile.SendMessage("You may not run that command here."); + from.SendMessage("You may not run that command here."); return; } @@ -233,17 +231,17 @@ namespace Server.Commands if (list.Count > 0) { - CommandLogging.WriteLine(e.Mobile, "{0} {1} starting facet clear of {2} ({3} object{4})", - e.Mobile.AccessLevel, CommandLogging.Format(e.Mobile), map, list.Count, list.Count == 1 ? "" : "s"); + CommandLogging.WriteLine(from, "{0} {1} starting facet clear of {2} ({3} object{4})", + from.AccessLevel, CommandLogging.Format(from), map, list.Count, list.Count == 1 ? "" : "s"); - e.Mobile.SendGump( + from.SendGump( new WarningGump(1060635, 30720, $"You are about to delete {list.Count} object{(list.Count == 1 ? "" : "s")} from this facet. Do you really wish to continue?", - 0xFFC000, 360, 260, DeleteList_Callback, list)); + 0xFFC000, 360, 260, okay => DeleteList_Callback(from, okay, list))); } else { - e.Mobile.SendMessage("There were no objects found to delete."); + from.SendMessage("There were no objects found to delete."); } } @@ -285,7 +283,7 @@ namespace Server.Commands } else if (obj is Mobile master && master.Player) { - ArrayList pets = new ArrayList(); + List pets = new List(); foreach (Mobile m in World.Mobiles.Values) if (m is BaseCreature bc) @@ -443,7 +441,7 @@ namespace Server.Commands { try { - int ser = e.GetInt32(0); + uint ser = e.GetUInt32(0); IEntity ent = World.FindEntity(ser); @@ -567,6 +565,7 @@ namespace Server.Commands } catch { + // ignored } from.SendMessage("Region name not found"); @@ -760,7 +759,7 @@ namespace Server.Commands { if (!BaseCommand.IsAccessible(from, targeted)) { - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. return; } diff --git a/Scripts/Commands/HelpInfo.cs b/Scripts/Commands/HelpInfo.cs index a450f80a1..92dd0e76b 100644 --- a/Scripts/Commands/HelpInfo.cs +++ b/Scripts/Commands/HelpInfo.cs @@ -243,7 +243,6 @@ namespace Server.Commands m_List = list; } - AddNewPage(); if (m_Page > 0) @@ -269,7 +268,6 @@ namespace Server.Commands if ((int)c.AccessLevel != last) { AddNewLine(); - AddEntryHtml(20 + OffsetSize + 160, Color(c.AccessLevel.ToString(), 0xFF0000)); AddEntryHeader(20); line++; @@ -278,9 +276,7 @@ namespace Server.Commands last = (int)c.AccessLevel; AddNewLine(); - AddEntryHtml(20 + OffsetSize + 160, c.Name); - AddEntryButton(20, ArrowRightID1, ArrowRightID2, 3 + i, ArrowRightWidth, ArrowRightHeight); } } @@ -295,7 +291,7 @@ namespace Server.Commands { case 0: { - m.CloseGump(typeof(CommandInfoGump)); + m.CloseGump(); break; } case 1: diff --git a/Scripts/Commands/Logging.cs b/Scripts/Commands/Logging.cs index 55b69d97f..76de569cb 100644 --- a/Scripts/Commands/Logging.cs +++ b/Scripts/Commands/Logging.cs @@ -36,6 +36,7 @@ namespace Server.Commands } catch { + // ignored } } @@ -87,6 +88,7 @@ namespace Server.Commands } catch { + // ignored } } diff --git a/Scripts/Commands/Profiling.cs b/Scripts/Commands/Profiling.cs index 022a6e47f..afb656428 100644 --- a/Scripts/Commands/Profiling.cs +++ b/Scripts/Commands/Profiling.cs @@ -1,6 +1,8 @@ using System; using System.Collections; +using System.Collections.Generic; using System.IO; +using System.Linq; using Server.Diagnostics; namespace Server.Commands @@ -52,6 +54,7 @@ namespace Server.Commands } catch { + // ignored } } @@ -80,6 +83,7 @@ namespace Server.Commands } catch { + // ignored } } @@ -89,37 +93,32 @@ namespace Server.Commands { using (StreamWriter op = new StreamWriter("objects.log")) { - Hashtable table = new Hashtable(); + Dictionary table = new Dictionary(); foreach (Item item in World.Items.Values) { Type type = item.GetType(); - object o = table[type]; - - if (o == null) - table[type] = 1; + if (table.ContainsKey(type)) + table[type] = 1 + table[type]; else - table[type] = 1 + (int)o; + table[type] = 1; } - ArrayList items = new ArrayList(table); - + List> items = table.ToList(); table.Clear(); foreach (Mobile m in World.Mobiles.Values) { Type type = m.GetType(); - object o = table[type]; - - if (o == null) - table[type] = 1; + if (table.ContainsKey(type)) + table[type] = 1 + table[type]; else - table[type] = 1 + (int)o; + table[type] = 1; } - ArrayList mobiles = new ArrayList(table); + List> mobiles = table.ToList(); items.Sort(new CountSorter()); mobiles.Sort(new CountSorter()); @@ -130,16 +129,16 @@ namespace Server.Commands op.WriteLine("# Items:"); - foreach (DictionaryEntry de in items) - op.WriteLine("{0}\t{1:F2}%\t{2}", de.Value, 100 * (int)de.Value / (double)World.Items.Count, de.Key); + items.ForEach(kvp => + op.WriteLine("{0}\t{1:F2}%\t{2}", kvp.Value, 100.0 * kvp.Value / World.Items.Count, kvp.Key)); op.WriteLine(); op.WriteLine(); op.WriteLine("#Mobiles:"); - foreach (DictionaryEntry de in mobiles) - op.WriteLine("{0}\t{1:F2}%\t{2}", de.Value, 100 * (int)de.Value / (double)World.Mobiles.Count, de.Key); + mobiles.ForEach(kvp => + op.WriteLine("{0}\t{1:F2}%\t{2}", kvp.Value, 100.0 * kvp.Value / World.Mobiles.Count, kvp.Key)); } e.Mobile.SendMessage("Object table has been generated. See the file : /objects.log"); @@ -149,7 +148,7 @@ namespace Server.Commands [Description("Generates a log file describing all items using expanded memory.")] public static void TraceExpanded_OnCommand(CommandEventArgs e) { - Hashtable typeTable = new Hashtable(); + Dictionary typeTable = new Dictionary(); foreach (Item item in World.Items.Values) { @@ -162,8 +161,10 @@ namespace Server.Commands do { - if (!(typeTable[itemType] is int[] countTable)) - typeTable[itemType] = countTable = new int[9]; + typeTable.TryGetValue(itemType, out int[] countTable); + + if (countTable == null) + countTable = new int[9]; if ((flags & ExpandFlag.Name) != 0) ++countTable[0]; @@ -213,16 +214,15 @@ namespace Server.Commands "Spawner" }; - ArrayList list = new ArrayList(typeTable); + List> list = typeTable.ToList(); - list.Sort(new CountSorter()); + list.Sort(new CountsSorter()); - foreach (DictionaryEntry de in list) + foreach (KeyValuePair kvp in list) { - Type itemType = de.Key as Type; - int[] countTable = de.Value as int[]; + int[] countTable = kvp.Value; - op.WriteLine("# {0}", itemType.FullName); + op.WriteLine("# {0}", kvp.Key.FullName); for (int i = 0; i < countTable.Length; ++i) if (countTable[i] > 0) @@ -234,6 +234,7 @@ namespace Server.Commands } catch { + // ignored } } @@ -242,7 +243,7 @@ namespace Server.Commands public static void TraceInternal_OnCommand(CommandEventArgs e) { int totalCount = 0; - Hashtable table = new Hashtable(); + Dictionary table = new Dictionary(); foreach (Item item in World.Items.Values) { @@ -252,7 +253,7 @@ namespace Server.Commands ++totalCount; Type type = item.GetType(); - int[] parms = (int[])table[type]; + int[] parms = table[type]; if (parms == null) table[type] = parms = new[] { 0, 0 }; @@ -269,12 +270,11 @@ namespace Server.Commands op.WriteLine(); op.WriteLine("Type\t\tCount\t\tAmount\t\tAvg. Amount"); - foreach (DictionaryEntry de in table) + foreach (KeyValuePair de in table) { - Type type = (Type)de.Key; - int[] parms = (int[])de.Value; + int[] parms = de.Value; - op.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3:F2}", type.Name, parms[0], parms[1], (double)parms[1] / parms[0]); + op.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3:F2}", de.Key.Name, parms[0], parms[1], (double)parms[1] / parms[0]); } } } @@ -291,7 +291,7 @@ namespace Server.Commands { try { - ArrayList types = new ArrayList(); + List types = new List(); using (BinaryReader bin = new BinaryReader(new FileStream(string.Format("Saves/{0}/{0}.tdb", type), FileMode.Open, FileAccess.Read, FileShare.Read))) @@ -304,7 +304,7 @@ namespace Server.Commands long total = 0; - Hashtable table = new Hashtable(); + Dictionary table = new Dictionary(); using (BinaryReader bin = new BinaryReader(new FileStream(string.Format("Saves/{0}/{0}.idx", type), FileMode.Open, FileAccess.Read, FileShare.Read))) @@ -317,16 +317,14 @@ namespace Server.Commands int serial = bin.ReadInt32(); long pos = bin.ReadInt64(); int length = bin.ReadInt32(); - Type objType = (Type)types[typeID]; + Type objType = types[typeID]; - while (objType != null && objType != typeof(object)) + while (objType != typeof(object)) { - object obj = table[objType]; - - if (obj == null) - table[objType] = length; + if (table.ContainsKey(objType)) + table[objType] = length + table[objType]; else - table[objType] = length + (int)obj; + table[objType] = length; objType = objType.BaseType; total += length; @@ -334,7 +332,7 @@ namespace Server.Commands } } - ArrayList list = new ArrayList(table); + List> list = table.ToList(); list.Sort(new CountSorter()); @@ -345,55 +343,46 @@ namespace Server.Commands op.WriteLine(); op.WriteLine(); - foreach (DictionaryEntry de in list) - op.WriteLine("{0}\t{1:F2}%\t{2}", de.Value, 100 * (int)de.Value / (double)total, de.Key); + list.ForEach(kvp => + op.WriteLine("{0}\t{1:F2}%\t{2}", kvp.Value, 100.0 * kvp.Value / total, kvp.Key)); } } catch { + // ignored } } - private class CountSorter : IComparer + private class CountSorter : IComparer> { - public int Compare(object x, object y) + public int Compare(KeyValuePair x, KeyValuePair y) { - DictionaryEntry a = (DictionaryEntry)x; - DictionaryEntry b = (DictionaryEntry)y; - - int aCount = GetCount(a.Value); - int bCount = GetCount(b.Value); + int aCount = x.Value; + int bCount = y.Value; int v = -aCount.CompareTo(bCount); - if (v == 0) - { - Type aType = (Type)a.Key; - Type bType = (Type)b.Key; + if (v != 0) + return v; - v = aType.FullName.CompareTo(bType.FullName); - } - - return v; + return x.Key.FullName.CompareTo(y.Key.FullName); } + } - private int GetCount(object obj) + private class CountsSorter : IComparer> + { + public int Compare(KeyValuePair x, KeyValuePair y) { - if (obj is int intObj) - return intObj; + int aCount = x.Value.Aggregate(0, (t, val) => t + val); + int bCount = y.Value.Aggregate(0, (t, val) => t + val); - if (obj is int[] list) - { - int total = 0; + int v = -aCount.CompareTo(bCount); - for (int i = 0; i < list.Length; ++i) - total += list[i]; + if (v != 0) + return v; - return total; - } - - return 0; + return x.Key.FullName.CompareTo(y.Key.FullName); } } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/Properties.cs b/Scripts/Commands/Properties.cs index f73ed389a..53070310d 100644 --- a/Scripts/Commands/Properties.cs +++ b/Scripts/Commands/Properties.cs @@ -8,6 +8,7 @@ using CPA = Server.CommandPropertyAttribute; namespace Server.Commands { + [Flags] public enum PropertyAccess { Read = 0x01, @@ -54,12 +55,12 @@ namespace Server.Commands { if (e.Length == 1) { - IEntity ent = World.FindEntity(e.GetInt32(0)); + IEntity ent = World.FindEntity(e.GetUInt32(0)); if (ent == null) e.Mobile.SendMessage("No object with that serial was found."); else if (!BaseCommand.IsAccessible(e.Mobile, ent)) - e.Mobile.SendMessage("That is not accessible."); + e.Mobile.SendLocalizedMessage(500447); // That is not accessible. else e.Mobile.SendGump(new PropertiesGump(e.Mobile, ent)); } @@ -394,7 +395,7 @@ namespace Server.Commands m_ParseParams[0] = value; - return method.Invoke(o, m_ParseParams); + return method?.Invoke(o, m_ParseParams); } private static bool IsNumeric(Type t) @@ -465,7 +466,7 @@ namespace Server.Commands } if (isSerial) // mutate back - toSet = (Serial)(int)toSet; + toSet = (Serial)(toSet ?? Serial.MinusOne); constructed = toSet; return null; @@ -549,7 +550,7 @@ namespace Server.Commands protected override void OnTarget(Mobile from, object o) { if (!BaseCommand.IsAccessible(from, o)) - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. else from.SendGump(new PropertiesGump(from, o)); } diff --git a/Scripts/Commands/Skills.cs b/Scripts/Commands/Skills.cs index c79056727..320ac9b44 100644 --- a/Scripts/Commands/Skills.cs +++ b/Scripts/Commands/Skills.cs @@ -22,8 +22,7 @@ namespace Server.Commands } else { - SkillName skill; - if (Enum.TryParse(arg.GetString(0), true, out skill)) + if (Enum.TryParse(arg.GetString(0), true, out SkillName skill)) arg.Mobile.Target = new SkillTarget(skill, arg.GetDouble(1)); else arg.Mobile.SendLocalizedMessage(1005631); // You have specified an invalid skill to set. @@ -50,8 +49,7 @@ namespace Server.Commands } else { - SkillName skill; - if (Enum.TryParse(arg.GetString(0), true, out skill)) + if (Enum.TryParse(arg.GetString(0), true, out SkillName skill)) arg.Mobile.Target = new SkillTarget(skill); else arg.Mobile.SendMessage("You have specified an invalid skill to get."); diff --git a/Scripts/Commands/Statics.cs b/Scripts/Commands/Statics.cs index f2ae92ddb..ee873143e 100644 --- a/Scripts/Commands/Statics.cs +++ b/Scripts/Commands/Statics.cs @@ -46,21 +46,25 @@ namespace Server CommandSystem.Register("UnfreezeWorld", AccessLevel.Administrator, UnfreezeWorld_OnCommand); } + public delegate void FreezeCallback( Mobile from, bool okay, StateInfo si ); + [Usage("Freeze")] [Description("Makes a targeted area of dynamic items static.")] public static void Freeze_OnCommand(CommandEventArgs e) { - BoundingBoxPicker.Begin(e.Mobile, FreezeBox_Callback, null); + Mobile from = e.Mobile; + BoundingBoxPicker.Begin(from, (map, start, end) => FreezeBox_Callback(from, map, start, end)); } [Usage("FreezeMap")] [Description("Makes every dynamic item in your map static.")] public static void FreezeMap_OnCommand(CommandEventArgs e) { - Map map = e.Mobile.Map; + Mobile from = e.Mobile; + Map map = from.Map; if (map != null && map != Map.Internal) - SendWarning(e.Mobile, "You are about to freeze all items in {0}.", BaseFreezeWarning, map, NullP3D, + SendWarning(from, "You are about to freeze all items in {0}.", BaseFreezeWarning, map, NullP3D, NullP3D, FreezeWarning_Callback); } @@ -73,31 +77,29 @@ namespace Server } public static void SendWarning(Mobile m, string header, string baseWarning, Map map, Point3D start, Point3D end, - WarningGumpCallback callback) + FreezeCallback callback) { m.SendGump(new WarningGump(1060635, 30720, string.Format(baseWarning, string.Format(header, map)), 0xFFC000, 420, - 400, callback, new StateInfo(map, start, end))); + 400, okay => callback(m, okay, new StateInfo(map, start, end)))); } - private static void FreezeBox_Callback(Mobile from, Map map, Point3D start, Point3D end, object state) + private static void FreezeBox_Callback(Mobile from, Map map, Point3D start, Point3D end) { SendWarning(from, "You are about to freeze a section of items.", BaseFreezeWarning, map, start, end, FreezeWarning_Callback); } - private static void FreezeWarning_Callback(Mobile from, bool okay, object state) + private static void FreezeWarning_Callback(Mobile from, bool okay, StateInfo si) { if (!okay) return; - StateInfo si = (StateInfo)state; - Freeze(from, si.m_Map, si.m_Start, si.m_End); } public static void Freeze(Mobile from, Map targetMap, Point3D start3d, Point3D end3d) { - Hashtable mapTable = new Hashtable(); + Dictionary> mapTable = new Dictionary>(); if (start3d == NullP3D && end3d == NullP3D) { @@ -123,14 +125,14 @@ namespace Server if (itemMap == null || itemMap == Map.Internal) continue; - Hashtable table = (Hashtable)mapTable[itemMap]; + Dictionary table = mapTable[itemMap]; if (table == null) - mapTable[itemMap] = table = new Hashtable(); + mapTable[itemMap] = table = new Dictionary(); Point2D p = new Point2D(item.X >> 3, item.Y >> 3); - DeltaState state = (DeltaState)table[p]; + DeltaState state = table[p]; if (state == null) table[p] = state = new DeltaState(p); @@ -157,14 +159,14 @@ namespace Server if (itemMap == null || itemMap == Map.Internal) continue; - Hashtable table = (Hashtable)mapTable[itemMap]; + Dictionary table = mapTable[itemMap]; if (table == null) - mapTable[itemMap] = table = new Hashtable(); + mapTable[itemMap] = table = new Dictionary(); Point2D p = new Point2D(item.X >> 3, item.Y >> 3); - DeltaState state = (DeltaState)table[p]; + DeltaState state = table[p]; if (state == null) table[p] = state = new DeltaState(p); @@ -179,7 +181,7 @@ namespace Server { from.SendGump(new NoticeGump(1060637, 30720, "No freezable items were found. Only the following item types are frozen:
- Static
- BaseFloor
- BaseWall", - 0xFFC000, 320, 240, null, null)); + 0xFFC000, 320, 240)); return; } @@ -187,10 +189,10 @@ namespace Server int totalFrozen = 0; - foreach (DictionaryEntry de in mapTable) + foreach (KeyValuePair> de in mapTable) { - Map map = (Map)de.Key; - Hashtable table = (Hashtable)de.Value; + Map map = de.Key; + Dictionary table = de.Value; TileMatrix matrix = map.Tiles; @@ -211,9 +213,8 @@ namespace Server foreach (DeltaState state in table.Values) { - int oldTileCount; StaticTile[] oldTiles = ReadStaticBlock(idxReader, mulStream, state.m_X, state.m_Y, - matrix.BlockWidth, matrix.BlockHeight, out oldTileCount); + matrix.BlockWidth, matrix.BlockHeight, out int oldTileCount); if (oldTileCount < 0) continue; @@ -296,18 +297,19 @@ namespace Server if (totalFrozen == 0 && badDataFile) from.SendGump(new NoticeGump(1060637, 30720, "Output data files could not be opened and the freeze operation has been aborted.

This probably means your server and client are using the same data files. Instructions on how to resolve this can be found in the first warning window.", - 0xFFC000, 320, 240, null, null)); + 0xFFC000, 320, 240)); else from.SendGump(new NoticeGump(1060637, 30720, $"Freeze operation completed successfully.

{totalFrozen} item{(totalFrozen != 1 ? "s were" : " was")} frozen.

You must restart your client and update it's data files to see the changes.", - 0xFFC000, 320, 240, null, null)); + 0xFFC000, 320, 240)); } [Usage("Unfreeze")] [Description("Makes a targeted area of static items dynamic.")] public static void Unfreeze_OnCommand(CommandEventArgs e) { - BoundingBoxPicker.Begin(e.Mobile, UnfreezeBox_Callback, null); + Mobile from = e.Mobile; + BoundingBoxPicker.Begin(from, (map, start, end) => UnfreezeBox_Callback(from, map, start, end)); } [Usage("UnfreezeMap")] @@ -329,19 +331,17 @@ namespace Server NullP3D, NullP3D, UnfreezeWarning_Callback); } - private static void UnfreezeBox_Callback(Mobile from, Map map, Point3D start, Point3D end, object state) + private static void UnfreezeBox_Callback(Mobile from, Map map, Point3D start, Point3D end) { SendWarning(from, "You are about to unfreeze a section of items.", BaseUnfreezeWarning, map, start, end, UnfreezeWarning_Callback); } - private static void UnfreezeWarning_Callback(Mobile from, bool okay, object state) + private static void UnfreezeWarning_Callback(Mobile from, bool okay, StateInfo si) { if (!okay) return; - StateInfo si = (StateInfo)state; - Unfreeze(from, si.m_Map, si.m_Start, si.m_End); } @@ -378,9 +378,8 @@ namespace Server for (int x = xStartBlock; x <= xEndBlock; ++x) for (int y = yStartBlock; y <= yEndBlock; ++y) { - int oldTileCount; StaticTile[] oldTiles = ReadStaticBlock(idxReader, mulStream, x, y, matrix.BlockWidth, - matrix.BlockHeight, out oldTileCount); + matrix.BlockHeight, out int oldTileCount); if (oldTileCount < 0) continue; @@ -493,11 +492,11 @@ namespace Server if (totalUnfrozen == 0 && badDataFile) from.SendGump(new NoticeGump(1060637, 30720, "Output data files could not be opened and the unfreeze operation has been aborted.

This probably means your server and client are using the same data files. Instructions on how to resolve this can be found in the first warning window.", - 0xFFC000, 320, 240, null, null)); + 0xFFC000, 320, 240)); else from.SendGump(new NoticeGump(1060637, 30720, $"Unfreeze operation completed successfully.

{totalUnfrozen} item{(totalUnfrozen != 1 ? "s were" : " was")} unfrozen.

You must restart your client and update it's data files to see the changes.", - 0xFFC000, 320, 240, null, null)); + 0xFFC000, 320, 240)); } private static FileStream OpenWrite(FileStream orig) @@ -580,7 +579,7 @@ namespace Server } } - private class StateInfo + public class StateInfo { public Map m_Map; public Point3D m_Start, m_End; @@ -593,4 +592,4 @@ namespace Server } } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/Wipe.cs b/Scripts/Commands/Wipe.cs index 259e65fbf..eec17443b 100644 --- a/Scripts/Commands/Wipe.cs +++ b/Scripts/Commands/Wipe.cs @@ -54,12 +54,7 @@ namespace Server.Commands public static void BeginWipe(Mobile from, WipeType type) { - BoundingBoxPicker.Begin(from, WipeBox_Callback, type); - } - - private static void WipeBox_Callback(Mobile from, Map map, Point3D start, Point3D end, object state) - { - DoWipe(from, map, start, end, (WipeType)state); + BoundingBoxPicker.Begin(from, (map, start, end) => DoWipe(from, map, start, end, type)); } public static void DoWipe(Mobile from, Map map, Point3D start, Point3D end, WipeType type) @@ -80,7 +75,7 @@ namespace Server.Commands if (!items && !multis || !mobiles) return; - eable = map.GetObjectsInBounds(rect, true, true); + eable = map.GetObjectsInBounds(rect); foreach (IEntity obj in eable) if (items && obj is Item && !(obj is BaseMulti || obj is HouseSign)) diff --git a/Scripts/Engines/BulkOrders/Books/BOBFilterGump.cs b/Scripts/Engines/BulkOrders/Books/BOBFilterGump.cs index aac526108..cf8a60051 100644 --- a/Scripts/Engines/BulkOrders/Books/BOBFilterGump.cs +++ b/Scripts/Engines/BulkOrders/Books/BOBFilterGump.cs @@ -74,8 +74,8 @@ namespace Server.Engines.BulkOrders public BOBFilterGump(PlayerMobile from, BulkOrderBook book) : base(12, 24) { - from.CloseGump(typeof(BOBGump)); - from.CloseGump(typeof(BOBFilterGump)); + from.CloseGump(); + from.CloseGump(); m_From = from; m_Book = book; diff --git a/Scripts/Engines/BulkOrders/Books/BOBGump.cs b/Scripts/Engines/BulkOrders/Books/BOBGump.cs index 12cb1cecd..84ee71da2 100644 --- a/Scripts/Engines/BulkOrders/Books/BOBGump.cs +++ b/Scripts/Engines/BulkOrders/Books/BOBGump.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Items; using Server.Mobiles; @@ -13,18 +13,14 @@ namespace Server.Engines.BulkOrders private const int LabelColor = 0x7FFF; private BulkOrderBook m_Book; private PlayerMobile m_From; - private ArrayList m_List; + private List m_List; private int m_Page; - public BOBGump(PlayerMobile from, BulkOrderBook book) : this(from, book, 0, null) + public BOBGump(PlayerMobile from, BulkOrderBook book, int page = 0, List list = null) : base(12, 24) { - } - - public BOBGump(PlayerMobile from, BulkOrderBook book, int page, ArrayList list) : base(12, 24) - { - from.CloseGump(typeof(BOBGump)); - from.CloseGump(typeof(BOBFilterGump)); + from.CloseGump(); + from.CloseGump(); m_From = from; m_Book = book; @@ -32,14 +28,14 @@ namespace Server.Engines.BulkOrders if (list == null) { - list = new ArrayList(book.Entries.Count); + list = new List(book.Entries.Count); for (int i = 0; i < book.Entries.Count; ++i) { - object obj = book.Entries[i]; + IBOBEntry entry = book.Entries[i]; - if (CheckFilter(obj)) - list.Add(obj); + if (CheckFilter(entry)) + list.Add(entry); } } @@ -92,17 +88,13 @@ namespace Server.Engines.BulkOrders for (int i = index; i < index + count && i >= 0 && i < list.Count; ++i) { - object obj = list[i]; + IBOBEntry entry = list[i]; - if (!CheckFilter(obj)) + if (!CheckFilter(entry)) continue; AddImageTiled(24, 94 + tableIndex * 32, canPrice ? 573 : 489, 2, 2624); - - if (obj is BOBLargeEntry entry) - tableIndex += entry.Entries.Length; - else - ++tableIndex; + tableIndex += entry is BOBLargeEntry largeEntry ? largeEntry.Entries.Length : 1; } AddAlphaRegion(18, 20, width - 17, 420); @@ -169,12 +161,12 @@ namespace Server.Engines.BulkOrders for (int i = index; i < index + count && i >= 0 && i < list.Count; ++i) { - object obj = list[i]; + IBOBEntry entry = list[i]; - if (!CheckFilter(obj)) + if (!CheckFilter(entry)) continue; - if (obj is BOBLargeEntry entry) + if (entry is BOBLargeEntry largeEntry) { int y = 96 + tableIndex * 32; @@ -189,9 +181,9 @@ namespace Server.Engines.BulkOrders AddHtmlLocalized(61, y, 50, 32, 1062225, LabelColor, false, false); // Large - for (int j = 0; j < entry.Entries.Length; ++j) + for (int j = 0; j < largeEntry.Entries.Length; ++j) { - BOBLargeSubEntry sub = entry.Entries[j]; + BOBLargeSubEntry sub = largeEntry.Entries[j]; AddHtmlLocalized(103, y, 130, 32, sub.Number, LabelColor, false, false); @@ -215,7 +207,7 @@ namespace Server.Engines.BulkOrders } else { - BOBSmallEntry smallEntry = (BOBSmallEntry)obj; + BOBSmallEntry smallEntry = (BOBSmallEntry)entry; int y = 96 + tableIndex++ * 32; @@ -249,26 +241,15 @@ namespace Server.Engines.BulkOrders } } - public Item Reconstruct(object obj) - { - Item item = null; - - if (obj is BOBLargeEntry entry) - item = entry.Reconstruct(); - else - item = ((BOBSmallEntry)obj).Reconstruct(); - - return item; - } - - public bool CheckFilter(object obj) - { - if (obj is BOBLargeEntry entry) + public bool CheckFilter(IBOBEntry entry) + { + if (entry is BOBLargeEntry largeEntry) return CheckFilter(entry.Material, entry.AmountMax, true, entry.RequireExceptional, entry.DeedType, - entry.Entries.Length > 0 ? entry.Entries[0].ItemType : null); - if (obj is BOBSmallEntry smallEntry) - return CheckFilter(smallEntry.Material, smallEntry.AmountMax, false, smallEntry.RequireExceptional, - smallEntry.DeedType, smallEntry.ItemType); + largeEntry.Entries.Length > 0 ? largeEntry.Entries[0].ItemType : null); + + if (entry is BOBSmallEntry smallEntry) + return CheckFilter(entry.Material, entry.AmountMax, false, entry.RequireExceptional, + entry.DeedType, smallEntry.ItemType); return false; } @@ -344,20 +325,15 @@ namespace Server.Engines.BulkOrders int slots = 0; int count = 0; - ArrayList list = m_List; + List list = m_List; for (int i = index; i >= 0 && i < list.Count; ++i) { - object obj = list[i]; + IBOBEntry entry = list[i]; - if (CheckFilter(obj)) + if (CheckFilter(entry)) { - int add; - - if (obj is BOBLargeEntry entry) - add = entry.Entries.Length; - else - add = 1; + int add = entry is BOBLargeEntry largeEntry ? largeEntry.Entries.Length : 1; if (slots + add > 10) break; @@ -377,52 +353,42 @@ namespace Server.Engines.BulkOrders return 0; int count = 0; - int add = 0; int page = 0; - ArrayList list = m_List; int i; - object obj; - + + List list = m_List; for (i = 0; i < index && i < list.Count; i++) { - obj = list[i]; - if (CheckFilter(obj)) + IBOBEntry entry = list[i]; + if (!CheckFilter(entry)) + continue; + + int add = entry is BOBLargeEntry largeEntry ? largeEntry.Entries.Length : 1; + count += add; + if (count > 10) { - if (obj is BOBLargeEntry entry) - add = entry.Entries.Length; - else - add = 1; - count += add; - if (count > 10) - { - page++; - count = add; - } + page++; + count = add; } } - /* now we are on the page of the bod preceeding the dropped one. + /* now we are on the page of the bod preceding the dropped one. * next step: checking whether we have to remain where we are. * The counter i needs to be incremented as the bod to this very moment * has not yet been removed from m_List */ i++; /* if, for instance, a big bod of size 6 has been removed, smaller bods - * might fall back into this page. Depending on their sizes, the page eeds + * might fall back into this page. Depending on their sizes, the page needs * to be adjusted accordingly. This is done now. */ if (count + sizeDropped > 10) { while (i < list.Count && count <= 10) { - obj = list[i]; - if (CheckFilter(obj)) - { - if (obj is BOBLargeEntry entry) - count += entry.Entries.Length; - else - count += 1; - } + IBOBEntry entry = list[i]; + if (CheckFilter(entry)) + count += entry is BOBLargeEntry largeEntry ? largeEntry.Entries.Length : 1; i++; } @@ -521,9 +487,6 @@ namespace Server.Engines.BulkOrders } default: { - bool canDrop = m_Book.IsChildOf(m_From.Backpack); - bool canPrice = canDrop || m_Book.RootParent is PlayerVendor; - index -= 5; int type = index % 2; @@ -532,9 +495,9 @@ namespace Server.Engines.BulkOrders if (index < 0 || index >= m_List.Count) break; - object obj = m_List[index]; + IBOBEntry bobEntry = m_List[index]; - if (!m_Book.Entries.Contains(obj)) + if (!m_Book.Entries.Contains(bobEntry)) { m_From.SendLocalizedMessage(1062382); // The deed selected is not available. break; @@ -544,54 +507,43 @@ namespace Server.Engines.BulkOrders { if (m_Book.IsChildOf(m_From.Backpack)) { - Item item = Reconstruct(obj); + Item item = bobEntry.Reconstruct(); - if (item != null) + Container pack = m_From.Backpack; + if (pack == null || !pack.CheckHold(m_From, item, true, true, 0, + item.PileWeight + item.TotalWeight)) { - Container pack = m_From.Backpack; - if (pack == null || !pack.CheckHold(m_From, item, true, true, 0, - item.PileWeight + item.TotalWeight)) - { - m_From.SendLocalizedMessage(503204); // You do not have room in your backpack for this - m_From.SendGump(new BOBGump(m_From, m_Book, m_Page, null)); - } - else - { - if (m_Book.IsChildOf(m_From.Backpack)) - { - int sizeOfDroppedBod; - if (obj is BOBLargeEntry entry) - sizeOfDroppedBod = entry.Entries.Length; - else - sizeOfDroppedBod = 1; - - m_From.AddToBackpack(item); - m_From.SendLocalizedMessage( - 1045152); // The bulk order deed has been placed in your backpack. - m_Book.Entries.Remove(obj); - m_Book.InvalidateProperties(); - - if (m_Book.Entries.Count / 5 < m_Book.ItemCount) - { - m_Book.ItemCount--; - m_Book.InvalidateItems(); - } - - if (m_Book.Entries.Count > 0) - { - m_Page = GetPageForIndex(index, sizeOfDroppedBod); - m_From.SendGump(new BOBGump(m_From, m_Book, m_Page, null)); - } - else - { - m_From.SendLocalizedMessage(1062381); // The book is empty. - } - } - } + m_From.SendLocalizedMessage(503204); // You do not have room in your backpack for this + m_From.SendGump(new BOBGump(m_From, m_Book, m_Page)); } else { - m_From.SendMessage("Internal error. The bulk order deed could not be reconstructed."); + if (m_Book.IsChildOf(m_From.Backpack)) + { + int sizeOfDroppedBod = bobEntry is BOBLargeEntry entry ? entry.Entries.Length : 1; + + m_From.AddToBackpack(item); + m_From.SendLocalizedMessage( + 1045152); // The bulk order deed has been placed in your backpack. + m_Book.Entries.Remove(bobEntry); + m_Book.InvalidateProperties(); + + if (m_Book.Entries.Count / 5 < m_Book.ItemCount) + { + m_Book.ItemCount--; + m_Book.InvalidateItems(); + } + + if (m_Book.Entries.Count > 0) + { + m_Page = GetPageForIndex(index, sizeOfDroppedBod); + m_From.SendGump(new BOBGump(m_From, m_Book, m_Page)); + } + else + { + m_From.SendLocalizedMessage(1062381); // The book is empty. + } + } } } } @@ -599,7 +551,7 @@ namespace Server.Engines.BulkOrders { if (m_Book.IsChildOf(m_From.Backpack)) { - m_From.Prompt = new SetPricePrompt(m_Book, obj, m_Page, m_List); + m_From.Prompt = new SetPricePrompt(m_Book, bobEntry, m_Page, m_List); m_From.SendLocalizedMessage(1062383); // Type in a price for the deed: } else if (m_Book.RootParent is PlayerVendor pv) @@ -608,18 +560,8 @@ namespace Server.Engines.BulkOrders if (vi != null && !vi.IsForSale) { - int sizeOfDroppedBod; - int price = 0; - if (obj is BOBLargeEntry entry) - { - price = entry.Price; - sizeOfDroppedBod = entry.Entries.Length; - } - else - { - price = ((BOBSmallEntry)obj).Price; - sizeOfDroppedBod = 1; - } + int sizeOfDroppedBod = bobEntry is BOBLargeEntry largeEntry ? largeEntry.Entries.Length : 1; + int price = bobEntry.Price; if (price == 0) { @@ -630,7 +572,7 @@ namespace Server.Engines.BulkOrders if (m_Book.Entries.Count > 0) { m_Page = GetPageForIndex(index, sizeOfDroppedBod); - m_From.SendGump(new BODBuyGump(m_From, m_Book, obj, m_Page, price)); + m_From.SendGump(new BODBuyGump(m_From, m_Book, bobEntry, m_Page, price)); } else { @@ -649,21 +591,21 @@ namespace Server.Engines.BulkOrders private class SetPricePrompt : Prompt { private BulkOrderBook m_Book; - private ArrayList m_List; - private object m_Object; + private List m_List; + private IBOBEntry m_Entry; private int m_Page; - public SetPricePrompt(BulkOrderBook book, object obj, int page, ArrayList list) + public SetPricePrompt(BulkOrderBook book, IBOBEntry entry, int page, List list) { m_Book = book; - m_Object = obj; + m_Entry = entry; m_Page = page; m_List = list; } public override void OnResponse(Mobile from, string text) { - if (m_Object != null && !m_Book.Entries.Contains(m_Object)) + if (m_Entry != null && !m_Book.Entries.Contains(m_Entry)) { from.SendLocalizedMessage(1062382); // The deed selected is not available. return; @@ -675,19 +617,16 @@ namespace Server.Engines.BulkOrders { from.SendLocalizedMessage(1062390); // The price you requested is outrageous! } - else if (m_Object == null) + else if (m_Entry == null) { for (int i = 0; i < m_List.Count; ++i) { - object obj = m_List[i]; + IBOBEntry entry = m_List[i]; - if (!m_Book.Entries.Contains(obj)) + if (!m_Book.Entries.Contains(entry)) continue; - - if (obj is BOBLargeEntry entry) - entry.Price = price; - else - ((BOBSmallEntry)obj).Price = price; + + entry.Price = price; } from.SendMessage("Deed prices set."); @@ -695,21 +634,10 @@ namespace Server.Engines.BulkOrders if (from is PlayerMobile mobile) mobile.SendGump(new BOBGump(mobile, m_Book, m_Page, m_List)); } - else if (m_Object is BOBLargeEntry entry) - { - entry.Price = price; - - from.SendLocalizedMessage(1062384); // Deed price set. - - if (from is PlayerMobile mobile) - mobile.SendGump(new BOBGump(mobile, m_Book, m_Page, m_List)); - } else { - ((BOBSmallEntry)m_Object).Price = price; - + m_Entry.Price = price; from.SendLocalizedMessage(1062384); // Deed price set. - if (from is PlayerMobile mobile) mobile.SendGump(new BOBGump(mobile, m_Book, m_Page, m_List)); } diff --git a/Scripts/Engines/BulkOrders/Books/BOBLargeEntry.cs b/Scripts/Engines/BulkOrders/Books/BOBLargeEntry.cs index 6c4497545..bb0135ae0 100644 --- a/Scripts/Engines/BulkOrders/Books/BOBLargeEntry.cs +++ b/Scripts/Engines/BulkOrders/Books/BOBLargeEntry.cs @@ -1,6 +1,6 @@ namespace Server.Engines.BulkOrders { - public class BOBLargeEntry + public class BOBLargeEntry: IBOBEntry { public BOBLargeEntry(LargeBOD bod) { @@ -80,8 +80,7 @@ namespace Server.Engines.BulkOrders for (int i = 0; i < Entries.Length; ++i) { entries[i] = new LargeBulkEntry(null, - new SmallBulkEntry(Entries[i].ItemType, Entries[i].Number, Entries[i].Graphic)); - entries[i].Amount = Entries[i].AmountCur; + new SmallBulkEntry(Entries[i].ItemType, Entries[i].Number, Entries[i].Graphic)) { Amount = Entries[i].AmountCur }; } return entries; diff --git a/Scripts/Engines/BulkOrders/Books/BOBSmallEntry.cs b/Scripts/Engines/BulkOrders/Books/BOBSmallEntry.cs index 3a4f9f149..789dc5913 100644 --- a/Scripts/Engines/BulkOrders/Books/BOBSmallEntry.cs +++ b/Scripts/Engines/BulkOrders/Books/BOBSmallEntry.cs @@ -2,7 +2,7 @@ using System; namespace Server.Engines.BulkOrders { - public class BOBSmallEntry + public class BOBSmallEntry : IBOBEntry { public BOBSmallEntry(SmallBOD bod) { diff --git a/Scripts/Engines/BulkOrders/Books/BODBuyGump.cs b/Scripts/Engines/BulkOrders/Books/BODBuyGump.cs index 64e232682..ecbab7d84 100644 --- a/Scripts/Engines/BulkOrders/Books/BODBuyGump.cs +++ b/Scripts/Engines/BulkOrders/Books/BODBuyGump.cs @@ -9,15 +9,15 @@ namespace Server.Engines.BulkOrders { private BulkOrderBook m_Book; private PlayerMobile m_From; - private object m_Object; + private IBOBEntry m_Entry; private int m_Page; private int m_Price; - public BODBuyGump(PlayerMobile from, BulkOrderBook book, object obj, int page, int price) : base(100, 200) + public BODBuyGump(PlayerMobile from, BulkOrderBook book, IBOBEntry entry, int page, int price) : base(100, 200) { m_From = from; m_Book = book; - m_Object = obj; + m_Entry = entry; m_Price = price; m_Page = page; @@ -40,100 +40,83 @@ namespace Server.Engines.BulkOrders public override void OnResponse(NetState sender, RelayInfo info) { - if (info.ButtonID == 2) + if (info.ButtonID != 2) { - PlayerVendor pv = m_Book.RootParent as PlayerVendor; + m_From.SendLocalizedMessage(503207); // Cancelled purchase. + return; + } - if (m_Book.Entries.Contains(m_Object) && pv != null) - { - int price = 0; + if (!(m_Book.RootParent is PlayerVendor pv)) + { + m_From.SendLocalizedMessage(1062382); // The deed selected is not available. + return; + } - VendorItem vi = pv.GetVendorItem(m_Book); + if (!m_Book.Entries.Contains(m_Entry)) + { + pv.SayTo(m_From, 1062382); // The deed selected is not available. + return; + } + + int price = 0; - if (vi != null && !vi.IsForSale) - { - if (m_Object is BOBLargeEntry entry) - price = entry.Price; - else - price = ((BOBSmallEntry)m_Object).Price; - } + VendorItem vi = pv.GetVendorItem(m_Book); - if (price != m_Price) - { - pv.SayTo(m_From, - "The price has been been changed. If you like, you may offer to purchase the item again."); - } - else if (price == 0) - { - pv.SayTo(m_From, 1062382); // The deed selected is not available. - } - else - { - Item item = null; + if (vi != null && !vi.IsForSale) + price = m_Entry.Price; - if (m_Object is BOBLargeEntry entry) - item = entry.Reconstruct(); - else - item = ((BOBSmallEntry)m_Object).Reconstruct(); + if (price != m_Price) + { + pv.SayTo(m_From, + "The price has been been changed. If you like, you may offer to purchase the item again."); + return; + } - if (item == null) - { - m_From.SendMessage("Internal error. The bulk order deed could not be reconstructed."); - } - else - { - pv.Say(m_From.Name); + if (price == 0) + { + pv.SayTo(m_From, 1062382); // The deed selected is not available. + return; + } - Container pack = m_From.Backpack; + Item item = m_Entry.Reconstruct(); + + pv.Say(m_From.Name); - if (pack == null || !pack.CheckHold(m_From, item, true, true, 0, - item.PileWeight + item.TotalWeight)) - { - pv.SayTo(m_From, 503204); // You do not have room in your backpack for this - m_From.SendGump(new BOBGump(m_From, m_Book, m_Page, null)); - } - else - { - if (pack.ConsumeTotal(typeof(Gold), price) || Banker.Withdraw(m_From, price)) - { - m_Book.Entries.Remove(m_Object); - m_Book.InvalidateProperties(); - pv.HoldGold += price; - m_From.AddToBackpack(item); - m_From.SendLocalizedMessage( - 1045152); // The bulk order deed has been placed in your backpack. + Container pack = m_From.Backpack; - if (m_Book.Entries.Count / 5 < m_Book.ItemCount) - { - m_Book.ItemCount--; - m_Book.InvalidateItems(); - } - - if (m_Book.Entries.Count > 0) - m_From.SendGump(new BOBGump(m_From, m_Book, m_Page, null)); - else - m_From.SendLocalizedMessage(1062381); // The book is empty. - } - else - { - pv.SayTo(m_From, 503205); // You cannot afford this item. - item.Delete(); - } - } - } - } - } - else - { - if (pv == null) - m_From.SendLocalizedMessage(1062382); // The deed selected is not available. - else - pv.SayTo(m_From, 1062382); // The deed selected is not available. - } + if (pack == null || !pack.CheckHold(m_From, item, true, true, 0, + item.PileWeight + item.TotalWeight)) + { + pv.SayTo(m_From, 503204); // You do not have room in your backpack for this + m_From.SendGump(new BOBGump(m_From, m_Book, m_Page)); } else { - m_From.SendLocalizedMessage(503207); // Cancelled purchase. + if (pack.ConsumeTotal(typeof(Gold), price) || Banker.Withdraw(m_From, price)) + { + m_Book.Entries.Remove(m_Entry); + m_Book.InvalidateProperties(); + pv.HoldGold += price; + m_From.AddToBackpack(item); + m_From.SendLocalizedMessage( + 1045152); // The bulk order deed has been placed in your backpack. + + if (m_Book.Entries.Count / 5 < m_Book.ItemCount) + { + m_Book.ItemCount--; + m_Book.InvalidateItems(); + } + + if (m_Book.Entries.Count > 0) + m_From.SendGump(new BOBGump(m_From, m_Book, m_Page)); + else + m_From.SendLocalizedMessage(1062381); // The book is empty. + } + else + { + pv.SayTo(m_From, 503205); // You cannot afford this item. + item.Delete(); + } } } } diff --git a/Scripts/Engines/BulkOrders/Books/BulkOrderBook.cs b/Scripts/Engines/BulkOrders/Books/BulkOrderBook.cs index 0a4c3b5ea..49dc2285e 100644 --- a/Scripts/Engines/BulkOrders/Books/BulkOrderBook.cs +++ b/Scripts/Engines/BulkOrders/Books/BulkOrderBook.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections; using System.Collections.Generic; using Server.Gumps; using Server.Multis; @@ -24,7 +22,7 @@ namespace Server.Engines.BulkOrders [CommandProperty( AccessLevel.GameMaster )] public SecureLevel Level { get; set; } - public ArrayList Entries { get; private set; } + public List Entries { get; private set; } public BOBFilter Filter { get; private set; } @@ -36,7 +34,7 @@ namespace Server.Engines.BulkOrders Weight = 1.0; LootType = LootType.Blessed; - Entries = new ArrayList(); + Entries = new List(); Filter = new BOBFilter(); Level = SecureLevel.CoOwners; @@ -73,9 +71,9 @@ namespace Server.Engines.BulkOrders SecureTrade trade = cont.Trade; if ( trade != null && trade.From.Mobile == from ) - trade.To.Mobile.SendGump( new BOBGump( (PlayerMobile)(trade.To.Mobile), this ) ); + trade.To.Mobile.SendGump( new BOBGump( (PlayerMobile)trade.To.Mobile, this ) ); else if ( trade != null && trade.To.Mobile == from ) - trade.From.Mobile.SendGump( new BOBGump( (PlayerMobile)(trade.From.Mobile), this ) ); + trade.From.Mobile.SendGump( new BOBGump( (PlayerMobile)trade.From.Mobile, this ) ); } } } @@ -216,7 +214,7 @@ namespace Server.Engines.BulkOrders int count = reader.ReadEncodedInt(); - Entries = new ArrayList( count ); + Entries = new List( count ); for ( int i = 0; i < count; ++i ) { @@ -240,7 +238,7 @@ namespace Server.Engines.BulkOrders list.Add( 1062344, Entries.Count.ToString() ); // Deeds in book: ~1_val~ - if ( m_BookName != null && m_BookName.Length > 0 ) + if ( !string.IsNullOrEmpty(m_BookName) ) list.Add( 1062481, m_BookName ); // Book Name: ~1_val~ } diff --git a/Scripts/Engines/BulkOrders/Books/IBOBEntry.cs b/Scripts/Engines/BulkOrders/Books/IBOBEntry.cs new file mode 100644 index 000000000..71dd7c2f7 --- /dev/null +++ b/Scripts/Engines/BulkOrders/Books/IBOBEntry.cs @@ -0,0 +1,12 @@ +namespace Server.Engines.BulkOrders +{ + public interface IBOBEntry + { + bool RequireExceptional{ get; } + BODType DeedType{ get; } + BulkMaterialType Material{ get; } + int AmountMax{ get; } + int Price{ get; set; } + Item Reconstruct(); + } +} \ No newline at end of file diff --git a/Scripts/Engines/BulkOrders/LargeBODAcceptGump.cs b/Scripts/Engines/BulkOrders/LargeBODAcceptGump.cs index e5619b07a..91815312d 100644 --- a/Scripts/Engines/BulkOrders/LargeBODAcceptGump.cs +++ b/Scripts/Engines/BulkOrders/LargeBODAcceptGump.cs @@ -13,8 +13,8 @@ namespace Server.Engines.BulkOrders m_From = from; m_Deed = deed; - m_From.CloseGump(typeof(LargeBODAcceptGump)); - m_From.CloseGump(typeof(SmallBODAcceptGump)); + m_From.CloseGump(); + m_From.CloseGump(); LargeBulkEntry[] entries = deed.Entries; diff --git a/Scripts/Engines/BulkOrders/LargeBODGump.cs b/Scripts/Engines/BulkOrders/LargeBODGump.cs index e7d992fb0..35792ff5a 100644 --- a/Scripts/Engines/BulkOrders/LargeBODGump.cs +++ b/Scripts/Engines/BulkOrders/LargeBODGump.cs @@ -13,8 +13,8 @@ namespace Server.Engines.BulkOrders m_From = from; m_Deed = deed; - m_From.CloseGump(typeof(LargeBODGump)); - m_From.CloseGump(typeof(SmallBODGump)); + m_From.CloseGump(); + m_From.CloseGump(); LargeBulkEntry[] entries = deed.Entries; diff --git a/Scripts/Engines/BulkOrders/Rewards.cs b/Scripts/Engines/BulkOrders/Rewards.cs index 11977639c..6a6feefda 100644 --- a/Scripts/Engines/BulkOrders/Rewards.cs +++ b/Scripts/Engines/BulkOrders/Rewards.cs @@ -691,7 +691,7 @@ namespace Server.Engines.BulkOrders switch (Utility.Random(4)) { default: - case 0: return new SmallStretchedHideEastDeed(); + return new SmallStretchedHideEastDeed(); case 1: return new SmallStretchedHideSouthDeed(); case 2: return new MediumStretchedHideEastDeed(); case 3: return new MediumStretchedHideSouthDeed(); @@ -703,7 +703,7 @@ namespace Server.Engines.BulkOrders switch (Utility.Random(4)) { default: - case 0: return new LightFlowerTapestryEastDeed(); + return new LightFlowerTapestryEastDeed(); case 1: return new LightFlowerTapestrySouthDeed(); case 2: return new DarkFlowerTapestryEastDeed(); case 3: return new DarkFlowerTapestrySouthDeed(); @@ -715,7 +715,7 @@ namespace Server.Engines.BulkOrders switch (Utility.Random(4)) { default: - case 0: return new BrownBearRugEastDeed(); + return new BrownBearRugEastDeed(); case 1: return new BrownBearRugSouthDeed(); case 2: return new PolarBearRugEastDeed(); case 3: return new PolarBearRugSouthDeed(); diff --git a/Scripts/Engines/BulkOrders/SmallBODAcceptGump.cs b/Scripts/Engines/BulkOrders/SmallBODAcceptGump.cs index 93aff2b86..21260cafb 100644 --- a/Scripts/Engines/BulkOrders/SmallBODAcceptGump.cs +++ b/Scripts/Engines/BulkOrders/SmallBODAcceptGump.cs @@ -13,8 +13,8 @@ namespace Server.Engines.BulkOrders m_From = from; m_Deed = deed; - m_From.CloseGump(typeof(LargeBODAcceptGump)); - m_From.CloseGump(typeof(SmallBODAcceptGump)); + m_From.CloseGump(); + m_From.CloseGump(); AddPage(0); diff --git a/Scripts/Engines/BulkOrders/SmallBODGump.cs b/Scripts/Engines/BulkOrders/SmallBODGump.cs index d9cc254c2..10f0125d1 100644 --- a/Scripts/Engines/BulkOrders/SmallBODGump.cs +++ b/Scripts/Engines/BulkOrders/SmallBODGump.cs @@ -13,8 +13,8 @@ namespace Server.Engines.BulkOrders m_From = from; m_Deed = deed; - m_From.CloseGump(typeof(LargeBODGump)); - m_From.CloseGump(typeof(SmallBODGump)); + m_From.CloseGump(); + m_From.CloseGump(); AddPage(0); diff --git a/Scripts/Engines/BulkOrders/SmallSmithBOD.cs b/Scripts/Engines/BulkOrders/SmallSmithBOD.cs index 06ace1322..6053a358d 100644 --- a/Scripts/Engines/BulkOrders/SmallSmithBOD.cs +++ b/Scripts/Engines/BulkOrders/SmallSmithBOD.cs @@ -141,7 +141,7 @@ namespace Server.Engines.BulkOrders if (entries.Length > 0) { - double theirSkill = m.Skills[SkillName.Blacksmith].Base; + double theirSkill = m.Skills.Blacksmith.Base; int amountMax; if (theirSkill >= 70.1) diff --git a/Scripts/Engines/BulkOrders/SmallTailorBOD.cs b/Scripts/Engines/BulkOrders/SmallTailorBOD.cs index 7d5ddf3bf..2015e1f7f 100644 --- a/Scripts/Engines/BulkOrders/SmallTailorBOD.cs +++ b/Scripts/Engines/BulkOrders/SmallTailorBOD.cs @@ -127,7 +127,7 @@ namespace Server.Engines.BulkOrders SmallBulkEntry[] entries; bool useMaterials = Utility.RandomBool(); - double theirSkill = m.Skills[SkillName.Tailoring].Base; + double theirSkill = m.Skills.Tailoring.Base; if (useMaterials && theirSkill >= 6.2 ) // Ugly, but the easiest leather BOD is Leather Cap which requires at least 6.2 skill. entries = SmallBulkEntry.TailorLeather; diff --git a/Scripts/Engines/CannedEvil/ChampionSpawn.cs b/Scripts/Engines/CannedEvil/ChampionSpawn.cs index 1fb2ecfab..b272337b9 100644 --- a/Scripts/Engines/CannedEvil/ChampionSpawn.cs +++ b/Scripts/Engines/CannedEvil/ChampionSpawn.cs @@ -393,6 +393,7 @@ namespace Server.Engines.CannedEvil } catch { + // ignored } } } @@ -769,7 +770,6 @@ namespace Server.Engines.CannedEvil switch (index) { default: - case 0: x = -1; y = -1; break; diff --git a/Scripts/Engines/ConPVP/AcceptDuelGump.cs b/Scripts/Engines/ConPVP/AcceptDuelGump.cs index 1bd265942..9086e72bc 100644 --- a/Scripts/Engines/ConPVP/AcceptDuelGump.cs +++ b/Scripts/Engines/ConPVP/AcceptDuelGump.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Mobiles; using Server.Network; @@ -11,7 +11,7 @@ namespace Server.Engines.ConPVP private const int LabelColor32 = 0xFFFFFF; private const int BlackColor32 = 0x000008; - private static Hashtable m_IgnoreLists = new Hashtable(); + private static Dictionary> m_IgnoreLists = new Dictionary>(); private bool m_Active = true; private Mobile m_Challenger, m_Challenged; @@ -28,7 +28,7 @@ namespace Server.Engines.ConPVP m_Participant = p; m_Slot = slot; - challenged.CloseGump(typeof(AcceptDuelGump)); + challenged.CloseGump(); Closable = false; @@ -109,7 +109,7 @@ namespace Server.Engines.ConPVP m_Active = false; - m_Challenged.CloseGump(typeof(AcceptDuelGump)); + m_Challenged.CloseGump(); m_Challenger.SendMessage("{0} seems unresponsive.", m_Challenged.Name); m_Challenged.SendMessage("You decline the challenge."); @@ -117,14 +117,14 @@ namespace Server.Engines.ConPVP public static void BeginIgnore(Mobile source, Mobile toIgnore) { - ArrayList list = (ArrayList)m_IgnoreLists[source]; + List list = m_IgnoreLists[source]; if (list == null) - m_IgnoreLists[source] = list = new ArrayList(); + m_IgnoreLists[source] = list = new List(); for (int i = 0; i < list.Count; ++i) { - IgnoreEntry ie = (IgnoreEntry)list[i]; + IgnoreEntry ie = list[i]; if (ie.Ignored == toIgnore) { @@ -132,7 +132,8 @@ namespace Server.Engines.ConPVP return; } - if (ie.Expired) list.RemoveAt(i--); + if (ie.Expired) + list.RemoveAt(i--); } list.Add(new IgnoreEntry(toIgnore)); @@ -140,14 +141,14 @@ namespace Server.Engines.ConPVP public static bool IsIgnored(Mobile source, Mobile check) { - ArrayList list = (ArrayList)m_IgnoreLists[source]; + List list = m_IgnoreLists[source]; if (list == null) return false; for (int i = 0; i < list.Count; ++i) { - IgnoreEntry ie = (IgnoreEntry)list[i]; + IgnoreEntry ie = list[i]; if (ie.Expired) list.RemoveAt(i--); diff --git a/Scripts/Engines/ConPVP/Arena.cs b/Scripts/Engines/ConPVP/Arena.cs index f2ec33fff..88e98f2a2 100644 --- a/Scripts/Engines/ConPVP/Arena.cs +++ b/Scripts/Engines/ConPVP/Arena.cs @@ -8,15 +8,13 @@ namespace Server.Engines.ConPVP { public class ArenaController : Item { - private Arena m_Arena; - [Constructible] public ArenaController() : base(0x1B7A) { Visible = false; Movable = false; - m_Arena = new Arena(); + Arena = new Arena(); Instances.Add(this); } @@ -26,11 +24,7 @@ namespace Server.Engines.ConPVP } [CommandProperty(AccessLevel.GameMaster)] - public Arena Arena - { - get => m_Arena; - set { } - } + public Arena Arena{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] public bool IsPrivate{ get; set; } @@ -44,13 +38,13 @@ namespace Server.Engines.ConPVP base.OnDelete(); Instances.Remove(this); - m_Arena.Delete(); + Arena.Delete(); } public override void OnDoubleClick(Mobile from) { if (from.AccessLevel >= AccessLevel.GameMaster) - from.SendGump(new PropertiesGump(from, m_Arena)); + from.SendGump(new PropertiesGump(from, Arena)); } public override void Serialize(GenericWriter writer) @@ -61,7 +55,7 @@ namespace Server.Engines.ConPVP writer.Write(IsPrivate); - m_Arena.Serialize(writer); + Arena.Serialize(writer); } public override void Deserialize(GenericReader reader) @@ -80,7 +74,7 @@ namespace Server.Engines.ConPVP } case 0: { - m_Arena = new Arena(reader); + Arena = new Arena(reader); break; } } @@ -191,7 +185,6 @@ namespace Server.Engines.ConPVP private bool m_IsGuarded; private string m_Name; - private ArenaStartPoints m_Points; private SafeZone m_Region; @@ -200,7 +193,7 @@ namespace Server.Engines.ConPVP public Arena() { - m_Points = new ArenaStartPoints(); + Points = new ArenaStartPoints(); Players = new List(); } @@ -269,7 +262,7 @@ namespace Server.Engines.ConPVP } m_Active = reader.ReadBool(); - m_Points = new ArenaStartPoints(reader); + Points = new ArenaStartPoints(reader); if (m_Active) { @@ -425,11 +418,7 @@ namespace Server.Engines.ConPVP public bool IsOccupied => Players.Count > 0; [CommandProperty(AccessLevel.GameMaster)] - public ArenaStartPoints Points - { - get => m_Points; - set { } - } + public ArenaStartPoints Points{ get; private set; } public Item Teleporter{ get; set; } @@ -514,7 +503,7 @@ namespace Server.Engines.ConPVP if (index < 0) index = 0; - return m_Points.Points[index % m_Points.Points.Length]; + return Points.Points[index % Points.Points.Length]; } public void MoveInside(DuelPlayer[] players, int index) @@ -522,7 +511,7 @@ namespace Server.Engines.ConPVP if (index < 0) index = 0; else - index %= m_Points.Points.Length; + index %= Points.Points.Length; Point3D start = GetBaseStartPoint(index); @@ -652,7 +641,7 @@ namespace Server.Engines.ConPVP writer.Write(Wall); writer.Write(m_Active); - m_Points.Serialize(writer); + Points.Serialize(writer); } public static Arena FindArena(List players) diff --git a/Scripts/Engines/ConPVP/DuelContext.cs b/Scripts/Engines/ConPVP/DuelContext.cs index 98dbe000a..a7342adf5 100644 --- a/Scripts/Engines/ConPVP/DuelContext.cs +++ b/Scripts/Engines/ConPVP/DuelContext.cs @@ -33,19 +33,18 @@ namespace Server.Engines.ConPVP private Timer m_Countdown; - private ArrayList m_Entered = new ArrayList(); public EventGame m_EventGame; private Map m_GateFacet; private Point3D m_GatePoint; - public TournyMatch m_Match; + public TourneyMatch m_Match; public Arena m_OverrideArena; private Timer m_SDWarnTimer, m_SDActivateTimer; public Tournament m_Tournament; - private ArrayList m_Walls = new ArrayList(); + private List m_Walls = new List(); private bool m_Yielding; @@ -56,7 +55,7 @@ namespace Server.Engines.ConPVP public DuelContext(Mobile initiator, RulesetLayout layout, bool addNew) { Initiator = initiator; - Participants = new ArrayList(); + Participants = new List(); Ruleset = new Ruleset(layout); Ruleset.ApplyDefault(layout.Defaults[0]); @@ -64,8 +63,7 @@ namespace Server.Engines.ConPVP { Participants.Add(new Participant(this, 1)); Participants.Add(new Participant(this, 1)); - - ((Participant)Participants[0]).Add(initiator); + Participants[0].Add(initiator); } } @@ -83,7 +81,7 @@ namespace Server.Engines.ConPVP public Mobile Initiator{ get; } - public ArrayList Participants{ get; } + public List Participants{ get; } public Ruleset Ruleset{ get; private set; } @@ -93,22 +91,8 @@ namespace Server.Engines.ConPVP public bool IsSuddenDeath{ get; set; } - public bool IsOneVsOne - { - get - { - if (Participants.Count != 2) - return false; - - if (((Participant)Participants[0]).Players.Length != 1) - return false; - - if (((Participant)Participants[1]).Players.Length != 1) - return false; - - return true; - } - } + public bool IsOneVsOne => Participants.Count == 2 && Participants[0].Players.Length == 1 && + Participants[1].Players.Length == 1; public bool StartedBeginCountdown{ get; private set; } @@ -134,7 +118,7 @@ namespace Server.Engines.ConPVP public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse) { - Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse }); + Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse)); } public static bool AllowSpecialMove(Mobile from, string name, SpecialMove move) @@ -183,7 +167,7 @@ namespace Server.Engines.ConPVP DuelPlayer pl = Find(from); - if (pl == null || pl.Eliminated) + if (pl?.Eliminated != false) return true; if (CantDoAnything(from)) @@ -192,7 +176,8 @@ namespace Server.Engines.ConPVP if (spell is RecallSpell) from.SendMessage("You may not cast this spell."); - string title = null, option = null; + string title = null; + string option; if (spell is ArcanistSpell) { @@ -492,12 +477,8 @@ namespace Server.Engines.ConPVP return false; } - private void DelayBounce_Callback(object state) + private void DelayBounce_Callback(Mobile mob, Container corpse) { - object[] states = (object[])state; - Mobile mob = (Mobile)states[0]; - Container corpse = (Container)states[1]; - RemoveAggressions(mob); SendOutside(mob); Refresh(mob, corpse); @@ -698,11 +679,11 @@ namespace Server.Engines.ConPVP winner.Players.Length == 1 ? "{0} has won the duel." : "{0} and {1} team have won the duel.", winner.Players.Length == 1 ? "You have won the duel." : "Your team has won the duel."); - if (m_Tournament != null && winner.TournyPart != null) + if (m_Tournament != null && winner.TourneyPart != null) { - m_Match.Winner = winner.TournyPart; - winner.TournyPart.WonMatch(m_Match); - m_Tournament.HandleWon(Arena, m_Match, winner.TournyPart); + m_Match.Winner = winner.TourneyPart; + winner.TourneyPart.WonMatch(m_Match); + m_Tournament.HandleWon(Arena, m_Match, winner.TourneyPart); } for (int i = 0; i < Participants.Count; ++i) @@ -716,7 +697,7 @@ namespace Server.Engines.ConPVP loser.Players.Length == 1 ? "You have lost the duel." : "Your team has lost the duel."); if (m_Tournament != null) - loser.TournyPart?.LostMatch(m_Match); + loser.TourneyPart?.LostMatch(m_Match); } for (int j = 0; j < loser.Players.Length; ++j) @@ -724,7 +705,7 @@ namespace Server.Engines.ConPVP { RemoveAggressions(loser.Players[j].Mobile); loser.Players[j].Mobile.Delta(MobileDelta.Noto); - loser.Players[j].Mobile.CloseGump(typeof(BeginGump)); + loser.Players[j].Mobile.CloseGump(); if (m_Tournament != null) loser.Players[j].Mobile.SendEverything(); @@ -814,12 +795,6 @@ namespace Server.Engines.ConPVP StopSDTimers(); - Type[] types = - { - typeof(BeginGump), typeof(DuelContextGump), typeof(ParticipantGump), typeof(PickRulesetGump), - typeof(ReadyGump), typeof(ReadyUpGump), typeof(RulesetGump) - }; - for (int i = 0; i < Participants.Count; ++i) { Participant p = (Participant)Participants[i]; @@ -834,8 +809,7 @@ namespace Server.Engines.ConPVP if (pl.Mobile is PlayerMobile mobile) mobile.DuelPlayer = null; - for (int k = 0; k < types.Length; ++k) - pl.Mobile.CloseGump(types[k]); + CloseAllGumps(pl); } } @@ -936,33 +910,21 @@ namespace Server.Engines.ConPVP { cb(count); m_Countdown = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), count, - new TimerStateCallback(Countdown_Callback), new object[] { count - 1, cb }); + () => Countdown_Callback(--count, cb)); } public void StopCountdown() { m_Countdown?.Stop(); - m_Countdown = null; } - private void Countdown_Callback(object state) + private void Countdown_Callback(int count, CountdownCallback cb) { - object[] states = (object[])state; - - int count = (int)states[0]; - CountdownCallback cb = (CountdownCallback)states[1]; - if (count == 0) - { - m_Countdown?.Stop(); - - m_Countdown = null; - } + StopCountdown(); cb(count); - - states[0] = count - 1; } public void StopSDTimers() @@ -1051,7 +1013,7 @@ namespace Server.Engines.ConPVP { m_AutoTieTimer?.Stop(); - TimeSpan ts = m_Tournament == null || m_Tournament.TournyType == TournyType.Standard + TimeSpan ts = m_Tournament == null || m_Tournament.TourneyType == TourneyType.Standard ? AutoTieDelay : TimeSpan.FromMinutes(90.0); @@ -1077,11 +1039,11 @@ namespace Server.Engines.ConPVP StopSDTimers(); - ArrayList remaining = new ArrayList(); + List remaining = new List(); for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; if (p.Eliminated) { @@ -1107,8 +1069,8 @@ namespace Server.Engines.ConPVP DelayBounce(TimeSpan.FromSeconds(8.0), pl.Mobile, null); } - if (p.TournyPart != null) - remaining.Add(p.TournyPart); + if (p.TourneyPart != null) + remaining.Add(p.TourneyPart); } for (int j = 0; j < p.Players.Length; ++j) @@ -1204,12 +1166,10 @@ namespace Server.Engines.ConPVP } } - private static void ViewLadder_OnTarget(Mobile from, object obj, object state) + private static void ViewLadder_OnTarget(Mobile from, object obj, Ladder ladder) { if (obj is PlayerMobile pm) { - Ladder ladder = (Ladder)state; - LadderEntry entry = ladder.Find(pm); if (entry == null) @@ -1249,7 +1209,7 @@ namespace Server.Engines.ConPVP if (!pm.CheckAlive()) { } - else if (pm.Region.IsPartOf(typeof(Jail))) + else if (pm.Region.IsPartOf()) { } else if (CheckCombat(pm)) @@ -1285,7 +1245,7 @@ namespace Server.Engines.ConPVP if (prefs != null) { - e.Mobile.CloseGump(typeof(PreferencesGump)); + e.Mobile.CloseGump(); e.Mobile.SendGump(new PreferencesGump(e.Mobile, prefs)); } } @@ -1341,7 +1301,7 @@ namespace Server.Engines.ConPVP else { pm.SendMessage("Target a player to view their ranking and level."); - pm.BeginTarget(16, false, TargetFlags.None, new TargetStateCallback(ViewLadder_OnTarget), instance); + pm.BeginTarget(16, false, TargetFlags.None, ViewLadder_OnTarget, instance); } } } @@ -1551,12 +1511,20 @@ namespace Server.Engines.ConPVP } } } + + public void CloseAllGumps(DuelPlayer pl) + { + pl.Mobile.CloseGump(); + pl.Mobile.CloseGump(); + pl.Mobile.CloseGump(); + pl.Mobile.CloseGump(); + pl.Mobile.CloseGump(); + pl.Mobile.CloseGump(); + pl.Mobile.CloseGump(); + } public void CloseAllGumps() { - Type[] types = { typeof(DuelContextGump), typeof(ParticipantGump), typeof(RulesetGump) }; - int[] defs = { -1, -1, -1 }; - for (int i = 0; i < Participants.Count; ++i) { Participant p = (Participant)Participants[i]; @@ -1565,14 +1533,8 @@ namespace Server.Engines.ConPVP { DuelPlayer pl = p.Players[j]; - if (pl == null) - continue; - - Mobile mob = pl.Mobile; - - for (int k = 0; k < types.Length; ++k) - mob.CloseGump(types[k]); - //mob.CloseGump( types[k], defs[k] ); + if (pl != null) + CloseAllGumps(pl); } } } @@ -1582,9 +1544,6 @@ namespace Server.Engines.ConPVP if (StartedReadyCountdown) return; // sanity - Type[] types = { typeof(DuelContextGump), typeof(ReadyUpGump), typeof(ReadyGump) }; - int[] defs = { -1, -1, -1 }; - for (int i = 0; i < Participants.Count; ++i) { Participant p = (Participant)Participants[i]; @@ -1612,10 +1571,11 @@ namespace Server.Engines.ConPVP else mob.SendMessage(0x22, "{0} has rejected the {1}.", rejector.Name, Rematch ? "rematch" : page); } - - for (int k = 0; k < types.Length; ++k) - mob.CloseGump(types[k]); - //mob.CloseGump( types[k], defs[k] ); + + // Close all of them? + mob.CloseGump(); + mob.CloseGump(); + mob.CloseGump(); } } @@ -1655,7 +1615,7 @@ namespace Server.Engines.ConPVP ArchProtectionSpell.RemoveEntry(mob); - mob.EndAction(typeof(DefensiveSpell)); + mob.EndAction(); } TransformationSpellHelper.RemoveContext(mob, true); @@ -1664,11 +1624,11 @@ namespace Server.Engines.ConPVP if (DisguiseTimers.IsDisguised(mob)) DisguiseTimers.StopTimer(mob); - if (!mob.CanBeginAction(typeof(PolymorphSpell))) + if (!mob.CanBeginAction()) { mob.BodyMod = 0; mob.HueMod = -1; - mob.EndAction(typeof(PolymorphSpell)); + mob.EndAction(); } BaseArmor.ValidateMobile(mob); @@ -1692,7 +1652,7 @@ namespace Server.Engines.ConPVP public void DestroyWall() { for (int i = 0; i < m_Walls.Count; ++i) - ((Item)m_Walls[i]).Delete(); + m_Walls[i].Delete(); m_Walls.Clear(); } @@ -1739,11 +1699,11 @@ namespace Server.Engines.ConPVP { for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; if (p.Players.Length > 1) { - ArrayList players = new ArrayList(); + List players = new List(); for (int j = 0; j < p.Players.Length; ++j) { @@ -1758,7 +1718,7 @@ namespace Server.Engines.ConPVP if (players.Count > 1) for (int leaderIndex = 0; leaderIndex + 1 < players.Count; leaderIndex += Party.Capacity) { - Mobile leader = (Mobile)players[leaderIndex]; + Mobile leader = players[leaderIndex]; Party party = Party.Get(leader); if (party == null) @@ -1774,7 +1734,7 @@ namespace Server.Engines.ConPVP for (int j = leaderIndex + 1; j < players.Count && j < leaderIndex + Party.Capacity; ++j) { - Mobile player = (Mobile)players[j]; + Mobile player = players[j]; Party existing = Party.Get(player); if (existing == party) @@ -1807,7 +1767,7 @@ namespace Server.Engines.ConPVP { for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -1945,11 +1905,9 @@ namespace Server.Engines.ConPVP BeginAutoTie(); } - Type[] types = { typeof(ReadyGump), typeof(ReadyUpGump), typeof(BeginGump) }; - for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -1963,13 +1921,18 @@ namespace Server.Engines.ConPVP if (count > 0) { if (count == 10) - CloseAndSendGump(mob, new BeginGump(count), types); + { + mob.CloseGump(); + mob.CloseGump(); + mob.CloseGump(); + mob.SendGump(new BeginGump(count)); + } mob.Frozen = true; } else { - mob.CloseGump(typeof(BeginGump)); + mob.CloseGump(); mob.Frozen = false; } } @@ -1980,7 +1943,7 @@ namespace Server.Engines.ConPVP { for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2005,11 +1968,9 @@ namespace Server.Engines.ConPVP ReadyWait = true; ReadyCount = -1; - Type[] types = { typeof(ReadyUpGump) }; - for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2017,9 +1978,11 @@ namespace Server.Engines.ConPVP Mobile mob = pl?.Mobile; - if (mob != null) - if (m_Tournament == null) - CloseAndSendGump(mob, new ReadyUpGump(mob, this), types); + if (mob != null && m_Tournament == null) + { + mob.CloseGump(); + mob.SendGump(new ReadyUpGump(mob, this)); + } } } } @@ -2031,7 +1994,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2040,7 +2003,7 @@ namespace Server.Engines.ConPVP if (dp == null) return "a slot is empty"; - if (dp.Mobile.Region.IsPartOf(typeof(Jail))) + if (dp.Mobile.Region.IsPartOf()) return $"{dp.Mobile.Name} is in jail"; if (Sigil.ExistsOn(dp.Mobile)) @@ -2089,7 +2052,7 @@ namespace Server.Engines.ConPVP { for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2110,7 +2073,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2130,7 +2093,7 @@ namespace Server.Engines.ConPVP { for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2173,7 +2136,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2206,7 +2169,7 @@ namespace Server.Engines.ConPVP { for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2227,11 +2190,9 @@ namespace Server.Engines.ConPVP bool isAllReady = true; - Type[] types = { typeof(ReadyGump) }; - for (int i = 0; i < Participants.Count; ++i) { - Participant p = (Participant)Participants[i]; + Participant p = Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -2245,7 +2206,10 @@ namespace Server.Engines.ConPVP if (pl.Ready) { if (m_Tournament == null) - CloseAndSendGump(mob, new ReadyGump(mob, this, count), types); + { + mob.CloseGump(); + mob.SendGump(new ReadyGump(mob, this, count)); + } } else { @@ -2258,45 +2222,6 @@ namespace Server.Engines.ConPVP StartCountdown(3, SendReadyGump); } - public static void CloseAndSendGump(Mobile mob, Gump g, params Type[] types) - { - CloseAndSendGump(mob.NetState, g, types); - } - - public static void CloseAndSendGump(NetState ns, Gump g, params Type[] types) - { - Mobile mob = ns?.Mobile; - - if (mob != null) - { - foreach (Type type in types) mob.CloseGump(type); - - mob.SendGump(g); - } - - /*if ( ns == null ) - return; - - for ( int i = 0; i < types.Length; ++i ) - ns.Send( new CloseGump( Gump.GetTypeID( types[i] ), 0 ) ); - - g.SendTo( ns ); - - ns.AddGump( g ); - - Packet[] packets = new Packet[types.Length + 1]; - - for ( int i = 0; i < types.Length; ++i ) - packets[i] = new CloseGump( Gump.GetTypeID( types[i] ), 0 ); - - packets[types.Length] = (Packet) typeof( Gump ).InvokeMember( "Compile", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, g, null, null ); - - bool compress = ns.CompressionEnabled; - ns.CompressionEnabled = false; - ns.Send( BindPackets( compress, packets ) ); - ns.CompressionEnabled = compress;*/ - } - private class InternalWall : Item { public InternalWall() : base(0x80) @@ -2395,11 +2320,11 @@ namespace Server.Engines.ConPVP private class ExitTeleporter : Item { - private ArrayList m_Entries; + private List m_Entries; public ExitTeleporter() : base(0x1822) { - m_Entries = new ArrayList(); + m_Entries = new List(); Hue = 0x482; Movable = false; @@ -2428,7 +2353,7 @@ namespace Server.Engines.ConPVP { for (int i = 0; i < m_Entries.Count; ++i) { - ReturnEntry entry = (ReturnEntry)m_Entries[i]; + ReturnEntry entry = m_Entries[i]; if (entry.Mobile == mob) return entry; @@ -2472,7 +2397,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < m_Entries.Count; ++i) { - ReturnEntry entry = (ReturnEntry)m_Entries[i]; + ReturnEntry entry = m_Entries[i]; writer.Write(entry.Mobile); writer.Write(entry.Location); @@ -2495,7 +2420,7 @@ namespace Server.Engines.ConPVP { int count = reader.ReadEncodedInt(); - m_Entries = new ArrayList(count); + m_Entries = new List(count); for (int i = 0; i < count; ++i) { @@ -2586,35 +2511,5 @@ namespace Server.Engines.ConPVP Delete(); } } - - /*public static Packet BindPackets( bool compress, params Packet[] packets ) - { - if ( packets.Length == 0 ) - throw new ArgumentException( "No packets to bind", "packets" ); - - byte[][] compiled = new byte[packets.Length][]; - int[] lengths = new int[packets.Length]; - - int length = 0; - - for ( int i = 0; i < packets.Length; ++i ) - { - compiled[i] = packets[i].Compile( compress, out lengths[i] ); - length += lengths[i]; - } - - return new BoundPackets( length, compiled, lengths ); - } - - private class BoundPackets : Packet - { - public BoundPackets( int length, byte[][] compiled, int[] lengths ) : base( 0, length ) - { - m_Stream.Seek( 0, System.IO.SeekOrigin.Begin ); - - for ( int i = 0; i < compiled.Length; ++i ) - m_Stream.Write( compiled[i], 0, lengths[i] ); - } - }*/ } } \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/Games/BombingRun.cs b/Scripts/Engines/ConPVP/Games/BombingRun.cs index 4e6727021..11bd63e1b 100644 --- a/Scripts/Engines/ConPVP/Games/BombingRun.cs +++ b/Scripts/Engines/ConPVP/Games/BombingRun.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Text; using Server.Gumps; using Server.Items; @@ -15,7 +16,7 @@ namespace Server.Engines.ConPVP private BRGame m_Game; - private ArrayList m_Helpers; + private List m_Helpers; private Point3DList m_Path = new Point3DList(); private int m_PathIdx; @@ -29,7 +30,7 @@ namespace Server.Engines.ConPVP m_Game = game; - m_Helpers = new ArrayList(); + m_Helpers = new List(); m_Timer = new EffectTimer(this); m_Timer.Start(); @@ -230,7 +231,7 @@ namespace Server.Engines.ConPVP private void DoAnim(Point3D start, Point3D end, Map map) { Effects.SendMovingEffect(new Entity(Serial.Zero, start, map), new Entity(Serial.Zero, end, map), - ItemID, 15, 0, false, false, Hue, 0); + ItemID, 15, 0, false, false, Hue); } private void DoCatch(Mobile m) @@ -270,29 +271,21 @@ namespace Server.Engines.ConPVP dest = swap; }*/ - ArrayList list = new ArrayList(); - double rise, run, zslp; - double dist3d, dist2d; - double x, y, z; - int xd, yd, zd; - Point3D p; + List list = new List(); - xd = dest.X - org.X; - yd = dest.Y - org.Y; - zd = dest.Z - org.Z; - dist2d = Math.Sqrt(xd * xd + yd * yd); - if (zd != 0) - dist3d = Math.Sqrt(dist2d * dist2d + zd * zd); - else - dist3d = dist2d; + int xd = dest.X - org.X; + int yd = dest.Y - org.Y; + int zd = dest.Z - org.Z; + double dist2d = Math.Sqrt(xd * xd + yd * yd); + double dist3d = zd == 0 ? dist2d : Math.Sqrt(dist2d * dist2d + zd * zd); - rise = yd / dist3d; - run = xd / dist3d; - zslp = zd / dist3d; + double rise = yd / dist3d; + double run = xd / dist3d; + double zslp = zd / dist3d; - x = org.X; - y = org.Y; - z = org.Z; + double x = org.X; + double y = org.Y; + double z = org.Z; while (Utility.NumberBetween(x, dest.X, org.X, 0.5) && Utility.NumberBetween(y, dest.Y, org.Y, 0.5) && Utility.NumberBetween(z, dest.Z, org.Z, 0.5)) { @@ -302,7 +295,7 @@ namespace Server.Engines.ConPVP if (list.Count > 0) { - p = (Point3D)list[list.Count - 1]; + Point3D p = list[list.Count - 1]; if (p.X != ix || p.Y != iy || p.Z != iz) list.Add(new Point3D(ix, iy, iz)); @@ -317,9 +310,8 @@ namespace Server.Engines.ConPVP z += zslp; } - if (list.Count > 0) - if ((Point3D)list[list.Count - 1] != dest) - list.Add(dest); + if (list.Count > 0 && list[list.Count - 1] != dest) + list.Add(dest); /*if ( dist3d > 4 && ( dest.X != org.X || dest.Y != org.Y ) ) { @@ -359,7 +351,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < count; i++) { - p = (Point3D)list[i]; + Point3D p = list[i]; int xp = i - count / 2; @@ -371,7 +363,7 @@ namespace Server.Engines.ConPVP m_Path.Clear(); for (int i = 0; i < list.Count; i++) - m_Path.Add((Point3D)list[i]); + m_Path.Add(list[i]); m_PathIdx = 0; @@ -616,7 +608,7 @@ namespace Server.Engines.ConPVP for (int i = m_Helpers.Count - 1; i >= 0; i--) { - Mobile mob = (Mobile)m_Helpers[i]; + Mobile mob = m_Helpers[i]; BRPlayerInfo pi = team[mob]; if (pi != null) @@ -661,7 +653,7 @@ namespace Server.Engines.ConPVP if (m_Helpers.Count > 0) { - Mobile last = (Mobile)m_Helpers[0]; + Mobile last = m_Helpers[0]; if (m_Game.GetTeamInfo(last) != team) m_Helpers.Clear(); @@ -951,7 +943,7 @@ namespace Server.Engines.ConPVP { if (m_TeamInfo?.Game != null) { - from.CloseGump(typeof(BRBoardGump)); + from.CloseGump(); from.SendGump(new BRBoardGump(from, m_TeamInfo.Game)); } } @@ -983,16 +975,17 @@ namespace Server.Engines.ConPVP { } - public BRBoardGump(Mobile mob, BRGame game, BRTeamInfo section) - : base(60, 60) + public BRBoardGump(Mobile mob, BRGame game, BRTeamInfo section) : base(60, 60) { m_Game = game; BRTeamInfo ourTeam = game.GetTeamInfo(mob); - ArrayList entries = new ArrayList(); + List entries = new List(); + int total = 0; if (section == null) + { for (int i = 0; i < game.Context.Participants.Count; ++i) { BRTeamInfo teamInfo = game.Controller.TeamInfo[i % game.Controller.TeamInfo.Length]; @@ -1002,17 +995,15 @@ namespace Server.Engines.ConPVP entries.Add(teamInfo); } + + total = entries.Count; + } else foreach (BRPlayerInfo player in section.Players.Values) if (player.Score > 0) - entries.Add(player); + total++; entries.Sort(); - /* - delegate( IRankedCTF a, IRankedCTF b ) - { - return b.Score - a.Score; - } );*/ int height = 0; @@ -1027,7 +1018,7 @@ namespace Server.Engines.ConPVP AddImageTiled(16, 15, 369, height - 29, 3604); - for (int i = 0; i < entries.Count; i += 1) + for (int i = 0; i < total; i += 1) AddImageTiled(22, 58 + i * 75, 357, 70, 0x2430); AddAlphaRegion(16, 15, 369, height - 29); @@ -1043,7 +1034,7 @@ namespace Server.Engines.ConPVP if (section == null) for (int i = 0; i < entries.Count; ++i) { - BRTeamInfo teamInfo = entries[i] as BRTeamInfo; + BRTeamInfo teamInfo = entries[i]; AddImage(30, 70 + i * 75, 10152); AddImage(30, 85 + i * 75, 10151); @@ -1208,20 +1199,20 @@ namespace Server.Engines.ConPVP } [PropertyObject] - public sealed class BRTeamInfo : IRankedCTF, IComparable + public sealed class BRTeamInfo : IRankedCTF, IComparable { private BRGoal m_Goal; public BRTeamInfo(int teamID) { TeamID = teamID; - Players = new Hashtable(); + Players = new Dictionary(); } public BRTeamInfo(int teamID, GenericReader ip) { TeamID = teamID; - Players = new Hashtable(); + Players = new Dictionary(); int version = ip.ReadEncodedInt(); @@ -1247,7 +1238,7 @@ namespace Server.Engines.ConPVP [CommandProperty(AccessLevel.GameMaster)] public BRBoard Board{ get; set; } - public Hashtable Players{ get; } + public Dictionary Players{ get; } public BRPlayerInfo this[Mobile mob] { @@ -1281,9 +1272,8 @@ namespace Server.Engines.ConPVP } } - public int CompareTo(object obj) + public int CompareTo(BRTeamInfo ti) { - BRTeamInfo ti = (BRTeamInfo)obj; int res = ti.Captures.CompareTo(Captures); if (res == 0) { @@ -1367,32 +1357,16 @@ namespace Server.Engines.ConPVP public BRTeamInfo[] TeamInfo{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public BRTeamInfo Team1 - { - get => TeamInfo[0]; - set { } - } + public BRTeamInfo Team1 => TeamInfo[0]; [CommandProperty(AccessLevel.GameMaster)] - public BRTeamInfo Team2 - { - get => TeamInfo[1]; - set { } - } + public BRTeamInfo Team2 => TeamInfo[1]; [CommandProperty(AccessLevel.GameMaster)] - public BRTeamInfo Team3 - { - get => TeamInfo[2]; - set { } - } + public BRTeamInfo Team3 => TeamInfo[2]; [CommandProperty(AccessLevel.GameMaster)] - public BRTeamInfo Team4 - { - get => TeamInfo[3]; - set { } - } + public BRTeamInfo Team4 => TeamInfo[3]; [CommandProperty(AccessLevel.GameMaster)] public TimeSpan Duration{ get; set; } @@ -1515,7 +1489,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < m_Context.Participants.Count; ++i) { - Participant p = m_Context.Participants[i] as Participant; + Participant p = m_Context.Participants[i]; for (int j = 0; j < p.Players.Length; ++j) if (p.Players[j] != null) @@ -1566,19 +1540,12 @@ namespace Server.Engines.ConPVP public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse) { - Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse }); + Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse)); } - private void DelayBounce_Callback(object state) + private void DelayBounce_Callback(Mobile mob, Container corpse) { - object[] states = (object[])state; - Mobile mob = (Mobile)states[0]; - Container corpse = (Container)states[1]; - - DuelPlayer dp = null; - - if (mob is PlayerMobile mobile) - dp = mobile.DuelPlayer; + DuelPlayer dp = mob is PlayerMobile mobile ? mobile.DuelPlayer : null; m_Context.RemoveAggressions(mob); @@ -1631,7 +1598,7 @@ namespace Server.Engines.ConPVP } } - mob.CloseGump(typeof(BRBoardGump)); + mob.CloseGump(); mob.SendGump(new BRBoardGump(mob, this)); m_Context.Requip(mob, corpse); @@ -1651,7 +1618,7 @@ namespace Server.Engines.ConPVP } for (int i = 0; i < m_Context.Participants.Count; ++i) - ApplyHues(m_Context.Participants[i] as Participant, + ApplyHues(m_Context.Participants[i], Controller.TeamInfo[i % Controller.TeamInfo.Length].Color); m_FinishTimer?.Stop(); @@ -1664,51 +1631,49 @@ namespace Server.Engines.ConPVP private void Finish_Callback() { - ArrayList teams = new ArrayList(); + List teams = new List(); for (int i = 0; i < m_Context.Participants.Count; ++i) { BRTeamInfo teamInfo = Controller.TeamInfo[i % Controller.TeamInfo.Length]; - if (teamInfo == null) - continue; - - teams.Add(teamInfo); + if (teamInfo != null) + teams.Add(teamInfo); } teams.Sort(); - Tournament tourny = m_Context.m_Tournament; + Tournament tourney = m_Context.m_Tournament; StringBuilder sb = new StringBuilder(); - if (tourny != null && tourny.TournyType == TournyType.FreeForAll) + if (tourney != null && tourney.TourneyType == TourneyType.FreeForAll) { - sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant); + sb.Append(m_Context.Participants.Count * tourney.PlayersPerParticipant); sb.Append("-man FFA"); } - else if (tourny != null && tourny.TournyType == TournyType.RandomTeam) + else if (tourney != null && tourney.TourneyType == TourneyType.RandomTeam) { - sb.Append(tourny.ParticipantsPerMatch); + sb.Append(tourney.ParticipantsPerMatch); sb.Append("-team"); } - else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue) + else if (tourney != null && tourney.TourneyType == TourneyType.RedVsBlue) { sb.Append("Red v Blue"); } - else if (tourny != null && tourny.TournyType == TournyType.Faction) + else if (tourney != null && tourney.TourneyType == TourneyType.Faction) { - sb.Append(tourny.ParticipantsPerMatch); + sb.Append(tourney.ParticipantsPerMatch); sb.Append("-team Faction"); } - else if (tourny != null) + else if (tourney != null) { - for (int i = 0; i < tourny.ParticipantsPerMatch; ++i) + for (int i = 0; i < tourney.ParticipantsPerMatch; ++i) { if (sb.Length > 0) sb.Append('v'); - sb.Append(tourny.PlayersPerParticipant); + sb.Append(tourney.PlayersPerParticipant); } } @@ -1717,7 +1682,7 @@ namespace Server.Engines.ConPVP string title = sb.ToString(); - BRTeamInfo winner = (BRTeamInfo)(teams.Count > 0 ? teams[0] : null); + BRTeamInfo winner = teams.Count > 0 ? teams[0] : null; for (int i = 0; i < teams.Count; ++i) { @@ -1728,9 +1693,9 @@ namespace Server.Engines.ConPVP else if (i == 1) rank = TrophyRank.Silver; - BRPlayerInfo leader = ((BRTeamInfo)teams[i]).Leader; + BRPlayerInfo leader = teams[i].Leader; - foreach (BRPlayerInfo pl in ((BRTeamInfo)teams[i]).Players.Values) + foreach (BRPlayerInfo pl in teams[i].Players.Values) { Mobile mob = pl.Player; @@ -1767,7 +1732,7 @@ namespace Server.Engines.ConPVP if (pl == leader) item.ItemID = 4810; - item.Name = $"{item.Name}, {((BRTeamInfo)teams[i]).Name.ToLower()} team"; + item.Name = $"{item.Name}, {teams[i].Name.ToLower()} team"; if (!mob.PlaceInBackpack(item)) mob.BankBox.DropItem(item); @@ -1804,7 +1769,7 @@ namespace Server.Engines.ConPVP if (dp?.Mobile != null) { - dp.Mobile.CloseGump(typeof(BRBoardGump)); + dp.Mobile.CloseGump(); dp.Mobile.SendGump(new BRBoardGump(dp.Mobile, this)); } } @@ -1818,7 +1783,7 @@ namespace Server.Engines.ConPVP p.Players[j].Eliminated = true; } - m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant); + m_Context.Finish(m_Context.Participants[winner.TeamID]); } public override void OnStop() @@ -1838,10 +1803,10 @@ namespace Server.Engines.ConPVP m_Bomb?.Delete(); for (int i = 0; i < m_Context.Participants.Count; ++i) - ApplyHues(m_Context.Participants[i] as Participant, -1); + ApplyHues(m_Context.Participants[i], -1); m_FinishTimer?.Stop(); m_FinishTimer = null; } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/ConPVP/Games/CTF.cs b/Scripts/Engines/ConPVP/Games/CTF.cs index 2296b9ab3..abce7730b 100644 --- a/Scripts/Engines/ConPVP/Games/CTF.cs +++ b/Scripts/Engines/ConPVP/Games/CTF.cs @@ -31,7 +31,7 @@ namespace Server.Engines.ConPVP { if (m_TeamInfo?.Game != null) { - from.CloseGump(typeof(CTFBoardGump)); + from.CloseGump(); from.SendGump(new CTFBoardGump(from, m_TeamInfo.Game)); } } @@ -58,12 +58,7 @@ namespace Server.Engines.ConPVP private CTFGame m_Game; - public CTFBoardGump(Mobile mob, CTFGame game) - : this(mob, game, null) - { - } - - public CTFBoardGump(Mobile mob, CTFGame game, CTFTeamInfo section) + public CTFBoardGump(Mobile mob, CTFGame game, CTFTeamInfo section = null) : base(60, 60) { m_Game = game; @@ -719,60 +714,28 @@ namespace Server.Engines.ConPVP public CTFTeamInfo[] TeamInfo{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public CTFTeamInfo Team1 - { - get => TeamInfo[0]; - set { } - } + public CTFTeamInfo Team1 => TeamInfo[0]; [CommandProperty(AccessLevel.GameMaster)] - public CTFTeamInfo Team2 - { - get => TeamInfo[1]; - set { } - } + public CTFTeamInfo Team2 => TeamInfo[1]; [CommandProperty(AccessLevel.GameMaster)] - public CTFTeamInfo Team3 - { - get => TeamInfo[2]; - set { } - } + public CTFTeamInfo Team3 => TeamInfo[2]; [CommandProperty(AccessLevel.GameMaster)] - public CTFTeamInfo Team4 - { - get => TeamInfo[3]; - set { } - } + public CTFTeamInfo Team4 => TeamInfo[3]; [CommandProperty(AccessLevel.GameMaster)] - public CTFTeamInfo Team5 - { - get => TeamInfo[4]; - set { } - } + public CTFTeamInfo Team5 => TeamInfo[4]; [CommandProperty(AccessLevel.GameMaster)] - public CTFTeamInfo Team6 - { - get => TeamInfo[5]; - set { } - } + public CTFTeamInfo Team6 => TeamInfo[5]; [CommandProperty(AccessLevel.GameMaster)] - public CTFTeamInfo Team7 - { - get => TeamInfo[6]; - set { } - } + public CTFTeamInfo Team7 => TeamInfo[6]; [CommandProperty(AccessLevel.GameMaster)] - public CTFTeamInfo Team8 - { - get => TeamInfo[7]; - set { } - } + public CTFTeamInfo Team8 => TeamInfo[7]; [CommandProperty(AccessLevel.GameMaster)] public TimeSpan Duration{ get; set; } @@ -876,7 +839,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < m_Context.Participants.Count; ++i) { - Participant p = m_Context.Participants[i] as Participant; + Participant p = m_Context.Participants[i]; for (int j = 0; j < p.Players.Length; ++j) if (p.Players[j] != null) @@ -932,19 +895,12 @@ namespace Server.Engines.ConPVP public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse) { - Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse }); + Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse)); } - private void DelayBounce_Callback(object state) + private void DelayBounce_Callback(Mobile mob, Container corpse) { - object[] states = (object[])state; - Mobile mob = (Mobile)states[0]; - Container corpse = (Container)states[1]; - - DuelPlayer dp = null; - - if (mob is PlayerMobile mobile) - dp = mobile.DuelPlayer; + DuelPlayer dp = mob is PlayerMobile mobile ? mobile.DuelPlayer : null; m_Context.RemoveAggressions(mob); @@ -1027,7 +983,7 @@ namespace Server.Engines.ConPVP } } - mob.CloseGump(typeof(CTFBoardGump)); + mob.CloseGump(); mob.SendGump(new CTFBoardGump(mob, this)); m_Context.Requip(mob, corpse); @@ -1047,7 +1003,7 @@ namespace Server.Engines.ConPVP } for (int i = 0; i < m_Context.Participants.Count; ++i) - ApplyHues(m_Context.Participants[i] as Participant, Controller.TeamInfo[i % 8].Color); + ApplyHues(m_Context.Participants[i], Controller.TeamInfo[i % 8].Color); m_FinishTimer?.Stop(); @@ -1070,37 +1026,37 @@ namespace Server.Engines.ConPVP teams.Sort(delegate(CTFTeamInfo a, CTFTeamInfo b) { return b.Score - a.Score; }); - Tournament tourny = m_Context.m_Tournament; + Tournament tourney = m_Context.m_Tournament; StringBuilder sb = new StringBuilder(); - if (tourny != null && tourny.TournyType == TournyType.FreeForAll) + if (tourney != null && tourney.TourneyType == TourneyType.FreeForAll) { - sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant); + sb.Append(m_Context.Participants.Count * tourney.PlayersPerParticipant); sb.Append("-man FFA"); } - else if (tourny != null && tourny.TournyType == TournyType.RandomTeam) + else if (tourney != null && tourney.TourneyType == TourneyType.RandomTeam) { - sb.Append(tourny.ParticipantsPerMatch); + sb.Append(tourney.ParticipantsPerMatch); sb.Append("-team"); } - else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue) + else if (tourney != null && tourney.TourneyType == TourneyType.RedVsBlue) { sb.Append("Red v Blue"); } - else if (tourny != null && tourny.TournyType == TournyType.Faction) + else if (tourney != null && tourney.TourneyType == TourneyType.Faction) { - sb.Append(tourny.ParticipantsPerMatch); + sb.Append(tourney.ParticipantsPerMatch); sb.Append("-team Faction"); } - else if (tourny != null) + else if (tourney != null) { - for (int i = 0; i < tourny.ParticipantsPerMatch; ++i) + for (int i = 0; i < tourney.ParticipantsPerMatch; ++i) { if (sb.Length > 0) sb.Append('v'); - sb.Append(tourny.PlayersPerParticipant); + sb.Append(tourney.PlayersPerParticipant); } } @@ -1193,7 +1149,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < m_Context.Participants.Count; ++i) { - Participant p = m_Context.Participants[i] as Participant; + Participant p = m_Context.Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -1201,7 +1157,7 @@ namespace Server.Engines.ConPVP if (dp?.Mobile != null) { - dp.Mobile.CloseGump(typeof(CTFBoardGump)); + dp.Mobile.CloseGump(); dp.Mobile.SendGump(new CTFBoardGump(dp.Mobile, this)); } } @@ -1214,7 +1170,7 @@ namespace Server.Engines.ConPVP p.Players[j].Eliminated = true; } - m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant); + m_Context.Finish(m_Context.Participants[winner.TeamID]); } public override void OnStop() @@ -1236,7 +1192,7 @@ namespace Server.Engines.ConPVP } for (int i = 0; i < m_Context.Participants.Count; ++i) - ApplyHues(m_Context.Participants[i] as Participant, -1); + ApplyHues(m_Context.Participants[i], -1); m_FinishTimer?.Stop(); diff --git a/Scripts/Engines/ConPVP/Games/DoubleDom.cs b/Scripts/Engines/ConPVP/Games/DoubleDom.cs index 54a60c092..db89b1648 100644 --- a/Scripts/Engines/ConPVP/Games/DoubleDom.cs +++ b/Scripts/Engines/ConPVP/Games/DoubleDom.cs @@ -29,7 +29,7 @@ namespace Server.Engines.ConPVP { if (m_TeamInfo?.Game != null) { - from.CloseGump(typeof(DDBoardGump)); + from.CloseGump(); from.SendGump(new DDBoardGump(from, m_TeamInfo.Game)); } } @@ -389,18 +389,10 @@ namespace Server.Engines.ConPVP public DDTeamInfo[] TeamInfo{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public DDTeamInfo Team1 - { - get => TeamInfo[0]; - set { } - } + public DDTeamInfo Team1 => TeamInfo[0]; [CommandProperty(AccessLevel.GameMaster)] - public DDTeamInfo Team2 - { - get => TeamInfo[1]; - set { } - } + public DDTeamInfo Team2 => TeamInfo[1]; [CommandProperty(AccessLevel.GameMaster)] public DDWayPoint PointA{ get; set; } @@ -501,7 +493,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < m_Context.Participants.Count; ++i) { - Participant p = m_Context.Participants[i] as Participant; + Participant p = m_Context.Participants[i]; for (int j = 0; j < p.Players.Length; ++j) if (p.Players[j] != null) @@ -552,19 +544,12 @@ namespace Server.Engines.ConPVP public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse) { - Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse }); + Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse)); } - private void DelayBounce_Callback(object state) + private void DelayBounce_Callback(Mobile mob, Container corpse) { - object[] states = (object[])state; - Mobile mob = (Mobile)states[0]; - Container corpse = (Container)states[1]; - - DuelPlayer dp = null; - - if (mob is PlayerMobile mobile) - dp = mobile.DuelPlayer; + DuelPlayer dp = mob is PlayerMobile mobile ? mobile.DuelPlayer : null; m_Context.RemoveAggressions(mob); @@ -613,7 +598,7 @@ namespace Server.Engines.ConPVP } } - mob.CloseGump(typeof(DDBoardGump)); + mob.CloseGump(); mob.SendGump(new DDBoardGump(mob, this)); m_Context.Requip(mob, corpse); @@ -653,7 +638,7 @@ namespace Server.Engines.ConPVP Controller.PointB.Game = this; for (int i = 0; i < m_Context.Participants.Count; ++i) - ApplyHues(m_Context.Participants[i] as Participant, + ApplyHues(m_Context.Participants[i], Controller.TeamInfo[i % Controller.TeamInfo.Length].Color); m_FinishTimer?.Stop(); @@ -674,37 +659,37 @@ namespace Server.Engines.ConPVP teams.Sort((a, b) => b.Score - a.Score); - Tournament tourny = m_Context.m_Tournament; + Tournament tourney = m_Context.m_Tournament; StringBuilder sb = new StringBuilder(); - if (tourny != null && tourny.TournyType == TournyType.FreeForAll) + if (tourney != null && tourney.TourneyType == TourneyType.FreeForAll) { - sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant); + sb.Append(m_Context.Participants.Count * tourney.PlayersPerParticipant); sb.Append("-man FFA"); } - else if (tourny != null && tourny.TournyType == TournyType.RandomTeam) + else if (tourney != null && tourney.TourneyType == TourneyType.RandomTeam) { - sb.Append(tourny.ParticipantsPerMatch); + sb.Append(tourney.ParticipantsPerMatch); sb.Append("-team"); } - else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue) + else if (tourney != null && tourney.TourneyType == TourneyType.RedVsBlue) { sb.Append("Red v Blue"); } - else if (tourny != null && tourny.TournyType == TournyType.Faction) + else if (tourney != null && tourney.TourneyType == TourneyType.Faction) { - sb.Append(tourny.ParticipantsPerMatch); + sb.Append(tourney.ParticipantsPerMatch); sb.Append("-team Faction"); } - else if (tourny != null) + else if (tourney != null) { - for (int i = 0; i < tourny.ParticipantsPerMatch; ++i) + for (int i = 0; i < tourney.ParticipantsPerMatch; ++i) { if (sb.Length > 0) sb.Append('v'); - sb.Append(tourny.PlayersPerParticipant); + sb.Append(tourney.PlayersPerParticipant); } } @@ -797,7 +782,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < m_Context.Participants.Count; ++i) { - Participant p = m_Context.Participants[i] as Participant; + Participant p = m_Context.Participants[i]; for (int j = 0; j < p.Players.Length; ++j) { @@ -805,7 +790,7 @@ namespace Server.Engines.ConPVP if (dp?.Mobile != null) { - dp.Mobile.CloseGump(typeof(DDBoardGump)); + dp.Mobile.CloseGump(); dp.Mobile.SendGump(new DDBoardGump(dp.Mobile, this)); } } @@ -818,7 +803,7 @@ namespace Server.Engines.ConPVP p.Players[j].Eliminated = true; } - m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant); + m_Context.Finish(m_Context.Participants[winner.TeamID]); } public override void OnStop() @@ -854,7 +839,7 @@ namespace Server.Engines.ConPVP } for (int i = 0; i < m_Context.Participants.Count; ++i) - ApplyHues(m_Context.Participants[i] as Participant, -1); + ApplyHues(m_Context.Participants[i], -1); m_FinishTimer?.Stop(); m_FinishTimer = null; diff --git a/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs b/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs index ee171509e..567b55846 100644 --- a/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs +++ b/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Text; using Server.Gumps; using Server.Items; @@ -170,12 +171,10 @@ namespace Server.Engines.ConPVP private void ReKingify(Mobile m) { - KHTeamInfo ti = null; if (m_Game == null || m == null) return; - ti = m_Game.GetTeamInfo(m); - if (ti == null) + if (m_Game.GetTeamInfo(m) == null) return; King = m; @@ -216,7 +215,6 @@ namespace Server.Engines.ConPVP protected override void OnTick() { - KHTeamInfo ti = null; KHPlayerInfo pi = null; if (m_Hill == null || m_Hill.Deleted || m_Hill.Game == null) @@ -232,7 +230,7 @@ namespace Server.Engines.ConPVP return; } - ti = m_Hill.Game.GetTeamInfo(m_Hill.King); + KHTeamInfo ti = m_Hill.Game.GetTeamInfo(m_Hill.King); if (ti != null) pi = ti[m_Hill.King]; @@ -251,11 +249,9 @@ namespace Server.Engines.ConPVP if (m_Counter >= m_Hill.ScoreInterval) { string hill = m_Hill.Name; - string king = m_Hill.King.Name; - if (king == null) - king = ""; + string king = m_Hill.King.Name ?? ""; - if (hill == null || hill == "") + if (string.IsNullOrEmpty(hill)) hill = "the hill"; m_Hill.Game.Alert("{0} ({1}) is king of {2}!", king, ti.Name, hill); @@ -315,7 +311,7 @@ namespace Server.Engines.ConPVP { if (m_Game != null) { - from.CloseGump(typeof(KHBoardGump)); + from.CloseGump(); from.SendGump(new KHBoardGump(from, m_Game)); } else @@ -364,16 +360,14 @@ namespace Server.Engines.ConPVP KHTeamInfo ourTeam = game.GetTeamInfo(mob); - ArrayList entries = new ArrayList(); + List entries = new List(); for (int i = 0; i < game.Context.Participants.Count; ++i) { KHTeamInfo teamInfo = game.Controller.TeamInfo[i % game.Controller.TeamInfo.Length]; - if (teamInfo == null) - continue; - - entries.Add(teamInfo); + if (teamInfo != null) + entries.Add(teamInfo); } entries.Sort(); @@ -408,7 +402,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < entries.Count; ++i) { - KHTeamInfo teamInfo = entries[i] as KHTeamInfo; + KHTeamInfo teamInfo = entries[i]; AddImage(30, 70 + i * 75, 10152); AddImage(30, 85 + i * 75, 10151); @@ -505,7 +499,7 @@ namespace Server.Engines.ConPVP } } - public sealed class KHPlayerInfo : IRankedCTF, IComparable + public sealed class KHPlayerInfo : IRankedCTF, IComparable { private int m_Captures; @@ -521,30 +515,18 @@ namespace Server.Engines.ConPVP public Mobile Player{ get; } - public int CompareTo(object obj) + public int CompareTo(KHPlayerInfo pi) { - KHPlayerInfo pi = (KHPlayerInfo)obj; int res = pi.Score.CompareTo(Score); - if (res == 0) - { - res = pi.Captures.CompareTo(Captures); + if (res != 0) + return res; - if (res == 0) - res = pi.Kills.CompareTo(Kills); - } + res = pi.Captures.CompareTo(Captures); - return res; + return res != 0 ? res : pi.Kills.CompareTo(Kills); } - public string Name - { - get - { - if (Player?.Name == null) - return ""; - return Player.Name; - } - } + public string Name => Player.Name ?? ""; public int Kills { @@ -586,13 +568,13 @@ namespace Server.Engines.ConPVP public KHTeamInfo(int teamID) { TeamID = teamID; - Players = new Hashtable(); + Players = new Dictionary(); } public KHTeamInfo(int teamID, GenericReader ip) { TeamID = teamID; - Players = new Hashtable(); + Players = new Dictionary(); int version = ip.ReadEncodedInt(); @@ -613,7 +595,7 @@ namespace Server.Engines.ConPVP public KHPlayerInfo Leader{ get; set; } - public Hashtable Players{ get; } + public Dictionary Players{ get; } public KHPlayerInfo this[Mobile mob] { @@ -706,7 +688,7 @@ namespace Server.Engines.ConPVP Name = "King of the Hill Controller"; Duration = TimeSpan.FromMinutes(30.0); - Boards = new ArrayList(); + Boards = new List(); Hills = new HillOfTheKing[4]; TeamInfo = new KHTeamInfo[8]; @@ -722,60 +704,28 @@ namespace Server.Engines.ConPVP public KHTeamInfo[] TeamInfo{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public KHTeamInfo Team1_W - { - get => TeamInfo[0]; - set { } - } + public KHTeamInfo Team1_W => TeamInfo[0]; [CommandProperty(AccessLevel.GameMaster)] - public KHTeamInfo Team2_E - { - get => TeamInfo[1]; - set { } - } + public KHTeamInfo Team2_E => TeamInfo[1]; [CommandProperty(AccessLevel.GameMaster)] - public KHTeamInfo Team3_N - { - get => TeamInfo[2]; - set { } - } + public KHTeamInfo Team3_N => TeamInfo[2]; [CommandProperty(AccessLevel.GameMaster)] - public KHTeamInfo Team4_S - { - get => TeamInfo[3]; - set { } - } + public KHTeamInfo Team4_S => TeamInfo[3]; [CommandProperty(AccessLevel.GameMaster)] - public KHTeamInfo Team5_NW - { - get => TeamInfo[4]; - set { } - } + public KHTeamInfo Team5_NW => TeamInfo[4]; [CommandProperty(AccessLevel.GameMaster)] - public KHTeamInfo Team6_SE - { - get => TeamInfo[5]; - set { } - } + public KHTeamInfo Team6_SE => TeamInfo[5]; [CommandProperty(AccessLevel.GameMaster)] - public KHTeamInfo Team7_SW - { - get => TeamInfo[6]; - set { } - } + public KHTeamInfo Team7_SW => TeamInfo[6]; [CommandProperty(AccessLevel.GameMaster)] - public KHTeamInfo Team8_NE - { - get => TeamInfo[7]; - set { } - } + public KHTeamInfo Team8_NE => TeamInfo[7]; public HillOfTheKing[] Hills{ get; private set; } @@ -807,7 +757,7 @@ namespace Server.Engines.ConPVP set => Hills[3] = value; } - public ArrayList Boards{ get; private set; } + public List Boards{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] public TimeSpan Duration{ get; set; } @@ -873,7 +823,7 @@ namespace Server.Engines.ConPVP Duration = reader.ReadTimeSpan(); - Boards = reader.ReadItemList(); + Boards = reader.ReadStrongItemList(); Hills = new HillOfTheKing[reader.ReadEncodedInt()]; for (int i = 0; i < Hills.Length; ++i) @@ -893,8 +843,7 @@ namespace Server.Engines.ConPVP { private Timer m_FinishTimer; - public KHGame(KHController controller, DuelContext context) - : base(context) + public KHGame(KHController controller, DuelContext context) : base(context) { Controller = controller; } @@ -928,7 +877,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < m_Context.Participants.Count; ++i) { - Participant p = m_Context.Participants[i] as Participant; + Participant p = m_Context.Participants[i]; for (int j = 0; j < p.Players.Length; ++j) if (p.Players[j] != null) @@ -979,19 +928,12 @@ namespace Server.Engines.ConPVP public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse) { - Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse }); + Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse)); } - private void DelayBounce_Callback(object state) + private void DelayBounce_Callback(Mobile mob, Container corpse) { - object[] states = (object[])state; - Mobile mob = (Mobile)states[0]; - Container corpse = (Container)states[1]; - - DuelPlayer dp = null; - - if (mob is PlayerMobile mobile) - dp = mobile.DuelPlayer; + DuelPlayer dp = mob is PlayerMobile mobile ? mobile.DuelPlayer : null; m_Context.RemoveAggressions(mob); @@ -1045,7 +987,7 @@ namespace Server.Engines.ConPVP } } - mob.CloseGump(typeof(KHBoardGump)); + mob.CloseGump(); mob.SendGump(new KHBoardGump(mob, this)); m_Context.Requip(mob, corpse); @@ -1065,7 +1007,7 @@ namespace Server.Engines.ConPVP } for (int i = 0; i < m_Context.Participants.Count; ++i) - ApplyHues(m_Context.Participants[i] as Participant, + ApplyHues(m_Context.Participants[i], Controller.TeamInfo[i % Controller.TeamInfo.Length].Color); m_FinishTimer?.Stop(); @@ -1083,46 +1025,44 @@ namespace Server.Engines.ConPVP private void Finish_Callback() { - ArrayList teams = new ArrayList(); + List teams = new List(); for (int i = 0; i < m_Context.Participants.Count; ++i) { KHTeamInfo teamInfo = Controller.TeamInfo[i % Controller.TeamInfo.Length]; - if (teamInfo == null) - continue; - - teams.Add(teamInfo); + if (teamInfo != null) + teams.Add(teamInfo); } teams.Sort(); - Tournament tourny = m_Context.m_Tournament; + Tournament tourney = m_Context.m_Tournament; StringBuilder sb = new StringBuilder(); - if (tourny != null && tourny.TournyType == TournyType.FreeForAll) + if (tourney != null && tourney.TourneyType == TourneyType.FreeForAll) { - sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant); + sb.Append(m_Context.Participants.Count * tourney.PlayersPerParticipant); sb.Append("-man FFA"); } - else if (tourny != null && tourny.TournyType == TournyType.RandomTeam) + else if (tourney != null && tourney.TourneyType == TourneyType.RandomTeam) { - sb.Append(tourny.ParticipantsPerMatch); + sb.Append(tourney.ParticipantsPerMatch); sb.Append("-team"); } - else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue) + else if (tourney != null && tourney.TourneyType == TourneyType.RedVsBlue) { sb.Append("Red v Blue"); } - else if (tourny != null) + else if (tourney != null) { - for (int i = 0; i < tourny.ParticipantsPerMatch; ++i) + for (int i = 0; i < tourney.ParticipantsPerMatch; ++i) { if (sb.Length > 0) sb.Append('v'); - sb.Append(tourny.PlayersPerParticipant); + sb.Append(tourney.PlayersPerParticipant); } } @@ -1131,7 +1071,7 @@ namespace Server.Engines.ConPVP string title = sb.ToString(); - KHTeamInfo winner = (KHTeamInfo)(teams.Count > 0 ? teams[0] : null); + KHTeamInfo winner = teams.Count > 0 ? teams[0] : null; for (int i = 0; i < teams.Count; ++i) { @@ -1142,9 +1082,9 @@ namespace Server.Engines.ConPVP else if (i == 1) rank = TrophyRank.Silver; - KHPlayerInfo leader = ((KHTeamInfo)teams[i]).Leader; + KHPlayerInfo leader = teams[i].Leader; - foreach (KHPlayerInfo pl in ((KHTeamInfo)teams[i]).Players.Values) + foreach (KHPlayerInfo pl in teams[i].Players.Values) { Mobile mob = pl.Player; @@ -1182,7 +1122,7 @@ namespace Server.Engines.ConPVP if (pl == leader) item.ItemID = 4810; - item.Name = $"{item.Name}, {((KHTeamInfo)teams[i]).Name.ToLower()}"; + item.Name = $"{item.Name}, {teams[i].Name.ToLower()}"; if (!mob.PlaceInBackpack(item)) mob.BankBox.DropItem(item); @@ -1219,21 +1159,22 @@ namespace Server.Engines.ConPVP if (dp?.Mobile != null) { - dp.Mobile.CloseGump(typeof(KHBoardGump)); + dp.Mobile.CloseGump(); dp.Mobile.SendGump(new KHBoardGump(dp.Mobile, this)); } } - if (i == winner.TeamID) + if (i == winner?.TeamID) continue; - if (p?.Players != null) + if (p.Players != null) for (int j = 0; j < p.Players.Length; ++j) if (p.Players[j] != null) p.Players[j].Eliminated = true; } - m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant); + if (winner != null) + m_Context.Finish(m_Context.Participants[winner.TeamID]); } public override void OnStop() @@ -1250,10 +1191,10 @@ namespace Server.Engines.ConPVP board.m_Game = null; for (int i = 0; i < m_Context.Participants.Count; ++i) - ApplyHues(m_Context.Participants[i] as Participant, -1); + ApplyHues(m_Context.Participants[i], -1); m_FinishTimer?.Stop(); m_FinishTimer = null; } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/ConPVP/Games/TourneyMatch.cs b/Scripts/Engines/ConPVP/Games/TourneyMatch.cs new file mode 100644 index 000000000..71e351dde --- /dev/null +++ b/Scripts/Engines/ConPVP/Games/TourneyMatch.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Server.Network; + +namespace Server.Engines.ConPVP +{ + public class TourneyMatch + { + public TourneyMatch(List participants) + { + Participants = participants; + + for (int i = 0; i < participants.Count; ++i) + { + TourneyParticipant part = participants[i]; + + StringBuilder sb = new StringBuilder(); + + sb.Append("Matched in a duel against "); + + if (participants.Count > 2) + sb.AppendFormat("{0} other {1}: ", participants.Count - 1, + part.Players.Count == 1 ? "players" : "teams"); + + bool hasAppended = false; + + for (int j = 0; j < participants.Count; ++j) + { + if (i == j) + continue; + + if (hasAppended) + sb.Append(", "); + + sb.Append(participants[j].NameList); + hasAppended = true; + } + + sb.Append("."); + + part.AddLog(sb.ToString()); + } + } + + public List Participants{ get; set; } + + public TourneyParticipant Winner{ get; set; } + + public DuelContext Context{ get; set; } + + public bool InProgress => Context != null && Context.Registered; + + public void Start(Arena arena, Tournament tourney) + { + TourneyParticipant first = Participants[0]; + + DuelContext dc = new DuelContext(first.Players[0], tourney.Ruleset.Layout, false); + dc.Ruleset.Options.SetAll(false); + dc.Ruleset.Options.Or(tourney.Ruleset.Options); + + for (int i = 0; i < Participants.Count; ++i) + { + TourneyParticipant tourneyPart = Participants[i]; + Participant duelPart = new Participant(dc, tourneyPart.Players.Count) + { + TourneyPart = tourneyPart + }; + + + for (int j = 0; j < tourneyPart.Players.Count; ++j) + duelPart.Add(tourneyPart.Players[j]); + + for (int j = 0; j < duelPart.Players.Length; ++j) + if (duelPart.Players[j] != null) + duelPart.Players[j].Ready = true; + + dc.Participants.Add(duelPart); + } + + if (tourney.EventController != null) + dc.m_EventGame = tourney.EventController.Construct(dc); + + dc.m_Tournament = tourney; + dc.m_Match = this; + + dc.m_OverrideArena = arena; + + if (tourney.SuddenDeath > TimeSpan.Zero && + (tourney.SuddenDeathRounds == 0 || tourney.Pyramid.Levels.Count <= tourney.SuddenDeathRounds)) + dc.StartSuddenDeath(tourney.SuddenDeath); + + dc.SendReadyGump(0); + + if (dc.StartedBeginCountdown) + { + Context = dc; + + for (int i = 0; i < Participants.Count; ++i) + { + TourneyParticipant p = Participants[i]; + + for (int j = 0; j < p.Players.Count; ++j) + { + Mobile mob = p.Players[j]; + + foreach (Mobile view in mob.GetMobilesInRange(18)) + if (!mob.CanSee(view)) + mob.Send(view.RemovePacket); + + mob.LocalOverheadMessage(MessageType.Emote, 0x3B2, false, + "* Your mind focuses intently on the fight and all other distractions fade away *"); + } + } + } + else + { + dc.Unregister(); + dc.StopCountdown(); + } + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/Gumps/AcceptTeamGump.cs b/Scripts/Engines/ConPVP/Gumps/AcceptTeamGump.cs new file mode 100644 index 000000000..1300bb2df --- /dev/null +++ b/Scripts/Engines/ConPVP/Gumps/AcceptTeamGump.cs @@ -0,0 +1,382 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using Server.Gumps; +using Server.Mobiles; +using Server.Network; + +namespace Server.Engines.ConPVP +{ + public class AcceptTeamGump : Gump + { + private const int BlackColor32 = 0x000008; + private const int LabelColor32 = 0xFFFFFF; + private bool m_Active; + + private Mobile m_From; + private List m_Players; + private Mobile m_Registrar; + private Mobile m_Requested; + private Tournament m_Tournament; + + public AcceptTeamGump(Mobile from, Mobile requested, Tournament tourney, Mobile registrar, List players) : + base(50, 50) + { + m_From = from; + m_Requested = requested; + m_Tournament = tourney; + m_Registrar = registrar; + m_Players = players; + + m_Active = true; + + #region Rules + + Ruleset ruleset = tourney.Ruleset; + Ruleset basedef = ruleset.Base; + + int height = 185 + 35 + 60 + 12; + + int changes = 0; + + BitArray defs; + + if (ruleset.Flavors.Count > 0) + { + defs = new BitArray(basedef.Options); + + for (int i = 0; i < ruleset.Flavors.Count; ++i) + defs.Or(((Ruleset)ruleset.Flavors[i]).Options); + + height += ruleset.Flavors.Count * 18; + } + else + { + defs = basedef.Options; + } + + BitArray opts = ruleset.Options; + + for (int i = 0; i < opts.Length; ++i) + if (defs[i] != opts[i]) + ++changes; + + height += changes * 22; + + height += 10 + 22 + 25 + 25; + + #endregion + + Closable = false; + + AddPage(0); + + AddBackground(1, 1, 398, height, 3600); + + AddImageTiled(16, 15, 369, height - 29, 3604); + AddAlphaRegion(16, 15, 369, height - 29); + + AddImage(215, -43, 0xEE40); + + StringBuilder sb = new StringBuilder(); + + if (tourney.TourneyType == TourneyType.FreeForAll) + { + sb.Append("FFA"); + } + else if (tourney.TourneyType == TourneyType.RandomTeam) + { + sb.Append(tourney.ParticipantsPerMatch); + sb.Append("-Team"); + } + else if (tourney.TourneyType == TourneyType.Faction) + { + sb.Append(tourney.ParticipantsPerMatch); + sb.Append("-Team Faction"); + } + else if (tourney.TourneyType == TourneyType.RedVsBlue) + { + sb.Append("Red v Blue"); + } + else + { + for (int i = 0; i < tourney.ParticipantsPerMatch; ++i) + { + if (sb.Length > 0) + sb.Append('v'); + + sb.Append(tourney.PlayersPerParticipant); + } + } + + if (tourney.EventController != null) + sb.Append(' ').Append(tourney.EventController.Title); + + sb.Append(" Tournament Invitation"); + + AddBorderedText(22, 22, 294, 20, Center(sb.ToString()), LabelColor32, BlackColor32); + + AddBorderedText(22, 50, 294, 40, + $"You have been asked to partner with {from.Name} in a tournament. Do you accept?", + 0xB0C868, BlackColor32); + + AddImageTiled(32, 88, 264, 1, 9107); + AddImageTiled(42, 90, 264, 1, 9157); + + #region Rules + + int y = 100; + + string groupText = null; + + switch (tourney.GroupType) + { + case GroupingType.HighVsLow: + groupText = "High vs Low"; + break; + case GroupingType.Nearest: + groupText = "Closest opponent"; + break; + case GroupingType.Random: + groupText = "Random"; + break; + } + + AddBorderedText(35, y, 190, 20, $"Grouping: {groupText}", LabelColor32, BlackColor32); + y += 20; + + string tieText = null; + + switch (tourney.TieType) + { + case TieType.Random: + tieText = "Random"; + break; + case TieType.Highest: + tieText = "Highest advances"; + break; + case TieType.Lowest: + tieText = "Lowest advances"; + break; + case TieType.FullAdvancement: + tieText = tourney.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances"; + break; + case TieType.FullElimination: + tieText = tourney.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated"; + break; + } + + AddBorderedText(35, y, 190, 20, $"Tiebreaker: {tieText}", LabelColor32, BlackColor32); + y += 20; + + string sdText = "Off"; + + if (tourney.SuddenDeath > TimeSpan.Zero) + { + sdText = $"{(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2}"; + + if (tourney.SuddenDeathRounds > 0) + sdText = $"{sdText} (first {tourney.SuddenDeathRounds} rounds)"; + else + sdText = $"{sdText} (all rounds)"; + } + + AddBorderedText(35, y, 240, 20, $"Sudden Death: {sdText}", LabelColor32, BlackColor32); + y += 20; + + y += 6; + AddImageTiled(32, y - 1, 264, 1, 9107); + AddImageTiled(42, y + 1, 264, 1, 9157); + y += 6; + + AddBorderedText(35, y, 190, 20, $"Ruleset: {basedef.Title}", LabelColor32, BlackColor32); + y += 20; + + for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18) + AddBorderedText(35, y, 190, 20, $" + {((Ruleset)ruleset.Flavors[i]).Title}", LabelColor32, BlackColor32); + + y += 4; + + if (changes > 0) + { + AddBorderedText(35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32); + y += 20; + + for (int i = 0; i < opts.Length; ++i) + if (defs[i] != opts[i]) + { + string name = ruleset.Layout.FindByIndex(i); + + if (name != null) // sanity + { + AddImage(35, y, opts[i] ? 0xD3 : 0xD2); + AddBorderedText(60, y, 165, 22, name, LabelColor32, BlackColor32); + } + + y += 22; + } + } + else + { + AddBorderedText(35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32); + y += 20; + } + + #endregion + + y += 8; + AddImageTiled(32, y - 1, 264, 1, 9107); + AddImageTiled(42, y + 1, 264, 1, 9157); + y += 8; + + AddRadio(24, y, 9727, 9730, true, 1); + AddBorderedText(60, y + 5, 250, 20, "Yes, I will join them.", LabelColor32, BlackColor32); + y += 35; + + AddRadio(24, y, 9727, 9730, false, 2); + AddBorderedText(60, y + 5, 250, 20, "No, I do not wish to fight.", LabelColor32, BlackColor32); + y += 35; + + AddRadio(24, y, 9727, 9730, false, 3); + AddBorderedText(60, y + 5, 270, 20, "No, most certainly not. Do not ask again.", LabelColor32, BlackColor32); + y += 35; + + y -= 3; + AddButton(314, y, 247, 248, 1, GumpButtonType.Reply, 0); + + Timer.DelayCall(TimeSpan.FromSeconds(15.0), AutoReject); + } + + public string Center(string text) + { + return $"
{text}
"; + } + + public string Color(string text, int color) + { + return $"{text}"; + } + + private void AddBorderedText(int x, int y, int width, int height, string text, int color, int borderColor) + { + AddColoredText(x - 1, y - 1, width, height, text, borderColor); + AddColoredText(x - 1, y + 1, width, height, text, borderColor); + AddColoredText(x + 1, y - 1, width, height, text, borderColor); + AddColoredText(x + 1, y + 1, width, height, text, borderColor); + AddColoredText(x, y, width, height, text, color); + } + + private void AddColoredText(int x, int y, int width, int height, string text, int color) + { + if (color == 0) + AddHtml(x, y, width, height, text, false, false); + else + AddHtml(x, y, width, height, Color(text, color), false, false); + } + + public void AutoReject() + { + if (!m_Active) + return; + + m_Active = false; + + m_Requested.CloseGump(); + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + if (m_Registrar != null) + { + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, $"{m_Requested.Name} seems unresponsive.", m_From.NetState); + + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, $"You have declined the partnership with {m_From.Name}.", m_Requested.NetState); + } + } + + public override void OnResponse(NetState sender, RelayInfo info) + { + Mobile from = m_From; + Mobile mob = m_Requested; + + if (info.ButtonID != 1 || !m_Active) + return; + + m_Active = false; + + if (info.IsSwitched(1)) + { + if (!(mob is PlayerMobile pm)) + return; + + if (AcceptDuelGump.IsIgnored(mob, from) || mob.Blessed) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "They ignore your invitation.", from.NetState); + } + else if (pm.DuelContext != null) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "They are already assigned to another duel.", from.NetState); + } + else if (m_Players.Contains(mob)) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "You have already named them as a team member.", from.NetState); + } + else if (m_Tournament.HasParticipant(mob)) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "They have already entered this tournament.", from.NetState); + } + else if (m_Players.Count >= m_Tournament.PlayersPerParticipant) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "Your team is full.", from.NetState); + } + else + { + m_Players.Add(mob); + + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + if (m_Registrar != null) + { + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x59, false, $"{mob.Name} has accepted your offer of partnership.", from.NetState); + + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x59, false, $"You have accepted the partnership with {from.Name}.", mob.NetState); + } + } + } + else + { + if (info.IsSwitched(3)) + AcceptDuelGump.BeginIgnore(m_Requested, m_From); + + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + if (m_Registrar != null) + { + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, $"{mob.Name} has declined your offer of partnership.", from.NetState); + + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, $"You have declined the partnership with {from.Name}.", mob.NetState); + } + } + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/ArenaGump.cs b/Scripts/Engines/ConPVP/Gumps/ArenaGump.cs similarity index 95% rename from Scripts/Engines/ConPVP/ArenaGump.cs rename to Scripts/Engines/ConPVP/Gumps/ArenaGump.cs index d9161a52b..7c1685241 100644 --- a/Scripts/Engines/ConPVP/ArenaGump.cs +++ b/Scripts/Engines/ConPVP/Gumps/ArenaGump.cs @@ -50,7 +50,7 @@ namespace Server.Engines.ConPVP return false; } - from.CloseGump(typeof(ArenaGump)); + from.CloseGump(); from.SendGump(new ArenaGump(from, this)); if (!from.Hidden || from.AccessLevel == AccessLevel.Player) diff --git a/Scripts/Engines/ConPVP/BeginGump.cs b/Scripts/Engines/ConPVP/Gumps/BeginGump.cs similarity index 100% rename from Scripts/Engines/ConPVP/BeginGump.cs rename to Scripts/Engines/ConPVP/Gumps/BeginGump.cs diff --git a/Scripts/Engines/ConPVP/Gumps/ConfirmSignupGump.cs b/Scripts/Engines/ConPVP/Gumps/ConfirmSignupGump.cs new file mode 100644 index 000000000..e88ab26a9 --- /dev/null +++ b/Scripts/Engines/ConPVP/Gumps/ConfirmSignupGump.cs @@ -0,0 +1,566 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using Server.Factions; +using Server.Gumps; +using Server.Mobiles; +using Server.Network; +using Server.Targeting; + +namespace Server.Engines.ConPVP +{ +public class ConfirmSignupGump : Gump + { + private const int BlackColor32 = 0x000008; + private const int LabelColor32 = 0xFFFFFF; + private Mobile m_From; + private List m_Players; + private Mobile m_Registrar; + private Tournament m_Tournament; + + public ConfirmSignupGump(Mobile from, Mobile registrar, Tournament tourney, List players) : base(50, 50) + { + m_From = from; + m_Registrar = registrar; + m_Tournament = tourney; + m_Players = players; + + m_From.CloseGump(); + m_From.CloseGump(); + m_From.CloseGump(); + m_From.CloseGump(); + + #region Rules + + Ruleset ruleset = tourney.Ruleset; + Ruleset basedef = ruleset.Base; + + int height = 185 + 60 + 12; + + int changes = 0; + + BitArray defs; + + if (ruleset.Flavors.Count > 0) + { + defs = new BitArray(basedef.Options); + + for (int i = 0; i < ruleset.Flavors.Count; ++i) + defs.Or(((Ruleset)ruleset.Flavors[i]).Options); + + height += ruleset.Flavors.Count * 18; + } + else + { + defs = basedef.Options; + } + + BitArray opts = ruleset.Options; + + for (int i = 0; i < opts.Length; ++i) + if (defs[i] != opts[i]) + ++changes; + + height += changes * 22; + + height += 10 + 22 + 25 + 25; + + if (tourney.PlayersPerParticipant > 1) + height += 36 + tourney.PlayersPerParticipant * 20; + + #endregion + + Closable = false; + + AddPage(0); + + //AddBackground( 0, 0, 400, 220, 9150 ); + AddBackground(1, 1, 398, height, 3600); + //AddBackground( 16, 15, 369, 189, 9100 ); + + AddImageTiled(16, 15, 369, height - 29, 3604); + AddAlphaRegion(16, 15, 369, height - 29); + + AddImage(215, -43, 0xEE40); + //AddImage( 330, 141, 0x8BA ); + + StringBuilder sb = new StringBuilder(); + + if (tourney.TourneyType == TourneyType.FreeForAll) + { + sb.Append("FFA"); + } + else if (tourney.TourneyType == TourneyType.RandomTeam) + { + sb.Append(tourney.ParticipantsPerMatch); + sb.Append("-Team"); + } + else if (tourney.TourneyType == TourneyType.Faction) + { + sb.Append(tourney.ParticipantsPerMatch); + sb.Append("-Team Faction"); + } + else if (tourney.TourneyType == TourneyType.RedVsBlue) + { + sb.Append("Red v Blue"); + } + else + { + for (int i = 0; i < tourney.ParticipantsPerMatch; ++i) + { + if (sb.Length > 0) + sb.Append('v'); + + sb.Append(tourney.PlayersPerParticipant); + } + } + + if (tourney.EventController != null) + sb.Append(' ').Append(tourney.EventController.Title); + + sb.Append(" Tournament Signup"); + + AddBorderedText(22, 22, 294, 20, Center(sb.ToString()), LabelColor32, BlackColor32); + AddBorderedText(22, 50, 294, 40, "You have requested to join the tournament. Do you accept the rules?", 0xB0C868, + BlackColor32); + + AddImageTiled(32, 88, 264, 1, 9107); + AddImageTiled(42, 90, 264, 1, 9157); + + #region Rules + + int y = 100; + + string groupText = null; + + switch (tourney.GroupType) + { + case GroupingType.HighVsLow: + groupText = "High vs Low"; + break; + case GroupingType.Nearest: + groupText = "Closest opponent"; + break; + case GroupingType.Random: + groupText = "Random"; + break; + } + + AddBorderedText(35, y, 190, 20, $"Grouping: {groupText}", LabelColor32, BlackColor32); + y += 20; + + string tieText = null; + + switch (tourney.TieType) + { + case TieType.Random: + tieText = "Random"; + break; + case TieType.Highest: + tieText = "Highest advances"; + break; + case TieType.Lowest: + tieText = "Lowest advances"; + break; + case TieType.FullAdvancement: + tieText = tourney.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances"; + break; + case TieType.FullElimination: + tieText = tourney.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated"; + break; + } + + AddBorderedText(35, y, 190, 20, $"Tiebreaker: {tieText}", LabelColor32, BlackColor32); + y += 20; + + string sdText = "Off"; + + if (tourney.SuddenDeath > TimeSpan.Zero) + { + sdText = $"{(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2}"; + + if (tourney.SuddenDeathRounds > 0) + sdText = $"{sdText} (first {tourney.SuddenDeathRounds} rounds)"; + else + sdText = $"{sdText} (all rounds)"; + } + + AddBorderedText(35, y, 240, 20, $"Sudden Death: {sdText}", LabelColor32, BlackColor32); + y += 20; + + y += 6; + AddImageTiled(32, y - 1, 264, 1, 9107); + AddImageTiled(42, y + 1, 264, 1, 9157); + y += 6; + + AddBorderedText(35, y, 190, 20, $"Ruleset: {basedef.Title}", LabelColor32, BlackColor32); + y += 20; + + for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18) + AddBorderedText(35, y, 190, 20, $" + {((Ruleset)ruleset.Flavors[i]).Title}", LabelColor32, BlackColor32); + + y += 4; + + if (changes > 0) + { + AddBorderedText(35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32); + y += 20; + + for (int i = 0; i < opts.Length; ++i) + if (defs[i] != opts[i]) + { + string name = ruleset.Layout.FindByIndex(i); + + if (name != null) // sanity + { + AddImage(35, y, opts[i] ? 0xD3 : 0xD2); + AddBorderedText(60, y, 165, 22, name, LabelColor32, BlackColor32); + } + + y += 22; + } + } + else + { + AddBorderedText(35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32); + y += 20; + } + + #endregion + + #region Team + + if (tourney.PlayersPerParticipant > 1) + { + y += 8; + AddImageTiled(32, y - 1, 264, 1, 9107); + AddImageTiled(42, y + 1, 264, 1, 9157); + y += 8; + + AddBorderedText(35, y, 190, 20, "Your Team", LabelColor32, BlackColor32); + y += 20; + + for (int i = 0; i < players.Count; ++i, y += 20) + { + if (i == 0) + AddImage(35, y, 0xD2); + else + AddGoldenButton(35, y, 1 + i); + + AddBorderedText(60, y, 200, 20, players[i].Name, LabelColor32, BlackColor32); + } + + for (int i = players.Count; i < tourney.PlayersPerParticipant; ++i, y += 20) + { + if (i == 0) + AddImage(35, y, 0xD2); + else + AddGoldenButton(35, y, 1 + i); + + AddBorderedText(60, y, 200, 20, "(Empty)", LabelColor32, BlackColor32); + } + } + + #endregion + + y += 8; + AddImageTiled(32, y - 1, 264, 1, 9107); + AddImageTiled(42, y + 1, 264, 1, 9157); + y += 8; + + AddRadio(24, y, 9727, 9730, true, 1); + AddBorderedText(60, y + 5, 250, 20, "Yes, I wish to join the tournament.", LabelColor32, BlackColor32); + y += 35; + + AddRadio(24, y, 9727, 9730, false, 2); + AddBorderedText(60, y + 5, 250, 20, "No, I do not wish to join.", LabelColor32, BlackColor32); + y += 35; + + y -= 3; + AddButton(314, y, 247, 248, 1, GumpButtonType.Reply, 0); + } + + public string Center(string text) + { + return $"
{text}
"; + } + + public string Color(string text, int color) + { + return $"{text}"; + } + + private void AddBorderedText(int x, int y, int width, int height, string text, int color, int borderColor) + { + AddColoredText(x - 1, y - 1, width, height, text, borderColor); + AddColoredText(x - 1, y + 1, width, height, text, borderColor); + AddColoredText(x + 1, y - 1, width, height, text, borderColor); + AddColoredText(x + 1, y + 1, width, height, text, borderColor); + AddColoredText(x, y, width, height, text, color); + } + + private void AddColoredText(int x, int y, int width, int height, string text, int color) + { + if (color == 0) + AddHtml(x, y, width, height, text, false, false); + else + AddHtml(x, y, width, height, Color(text, color), false, false); + } + + public void AddGoldenButton(int x, int y, int bid) + { + AddButton(x, y, 0xD2, 0xD2, bid, GumpButtonType.Reply, 0); + AddButton(x + 3, y + 3, 0xD8, 0xD8, bid, GumpButtonType.Reply, 0); + } + + public override void OnResponse(NetState sender, RelayInfo info) + { + if (info.ButtonID == 1 && info.IsSwitched(1)) + { + Tournament tourney = m_Tournament; + Mobile from = m_From; + + switch (tourney.Stage) + { + case TournamentStage.Fighting: + { + if (m_Registrar != null) + { + if (m_Tournament.HasParticipant(from)) + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "Excuse me? You are already signed up.", from.NetState); + else + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "The tournament has already begun. You are too late to signup now.", + from.NetState); + } + + break; + } + case TournamentStage.Inactive: + { + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "The tournament is closed.", from.NetState); + + break; + } + case TournamentStage.Signup: + { + if (m_Players.Count != tourney.PlayersPerParticipant) + { + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "You have not yet chosen your team.", from.NetState); + + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + break; + } + + Ladder ladder = Ladder.Instance; + + for (int i = 0; i < m_Players.Count; ++i) + { + Mobile mob = m_Players[i]; + + LadderEntry entry = ladder?.Find(mob); + + if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement) + { + if (m_Registrar != null) + { + if (mob == from) + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "You have not yet proven yourself a worthy dueler.", from.NetState); + else + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, $"{mob.Name} has not yet proven themselves a worthy dueler.", + from.NetState); + } + + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + return; + } + + if (tourney.IsFactionRestricted && Faction.Find(mob) == null) + { + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "Only those who have declared their faction allegiance may participate.", + from.NetState); + + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + return; + } + + if (tourney.HasParticipant(mob)) + { + if (m_Registrar != null) + { + if (mob == from) + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "You have already entered this tournament.", from.NetState); + else + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, $"{mob.Name} has already entered this tournament.", from.NetState); + } + + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + return; + } + + if (mob is PlayerMobile mobile && mobile.DuelContext != null) + { + if (mob == from) + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, + "You are already assigned to a duel. You must yield it before joining this tournament.", + from.NetState); + else + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, + $"{mobile.Name} is already assigned to a duel. They must yield it before joining this tournament.", + from.NetState); + + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + return; + } + } + + if (m_Registrar != null) + { + string fmt; + + if (tourney.PlayersPerParticipant == 1) + fmt = + "As you say m'{0}. I've written your name to the bracket. The tournament will begin {1}."; + else if (tourney.PlayersPerParticipant == 2) + fmt = + "As you wish m'{0}. The tournament will begin {1}, but first you must name your partner."; + else + fmt = "As you wish m'{0}. The tournament will begin {1}, but first you must name your team."; + + string timeUntil; + int minutesUntil = (int)Math.Round((tourney.SignupStart + tourney.SignupPeriod - DateTime.UtcNow) + .TotalMinutes); + + if (minutesUntil == 0) + timeUntil = "momentarily"; + else + timeUntil = $"in {minutesUntil} minute{(minutesUntil == 1 ? "" : "s")}"; + + m_Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, string.Format(fmt, from.Female ? "Lady" : "Lord", timeUntil), from.NetState); + } + + TourneyParticipant part = new TourneyParticipant(from); + part.Players.Clear(); + part.Players.AddRange(m_Players); + + tourney.Participants.Add(part); + + break; + } + } + } + else if (info.ButtonID > 1) + { + int index = info.ButtonID - 1; + + if (index > 0 && index < m_Players.Count) + { + m_Players.RemoveAt(index); + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + } + else if (m_Players.Count < m_Tournament.PlayersPerParticipant) + { + m_From.BeginTarget(12, false, TargetFlags.None, AddPlayer_OnTarget); + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + } + } + } + + private void AddPlayer_OnTarget(Mobile from, object obj) + { + if (!(obj is Mobile mob) || mob == from) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "Excuse me?", from.NetState); + } + else if (!mob.Player) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + if (mob.Body.IsHuman) + mob.SayTo(from, 1005443); // Nay, I would rather stay here and watch a nail rust. + else + mob.SayTo(from, 1005444); // The creature ignores your offer. + } + else if (AcceptDuelGump.IsIgnored(mob, from) || mob.Blessed) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "They ignore your invitation.", from.NetState); + } + else + { + if (!(mob is PlayerMobile pm)) + return; + + if (pm.DuelContext != null) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "They are already assigned to another duel.", from.NetState); + } + else if (mob.HasGump()) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "They have already been offered a partnership.", from.NetState); + } + else if (mob.HasGump()) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "They are already trying to join this tournament.", from.NetState); + } + else if (m_Players.Contains(mob)) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "You have already named them as a team member.", from.NetState); + } + else if (m_Tournament.HasParticipant(mob)) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "They have already entered this tournament.", from.NetState); + } + else if (m_Players.Count >= m_Tournament.PlayersPerParticipant) + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "Your team is full.", from.NetState); + } + else + { + m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); + mob.SendGump(new AcceptTeamGump(from, mob, m_Tournament, m_Registrar, m_Players)); + + m_Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x59, false, + $"As you command m'{(from.Female ? "Lady" : "Lord")}. I've given your offer to {mob.Name}.", + from.NetState); + } + } + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/DuelContextGump.cs b/Scripts/Engines/ConPVP/Gumps/DuelContextGump.cs similarity index 92% rename from Scripts/Engines/ConPVP/DuelContextGump.cs rename to Scripts/Engines/ConPVP/Gumps/DuelContextGump.cs index a6560083c..1d38f2d5c 100644 --- a/Scripts/Engines/ConPVP/DuelContextGump.cs +++ b/Scripts/Engines/ConPVP/Gumps/DuelContextGump.cs @@ -10,9 +10,9 @@ namespace Server.Engines.ConPVP From = from; Context = context; - from.CloseGump(typeof(RulesetGump)); - from.CloseGump(typeof(DuelContextGump)); - from.CloseGump(typeof(ParticipantGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); int count = context.Participants.Count; diff --git a/Scripts/Engines/ConPVP/LadderGump.cs b/Scripts/Engines/ConPVP/Gumps/LadderGump.cs similarity index 85% rename from Scripts/Engines/ConPVP/LadderGump.cs rename to Scripts/Engines/ConPVP/Gumps/LadderGump.cs index d7ab629a1..f8a544e4f 100644 --- a/Scripts/Engines/ConPVP/LadderGump.cs +++ b/Scripts/Engines/ConPVP/Gumps/LadderGump.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Network; @@ -41,7 +41,7 @@ namespace Server.Engines.ConPVP { case 1: { - Ladder = reader.ReadItem() as LadderController; + Ladder = reader.ReadItem(); break; } } @@ -51,15 +51,12 @@ namespace Server.Engines.ConPVP { if (from.InRange(GetWorldLocation(), 2)) { - Ladder ladder = ConPVP.Ladder.Instance; - - if (Ladder != null) - ladder = Ladder.Ladder; + Ladder ladder = ConPVP.Ladder.Instance ?? Ladder.Ladder; if (ladder != null) { - from.CloseGump(typeof(LadderGump)); - from.SendGump(new LadderGump(ladder, 0)); + from.CloseGump(); + from.SendGump(new LadderGump(ladder)); } } else @@ -74,24 +71,19 @@ namespace Server.Engines.ConPVP private int m_ColumnX = 12; private Ladder m_Ladder; - private ArrayList m_List; + private List m_List; private int m_Page; - public LadderGump(Ladder ladder) : this(ladder, 0) - { - } - - public LadderGump(Ladder ladder, int page) : base(50, 50) + public LadderGump(Ladder ladder, int page = 0) : base(50, 50) { m_Ladder = ladder; m_Page = page; AddPage(0); - ArrayList list = ladder.ToArrayList(); - m_List = list; + m_List = new List(ladder.Entries); - int lc = Math.Min(list.Count, 150); + int lc = Math.Min(m_List.Count, 150); int start = page * 15; int end = start + 15; @@ -121,7 +113,7 @@ namespace Server.Engines.ConPVP AddImage(466, height - 12 - 2 - 16, 0x2622); AddHtml(16, height - 12 - 2 - 18, 400, 20, - Color(string.Format("Top {3} of {0:N0} duelists, page {1} of {2}", list.Count, page + 1, (lc + 14) / 15, lc), + Color(string.Format("Top {3} of {0:N0} duelists, page {1} of {2}", m_List.Count, page + 1, (lc + 14) / 15, lc), 0xFFC000), false, false); AddColumnHeader(75, "Rank"); @@ -133,7 +125,7 @@ namespace Server.Engines.ConPVP for (int i = start; i < end && i < lc; ++i) { - LadderEntry entry = (LadderEntry)list[i]; + LadderEntry entry = m_List[i]; int y = 32 + (i - start) * 20; int x = 12; @@ -153,8 +145,7 @@ namespace Server.Engines.ConPVP int xp = entry.Experience; int level = Ladder.GetLevel(xp); - int xpBase, xpAdvance; - Ladder.GetLevelInfo(level, out xpBase, out xpAdvance); + Ladder.GetLevelInfo(level, out int xpBase, out int xpAdvance); int width; diff --git a/Scripts/Engines/ConPVP/ParticipantGump.cs b/Scripts/Engines/ConPVP/Gumps/ParticipantGump.cs similarity index 94% rename from Scripts/Engines/ConPVP/ParticipantGump.cs rename to Scripts/Engines/ConPVP/Gumps/ParticipantGump.cs index 58d8a8787..c4837161e 100644 --- a/Scripts/Engines/ConPVP/ParticipantGump.cs +++ b/Scripts/Engines/ConPVP/Gumps/ParticipantGump.cs @@ -13,9 +13,9 @@ namespace Server.Engines.ConPVP Context = context; Participant = p; - from.CloseGump(typeof(RulesetGump)); - from.CloseGump(typeof(DuelContextGump)); - from.CloseGump(typeof(ParticipantGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); int count = p.Players.Length; @@ -231,7 +231,7 @@ namespace Server.Engines.ConPVP from.SendMessage("{0} cannot fight because they have recently been in combat with another player.", pm.Name); } - else if (mob.HasGump(typeof(AcceptDuelGump))) + else if (mob.HasGump()) { from.SendMessage("{0} has already been offered a duel."); } diff --git a/Scripts/Engines/ConPVP/PickRulesetGump.cs b/Scripts/Engines/ConPVP/Gumps/PickRulesetGump.cs similarity index 100% rename from Scripts/Engines/ConPVP/PickRulesetGump.cs rename to Scripts/Engines/ConPVP/Gumps/PickRulesetGump.cs diff --git a/Scripts/Engines/ConPVP/ReadyGump.cs b/Scripts/Engines/ConPVP/Gumps/ReadyGump.cs similarity index 91% rename from Scripts/Engines/ConPVP/ReadyGump.cs rename to Scripts/Engines/ConPVP/Gumps/ReadyGump.cs index 3853f0f18..ff04ced65 100644 --- a/Scripts/Engines/ConPVP/ReadyGump.cs +++ b/Scripts/Engines/ConPVP/Gumps/ReadyGump.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Network; @@ -16,7 +16,7 @@ namespace Server.Engines.ConPVP m_Context = context; m_Count = count; - ArrayList parts = context.Participants; + List parts = context.Participants; int height = 25 + 20; @@ -35,7 +35,7 @@ namespace Server.Engines.ConPVP height += 25; Closable = false; - Dragable = false; + Draggable = false; AddPage(0); diff --git a/Scripts/Engines/ConPVP/ReadyUpGump.cs b/Scripts/Engines/ConPVP/Gumps/ReadyUpGump.cs similarity index 92% rename from Scripts/Engines/ConPVP/ReadyUpGump.cs rename to Scripts/Engines/ConPVP/Gumps/ReadyUpGump.cs index fc522ef4d..c19878547 100644 --- a/Scripts/Engines/ConPVP/ReadyUpGump.cs +++ b/Scripts/Engines/ConPVP/Gumps/ReadyUpGump.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Mobiles; using Server.Network; @@ -36,13 +37,13 @@ namespace Server.Engines.ConPVP AddPage(1); - ArrayList parts = context.Participants; + List parts = context.Participants; int height = 25 + 20; for (int i = 0; i < parts.Count; ++i) { - Participant p = (Participant)parts[i]; + Participant p = parts[i]; height += 4; @@ -63,7 +64,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < parts.Count; ++i) { - Participant p = (Participant)parts[i]; + Participant p = parts[i]; y += 4; diff --git a/Scripts/Engines/ConPVP/RulesetGump.cs b/Scripts/Engines/ConPVP/Gumps/RulesetGump.cs similarity index 84% rename from Scripts/Engines/ConPVP/RulesetGump.cs rename to Scripts/Engines/ConPVP/Gumps/RulesetGump.cs index 74f893424..3470e6ac5 100644 --- a/Scripts/Engines/ConPVP/RulesetGump.cs +++ b/Scripts/Engines/ConPVP/Gumps/RulesetGump.cs @@ -12,13 +12,8 @@ namespace Server.Engines.ConPVP private bool m_ReadOnly; private Ruleset m_Ruleset; - public RulesetGump(Mobile from, Ruleset ruleset, RulesetLayout page, DuelContext duelContext) : this(from, ruleset, - page, duelContext, false) - { - } - - public RulesetGump(Mobile from, Ruleset ruleset, RulesetLayout page, DuelContext duelContext, bool readOnly) : base( - readOnly ? 310 : 50, 50) + public RulesetGump(Mobile from, Ruleset ruleset, RulesetLayout page, DuelContext duelContext, bool readOnly = false) + : base(readOnly ? 310 : 50, 50) { m_From = from; m_Ruleset = ruleset; @@ -26,11 +21,11 @@ namespace Server.Engines.ConPVP m_DuelContext = duelContext; m_ReadOnly = readOnly; - Dragable = !readOnly; + Draggable = !readOnly; - from.CloseGump(typeof(RulesetGump)); - from.CloseGump(typeof(DuelContextGump)); - from.CloseGump(typeof(ParticipantGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); RulesetLayout depthCounter = page; int depth = 0; diff --git a/Scripts/Engines/ConPVP/Gumps/TournamentBracketGump.cs b/Scripts/Engines/ConPVP/Gumps/TournamentBracketGump.cs new file mode 100644 index 000000000..85b88c532 --- /dev/null +++ b/Scripts/Engines/ConPVP/Gumps/TournamentBracketGump.cs @@ -0,0 +1,862 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using Server.Gumps; +using Server.Mobiles; +using Server.Network; + +namespace Server.Engines.ConPVP +{ + public enum TourneyBracketGumpType + { + Index, + Rules_Info, + Participant_List, + Participant_Info, + Round_List, + Round_Info, + Match_Info, + Player_Info + } + + public class TournamentBracketGump : Gump + { + private const int BlackColor32 = 0x000008; + private const int LabelColor32 = 0xFFFFFF; + private Mobile m_From; + private List m_List; + private object m_Object; + private int m_Page; + private int m_PerPage; + private Tournament m_Tournament; + private TourneyBracketGumpType m_Type; + + public TournamentBracketGump(Mobile from, Tournament tourney, TourneyBracketGumpType type, + List list = null, int page = 0, object obj = null) : base(50, 50) + { + m_From = from; + m_Tournament = tourney; + m_Type = type; + m_List = list; + m_Page = page; + m_Object = obj; + m_PerPage = 12; + + switch (type) + { + case TourneyBracketGumpType.Index: + { + AddPage(0); + AddBackground(0, 0, 300, 300, 9380); + + StringBuilder sb = new StringBuilder(); + + if (tourney.TourneyType == TourneyType.FreeForAll) + { + sb.Append("FFA"); + } + else if (tourney.TourneyType == TourneyType.RandomTeam) + { + sb.Append(tourney.ParticipantsPerMatch); + sb.Append("-Team"); + } + else if (tourney.TourneyType == TourneyType.RedVsBlue) + { + sb.Append("Red v Blue"); + } + else if (tourney.TourneyType == TourneyType.Faction) + { + sb.Append(tourney.ParticipantsPerMatch); + sb.Append("-Team Faction"); + } + else + { + for (int i = 0; i < tourney.ParticipantsPerMatch; ++i) + { + if (sb.Length > 0) + sb.Append('v'); + + sb.Append(tourney.PlayersPerParticipant); + } + } + + if (tourney.EventController != null) + sb.Append(' ').Append(tourney.EventController.Title); + + sb.Append(" Tournament Bracket"); + + AddHtml(25, 35, 250, 20, Center(sb.ToString()), false, false); + + AddRightArrow(25, 53, ToButtonID(0, 4), "Rules"); + AddRightArrow(25, 71, ToButtonID(0, 1), "Participants"); + + if (m_Tournament.Stage == TournamentStage.Signup) + { + TimeSpan until = m_Tournament.SignupStart + m_Tournament.SignupPeriod - DateTime.UtcNow; + string text; + int secs = (int)until.TotalSeconds; + + if (secs > 0) + { + int mins = secs / 60; + secs %= 60; + + if (mins > 0 && secs > 0) + text = + $"The tournament will begin in {mins} minute{(mins == 1 ? "" : "s")} and {secs} second{(secs == 1 ? "" : "s")}."; + else if (mins > 0) + text = $"The tournament will begin in {mins} minute{(mins == 1 ? "" : "s")}."; + else if (secs > 0) + text = $"The tournament will begin in {secs} second{(secs == 1 ? "" : "s")}."; + else + text = "The tournament will begin shortly."; + } + else + { + text = "The tournament will begin shortly."; + } + + AddHtml(25, 92, 250, 40, text, false, false); + } + else + { + AddRightArrow(25, 89, ToButtonID(0, 2), "Rounds"); + } + + break; + } + case TourneyBracketGumpType.Rules_Info: + { + Ruleset ruleset = tourney.Ruleset; + Ruleset basedef = ruleset.Base; + + BitArray defs; + + if (ruleset.Flavors.Count > 0) + { + defs = new BitArray(basedef.Options); + + for (int i = 0; i < ruleset.Flavors.Count; ++i) + defs.Or(((Ruleset)ruleset.Flavors[i]).Options); + } + else + { + defs = basedef.Options; + } + + int changes = 0; + + BitArray opts = ruleset.Options; + + for (int i = 0; i < opts.Length; ++i) + if (defs[i] != opts[i]) + ++changes; + + AddPage(0); + AddBackground(0, 0, 300, + 60 + 18 + 20 + 20 + 20 + 8 + 20 + ruleset.Flavors.Count * 18 + 4 + 20 + changes * 22 + 6, 9380); + + AddLeftArrow(25, 11, ToButtonID(0, 0)); + AddHtml(25, 35, 250, 20, Center("Rules"), false, false); + + int y = 53; + + string groupText = null; + + switch (tourney.GroupType) + { + case GroupingType.HighVsLow: + groupText = "High vs Low"; + break; + case GroupingType.Nearest: + groupText = "Closest opponent"; + break; + case GroupingType.Random: + groupText = "Random"; + break; + } + + AddHtml(35, y, 190, 20, $"Grouping: {groupText}", false, false); + y += 20; + + string tieText = null; + + switch (tourney.TieType) + { + case TieType.Random: + tieText = "Random"; + break; + case TieType.Highest: + tieText = "Highest advances"; + break; + case TieType.Lowest: + tieText = "Lowest advances"; + break; + case TieType.FullAdvancement: + tieText = tourney.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances"; + break; + case TieType.FullElimination: + tieText = tourney.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated"; + break; + } + + AddHtml(35, y, 190, 20, $"Tiebreaker: {tieText}", false, false); + y += 20; + + string sdText = "Off"; + + if (tourney.SuddenDeath > TimeSpan.Zero) + { + sdText = $"{(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2}"; + + if (tourney.SuddenDeathRounds > 0) + sdText = $"{sdText} (first {tourney.SuddenDeathRounds} rounds)"; + else + sdText = $"{sdText} (all rounds)"; + } + + AddHtml(35, y, 240, 20, $"Sudden Death: {sdText}", false, false); + y += 20; + + y += 8; + + AddHtml(35, y, 190, 20, $"Ruleset: {basedef.Title}", false, false); + y += 20; + + for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18) + AddHtml(35, y, 190, 20, $" + {((Ruleset)ruleset.Flavors[i]).Title}", false, false); + + y += 4; + + if (changes > 0) + { + AddHtml(35, y, 190, 20, "Modifications:", false, false); + y += 20; + + for (int i = 0; i < opts.Length; ++i) + if (defs[i] != opts[i]) + { + string name = ruleset.Layout.FindByIndex(i); + + if (name != null) // sanity + { + AddImage(35, y, opts[i] ? 0xD3 : 0xD2); + AddHtml(60, y, 165, 22, name, false, false); + } + + y += 22; + } + } + else + { + AddHtml(35, y, 190, 20, "Modifications: None", false, false); + } + + break; + } + case TourneyBracketGumpType.Participant_List: + { + AddPage(0); + AddBackground(0, 0, 300, 300, 9380); + + List pList = m_List != null + ? Utility.CastListCovariant(m_List) + : new List(tourney.Participants); + + AddLeftArrow(25, 11, ToButtonID(0, 0)); + AddHtml(25, 35, 250, 20, Center($"{pList.Count} Participant{(pList.Count == 1 ? "" : "s")}"), false, + false); + + StartPage(out int index, out int count, out int y, 12); + + for (int i = 0; i < count; ++i, y += 18) + { + TourneyParticipant part = pList[index + i]; + string name = part.NameList; + + if (m_Tournament.TourneyType != TourneyType.Standard && part.Players.Count == 1) + if (part.Players[0] is PlayerMobile pm && pm.DuelPlayer != null) + name = Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666); + + AddRightArrow(25, y, ToButtonID(2, index + i), name); + } + + break; + } + case TourneyBracketGumpType.Participant_Info: + { + if (!(obj is TourneyParticipant part)) + break; + + AddPage(0); + AddBackground(0, 0, 300, 60 + 18 + 20 + part.Players.Count * 18 + 20 + 20 + 160, 9380); + + AddLeftArrow(25, 11, ToButtonID(0, 1)); + AddHtml(25, 35, 250, 20, Center("Participants"), false, false); + + int y = 53; + + AddHtml(25, y, 200, 20, part.Players.Count == 1 ? "Players" : "Team", false, false); + y += 20; + + for (int i = 0; i < part.Players.Count; ++i) + { + Mobile mob = part.Players[i]; + string name = mob.Name; + + if (m_Tournament.TourneyType != TourneyType.Standard) + if (mob is PlayerMobile pm && pm.DuelPlayer != null) + name = Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666); + + AddRightArrow(35, y, ToButtonID(4, i), name); + y += 18; + } + + AddHtml(25, y, 200, 20, + $"Free Advances: {(part.FreeAdvances == 0 ? "None" : part.FreeAdvances.ToString())}", false, false); + y += 20; + + AddHtml(25, y, 200, 20, "Log:", false, false); + y += 20; + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < part.Log.Count; ++i) + { + if (sb.Length > 0) + sb.Append("
"); + + sb.Append(part.Log[i]); + } + + if (sb.Length == 0) + sb.Append("Nothing logged yet."); + + AddHtml(25, y, 250, 150, Color(sb.ToString(), BlackColor32), false, true); + + break; + } + case TourneyBracketGumpType.Player_Info: + { + AddPage(0); + AddBackground(0, 0, 300, 300, 9380); + + AddLeftArrow(25, 11, ToButtonID(0, 3)); + AddHtml(25, 35, 250, 20, Center("Participants"), false, false); + + if (!(obj is Mobile mob)) + break; + + Ladder ladder = Ladder.Instance; + LadderEntry entry = ladder?.Find(mob); + + AddHtml(25, 53, 250, 20, $"Name: {mob.Name}", false, false); + AddHtml(25, 73, 250, 20, + $"Guild: {(mob.Guild == null ? "None" : mob.Guild.Name + " [" + mob.Guild.Abbreviation + "]")}", + false, false); + AddHtml(25, 93, 250, 20, $"Rank: {(entry == null ? "N/A" : LadderGump.Rank(entry.Index + 1))}", false, + false); + AddHtml(25, 113, 250, 20, $"Level: {(entry == null ? 0 : Ladder.GetLevel(entry.Experience))}", false, + false); + AddHtml(25, 133, 250, 20, $"Wins: {entry?.Wins ?? 0:N0}", false, false); + AddHtml(25, 153, 250, 20, $"Losses: {entry?.Losses ?? 0:N0}", false, false); + + break; + } + case TourneyBracketGumpType.Round_List: + { + AddPage(0); + AddBackground(0, 0, 300, 300, 9380); + + AddLeftArrow(25, 11, ToButtonID(0, 0)); + AddHtml(25, 35, 250, 20, Center("Rounds"), false, false); + +// List levelsList = m_List != null +// ? Utility.CastListCovariant(m_List) +// : new List(tourney.Pyramid.Levels); + + StartPage(out int index, out int count, out int y, 12); + + for (int i = 0; i < count; ++i, y += 18) + AddRightArrow(25, y, ToButtonID(3, index + i), "Round #" + (index + i + 1)); + + break; + } + case TourneyBracketGumpType.Round_Info: + { + AddPage(0); + AddBackground(0, 0, 300, 300, 9380); + + AddLeftArrow(25, 11, ToButtonID(0, 2)); + AddHtml(25, 35, 250, 20, Center("Rounds"), false, false); + + if (!(m_Object is PyramidLevel level)) + break; + + List matchesList = m_List != null + ? Utility.CastListCovariant(m_List) + : new List(level.Matches); + + AddRightArrow(25, 53, ToButtonID(5, 0), + $"Free Advance: {(level.FreeAdvance == null ? "None" : level.FreeAdvance.NameList)}"); + + AddHtml(25, 73, 200, 20, $"{matchesList.Count} Match{(matchesList.Count == 1 ? "" : "es")}", false, false); + + StartPage(out int index, out int count, out int y, 10); + + for (int i = 0; i < count; ++i, y += 18) + { + TourneyMatch match = matchesList[index + i]; + + int color = -1; + + if (match.InProgress) + color = 0x336666; + else if (match.Context != null && match.Winner == null) + color = 0x666666; + + StringBuilder sb = new StringBuilder(); + + if (m_Tournament.TourneyType == TourneyType.Standard) + for (int j = 0; j < match.Participants.Count; ++j) + { + if (sb.Length > 0) + sb.Append(" vs "); + + TourneyParticipant part = match.Participants[j]; + string txt = part.NameList; + + if (color == -1 && match.Context != null && match.Winner == part) + txt = Color(txt, 0x336633); + else if (color == -1 && match.Context != null) + txt = Color(txt, 0x663333); + + sb.Append(txt); + } + else if (m_Tournament.EventController != null || m_Tournament.TourneyType == TourneyType.RandomTeam || + m_Tournament.TourneyType == TourneyType.RedVsBlue || + m_Tournament.TourneyType == TourneyType.Faction) + for (int j = 0; j < match.Participants.Count; ++j) + { + if (sb.Length > 0) + sb.Append(" vs "); + + TourneyParticipant part = match.Participants[j]; + string txt; + + if (m_Tournament.EventController != null) + { + txt = $"Team {m_Tournament.EventController.GetTeamName(j)} ({part.Players.Count})"; + } + else if (m_Tournament.TourneyType == TourneyType.RandomTeam) + { + txt = $"Team {j + 1} ({part.Players.Count})"; + } + else if (m_Tournament.TourneyType == TourneyType.Faction) + { + if (m_Tournament.ParticipantsPerMatch == 4) + { + string name = "(null)"; + + switch (j) + { + case 0: + { + name = "Minax"; + break; + } + case 1: + { + name = "Council of Mages"; + break; + } + case 2: + { + name = "True Britannians"; + break; + } + case 3: + { + name = "Shadowlords"; + break; + } + } + + txt = $"{name} ({part.Players.Count})"; + } + else if (m_Tournament.ParticipantsPerMatch == 2) + { + txt = $"{(j == 0 ? "Evil" : "Hero")} Team ({part.Players.Count})"; + } + else + { + txt = $"Team {j + 1} ({part.Players.Count})"; + } + } + else + { + txt = $"Team {(j == 0 ? "Red" : "Blue")} ({part.Players.Count})"; + } + + if (color == -1 && match.Context != null && match.Winner == part) + txt = Color(txt, 0x336633); + else if (color == -1 && match.Context != null) + txt = Color(txt, 0x663333); + + sb.Append(txt); + } + else if (m_Tournament.TourneyType == TourneyType.FreeForAll) sb.Append("Free For All"); + + string str = sb.ToString(); + + if (color >= 0) + str = Color(str, color); + + AddRightArrow(25, y, ToButtonID(5, index + i + 1), str); + } + + break; + } + case TourneyBracketGumpType.Match_Info: + { + if (!(obj is TourneyMatch match)) + break; + + int ct = m_Tournament.TourneyType == TourneyType.FreeForAll ? 2 : match.Participants.Count; + + AddPage(0); + AddBackground(0, 0, 300, 60 + 18 + 20 + 20 + 20 + ct * 18 + 6, 9380); + + AddLeftArrow(25, 11, ToButtonID(0, 5)); + AddHtml(25, 35, 250, 20, Center("Rounds"), false, false); + + AddHtml(25, 53, 250, 20, $"Winner: {(match.Winner == null ? "N/A" : match.Winner.NameList)}", false, + false); + AddHtml(25, 73, 250, 20, + $"State: {(match.InProgress ? "In progress" : match.Context != null ? "Complete" : "Waiting")}", + false, false); + AddHtml(25, 93, 250, 20, "Participants:", false, false); + + if (m_Tournament.TourneyType == TourneyType.Standard) + for (int i = 0; i < match.Participants.Count; ++i) + { + TourneyParticipant part = match.Participants[i]; + + AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), part.NameList); + } + else if (m_Tournament.EventController != null || m_Tournament.TourneyType == TourneyType.RandomTeam || + m_Tournament.TourneyType == TourneyType.RedVsBlue || + m_Tournament.TourneyType == TourneyType.Faction) + for (int i = 0; i < match.Participants.Count; ++i) + { + TourneyParticipant part = match.Participants[i]; + + if (m_Tournament.EventController != null) + { + AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), + $"Team {m_Tournament.EventController.GetTeamName(i)} ({part.Players.Count})"); + } + else if (m_Tournament.TourneyType == TourneyType.RandomTeam) + { + AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), + $"Team {i + 1} ({part.Players.Count})"); + } + else if (m_Tournament.TourneyType == TourneyType.Faction) + { + if (m_Tournament.ParticipantsPerMatch == 4) + { + string name = "(null)"; + + switch (i) + { + case 0: + { + name = "Minax"; + break; + } + case 1: + { + name = "Council of Mages"; + break; + } + case 2: + { + name = "True Britannians"; + break; + } + case 3: + { + name = "Shadowlords"; + break; + } + } + + AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), + $"{name} ({part.Players.Count})"); + } + else if (m_Tournament.ParticipantsPerMatch == 2) + { + AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), + $"{(i == 0 ? "Evil" : "Hero")} Team ({part.Players.Count})"); + } + else + { + AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), + $"Team {i + 1} ({part.Players.Count})"); + } + } + else + { + AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), + $"Team {(i == 0 ? "Red" : "Blue")} ({part.Players.Count})"); + } + } + else if (m_Tournament.TourneyType == TourneyType.FreeForAll) + AddHtml(25, 113, 250, 20, "Free For All", false, false); + + break; + } + } + } + + public string Center(string text) + { + return $"
{text}
"; + } + + public string Color(string text, int color) + { + return $"{text}"; + } + + private void AddBorderedText(int x, int y, int width, int height, string text, int color, int borderColor) + { + AddColoredText(x - 1, y - 1, width, height, text, borderColor); + AddColoredText(x - 1, y + 1, width, height, text, borderColor); + AddColoredText(x + 1, y - 1, width, height, text, borderColor); + AddColoredText(x + 1, y + 1, width, height, text, borderColor); + AddColoredText(x, y, width, height, text, color); + } + + private void AddColoredText(int x, int y, int width, int height, string text, int color) + { + if (color == 0) + AddHtml(x, y, width, height, text, false, false); + else + AddHtml(x, y, width, height, Color(text, color), false, false); + } + + public void AddRightArrow(int x, int y, int bid, string text) + { + AddButton(x, y, 0x15E1, 0x15E5, bid, GumpButtonType.Reply, 0); + + if (text != null) + AddHtml(x + 20, y - 1, 230, 20, text, false, false); + } + + public void AddRightArrow(int x, int y, int bid) + { + AddRightArrow(x, y, bid, null); + } + + public void AddLeftArrow(int x, int y, int bid, string text) + { + AddButton(x, y, 0x15E3, 0x15E7, bid, GumpButtonType.Reply, 0); + + if (text != null) + AddHtml(x + 20, y - 1, 230, 20, text, false, false); + } + + public void AddLeftArrow(int x, int y, int bid) + { + AddLeftArrow(x, y, bid, null); + } + + public int ToButtonID(int type, int index) + { + return 1 + index * 7 + type; + } + + public bool FromButtonID(int bid, out int type, out int index) + { + type = (bid - 1) % 7; + index = (bid - 1) / 7; + return bid >= 1; + } + + public void StartPage(out int index, out int count, out int y, int perPage) + { + m_PerPage = perPage; + + index = Math.Max(m_Page * perPage, 0); + count = Math.Max(Math.Min(m_List.Count - index, perPage), 0); + + y = 53 + (12 - perPage) * 18; + + if (m_Page > 0) + AddLeftArrow(242, 35, ToButtonID(1, 0)); + + if ((m_Page + 1) * perPage < m_List.Count) + AddRightArrow(260, 35, ToButtonID(1, 1)); + } + + public override void OnResponse(NetState sender, RelayInfo info) + { + if (!FromButtonID(info.ButtonID, out int type, out int index)) + return; + + switch (type) + { + case 0: + { + switch (index) + { + case 0: + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TourneyBracketGumpType.Index)); + break; + case 1: + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, + TourneyBracketGumpType.Participant_List)); + break; + case 2: + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TourneyBracketGumpType.Round_List)); + break; + case 4: + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TourneyBracketGumpType.Rules_Info)); + break; + case 3: + { + Mobile mob = m_Object as Mobile; + + for (int i = 0; i < m_Tournament.Participants.Count; ++i) + { + TourneyParticipant part = m_Tournament.Participants[i]; + + if (part.Players.Contains(mob)) + { + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, + TourneyBracketGumpType.Participant_Info, null, 0, part)); + break; + } + } + + break; + } + case 5: + { + if (!(m_Object is TourneyMatch match)) + break; + + for (int i = 0; i < m_Tournament.Pyramid.Levels.Count; ++i) + { + PyramidLevel level = m_Tournament.Pyramid.Levels[i]; + + if (level.Matches.Contains(match)) + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, + TourneyBracketGumpType.Round_Info, null, 0, level)); + } + + break; + } + } + + break; + } + case 1: + { + switch (index) + { + case 0: + { + if (m_List != null && m_Page > 0) + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, m_Type, m_List, m_Page - 1, + m_Object)); + + break; + } + case 1: + { + if (m_List != null && (m_Page + 1) * m_PerPage < m_List.Count) + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, m_Type, m_List, m_Page + 1, + m_Object)); + + break; + } + } + + break; + } + case 2: + { + if (m_Type != TourneyBracketGumpType.Participant_List) + break; + + if (index >= 0 && index < m_List.Count) + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, + TourneyBracketGumpType.Participant_Info, null, 0, m_List[index])); + + break; + } + case 3: + { + if (m_Type != TourneyBracketGumpType.Round_List) + break; + + if (index >= 0 && index < m_List.Count) + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TourneyBracketGumpType.Round_Info, + null, 0, m_List[index])); + + break; + } + case 4: + { + if (m_Type != TourneyBracketGumpType.Participant_Info) + break; + + if (m_Object is TourneyParticipant part && index >= 0 && index < part.Players.Count) + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TourneyBracketGumpType.Player_Info, + null, 0, part.Players[index])); + + break; + } + case 5: + { + if (m_Type != TourneyBracketGumpType.Round_Info) + break; + + if (!(m_Object is PyramidLevel level)) + break; + + if (index == 0) + { + if (level.FreeAdvance != null) + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, + TourneyBracketGumpType.Participant_Info, null, 0, level.FreeAdvance)); + else + m_From.SendGump( + new TournamentBracketGump(m_From, m_Tournament, m_Type, m_List, m_Page, m_Object)); + } + else if (index >= 1 && index <= level.Matches.Count) + { + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TourneyBracketGumpType.Match_Info, + null, 0, level.Matches[index - 1])); + } + + break; + } + case 6: + { + if (m_Type != TourneyBracketGumpType.Match_Info) + break; + + if (m_Object is TourneyMatch match && index >= 0 && index < match.Participants.Count) + m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, + TourneyBracketGumpType.Participant_Info, null, 0, match.Participants[index])); + + break; + } + } + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/Ladder.cs b/Scripts/Engines/ConPVP/Ladder.cs index d298fe710..cc8a4406d 100644 --- a/Scripts/Engines/ConPVP/Ladder.cs +++ b/Scripts/Engines/ConPVP/Ladder.cs @@ -1,40 +1,34 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Engines.ConPVP { public class LadderController : Item { - private Ladder m_Ladder; - [Constructible] public LadderController() : base(0x1B7A) { Visible = false; Movable = false; - m_Ladder = new Ladder(); + Ladder = new Ladder(); if (Ladder.Instance == null) - Ladder.Instance = m_Ladder; + Ladder.Instance = Ladder; } public LadderController(Serial serial) : base(serial) { } - //[CommandProperty( AccessLevel.GameMaster )] - public Ladder Ladder - { - get => m_Ladder; - set { } - } + [CommandProperty( AccessLevel.Administrator )] + public Ladder Ladder{ get; private set; } public override string DefaultName => "ladder controller"; public override void Delete() { - if (Ladder.Instance == m_Ladder) + if (Ladder.Instance == Ladder) Ladder.Instance = null; base.Delete(); @@ -46,9 +40,9 @@ namespace Server.Engines.ConPVP writer.Write(1); - m_Ladder.Serialize(writer); + Ladder.Serialize(writer); - writer.Write(Ladder.Instance == m_Ladder); + writer.Write(Ladder.Instance == Ladder); } public override void Deserialize(GenericReader reader) @@ -62,10 +56,10 @@ namespace Server.Engines.ConPVP case 1: case 0: { - m_Ladder = new Ladder(reader); + Ladder = new Ladder(reader); if (version < 1 || reader.ReadBool()) - Ladder.Instance = m_Ladder; + Ladder.Instance = Ladder; break; } @@ -120,14 +114,13 @@ namespace Server.Engines.ConPVP /* +6 */ { 40, 160 } }; - private ArrayList m_Entries; + public List Entries{ get; } = new List(); - private Hashtable m_Table; + private Dictionary m_Table; public Ladder() { - m_Table = new Hashtable(); - m_Entries = new ArrayList(); + m_Table = new Dictionary(); } public Ladder(GenericReader reader) @@ -141,8 +134,8 @@ namespace Server.Engines.ConPVP { int count = reader.ReadEncodedInt(); - m_Table = new Hashtable(count); - m_Entries = new ArrayList(count); + m_Table = new Dictionary(count); + Entries = new List(count); for (int i = 0; i < count; ++i) { @@ -151,18 +144,18 @@ namespace Server.Engines.ConPVP if (entry.Mobile != null) { m_Table[entry.Mobile] = entry; - entry.Index = m_Entries.Count; - m_Entries.Add(entry); + entry.Index = Entries.Count; + Entries.Add(entry); } } if (version == 0) { - m_Entries.Sort(); + Entries.Sort(); - for (int i = 0; i < m_Entries.Count; ++i) + for (int i = 0; i < Entries.Count; ++i) { - LadderEntry entry = (LadderEntry)m_Entries[i]; + LadderEntry entry = Entries[i]; entry.Index = i; } @@ -247,20 +240,15 @@ namespace Server.Engines.ConPVP return xp * (weWon ? 1 : -1); } - public ArrayList ToArrayList() - { - return m_Entries; - } - private int Swap(int idx, int newIdx) { - object hold = m_Entries[idx]; + LadderEntry hold = Entries[idx]; - m_Entries[idx] = m_Entries[newIdx]; - m_Entries[newIdx] = hold; + Entries[idx] = Entries[newIdx]; + Entries[newIdx] = hold; - ((LadderEntry)m_Entries[idx]).Index = idx; - ((LadderEntry)m_Entries[newIdx]).Index = newIdx; + Entries[idx].Index = idx; + Entries[newIdx].Index = newIdx; return newIdx; } @@ -269,29 +257,25 @@ namespace Server.Engines.ConPVP { int index = entry.Index; - if (index >= 0 && index < m_Entries.Count) + if (index >= 0 && index < Entries.Count) { - // sanity - - int c; - - while (index - 1 >= 0 && (c = entry.CompareTo(m_Entries[index - 1])) < 0) + while (index - 1 >= 0 && (entry.CompareTo(Entries[index - 1])) < 0) index = Swap(index, index - 1); - while (index + 1 < m_Entries.Count && (c = entry.CompareTo(m_Entries[index + 1])) > 0) + while (index + 1 < Entries.Count && (entry.CompareTo(Entries[index + 1])) > 0) index = Swap(index, index + 1); } } public LadderEntry Find(Mobile mob) { - LadderEntry entry = (LadderEntry)m_Table[mob]; + LadderEntry entry = m_Table[mob]; if (entry == null) { m_Table[mob] = entry = new LadderEntry(mob, this); - entry.Index = m_Entries.Count; - m_Entries.Add(entry); + entry.Index = Entries.Count; + Entries.Add(entry); } return entry; @@ -299,17 +283,17 @@ namespace Server.Engines.ConPVP public LadderEntry FindNoCreate(Mobile mob) { - return m_Table[mob] as LadderEntry; + return m_Table[mob]; } public void Serialize(GenericWriter writer) { writer.WriteEncodedInt(1); // version; - writer.WriteEncodedInt(m_Entries.Count); + writer.WriteEncodedInt(Entries.Count); - for (int i = 0; i < m_Entries.Count; ++i) - ((LadderEntry)m_Entries[i]).Serialize(writer); + for (int i = 0; i < Entries.Count; ++i) + Entries[i].Serialize(writer); } } diff --git a/Scripts/Engines/ConPVP/Participant.cs b/Scripts/Engines/ConPVP/Participant.cs index 0f379aae8..e228c1466 100644 --- a/Scripts/Engines/ConPVP/Participant.cs +++ b/Scripts/Engines/ConPVP/Participant.cs @@ -19,7 +19,7 @@ namespace Server.Engines.ConPVP public DuelContext Context{ get; } - public TournyParticipant TournyPart{ get; set; } + public TourneyParticipant TourneyPart{ get; set; } public int FilledSlots { diff --git a/Scripts/Engines/ConPVP/Preferences.cs b/Scripts/Engines/ConPVP/Preferences.cs index 31bdc45ee..f919854dc 100644 --- a/Scripts/Engines/ConPVP/Preferences.cs +++ b/Scripts/Engines/ConPVP/Preferences.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using Server.Gumps; using Server.Network; @@ -7,18 +6,16 @@ namespace Server.Engines.ConPVP { public class PreferencesController : Item { - private Preferences m_Preferences; - [Constructible] public PreferencesController() : base(0x1B7A) { Visible = false; Movable = false; - m_Preferences = new Preferences(); + Preferences = new Preferences(); if (Preferences.Instance == null) - Preferences.Instance = m_Preferences; + Preferences.Instance = Preferences; else Delete(); } @@ -27,18 +24,14 @@ namespace Server.Engines.ConPVP { } - //[CommandProperty( AccessLevel.GameMaster )] - public Preferences Preferences - { - get => m_Preferences; - set { } - } + [CommandProperty( AccessLevel.Administrator )] + public Preferences Preferences{ get; private set; } public override string DefaultName => "preferences controller"; public override void Delete() { - if (Preferences.Instance != m_Preferences) + if (Preferences.Instance != Preferences) base.Delete(); } @@ -48,7 +41,7 @@ namespace Server.Engines.ConPVP writer.Write(0); - m_Preferences.Serialize(writer); + Preferences.Serialize(writer); } public override void Deserialize(GenericReader reader) @@ -61,8 +54,8 @@ namespace Server.Engines.ConPVP { case 0: { - m_Preferences = new Preferences(reader); - Preferences.Instance = m_Preferences; + Preferences = new Preferences(reader); + Preferences.Instance = Preferences; break; } } @@ -71,12 +64,12 @@ namespace Server.Engines.ConPVP public class Preferences { - private Hashtable m_Table; + private Dictionary m_Table; public Preferences() { - m_Table = new Hashtable(); - Entries = new ArrayList(); + m_Table = new Dictionary(); + Entries = new List(); } public Preferences(GenericReader reader) @@ -89,12 +82,12 @@ namespace Server.Engines.ConPVP { int count = reader.ReadEncodedInt(); - m_Table = new Hashtable(count); - Entries = new ArrayList(count); + m_Table = new Dictionary(count); + Entries = new List(count); for (int i = 0; i < count; ++i) { - PreferencesEntry entry = new PreferencesEntry(reader, this, version); + PreferencesEntry entry = new PreferencesEntry(reader, version); if (entry.Mobile != null) { @@ -108,17 +101,17 @@ namespace Server.Engines.ConPVP } } - public ArrayList Entries{ get; } + public List Entries{ get; } public static Preferences Instance{ get; set; } public PreferencesEntry Find(Mobile mob) { - PreferencesEntry entry = (PreferencesEntry)m_Table[mob]; + PreferencesEntry entry = m_Table[mob]; if (entry == null) { - m_Table[mob] = entry = new PreferencesEntry(mob, this); + m_Table[mob] = entry = new PreferencesEntry(mob); Entries.Add(entry); } @@ -132,25 +125,20 @@ namespace Server.Engines.ConPVP writer.WriteEncodedInt(Entries.Count); for (int i = 0; i < Entries.Count; ++i) - ((PreferencesEntry)Entries[i]).Serialize(writer); + Entries[i].Serialize(writer); } } public class PreferencesEntry { - private Preferences m_Preferences; - - public PreferencesEntry(Mobile mob, Preferences prefs) + public PreferencesEntry(Mobile mob) { - m_Preferences = prefs; Mobile = mob; - Disliked = new ArrayList(); + Disliked = new List(); } - public PreferencesEntry(GenericReader reader, Preferences prefs, int version) + public PreferencesEntry(GenericReader reader, int version) { - m_Preferences = prefs; - switch (version) { case 0: @@ -159,7 +147,7 @@ namespace Server.Engines.ConPVP int count = reader.ReadEncodedInt(); - Disliked = new ArrayList(count); + Disliked = new List(count); for (int i = 0; i < count; ++i) Disliked.Add(reader.ReadString()); @@ -171,7 +159,7 @@ namespace Server.Engines.ConPVP public Mobile Mobile{ get; } - public ArrayList Disliked{ get; } + public List Disliked{ get; } public void Serialize(GenericWriter writer) { @@ -180,7 +168,7 @@ namespace Server.Engines.ConPVP writer.WriteEncodedInt(Disliked.Count); for (int i = 0; i < Disliked.Count; ++i) - writer.Write((string)Disliked[i]); + writer.Write(Disliked[i]); } } @@ -188,11 +176,9 @@ namespace Server.Engines.ConPVP { private int m_ColumnX = 12; private PreferencesEntry m_Entry; - private Mobile m_From; public PreferencesGump(Mobile from, Preferences prefs) : base(50, 50) { - m_From = from; m_Entry = prefs.Find(from); if (m_Entry == null) @@ -221,10 +207,7 @@ namespace Server.Engines.ConPVP { Arena ar = arenas[i]; - string name = ar.Name; - - if (name == null) - name = "(no name)"; + string name = ar.Name ?? "(no name)"; int x = 12; int y = 32 + i * 31; @@ -235,7 +218,6 @@ namespace Server.Engines.ConPVP x += 35; AddBorderedText(x + 5, y + 5, 115 - 5, name, color, 0); - x += 115; } } @@ -272,12 +254,6 @@ namespace Server.Engines.ConPVP private void AddBorderedText(int x, int y, int width, string text, int color, int borderColor) { - /*AddColoredText( x - 1, y, width, text, borderColor ); - AddColoredText( x + 1, y, width, text, borderColor ); - AddColoredText( x, y - 1, width, text, borderColor ); - AddColoredText( x, y + 1, width, text, borderColor );*/ - /*AddColoredText( x - 1, y - 1, width, text, borderColor ); - AddColoredText( x + 1, y + 1, width, text, borderColor );*/ AddColoredText(x, y, width, text, color); } diff --git a/Scripts/Engines/ConPVP/Ruleset.cs b/Scripts/Engines/ConPVP/Ruleset.cs index ba25e7a5b..abf20c95f 100644 --- a/Scripts/Engines/ConPVP/Ruleset.cs +++ b/Scripts/Engines/ConPVP/Ruleset.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; namespace Server.Engines.ConPVP { @@ -18,7 +19,7 @@ namespace Server.Engines.ConPVP public Ruleset Base{ get; private set; } - public ArrayList Flavors{ get; } = new ArrayList(); + public List Flavors{ get; } = new List(); public bool Changed{ get; set; } @@ -36,7 +37,7 @@ namespace Server.Engines.ConPVP { for (int i = 0; i < Flavors.Count; ++i) { - Ruleset flavor = (Ruleset)Flavors[i]; + Ruleset flavor = Flavors[i]; Options.Or(flavor.Options); } diff --git a/Scripts/Engines/ConPVP/RulesetLayout.cs b/Scripts/Engines/ConPVP/RulesetLayout.cs index 59248f47c..12ab2438a 100644 --- a/Scripts/Engines/ConPVP/RulesetLayout.cs +++ b/Scripts/Engines/ConPVP/RulesetLayout.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Engines.ConPVP { @@ -45,634 +45,619 @@ namespace Server.Engines.ConPVP { get { - if (m_Root == null) + if (m_Root != null) + return m_Root; + + List entries = new List { - ArrayList entries = new ArrayList(); - - entries.Add(new RulesetLayout("Spells", new[] - { - new RulesetLayout("1st Circle", "Spells", new[] + new RulesetLayout("Spells", + new[] { - "Reactive Armor", "Clumsy", - "Create Food", "Feeblemind", - "Heal", "Magic Arrow", - "Night Sight", "Weaken" - }), - new RulesetLayout("2nd Circle", "Spells", new[] - { - "Agility", "Cunning", - "Cure", "Harm", - "Magic Trap", "Untrap", - "Protection", "Strength" - }), - new RulesetLayout("3rd Circle", "Spells", new[] - { - "Bless", "Fireball", - "Magic Lock", "Poison", - "Telekinesis", "Teleport", - "Unlock Spell", "Wall of Stone" - }), - new RulesetLayout("4th Circle", "Spells", new[] - { - "Arch Cure", "Arch Protection", - "Curse", "Fire Field", - "Greater Heal", "Lightning", - "Mana Drain", "Recall" - }), - new RulesetLayout("5th Circle", "Spells", new[] - { - "Blade Spirits", "Dispel Field", - "Incognito", "Magic Reflection", - "Mind Blast", "Paralyze", - "Poison Field", "Summon Creature" - }), - new RulesetLayout("6th Circle", "Spells", new[] - { - "Dispel", "Energy Bolt", - "Explosion", "Invisibility", - "Mark", "Mass Curse", - "Paralyze Field", "Reveal" - }), - new RulesetLayout("7th Circle", "Spells", new[] - { - "Chain Lightning", "Energy Field", - "Flame Strike", "Gate Travel", - "Mana Vampire", "Mass Dispel", - "Meteor Swarm", "Polymorph" - }), - new RulesetLayout("8th Circle", "Spells", new[] - { - "Earthquake", "Energy Vortex", - "Resurrection", "Air Elemental", - "Summon Daemon", "Earth Elemental", - "Fire Elemental", "Water Elemental" + new RulesetLayout("1st Circle", "Spells", + new[] + { + "Reactive Armor", "Clumsy", "Create Food", "Feeblemind", "Heal", "Magic Arrow", "Night Sight", + "Weaken" + }), + new RulesetLayout("2nd Circle", "Spells", + new[] { "Agility", "Cunning", "Cure", "Harm", "Magic Trap", "Untrap", "Protection", "Strength" }), + new RulesetLayout("3rd Circle", "Spells", + new[] + { + "Bless", "Fireball", "Magic Lock", "Poison", "Telekinesis", "Teleport", "Unlock Spell", + "Wall of Stone" + }), + new RulesetLayout("4th Circle", "Spells", + new[] + { + "Arch Cure", "Arch Protection", "Curse", "Fire Field", "Greater Heal", "Lightning", "Mana Drain", + "Recall" + }), + new RulesetLayout("5th Circle", "Spells", + new[] + { + "Blade Spirits", "Dispel Field", "Incognito", "Magic Reflection", "Mind Blast", "Paralyze", + "Poison Field", "Summon Creature" + }), + new RulesetLayout("6th Circle", "Spells", + new[] + { + "Dispel", "Energy Bolt", "Explosion", "Invisibility", "Mark", "Mass Curse", "Paralyze Field", + "Reveal" + }), + new RulesetLayout("7th Circle", "Spells", + new[] + { + "Chain Lightning", "Energy Field", "Flame Strike", "Gate Travel", "Mana Vampire", "Mass Dispel", + "Meteor Swarm", "Polymorph" + }), + new RulesetLayout("8th Circle", "Spells", + new[] + { + "Earthquake", "Energy Vortex", "Resurrection", "Air Elemental", "Summon Daemon", "Earth Elemental", + "Fire Elemental", "Water Elemental" + }) }) + }; + + if (Core.AOS) + { + entries.Add(new RulesetLayout("Chivalry", new[] + { + "Cleanse by Fire", + "Close Wounds", + "Consecrate Weapon", + "Dispel Evil", + "Divine Fury", + "Enemy of One", + "Holy Light", + "Noble Sacrifice", + "Remove Curse", + "Sacred Journey" })); - if (Core.AOS) + entries.Add(new RulesetLayout("Necromancy", new[] { - entries.Add(new RulesetLayout("Chivalry", new[] + "Animate Dead", + "Blood Oath", + "Corpse Skin", + "Curse Weapon", + "Evil Omen", + "Horrific Beast", + "Lich Form", + "Mind Rot", + "Pain Spike", + "Poison Strike", + "Strangle", + "Summon Familiar", + "Vampiric Embrace", + "Vengeful Spirit", + "Wither", + "Wraith Form" + })); + + if (Core.SE) + { + entries.Add(new RulesetLayout("Bushido", new[] { - "Cleanse by Fire", - "Close Wounds", - "Consecrate Weapon", - "Dispel Evil", - "Divine Fury", - "Enemy of One", - "Holy Light", - "Noble Sacrifice", - "Remove Curse", - "Sacred Journey" + "Confidence", + "Counter Attack", + "Evasion", + "Honorable Execution", + "Lightning Strike", + "Momentum Strike" })); - entries.Add(new RulesetLayout("Necromancy", new[] + entries.Add(new RulesetLayout("Ninjitsu", new[] { - "Animate Dead", - "Blood Oath", - "Corpse Skin", - "Curse Weapon", - "Evil Omen", - "Horrific Beast", - "Lich Form", - "Mind Rot", - "Pain Spike", - "Poison Strike", - "Strangle", - "Summon Familiar", - "Vampiric Embrace", - "Vengeful Spirit", - "Wither", - "Wraith Form" + "Animal Form", + "Backstab", + "Death Strike", + "Focus Attack", + "Ki Attack", + "Mirror Image", + "Shadow Jump", + "Suprise Attack" })); - if (Core.SE) - { - entries.Add(new RulesetLayout("Bushido", new[] + if (Core.ML) + entries.Add(new RulesetLayout("Spellweaving", new[] { - "Confidence", - "Counter Attack", - "Evasion", - "Honorable Execution", - "Lightning Strike", - "Momentum Strike" - })); - - entries.Add(new RulesetLayout("Ninjitsu", new[] - { - "Animal Form", - "Backstab", - "Death Strike", - "Focus Attack", - "Ki Attack", - "Mirror Image", - "Shadow Jump", - "Suprise Attack" - })); - - if (Core.ML) - entries.Add(new RulesetLayout("Spellweaving", new[] - { - "Arcane Circle", - "Arcane Empowerment", - "Attune Weapon", - "Dryad Allure", - "Essence of Wind", - "Ethereal Voyage", - "Gift of Life", - "Gift of Renewal", - "Immolating Weapon", - "Nature's Fury", - "Reaper Form", - "Summon Fey", - "Summon Fiend", - "Thunderstorm", - "Wildfire", - "Word of Death" - })); - } - } - - if (Core.AOS) - { - if (Core.SE) - entries.Add(new RulesetLayout("Combat Abilities", new[] - { - "Stun", - "Disarm", - "Armor Ignore", - "Bleed Attack", - "Concussion Blow", - "Crushing Blow", - "Disarm", - "Dismount", - "Double Strike", - "Infectious Strike", - "Mortal Strike", - "Moving Shot", - "Paralyzing Blow", - "Shadow Strike", - "Whirlwind Attack", - "Riding Swipe", - "Frenzied Whirlwind", - "Block", - "Defense Mastery", - "Nerve Strike", - "Talon Strike", - "Feint", - "Dual Wield", - "Double Shot", - "Armor Pierce" - })); - else - entries.Add(new RulesetLayout("Combat Abilities", new[] - { - "Stun", - "Disarm", - "Armor Ignore", - "Bleed Attack", - "Concussion Blow", - "Crushing Blow", - "Disarm", - "Dismount", - "Double Strike", - "Infectious Strike", - "Mortal Strike", - "Moving Shot", - "Paralyzing Blow", - "Shadow Strike", - "Whirlwind Attack" + "Arcane Circle", + "Arcane Empowerment", + "Attune Weapon", + "Dryad Allure", + "Essence of Wind", + "Ethereal Voyage", + "Gift of Life", + "Gift of Renewal", + "Immolating Weapon", + "Nature's Fury", + "Reaper Form", + "Summon Fey", + "Summon Fiend", + "Thunderstorm", + "Wildfire", + "Word of Death" })); } - else - { + } + + if (Core.AOS) + { + if (Core.SE) entries.Add(new RulesetLayout("Combat Abilities", new[] { "Stun", "Disarm", + "Armor Ignore", + "Bleed Attack", "Concussion Blow", "Crushing Blow", - "Paralyzing Blow" + "Disarm", + "Dismount", + "Double Strike", + "Infectious Strike", + "Mortal Strike", + "Moving Shot", + "Paralyzing Blow", + "Shadow Strike", + "Whirlwind Attack", + "Riding Swipe", + "Frenzied Whirlwind", + "Block", + "Defense Mastery", + "Nerve Strike", + "Talon Strike", + "Feint", + "Dual Wield", + "Double Shot", + "Armor Pierce" })); - } - - entries.Add(new RulesetLayout("Skills", new[] + else + entries.Add(new RulesetLayout("Combat Abilities", new[] + { + "Stun", + "Disarm", + "Armor Ignore", + "Bleed Attack", + "Concussion Blow", + "Crushing Blow", + "Disarm", + "Dismount", + "Double Strike", + "Infectious Strike", + "Mortal Strike", + "Moving Shot", + "Paralyzing Blow", + "Shadow Strike", + "Whirlwind Attack" + })); + } + else + { + entries.Add(new RulesetLayout("Combat Abilities", new[] { - "Anatomy", - "Detect Hidden", - "Evaluating Intelligence", - "Hiding", - "Poisoning", - "Snooping", - "Stealing", - "Spirit Speak", - "Stealth" + "Stun", + "Disarm", + "Concussion Blow", + "Crushing Blow", + "Paralyzing Blow" + })); + } + + entries.Add(new RulesetLayout("Skills", new[] + { + "Anatomy", + "Detect Hidden", + "Evaluating Intelligence", + "Hiding", + "Poisoning", + "Snooping", + "Stealing", + "Spirit Speak", + "Stealth" + })); + + if (Core.AOS) + { + entries.Add(new RulesetLayout("Weapons", new[] + { + "Magical", + "Melee", + "Ranged", + "Poisoned", + "Wrestling" })); - if (Core.AOS) + entries.Add(new RulesetLayout("Armor", new[] { - entries.Add(new RulesetLayout("Weapons", new[] - { - "Magical", - "Melee", - "Ranged", - "Poisoned", - "Wrestling" - })); - - entries.Add(new RulesetLayout("Armor", new[] - { - "Magical", - "Shields" - })); - } - else - { - entries.Add(new RulesetLayout("Weapons", new[] - { - "Magical", - "Melee", - "Ranged", - "Poisoned", - "Wrestling", - "Runics" - })); - - entries.Add(new RulesetLayout("Armor", new[] - { - "Magical", - "Shields", - "Colored" - })); - } - - if (Core.SE) - entries.Add(new RulesetLayout("Items", new[] - { - new RulesetLayout("Potions", new[] - { - "Agility", - "Cure", - "Explosion", - "Heal", - "Nightsight", - "Poison", - "Refresh", - "Strength" - }) - }, - new[] - { - "Bandages", - "Wands", - "Trapped Containers", - "Bolas", - "Mounts", - "Orange Petals", - "Shurikens", - "Fukiya Darts", - "Fire Horns" - })); - else - entries.Add(new RulesetLayout("Items", new[] - { - new RulesetLayout("Potions", new[] - { - "Agility", - "Cure", - "Explosion", - "Heal", - "Nightsight", - "Poison", - "Refresh", - "Strength" - }) - }, - new[] - { - "Bandages", - "Wands", - "Trapped Containers", - "Bolas", - "Mounts", - "Orange Petals", - "Fire Horns" - })); - - m_Root = new RulesetLayout("Rules", (RulesetLayout[])entries.ToArray(typeof(RulesetLayout))); - m_Root.ComputeOffsets(); - - // Set up default rulesets - - if (!Core.AOS) - { - #region Mage 5x - - Ruleset m5x = new Ruleset(m_Root); - - m5x.Title = "Mage 5x"; - - m5x.SetOptionRange("Spells", true); - - m5x.SetOption("Spells", "Wall of Stone", false); - m5x.SetOption("Spells", "Fire Field", false); - m5x.SetOption("Spells", "Poison Field", false); - m5x.SetOption("Spells", "Energy Field", false); - m5x.SetOption("Spells", "Reactive Armor", false); - m5x.SetOption("Spells", "Protection", false); - m5x.SetOption("Spells", "Teleport", false); - m5x.SetOption("Spells", "Wall of Stone", false); - m5x.SetOption("Spells", "Arch Protection", false); - m5x.SetOption("Spells", "Recall", false); - m5x.SetOption("Spells", "Blade Spirits", false); - m5x.SetOption("Spells", "Incognito", false); - m5x.SetOption("Spells", "Magic Reflection", false); - m5x.SetOption("Spells", "Paralyze", false); - m5x.SetOption("Spells", "Summon Creature", false); - m5x.SetOption("Spells", "Invisibility", false); - m5x.SetOption("Spells", "Mark", false); - m5x.SetOption("Spells", "Paralyze Field", false); - m5x.SetOption("Spells", "Energy Field", false); - m5x.SetOption("Spells", "Gate Travel", false); - m5x.SetOption("Spells", "Polymorph", false); - m5x.SetOption("Spells", "Energy Vortex", false); - m5x.SetOption("Spells", "Air Elemental", false); - m5x.SetOption("Spells", "Summon Daemon", false); - m5x.SetOption("Spells", "Earth Elemental", false); - m5x.SetOption("Spells", "Fire Elemental", false); - m5x.SetOption("Spells", "Water Elemental", false); - m5x.SetOption("Spells", "Earthquake", false); - m5x.SetOption("Spells", "Meteor Swarm", false); - m5x.SetOption("Spells", "Chain Lightning", false); - m5x.SetOption("Spells", "Resurrection", false); - - m5x.SetOption("Weapons", "Wrestling", true); - - m5x.SetOption("Skills", "Anatomy", true); - m5x.SetOption("Skills", "Detect Hidden", true); - m5x.SetOption("Skills", "Evaluating Intelligence", true); - - m5x.SetOption("Items", "Trapped Containers", true); - - #endregion - - #region Mage 7x - - Ruleset m7x = new Ruleset(m_Root); - - m7x.Title = "Mage 7x"; - - m7x.SetOptionRange("Spells", true); - - m7x.SetOption("Spells", "Wall of Stone", false); - m7x.SetOption("Spells", "Fire Field", false); - m7x.SetOption("Spells", "Poison Field", false); - m7x.SetOption("Spells", "Energy Field", false); - m7x.SetOption("Spells", "Reactive Armor", false); - m7x.SetOption("Spells", "Protection", false); - m7x.SetOption("Spells", "Teleport", false); - m7x.SetOption("Spells", "Wall of Stone", false); - m7x.SetOption("Spells", "Arch Protection", false); - m7x.SetOption("Spells", "Recall", false); - m7x.SetOption("Spells", "Blade Spirits", false); - m7x.SetOption("Spells", "Incognito", false); - m7x.SetOption("Spells", "Magic Reflection", false); - m7x.SetOption("Spells", "Paralyze", false); - m7x.SetOption("Spells", "Summon Creature", false); - m7x.SetOption("Spells", "Invisibility", false); - m7x.SetOption("Spells", "Mark", false); - m7x.SetOption("Spells", "Paralyze Field", false); - m7x.SetOption("Spells", "Energy Field", false); - m7x.SetOption("Spells", "Gate Travel", false); - m7x.SetOption("Spells", "Polymorph", false); - m7x.SetOption("Spells", "Energy Vortex", false); - m7x.SetOption("Spells", "Air Elemental", false); - m7x.SetOption("Spells", "Summon Daemon", false); - m7x.SetOption("Spells", "Earth Elemental", false); - m7x.SetOption("Spells", "Fire Elemental", false); - m7x.SetOption("Spells", "Water Elemental", false); - m7x.SetOption("Spells", "Earthquake", false); - m7x.SetOption("Spells", "Meteor Swarm", false); - m7x.SetOption("Spells", "Chain Lightning", false); - m7x.SetOption("Spells", "Resurrection", false); - - m7x.SetOption("Combat Abilities", "Stun", true); - - m7x.SetOption("Skills", "Anatomy", true); - m7x.SetOption("Skills", "Detect Hidden", true); - m7x.SetOption("Skills", "Poisoning", true); - m7x.SetOption("Skills", "Evaluating Intelligence", true); - - m7x.SetOption("Weapons", "Wrestling", true); - - m7x.SetOption("Potions", "Refresh", true); - m7x.SetOption("Items", "Trapped Containers", true); - m7x.SetOption("Items", "Bandages", true); - - #endregion - - #region Standard 7x - - Ruleset s7x = new Ruleset(m_Root); - - s7x.Title = "Standard 7x"; - - s7x.SetOptionRange("Spells", true); - - s7x.SetOption("Spells", "Wall of Stone", false); - s7x.SetOption("Spells", "Fire Field", false); - s7x.SetOption("Spells", "Poison Field", false); - s7x.SetOption("Spells", "Energy Field", false); - s7x.SetOption("Spells", "Teleport", false); - s7x.SetOption("Spells", "Wall of Stone", false); - s7x.SetOption("Spells", "Arch Protection", false); - s7x.SetOption("Spells", "Recall", false); - s7x.SetOption("Spells", "Blade Spirits", false); - s7x.SetOption("Spells", "Incognito", false); - s7x.SetOption("Spells", "Magic Reflection", false); - s7x.SetOption("Spells", "Paralyze", false); - s7x.SetOption("Spells", "Summon Creature", false); - s7x.SetOption("Spells", "Invisibility", false); - s7x.SetOption("Spells", "Mark", false); - s7x.SetOption("Spells", "Paralyze Field", false); - s7x.SetOption("Spells", "Energy Field", false); - s7x.SetOption("Spells", "Gate Travel", false); - s7x.SetOption("Spells", "Polymorph", false); - s7x.SetOption("Spells", "Energy Vortex", false); - s7x.SetOption("Spells", "Air Elemental", false); - s7x.SetOption("Spells", "Summon Daemon", false); - s7x.SetOption("Spells", "Earth Elemental", false); - s7x.SetOption("Spells", "Fire Elemental", false); - s7x.SetOption("Spells", "Water Elemental", false); - s7x.SetOption("Spells", "Earthquake", false); - s7x.SetOption("Spells", "Meteor Swarm", false); - s7x.SetOption("Spells", "Chain Lightning", false); - s7x.SetOption("Spells", "Resurrection", false); - - s7x.SetOptionRange("Combat Abilities", true); - - s7x.SetOption("Skills", "Anatomy", true); - s7x.SetOption("Skills", "Detect Hidden", true); - s7x.SetOption("Skills", "Poisoning", true); - s7x.SetOption("Skills", "Evaluating Intelligence", true); - - s7x.SetOptionRange("Weapons", true); - s7x.SetOption("Weapons", "Runics", false); - s7x.SetOptionRange("Armor", true); - - s7x.SetOption("Potions", "Refresh", true); - s7x.SetOption("Items", "Bandages", true); - s7x.SetOption("Items", "Trapped Containers", true); - - #endregion - - m_Root.Defaults = new[] { m5x, m7x, s7x }; - } - else - { - #region Standard All Skills - - Ruleset all = new Ruleset(m_Root); - - all.Title = "Standard All Skills"; - - - all.SetOptionRange("Spells", true); - - all.SetOption("Spells", "Wall of Stone", false); - all.SetOption("Spells", "Fire Field", false); - all.SetOption("Spells", "Poison Field", false); - all.SetOption("Spells", "Energy Field", false); - all.SetOption("Spells", "Teleport", false); - all.SetOption("Spells", "Wall of Stone", false); - all.SetOption("Spells", "Arch Protection", false); - all.SetOption("Spells", "Recall", false); - all.SetOption("Spells", "Blade Spirits", false); - all.SetOption("Spells", "Incognito", false); - all.SetOption("Spells", "Magic Reflection", false); - all.SetOption("Spells", "Paralyze", false); - all.SetOption("Spells", "Summon Creature", false); - all.SetOption("Spells", "Invisibility", false); - all.SetOption("Spells", "Mark", false); - all.SetOption("Spells", "Paralyze Field", false); - all.SetOption("Spells", "Energy Field", false); - all.SetOption("Spells", "Gate Travel", false); - all.SetOption("Spells", "Polymorph", false); - all.SetOption("Spells", "Energy Vortex", false); - all.SetOption("Spells", "Air Elemental", false); - all.SetOption("Spells", "Summon Daemon", false); - all.SetOption("Spells", "Earth Elemental", false); - all.SetOption("Spells", "Fire Elemental", false); - all.SetOption("Spells", "Water Elemental", false); - all.SetOption("Spells", "Earthquake", false); - all.SetOption("Spells", "Meteor Swarm", false); - all.SetOption("Spells", "Chain Lightning", false); - all.SetOption("Spells", "Resurrection", false); - - all.SetOptionRange("Necromancy", true); - all.SetOption("Necromancy", "Summon Familiar", false); - all.SetOption("Necromancy", "Vengeful Spirit", false); - all.SetOption("Necromancy", "Animate Dead", false); - all.SetOption("Necromancy", "Wither", false); - all.SetOption("Necromancy", "Poison Strike", false); - - all.SetOptionRange("Chivalry", true); - all.SetOption("Chivalry", "Sacred Journey", false); - all.SetOption("Chivalry", "Enemy of One", false); - all.SetOption("Chivalry", "Noble Sacrifice", false); - - all.SetOptionRange("Combat Abilities", true); - all.SetOption("Combat Abilities", "Paralyzing Blow", false); - all.SetOption("Combat Abilities", "Shadow Strike", false); - - all.SetOption("Skills", "Anatomy", true); - all.SetOption("Skills", "Detect Hidden", true); - all.SetOption("Skills", "Poisoning", true); - all.SetOption("Skills", "Spirit Speak", true); - all.SetOption("Skills", "Evaluating Intelligence", true); - - all.SetOptionRange("Weapons", true); - all.SetOption("Weapons", "Poisoned", false); - - all.SetOptionRange("Armor", true); - - all.SetOptionRange("Ninjitsu", true); - all.SetOption("Ninjitsu", "Animal Form", false); - all.SetOption("Ninjitsu", "Mirror Image", false); - all.SetOption("Ninjitsu", "Backstab", false); - all.SetOption("Ninjitsu", "Suprise Attack", false); - all.SetOption("Ninjitsu", "Shadow Jump", false); - - all.SetOptionRange("Bushido", true); - - all.SetOptionRange("Spellweaving", true); - all.SetOption("Spellweaving", "Gift of Life", false); - all.SetOption("Spellweaving", "Summon Fey", false); - all.SetOption("Spellweaving", "Summon Fiend", false); - all.SetOption("Spellweaving", "Nature's Fury", false); - - all.SetOption("Potions", "Refresh", true); - all.SetOption("Items", "Bandages", true); - all.SetOption("Items", "Trapped Containers", true); - - m_Root.Defaults = new[] { all }; - - #endregion - } - - // Set up flavors - - Ruleset pots = new Ruleset(m_Root); - - pots.Title = "Potions"; - - pots.SetOptionRange("Potions", true); - pots.SetOption("Potions", "Explosion", false); - - Ruleset para = new Ruleset(m_Root); - - para.Title = "Paralyze"; - para.SetOption("Spells", "Paralyze", true); - para.SetOption("Spells", "Paralyze Field", true); - para.SetOption("Combat Abilities", "Paralyzing Blow", true); - - Ruleset fields = new Ruleset(m_Root); - - fields.Title = "Fields"; - fields.SetOption("Spells", "Wall of Stone", true); - fields.SetOption("Spells", "Fire Field", true); - fields.SetOption("Spells", "Poison Field", true); - fields.SetOption("Spells", "Energy Field", true); - fields.SetOption("Spells", "Wildfire", true); - - Ruleset area = new Ruleset(m_Root); - - area.Title = "Area Effect"; - area.SetOption("Spells", "Earthquake", true); - area.SetOption("Spells", "Meteor Swarm", true); - area.SetOption("Spells", "Chain Lightning", true); - area.SetOption("Necromancy", "Wither", true); - area.SetOption("Necromancy", "Poison Strike", true); - - Ruleset summons = new Ruleset(m_Root); - - summons.Title = "Summons"; - summons.SetOption("Spells", "Blade Spirits", true); - summons.SetOption("Spells", "Energy Vortex", true); - summons.SetOption("Spells", "Air Elemental", true); - summons.SetOption("Spells", "Summon Daemon", true); - summons.SetOption("Spells", "Earth Elemental", true); - summons.SetOption("Spells", "Fire Elemental", true); - summons.SetOption("Spells", "Water Elemental", true); - summons.SetOption("Necromancy", "Summon Familiar", true); - summons.SetOption("Necromancy", "Vengeful Spirit", true); - summons.SetOption("Necromancy", "Animate Dead", true); - summons.SetOption("Ninjitsu", "Mirror Image", true); - summons.SetOption("Spellweaving", "Summon Fey", true); - summons.SetOption("Spellweaving", "Summon Fiend", true); - summons.SetOption("Spellweaving", "Nature's Fury", true); - - m_Root.Flavors = new[] { pots, para, fields, area, summons }; + "Magical", + "Shields" + })); } + else + { + entries.Add(new RulesetLayout("Weapons", new[] + { + "Magical", + "Melee", + "Ranged", + "Poisoned", + "Wrestling", + "Runics" + })); + + entries.Add(new RulesetLayout("Armor", new[] + { + "Magical", + "Shields", + "Colored" + })); + } + + if (Core.SE) + entries.Add(new RulesetLayout("Items", new[] + { + new RulesetLayout("Potions", new[] + { + "Agility", + "Cure", + "Explosion", + "Heal", + "Nightsight", + "Poison", + "Refresh", + "Strength" + }) + }, + new[] + { + "Bandages", + "Wands", + "Trapped Containers", + "Bolas", + "Mounts", + "Orange Petals", + "Shurikens", + "Fukiya Darts", + "Fire Horns" + })); + else + entries.Add(new RulesetLayout("Items", new[] + { + new RulesetLayout("Potions", new[] + { + "Agility", + "Cure", + "Explosion", + "Heal", + "Nightsight", + "Poison", + "Refresh", + "Strength" + }) + }, + new[] + { + "Bandages", + "Wands", + "Trapped Containers", + "Bolas", + "Mounts", + "Orange Petals", + "Fire Horns" + })); + + m_Root = new RulesetLayout("Rules", entries.ToArray()); + m_Root.ComputeOffsets(); + + // Set up default rulesets + + if (!Core.AOS) + { + #region Mage 5x + + Ruleset m5x = new Ruleset(m_Root); + + m5x.Title = "Mage 5x"; + + m5x.SetOptionRange("Spells", true); + + m5x.SetOption("Spells", "Wall of Stone", false); + m5x.SetOption("Spells", "Fire Field", false); + m5x.SetOption("Spells", "Poison Field", false); + m5x.SetOption("Spells", "Energy Field", false); + m5x.SetOption("Spells", "Reactive Armor", false); + m5x.SetOption("Spells", "Protection", false); + m5x.SetOption("Spells", "Teleport", false); + m5x.SetOption("Spells", "Wall of Stone", false); + m5x.SetOption("Spells", "Arch Protection", false); + m5x.SetOption("Spells", "Recall", false); + m5x.SetOption("Spells", "Blade Spirits", false); + m5x.SetOption("Spells", "Incognito", false); + m5x.SetOption("Spells", "Magic Reflection", false); + m5x.SetOption("Spells", "Paralyze", false); + m5x.SetOption("Spells", "Summon Creature", false); + m5x.SetOption("Spells", "Invisibility", false); + m5x.SetOption("Spells", "Mark", false); + m5x.SetOption("Spells", "Paralyze Field", false); + m5x.SetOption("Spells", "Energy Field", false); + m5x.SetOption("Spells", "Gate Travel", false); + m5x.SetOption("Spells", "Polymorph", false); + m5x.SetOption("Spells", "Energy Vortex", false); + m5x.SetOption("Spells", "Air Elemental", false); + m5x.SetOption("Spells", "Summon Daemon", false); + m5x.SetOption("Spells", "Earth Elemental", false); + m5x.SetOption("Spells", "Fire Elemental", false); + m5x.SetOption("Spells", "Water Elemental", false); + m5x.SetOption("Spells", "Earthquake", false); + m5x.SetOption("Spells", "Meteor Swarm", false); + m5x.SetOption("Spells", "Chain Lightning", false); + m5x.SetOption("Spells", "Resurrection", false); + + m5x.SetOption("Weapons", "Wrestling", true); + + m5x.SetOption("Skills", "Anatomy", true); + m5x.SetOption("Skills", "Detect Hidden", true); + m5x.SetOption("Skills", "Evaluating Intelligence", true); + + m5x.SetOption("Items", "Trapped Containers", true); + + #endregion + + #region Mage 7x + + Ruleset m7x = new Ruleset(m_Root); + + m7x.Title = "Mage 7x"; + + m7x.SetOptionRange("Spells", true); + + m7x.SetOption("Spells", "Wall of Stone", false); + m7x.SetOption("Spells", "Fire Field", false); + m7x.SetOption("Spells", "Poison Field", false); + m7x.SetOption("Spells", "Energy Field", false); + m7x.SetOption("Spells", "Reactive Armor", false); + m7x.SetOption("Spells", "Protection", false); + m7x.SetOption("Spells", "Teleport", false); + m7x.SetOption("Spells", "Wall of Stone", false); + m7x.SetOption("Spells", "Arch Protection", false); + m7x.SetOption("Spells", "Recall", false); + m7x.SetOption("Spells", "Blade Spirits", false); + m7x.SetOption("Spells", "Incognito", false); + m7x.SetOption("Spells", "Magic Reflection", false); + m7x.SetOption("Spells", "Paralyze", false); + m7x.SetOption("Spells", "Summon Creature", false); + m7x.SetOption("Spells", "Invisibility", false); + m7x.SetOption("Spells", "Mark", false); + m7x.SetOption("Spells", "Paralyze Field", false); + m7x.SetOption("Spells", "Energy Field", false); + m7x.SetOption("Spells", "Gate Travel", false); + m7x.SetOption("Spells", "Polymorph", false); + m7x.SetOption("Spells", "Energy Vortex", false); + m7x.SetOption("Spells", "Air Elemental", false); + m7x.SetOption("Spells", "Summon Daemon", false); + m7x.SetOption("Spells", "Earth Elemental", false); + m7x.SetOption("Spells", "Fire Elemental", false); + m7x.SetOption("Spells", "Water Elemental", false); + m7x.SetOption("Spells", "Earthquake", false); + m7x.SetOption("Spells", "Meteor Swarm", false); + m7x.SetOption("Spells", "Chain Lightning", false); + m7x.SetOption("Spells", "Resurrection", false); + + m7x.SetOption("Combat Abilities", "Stun", true); + + m7x.SetOption("Skills", "Anatomy", true); + m7x.SetOption("Skills", "Detect Hidden", true); + m7x.SetOption("Skills", "Poisoning", true); + m7x.SetOption("Skills", "Evaluating Intelligence", true); + + m7x.SetOption("Weapons", "Wrestling", true); + + m7x.SetOption("Potions", "Refresh", true); + m7x.SetOption("Items", "Trapped Containers", true); + m7x.SetOption("Items", "Bandages", true); + + #endregion + + #region Standard 7x + + Ruleset s7x = new Ruleset(m_Root); + + s7x.Title = "Standard 7x"; + + s7x.SetOptionRange("Spells", true); + + s7x.SetOption("Spells", "Wall of Stone", false); + s7x.SetOption("Spells", "Fire Field", false); + s7x.SetOption("Spells", "Poison Field", false); + s7x.SetOption("Spells", "Energy Field", false); + s7x.SetOption("Spells", "Teleport", false); + s7x.SetOption("Spells", "Wall of Stone", false); + s7x.SetOption("Spells", "Arch Protection", false); + s7x.SetOption("Spells", "Recall", false); + s7x.SetOption("Spells", "Blade Spirits", false); + s7x.SetOption("Spells", "Incognito", false); + s7x.SetOption("Spells", "Magic Reflection", false); + s7x.SetOption("Spells", "Paralyze", false); + s7x.SetOption("Spells", "Summon Creature", false); + s7x.SetOption("Spells", "Invisibility", false); + s7x.SetOption("Spells", "Mark", false); + s7x.SetOption("Spells", "Paralyze Field", false); + s7x.SetOption("Spells", "Energy Field", false); + s7x.SetOption("Spells", "Gate Travel", false); + s7x.SetOption("Spells", "Polymorph", false); + s7x.SetOption("Spells", "Energy Vortex", false); + s7x.SetOption("Spells", "Air Elemental", false); + s7x.SetOption("Spells", "Summon Daemon", false); + s7x.SetOption("Spells", "Earth Elemental", false); + s7x.SetOption("Spells", "Fire Elemental", false); + s7x.SetOption("Spells", "Water Elemental", false); + s7x.SetOption("Spells", "Earthquake", false); + s7x.SetOption("Spells", "Meteor Swarm", false); + s7x.SetOption("Spells", "Chain Lightning", false); + s7x.SetOption("Spells", "Resurrection", false); + + s7x.SetOptionRange("Combat Abilities", true); + + s7x.SetOption("Skills", "Anatomy", true); + s7x.SetOption("Skills", "Detect Hidden", true); + s7x.SetOption("Skills", "Poisoning", true); + s7x.SetOption("Skills", "Evaluating Intelligence", true); + + s7x.SetOptionRange("Weapons", true); + s7x.SetOption("Weapons", "Runics", false); + s7x.SetOptionRange("Armor", true); + + s7x.SetOption("Potions", "Refresh", true); + s7x.SetOption("Items", "Bandages", true); + s7x.SetOption("Items", "Trapped Containers", true); + + #endregion + + m_Root.Defaults = new[] { m5x, m7x, s7x }; + } + else + { + #region Standard All Skills + + Ruleset all = new Ruleset(m_Root); + + all.Title = "Standard All Skills"; + + + all.SetOptionRange("Spells", true); + + all.SetOption("Spells", "Wall of Stone", false); + all.SetOption("Spells", "Fire Field", false); + all.SetOption("Spells", "Poison Field", false); + all.SetOption("Spells", "Energy Field", false); + all.SetOption("Spells", "Teleport", false); + all.SetOption("Spells", "Wall of Stone", false); + all.SetOption("Spells", "Arch Protection", false); + all.SetOption("Spells", "Recall", false); + all.SetOption("Spells", "Blade Spirits", false); + all.SetOption("Spells", "Incognito", false); + all.SetOption("Spells", "Magic Reflection", false); + all.SetOption("Spells", "Paralyze", false); + all.SetOption("Spells", "Summon Creature", false); + all.SetOption("Spells", "Invisibility", false); + all.SetOption("Spells", "Mark", false); + all.SetOption("Spells", "Paralyze Field", false); + all.SetOption("Spells", "Energy Field", false); + all.SetOption("Spells", "Gate Travel", false); + all.SetOption("Spells", "Polymorph", false); + all.SetOption("Spells", "Energy Vortex", false); + all.SetOption("Spells", "Air Elemental", false); + all.SetOption("Spells", "Summon Daemon", false); + all.SetOption("Spells", "Earth Elemental", false); + all.SetOption("Spells", "Fire Elemental", false); + all.SetOption("Spells", "Water Elemental", false); + all.SetOption("Spells", "Earthquake", false); + all.SetOption("Spells", "Meteor Swarm", false); + all.SetOption("Spells", "Chain Lightning", false); + all.SetOption("Spells", "Resurrection", false); + + all.SetOptionRange("Necromancy", true); + all.SetOption("Necromancy", "Summon Familiar", false); + all.SetOption("Necromancy", "Vengeful Spirit", false); + all.SetOption("Necromancy", "Animate Dead", false); + all.SetOption("Necromancy", "Wither", false); + all.SetOption("Necromancy", "Poison Strike", false); + + all.SetOptionRange("Chivalry", true); + all.SetOption("Chivalry", "Sacred Journey", false); + all.SetOption("Chivalry", "Enemy of One", false); + all.SetOption("Chivalry", "Noble Sacrifice", false); + + all.SetOptionRange("Combat Abilities", true); + all.SetOption("Combat Abilities", "Paralyzing Blow", false); + all.SetOption("Combat Abilities", "Shadow Strike", false); + + all.SetOption("Skills", "Anatomy", true); + all.SetOption("Skills", "Detect Hidden", true); + all.SetOption("Skills", "Poisoning", true); + all.SetOption("Skills", "Spirit Speak", true); + all.SetOption("Skills", "Evaluating Intelligence", true); + + all.SetOptionRange("Weapons", true); + all.SetOption("Weapons", "Poisoned", false); + + all.SetOptionRange("Armor", true); + + all.SetOptionRange("Ninjitsu", true); + all.SetOption("Ninjitsu", "Animal Form", false); + all.SetOption("Ninjitsu", "Mirror Image", false); + all.SetOption("Ninjitsu", "Backstab", false); + all.SetOption("Ninjitsu", "Suprise Attack", false); + all.SetOption("Ninjitsu", "Shadow Jump", false); + + all.SetOptionRange("Bushido", true); + + all.SetOptionRange("Spellweaving", true); + all.SetOption("Spellweaving", "Gift of Life", false); + all.SetOption("Spellweaving", "Summon Fey", false); + all.SetOption("Spellweaving", "Summon Fiend", false); + all.SetOption("Spellweaving", "Nature's Fury", false); + + all.SetOption("Potions", "Refresh", true); + all.SetOption("Items", "Bandages", true); + all.SetOption("Items", "Trapped Containers", true); + + m_Root.Defaults = new[] { all }; + + #endregion + } + + // Set up flavors + + Ruleset pots = new Ruleset(m_Root) { Title = "Potions" }; + + + pots.SetOptionRange("Potions", true); + pots.SetOption("Potions", "Explosion", false); + + Ruleset para = new Ruleset(m_Root) { Title = "Paralyze" }; + + para.SetOption("Spells", "Paralyze", true); + para.SetOption("Spells", "Paralyze Field", true); + para.SetOption("Combat Abilities", "Paralyzing Blow", true); + + Ruleset fields = new Ruleset(m_Root) { Title = "Fields" }; + + fields.SetOption("Spells", "Wall of Stone", true); + fields.SetOption("Spells", "Fire Field", true); + fields.SetOption("Spells", "Poison Field", true); + fields.SetOption("Spells", "Energy Field", true); + fields.SetOption("Spells", "Wildfire", true); + + Ruleset area = new Ruleset(m_Root) { Title = "Area Effect" }; + + area.SetOption("Spells", "Earthquake", true); + area.SetOption("Spells", "Meteor Swarm", true); + area.SetOption("Spells", "Chain Lightning", true); + area.SetOption("Necromancy", "Wither", true); + area.SetOption("Necromancy", "Poison Strike", true); + + Ruleset summons = new Ruleset(m_Root) { Title = "Summons" }; + + summons.SetOption("Spells", "Blade Spirits", true); + summons.SetOption("Spells", "Energy Vortex", true); + summons.SetOption("Spells", "Air Elemental", true); + summons.SetOption("Spells", "Summon Daemon", true); + summons.SetOption("Spells", "Earth Elemental", true); + summons.SetOption("Spells", "Fire Elemental", true); + summons.SetOption("Spells", "Water Elemental", true); + summons.SetOption("Necromancy", "Summon Familiar", true); + summons.SetOption("Necromancy", "Vengeful Spirit", true); + summons.SetOption("Necromancy", "Animate Dead", true); + summons.SetOption("Ninjitsu", "Mirror Image", true); + summons.SetOption("Spellweaving", "Summon Fey", true); + summons.SetOption("Spellweaving", "Summon Fiend", true); + summons.SetOption("Spellweaving", "Nature's Fury", true); + + m_Root.Flavors = new[] { pots, para, fields, area, summons }; return m_Root; } diff --git a/Scripts/Engines/ConPVP/StakesContainer.cs b/Scripts/Engines/ConPVP/StakesContainer.cs deleted file mode 100644 index bc41e03ee..000000000 --- a/Scripts/Engines/ConPVP/StakesContainer.cs +++ /dev/null @@ -1,121 +0,0 @@ -namespace Server.Engines.ConPVP -{ -#if false - [Flippable( 0x9A8, 0xE80 )] - public class StakesContainer : LockableContainer - { - private Mobile m_Initiator; - private Participant m_Participant; - private Hashtable m_Owners; - - public override bool CheckItemUse( Mobile from, Item item ) - { - Mobile owner = (Mobile)m_Owners[item]; - - if ( owner != null && owner != from ) - return false; - - return base.CheckItemUse( from, item ); - } - - public override bool CheckTarget( Mobile from, Server.Targeting.Target targ, object targeted ) - { - Mobile owner = (Mobile)m_Owners[targeted]; - - if ( owner != null && owner != from ) - return false; - - return base.CheckTarget( from, targ, targeted ); - } - - public override bool CheckLift(Mobile from, Item item) - { - Mobile owner = (Mobile)m_Owners[item]; - - if ( owner != null && owner != from ) - return false; - - return base.CheckLift( from, item ); - } - - public void ReturnItems() - { - ArrayList items = new ArrayList( this.Items ); - - for ( int i = 0; i < items.Count; ++i ) - { - Item item = (Item)items[i]; - Mobile owner = (Mobile)m_Owners[item]; - - if ( owner == null || owner.Deleted ) - owner = m_Initiator; - - if ( owner == null || owner.Deleted ) - return; - - if ( item.LootType != LootType.Blessed || !owner.PlaceInBackpack( item ) ) - owner.BankBox.DropItem( item ); - } - } - - public override bool TryDropItem( Mobile from, Item dropped, bool sendFullMessage ) - { - if ( m_Participant == null || !m_Participant.Contains( from ) ) - { - if ( sendFullMessage ) - from.SendMessage( "You are not allowed to place items here." ); - - return false; - } - - if ( dropped is Container || dropped.Stackable ) - { - if ( sendFullMessage ) - from.SendMessage( "That item cannot be used as stakes." ); - - return false; - } - - if ( !base.TryDropItem( from, dropped, sendFullMessage ) ) - return false; - - if ( from != null ) - m_Owners[dropped] = from; - - return true; - } - - public override void RemoveItem( Item item ) - { - base.RemoveItem( item ); - m_Owners.Remove( item ); - } - - public StakesContainer( DuelContext context, Participant participant ) : base( 0x9A8 ) - { - Movable = false; - m_Initiator = context.Initiator; - m_Participant = participant; - m_Owners = new Hashtable(); - } - - public StakesContainer( Serial serial ) : base( serial ) - { - } - - public override void Serialize( GenericWriter writer ) - { - base.Serialize( writer ); - - writer.Write( (int) 0 ); // version - } - - public override void Deserialize( GenericReader reader ) - { - base.Deserialize( reader ); - - int version = reader.ReadInt(); - } - } -#endif -} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/Tournament.cs b/Scripts/Engines/ConPVP/Tournament.cs index ac2687cd0..7c46ababb 100644 --- a/Scripts/Engines/ConPVP/Tournament.cs +++ b/Scripts/Engines/ConPVP/Tournament.cs @@ -1,16 +1,10 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Text; -using Server.ContextMenus; -using Server.Ethics; using Server.Factions; -using Server.Gumps; using Server.Items; -using Server.Mobiles; using Server.Network; using Server.Regions; -using Server.Targeting; namespace Server.Engines.ConPVP { @@ -37,1310 +31,7 @@ namespace Server.Engines.ConPVP FullAdvancement } - public class TournamentRegistrar : Banker - { - [Constructible] - public TournamentRegistrar() - { - Timer.DelayCall(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), Announce_Callback); - } - - public TournamentRegistrar(Serial serial) : base(serial) - { - } - - [CommandProperty(AccessLevel.GameMaster)] - public TournamentController Tournament{ get; set; } - - private void Announce_Callback() - { - Tournament tourny = null; - - if (Tournament != null) - tourny = Tournament.Tournament; - - if (tourny != null && tourny.Stage == TournamentStage.Signup) - PublicOverheadMessage(MessageType.Regular, 0x35, false, - "Come one, come all! Do you aspire to be a fighter of great renown? Join this tournament and show the world your abilities."); - } - - public override void OnMovement(Mobile m, Point3D oldLocation) - { - base.OnMovement(m, oldLocation); - - Tournament tourny = null; - - if (Tournament != null) - tourny = Tournament.Tournament; - - if (InRange(m, 4) && !InRange(oldLocation, 4) && tourny != null && tourny.Stage == TournamentStage.Signup && - m.CanBeginAction(this)) - { - Ladder ladder = Ladder.Instance; - - LadderEntry entry = ladder?.Find(m); - - if (entry != null && Ladder.GetLevel(entry.Experience) < tourny.LevelRequirement) - return; - - if (tourny.IsFactionRestricted && Faction.Find(m) == null) return; - - if (tourny.HasParticipant(m)) - return; - - PrivateOverheadMessage(MessageType.Regular, 0x35, false, - $"Hello m'{(m.Female ? "Lady" : "Lord")}. Dost thou wish to enter this tournament? You need only to write your name in this book.", - m.NetState); - m.BeginAction(this); - Timer.DelayCall(TimeSpan.FromSeconds(10.0), new TimerStateCallback(ReleaseLock_Callback), m); - } - } - - private void ReleaseLock_Callback(object obj) - { - ((Mobile)obj).EndAction(this); - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); - - writer.Write(Tournament); - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - - switch (version) - { - case 0: - { - Tournament = reader.ReadItem() as TournamentController; - break; - } - } - - Timer.DelayCall(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), Announce_Callback); - } - } - - public class TournamentSignupItem : Item - { - [Constructible] - public TournamentSignupItem() : base(4029) - { - Movable = false; - } - - public TournamentSignupItem(Serial serial) : base(serial) - { - } - - [CommandProperty(AccessLevel.GameMaster)] - public TournamentController Tournament{ get; set; } - - [CommandProperty(AccessLevel.GameMaster)] - public Mobile Registrar{ get; set; } - - public override string DefaultName => "tournament signup book"; - - public override void OnDoubleClick(Mobile from) - { - if (!from.InRange(GetWorldLocation(), 2)) - { - from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that - } - else - { - Tournament tourny = Tournament?.Tournament; - - if (tourny != null) - { - if (Registrar != null) - Registrar.Direction = Registrar.GetDirectionTo(this); - - switch (tourny.Stage) - { - case TournamentStage.Fighting: - { - if (Registrar != null) - { - if (tourny.HasParticipant(from)) - Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "Excuse me? You are already signed up.", from.NetState); - else - Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "The tournament has already begun. You are too late to signup now.", - from.NetState); - } - - break; - } - case TournamentStage.Inactive: - { - Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "The tournament is closed.", from.NetState); - - break; - } - case TournamentStage.Signup: - { - Ladder ladder = Ladder.Instance; - LadderEntry entry = ladder?.Find(from); - - if (entry != null && Ladder.GetLevel(entry.Experience) < tourny.LevelRequirement) - { - Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "You have not yet proven yourself a worthy dueler.", from.NetState); - - break; - } - - if (tourny.IsFactionRestricted && Faction.Find(from) == null) - { - Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "Only those who have declared their faction allegiance may participate.", - from.NetState); - - break; - } - - if (from.HasGump(typeof(AcceptTeamGump))) - { - Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "You must first respond to the offer I've given you.", from.NetState); - } - else if (from.HasGump(typeof(AcceptDuelGump))) - { - Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "You must first cancel your duel offer.", from.NetState); - } - else if (from is PlayerMobile mobile && mobile.DuelContext != null) - { - Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "You are already participating in a duel.", mobile.NetState); - } - else if (!tourny.HasParticipant(from)) - { - ArrayList players = new ArrayList(); - players.Add(from); - from.CloseGump(typeof(ConfirmSignupGump)); - from.SendGump(new ConfirmSignupGump(from, Registrar, tourny, players)); - } - else - { - Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "You have already entered this tournament.", from.NetState); - } - - break; - } - } - } - } - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); - - writer.Write(Tournament); - writer.Write(Registrar); - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - - switch (version) - { - case 0: - { - Tournament = reader.ReadItem() as TournamentController; - Registrar = reader.ReadMobile(); - break; - } - } - } - } - - public class ConfirmSignupGump : Gump - { - private const int BlackColor32 = 0x000008; - private const int LabelColor32 = 0xFFFFFF; - private Mobile m_From; - private ArrayList m_Players; - private Mobile m_Registrar; - private Tournament m_Tournament; - - public ConfirmSignupGump(Mobile from, Mobile registrar, Tournament tourny, ArrayList players) : base(50, 50) - { - m_From = from; - m_Registrar = registrar; - m_Tournament = tourny; - m_Players = players; - - m_From.CloseGump(typeof(AcceptTeamGump)); - m_From.CloseGump(typeof(AcceptDuelGump)); - m_From.CloseGump(typeof(DuelContextGump)); - m_From.CloseGump(typeof(ConfirmSignupGump)); - - #region Rules - - Ruleset ruleset = tourny.Ruleset; - Ruleset basedef = ruleset.Base; - - int height = 185 + 60 + 12; - - int changes = 0; - - BitArray defs; - - if (ruleset.Flavors.Count > 0) - { - defs = new BitArray(basedef.Options); - - for (int i = 0; i < ruleset.Flavors.Count; ++i) - defs.Or(((Ruleset)ruleset.Flavors[i]).Options); - - height += ruleset.Flavors.Count * 18; - } - else - { - defs = basedef.Options; - } - - BitArray opts = ruleset.Options; - - for (int i = 0; i < opts.Length; ++i) - if (defs[i] != opts[i]) - ++changes; - - height += changes * 22; - - height += 10 + 22 + 25 + 25; - - if (tourny.PlayersPerParticipant > 1) - height += 36 + tourny.PlayersPerParticipant * 20; - - #endregion - - Closable = false; - - AddPage(0); - - //AddBackground( 0, 0, 400, 220, 9150 ); - AddBackground(1, 1, 398, height, 3600); - //AddBackground( 16, 15, 369, 189, 9100 ); - - AddImageTiled(16, 15, 369, height - 29, 3604); - AddAlphaRegion(16, 15, 369, height - 29); - - AddImage(215, -43, 0xEE40); - //AddImage( 330, 141, 0x8BA ); - - StringBuilder sb = new StringBuilder(); - - if (tourny.TournyType == TournyType.FreeForAll) - { - sb.Append("FFA"); - } - else if (tourny.TournyType == TournyType.RandomTeam) - { - sb.Append(tourny.ParticipantsPerMatch); - sb.Append("-Team"); - } - else if (tourny.TournyType == TournyType.Faction) - { - sb.Append(tourny.ParticipantsPerMatch); - sb.Append("-Team Faction"); - } - else if (tourny.TournyType == TournyType.RedVsBlue) - { - sb.Append("Red v Blue"); - } - else - { - for (int i = 0; i < tourny.ParticipantsPerMatch; ++i) - { - if (sb.Length > 0) - sb.Append('v'); - - sb.Append(tourny.PlayersPerParticipant); - } - } - - if (tourny.EventController != null) - sb.Append(' ').Append(tourny.EventController.Title); - - sb.Append(" Tournament Signup"); - - AddBorderedText(22, 22, 294, 20, Center(sb.ToString()), LabelColor32, BlackColor32); - AddBorderedText(22, 50, 294, 40, "You have requested to join the tournament. Do you accept the rules?", 0xB0C868, - BlackColor32); - - AddImageTiled(32, 88, 264, 1, 9107); - AddImageTiled(42, 90, 264, 1, 9157); - - #region Rules - - int y = 100; - - string groupText = null; - - switch (tourny.GroupType) - { - case GroupingType.HighVsLow: - groupText = "High vs Low"; - break; - case GroupingType.Nearest: - groupText = "Closest opponent"; - break; - case GroupingType.Random: - groupText = "Random"; - break; - } - - AddBorderedText(35, y, 190, 20, $"Grouping: {groupText}", LabelColor32, BlackColor32); - y += 20; - - string tieText = null; - - switch (tourny.TieType) - { - case TieType.Random: - tieText = "Random"; - break; - case TieType.Highest: - tieText = "Highest advances"; - break; - case TieType.Lowest: - tieText = "Lowest advances"; - break; - case TieType.FullAdvancement: - tieText = tourny.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances"; - break; - case TieType.FullElimination: - tieText = tourny.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated"; - break; - } - - AddBorderedText(35, y, 190, 20, $"Tiebreaker: {tieText}", LabelColor32, BlackColor32); - y += 20; - - string sdText = "Off"; - - if (tourny.SuddenDeath > TimeSpan.Zero) - { - sdText = $"{(int)tourny.SuddenDeath.TotalMinutes}:{tourny.SuddenDeath.Seconds:D2}"; - - if (tourny.SuddenDeathRounds > 0) - sdText = $"{sdText} (first {tourny.SuddenDeathRounds} rounds)"; - else - sdText = $"{sdText} (all rounds)"; - } - - AddBorderedText(35, y, 240, 20, $"Sudden Death: {sdText}", LabelColor32, BlackColor32); - y += 20; - - y += 6; - AddImageTiled(32, y - 1, 264, 1, 9107); - AddImageTiled(42, y + 1, 264, 1, 9157); - y += 6; - - AddBorderedText(35, y, 190, 20, $"Ruleset: {basedef.Title}", LabelColor32, BlackColor32); - y += 20; - - for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18) - AddBorderedText(35, y, 190, 20, $" + {((Ruleset)ruleset.Flavors[i]).Title}", LabelColor32, BlackColor32); - - y += 4; - - if (changes > 0) - { - AddBorderedText(35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32); - y += 20; - - for (int i = 0; i < opts.Length; ++i) - if (defs[i] != opts[i]) - { - string name = ruleset.Layout.FindByIndex(i); - - if (name != null) // sanity - { - AddImage(35, y, opts[i] ? 0xD3 : 0xD2); - AddBorderedText(60, y, 165, 22, name, LabelColor32, BlackColor32); - } - - y += 22; - } - } - else - { - AddBorderedText(35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32); - y += 20; - } - - #endregion - - #region Team - - if (tourny.PlayersPerParticipant > 1) - { - y += 8; - AddImageTiled(32, y - 1, 264, 1, 9107); - AddImageTiled(42, y + 1, 264, 1, 9157); - y += 8; - - AddBorderedText(35, y, 190, 20, "Your Team", LabelColor32, BlackColor32); - y += 20; - - for (int i = 0; i < players.Count; ++i, y += 20) - { - if (i == 0) - AddImage(35, y, 0xD2); - else - AddGoldenButton(35, y, 1 + i); - - AddBorderedText(60, y, 200, 20, ((Mobile)players[i]).Name, LabelColor32, BlackColor32); - } - - for (int i = players.Count; i < tourny.PlayersPerParticipant; ++i, y += 20) - { - if (i == 0) - AddImage(35, y, 0xD2); - else - AddGoldenButton(35, y, 1 + i); - - AddBorderedText(60, y, 200, 20, "(Empty)", LabelColor32, BlackColor32); - } - } - - #endregion - - y += 8; - AddImageTiled(32, y - 1, 264, 1, 9107); - AddImageTiled(42, y + 1, 264, 1, 9157); - y += 8; - - AddRadio(24, y, 9727, 9730, true, 1); - AddBorderedText(60, y + 5, 250, 20, "Yes, I wish to join the tournament.", LabelColor32, BlackColor32); - y += 35; - - AddRadio(24, y, 9727, 9730, false, 2); - AddBorderedText(60, y + 5, 250, 20, "No, I do not wish to join.", LabelColor32, BlackColor32); - y += 35; - - y -= 3; - AddButton(314, y, 247, 248, 1, GumpButtonType.Reply, 0); - } - - public string Center(string text) - { - return $"
{text}
"; - } - - public string Color(string text, int color) - { - return $"{text}"; - } - - private void AddBorderedText(int x, int y, int width, int height, string text, int color, int borderColor) - { - AddColoredText(x - 1, y - 1, width, height, text, borderColor); - AddColoredText(x - 1, y + 1, width, height, text, borderColor); - AddColoredText(x + 1, y - 1, width, height, text, borderColor); - AddColoredText(x + 1, y + 1, width, height, text, borderColor); - AddColoredText(x, y, width, height, text, color); - } - - private void AddColoredText(int x, int y, int width, int height, string text, int color) - { - if (color == 0) - AddHtml(x, y, width, height, text, false, false); - else - AddHtml(x, y, width, height, Color(text, color), false, false); - } - - public void AddGoldenButton(int x, int y, int bid) - { - AddButton(x, y, 0xD2, 0xD2, bid, GumpButtonType.Reply, 0); - AddButton(x + 3, y + 3, 0xD8, 0xD8, bid, GumpButtonType.Reply, 0); - } - - public override void OnResponse(NetState sender, RelayInfo info) - { - if (info.ButtonID == 1 && info.IsSwitched(1)) - { - Tournament tourny = m_Tournament; - Mobile from = m_From; - - switch (tourny.Stage) - { - case TournamentStage.Fighting: - { - if (m_Registrar != null) - { - if (m_Tournament.HasParticipant(from)) - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "Excuse me? You are already signed up.", from.NetState); - else - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "The tournament has already begun. You are too late to signup now.", - from.NetState); - } - - break; - } - case TournamentStage.Inactive: - { - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "The tournament is closed.", from.NetState); - - break; - } - case TournamentStage.Signup: - { - if (m_Players.Count != tourny.PlayersPerParticipant) - { - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "You have not yet chosen your team.", from.NetState); - - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - break; - } - - Ladder ladder = Ladder.Instance; - - for (int i = 0; i < m_Players.Count; ++i) - { - Mobile mob = (Mobile)m_Players[i]; - - LadderEntry entry = ladder?.Find(mob); - - if (entry != null && Ladder.GetLevel(entry.Experience) < tourny.LevelRequirement) - { - if (m_Registrar != null) - { - if (mob == from) - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "You have not yet proven yourself a worthy dueler.", from.NetState); - else - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, $"{mob.Name} has not yet proven themselves a worthy dueler.", - from.NetState); - } - - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - return; - } - - if (tourny.IsFactionRestricted && Faction.Find(mob) == null) - { - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "Only those who have declared their faction allegiance may participate.", - from.NetState); - - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - return; - } - - if (tourny.HasParticipant(mob)) - { - if (m_Registrar != null) - { - if (mob == from) - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, "You have already entered this tournament.", from.NetState); - else - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, $"{mob.Name} has already entered this tournament.", from.NetState); - } - - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - return; - } - - if (mob is PlayerMobile mobile && mobile.DuelContext != null) - { - if (mob == from) - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, - "You are already assigned to a duel. You must yield it before joining this tournament.", - from.NetState); - else - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, - $"{mobile.Name} is already assigned to a duel. They must yield it before joining this tournament.", - from.NetState); - - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - return; - } - } - - if (m_Registrar != null) - { - string fmt; - - if (tourny.PlayersPerParticipant == 1) - fmt = - "As you say m'{0}. I've written your name to the bracket. The tournament will begin {1}."; - else if (tourny.PlayersPerParticipant == 2) - fmt = - "As you wish m'{0}. The tournament will begin {1}, but first you must name your partner."; - else - fmt = "As you wish m'{0}. The tournament will begin {1}, but first you must name your team."; - - string timeUntil; - int minutesUntil = (int)Math.Round((tourny.SignupStart + tourny.SignupPeriod - DateTime.UtcNow) - .TotalMinutes); - - if (minutesUntil == 0) - timeUntil = "momentarily"; - else - timeUntil = $"in {minutesUntil} minute{(minutesUntil == 1 ? "" : "s")}"; - - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x35, false, string.Format(fmt, from.Female ? "Lady" : "Lord", timeUntil), from.NetState); - } - - TournyParticipant part = new TournyParticipant(from); - part.Players.Clear(); - part.Players.AddRange(m_Players); - - tourny.Participants.Add(part); - - break; - } - } - } - else if (info.ButtonID > 1) - { - int index = info.ButtonID - 1; - - if (index > 0 && index < m_Players.Count) - { - m_Players.RemoveAt(index); - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - } - else if (m_Players.Count < m_Tournament.PlayersPerParticipant) - { - m_From.BeginTarget(12, false, TargetFlags.None, AddPlayer_OnTarget); - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - } - } - } - - private void AddPlayer_OnTarget(Mobile from, object obj) - { - if (!(obj is Mobile mob) || mob == from) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "Excuse me?", from.NetState); - } - else if (!mob.Player) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - if (mob.Body.IsHuman) - mob.SayTo(from, 1005443); // Nay, I would rather stay here and watch a nail rust. - else - mob.SayTo(from, 1005444); // The creature ignores your offer. - } - else if (AcceptDuelGump.IsIgnored(mob, from) || mob.Blessed) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "They ignore your invitation.", from.NetState); - } - else - { - if (!(mob is PlayerMobile pm)) - return; - - if (pm.DuelContext != null) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "They are already assigned to another duel.", from.NetState); - } - else if (mob.HasGump(typeof(AcceptTeamGump))) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "They have already been offered a partnership.", from.NetState); - } - else if (mob.HasGump(typeof(ConfirmSignupGump))) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "They are already trying to join this tournament.", from.NetState); - } - else if (m_Players.Contains(mob)) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "You have already named them as a team member.", from.NetState); - } - else if (m_Tournament.HasParticipant(mob)) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "They have already entered this tournament.", from.NetState); - } - else if (m_Players.Count >= m_Tournament.PlayersPerParticipant) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "Your team is full.", from.NetState); - } - else - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - mob.SendGump(new AcceptTeamGump(from, mob, m_Tournament, m_Registrar, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x59, false, - $"As you command m'{(from.Female ? "Lady" : "Lord")}. I've given your offer to {mob.Name}.", - from.NetState); - } - } - } - } - - public class AcceptTeamGump : Gump - { - private const int BlackColor32 = 0x000008; - private const int LabelColor32 = 0xFFFFFF; - private bool m_Active; - - private Mobile m_From; - private ArrayList m_Players; - private Mobile m_Registrar; - private Mobile m_Requested; - private Tournament m_Tournament; - - public AcceptTeamGump(Mobile from, Mobile requested, Tournament tourny, Mobile registrar, ArrayList players) : - base(50, 50) - { - m_From = from; - m_Requested = requested; - m_Tournament = tourny; - m_Registrar = registrar; - m_Players = players; - - m_Active = true; - - #region Rules - - Ruleset ruleset = tourny.Ruleset; - Ruleset basedef = ruleset.Base; - - int height = 185 + 35 + 60 + 12; - - int changes = 0; - - BitArray defs; - - if (ruleset.Flavors.Count > 0) - { - defs = new BitArray(basedef.Options); - - for (int i = 0; i < ruleset.Flavors.Count; ++i) - defs.Or(((Ruleset)ruleset.Flavors[i]).Options); - - height += ruleset.Flavors.Count * 18; - } - else - { - defs = basedef.Options; - } - - BitArray opts = ruleset.Options; - - for (int i = 0; i < opts.Length; ++i) - if (defs[i] != opts[i]) - ++changes; - - height += changes * 22; - - height += 10 + 22 + 25 + 25; - - #endregion - - Closable = false; - - AddPage(0); - - AddBackground(1, 1, 398, height, 3600); - - AddImageTiled(16, 15, 369, height - 29, 3604); - AddAlphaRegion(16, 15, 369, height - 29); - - AddImage(215, -43, 0xEE40); - - StringBuilder sb = new StringBuilder(); - - if (tourny.TournyType == TournyType.FreeForAll) - { - sb.Append("FFA"); - } - else if (tourny.TournyType == TournyType.RandomTeam) - { - sb.Append(tourny.ParticipantsPerMatch); - sb.Append("-Team"); - } - else if (tourny.TournyType == TournyType.Faction) - { - sb.Append(tourny.ParticipantsPerMatch); - sb.Append("-Team Faction"); - } - else if (tourny.TournyType == TournyType.RedVsBlue) - { - sb.Append("Red v Blue"); - } - else - { - for (int i = 0; i < tourny.ParticipantsPerMatch; ++i) - { - if (sb.Length > 0) - sb.Append('v'); - - sb.Append(tourny.PlayersPerParticipant); - } - } - - if (tourny.EventController != null) - sb.Append(' ').Append(tourny.EventController.Title); - - sb.Append(" Tournament Invitation"); - - AddBorderedText(22, 22, 294, 20, Center(sb.ToString()), LabelColor32, BlackColor32); - - AddBorderedText(22, 50, 294, 40, - $"You have been asked to partner with {from.Name} in a tournament. Do you accept?", - 0xB0C868, BlackColor32); - - AddImageTiled(32, 88, 264, 1, 9107); - AddImageTiled(42, 90, 264, 1, 9157); - - #region Rules - - int y = 100; - - string groupText = null; - - switch (tourny.GroupType) - { - case GroupingType.HighVsLow: - groupText = "High vs Low"; - break; - case GroupingType.Nearest: - groupText = "Closest opponent"; - break; - case GroupingType.Random: - groupText = "Random"; - break; - } - - AddBorderedText(35, y, 190, 20, $"Grouping: {groupText}", LabelColor32, BlackColor32); - y += 20; - - string tieText = null; - - switch (tourny.TieType) - { - case TieType.Random: - tieText = "Random"; - break; - case TieType.Highest: - tieText = "Highest advances"; - break; - case TieType.Lowest: - tieText = "Lowest advances"; - break; - case TieType.FullAdvancement: - tieText = tourny.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances"; - break; - case TieType.FullElimination: - tieText = tourny.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated"; - break; - } - - AddBorderedText(35, y, 190, 20, $"Tiebreaker: {tieText}", LabelColor32, BlackColor32); - y += 20; - - string sdText = "Off"; - - if (tourny.SuddenDeath > TimeSpan.Zero) - { - sdText = $"{(int)tourny.SuddenDeath.TotalMinutes}:{tourny.SuddenDeath.Seconds:D2}"; - - if (tourny.SuddenDeathRounds > 0) - sdText = $"{sdText} (first {tourny.SuddenDeathRounds} rounds)"; - else - sdText = $"{sdText} (all rounds)"; - } - - AddBorderedText(35, y, 240, 20, $"Sudden Death: {sdText}", LabelColor32, BlackColor32); - y += 20; - - y += 6; - AddImageTiled(32, y - 1, 264, 1, 9107); - AddImageTiled(42, y + 1, 264, 1, 9157); - y += 6; - - AddBorderedText(35, y, 190, 20, $"Ruleset: {basedef.Title}", LabelColor32, BlackColor32); - y += 20; - - for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18) - AddBorderedText(35, y, 190, 20, $" + {((Ruleset)ruleset.Flavors[i]).Title}", LabelColor32, BlackColor32); - - y += 4; - - if (changes > 0) - { - AddBorderedText(35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32); - y += 20; - - for (int i = 0; i < opts.Length; ++i) - if (defs[i] != opts[i]) - { - string name = ruleset.Layout.FindByIndex(i); - - if (name != null) // sanity - { - AddImage(35, y, opts[i] ? 0xD3 : 0xD2); - AddBorderedText(60, y, 165, 22, name, LabelColor32, BlackColor32); - } - - y += 22; - } - } - else - { - AddBorderedText(35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32); - y += 20; - } - - #endregion - - y += 8; - AddImageTiled(32, y - 1, 264, 1, 9107); - AddImageTiled(42, y + 1, 264, 1, 9157); - y += 8; - - AddRadio(24, y, 9727, 9730, true, 1); - AddBorderedText(60, y + 5, 250, 20, "Yes, I will join them.", LabelColor32, BlackColor32); - y += 35; - - AddRadio(24, y, 9727, 9730, false, 2); - AddBorderedText(60, y + 5, 250, 20, "No, I do not wish to fight.", LabelColor32, BlackColor32); - y += 35; - - AddRadio(24, y, 9727, 9730, false, 3); - AddBorderedText(60, y + 5, 270, 20, "No, most certainly not. Do not ask again.", LabelColor32, BlackColor32); - y += 35; - - y -= 3; - AddButton(314, y, 247, 248, 1, GumpButtonType.Reply, 0); - - Timer.DelayCall(TimeSpan.FromSeconds(15.0), AutoReject); - } - - public string Center(string text) - { - return $"
{text}
"; - } - - public string Color(string text, int color) - { - return $"{text}"; - } - - private void AddBorderedText(int x, int y, int width, int height, string text, int color, int borderColor) - { - AddColoredText(x - 1, y - 1, width, height, text, borderColor); - AddColoredText(x - 1, y + 1, width, height, text, borderColor); - AddColoredText(x + 1, y - 1, width, height, text, borderColor); - AddColoredText(x + 1, y + 1, width, height, text, borderColor); - AddColoredText(x, y, width, height, text, color); - } - - private void AddColoredText(int x, int y, int width, int height, string text, int color) - { - if (color == 0) - AddHtml(x, y, width, height, text, false, false); - else - AddHtml(x, y, width, height, Color(text, color), false, false); - } - - public void AutoReject() - { - if (!m_Active) - return; - - m_Active = false; - - m_Requested.CloseGump(typeof(AcceptTeamGump)); - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - if (m_Registrar != null) - { - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, $"{m_Requested.Name} seems unresponsive.", m_From.NetState); - - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, $"You have declined the partnership with {m_From.Name}.", m_Requested.NetState); - } - } - - public override void OnResponse(NetState sender, RelayInfo info) - { - Mobile from = m_From; - Mobile mob = m_Requested; - - if (info.ButtonID != 1 || !m_Active) - return; - - m_Active = false; - - if (info.IsSwitched(1)) - { - if (!(mob is PlayerMobile pm)) - return; - - if (AcceptDuelGump.IsIgnored(mob, from) || mob.Blessed) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "They ignore your invitation.", from.NetState); - } - else if (pm.DuelContext != null) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "They are already assigned to another duel.", from.NetState); - } - else if (m_Players.Contains(mob)) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "You have already named them as a team member.", from.NetState); - } - else if (m_Tournament.HasParticipant(mob)) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "They have already entered this tournament.", from.NetState); - } - else if (m_Players.Count >= m_Tournament.PlayersPerParticipant) - { - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - m_Registrar?.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, "Your team is full.", from.NetState); - } - else - { - m_Players.Add(mob); - - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - if (m_Registrar != null) - { - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x59, false, $"{mob.Name} has accepted your offer of partnership.", from.NetState); - - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x59, false, $"You have accepted the partnership with {from.Name}.", mob.NetState); - } - } - } - else - { - if (info.IsSwitched(3)) - AcceptDuelGump.BeginIgnore(m_Requested, m_From); - - m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); - - if (m_Registrar != null) - { - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, $"{mob.Name} has declined your offer of partnership.", from.NetState); - - m_Registrar.PrivateOverheadMessage(MessageType.Regular, - 0x22, false, $"You have declined the partnership with {from.Name}.", mob.NetState); - } - } - } - } - - public class TournamentController : Item - { - private static ArrayList m_Instances = new ArrayList(); - private Tournament m_Tournament; - - [Constructible] - public TournamentController() : base(0x1B7A) - { - Visible = false; - Movable = false; - - m_Tournament = new Tournament(); - m_Instances.Add(this); - } - - public TournamentController(Serial serial) : base(serial) - { - } - - [CommandProperty(AccessLevel.GameMaster)] - public Tournament Tournament - { - get => m_Tournament; - set { } - } - - public static bool IsActive - { - get - { - for (int i = 0; i < m_Instances.Count; ++i) - { - TournamentController controller = (TournamentController)m_Instances[i]; - - if (controller != null && !controller.Deleted && controller.Tournament != null && - controller.Tournament.Stage != TournamentStage.Inactive) - return true; - } - - return false; - } - } - - public override string DefaultName => "tournament controller"; - - public override void GetContextMenuEntries(Mobile from, List list) - { - base.GetContextMenuEntries(from, list); - - if (from.AccessLevel >= AccessLevel.GameMaster && m_Tournament != null) - { - list.Add(new EditEntry(m_Tournament)); - - if (m_Tournament.CurrentStage == TournamentStage.Inactive) - list.Add(new StartEntry(m_Tournament)); - } - } - - public override void OnDoubleClick(Mobile from) - { - if (from.AccessLevel >= AccessLevel.GameMaster && m_Tournament != null) - { - from.CloseGump(typeof(PickRulesetGump)); - from.CloseGump(typeof(RulesetGump)); - from.SendGump(new PickRulesetGump(from, null, m_Tournament.Ruleset)); - } - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); - - m_Tournament.Serialize(writer); - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - - switch (version) - { - case 0: - { - m_Tournament = new Tournament(reader); - break; - } - } - - m_Instances.Add(this); - } - - public override void OnDelete() - { - base.OnDelete(); - - m_Instances.Remove(this); - } - - private class EditEntry : ContextMenuEntry - { - private Tournament m_Tournament; - - public EditEntry(Tournament tourny) : base(5101) - { - m_Tournament = tourny; - } - - public override void OnClick() - { - Owner.From.SendGump(new PropertiesGump(Owner.From, m_Tournament)); - } - } - - private class StartEntry : ContextMenuEntry - { - private Tournament m_Tournament; - - public StartEntry(Tournament tourny) : base(5113) - { - m_Tournament = tourny; - } - - public override void OnClick() - { - if (m_Tournament.Stage == TournamentStage.Inactive) - { - m_Tournament.SignupStart = DateTime.UtcNow; - m_Tournament.Stage = TournamentStage.Signup; - m_Tournament.Participants.Clear(); - m_Tournament.Pyramid.Levels.Clear(); - m_Tournament.Alert("Hear ye! Hear ye!", - "Tournament signup has opened. You can enter by signing up with the registrar."); - } - } - } - } - - public enum TournyType + public enum TourneyType { Standard, FreeForAll, @@ -1382,7 +73,7 @@ namespace Server.Engines.ConPVP } case 2: { - TournyType = (TournyType)reader.ReadEncodedInt(); + TourneyType = (TourneyType)reader.ReadEncodedInt(); goto case 1; } @@ -1403,12 +94,12 @@ namespace Server.Engines.ConPVP m_PlayersPerParticipant = reader.ReadEncodedInt(); SignupPeriod = reader.ReadTimeSpan(); CurrentStage = TournamentStage.Inactive; - Pyramid = new TournyPyramid(); + Pyramid = new TourneyPyramid(); Ruleset = new Ruleset(RulesetLayout.Root); Ruleset.ApplyDefault(Ruleset.Layout.Defaults[0]); - Participants = new ArrayList(); - Undefeated = new ArrayList(); - Arenas = new ArrayList(); + Participants = new List(); + Undefeated = new List(); + Arenas = new List(); break; } @@ -1421,18 +112,18 @@ namespace Server.Engines.ConPVP { m_ParticipantsPerMatch = 2; m_PlayersPerParticipant = 1; - Pyramid = new TournyPyramid(); + Pyramid = new TourneyPyramid(); Ruleset = new Ruleset(RulesetLayout.Root); Ruleset.ApplyDefault(Ruleset.Layout.Defaults[0]); - Participants = new ArrayList(); - Undefeated = new ArrayList(); - Arenas = new ArrayList(); + Participants = new List(); + Undefeated = new List(); + Arenas = new List(); SignupPeriod = TimeSpan.FromMinutes(10.0); Timer.DelayCall(SliceInterval, SliceInterval, Slice); } - public bool IsNotoRestricted => TournyType != TournyType.Standard; + public bool IsNotoRestricted => TourneyType != TourneyType.Standard; [CommandProperty(AccessLevel.GameMaster)] public EventController EventController{ get; set; } @@ -1441,7 +132,7 @@ namespace Server.Engines.ConPVP public int SuddenDeathRounds{ get; set; } [CommandProperty(AccessLevel.GameMaster)] - public TournyType TournyType{ get; set; } + public TourneyType TourneyType{ get; set; } [CommandProperty(AccessLevel.GameMaster)] public GroupingType GroupType{ get; set; } @@ -1499,23 +190,21 @@ namespace Server.Engines.ConPVP set => CurrentStage = value; } - public TournyPyramid Pyramid{ get; set; } + public TourneyPyramid Pyramid{ get; set; } - public ArrayList Arenas{ get; set; } + public List Arenas{ get; set; } - public ArrayList Participants{ get; set; } + public List Participants{ get; set; } - public ArrayList Undefeated{ get; set; } + public List Undefeated{ get; set; } - public bool IsFactionRestricted => FactionRestricted || TournyType == TournyType.Faction; + public bool IsFactionRestricted => FactionRestricted || TourneyType == TourneyType.Faction; public bool HasParticipant(Mobile mob) { for (int i = 0; i < Participants.Count; ++i) { - TournyParticipant part = (TournyParticipant)Participants[i]; - - if (part.Players.Contains(mob)) + if (Participants[i].Players.Contains(mob)) return true; } @@ -1532,7 +221,7 @@ namespace Server.Engines.ConPVP writer.WriteEncodedInt(SuddenDeathRounds); - writer.WriteEncodedInt((int)TournyType); + writer.WriteEncodedInt((int)TourneyType); writer.WriteEncodedInt((int)GroupType); writer.WriteEncodedInt((int)TieType); @@ -1543,10 +232,10 @@ namespace Server.Engines.ConPVP writer.Write(SignupPeriod); } - public void HandleTie(Arena arena, TournyMatch match, ArrayList remaining) + public void HandleTie(Arena arena, TourneyMatch match, List remaining) { if (remaining.Count == 1) - HandleWon(arena, match, (TournyParticipant)remaining[0]); + HandleWon(arena, match, remaining[0]); if (remaining.Count < 2) return; @@ -1555,23 +244,17 @@ namespace Server.Engines.ConPVP sb.Append("The match has ended in a tie "); - if (remaining.Count == 2) - sb.Append("between "); - else - sb.Append("among "); + sb.Append(remaining.Count == 2 ? "between " : "among "); sb.Append(remaining.Count); - - if (((TournyParticipant)remaining[0]).Players.Count == 1) - sb.Append(" players: "); - else - sb.Append(" teams: "); + + sb.Append(remaining[0].Players.Count == 1 ? " players: " : " teams: "); bool hasAppended = false; for (int j = 0; j < match.Participants.Count; ++j) { - TournyParticipant part = (TournyParticipant)match.Participants[j]; + TourneyParticipant part = match.Participants[j]; if (remaining.Contains(part)) { @@ -1596,7 +279,7 @@ namespace Server.Engines.ConPVP if (tieType == TieType.FullElimination && remaining.Count >= Undefeated.Count) tieType = TieType.FullAdvancement; - switch (TieType) + switch (tieType) { case TieType.FullAdvancement: { @@ -1613,7 +296,7 @@ namespace Server.Engines.ConPVP } case TieType.Random: { - TournyParticipant advanced = (TournyParticipant)remaining[Utility.Random(remaining.Count)]; + TourneyParticipant advanced = remaining[Utility.Random(remaining.Count)]; for (int i = 0; i < remaining.Count; ++i) if (remaining[i] != advanced) @@ -1627,11 +310,11 @@ namespace Server.Engines.ConPVP } case TieType.Highest: { - TournyParticipant advanced = null; + TourneyParticipant advanced = null; for (int i = 0; i < remaining.Count; ++i) { - TournyParticipant part = (TournyParticipant)remaining[i]; + TourneyParticipant part = remaining[i]; if (advanced == null || part.TotalLadderXP > advanced.TotalLadderXP) advanced = part; @@ -1649,11 +332,11 @@ namespace Server.Engines.ConPVP } case TieType.Lowest: { - TournyParticipant advanced = null; + TourneyParticipant advanced = null; for (int i = 0; i < remaining.Count; ++i) { - TournyParticipant part = (TournyParticipant)remaining[i]; + TourneyParticipant part = remaining[i]; if (advanced == null || part.TotalLadderXP < advanced.TotalLadderXP) advanced = part; @@ -1681,19 +364,19 @@ namespace Server.Engines.ConPVP if (!part.Eliminated) return; - if (TournyType == TournyType.FreeForAll) + if (TourneyType == TourneyType.FreeForAll) { int rem = 0; for (int i = 0; i < part.Context.Participants.Count; ++i) { - Participant check = (Participant)part.Context.Participants[i]; + Participant check = part.Context.Participants[i]; if (check != null && !check.Eliminated) ++rem; } - TournyParticipant tp = part.TournyPart; + TourneyParticipant tp = part.TourneyPart; if (tp == null) return; @@ -1705,7 +388,7 @@ namespace Server.Engines.ConPVP } } - public void HandleWon(Arena arena, TournyMatch match, TournyParticipant winner) + public void HandleWon(Arena arena, TourneyMatch match, TourneyParticipant winner) { StringBuilder sb = new StringBuilder(); @@ -1725,7 +408,7 @@ namespace Server.Engines.ConPVP for (int j = 0; j < match.Participants.Count; ++j) { - TournyParticipant part = (TournyParticipant)match.Participants[j]; + TourneyParticipant part = match.Participants[j]; if (part == winner) continue; @@ -1741,7 +424,7 @@ namespace Server.Engines.ConPVP sb.Append("."); - if (TournyType == TournyType.Standard) + if (TourneyType == TourneyType.Standard) Alert(arena, sb.ToString()); } @@ -1752,44 +435,44 @@ namespace Server.Engines.ConPVP private void GiveAwards() { - switch (TournyType) + switch (TourneyType) { - case TournyType.FreeForAll: + case TourneyType.FreeForAll: { if (Pyramid.Levels.Count < 1) break; - PyramidLevel top = Pyramid.Levels[Pyramid.Levels.Count - 1] as PyramidLevel; + PyramidLevel top = Pyramid.Levels[Pyramid.Levels.Count - 1]; if (top.FreeAdvance != null || top.Matches.Count != 1) break; - TournyMatch match = top.Matches[0] as TournyMatch; - TournyParticipant winner = match.Winner; + TourneyMatch match = top.Matches[0]; + TourneyParticipant winner = match.Winner; if (winner != null) GiveAwards(winner.Players, TrophyRank.Gold, ComputeCashAward()); break; } - case TournyType.Standard: + case TourneyType.Standard: { if (Pyramid.Levels.Count < 2) break; - PyramidLevel top = Pyramid.Levels[Pyramid.Levels.Count - 1] as PyramidLevel; + PyramidLevel top = Pyramid.Levels[Pyramid.Levels.Count - 1]; if (top.FreeAdvance != null || top.Matches.Count != 1) break; int cash = ComputeCashAward(); - TournyMatch match = top.Matches[0] as TournyMatch; - TournyParticipant winner = match.Winner; + TourneyMatch match = top.Matches[0]; + TourneyParticipant winner = match.Winner; for (int i = 0; i < match.Participants.Count; ++i) { - TournyParticipant part = (TournyParticipant)match.Participants[i]; + TourneyParticipant part = match.Participants[i]; if (part == winner) GiveAwards(part.Players, TrophyRank.Gold, cash); @@ -1797,19 +480,19 @@ namespace Server.Engines.ConPVP GiveAwards(part.Players, TrophyRank.Silver, cash / 2); } - PyramidLevel next = Pyramid.Levels[Pyramid.Levels.Count - 2] as PyramidLevel; + PyramidLevel next = Pyramid.Levels[Pyramid.Levels.Count - 2]; if (next.Matches.Count > 2) break; for (int i = 0; i < next.Matches.Count; ++i) { - match = (TournyMatch)next.Matches[i]; + match = next.Matches[i]; winner = match.Winner; for (int j = 0; j < match.Participants.Count; ++j) { - TournyParticipant part = (TournyParticipant)match.Participants[j]; + TourneyParticipant part = match.Participants[j]; if (part != winner) GiveAwards(part.Players, TrophyRank.Bronze, cash / 4); @@ -1821,7 +504,7 @@ namespace Server.Engines.ConPVP } } - private void GiveAwards(ArrayList players, TrophyRank rank, int cash) + private void GiveAwards(List players, TrophyRank rank, int cash) { if (players.Count == 0) return; @@ -1835,22 +518,22 @@ namespace Server.Engines.ConPVP StringBuilder sb = new StringBuilder(); - if (TournyType == TournyType.FreeForAll) + if (TourneyType == TourneyType.FreeForAll) { sb.Append(Participants.Count * m_PlayersPerParticipant); sb.Append("-man FFA"); } - else if (TournyType == TournyType.RandomTeam) + else if (TourneyType == TourneyType.RandomTeam) { sb.Append(m_ParticipantsPerMatch); sb.Append("-Team"); } - else if (TournyType == TournyType.Faction) + else if (TourneyType == TourneyType.Faction) { sb.Append(m_ParticipantsPerMatch); sb.Append("-Team Faction"); } - else if (TournyType == TournyType.RedVsBlue) + else if (TourneyType == TourneyType.RedVsBlue) { sb.Append("Red v Blue"); } @@ -1874,7 +557,7 @@ namespace Server.Engines.ConPVP for (int i = 0; i < players.Count; ++i) { - Mobile mob = (Mobile)players[i]; + Mobile mob = players[i]; if (mob == null || mob.Deleted) continue; @@ -1913,15 +596,15 @@ namespace Server.Engines.ConPVP { for (int i = Participants.Count - 1; i >= 0; --i) { - TournyParticipant part = (TournyParticipant)Participants[i]; + TourneyParticipant part = Participants[i]; bool bad = false; for (int j = 0; j < part.Players.Count; ++j) { - Mobile check = (Mobile)part.Players[j]; + Mobile check = part.Players[j]; if (check.Deleted || check.Map == null || check.Map == Map.Internal || !check.Alive || - Sigil.ExistsOn(check) || check.Region.IsPartOf(typeof(Jail))) + Sigil.ExistsOn(check) || check.Region.IsPartOf()) { bad = true; break; @@ -1931,7 +614,7 @@ namespace Server.Engines.ConPVP if (bad) { for (int j = 0; j < part.Players.Count; ++j) - ((Mobile)part.Players[j]).SendMessage("You have been disqualified from the tournament."); + part.Players[j].SendMessage("You have been disqualified from the tournament."); Participants.RemoveAt(i); } @@ -1944,16 +627,16 @@ namespace Server.Engines.ConPVP Undefeated.Clear(); Pyramid.Levels.Clear(); - Pyramid.AddLevel(m_ParticipantsPerMatch, Participants, GroupType, TournyType); + Pyramid.AddLevel(m_ParticipantsPerMatch, Participants, GroupType, TourneyType); - PyramidLevel level = (PyramidLevel)Pyramid.Levels[0]; + PyramidLevel level = Pyramid.Levels[0]; if (level.FreeAdvance != null) Undefeated.Add(level.FreeAdvance); for (int i = 0; i < level.Matches.Count; ++i) { - TournyMatch match = (TournyMatch)level.Matches[i]; + TourneyMatch match = level.Matches[i]; Undefeated.AddRange(match.Participants); } @@ -1984,27 +667,27 @@ namespace Server.Engines.ConPVP { if (Undefeated.Count == 1) { - TournyParticipant winner = (TournyParticipant)Undefeated[0]; + TourneyParticipant winner = Undefeated[0]; try { if (EventController != null) { Alert("The tournament has completed!", - $"Team {EventController.GetTeamName(((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner))} has won!"); + $"Team {EventController.GetTeamName(Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner))} has won!"); } - else if (TournyType == TournyType.RandomTeam) + else if (TourneyType == TourneyType.RandomTeam) { Alert("The tournament has completed!", - $"Team {((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner) + 1} has won!"); + $"Team {Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner) + 1} has won!"); } - else if (TournyType == TournyType.Faction) + else if (TourneyType == TourneyType.Faction) { if (m_ParticipantsPerMatch == 4) { string name = "(null)"; - switch (((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf( + switch (Pyramid.Levels[0].Matches[0].Participants.IndexOf( winner)) { case 0: @@ -2034,18 +717,18 @@ namespace Server.Engines.ConPVP else if (m_ParticipantsPerMatch == 2) { Alert("The tournament has completed!", - $"The {(((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner) == 0 ? "Evil" : "Hero")} team has won!"); + $"The {(Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner) == 0 ? "Evil" : "Hero")} team has won!"); } else { Alert("The tournament has completed!", - $"Team {((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner) + 1} has won!"); + $"Team {Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner) + 1} has won!"); } } - else if (TournyType == TournyType.RedVsBlue) + else if (TourneyType == TourneyType.RedVsBlue) { Alert("The tournament has completed!", - $"Team {(((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner) == 0 ? "Red" : "Blue")} has won!"); + $"Team {(Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner) == 0 ? "Red" : "Blue")} has won!"); } else { @@ -2055,6 +738,7 @@ namespace Server.Engines.ConPVP } catch { + // ignored } GiveAwards(); @@ -2064,12 +748,12 @@ namespace Server.Engines.ConPVP } else if (Pyramid.Levels.Count > 0) { - PyramidLevel activeLevel = (PyramidLevel)Pyramid.Levels[Pyramid.Levels.Count - 1]; + PyramidLevel activeLevel = Pyramid.Levels[Pyramid.Levels.Count - 1]; bool stillGoing = false; for (int i = 0; i < activeLevel.Matches.Count; ++i) { - TournyMatch match = (TournyMatch)activeLevel.Matches[i]; + TourneyMatch match = activeLevel.Matches[i]; if (match.Winner == null) { @@ -2093,51 +777,52 @@ namespace Server.Engines.ConPVP { for (int i = Undefeated.Count - 1; i >= 0; --i) { - TournyParticipant part = (TournyParticipant)Undefeated[i]; + TourneyParticipant part = Undefeated[i]; bool bad = false; for (int j = 0; j < part.Players.Count; ++j) { - Mobile check = (Mobile)part.Players[j]; + Mobile check = part.Players[j]; if (check.Deleted || check.Map == null || check.Map == Map.Internal || !check.Alive || - Sigil.ExistsOn(check) || check.Region.IsPartOf(typeof(Jail))) + Sigil.ExistsOn(check) || check.Region.IsPartOf()) { bad = true; break; } } - if (bad) - { - for (int j = 0; j < part.Players.Count; ++j) - ((Mobile)part.Players[j]).SendMessage("You have been disqualified from the tournament."); + if (!bad) + continue; + + for (int j = 0; j < part.Players.Count; ++j) + part.Players[j].SendMessage("You have been disqualified from the tournament."); Undefeated.RemoveAt(i); if (Undefeated.Count == 1) { - TournyParticipant winner = (TournyParticipant)Undefeated[0]; + TourneyParticipant winner = Undefeated[0]; try { if (EventController != null) { Alert("The tournament has completed!", - $"Team {EventController.GetTeamName(((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner))} has won"); + $"Team {EventController.GetTeamName(Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner))} has won"); } - else if (TournyType == TournyType.RandomTeam) + else if (TourneyType == TourneyType.RandomTeam) { Alert("The tournament has completed!", - $"Team {((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner) + 1} has won!"); + $"Team {Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner) + 1} has won!"); } - else if (TournyType == TournyType.Faction) + else if (TourneyType == TourneyType.Faction) { if (m_ParticipantsPerMatch == 4) { string name = "(null)"; - switch (((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]) + switch (Pyramid.Levels[0].Matches[0] .Participants.IndexOf(winner)) { case 0: @@ -2167,18 +852,18 @@ namespace Server.Engines.ConPVP else if (m_ParticipantsPerMatch == 2) { Alert("The tournament has completed!", - $"The {(((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner) == 0 ? "Evil" : "Hero")} team has won!"); + $"The {(Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner) == 0 ? "Evil" : "Hero")} team has won!"); } else { Alert("The tournament has completed!", - $"Team {((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner) + 1} has won!"); + $"Team {Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner) + 1} has won!"); } } - else if (TournyType == TournyType.RedVsBlue) + else if (TourneyType == TourneyType.RedVsBlue) { Alert("The tournament has completed!", - $"Team {(((TournyMatch)((PyramidLevel)Pyramid.Levels[0]).Matches[0]).Participants.IndexOf(winner) == 0 ? "Red" : "Blue")} has won!"); + $"Team {(Pyramid.Levels[0].Matches[0].Participants.IndexOf(winner) == 0 ? "Red" : "Blue")} has won!"); } else { @@ -2188,6 +873,7 @@ namespace Server.Engines.ConPVP } catch { + // ignored } GiveAwards(); @@ -2196,11 +882,11 @@ namespace Server.Engines.ConPVP Undefeated.Clear(); break; } - } + } if (Undefeated.Count > 1) - Pyramid.AddLevel(m_ParticipantsPerMatch, Undefeated, GroupType, TournyType); + Pyramid.AddLevel(m_ParticipantsPerMatch, Undefeated, GroupType, TourneyType); } } } @@ -2216,1350 +902,11 @@ namespace Server.Engines.ConPVP { if (arena?.Announcer != null) for (int j = 0; j < alerts.Length; ++j) - Timer.DelayCall(TimeSpan.FromSeconds(Math.Max(j - 0.5, 0.0)), new TimerStateCallback(Alert_Callback), - new object[] { arena.Announcer, alerts[j] }); - } - - private void Alert_Callback(object state) - { - object[] states = (object[])state; - - ((Mobile)states[0])?.PublicOverheadMessage(MessageType.Regular, 0x35, false, (string)states[1]); - } - } - - public class TournyPyramid - { - public TournyPyramid() - { - Levels = new ArrayList(); - } - - public ArrayList Levels{ get; set; } - - public void AddLevel(int partsPerMatch, ArrayList participants, GroupingType groupType, TournyType tournyType) - { - ArrayList copy = new ArrayList(participants); - - if (groupType == GroupingType.Nearest || groupType == GroupingType.HighVsLow) - copy.Sort(); - - PyramidLevel level = new PyramidLevel(); - - switch (tournyType) - { - case TournyType.RedVsBlue: { - TournyParticipant[] parts = new TournyParticipant[2]; - - for (int i = 0; i < parts.Length; ++i) - parts[i] = new TournyParticipant(new ArrayList()); - - for (int i = 0; i < copy.Count; ++i) - { - ArrayList players = ((TournyParticipant)copy[i]).Players; - - for (int j = 0; j < players.Count; ++j) - { - Mobile mob = (Mobile)players[j]; - - if (mob.Kills >= 5) - parts[0].Players.Add(mob); - else - parts[1].Players.Add(mob); - } - } - - level.Matches.Add(new TournyMatch(new ArrayList(parts))); - break; + string alert = alerts[j]; + Timer.DelayCall(TimeSpan.FromSeconds(Math.Max(j - 0.5, 0.0)), + () => arena.Announcer.PublicOverheadMessage(MessageType.Regular, 0x35, false, alert)); } - case TournyType.Faction: - { - TournyParticipant[] parts = new TournyParticipant[partsPerMatch]; - - for (int i = 0; i < parts.Length; ++i) - parts[i] = new TournyParticipant(new ArrayList()); - - for (int i = 0; i < copy.Count; ++i) - { - ArrayList players = ((TournyParticipant)copy[i]).Players; - - for (int j = 0; j < players.Count; ++j) - { - Mobile mob = (Mobile)players[j]; - - int index = -1; - - if (partsPerMatch == 4) - { - Faction fac = Faction.Find(mob); - - if (fac != null) index = fac.Definition.Sort; - } - else if (partsPerMatch == 2) - { - if (Ethic.Evil.IsEligible(mob)) - index = 0; - else if (Ethic.Hero.IsEligible(mob)) index = 1; - } - - if (index < 0 || index >= partsPerMatch) index = i % partsPerMatch; - - parts[index].Players.Add(mob); - } - } - - level.Matches.Add(new TournyMatch(new ArrayList(parts))); - break; - } - case TournyType.RandomTeam: - { - TournyParticipant[] parts = new TournyParticipant[partsPerMatch]; - - for (int i = 0; i < partsPerMatch; ++i) - parts[i] = new TournyParticipant(new ArrayList()); - - for (int i = 0; i < copy.Count; ++i) - parts[i % parts.Length].Players.AddRange(((TournyParticipant)copy[i]).Players); - - level.Matches.Add(new TournyMatch(new ArrayList(parts))); - break; - } - case TournyType.FreeForAll: - { - level.Matches.Add(new TournyMatch(copy)); - break; - } - case TournyType.Standard: - { - if (partsPerMatch >= 2 && participants.Count % partsPerMatch == 1) - { - int lowAdvances = int.MaxValue; - - for (int i = 0; i < participants.Count; ++i) - { - TournyParticipant p = (TournyParticipant)participants[i]; - - if (p.FreeAdvances < lowAdvances) - lowAdvances = p.FreeAdvances; - } - - ArrayList toAdvance = new ArrayList(); - - for (int i = 0; i < participants.Count; ++i) - { - TournyParticipant p = (TournyParticipant)participants[i]; - - if (p.FreeAdvances == lowAdvances) - toAdvance.Add(p); - } - - if (toAdvance.Count == 0) - toAdvance = copy; // sanity - - int idx = Utility.Random(toAdvance.Count); - - ((TournyParticipant)toAdvance[idx]).AddLog( - "Advanced automatically due to an odd number of challengers."); - level.FreeAdvance = (TournyParticipant)toAdvance[idx]; - ++level.FreeAdvance.FreeAdvances; - copy.Remove(toAdvance[idx]); - } - - while (copy.Count >= partsPerMatch) - { - ArrayList thisMatch = new ArrayList(); - - for (int i = 0; i < partsPerMatch; ++i) - { - int idx = 0; - - switch (groupType) - { - case GroupingType.HighVsLow: - idx = i * (copy.Count - 1) / (partsPerMatch - 1); - break; - case GroupingType.Nearest: - idx = 0; - break; - case GroupingType.Random: - idx = Utility.Random(copy.Count); - break; - } - - thisMatch.Add(copy[idx]); - copy.RemoveAt(idx); - } - - level.Matches.Add(new TournyMatch(thisMatch)); - } - - if (copy.Count > 1) - level.Matches.Add(new TournyMatch(copy)); - - break; - } - } - - Levels.Add(level); - } - } - - public class PyramidLevel - { - public PyramidLevel() - { - Matches = new ArrayList(); - } - - public ArrayList Matches{ get; set; } - - public TournyParticipant FreeAdvance{ get; set; } - } - - public class TournyMatch - { - public TournyMatch(ArrayList participants) - { - Participants = participants; - - for (int i = 0; i < participants.Count; ++i) - { - TournyParticipant part = (TournyParticipant)participants[i]; - - StringBuilder sb = new StringBuilder(); - - sb.Append("Matched in a duel against "); - - if (participants.Count > 2) - sb.AppendFormat("{0} other {1}: ", participants.Count - 1, - part.Players.Count == 1 ? "players" : "teams"); - - bool hasAppended = false; - - for (int j = 0; j < participants.Count; ++j) - { - if (i == j) - continue; - - if (hasAppended) - sb.Append(", "); - - sb.Append(((TournyParticipant)participants[j]).NameList); - hasAppended = true; - } - - sb.Append("."); - - part.AddLog(sb.ToString()); - } - } - - public ArrayList Participants{ get; set; } - - public TournyParticipant Winner{ get; set; } - - public DuelContext Context{ get; set; } - - public bool InProgress => Context != null && Context.Registered; - - public void Start(Arena arena, Tournament tourny) - { - TournyParticipant first = (TournyParticipant)Participants[0]; - - DuelContext dc = new DuelContext((Mobile)first.Players[0], tourny.Ruleset.Layout, false); - dc.Ruleset.Options.SetAll(false); - dc.Ruleset.Options.Or(tourny.Ruleset.Options); - - for (int i = 0; i < Participants.Count; ++i) - { - TournyParticipant tournyPart = (TournyParticipant)Participants[i]; - Participant duelPart = new Participant(dc, tournyPart.Players.Count); - - duelPart.TournyPart = tournyPart; - - for (int j = 0; j < tournyPart.Players.Count; ++j) - duelPart.Add((Mobile)tournyPart.Players[j]); - - for (int j = 0; j < duelPart.Players.Length; ++j) - if (duelPart.Players[j] != null) - duelPart.Players[j].Ready = true; - - dc.Participants.Add(duelPart); - } - - if (tourny.EventController != null) - dc.m_EventGame = tourny.EventController.Construct(dc); - - dc.m_Tournament = tourny; - dc.m_Match = this; - - dc.m_OverrideArena = arena; - - if (tourny.SuddenDeath > TimeSpan.Zero && - (tourny.SuddenDeathRounds == 0 || tourny.Pyramid.Levels.Count <= tourny.SuddenDeathRounds)) - dc.StartSuddenDeath(tourny.SuddenDeath); - - dc.SendReadyGump(0); - - if (dc.StartedBeginCountdown) - { - Context = dc; - - for (int i = 0; i < Participants.Count; ++i) - { - TournyParticipant p = (TournyParticipant)Participants[i]; - - for (int j = 0; j < p.Players.Count; ++j) - { - Mobile mob = (Mobile)p.Players[j]; - - foreach (Mobile view in mob.GetMobilesInRange(18)) - if (!mob.CanSee(view)) - mob.Send(view.RemovePacket); - - mob.LocalOverheadMessage(MessageType.Emote, 0x3B2, false, - "* Your mind focuses intently on the fight and all other distractions fade away *"); - } - } - } - else - { - dc.Unregister(); - dc.StopCountdown(); - } - } - } - - public class TournyParticipant : IComparable - { - public TournyParticipant(Mobile owner) - { - Log = new ArrayList(); - Players = new ArrayList(); - Players.Add(owner); - } - - public TournyParticipant(ArrayList players) - { - Log = new ArrayList(); - Players = players; - } - - public ArrayList Players{ get; set; } - - public ArrayList Log{ get; set; } - - public int FreeAdvances{ get; set; } - - public int TotalLadderXP - { - get - { - Ladder ladder = Ladder.Instance; - - if (ladder == null) - return 0; - - int total = 0; - - for (int i = 0; i < Players.Count; ++i) - { - Mobile mob = (Mobile)Players[i]; - LadderEntry entry = ladder.Find(mob); - - if (entry != null) - total += entry.Experience; - } - - return total; - } - } - - public string NameList - { - get - { - StringBuilder sb = new StringBuilder(); - - for (int i = 0; i < Players.Count; ++i) - { - if (Players[i] == null) - continue; - - Mobile mob = (Mobile)Players[i]; - - if (sb.Length > 0) - { - if (Players.Count == 2) - sb.Append(" and "); - else if (i + 1 < Players.Count) - sb.Append(", "); - else - sb.Append(", and "); - } - - sb.Append(mob.Name); - } - - if (sb.Length == 0) - return "Empty"; - - return sb.ToString(); - } - } - - public int CompareTo(object obj) - { - TournyParticipant p = (TournyParticipant)obj; - - return p.TotalLadderXP - TotalLadderXP; - } - - public void AddLog(string text) - { - Log.Add(text); - } - - public void AddLog(string format, params object[] args) - { - AddLog(string.Format(format, args)); - } - - public void WonMatch(TournyMatch match) - { - AddLog("Match won."); - } - - public void LostMatch(TournyMatch match) - { - AddLog("Match lost."); - } - } - - public enum TournyBracketGumpType - { - Index, - Rules_Info, - Participant_List, - Participant_Info, - Round_List, - Round_Info, - Match_Info, - Player_Info - } - - public class TournamentBracketGump : Gump - { - private const int BlackColor32 = 0x000008; - private const int LabelColor32 = 0xFFFFFF; - private Mobile m_From; - private ArrayList m_List; - private object m_Object; - private int m_Page; - private int m_PerPage; - private Tournament m_Tournament; - private TournyBracketGumpType m_Type; - - public TournamentBracketGump(Mobile from, Tournament tourny, TournyBracketGumpType type, ArrayList list, int page, - object obj) : base(50, 50) - { - m_From = from; - m_Tournament = tourny; - m_Type = type; - m_List = list; - m_Page = page; - m_Object = obj; - m_PerPage = 12; - - switch (type) - { - case TournyBracketGumpType.Index: - { - AddPage(0); - AddBackground(0, 0, 300, 300, 9380); - - StringBuilder sb = new StringBuilder(); - - if (tourny.TournyType == TournyType.FreeForAll) - { - sb.Append("FFA"); - } - else if (tourny.TournyType == TournyType.RandomTeam) - { - sb.Append(tourny.ParticipantsPerMatch); - sb.Append("-Team"); - } - else if (tourny.TournyType == TournyType.RedVsBlue) - { - sb.Append("Red v Blue"); - } - else if (tourny.TournyType == TournyType.Faction) - { - sb.Append(tourny.ParticipantsPerMatch); - sb.Append("-Team Faction"); - } - else - { - for (int i = 0; i < tourny.ParticipantsPerMatch; ++i) - { - if (sb.Length > 0) - sb.Append('v'); - - sb.Append(tourny.PlayersPerParticipant); - } - } - - if (tourny.EventController != null) - sb.Append(' ').Append(tourny.EventController.Title); - - sb.Append(" Tournament Bracket"); - - AddHtml(25, 35, 250, 20, Center(sb.ToString()), false, false); - - AddRightArrow(25, 53, ToButtonID(0, 4), "Rules"); - AddRightArrow(25, 71, ToButtonID(0, 1), "Participants"); - - if (m_Tournament.Stage == TournamentStage.Signup) - { - TimeSpan until = m_Tournament.SignupStart + m_Tournament.SignupPeriod - DateTime.UtcNow; - string text; - int secs = (int)until.TotalSeconds; - - if (secs > 0) - { - int mins = secs / 60; - secs %= 60; - - if (mins > 0 && secs > 0) - text = - $"The tournament will begin in {mins} minute{(mins == 1 ? "" : "s")} and {secs} second{(secs == 1 ? "" : "s")}."; - else if (mins > 0) - text = $"The tournament will begin in {mins} minute{(mins == 1 ? "" : "s")}."; - else if (secs > 0) - text = $"The tournament will begin in {secs} second{(secs == 1 ? "" : "s")}."; - else - text = "The tournament will begin shortly."; - } - else - { - text = "The tournament will begin shortly."; - } - - AddHtml(25, 92, 250, 40, text, false, false); - } - else - { - AddRightArrow(25, 89, ToButtonID(0, 2), "Rounds"); - } - - break; - } - case TournyBracketGumpType.Rules_Info: - { - Ruleset ruleset = tourny.Ruleset; - Ruleset basedef = ruleset.Base; - - BitArray defs; - - if (ruleset.Flavors.Count > 0) - { - defs = new BitArray(basedef.Options); - - for (int i = 0; i < ruleset.Flavors.Count; ++i) - defs.Or(((Ruleset)ruleset.Flavors[i]).Options); - } - else - { - defs = basedef.Options; - } - - int changes = 0; - - BitArray opts = ruleset.Options; - - for (int i = 0; i < opts.Length; ++i) - if (defs[i] != opts[i]) - ++changes; - - AddPage(0); - AddBackground(0, 0, 300, - 60 + 18 + 20 + 20 + 20 + 8 + 20 + ruleset.Flavors.Count * 18 + 4 + 20 + changes * 22 + 6, 9380); - - AddLeftArrow(25, 11, ToButtonID(0, 0)); - AddHtml(25, 35, 250, 20, Center("Rules"), false, false); - - int y = 53; - - string groupText = null; - - switch (tourny.GroupType) - { - case GroupingType.HighVsLow: - groupText = "High vs Low"; - break; - case GroupingType.Nearest: - groupText = "Closest opponent"; - break; - case GroupingType.Random: - groupText = "Random"; - break; - } - - AddHtml(35, y, 190, 20, $"Grouping: {groupText}", false, false); - y += 20; - - string tieText = null; - - switch (tourny.TieType) - { - case TieType.Random: - tieText = "Random"; - break; - case TieType.Highest: - tieText = "Highest advances"; - break; - case TieType.Lowest: - tieText = "Lowest advances"; - break; - case TieType.FullAdvancement: - tieText = tourny.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances"; - break; - case TieType.FullElimination: - tieText = tourny.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated"; - break; - } - - AddHtml(35, y, 190, 20, $"Tiebreaker: {tieText}", false, false); - y += 20; - - string sdText = "Off"; - - if (tourny.SuddenDeath > TimeSpan.Zero) - { - sdText = $"{(int)tourny.SuddenDeath.TotalMinutes}:{tourny.SuddenDeath.Seconds:D2}"; - - if (tourny.SuddenDeathRounds > 0) - sdText = $"{sdText} (first {tourny.SuddenDeathRounds} rounds)"; - else - sdText = $"{sdText} (all rounds)"; - } - - AddHtml(35, y, 240, 20, $"Sudden Death: {sdText}", false, false); - y += 20; - - y += 8; - - AddHtml(35, y, 190, 20, $"Ruleset: {basedef.Title}", false, false); - y += 20; - - for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18) - AddHtml(35, y, 190, 20, $" + {((Ruleset)ruleset.Flavors[i]).Title}", false, false); - - y += 4; - - if (changes > 0) - { - AddHtml(35, y, 190, 20, "Modifications:", false, false); - y += 20; - - for (int i = 0; i < opts.Length; ++i) - if (defs[i] != opts[i]) - { - string name = ruleset.Layout.FindByIndex(i); - - if (name != null) // sanity - { - AddImage(35, y, opts[i] ? 0xD3 : 0xD2); - AddHtml(60, y, 165, 22, name, false, false); - } - - y += 22; - } - } - else - { - AddHtml(35, y, 190, 20, "Modifications: None", false, false); - y += 20; - } - - break; - } - case TournyBracketGumpType.Participant_List: - { - AddPage(0); - AddBackground(0, 0, 300, 300, 9380); - - if (m_List == null) - m_List = new ArrayList(tourny.Participants); - - AddLeftArrow(25, 11, ToButtonID(0, 0)); - AddHtml(25, 35, 250, 20, Center($"{m_List.Count} Participant{(m_List.Count == 1 ? "" : "s")}"), false, - false); - - int index, count, y; - StartPage(out index, out count, out y, 12); - - for (int i = 0; i < count; ++i, y += 18) - { - TournyParticipant part = (TournyParticipant)m_List[index + i]; - string name = part.NameList; - - if (m_Tournament.TournyType != TournyType.Standard && part.Players.Count == 1) - if (part.Players[0] is PlayerMobile pm && pm.DuelPlayer != null) - name = Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666); - - AddRightArrow(25, y, ToButtonID(2, index + i), name); - } - - break; - } - case TournyBracketGumpType.Participant_Info: - { - if (!(obj is TournyParticipant part)) - break; - - AddPage(0); - AddBackground(0, 0, 300, 60 + 18 + 20 + part.Players.Count * 18 + 20 + 20 + 160, 9380); - - AddLeftArrow(25, 11, ToButtonID(0, 1)); - AddHtml(25, 35, 250, 20, Center("Participants"), false, false); - - int y = 53; - - AddHtml(25, y, 200, 20, part.Players.Count == 1 ? "Players" : "Team", false, false); - y += 20; - - for (int i = 0; i < part.Players.Count; ++i) - { - Mobile mob = (Mobile)part.Players[i]; - string name = mob.Name; - - if (m_Tournament.TournyType != TournyType.Standard) - if (mob is PlayerMobile pm && pm.DuelPlayer != null) - name = Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666); - - AddRightArrow(35, y, ToButtonID(4, i), name); - y += 18; - } - - AddHtml(25, y, 200, 20, - $"Free Advances: {(part.FreeAdvances == 0 ? "None" : part.FreeAdvances.ToString())}", false, false); - y += 20; - - AddHtml(25, y, 200, 20, "Log:", false, false); - y += 20; - - StringBuilder sb = new StringBuilder(); - - for (int i = 0; i < part.Log.Count; ++i) - { - if (sb.Length > 0) - sb.Append("
"); - - sb.Append(part.Log[i]); - } - - if (sb.Length == 0) - sb.Append("Nothing logged yet."); - - AddHtml(25, y, 250, 150, Color(sb.ToString(), BlackColor32), false, true); - - break; - } - case TournyBracketGumpType.Player_Info: - { - AddPage(0); - AddBackground(0, 0, 300, 300, 9380); - - AddLeftArrow(25, 11, ToButtonID(0, 3)); - AddHtml(25, 35, 250, 20, Center("Participants"), false, false); - - if (!(obj is Mobile mob)) - break; - - Ladder ladder = Ladder.Instance; - LadderEntry entry = ladder?.Find(mob); - - AddHtml(25, 53, 250, 20, $"Name: {mob.Name}", false, false); - AddHtml(25, 73, 250, 20, - $"Guild: {(mob.Guild == null ? "None" : mob.Guild.Name + " [" + mob.Guild.Abbreviation + "]")}", - false, false); - AddHtml(25, 93, 250, 20, $"Rank: {(entry == null ? "N/A" : LadderGump.Rank(entry.Index + 1))}", false, - false); - AddHtml(25, 113, 250, 20, $"Level: {(entry == null ? 0 : Ladder.GetLevel(entry.Experience))}", false, - false); - AddHtml(25, 133, 250, 20, $"Wins: {entry?.Wins ?? 0:N0}", false, false); - AddHtml(25, 153, 250, 20, $"Losses: {entry?.Losses ?? 0:N0}", false, false); - - break; - } - case TournyBracketGumpType.Round_List: - { - AddPage(0); - AddBackground(0, 0, 300, 300, 9380); - - AddLeftArrow(25, 11, ToButtonID(0, 0)); - AddHtml(25, 35, 250, 20, Center("Rounds"), false, false); - - if (m_List == null) - m_List = new ArrayList(tourny.Pyramid.Levels); - - int index, count, y; - StartPage(out index, out count, out y, 12); - - for (int i = 0; i < count; ++i, y += 18) - // PyramidLevel level = (PyramidLevel)m_List[index + i]; - - AddRightArrow(25, y, ToButtonID(3, index + i), "Round #" + (index + i + 1)); - - break; - } - case TournyBracketGumpType.Round_Info: - { - AddPage(0); - AddBackground(0, 0, 300, 300, 9380); - - AddLeftArrow(25, 11, ToButtonID(0, 2)); - AddHtml(25, 35, 250, 20, Center("Rounds"), false, false); - - if (!(m_Object is PyramidLevel level)) - break; - - if (m_List == null) - m_List = new ArrayList(level.Matches); - - AddRightArrow(25, 53, ToButtonID(5, 0), - $"Free Advance: {(level.FreeAdvance == null ? "None" : level.FreeAdvance.NameList)}"); - - AddHtml(25, 73, 200, 20, $"{m_List.Count} Match{(m_List.Count == 1 ? "" : "es")}", false, false); - - int index, count, y; - StartPage(out index, out count, out y, 10); - - for (int i = 0; i < count; ++i, y += 18) - { - TournyMatch match = (TournyMatch)m_List[index + i]; - - int color = -1; - - if (match.InProgress) - color = 0x336666; - else if (match.Context != null && match.Winner == null) - color = 0x666666; - - StringBuilder sb = new StringBuilder(); - - if (m_Tournament.TournyType == TournyType.Standard) - for (int j = 0; j < match.Participants.Count; ++j) - { - if (sb.Length > 0) - sb.Append(" vs "); - - TournyParticipant part = (TournyParticipant)match.Participants[j]; - string txt = part.NameList; - - if (color == -1 && match.Context != null && match.Winner == part) - txt = Color(txt, 0x336633); - else if (color == -1 && match.Context != null) - txt = Color(txt, 0x663333); - - sb.Append(txt); - } - else if (m_Tournament.EventController != null || m_Tournament.TournyType == TournyType.RandomTeam || - m_Tournament.TournyType == TournyType.RedVsBlue || - m_Tournament.TournyType == TournyType.Faction) - for (int j = 0; j < match.Participants.Count; ++j) - { - if (sb.Length > 0) - sb.Append(" vs "); - - TournyParticipant part = (TournyParticipant)match.Participants[j]; - string txt; - - if (m_Tournament.EventController != null) - { - txt = $"Team {m_Tournament.EventController.GetTeamName(j)} ({part.Players.Count})"; - } - else if (m_Tournament.TournyType == TournyType.RandomTeam) - { - txt = $"Team {j + 1} ({part.Players.Count})"; - } - else if (m_Tournament.TournyType == TournyType.Faction) - { - if (m_Tournament.ParticipantsPerMatch == 4) - { - string name = "(null)"; - - switch (j) - { - case 0: - { - name = "Minax"; - break; - } - case 1: - { - name = "Council of Mages"; - break; - } - case 2: - { - name = "True Britannians"; - break; - } - case 3: - { - name = "Shadowlords"; - break; - } - } - - txt = $"{name} ({part.Players.Count})"; - } - else if (m_Tournament.ParticipantsPerMatch == 2) - { - txt = $"{(j == 0 ? "Evil" : "Hero")} Team ({part.Players.Count})"; - } - else - { - txt = $"Team {j + 1} ({part.Players.Count})"; - } - } - else - { - txt = $"Team {(j == 0 ? "Red" : "Blue")} ({part.Players.Count})"; - } - - if (color == -1 && match.Context != null && match.Winner == part) - txt = Color(txt, 0x336633); - else if (color == -1 && match.Context != null) - txt = Color(txt, 0x663333); - - sb.Append(txt); - } - else if (m_Tournament.TournyType == TournyType.FreeForAll) sb.Append("Free For All"); - - string str = sb.ToString(); - - if (color >= 0) - str = Color(str, color); - - AddRightArrow(25, y, ToButtonID(5, index + i + 1), str); - } - - break; - } - case TournyBracketGumpType.Match_Info: - { - if (!(obj is TournyMatch match)) - break; - - int ct = m_Tournament.TournyType == TournyType.FreeForAll ? 2 : match.Participants.Count; - - AddPage(0); - AddBackground(0, 0, 300, 60 + 18 + 20 + 20 + 20 + ct * 18 + 6, 9380); - - AddLeftArrow(25, 11, ToButtonID(0, 5)); - AddHtml(25, 35, 250, 20, Center("Rounds"), false, false); - - AddHtml(25, 53, 250, 20, $"Winner: {(match.Winner == null ? "N/A" : match.Winner.NameList)}", false, - false); - AddHtml(25, 73, 250, 20, - $"State: {(match.InProgress ? "In progress" : match.Context != null ? "Complete" : "Waiting")}", - false, false); - AddHtml(25, 93, 250, 20, "Participants:", false, false); - - if (m_Tournament.TournyType == TournyType.Standard) - for (int i = 0; i < match.Participants.Count; ++i) - { - TournyParticipant part = (TournyParticipant)match.Participants[i]; - - AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), part.NameList); - } - else if (m_Tournament.EventController != null || m_Tournament.TournyType == TournyType.RandomTeam || - m_Tournament.TournyType == TournyType.RedVsBlue || - m_Tournament.TournyType == TournyType.Faction) - for (int i = 0; i < match.Participants.Count; ++i) - { - TournyParticipant part = (TournyParticipant)match.Participants[i]; - - if (m_Tournament.EventController != null) - { - AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), - $"Team {m_Tournament.EventController.GetTeamName(i)} ({part.Players.Count})"); - } - else if (m_Tournament.TournyType == TournyType.RandomTeam) - { - AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), - $"Team {i + 1} ({part.Players.Count})"); - } - else if (m_Tournament.TournyType == TournyType.Faction) - { - if (m_Tournament.ParticipantsPerMatch == 4) - { - string name = "(null)"; - - switch (i) - { - case 0: - { - name = "Minax"; - break; - } - case 1: - { - name = "Council of Mages"; - break; - } - case 2: - { - name = "True Britannians"; - break; - } - case 3: - { - name = "Shadowlords"; - break; - } - } - - AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), - $"{name} ({part.Players.Count})"); - } - else if (m_Tournament.ParticipantsPerMatch == 2) - { - AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), - $"{(i == 0 ? "Evil" : "Hero")} Team ({part.Players.Count})"); - } - else - { - AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), - $"Team {i + 1} ({part.Players.Count})"); - } - } - else - { - AddRightArrow(25, 113 + i * 18, ToButtonID(6, i), - $"Team {(i == 0 ? "Red" : "Blue")} ({part.Players.Count})"); - } - } - else if (m_Tournament.TournyType == TournyType.FreeForAll) - AddHtml(25, 113, 250, 20, "Free For All", false, false); - - break; - } - } - } - - public string Center(string text) - { - return $"
{text}
"; - } - - public string Color(string text, int color) - { - return $"{text}"; - } - - private void AddBorderedText(int x, int y, int width, int height, string text, int color, int borderColor) - { - AddColoredText(x - 1, y - 1, width, height, text, borderColor); - AddColoredText(x - 1, y + 1, width, height, text, borderColor); - AddColoredText(x + 1, y - 1, width, height, text, borderColor); - AddColoredText(x + 1, y + 1, width, height, text, borderColor); - AddColoredText(x, y, width, height, text, color); - } - - private void AddColoredText(int x, int y, int width, int height, string text, int color) - { - if (color == 0) - AddHtml(x, y, width, height, text, false, false); - else - AddHtml(x, y, width, height, Color(text, color), false, false); - } - - public void AddRightArrow(int x, int y, int bid, string text) - { - AddButton(x, y, 0x15E1, 0x15E5, bid, GumpButtonType.Reply, 0); - - if (text != null) - AddHtml(x + 20, y - 1, 230, 20, text, false, false); - } - - public void AddRightArrow(int x, int y, int bid) - { - AddRightArrow(x, y, bid, null); - } - - public void AddLeftArrow(int x, int y, int bid, string text) - { - AddButton(x, y, 0x15E3, 0x15E7, bid, GumpButtonType.Reply, 0); - - if (text != null) - AddHtml(x + 20, y - 1, 230, 20, text, false, false); - } - - public void AddLeftArrow(int x, int y, int bid) - { - AddLeftArrow(x, y, bid, null); - } - - public int ToButtonID(int type, int index) - { - return 1 + index * 7 + type; - } - - public bool FromButtonID(int bid, out int type, out int index) - { - type = (bid - 1) % 7; - index = (bid - 1) / 7; - return bid >= 1; - } - - public void StartPage(out int index, out int count, out int y, int perPage) - { - m_PerPage = perPage; - - index = Math.Max(m_Page * perPage, 0); - count = Math.Max(Math.Min(m_List.Count - index, perPage), 0); - - y = 53 + (12 - perPage) * 18; - - if (m_Page > 0) - AddLeftArrow(242, 35, ToButtonID(1, 0)); - - if ((m_Page + 1) * perPage < m_List.Count) - AddRightArrow(260, 35, ToButtonID(1, 1)); - } - - public override void OnResponse(NetState sender, RelayInfo info) - { - int type, index; - - if (!FromButtonID(info.ButtonID, out type, out index)) - return; - - switch (type) - { - case 0: - { - switch (index) - { - case 0: - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TournyBracketGumpType.Index, - null, 0, null)); - break; - case 1: - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, - TournyBracketGumpType.Participant_List, null, 0, null)); - break; - case 2: - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TournyBracketGumpType.Round_List, - null, 0, null)); - break; - case 4: - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TournyBracketGumpType.Rules_Info, - null, 0, null)); - break; - case 3: - { - Mobile mob = m_Object as Mobile; - - for (int i = 0; i < m_Tournament.Participants.Count; ++i) - { - TournyParticipant part = (TournyParticipant)m_Tournament.Participants[i]; - - if (part.Players.Contains(mob)) - { - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, - TournyBracketGumpType.Participant_Info, null, 0, part)); - break; - } - } - - break; - } - case 5: - { - if (!(m_Object is TournyMatch match)) - break; - - for (int i = 0; i < m_Tournament.Pyramid.Levels.Count; ++i) - { - PyramidLevel level = (PyramidLevel)m_Tournament.Pyramid.Levels[i]; - - if (level.Matches.Contains(match)) - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, - TournyBracketGumpType.Round_Info, null, 0, level)); - } - - break; - } - } - - break; - } - case 1: - { - switch (index) - { - case 0: - { - if (m_List != null && m_Page > 0) - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, m_Type, m_List, m_Page - 1, - m_Object)); - - break; - } - case 1: - { - if (m_List != null && (m_Page + 1) * m_PerPage < m_List.Count) - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, m_Type, m_List, m_Page + 1, - m_Object)); - - break; - } - } - - break; - } - case 2: - { - if (m_Type != TournyBracketGumpType.Participant_List) - break; - - if (index >= 0 && index < m_List.Count) - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, - TournyBracketGumpType.Participant_Info, null, 0, m_List[index])); - - break; - } - case 3: - { - if (m_Type != TournyBracketGumpType.Round_List) - break; - - if (index >= 0 && index < m_List.Count) - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TournyBracketGumpType.Round_Info, - null, 0, m_List[index])); - - break; - } - case 4: - { - if (m_Type != TournyBracketGumpType.Participant_Info) - break; - - if (m_Object is TournyParticipant part && index >= 0 && index < part.Players.Count) - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TournyBracketGumpType.Player_Info, - null, 0, part.Players[index])); - - break; - } - case 5: - { - if (m_Type != TournyBracketGumpType.Round_Info) - break; - - if (!(m_Object is PyramidLevel level)) - break; - - if (index == 0) - { - if (level.FreeAdvance != null) - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, - TournyBracketGumpType.Participant_Info, null, 0, level.FreeAdvance)); - else - m_From.SendGump( - new TournamentBracketGump(m_From, m_Tournament, m_Type, m_List, m_Page, m_Object)); - } - else if (index >= 1 && index <= level.Matches.Count) - { - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, TournyBracketGumpType.Match_Info, - null, 0, level.Matches[index - 1])); - } - - break; - } - case 6: - { - if (m_Type != TournyBracketGumpType.Match_Info) - break; - - if (m_Object is TournyMatch match && index >= 0 && index < match.Participants.Count) - m_From.SendGump(new TournamentBracketGump(m_From, m_Tournament, - TournyBracketGumpType.Participant_Info, null, 0, match.Participants[index])); - - break; - } - } - } - } - - public class TournamentBracketItem : Item - { - [Constructible] - public TournamentBracketItem() : base(3774) - { - Movable = false; - } - - public TournamentBracketItem(Serial serial) : base(serial) - { - } - - [CommandProperty(AccessLevel.GameMaster)] - public TournamentController Tournament{ get; set; } - - public override string DefaultName => "tournament bracket"; - - public override void OnDoubleClick(Mobile from) - { - if (!from.InRange(GetWorldLocation(), 2)) - { - from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that - } - else - { - Tournament tourny = Tournament?.Tournament; - - if (tourny != null) - { - from.CloseGump(typeof(TournamentBracketGump)); - from.SendGump(new TournamentBracketGump(from, tourny, TournyBracketGumpType.Index, null, 0, null)); - - /*if ( tourny.Stage == TournamentStage.Fighting && tourny.Pyramid.Levels.Count > 0 ) - from.SendGump( new TournamentBracketGump( tourny, (PyramidLevel)tourny.Pyramid.Levels[tourny.Pyramid.Levels.Count - 1] ) ); - else - from.SendGump( new TournamentBracketGump( tourny, 0 ) );*/ - } - } - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); - - writer.Write(Tournament); - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - - switch (version) - { - case 0: - { - Tournament = reader.ReadItem() as TournamentController; - break; - } - } } } } \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/TournamentBracketItem.cs b/Scripts/Engines/ConPVP/TournamentBracketItem.cs new file mode 100644 index 000000000..f1800b044 --- /dev/null +++ b/Scripts/Engines/ConPVP/TournamentBracketItem.cs @@ -0,0 +1,65 @@ +using Server.Network; + +namespace Server.Engines.ConPVP +{ + public class TournamentBracketItem : Item + { + [Constructible] + public TournamentBracketItem() : base(3774) + { + Movable = false; + } + + public TournamentBracketItem(Serial serial) : base(serial) + { + } + + [CommandProperty(AccessLevel.GameMaster)] + public TournamentController Tournament{ get; set; } + + public override string DefaultName => "tournament bracket"; + + public override void OnDoubleClick(Mobile from) + { + if (!from.InRange(GetWorldLocation(), 2)) + { + from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that + } + else + { + Tournament tourney = Tournament?.Tournament; + + if (tourney != null) + { + from.CloseGump(); + from.SendGump(new TournamentBracketGump(from, tourney, TourneyBracketGumpType.Index)); + } + } + } + + public override void Serialize(GenericWriter writer) + { + base.Serialize(writer); + + writer.Write(0); + + writer.Write(Tournament); + } + + public override void Deserialize(GenericReader reader) + { + base.Deserialize(reader); + + int version = reader.ReadInt(); + + switch (version) + { + case 0: + { + Tournament = reader.ReadItem() as TournamentController; + break; + } + } + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/TournamentController.cs b/Scripts/Engines/ConPVP/TournamentController.cs new file mode 100644 index 000000000..23d83eb01 --- /dev/null +++ b/Scripts/Engines/ConPVP/TournamentController.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using Server.ContextMenus; +using Server.Gumps; + +namespace Server.Engines.ConPVP +{ + public class TournamentController : Item + { + private static List m_Instances = new List(); + + [Constructible] + public TournamentController() : base(0x1B7A) + { + Visible = false; + Movable = false; + + Tournament = new Tournament(); + m_Instances.Add(this); + } + + public TournamentController(Serial serial) : base(serial) + { + } + + [CommandProperty(AccessLevel.GameMaster)] + public Tournament Tournament{ get; private set; } + + public static bool IsActive + { + get + { + for (int i = 0; i < m_Instances.Count; ++i) + { + TournamentController controller = m_Instances[i]; + + if (controller != null && !controller.Deleted && controller.Tournament != null && + controller.Tournament.Stage != TournamentStage.Inactive) + return true; + } + + return false; + } + } + + public override string DefaultName => "tournament controller"; + + public override void GetContextMenuEntries(Mobile from, List list) + { + base.GetContextMenuEntries(from, list); + + if (from.AccessLevel >= AccessLevel.GameMaster && Tournament != null) + { + list.Add(new EditEntry(Tournament)); + + if (Tournament.CurrentStage == TournamentStage.Inactive) + list.Add(new StartEntry(Tournament)); + } + } + + public override void OnDoubleClick(Mobile from) + { + if (from.AccessLevel >= AccessLevel.GameMaster && Tournament != null) + { + from.CloseGump(); + from.CloseGump(); + from.SendGump(new PickRulesetGump(from, null, Tournament.Ruleset)); + } + } + + public override void Serialize(GenericWriter writer) + { + base.Serialize(writer); + + writer.Write(0); + + Tournament.Serialize(writer); + } + + public override void Deserialize(GenericReader reader) + { + base.Deserialize(reader); + + int version = reader.ReadInt(); + + switch (version) + { + case 0: + { + Tournament = new Tournament(reader); + break; + } + } + + m_Instances.Add(this); + } + + public override void OnDelete() + { + base.OnDelete(); + + m_Instances.Remove(this); + } + + private class EditEntry : ContextMenuEntry + { + private Tournament m_Tournament; + + public EditEntry(Tournament tourney) : base(5101) + { + m_Tournament = tourney; + } + + public override void OnClick() + { + Owner.From.SendGump(new PropertiesGump(Owner.From, m_Tournament)); + } + } + + private class StartEntry : ContextMenuEntry + { + private Tournament m_Tournament; + + public StartEntry(Tournament tourney) : base(5113) + { + m_Tournament = tourney; + } + + public override void OnClick() + { + if (m_Tournament.Stage == TournamentStage.Inactive) + { + m_Tournament.SignupStart = DateTime.UtcNow; + m_Tournament.Stage = TournamentStage.Signup; + m_Tournament.Participants.Clear(); + m_Tournament.Pyramid.Levels.Clear(); + m_Tournament.Alert("Hear ye! Hear ye!", + "Tournament signup has opened. You can enter by signing up with the registrar."); + } + } + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/TournamentPyramid.cs b/Scripts/Engines/ConPVP/TournamentPyramid.cs new file mode 100644 index 000000000..520e4a3f0 --- /dev/null +++ b/Scripts/Engines/ConPVP/TournamentPyramid.cs @@ -0,0 +1,189 @@ +using System.Collections.Generic; +using Server.Ethics; +using Server.Factions; + +namespace Server.Engines.ConPVP +{ + public class TourneyPyramid + { + public TourneyPyramid() + { + Levels = new List(); + } + + public List Levels{ get; set; } + + public void AddLevel(int partsPerMatch, List participants, GroupingType groupType, TourneyType tourneyType) + { + List copy = new List(participants); + + if (groupType == GroupingType.Nearest || groupType == GroupingType.HighVsLow) + copy.Sort(); + + PyramidLevel level = new PyramidLevel(); + + switch (tourneyType) + { + case TourneyType.RedVsBlue: + { + TourneyParticipant[] parts = new TourneyParticipant[2]; + + for (int i = 0; i < parts.Length; ++i) + parts[i] = new TourneyParticipant(new List()); + + for (int i = 0; i < copy.Count; ++i) + { + List players = copy[i].Players; + + for (int j = 0; j < players.Count; ++j) + { + Mobile mob = players[j]; + + if (mob.Kills >= 5) + parts[0].Players.Add(mob); + else + parts[1].Players.Add(mob); + } + } + + level.Matches.Add(new TourneyMatch(new List(parts))); + break; + } + case TourneyType.Faction: + { + TourneyParticipant[] parts = new TourneyParticipant[partsPerMatch]; + + for (int i = 0; i < parts.Length; ++i) + parts[i] = new TourneyParticipant(new List()); + + for (int i = 0; i < copy.Count; ++i) + { + List players = copy[i].Players; + + for (int j = 0; j < players.Count; ++j) + { + Mobile mob = players[j]; + + int index = -1; + + if (partsPerMatch == 4) + { + Faction fac = Faction.Find(mob); + + if (fac != null) index = fac.Definition.Sort; + } + else if (partsPerMatch == 2) + { + if (Ethic.Evil.IsEligible(mob)) + index = 0; + else if (Ethic.Hero.IsEligible(mob)) index = 1; + } + + if (index < 0 || index >= partsPerMatch) index = i % partsPerMatch; + + parts[index].Players.Add(mob); + } + } + + level.Matches.Add(new TourneyMatch(new List(parts))); + break; + } + case TourneyType.RandomTeam: + { + TourneyParticipant[] parts = new TourneyParticipant[partsPerMatch]; + + for (int i = 0; i < partsPerMatch; ++i) + parts[i] = new TourneyParticipant(new List()); + + for (int i = 0; i < copy.Count; ++i) + parts[i % parts.Length].Players.AddRange(copy[i].Players); + + level.Matches.Add(new TourneyMatch(new List(parts))); + break; + } + case TourneyType.FreeForAll: + { + level.Matches.Add(new TourneyMatch(copy)); + break; + } + case TourneyType.Standard: + { + if (partsPerMatch >= 2 && participants.Count % partsPerMatch == 1) + { + int lowAdvances = int.MaxValue; + + for (int i = 0; i < participants.Count; ++i) + { + TourneyParticipant p = participants[i]; + + if (p.FreeAdvances < lowAdvances) + lowAdvances = p.FreeAdvances; + } + + List toAdvance = new List(); + + for (int i = 0; i < participants.Count; ++i) + { + TourneyParticipant p = participants[i]; + + if (p.FreeAdvances == lowAdvances) + toAdvance.Add(p); + } + + if (toAdvance.Count == 0) + toAdvance = copy; // sanity + + int idx = Utility.Random(toAdvance.Count); + + toAdvance[idx].AddLog( + "Advanced automatically due to an odd number of challengers."); + level.FreeAdvance = toAdvance[idx]; + ++level.FreeAdvance.FreeAdvances; + copy.Remove(toAdvance[idx]); + } + + while (copy.Count >= partsPerMatch) + { + List thisMatch = new List(); + + for (int i = 0; i < partsPerMatch; ++i) + { + int idx = 0; + + switch (groupType) + { + case GroupingType.HighVsLow: + idx = i * (copy.Count - 1) / (partsPerMatch - 1); + break; + case GroupingType.Nearest: + idx = 0; + break; + case GroupingType.Random: + idx = Utility.Random(copy.Count); + break; + } + + thisMatch.Add(copy[idx]); + copy.RemoveAt(idx); + } + + level.Matches.Add(new TourneyMatch(thisMatch)); + } + + if (copy.Count > 1) + level.Matches.Add(new TourneyMatch(copy)); + + break; + } + } + + Levels.Add(level); + } + } + + public class PyramidLevel + { + public List Matches{ get; set; } = new List(); + public TourneyParticipant FreeAdvance{ get; set; } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/TournamentRegistrar.cs b/Scripts/Engines/ConPVP/TournamentRegistrar.cs new file mode 100644 index 000000000..562d7cccf --- /dev/null +++ b/Scripts/Engines/ConPVP/TournamentRegistrar.cs @@ -0,0 +1,93 @@ +using System; +using Server.Factions; +using Server.Mobiles; +using Server.Network; + +namespace Server.Engines.ConPVP +{ +public class TournamentRegistrar : Banker + { + [Constructible] + public TournamentRegistrar() + { + Timer.DelayCall(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), Announce_Callback); + } + + public TournamentRegistrar(Serial serial) : base(serial) + { + } + + [CommandProperty(AccessLevel.GameMaster)] + public TournamentController Tournament{ get; set; } + + private void Announce_Callback() + { + Tournament tourney = Tournament?.Tournament; + + if (tourney?.Stage == TournamentStage.Signup) + PublicOverheadMessage(MessageType.Regular, 0x35, false, + "Come one, come all! Do you aspire to be a fighter of great renown? Join this tournament and show the world your abilities."); + } + + public override void OnMovement(Mobile m, Point3D oldLocation) + { + base.OnMovement(m, oldLocation); + + Tournament tourney = Tournament?.Tournament; + + if (InRange(m, 4) && !InRange(oldLocation, 4) && tourney != null && tourney.Stage == TournamentStage.Signup && + m.CanBeginAction(this)) + { + Ladder ladder = Ladder.Instance; + + LadderEntry entry = ladder?.Find(m); + + if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement) + return; + + if (tourney.IsFactionRestricted && Faction.Find(m) == null) return; + + if (tourney.HasParticipant(m)) + return; + + PrivateOverheadMessage(MessageType.Regular, 0x35, false, + $"Hello m'{(m.Female ? "Lady" : "Lord")}. Dost thou wish to enter this tournament? You need only to write your name in this book.", + m.NetState); + m.BeginAction(this); + Timer.DelayCall(TimeSpan.FromSeconds(10.0), ReleaseLock_Callback, m); + } + } + + public void ReleaseLock_Callback(Mobile m) + { + m.EndAction(this); + } + + public override void Serialize(GenericWriter writer) + { + base.Serialize(writer); + + writer.Write(0); + + writer.Write(Tournament); + } + + public override void Deserialize(GenericReader reader) + { + base.Deserialize(reader); + + int version = reader.ReadInt(); + + switch (version) + { + case 0: + { + Tournament = reader.ReadItem() as TournamentController; + break; + } + } + + Timer.DelayCall(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), Announce_Callback); + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/TournamentSignupItem.cs b/Scripts/Engines/ConPVP/TournamentSignupItem.cs new file mode 100644 index 000000000..b03dbefaf --- /dev/null +++ b/Scripts/Engines/ConPVP/TournamentSignupItem.cs @@ -0,0 +1,149 @@ +using System.Collections.Generic; +using Server.Factions; +using Server.Mobiles; +using Server.Network; + +namespace Server.Engines.ConPVP +{ +public class TournamentSignupItem : Item + { + [Constructible] + public TournamentSignupItem() : base(4029) + { + Movable = false; + } + + public TournamentSignupItem(Serial serial) : base(serial) + { + } + + [CommandProperty(AccessLevel.GameMaster)] + public TournamentController Tournament{ get; set; } + + [CommandProperty(AccessLevel.GameMaster)] + public Mobile Registrar{ get; set; } + + public override string DefaultName => "tournament signup book"; + + public override void OnDoubleClick(Mobile from) + { + if (!from.InRange(GetWorldLocation(), 2)) + { + from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that + } + else + { + Tournament tourney = Tournament?.Tournament; + + if (tourney == null) + return; + + if (Registrar != null) + Registrar.Direction = Registrar.GetDirectionTo(this); + + switch (tourney.Stage) + { + case TournamentStage.Fighting: + { + if (Registrar != null) + { + if (tourney.HasParticipant(from)) + Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "Excuse me? You are already signed up.", from.NetState); + else + Registrar.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "The tournament has already begun. You are too late to signup now.", + from.NetState); + } + + break; + } + case TournamentStage.Inactive: + { + Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "The tournament is closed.", from.NetState); + + break; + } + case TournamentStage.Signup: + { + Ladder ladder = Ladder.Instance; + LadderEntry entry = ladder?.Find(from); + + if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement) + { + Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "You have not yet proven yourself a worthy dueler.", from.NetState); + + break; + } + + if (tourney.IsFactionRestricted && Faction.Find(from) == null) + { + Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "Only those who have declared their faction allegiance may participate.", + from.NetState); + + break; + } + + if (from.HasGump()) + { + Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "You must first respond to the offer I've given you.", from.NetState); + } + else if (from.HasGump()) + { + Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "You must first cancel your duel offer.", from.NetState); + } + else if (from is PlayerMobile mobile && mobile.DuelContext != null) + { + Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x22, false, "You are already participating in a duel.", mobile.NetState); + } + else if (!tourney.HasParticipant(from)) + { + from.CloseGump(); + from.SendGump(new ConfirmSignupGump(from, Registrar, tourney, new List { from })); + } + else + { + Registrar?.PrivateOverheadMessage(MessageType.Regular, + 0x35, false, "You have already entered this tournament.", from.NetState); + } + + break; + } + } + } + } + + public override void Serialize(GenericWriter writer) + { + base.Serialize(writer); + + writer.Write(0); + + writer.Write(Tournament); + writer.Write(Registrar); + } + + public override void Deserialize(GenericReader reader) + { + base.Deserialize(reader); + + int version = reader.ReadInt(); + + switch (version) + { + case 0: + { + Tournament = reader.ReadItem() as TournamentController; + Registrar = reader.ReadMobile(); + break; + } + } + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/ConPVP/TourneyParticipant.cs b/Scripts/Engines/ConPVP/TourneyParticipant.cs new file mode 100644 index 000000000..bcd77cbd1 --- /dev/null +++ b/Scripts/Engines/ConPVP/TourneyParticipant.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Server.Engines.ConPVP +{ + public class TourneyParticipant : IComparable + { + public TourneyParticipant(Mobile owner) + { + Log = new List(); + Players = new List { owner }; + } + + public TourneyParticipant(List players) + { + Log = new List(); + Players = players; + } + + public List Players{ get; set; } + + public List Log{ get; set; } + + public int FreeAdvances{ get; set; } + + public int TotalLadderXP + { + get + { + Ladder ladder = Ladder.Instance; + + if (ladder == null) + return 0; + + int total = 0; + + for (int i = 0; i < Players.Count; ++i) + { + Mobile mob = Players[i]; + LadderEntry entry = ladder.Find(mob); + + if (entry != null) + total += entry.Experience; + } + + return total; + } + } + + public string NameList + { + get + { + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < Players.Count; ++i) + { + if (Players[i] == null) + continue; + + Mobile mob = Players[i]; + + if (sb.Length > 0) + { + if (Players.Count == 2) + sb.Append(" and "); + else if (i + 1 < Players.Count) + sb.Append(", "); + else + sb.Append(", and "); + } + + sb.Append(mob.Name); + } + + if (sb.Length == 0) + return "Empty"; + + return sb.ToString(); + } + } + + public int CompareTo(TourneyParticipant p) + { + return p.TotalLadderXP - TotalLadderXP; + } + + public void AddLog(string text) + { + Log.Add(text); + } + + public void AddLog(string format, params object[] args) + { + AddLog(string.Format(format, args)); + } + + public void WonMatch(TourneyMatch match) + { + AddLog("Match won."); + } + + public void LostMatch(TourneyMatch match) + { + AddLog("Match lost."); + } + } +} \ No newline at end of file diff --git a/Scripts/Engines/Craft/Core/CraftGump.cs b/Scripts/Engines/Craft/Core/CraftGump.cs index dda11c379..929bd3ccf 100644 --- a/Scripts/Engines/Craft/Core/CraftGump.cs +++ b/Scripts/Engines/Craft/Core/CraftGump.cs @@ -35,8 +35,8 @@ namespace Server.Engines.Craft CraftContext context = craftSystem.GetContext(from); - from.CloseGump(typeof(CraftGump)); - from.CloseGump(typeof(CraftGumpItem)); + from.CloseGump(); + from.CloseGump(); AddPage(0); @@ -125,7 +125,7 @@ namespace Server.Engines.Craft if (from.Backpack != null) { - Item[] items = from.Backpack.FindItemsByType(resourceType, true); + Item[] items = from.Backpack.FindItemsByType(resourceType); for (int i = 0; i < items.Length; ++i) resourceCount += items[i].Amount; @@ -163,7 +163,7 @@ namespace Server.Engines.Craft if (from.Backpack != null) { - Item[] items = from.Backpack.FindItemsByType(resourceType, true); + Item[] items = from.Backpack.FindItemsByType(resourceType); for (int i = 0; i < items.Length; ++i) resourceCount += items[i].Amount; @@ -219,7 +219,7 @@ namespace Server.Engines.Craft if (from.Backpack != null) { - Item[] items = from.Backpack.FindItemsByType(subResource.ItemType, true); + Item[] items = from.Backpack.FindItemsByType(subResource.ItemType); for (int j = 0; j < items.Length; ++j) resourceCount += items[j].Amount; @@ -471,8 +471,6 @@ namespace Server.Engines.Craft { if (m_Page == CraftPage.PickResource && index >= 0 && index < system.CraftSubRes.Count) { - int groupIndex = context?.LastGroupIndex ?? -1; - CraftSubRes res = system.CraftSubRes.GetAt(index); if (m_From.Skills[system.MainSkill].Base < res.RequiredSkill) @@ -489,8 +487,6 @@ namespace Server.Engines.Craft } else if (m_Page == CraftPage.PickResource2 && index >= 0 && index < system.CraftSubRes2.Count) { - int groupIndex = context?.LastGroupIndex ?? -1; - CraftSubRes res = system.CraftSubRes2.GetAt(index); if (m_From.Skills[system.MainSkill].Base < res.RequiredSkill) diff --git a/Scripts/Engines/Craft/Core/CraftGumpItem.cs b/Scripts/Engines/Craft/Core/CraftGumpItem.cs index 7acc3ebf8..af0d39317 100644 --- a/Scripts/Engines/Craft/Core/CraftGumpItem.cs +++ b/Scripts/Engines/Craft/Core/CraftGumpItem.cs @@ -34,8 +34,8 @@ namespace Server.Engines.Craft m_CraftItem = craftItem; m_Tool = tool; - from.CloseGump(typeof(CraftGump)); - from.CloseGump(typeof(CraftGumpItem)); + from.CloseGump(); + from.CloseGump(); AddPage(0); AddBackground(0, 0, 530, 417, 5054); @@ -143,7 +143,7 @@ namespace Server.Engines.Craft for (int i = 0; i < m_CraftItem.Skills.Count; i++) { CraftSkill skill = m_CraftItem.Skills.GetAt(i); - double minSkill = skill.MinSkill, maxSkill = skill.MaxSkill; + double minSkill = skill.MinSkill; if (minSkill < 0) minSkill = 0; diff --git a/Scripts/Engines/Craft/Core/CraftItem.cs b/Scripts/Engines/Craft/Core/CraftItem.cs index 8ad9a8236..db10e6355 100644 --- a/Scripts/Engines/Craft/Core/CraftItem.cs +++ b/Scripts/Engines/Craft/Core/CraftItem.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Commands; using Server.Factions; using Server.Items; @@ -142,6 +141,7 @@ namespace Server.Engines.Craft } catch { + // ignored } if (item != null) @@ -177,9 +177,9 @@ namespace Server.Engines.Craft public bool ConsumeAttributes(Mobile from, ref object message, bool consume) { - bool consumMana = false; - bool consumHits = false; - bool consumStam = false; + bool consumMana; + bool consumHits; + bool consumStam; if (Hits > 0 && from.Hits < Hits) { @@ -755,7 +755,7 @@ namespace Server.Engines.Craft public void Craft(Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool) { - if (from.BeginAction(typeof(CraftSystem))) + if (from.BeginAction()) { if (RequiredExpansion == Expansion.None || from.NetState != null && from.NetState.SupportsExpansion(RequiredExpansion)) @@ -794,39 +794,39 @@ namespace Server.Engines.Craft } else { - from.EndAction(typeof(CraftSystem)); + from.EndAction(); from.SendGump(new CraftGump(from, craftSystem, tool, message)); } } else { - from.EndAction(typeof(CraftSystem)); + from.EndAction(); from.SendGump(new CraftGump(from, craftSystem, tool, message)); } } else { - from.EndAction(typeof(CraftSystem)); + from.EndAction(); from.SendGump(new CraftGump(from, craftSystem, tool, badCraft)); } } else { - from.EndAction(typeof(CraftSystem)); + from.EndAction(); from.SendGump(new CraftGump(from, craftSystem, tool, 1072847)); // You must learn that recipe from a scroll. } } else { - from.EndAction(typeof(CraftSystem)); + from.EndAction(); from.SendGump(new CraftGump(from, craftSystem, tool, 1044153)); // You don't have the required skills to attempt this item. } } else { - from.EndAction(typeof(CraftSystem)); + from.EndAction(); from.SendGump(new CraftGump(from, craftSystem, tool, RequiredExpansionMessage(RequiredExpansion))); //The {0} expansion is required to attempt this item. } @@ -1098,7 +1098,7 @@ namespace Server.Engines.Craft } else { - m_From.EndAction(typeof(CraftSystem)); + m_From.EndAction(); int badCraft = m_CraftSystem.CanCraft(m_From, m_Tool, m_CraftItem.ItemType); diff --git a/Scripts/Engines/Craft/Core/Enhance.cs b/Scripts/Engines/Craft/Core/Enhance.cs index 7be1b7cfe..95969b93d 100644 --- a/Scripts/Engines/Craft/Core/Enhance.cs +++ b/Scripts/Engines/Craft/Core/Enhance.cs @@ -80,18 +80,18 @@ namespace Server.Engines.Craft } int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0; - int dura = 0, luck = 0, lreq = 0, dinc = 0; - int baseChance = 0; + int dura, luck, lreq, dinc = 0; + int baseChance; bool physBonus = false; - bool fireBonus = false; - bool coldBonus = false; - bool nrgyBonus = false; - bool poisBonus = false; - bool duraBonus = false; - bool luckBonus = false; - bool lreqBonus = false; - bool dincBonus = false; + bool fireBonus; + bool coldBonus; + bool nrgyBonus; + bool poisBonus; + bool duraBonus; + bool luckBonus; + bool lreqBonus; + bool dincBonus; if (item is BaseWeapon weapon) { diff --git a/Scripts/Engines/Craft/Core/QueryMakersMarkGump.cs b/Scripts/Engines/Craft/Core/QueryMakersMarkGump.cs index 3a76d1d0a..2330b23e5 100644 --- a/Scripts/Engines/Craft/Core/QueryMakersMarkGump.cs +++ b/Scripts/Engines/Craft/Core/QueryMakersMarkGump.cs @@ -17,7 +17,7 @@ namespace Server.Engines.Craft public QueryMakersMarkGump(int quality, Mobile from, CraftItem craftItem, CraftSystem craftSystem, Type typeRes, BaseTool tool) : base(100, 200) { - from.CloseGump(typeof(QueryMakersMarkGump)); + from.CloseGump(); m_Quality = quality; m_From = from; diff --git a/Scripts/Engines/Craft/Core/Recipes.cs b/Scripts/Engines/Craft/Core/Recipes.cs index 8ee5d1034..cba5b4fc8 100644 --- a/Scripts/Engines/Craft/Core/Recipes.cs +++ b/Scripts/Engines/Craft/Core/Recipes.cs @@ -56,7 +56,7 @@ namespace Server.Engines.Craft private static void LearnAllRecipes_OnCommand(CommandEventArgs e) { Mobile m = e.Mobile; - m.SendMessage("Target a player to teach them all of the recipies."); + m.SendMessage("Target a player to teach them all of the recipes."); m.BeginTarget(-1, false, TargetFlags.None, delegate(Mobile from, object targeted) { @@ -65,7 +65,7 @@ namespace Server.Engines.Craft foreach (KeyValuePair kvp in Recipes) mobile.AcquireRecipe(kvp.Key); - m.SendMessage("You teach them all of the recipies."); + m.SendMessage("You teach them all of the recipes."); } else { @@ -75,11 +75,11 @@ namespace Server.Engines.Craft } [Usage("ForgetAllRecipes")] - [Description("Makes a player forget all the recipies they've learned.")] + [Description("Makes a player forget all the recipes they've learned.")] private static void ForgetAllRecipes_OnCommand(CommandEventArgs e) { Mobile m = e.Mobile; - m.SendMessage("Target a player to have them forget all of the recipies they've learned."); + m.SendMessage("Target a player to have them forget all of the recipes they've learned."); m.BeginTarget(-1, false, TargetFlags.None, delegate(Mobile from, object targeted) { @@ -87,7 +87,7 @@ namespace Server.Engines.Craft { mobile.ResetRecipes(); - m.SendMessage("They forget all their recipies."); + m.SendMessage("They forget all their recipes."); } else { diff --git a/Scripts/Engines/Craft/Core/Repair.cs b/Scripts/Engines/Craft/Core/Repair.cs index f71d91249..e27aba97a 100644 --- a/Scripts/Engines/Craft/Core/Repair.cs +++ b/Scripts/Engines/Craft/Core/Repair.cs @@ -37,11 +37,6 @@ namespace Server.Engines.Craft m_Deed = deed; } - private static void EndGolemRepair(object state) - { - ((Mobile)state).EndAction(typeof(Golem)); - } - private int GetWeakenChance(Mobile mob, SkillName skill, int curHits, int maxHits) { // 40% - (1% per hp lost) - (1% per 10 craft skill) @@ -229,14 +224,14 @@ namespace Server.Engines.Craft } else { - double skillValue = usingDeed ? m_Deed.SkillLevel : from.Skills[SkillName.Tinkering].Value; + double skillValue = usingDeed ? m_Deed.SkillLevel : from.Skills.Tinkering.Value; if (skillValue < 60.0) { number = 1044153; // You don't have the required skills to attempt this item. //TODO: How does OSI handle this with deeds with golems? } - else if (!from.CanBeginAction(typeof(Golem))) + else if (!from.CanBeginAction()) { number = 501789; // You must wait before trying again. } @@ -263,9 +258,8 @@ namespace Server.Engines.Craft number = 1044279; // You repair the item. toDelete = true; - from.BeginAction(typeof(Golem)); - Timer.DelayCall(TimeSpan.FromSeconds(12.0), new TimerStateCallback(EndGolemRepair), - from); + from.BeginAction(); + Timer.DelayCall(TimeSpan.FromSeconds(12.0), from.EndAction); } else { diff --git a/Scripts/Engines/Craft/Core/Resmelt.cs b/Scripts/Engines/Craft/Core/Resmelt.cs index 28812e68a..3fffe268e 100644 --- a/Scripts/Engines/Craft/Core/Resmelt.cs +++ b/Scripts/Engines/Craft/Core/Resmelt.cs @@ -95,7 +95,7 @@ namespace Server.Engines.Craft break; } - if (difficulty > from.Skills[SkillName.Mining].Value) + if (difficulty > from.Skills.Mining.Value) return SmeltResult.NoSkill; Type resourceType = info.ResourceTypes[0]; @@ -130,9 +130,7 @@ namespace Server.Engines.Craft { if (num == 1044267) { - bool anvil, forge; - - DefBlacksmithy.CheckAnvilAndForge(from, 2, out anvil, out forge); + DefBlacksmithy.CheckAnvilAndForge(from, 2, out bool anvil, out bool forge); if (!anvil) num = 1044266; // You must be near an anvil diff --git a/Scripts/Engines/Craft/DefAlchemy.cs b/Scripts/Engines/Craft/DefAlchemy.cs index 6ac3c1ff2..a339df268 100644 --- a/Scripts/Engines/Craft/DefAlchemy.cs +++ b/Scripts/Engines/Craft/DefAlchemy.cs @@ -84,7 +84,7 @@ namespace Server.Engines.Craft public override void InitCraftList() { - int index = -1; + int index; // Refresh Potion index = AddCraft(typeof(RefreshPotion), 1044530, 1044538, -25, 25.0, typeof(BlackPearl), 1044353, 1, 1044361); diff --git a/Scripts/Engines/Craft/DefBlacksmithy.cs b/Scripts/Engines/Craft/DefBlacksmithy.cs index f99e59af1..24b347ee1 100644 --- a/Scripts/Engines/Craft/DefBlacksmithy.cs +++ b/Scripts/Engines/Craft/DefBlacksmithy.cs @@ -118,8 +118,7 @@ namespace Server.Engines.Craft if (!BaseTool.CheckAccessible(tool, from)) return 1044263; // The tool must be on your person to use. - bool anvil, forge; - CheckAnvilAndForge(from, 2, out anvil, out forge); + CheckAnvilAndForge(from, 2, out bool anvil, out bool forge); if (anvil && forge) return 0; diff --git a/Scripts/Engines/Craft/DefBowFletching.cs b/Scripts/Engines/Craft/DefBowFletching.cs index 52c3c371f..e64f7bf0f 100644 --- a/Scripts/Engines/Craft/DefBowFletching.cs +++ b/Scripts/Engines/Craft/DefBowFletching.cs @@ -76,7 +76,7 @@ namespace Server.Engines.Craft public override void InitCraftList() { - int index = -1; + int index; // Materials AddCraft(typeof(Kindling), 1044457, 1023553, 0.0, 00.0, typeof(Log), 1044041, 1, 1044351); diff --git a/Scripts/Engines/Craft/DefCooking.cs b/Scripts/Engines/Craft/DefCooking.cs index c6751b967..aa5ccb59e 100644 --- a/Scripts/Engines/Craft/DefCooking.cs +++ b/Scripts/Engines/Craft/DefCooking.cs @@ -71,7 +71,7 @@ namespace Server.Engines.Craft public override void InitCraftList() { - int index = -1; + int index; /* Begin Ingredients */ index = AddCraft(typeof(SackFlour), 1044495, 1024153, 0.0, 100.0, typeof(WheatSheaf), 1044489, 2, 1044490); diff --git a/Scripts/Engines/Craft/DefGlassblowing.cs b/Scripts/Engines/Craft/DefGlassblowing.cs index 0ba7a8040..dd0e803b6 100644 --- a/Scripts/Engines/Craft/DefGlassblowing.cs +++ b/Scripts/Engines/Craft/DefGlassblowing.cs @@ -41,14 +41,12 @@ namespace Server.Engines.Craft return 1044038; // You have worn out your tool! if (!BaseTool.CheckTool(tool, from)) return 1048146; // If you have a tool equipped, you must use that tool. - if (!(from is PlayerMobile mobile && mobile.Glassblowing && mobile.Skills[SkillName.Alchemy].Base >= 100.0)) + if (!(from is PlayerMobile mobile && mobile.Glassblowing && mobile.Skills.Alchemy.Base >= 100.0)) return 1044634; // You havent learned glassblowing. if (!BaseTool.CheckAccessible(tool, from)) return 1044263; // The tool must be on your person to use. - bool anvil, forge; - - DefBlacksmithy.CheckAnvilAndForge(from, 2, out anvil, out forge); + DefBlacksmithy.CheckAnvilAndForge(from, 2, out _, out bool forge); if (forge) return 0; diff --git a/Scripts/Engines/Craft/DefMasonry.cs b/Scripts/Engines/Craft/DefMasonry.cs index 44d9d83e4..4825822a9 100644 --- a/Scripts/Engines/Craft/DefMasonry.cs +++ b/Scripts/Engines/Craft/DefMasonry.cs @@ -43,7 +43,7 @@ namespace Server.Engines.Craft return 1044038; // You have worn out your tool! if (!BaseTool.CheckTool(tool, from)) return 1048146; // If you have a tool equipped, you must use that tool. - if (!(from is PlayerMobile mobile && mobile.Masonry && mobile.Skills[SkillName.Carpentry].Base >= 100.0)) + if (!(from is PlayerMobile mobile && mobile.Masonry && mobile.Skills.Carpentry.Base >= 100.0)) return 1044633; // You havent learned stonecraft. if (!BaseTool.CheckAccessible(tool, from)) return 1044263; // The tool must be on your person to use. diff --git a/Scripts/Engines/Craft/DefTailoring.cs b/Scripts/Engines/Craft/DefTailoring.cs index 86b335a8a..355dcf723 100644 --- a/Scripts/Engines/Craft/DefTailoring.cs +++ b/Scripts/Engines/Craft/DefTailoring.cs @@ -95,7 +95,7 @@ namespace Server.Engines.Craft public override void InitCraftList() { - int index = -1; + int index; #region Hats diff --git a/Scripts/Engines/Craft/DefTinkering.cs b/Scripts/Engines/Craft/DefTinkering.cs index 5ac122fa3..2f20ea63b 100644 --- a/Scripts/Engines/Craft/DefTinkering.cs +++ b/Scripts/Engines/Craft/DefTinkering.cs @@ -146,7 +146,7 @@ namespace Server.Engines.Craft public override void InitCraftList() { - int index = -1; + int index; #region Wooden Items @@ -489,9 +489,7 @@ namespace Server.Engines.Craft protected override void OnTarget(Mobile from, object targeted) { - int message; - - if (m_TrapCraft.Acquire(targeted, out message)) + if (m_TrapCraft.Acquire(targeted, out int message)) m_TrapCraft.CraftItem.CompleteCraft(m_TrapCraft.Quality, false, m_TrapCraft.From, m_TrapCraft.CraftSystem, m_TrapCraft.TypeRes, m_TrapCraft.Tool, m_TrapCraft); else diff --git a/Scripts/Engines/Doom/GauntletSpawner.cs b/Scripts/Engines/Doom/GauntletSpawner.cs index c146d307a..5c231bc59 100644 --- a/Scripts/Engines/Doom/GauntletSpawner.cs +++ b/Scripts/Engines/Doom/GauntletSpawner.cs @@ -205,7 +205,7 @@ namespace Server.Engines.Doom if (map == null) return; - BaseTrap trap = null; + BaseTrap trap; int random = Utility.Random(100); @@ -324,6 +324,7 @@ namespace Server.Engines.Doom } catch { + // ignored } } @@ -409,9 +410,7 @@ namespace Server.Engines.Doom TypeName = reader.ReadString(); Door = reader.ReadItem(); - ; Addon = reader.ReadItem(); - ; Sequence = reader.ReadItem(); State = (GauntletSpawnerState)reader.ReadInt(); diff --git a/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs b/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs index 2c555c966..cf45b0a6f 100644 --- a/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs +++ b/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs @@ -521,7 +521,7 @@ namespace Server.Engines.Doom protected override void OnTick() { - if (m_Player == null || !(m_Player.Map == Map.Malas)) + if (m_Player == null || m_Player.Map != Map.Malas) { Stop(); } diff --git a/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleItems.cs b/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleItems.cs index 76e3dbfd9..95aff9979 100644 --- a/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleItems.cs +++ b/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleItems.cs @@ -128,7 +128,7 @@ namespace Server.Engines.Doom } else { - m.SendLocalizedMessage(1060001); // You throw the switch, but the mechanism cannot be engaged again so soon. + m?.SendLocalizedMessage(1060001); // You throw the switch, but the mechanism cannot be engaged again so soon. } } diff --git a/Scripts/Engines/Ethics/Evil/Powers/Blight.cs b/Scripts/Engines/Ethics/Evil/Powers/Blight.cs index e23350625..948794aa5 100644 --- a/Scripts/Engines/Ethics/Evil/Powers/Blight.cs +++ b/Scripts/Engines/Ethics/Evil/Powers/Blight.cs @@ -19,14 +19,12 @@ namespace Server.Ethics.Evil public override void BeginInvoke(Player from) { - from.Mobile.BeginTarget(12, true, TargetFlags.None, new TargetStateCallback(Power_OnTarget), from); + from.Mobile.BeginTarget(12, true, TargetFlags.None, Power_OnTarget, from); from.Mobile.SendMessage("Where do you wish to blight?"); } - private void Power_OnTarget(Mobile fromMobile, object obj, object state) + private void Power_OnTarget(Mobile fromMobile, object obj, Player from) { - Player from = state as Player; - if (!(obj is IPoint3D p)) return; diff --git a/Scripts/Engines/Ethics/Evil/Powers/UnholyItem.cs b/Scripts/Engines/Ethics/Evil/Powers/UnholyItem.cs index a161b9338..d25c99861 100644 --- a/Scripts/Engines/Ethics/Evil/Powers/UnholyItem.cs +++ b/Scripts/Engines/Ethics/Evil/Powers/UnholyItem.cs @@ -18,15 +18,12 @@ namespace Server.Ethics.Evil public override void BeginInvoke(Player from) { - from.Mobile.BeginTarget(12, false, TargetFlags.None, new TargetStateCallback(Power_OnTarget), from); + from.Mobile.BeginTarget(12, false, TargetFlags.None, Power_OnTarget, from); from.Mobile.SendMessage("Which item do you wish to imbue?"); } - private void Power_OnTarget(Mobile fromMobile, object obj, object state) + private void Power_OnTarget(Mobile fromMobile, object obj, Player from) { - if (!(state is Player from)) - return; - if (!(obj is Item item)) { from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You may not imbue that."); diff --git a/Scripts/Engines/Ethics/Hero/Powers/Bless.cs b/Scripts/Engines/Ethics/Hero/Powers/Bless.cs index cfad8bd99..c9bc49b5c 100644 --- a/Scripts/Engines/Ethics/Hero/Powers/Bless.cs +++ b/Scripts/Engines/Ethics/Hero/Powers/Bless.cs @@ -19,15 +19,12 @@ namespace Server.Ethics.Hero public override void BeginInvoke(Player from) { - from.Mobile.BeginTarget(12, true, TargetFlags.None, new TargetStateCallback(Power_OnTarget), from); + from.Mobile.BeginTarget(12, true, TargetFlags.None, Power_OnTarget, from); from.Mobile.SendMessage("Where do you wish to bless?"); } - private void Power_OnTarget(Mobile fromMobile, object obj, object state) + private void Power_OnTarget(Mobile fromMobile, object obj, Player from) { - if (!(state is Player from)) - return; - if (!(obj is IPoint3D p)) return; diff --git a/Scripts/Engines/Ethics/Hero/Powers/HolyItem.cs b/Scripts/Engines/Ethics/Hero/Powers/HolyItem.cs index 8b4f058f8..06f6b5707 100644 --- a/Scripts/Engines/Ethics/Hero/Powers/HolyItem.cs +++ b/Scripts/Engines/Ethics/Hero/Powers/HolyItem.cs @@ -18,15 +18,12 @@ namespace Server.Ethics.Hero public override void BeginInvoke(Player from) { - from.Mobile.BeginTarget(12, false, TargetFlags.None, new TargetStateCallback(Power_OnTarget), from); + from.Mobile.BeginTarget(12, false, TargetFlags.None, Power_OnTarget, from); from.Mobile.SendMessage("Which item do you wish to imbue?"); } - private void Power_OnTarget(Mobile fromMobile, object obj, object state) + private void Power_OnTarget(Mobile fromMobile, object obj, Player from) { - if (!(state is Player from)) - return; - if (!(obj is Item item)) { from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You may not imbue that."); diff --git a/Scripts/Engines/Factions/Core/Faction.cs b/Scripts/Engines/Factions/Core/Faction.cs index 2c4672dc5..9363b9f64 100644 --- a/Scripts/Engines/Factions/Core/Faction.cs +++ b/Scripts/Engines/Factions/Core/Faction.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using Server.Accounting; using Server.Commands; @@ -677,11 +676,11 @@ namespace Server.Factions public static void FactionItemReset_OnCommand(CommandEventArgs e) { - ArrayList pots = new ArrayList(); + List items = new List(); foreach (Item item in World.Items.Values) if (item is IFactionItem && !(item is HoodedShroudOfShadows)) - pots.Add(item); + items.Add(item); int[] hues = new int[Factions.Count * 2]; @@ -693,9 +692,9 @@ namespace Server.Factions int count = 0; - for (int i = 0; i < pots.Count; ++i) + for (int i = 0; i < items.Count; ++i) { - Item item = (Item)pots[i]; + Item item = items[i]; IFactionItem fci = (IFactionItem)item; if (fci.FactionItemState != null || item.LootType != LootType.Blessed) @@ -918,7 +917,7 @@ namespace Server.Factions if (smallest == null) return true; // sanity - if (StabilityFactor > 0 && (Members.Count + influx) * 100 / StabilityFactor > smallest.Members.Count) + if ((Members.Count + influx) * 100 / StabilityFactor > smallest.Members.Count) return false; return true; @@ -939,7 +938,7 @@ namespace Server.Factions return; } - if (killer.GetDistanceToSqrt(victim) > 64) + if (killer?.GetDistanceToSqrt(victim) > 64) { sigil.ReturnHome(); killer.SendLocalizedMessage(1042230); // The sigil has gone back to its home location. @@ -947,13 +946,13 @@ namespace Server.Factions else if (Sigil.ExistsOn(killer)) { sigil.ReturnHome(); - killer.SendLocalizedMessage( + killer?.SendLocalizedMessage( 1010258); // The sigil has gone back to its home location because you already have a sigil. } else if (!killerPack.TryDropItem(killer, sigil, false)) { sigil.ReturnHome(); - killer.SendLocalizedMessage(1010259); // The sigil has gone home because your backpack is full. + killer?.SendLocalizedMessage(1010259); // The sigil has gone home because your backpack is full. } }); @@ -998,7 +997,7 @@ namespace Server.Factions #region Dueling - if (victim.Region.IsPartOf(typeof(SafeZone))) + if (victim.Region.IsPartOf()) return; #endregion @@ -1231,12 +1230,7 @@ namespace Server.Factions } } - context.m_Timer = Timer.DelayCall(SkillLossPeriod, new TimerStateCallback(ClearSkillLoss_Callback), mob); - } - - private static void ClearSkillLoss_Callback(object state) - { - ClearSkillLoss((Mobile)state); + context.m_Timer = Timer.DelayCall(SkillLossPeriod, () => ClearSkillLoss(mob)); } public static bool ClearSkillLoss(Mobile mob) diff --git a/Scripts/Engines/Factions/Core/Keywords.cs b/Scripts/Engines/Factions/Core/Keywords.cs index 4dd124bd2..07f635afd 100644 --- a/Scripts/Engines/Factions/Core/Keywords.cs +++ b/Scripts/Engines/Factions/Core/Keywords.cs @@ -11,10 +11,8 @@ namespace Server.Factions EventSink.Speech += EventSink_Speech; } - private static void ShowScore_Sandbox(object state) + private static void ShowScore_Sandbox(PlayerState pl) { - PlayerState pl = (PlayerState)state; - pl?.Mobile.PublicOverheadMessage(MessageType.Regular, pl.Mobile.SpeechHue, true, pl.KillPoints.ToString("N0")); // NOTE: Added 'N0' } @@ -141,16 +139,13 @@ namespace Server.Factions PlayerState pl = PlayerState.Find(from); if (pl != null) - Timer.DelayCall(TimeSpan.Zero, new TimerStateCallback(ShowScore_Sandbox), pl); + Timer.DelayCall(TimeSpan.Zero, ShowScore_Sandbox, pl); break; } case 0x0178: // i honor your leadership { - Faction faction = Faction.Find(from); - - faction?.BeginHonorLeadership(from); - + Faction.Find(from)?.BeginHonorLeadership(from); break; } } diff --git a/Scripts/Engines/Factions/Core/Town.cs b/Scripts/Engines/Factions/Core/Town.cs index 0c094f070..da8a2365d 100644 --- a/Scripts/Engines/Factions/Core/Town.cs +++ b/Scripts/Engines/Factions/Core/Town.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using Server.Commands; using Server.Targeting; @@ -7,7 +6,7 @@ using Server.Targeting; namespace Server.Factions { [CustomEnum(new[] { "Britain", "Magincia", "Minoc", "Moonglow", "Skara Brae", "Trinsic", "Vesper", "Yew" })] - public abstract class Town : IComparable + public abstract class Town : IComparable, IComparable { public const int SilverCaptureBonus = 10000; @@ -133,6 +132,11 @@ namespace Server.Factions public static List Towns => Reflector.Towns; + public int CompareTo(Town other) + { + return Definition.Sort - other.Definition.Sort; + } + public int CompareTo(object obj) { return Definition.Sort - ((Town)obj).Definition.Sort; @@ -225,12 +229,12 @@ namespace Server.Factions if (Silver + flow < 0) { - ArrayList toDelete = BuildFinanceList(); + List toDelete = BuildFinanceList(); while (Silver + flow < 0 && toDelete.Count > 0) { int index = Utility.Random(toDelete.Count); - Mobile mob = (Mobile)toDelete[index]; + Mobile mob = toDelete[index]; mob.Delete(); @@ -242,19 +246,15 @@ namespace Server.Factions Silver += flow; } - public ArrayList BuildFinanceList() + public List BuildFinanceList() { - ArrayList list = new ArrayList(); + List list = new List(); - List vendorLists = VendorLists; + for (int i = 0; i < VendorLists.Count; ++i) + list.AddRange(VendorLists[i].Vendors); - for (int i = 0; i < vendorLists.Count; ++i) - list.AddRange(vendorLists[i].Vendors); - - List guardLists = GuardLists; - - for (int i = 0; i < guardLists.Count; ++i) - list.AddRange(guardLists[i].Guards); + for (int i = 0; i < GuardLists.Count; ++i) + list.AddRange(GuardLists[i].Guards); return list; } diff --git a/Scripts/Engines/Factions/Gumps/FactionGump.cs b/Scripts/Engines/Factions/Gumps/FactionGump.cs index 2e6d9b804..4a9911614 100644 --- a/Scripts/Engines/Factions/Gumps/FactionGump.cs +++ b/Scripts/Engines/Factions/Gumps/FactionGump.cs @@ -32,7 +32,7 @@ namespace Server.Factions public static bool Exists(Mobile mob) { - return mob.FindGump(typeof(FactionGump)) != null; + return mob.HasGump(); } public void AddHtmlText(int x, int y, int width, int height, TextDefinition text, bool back, bool scroll) diff --git a/Scripts/Engines/Factions/Gumps/FactionImbueGump.cs b/Scripts/Engines/Factions/Gumps/FactionImbueGump.cs index 896549c00..d712520e6 100644 --- a/Scripts/Engines/Factions/Gumps/FactionImbueGump.cs +++ b/Scripts/Engines/Factions/Gumps/FactionImbueGump.cs @@ -14,7 +14,6 @@ namespace Server.Factions private Item m_Item; private Mobile m_Mobile; private object m_Notice; - private int m_Quality; private BaseTool m_Tool; public FactionImbueGump(int quality, Item item, Mobile from, CraftSystem craftSystem, BaseTool tool, object notice, @@ -26,7 +25,6 @@ namespace Server.Factions m_CraftSystem = craftSystem; m_Tool = tool; m_Notice = notice; - m_Quality = quality; m_Definition = def; AddPage(0); @@ -38,7 +36,7 @@ namespace Server.Factions AddHtmlLocalized(20, 60, 170, 25, 1018302, false, false); // Item quality: - AddHtmlLocalized(175, 60, 100, 25, 1018305 - m_Quality, false, false); // Exceptional, Average, Low + AddHtmlLocalized(175, 60, 100, 25, 1018305 - quality, false, false); // Exceptional, Average, Low AddHtmlLocalized(20, 80, 170, 25, 1011572, false, false); // Item Cost : AddLabel(175, 80, 0x34, def.SilverCost.ToString("N0")); // NOTE: Added 'N0' diff --git a/Scripts/Engines/Factions/Gumps/FactionStoneGump.cs b/Scripts/Engines/Factions/Gumps/FactionStoneGump.cs index 49fb5fded..410ffc868 100644 --- a/Scripts/Engines/Factions/Gumps/FactionStoneGump.cs +++ b/Scripts/Engines/Factions/Gumps/FactionStoneGump.cs @@ -267,9 +267,7 @@ namespace Server.Factions public override void OnResponse(NetState sender, RelayInfo info) { - int type, index; - - if (!FromButtonID(info.ButtonID, out type, out index)) + if (!FromButtonID(info.ButtonID, out int type, out int index)) return; switch (type) diff --git a/Scripts/Engines/Factions/Gumps/FinanceGump.cs b/Scripts/Engines/Factions/Gumps/FinanceGump.cs index b4286d38b..8b37c80c2 100644 --- a/Scripts/Engines/Factions/Gumps/FinanceGump.cs +++ b/Scripts/Engines/Factions/Gumps/FinanceGump.cs @@ -190,9 +190,7 @@ namespace Server.Factions return; } - int type, index; - - if (!FromButtonID(info.ButtonID, out type, out index)) + if (!FromButtonID(info.ButtonID, out int type, out int index)) return; switch (type) @@ -259,8 +257,6 @@ namespace Server.Factions { VendorList vendorList = vendorLists[index]; - Town town = Town.FromRegion(m_From.Region); - if (Town.FromRegion(m_From.Region) != m_Town) { m_From.SendLocalizedMessage(1010305); // You must be in your controlled city to buy Items diff --git a/Scripts/Engines/Factions/Gumps/SheriffGump.cs b/Scripts/Engines/Factions/Gumps/SheriffGump.cs index c1ab3ed7d..ec8131e6e 100644 --- a/Scripts/Engines/Factions/Gumps/SheriffGump.cs +++ b/Scripts/Engines/Factions/Gumps/SheriffGump.cs @@ -153,7 +153,6 @@ namespace Server.Factions if (index >= 0 && index < m_Town.GuardLists.Count) { GuardList guardList = m_Town.GuardLists[index]; - Town town = Town.FromRegion(m_From.Region); if (Town.FromRegion(m_From.Region) != m_Town) { diff --git a/Scripts/Engines/Factions/Items/Power Faction Items/ClarityPotion.cs b/Scripts/Engines/Factions/Items/Power Faction Items/ClarityPotion.cs index d647c9361..30c1ffbaf 100644 --- a/Scripts/Engines/Factions/Items/Power Faction Items/ClarityPotion.cs +++ b/Scripts/Engines/Factions/Items/Power Faction Items/ClarityPotion.cs @@ -19,7 +19,7 @@ namespace Server public override bool Use(Mobile from) { - if (from.BeginAction(typeof(ClarityPotion))) + if (from.BeginAction()) { int amount = Utility.Dice(3, 3, 3); int time = Utility.RandomMinMax(5, 30); @@ -42,7 +42,7 @@ namespace Server from.PlaySound(0x1EE); from.AddStatMod(new StatMod(StatType.Int, "clarity-potion", amount, TimeSpan.FromMinutes(time))); - Timer.DelayCall(TimeSpan.FromMinutes(time), delegate { from.EndAction(typeof(ClarityPotion)); }); + Timer.DelayCall(TimeSpan.FromMinutes(time), delegate { from.EndAction(); }); return true; } diff --git a/Scripts/Engines/Factions/Items/Power Faction Items/PowerFactionItem.cs b/Scripts/Engines/Factions/Items/Power Faction Items/PowerFactionItem.cs index e794afd6c..600caeae0 100644 --- a/Scripts/Engines/Factions/Items/Power Faction Items/PowerFactionItem.cs +++ b/Scripts/Engines/Factions/Items/Power Faction Items/PowerFactionItem.cs @@ -72,6 +72,7 @@ namespace Server } catch { + // ignored } } diff --git a/Scripts/Engines/Factions/Items/Power Faction Items/StormsEye.cs b/Scripts/Engines/Factions/Items/Power Faction Items/StormsEye.cs index 3aa5a6b5a..d41c93929 100644 --- a/Scripts/Engines/Factions/Items/Power Faction Items/StormsEye.cs +++ b/Scripts/Engines/Factions/Items/Power Faction Items/StormsEye.cs @@ -34,13 +34,13 @@ namespace Server Point3D origin = new Point3D(pt); Map facet = from.Map; - if (facet != null && facet.CanFit(pt.X, pt.Y, pt.Z, 16, false, false, true)) + if (facet != null && facet.CanFit(pt.X, pt.Y, pt.Z, 16, false, false)) { Movable = false; Effects.SendMovingEffect( from, new Entity(Serial.Zero, origin, facet), - ItemID & 0x3FFF, 7, 0, false, false, Hue - 1, 0 + ItemID & 0x3FFF, 7, 0, false, false, Hue - 1 ); Timer.DelayCall(TimeSpan.FromSeconds(0.5), delegate @@ -80,11 +80,11 @@ namespace Server from.DoHarmful(mob); - SpellHelper.Damage(TimeSpan.FromSeconds(0.50), mob, from, damage / 3, 0, 0, 0, 0, + SpellHelper.Damage(TimeSpan.FromSeconds(0.50), mob, from, damage / 3.0, 0, 0, 0, 0, 100); - SpellHelper.Damage(TimeSpan.FromSeconds(0.70), mob, from, damage / 3, 0, 0, 0, 0, + SpellHelper.Damage(TimeSpan.FromSeconds(0.70), mob, from, damage / 3.0, 0, 0, 0, 0, 100); - SpellHelper.Damage(TimeSpan.FromSeconds(1.00), mob, from, damage / 3, 0, 0, 0, 0, + SpellHelper.Damage(TimeSpan.FromSeconds(1.00), mob, from, damage / 3.0, 0, 0, 0, 0, 100); Timer.DelayCall(TimeSpan.FromSeconds(0.50), delegate { mob.PlaySound(0x1FB); }); diff --git a/Scripts/Engines/Factions/Items/Traps/BaseFactionTrap.cs b/Scripts/Engines/Factions/Items/Traps/BaseFactionTrap.cs index 14a400b14..c9f5f25be 100644 --- a/Scripts/Engines/Factions/Items/Traps/BaseFactionTrap.cs +++ b/Scripts/Engines/Factions/Items/Traps/BaseFactionTrap.cs @@ -124,7 +124,7 @@ namespace Server.Factions { case AllowedPlacing.FactionStronghold: { - StrongholdRegion region = (StrongholdRegion)Region.Find(p, m).GetRegion(typeof(StrongholdRegion)); + StrongholdRegion region = Region.Find(p, m).GetRegion(); if (region != null && region.Faction == Faction) return 0; @@ -160,7 +160,7 @@ namespace Server.Factions if (!CheckDecay() && CheckRange(m.Location, oldLocation, 6)) if (Faction.Find(m) != null && - (m.Skills[SkillName.DetectHidden].Value - 80.0) / 20.0 > Utility.RandomDouble()) + (m.Skills.DetectHidden.Value - 80.0) / 20.0 > Utility.RandomDouble()) PrivateOverheadLocalizedMessage(m, 1010154, MessageHue, "", ""); // [Faction Trap] } diff --git a/Scripts/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs b/Scripts/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs index 62aaa0d9d..4282e7223 100644 --- a/Scripts/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs +++ b/Scripts/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs @@ -418,7 +418,7 @@ namespace Server.Factions public virtual void GenerateBody(bool isFemale, bool randomHair) { - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (isFemale) { @@ -472,7 +472,7 @@ namespace Server.Factions m_Item = item; } - public Mobile Rider + Mobile IMount.Rider { get => m_Item.Rider; set { } diff --git a/Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs b/Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs index b99f4503a..2c1c2a774 100644 --- a/Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs +++ b/Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs @@ -15,6 +15,7 @@ using Server.Targeting; namespace Server.Factions { + [Flags] public enum GuardAI { Bless = 0x01, // heal, cure, +stats @@ -588,7 +589,7 @@ namespace Server.Factions m_Guard.Mana >= 11) { spell = new RecallSpell(m_Guard, null, - new RunebookEntry(m_Guard.Home, m_Guard.Map, "Guard's Home", null), null); + new RunebookEntry(m_Guard.Home, m_Guard.Map, "Guard's Home", null)); } else if (IsAllowed(GuardAI.Bless)) { @@ -598,7 +599,7 @@ namespace Server.Factions (m_Guard.Mana < 11 || m_Guard.NextCombatTime - Core.TickCount > 2000)) spell = new HealSpell(m_Guard, null); } - else if (m_Guard.CanBeginAction(typeof(BaseHealPotion))) + else if (m_Guard.CanBeginAction()) { UseItemByType(typeof(BaseHealPotion)); } diff --git a/Scripts/Engines/Harvest/Core/HarvestSystem.cs b/Scripts/Engines/Harvest/Core/HarvestSystem.cs index 1164e7a34..f86223d1d 100644 --- a/Scripts/Engines/Harvest/Core/HarvestSystem.cs +++ b/Scripts/Engines/Harvest/Core/HarvestSystem.cs @@ -96,11 +96,7 @@ namespace Server.Engines.Harvest if (!CheckHarvest(from, tool)) return; - int tileID; - Map map; - Point3D loc; - - if (!GetHarvestDetails(from, tool, toHarvest, out tileID, out map, out loc)) + if (!GetHarvestDetails(from, tool, toHarvest, out int tileID, out Map map, out Point3D loc)) { OnBadHarvestTarget(from, tool, toHarvest); return; @@ -340,11 +336,7 @@ namespace Server.Engines.Harvest return false; } - int tileID; - Map map; - Point3D loc; - - if (!GetHarvestDetails(from, tool, toHarvest, out tileID, out map, out loc)) + if (!GetHarvestDetails(from, tool, toHarvest, out int tileID, out Map map, out Point3D loc)) { from.EndAction(locked); OnBadHarvestTarget(from, tool, toHarvest); @@ -417,11 +409,7 @@ namespace Server.Engines.Harvest if (!CheckHarvest(from, tool)) return; - int tileID; - Map map; - Point3D loc; - - if (!GetHarvestDetails(from, tool, toHarvest, out tileID, out map, out loc)) + if (!GetHarvestDetails(from, tool, toHarvest, out int tileID, out Map map, out Point3D loc)) { OnBadHarvestTarget(from, tool, toHarvest); return; diff --git a/Scripts/Engines/Harvest/Core/HarvestTarget.cs b/Scripts/Engines/Harvest/Core/HarvestTarget.cs index f7f7c23c7..9b0c0e390 100644 --- a/Scripts/Engines/Harvest/Core/HarvestTarget.cs +++ b/Scripts/Engines/Harvest/Core/HarvestTarget.cs @@ -31,10 +31,12 @@ namespace Server.Engines.Harvest if (from is PlayerMobile player) { QuestSystem qs = player.Quest; + if (!(qs is WitchApprenticeQuest)) + return; - if (qs is WitchApprenticeQuest && - qs.FindObjective(typeof(FindIngredientObjective)) is FindIngredientObjective obj && - !obj.Completed && obj.Ingredient == Ingredient.Bones) + FindIngredientObjective obj = qs.FindObjective(); + + if (obj?.Completed == false && obj.Ingredient == Ingredient.Bones) { player.SendLocalizedMessage( 1055037); // You finish your grim work, finding some of the specific bones listed in the Hag's recipe. diff --git a/Scripts/Engines/Harvest/Fishing.cs b/Scripts/Engines/Harvest/Fishing.cs index e99c6e5c9..b51b9439d 100644 --- a/Scripts/Engines/Harvest/Fishing.cs +++ b/Scripts/Engines/Harvest/Fishing.cs @@ -137,9 +137,9 @@ namespace Server.Engines.Harvest if (qs is CollectorQuest) { - QuestObjective obj = qs.FindObjective(typeof(FishPearlsObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { if (Utility.RandomDouble() < 0.5) { @@ -167,8 +167,8 @@ namespace Server.Engines.Harvest { bool deepWater = SpecialFishingNet.FullValidation(map, loc.X, loc.Y); - double skillBase = from.Skills[SkillName.Fishing].Base; - double skillValue = from.Skills[SkillName.Fishing].Value; + double skillBase = from.Skills.Fishing.Base; + double skillValue = from.Skills.Fishing.Value; for (int i = 0; i < m_MutateTable.Length; ++i) { @@ -468,11 +468,7 @@ namespace Server.Engines.Harvest { base.OnHarvestStarted(from, tool, def, toHarvest); - int tileID; - Map map; - Point3D loc; - - if (GetHarvestDetails(from, tool, toHarvest, out tileID, out map, out loc)) + if (GetHarvestDetails(from, tool, toHarvest, out _, out Map map, out Point3D loc)) Timer.DelayCall(TimeSpan.FromSeconds(1.5), delegate { diff --git a/Scripts/Engines/Harvest/Mining.cs b/Scripts/Engines/Harvest/Mining.cs index 1d2e9b2c6..a06ddf046 100644 --- a/Scripts/Engines/Harvest/Mining.cs +++ b/Scripts/Engines/Harvest/Mining.cs @@ -209,7 +209,7 @@ namespace Server.Engines.Harvest if (def == OreAndStone) { if (from is PlayerMobile pm && pm.StoneMining && pm.ToggleMiningStone && - from.Skills[SkillName.Mining].Base >= 100.0 && 0.1 > Utility.RandomDouble()) + from.Skills.Mining.Base >= 100.0 && 0.1 > Utility.RandomDouble()) return resource.Types[1]; return resource.Types[0]; @@ -251,7 +251,7 @@ namespace Server.Engines.Harvest if (!base.CheckHarvest(from, tool, def, toHarvest)) return false; - if (def == Sand && !(from is PlayerMobile mobile && mobile.Skills[SkillName.Mining].Base >= 100.0 && + if (def == Sand && !(from is PlayerMobile mobile && mobile.Skills.Mining.Base >= 100.0 && mobile.SandMining)) { OnBadHarvestTarget(from, tool, toHarvest); diff --git a/Scripts/Engines/Help/HelpGump.cs b/Scripts/Engines/Help/HelpGump.cs index 385ddb0e0..3ceb40308 100644 --- a/Scripts/Engines/Help/HelpGump.cs +++ b/Scripts/Engines/Help/HelpGump.cs @@ -54,7 +54,7 @@ namespace Server.Engines.Help { public HelpGump(Mobile from) : base(0, 0) { - from.CloseGump(typeof(HelpGump)); + from.CloseGump(); bool isYoung = IsYoung(from); @@ -252,11 +252,11 @@ namespace Server.Engines.Help { BaseHouse house = BaseHouse.FindHouseAt(from); - if (house != null && house.IsAosRules && !from.Region.IsPartOf(typeof(SafeZone))) // Dueling + if (house != null && house.IsAosRules && !from.Region.IsPartOf()) // Dueling { from.Location = house.BanLocation; } - else if (from.Region.IsPartOf(typeof(Jail))) + else if (from.Region.IsPartOf()) { from.SendLocalizedMessage(1114345, "", 0x35); // You'll need a better jailbreak plan than that! } @@ -315,7 +315,7 @@ namespace Server.Engines.Help { if (IsYoung(from)) { - if (from.Region.IsPartOf(typeof(Jail))) + if (from.Region.IsPartOf()) from.SendLocalizedMessage(1114345, "", 0x35); // You'll need a better jailbreak plan than that! else if (from.Region.IsPartOf("Haven Island")) from.SendLocalizedMessage(1041529); // You're already in Haven diff --git a/Scripts/Engines/Help/PagePromptGump.cs b/Scripts/Engines/Help/PagePromptGump.cs index 0008af466..9e8e1a2a4 100644 --- a/Scripts/Engines/Help/PagePromptGump.cs +++ b/Scripts/Engines/Help/PagePromptGump.cs @@ -13,7 +13,7 @@ namespace Server.Engines.Help m_From = from; m_Type = type; - from.CloseGump(typeof(PagePromptGump)); + from.CloseGump(); AddBackground(50, 50, 540, 350, 2600); diff --git a/Scripts/Engines/Help/PageQueue.cs b/Scripts/Engines/Help/PageQueue.cs index 390667b58..e387bbe04 100644 --- a/Scripts/Engines/Help/PageQueue.cs +++ b/Scripts/Engines/Help/PageQueue.cs @@ -146,10 +146,10 @@ namespace Server.Engines.Help public class PageQueue { - private static Hashtable m_KeyedByHandler = new Hashtable(); - private static Hashtable m_KeyedBySender = new Hashtable(); + private static Dictionary m_KeyedByHandler = new Dictionary(); + private static Dictionary m_KeyedBySender = new Dictionary(); - public static ArrayList List{ get; } = new ArrayList(); + public static List List{ get; } = new List(); public static void Initialize() { @@ -326,4 +326,4 @@ namespace Server.Engines.Help Email.AsyncSend(mail); } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Help/PageQueueGump.cs b/Scripts/Engines/Help/PageQueueGump.cs index 7a9d7cc03..9c24b15ae 100644 --- a/Scripts/Engines/Help/PageQueueGump.cs +++ b/Scripts/Engines/Help/PageQueueGump.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Server.Gumps; using Server.Network; @@ -54,11 +54,11 @@ namespace Server.Engines.Help Add(new GumpLabel(180, 12, 2100, "Page Queue")); - ArrayList list = PageQueue.List; - - for (int i = 0; i < list.Count;) + List list = PageQueue.List; + + for (int i = 0;i < list.Count;) { - PageEntry e = (PageEntry)list[i]; + PageEntry e = list[i]; if (e.Sender.Deleted || e.Sender.NetState == null) { @@ -66,42 +66,39 @@ namespace Server.Engines.Help PageQueue.Remove(e); } else - { ++i; - } } - m_List = (PageEntry[])list.ToArray(typeof(PageEntry)); + m_List = list.ToArray(); - if (m_List.Length > 0) - { - Add(new GumpPage(1)); - - for (int i = 0; i < m_List.Length; ++i) - { - PageEntry e = m_List[i]; - - if (i >= 5 && i % 5 == 0) - { - Add(new GumpButton(368, 12, 0xFA5, 0xFA7, 0, GumpButtonType.Page, i / 5 + 1)); - Add(new GumpLabel(298, 12, 2100, "Next Page")); - Add(new GumpPage(i / 5 + 1)); - Add(new GumpButton(12, 12, 0xFAE, 0xFB0, 0, GumpButtonType.Page, i / 5)); - Add(new GumpLabel(48, 12, 2100, "Previous Page")); - } - - string typeString = PageQueue.GetPageTypeName(e.Type); - - string html = - $"[{typeString}] {e.Message} [{(e.Handler == null ? "Unhandled" : "Handling")}]"; - - Add(new GumpHtml(12, 44 + i % 5 * 80, 350, 70, html, true, true)); - Add(new GumpButton(370, 44 + i % 5 * 80 + 24, 0xFA5, 0xFA7, i + 1, GumpButtonType.Reply, 0)); - } - } - else + if (m_List.Length <= 0) { Add(new GumpLabel(12, 44, 2100, "The page queue is empty.")); + return; + } + + Add(new GumpPage(1)); + + for (int i = 0; i < m_List.Length; ++i) + { + PageEntry e = m_List[i]; + + if (i >= 5 && i % 5 == 0) + { + Add(new GumpButton(368, 12, 0xFA5, 0xFA7, 0, GumpButtonType.Page, i / 5 + 1)); + Add(new GumpLabel(298, 12, 2100, "Next Page")); + Add(new GumpPage(i / 5 + 1)); + Add(new GumpButton(12, 12, 0xFAE, 0xFB0, 0, GumpButtonType.Page, i / 5)); + Add(new GumpLabel(48, 12, 2100, "Previous Page")); + } + + string typeString = PageQueue.GetPageTypeName(e.Type); + + string html = + $"[{typeString}] {e.Message} [{(e.Handler == null ? "Unhandled" : "Handling")}]"; + + Add(new GumpHtml(12, 44 + i % 5 * 80, 350, 70, html, true, true)); + Add(new GumpButton(370, 44 + i % 5 * 80 + 24, 0xFA5, 0xFA7, i + 1, GumpButtonType.Reply, 0)); } } @@ -126,8 +123,6 @@ namespace Server.Engines.Help public class PredefinedResponse { - private static ArrayList m_List; - public PredefinedResponse(string title, string message) { Title = title; @@ -138,25 +133,13 @@ namespace Server.Engines.Help public string Message{ get; set; } - public static ArrayList List - { - get - { - if (m_List == null) - m_List = Load(); - - return m_List; - } - } + public static List List{ get; private set; } = Load(); public static PredefinedResponse Add(string title, string message) { - if (m_List == null) - m_List = Load(); - PredefinedResponse resp = new PredefinedResponse(title, message); - m_List.Add(resp); + List.Add(resp); Save(); return resp; @@ -164,8 +147,8 @@ namespace Server.Engines.Help public static void Save() { - if (m_List == null) - m_List = Load(); + if (List == null) + List = Load(); try { @@ -173,9 +156,9 @@ namespace Server.Engines.Help using (StreamWriter op = new StreamWriter(path)) { - for (int i = 0; i < m_List.Count; ++i) + for (int i = 0; i < List.Count; ++i) { - PredefinedResponse resp = (PredefinedResponse)m_List[i]; + PredefinedResponse resp = List[i]; op.WriteLine("{0}\t{1}", resp.Title, resp.Message); } @@ -187,41 +170,37 @@ namespace Server.Engines.Help } } - public static ArrayList Load() + public static List Load() { - ArrayList list = new ArrayList(); - string path = Path.Combine(Core.BaseDirectory, "Data/pageresponse.cfg"); - if (File.Exists(path)) - try + if (!File.Exists(path)) + return new List(); + + List list = new List(); + + try + { + using (StreamReader ip = new StreamReader(path)) { - using (StreamReader ip = new StreamReader(path)) + string line; + + while ((line = ip.ReadLine()?.Trim()) != null) { - string line; + if (line.Length == 0 || line.StartsWith("#")) + continue; - while ((line = ip.ReadLine()) != null) - try - { - line = line.Trim(); + string[] split = line.Split('\t'); - if (line.Length == 0 || line.StartsWith("#")) - continue; - - string[] split = line.Split('\t'); - - if (split.Length == 2) - list.Add(new PredefinedResponse(split[0], split[1])); - } - catch - { - } + if (split.Length == 2) + list.Add(new PredefinedResponse(split[0], split[1])); } } - catch (Exception e) - { - Console.WriteLine(e); - } + } + catch (Exception e) + { + Console.WriteLine(e); + } return list; } @@ -239,7 +218,7 @@ namespace Server.Engines.Help m_From = from; m_Response = response; - from.CloseGump(typeof(PredefGump)); + from.CloseGump(); bool canEdit = from.AccessLevel >= AccessLevel.GameMaster; @@ -252,7 +231,7 @@ namespace Server.Engines.Help AddHtml(10, 10, 390, 20, Color(Center("Predefined Responses"), LabelColor32), false, false); - ArrayList list = PredefinedResponse.List; + List list = PredefinedResponse.List; AddPage(1); @@ -269,7 +248,7 @@ namespace Server.Engines.Help AddLabel(48, 10, 2100, "Previous Page"); } - PredefinedResponse resp = (PredefinedResponse)list[i]; + PredefinedResponse resp = list[i]; string html = $"{resp.Title}
{resp.Message}"; @@ -357,7 +336,7 @@ namespace Server.Engines.Help { PredefinedResponse resp = new PredefinedResponse("", ""); - ArrayList list = PredefinedResponse.List; + List list = PredefinedResponse.List; list.Add(resp); m_From.SendGump(new PredefGump(m_From, resp)); @@ -369,11 +348,11 @@ namespace Server.Engines.Help int type = index % 3; index /= 3; - ArrayList list = PredefinedResponse.List; + List list = PredefinedResponse.List; if (index >= 0 && index < list.Count) { - PredefinedResponse resp = (PredefinedResponse)list[index]; + PredefinedResponse resp = list[index]; switch (type) { @@ -414,7 +393,7 @@ namespace Server.Engines.Help } else { - ArrayList list = PredefinedResponse.List; + List list = PredefinedResponse.List; switch (info.ButtonID) { @@ -473,117 +452,110 @@ namespace Server.Engines.Help public PageEntryGump(Mobile m, PageEntry entry) : base(30, 30) { - try + m_Mobile = m; + m_Entry = entry; + + int buttons = 0; + + int bottom = 356; + + AddPage(0); + + AddImageTiled(0, 0, 410, 456, 0xA40); + AddAlphaRegion(1, 1, 408, 454); + + AddPage(1); + + AddLabel(18, 18, 2100, "Sent:"); + AddLabelCropped(128, 18, 264, 20, 2100, entry.Sent.ToString()); + + AddLabel(18, 38, 2100, "Sender:"); + AddLabelCropped(128, 38, 264, 20, 2100, + $"{entry.Sender.RawName} {entry.Sender.Location} [{entry.Sender.Map}]"); + + AddButton(18, bottom - buttons * 22, 0xFAB, 0xFAD, 8, GumpButtonType.Reply, 0); + AddImageTiled(52, bottom - buttons * 22 + 1, 340, 80, 0xA40 /*0xBBC*/ /*0x2458*/); + AddImageTiled(53, bottom - buttons * 22 + 2, 338, 78, 0xBBC /*0x2426*/); + AddTextEntry(55, bottom - buttons++ * 22 + 2, 336, 78, 0x480, 0, ""); + + AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 0, GumpButtonType.Page, 2); + AddLabel(52, bottom - buttons++ * 22, 2100, "Predefined Response"); + + if (entry.Sender != m) { - m_Mobile = m; - m_Entry = entry; + AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 1, GumpButtonType.Reply, 0); + AddLabel(52, bottom - buttons++ * 22, 2100, "Go to Sender"); + } - int buttons = 0; + AddLabel(18, 58, 2100, "Handler:"); - int bottom = 356; + if (entry.Handler == null) + { + AddLabelCropped(128, 58, 264, 20, 2100, "Unhandled"); - AddPage(0); + AddButton(18, bottom - buttons * 22, 0xFB1, 0xFB3, 5, GumpButtonType.Reply, 0); + AddLabel(52, bottom - buttons++ * 22, 2100, "Delete Page"); - AddImageTiled(0, 0, 410, 456, 0xA40); - AddAlphaRegion(1, 1, 408, 454); + AddButton(18, bottom - buttons * 22, 0xFB7, 0xFB9, 4, GumpButtonType.Reply, 0); + AddLabel(52, bottom - buttons++ * 22, 2100, "Handle Page"); + } + else + { + AddLabelCropped(128, 58, 264, 20, m_AccessLevelHues[(int)entry.Handler.AccessLevel], entry.Handler.Name); - AddPage(1); - - AddLabel(18, 18, 2100, "Sent:"); - AddLabelCropped(128, 18, 264, 20, 2100, entry.Sent.ToString()); - - AddLabel(18, 38, 2100, "Sender:"); - AddLabelCropped(128, 38, 264, 20, 2100, - $"{entry.Sender.RawName} {entry.Sender.Location} [{entry.Sender.Map}]"); - - AddButton(18, bottom - buttons * 22, 0xFAB, 0xFAD, 8, GumpButtonType.Reply, 0); - AddImageTiled(52, bottom - buttons * 22 + 1, 340, 80, 0xA40 /*0xBBC*/ /*0x2458*/); - AddImageTiled(53, bottom - buttons * 22 + 2, 338, 78, 0xBBC /*0x2426*/); - AddTextEntry(55, bottom - buttons++ * 22 + 2, 336, 78, 0x480, 0, ""); - - AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 0, GumpButtonType.Page, 2); - AddLabel(52, bottom - buttons++ * 22, 2100, "Predefined Response"); - - if (entry.Sender != m) + if (entry.Handler != m) { - AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 1, GumpButtonType.Reply, 0); - AddLabel(52, bottom - buttons++ * 22, 2100, "Go to Sender"); - } - - AddLabel(18, 58, 2100, "Handler:"); - - if (entry.Handler == null) - { - AddLabelCropped(128, 58, 264, 20, 2100, "Unhandled"); - - AddButton(18, bottom - buttons * 22, 0xFB1, 0xFB3, 5, GumpButtonType.Reply, 0); - AddLabel(52, bottom - buttons++ * 22, 2100, "Delete Page"); - - AddButton(18, bottom - buttons * 22, 0xFB7, 0xFB9, 4, GumpButtonType.Reply, 0); - AddLabel(52, bottom - buttons++ * 22, 2100, "Handle Page"); + AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 2, GumpButtonType.Reply, 0); + AddLabel(52, bottom - buttons++ * 22, 2100, "Go to Handler"); } else { - AddLabelCropped(128, 58, 264, 20, m_AccessLevelHues[(int)entry.Handler.AccessLevel], entry.Handler.Name); + AddButton(18, bottom - buttons * 22, 0xFA2, 0xFA4, 6, GumpButtonType.Reply, 0); + AddLabel(52, bottom - buttons++ * 22, 2100, "Abandon Page"); - if (entry.Handler != m) - { - AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 2, GumpButtonType.Reply, 0); - AddLabel(52, bottom - buttons++ * 22, 2100, "Go to Handler"); - } - else - { - AddButton(18, bottom - buttons * 22, 0xFA2, 0xFA4, 6, GumpButtonType.Reply, 0); - AddLabel(52, bottom - buttons++ * 22, 2100, "Abandon Page"); - - AddButton(18, bottom - buttons * 22, 0xFB7, 0xFB9, 7, GumpButtonType.Reply, 0); - AddLabel(52, bottom - buttons++ * 22, 2100, "Page Handled"); - } - } - - AddLabel(18, 78, 2100, "Page Location:"); - AddLabelCropped(128, 78, 264, 20, 2100, $"{entry.PageLocation} [{entry.PageMap}]"); - - AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 3, GumpButtonType.Reply, 0); - AddLabel(52, bottom - buttons++ * 22, 2100, "Go to Page Location"); - - if (entry.SpeechLog != null) - { - AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 10, GumpButtonType.Reply, 0); - AddLabel(52, bottom - buttons++ * 22, 2100, "View Speech Log"); - } - - AddLabel(18, 98, 2100, "Page Type:"); - AddLabelCropped(128, 98, 264, 20, 2100, PageQueue.GetPageTypeName(entry.Type)); - - AddLabel(18, 118, 2100, "Message:"); - AddHtml(128, 118, 250, 100, entry.Message, true, true); - - AddPage(2); - - ArrayList preresp = PredefinedResponse.List; - - AddButton(18, 18, 0xFAE, 0xFB0, 0, GumpButtonType.Page, 1); - AddButton(410 - 18 - 32, 18, 0xFAB, 0xFAC, 9, GumpButtonType.Reply, 0); - - if (preresp.Count == 0) - { - AddLabel(52, 18, 2100, "There are no predefined responses."); - } - else - { - AddLabel(52, 18, 2100, "Back"); - - for (int i = 0; i < preresp.Count; ++i) - { - AddButton(18, 40 + i * 22, 0xFA5, 0xFA7, 100 + i, GumpButtonType.Reply, 0); - AddLabel(52, 40 + i * 22, 2100, ((PredefinedResponse)preresp[i]).Title); - } + AddButton(18, bottom - buttons * 22, 0xFB7, 0xFB9, 7, GumpButtonType.Reply, 0); + AddLabel(52, bottom - buttons++ * 22, 2100, "Page Handled"); } } - catch (Exception e) + + AddLabel(18, 78, 2100, "Page Location:"); + AddLabelCropped(128, 78, 264, 20, 2100, $"{entry.PageLocation} [{entry.PageMap}]"); + + AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 3, GumpButtonType.Reply, 0); + AddLabel(52, bottom - buttons++ * 22, 2100, "Go to Page Location"); + + if (entry.SpeechLog != null) { - Console.WriteLine(e); + AddButton(18, bottom - buttons * 22, 0xFA5, 0xFA7, 10, GumpButtonType.Reply, 0); + AddLabel(52, bottom - buttons * 22, 2100, "View Speech Log"); + } + + AddLabel(18, 98, 2100, "Page Type:"); + AddLabelCropped(128, 98, 264, 20, 2100, PageQueue.GetPageTypeName(entry.Type)); + + AddLabel(18, 118, 2100, "Message:"); + AddHtml(128, 118, 250, 100, entry.Message, true, true); + + AddPage(2); + + List preresp = PredefinedResponse.List; + + AddButton(18, 18, 0xFAE, 0xFB0, 0, GumpButtonType.Page, 1); + AddButton(410 - 18 - 32, 18, 0xFAB, 0xFAC, 9, GumpButtonType.Reply, 0); + + if (preresp.Count == 0) + { + AddLabel(52, 18, 2100, "There are no predefined responses."); + } + else + { + AddLabel(52, 18, 2100, "Back"); + + for (int i = 0; i < preresp.Count; ++i) + { + AddButton(18, 40 + i * 22, 0xFA5, 0xFA7, 100 + i, GumpButtonType.Reply, 0); + AddLabel(52, 40 + i * 22, 2100, preresp[i].Title); + } } } @@ -803,8 +775,7 @@ namespace Server.Engines.Help if (m_Entry.SpeechLog != null) { - Gump gump = new SpeechLogGump(m_Entry.Sender, m_Entry.SpeechLog); - state.Mobile.SendGump(gump); + state.Mobile.SendGump(new SpeechLogGump(m_Entry.Sender, m_Entry.SpeechLog)); } break; @@ -812,13 +783,13 @@ namespace Server.Engines.Help default: { int index = info.ButtonID - 100; - ArrayList preresp = PredefinedResponse.List; + List preresp = PredefinedResponse.List; if (index >= 0 && index < preresp.Count) { - m_Entry.AddResponse(state.Mobile, "[PreDef] " + ((PredefinedResponse)preresp[index]).Title); + m_Entry.AddResponse(state.Mobile, "[PreDef] " + preresp[index].Title); m_Entry.Sender.SendGump(new MessageSentGump(m_Entry.Sender, state.Mobile.Name, - ((PredefinedResponse)preresp[index]).Message)); + preresp[index].Message)); } Resend(state); diff --git a/Scripts/Engines/Help/StuckMenu.cs b/Scripts/Engines/Help/StuckMenu.cs index 644ed1cab..fa1358c50 100644 --- a/Scripts/Engines/Help/StuckMenu.cs +++ b/Scripts/Engines/Help/StuckMenu.cs @@ -120,7 +120,7 @@ namespace Server.Menus.Questions m_MarkUse = markUse; Closable = false; - Dragable = false; + Draggable = false; Disposable = false; AddBackground(0, 0, 270, 320, 2600); @@ -228,7 +228,7 @@ namespace Server.Menus.Questions if (m_Mobile.NetState == null || DateTime.UtcNow > m_End) { m_Mobile.Frozen = false; - m_Mobile.CloseGump(typeof(StuckMenu)); + m_Mobile.CloseGump(); Stop(); } diff --git a/Scripts/Engines/Khaldun/KhaldunGen.cs b/Scripts/Engines/Khaldun/KhaldunGen.cs index 67e814510..e247f8da0 100644 --- a/Scripts/Engines/Khaldun/KhaldunGen.cs +++ b/Scripts/Engines/Khaldun/KhaldunGen.cs @@ -43,11 +43,11 @@ namespace Server.Commands return false; } - public static Item TryCreateItem(int x, int y, int z, Item srcItem) + public static T TryCreateItem(int x, int y, int z, T srcItem) where T : Item { - IPooledEnumerable eable = Map.Felucca.GetItemsInBounds(new Rectangle2D(x, y, 1, 1)); + IPooledEnumerable eable = Map.Felucca.GetItemsInBounds(new Rectangle2D(x, y, 1, 1)); - foreach (Item item in eable) + foreach (T item in eable) if (item.GetType() == srcItem.GetType()) { eable.Free(); @@ -191,15 +191,13 @@ namespace Server.Commands // Generate Central Khaldun entrance DisappearingRaiseSwitch sw = - TryCreateItem(5459, 1426, 10, new DisappearingRaiseSwitch()) as DisappearingRaiseSwitch; - RaiseSwitch lv = TryCreateItem(5403, 1359, 0, new RaiseSwitch()) as RaiseSwitch; + TryCreateItem(5459, 1426, 10, new DisappearingRaiseSwitch()); + RaiseSwitch lv = TryCreateItem(5403, 1359, 0, new RaiseSwitch()); RaisableItem stone = - TryCreateItem(5403, 1360, 0, new RaisableItem(0x788, 10, 0x477, 0x475, TimeSpan.FromMinutes(1.5))) as - RaisableItem; + TryCreateItem(5403, 1360, 0, new RaisableItem(0x788, 10, 0x477, 0x475, TimeSpan.FromMinutes(1.5))); RaisableItem door = - TryCreateItem(5524, 1367, 0, new RaisableItem(0x1D0, 20, 0x477, 0x475, TimeSpan.FromMinutes(5.0))) as - RaisableItem; + TryCreateItem(5524, 1367, 0, new RaisableItem(0x1D0, 20, 0x477, 0x475, TimeSpan.FromMinutes(5.0))); sw.RaisableItem = stone; lv.RaisableItem = door; diff --git a/Scripts/Engines/Khaldun/PuzzleChest.cs b/Scripts/Engines/Khaldun/PuzzleChest.cs index 4cfac16d7..9b4eeac6d 100644 --- a/Scripts/Engines/Khaldun/PuzzleChest.cs +++ b/Scripts/Engines/Khaldun/PuzzleChest.cs @@ -259,8 +259,8 @@ namespace Server.Items solution = new PuzzleChestSolution(PuzzleChestCylinder.None, PuzzleChestCylinder.None, PuzzleChestCylinder.None, PuzzleChestCylinder.None, PuzzleChestCylinder.None); - from.CloseGump(typeof(PuzzleGump)); - from.CloseGump(typeof(StatusGump)); + from.CloseGump(); + from.CloseGump(); from.SendGump(new PuzzleGump(from, this, solution, 0)); return true; @@ -277,9 +277,7 @@ namespace Server.Items public void SubmitSolution(Mobile m, PuzzleChestSolution solution) { - int correctCylinders, correctColors; - - if (solution.Matches(Solution, out correctCylinders, out correctColors)) + if (solution.Matches(Solution, out int correctCylinders, out int correctColors)) { LockPick(m); @@ -553,7 +551,7 @@ namespace Server.Items m_Chest = chest; m_Solution = solution; - Dragable = false; + Draggable = false; AddBackground(25, 0, 500, 410, 0x53); diff --git a/Scripts/Engines/MLQuests/Definitions/BlightedGrove.cs b/Scripts/Engines/MLQuests/Definitions/BlightedGrove.cs index a92dee904..02c75d6c2 100644 --- a/Scripts/Engines/MLQuests/Definitions/BlightedGrove.cs +++ b/Scripts/Engines/MLQuests/Definitions/BlightedGrove.cs @@ -148,7 +148,7 @@ namespace Server.Engines.MLQuests.Definitions // The ability is awarded regardless of blacksmithy skill pm.AcquireRecipe(32); - if (pm.Skills[SkillName.Blacksmith].Base < 45.0) // TODO: Verify threshold + if (pm.Skills.Blacksmith.Base < 45.0) // TODO: Verify threshold pm.SendLocalizedMessage( 1075005); // You observe carefully but you can't grasp the complexities of smithing a bone handled machete. else diff --git a/Scripts/Engines/MLQuests/Definitions/Ilshenar.cs b/Scripts/Engines/MLQuests/Definitions/Ilshenar.cs index 6fbec765e..d9c3a8919 100644 --- a/Scripts/Engines/MLQuests/Definitions/Ilshenar.cs +++ b/Scripts/Engines/MLQuests/Definitions/Ilshenar.cs @@ -161,7 +161,7 @@ namespace Server.Engines.MLQuests.Definitions SetDex(70, 80); SetInt(80, 90); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = true; Body = 401; diff --git a/Scripts/Engines/MLQuests/Gumps/BaseQuestGump.cs b/Scripts/Engines/MLQuests/Gumps/BaseQuestGump.cs index 22c7656c7..984d6adff 100644 --- a/Scripts/Engines/MLQuests/Gumps/BaseQuestGump.cs +++ b/Scripts/Engines/MLQuests/Gumps/BaseQuestGump.cs @@ -284,12 +284,12 @@ namespace Server.Engines.MLQuests.Gumps */ public static void CloseOtherGumps(PlayerMobile pm) { - pm.CloseGump(typeof(InfoNPCGump)); - pm.CloseGump(typeof(QuestRewardGump)); - pm.CloseGump(typeof(QuestConversationGump)); - pm.CloseGump(typeof(QuestReportBackGump)); + pm.CloseGump(); + pm.CloseGump(); + pm.CloseGump(); + pm.CloseGump(); //pm.CloseGump( typeof( UnknownGump807 ) ); - pm.CloseGump(typeof(QuestCancelConfirmGump)); + pm.CloseGump(); } } } \ No newline at end of file diff --git a/Scripts/Engines/MLQuests/Gumps/QuestLogDetailedGump.cs b/Scripts/Engines/MLQuests/Gumps/QuestLogDetailedGump.cs index 5ba989daa..1829c8de9 100644 --- a/Scripts/Engines/MLQuests/Gumps/QuestLogDetailedGump.cs +++ b/Scripts/Engines/MLQuests/Gumps/QuestLogDetailedGump.cs @@ -26,7 +26,7 @@ namespace Server.Engines.MLQuests.Gumps if (closeGumps) { CloseOtherGumps(pm); - pm.CloseGump(typeof(QuestLogDetailedGump)); + pm.CloseGump(); } SetTitle(quest.Title); diff --git a/Scripts/Engines/MLQuests/Gumps/QuestLogGump.cs b/Scripts/Engines/MLQuests/Gumps/QuestLogGump.cs index 1ee375daf..efbcc89ba 100644 --- a/Scripts/Engines/MLQuests/Gumps/QuestLogGump.cs +++ b/Scripts/Engines/MLQuests/Gumps/QuestLogGump.cs @@ -23,8 +23,8 @@ namespace Server.Engines.MLQuests.Gumps if (closeGumps) { - pm.CloseGump(typeof(QuestLogGump)); - pm.CloseGump(typeof(QuestLogDetailedGump)); + pm.CloseGump(); + pm.CloseGump(); } RegisterButton(ButtonPosition.Right, ButtonGraphic.Okay, 3); diff --git a/Scripts/Engines/MLQuests/Gumps/QuestOfferGump.cs b/Scripts/Engines/MLQuests/Gumps/QuestOfferGump.cs index f86c62b12..565e575dc 100644 --- a/Scripts/Engines/MLQuests/Gumps/QuestOfferGump.cs +++ b/Scripts/Engines/MLQuests/Gumps/QuestOfferGump.cs @@ -16,7 +16,7 @@ namespace Server.Engines.MLQuests.Gumps m_Quester = quester; CloseOtherGumps(pm); - pm.CloseGump(typeof(QuestOfferGump)); + pm.CloseGump(); SetTitle(quest.Title); RegisterButton(ButtonPosition.Left, ButtonGraphic.Accept, 1); diff --git a/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs b/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs index 69208f4bf..a4eba1aa6 100644 --- a/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs +++ b/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs @@ -19,8 +19,6 @@ namespace Server.Engines.MLQuests.Gumps public class RaceChangeConfirmGump : Gump { - public static readonly Type Type = typeof(RaceChangeConfirmGump); - private static Dictionary m_Pending; private PlayerMobile m_From; @@ -30,7 +28,7 @@ namespace Server.Engines.MLQuests.Gumps public RaceChangeConfirmGump(IRaceChanger owner, PlayerMobile from, Race targetRace) : base(50, 50) { - from.CloseGump(Type); + from.CloseGump(); m_Owner = owner; m_From = from; @@ -152,8 +150,8 @@ namespace Server.Engines.MLQuests.Gumps from.SendLocalizedMessage(1073646); // Only the living may proceed... else if (from.Mounted) from.SendLocalizedMessage(1073647); // You may not continue while mounted... - else if (!from.CanBeginAction(typeof(PolymorphSpell)) || DisguiseTimers.IsDisguised(from) || - AnimalForm.UnderTransformation(from) || !from.CanBeginAction(typeof(IncognitoSpell)) || + else if (!from.CanBeginAction() || DisguiseTimers.IsDisguised(from) || + AnimalForm.UnderTransformation(from) || !from.CanBeginAction() || from.IsBodyMod) // TODO: Does this cover everything? from.SendLocalizedMessage(1073648); // You may only proceed while in your original state... else if (from.Spell != null && from.Spell.IsCasting) @@ -233,7 +231,6 @@ namespace Server.Engines.MLQuests.Gumps private class RaceChangeState { private static readonly TimeSpan m_TimeoutDelay = TimeSpan.FromMinutes(1); - private static readonly TimerStateCallback m_TimeoutCallback = Timeout; public IRaceChanger m_Owner; public Race m_TargetRace; @@ -243,7 +240,7 @@ namespace Server.Engines.MLQuests.Gumps { m_Owner = owner; m_TargetRace = targetRace; - m_Timeout = Timer.DelayCall(m_TimeoutDelay, m_TimeoutCallback, ns); + m_Timeout = Timer.DelayCall(m_TimeoutDelay, Timeout, ns); } } } diff --git a/Scripts/Engines/MLQuests/MLQuest.cs b/Scripts/Engines/MLQuests/MLQuest.cs index ec1c308b4..f5432a3d4 100644 --- a/Scripts/Engines/MLQuests/MLQuest.cs +++ b/Scripts/Engines/MLQuests/MLQuest.cs @@ -129,9 +129,7 @@ namespace Server.Engines.MLQuests while (checkQuest != null) { - DateTime nextAvailable; - - if (context.HasDoneQuest(checkQuest, out nextAvailable)) + if (context.HasDoneQuest(checkQuest, out DateTime nextAvailable)) { if (checkQuest.OneTimeOnly) { diff --git a/Scripts/Engines/MLQuests/MLQuestEntry.cs b/Scripts/Engines/MLQuests/MLQuestEntry.cs index f85bf66b8..560ad1375 100644 --- a/Scripts/Engines/MLQuests/MLQuestEntry.cs +++ b/Scripts/Engines/MLQuests/MLQuestEntry.cs @@ -459,7 +459,7 @@ namespace Server.Engines.MLQuests MLQuest quest = MLQuestSystem.ReadQuestRef(reader); // TODO: Serialize quester TYPE too, the quest giver reference then becomes optional (only for escorts) - IQuestGiver quester = World.FindEntity(reader.ReadInt()) as IQuestGiver; + IQuestGiver quester = World.FindEntity(reader.ReadUInt()) as IQuestGiver; bool claimReward = reader.ReadBool(); int objectives = reader.ReadInt(); diff --git a/Scripts/Engines/MLQuests/MLQuestSystem.cs b/Scripts/Engines/MLQuests/MLQuestSystem.cs index ae797231e..f9a4177dc 100644 --- a/Scripts/Engines/MLQuests/MLQuestSystem.cs +++ b/Scripts/Engines/MLQuests/MLQuestSystem.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.IO; using Server.Commands; @@ -158,9 +157,8 @@ namespace Server.Engines.MLQuests } Type index = ScriptCompiler.FindTypeByName(e.GetString(0)); - MLQuest quest; - if (index == null || !Quests.TryGetValue(index, out quest)) + if (index == null || !Quests.TryGetValue(index, out MLQuest quest)) { m.SendMessage("Invalid quest type name."); return; @@ -232,7 +230,7 @@ namespace Server.Engines.MLQuests { Mobile m = e.Mobile; - ArrayList found = new ArrayList(); + List found = new List(); foreach (Item item in World.Items.Values) if (item.QuestItem) @@ -303,10 +301,7 @@ namespace Server.Engines.MLQuests MLQuestContext context = GetContext(pm); - MLQuest quest; - MLQuestInstance entry; - - if (!FindQuest(quester, pm, context, out quest, out entry)) + if (!FindQuest(quester, pm, context, out MLQuest quest, out MLQuestInstance entry)) { Tell(quester, pm, 1080107); // I'm sorry, I have nothing for you at this time. return; diff --git a/Scripts/Engines/MLQuests/Mobiles/BoonCollector.cs b/Scripts/Engines/MLQuests/Mobiles/BoonCollector.cs index fb343af6b..8036381fd 100644 --- a/Scripts/Engines/MLQuests/Mobiles/BoonCollector.cs +++ b/Scripts/Engines/MLQuests/Mobiles/BoonCollector.cs @@ -79,7 +79,7 @@ namespace Server.Engines.MLQuests.Mobiles public void TryTalkTo(Mobile from, bool fromClick) { - if (!from.Hidden && !from.HasGump(typeOfRaceChangeConfirmGump) && + if (!from.Hidden && !from.HasGump() && !RaceChangeConfirmGump.IsPending(from.NetState) && CanTalkTo(from)) TalkTo(from as PlayerMobile); else if (fromClick) diff --git a/Scripts/Engines/MLQuests/Objectives/GainSkillObjective.cs b/Scripts/Engines/MLQuests/Objectives/GainSkillObjective.cs index a2c241db9..1c4af0638 100644 --- a/Scripts/Engines/MLQuests/Objectives/GainSkillObjective.cs +++ b/Scripts/Engines/MLQuests/Objectives/GainSkillObjective.cs @@ -4,6 +4,7 @@ using Server.Mobiles; namespace Server.Engines.MLQuests.Objectives { + [Flags] public enum GainSkillObjectiveFlags : byte { None = 0x00, @@ -15,17 +16,7 @@ namespace Server.Engines.MLQuests.Objectives { private GainSkillObjectiveFlags m_Flags; - public GainSkillObjective() - : this(SkillName.Alchemy, 0) - { - } - - public GainSkillObjective(SkillName skill, int thresholdFixed) - : this(skill, thresholdFixed, false, false) - { - } - - public GainSkillObjective(SkillName skill, int thresholdFixed, bool useReal, bool accelerate) + public GainSkillObjective(SkillName skill = SkillName.Alchemy, int thresholdFixed = 0, bool useReal = false, bool accelerate = false) { Skill = skill; ThresholdFixed = thresholdFixed; @@ -74,10 +65,7 @@ namespace Server.Engines.MLQuests.Objectives int skillLabel = AosSkillBonuses.GetLabel(Skill); string args; - if (ThresholdFixed % 10 == 0) - args = $"#{skillLabel}\t{ThresholdFixed / 10}"; // as seen on OSI - else - args = $"#{skillLabel}\t{(double)ThresholdFixed / 10:0.0}"; // for non-integer skill levels + args = ThresholdFixed % 10 == 0 ? $"#{skillLabel}\t{ThresholdFixed / 10}" : $"#{skillLabel}\t{(double)ThresholdFixed / 10:0.0}"; g.AddHtmlLocalized(98, y, 312, 16, 1077485, args, 0x15F90, false, false); // Increase ~1_SKILL~ to ~2_VALUE~ y += 16; @@ -171,4 +159,4 @@ namespace Server.Engines.MLQuests.Objectives } } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/MyRunUO/DatabaseCommandQueue.cs b/Scripts/Engines/MyRunUO/DatabaseCommandQueue.cs index e5f07a95e..22125e710 100644 --- a/Scripts/Engines/MyRunUO/DatabaseCommandQueue.cs +++ b/Scripts/Engines/MyRunUO/DatabaseCommandQueue.cs @@ -11,7 +11,6 @@ namespace Server.Engines.MyRunUO private string m_ConnectionString; private Queue m_Queue; private ManualResetEvent m_Sync; - private Thread m_Thread; public DatabaseCommandQueue(string completionString, string threadName) : this(Config.CompileConnectionString(), completionString, threadName) @@ -35,10 +34,9 @@ namespace Server.Engines.MyRunUO m_Sync = new ManualResetEvent(true); - m_Thread = new Thread(Thread_Start); - m_Thread.Name = threadName; //"MyRunUO Database Command Queue"; - m_Thread.Priority = Config.DatabaseThreadPriority; - m_Thread.Start(); + // MyRunUO Database Command Queue; + Thread thread = new Thread(Thread_Start) { Name = threadName, Priority = Config.DatabaseThreadPriority }; + thread.Start(); } public bool HasCompleted{ get; private set; } @@ -54,6 +52,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } } } @@ -111,6 +110,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } try @@ -119,6 +119,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } try @@ -127,6 +128,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } try @@ -135,6 +137,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } Console.WriteLine(m_CompletionString, (DateTime.UtcNow - start).TotalSeconds); @@ -164,6 +167,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } try @@ -172,6 +176,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } try @@ -180,6 +185,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } try @@ -188,6 +194,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } try @@ -196,6 +203,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } Console.WriteLine("MyRunUO: Unable to connect to the database"); diff --git a/Scripts/Engines/MyRunUO/LayerComparer.cs b/Scripts/Engines/MyRunUO/LayerComparer.cs index 492361586..5fd198a0e 100644 --- a/Scripts/Engines/MyRunUO/LayerComparer.cs +++ b/Scripts/Engines/MyRunUO/LayerComparer.cs @@ -1,8 +1,8 @@ -using System.Collections; +using System.Collections.Generic; namespace Server.Engines.MyRunUO { - public class LayerComparer : IComparer + public class LayerComparer : IComparer { private static Layer PlateArms = (Layer)255; private static Layer ChainTunic = (Layer)254; @@ -36,7 +36,7 @@ namespace Server.Engines.MyRunUO Layer.Talisman }; - public static readonly IComparer Instance = new LayerComparer(); + public static readonly IComparer Instance = new LayerComparer(); static LayerComparer() { @@ -48,16 +48,16 @@ namespace Server.Engines.MyRunUO public static int[] TranslationTable{ get; } - public int Compare(object x, object y) + public int Compare(Item a, Item b) { - Item a = (Item)x; - Item b = (Item)y; - - Layer aLayer = a.Layer; - Layer bLayer = b.Layer; - - aLayer = Fix(a.ItemID, aLayer); - bLayer = Fix(b.ItemID, bLayer); + if (a == null) + return b == null ? 0 : 1; + + if (b == null) + return -1; + + Layer aLayer = Fix(a.ItemID, a.Layer); + Layer bLayer = Fix(b.ItemID, b.Layer); return TranslationTable[(int)bLayer] - TranslationTable[(int)aLayer]; } @@ -75,10 +75,7 @@ namespace Server.Engines.MyRunUO if (itemID == 0x13BF || itemID == 0x13C4) // chainmail tunic return ChainTunic; - if (itemID == 0x1C08 || itemID == 0x1C09) // leather skirt - return LeatherShorts; - - if (itemID == 0x1C00 || itemID == 0x1C01) // leather shorts + if (itemID == 0x1C08 || itemID == 0x1C09 || itemID == 0x1C00 || itemID == 0x1C01) // leather skirt/shorts return LeatherShorts; return oldLayer; diff --git a/Scripts/Engines/MyRunUO/MyRunUO.cs b/Scripts/Engines/MyRunUO/MyRunUO.cs index ba8cf42f9..7983144ac 100644 --- a/Scripts/Engines/MyRunUO/MyRunUO.cs +++ b/Scripts/Engines/MyRunUO/MyRunUO.cs @@ -25,11 +25,11 @@ namespace Server.Engines.MyRunUO private static DatabaseCommandQueue m_Command; - private static ArrayList m_MobilesToUpdate = new ArrayList(); + private static List m_MobilesToUpdate = new List(); private List m_Collecting; private int m_Index; - private ArrayList m_Items = new ArrayList(); + private List m_Items = new List(); private string m_LayersPath; private ArrayList m_List; private string m_MobilesPath; @@ -182,7 +182,7 @@ namespace Server.Engines.MyRunUO protected override void OnTick() { - bool shouldExit = false; + bool shouldExit; try { @@ -271,8 +271,8 @@ namespace Server.Engines.MyRunUO } else { - m_List = m_MobilesToUpdate; - m_MobilesToUpdate = new ArrayList(); + m_List = new ArrayList(m_MobilesToUpdate); + m_MobilesToUpdate = new List(); m_Stage = Stage.DumpingMobiles; m_Index = 0; } @@ -282,7 +282,7 @@ namespace Server.Engines.MyRunUO { if (m_Command == null) { - m_Command = new DatabaseCommandQueue("MyRunUO: Characeter database updated in {0:F1} seconds", + m_Command = new DatabaseCommandQueue("MyRunUO: Character database updated in {0:F1} seconds", "MyRunUO Character Database Thread"); if (Config.LoadDataInFile) @@ -306,7 +306,7 @@ namespace Server.Engines.MyRunUO m_Command.Enqueue(text); } - public void ExecuteNonQuery(string format, params string[] args) + public void ExecuteNonQuery(string format, params object[] args) { ExecuteNonQuery(string.Format(format, args)); } @@ -320,10 +320,7 @@ namespace Server.Engines.MyRunUO { if (sb == null) { - if (charIndex > 0) - sb = new StringBuilder(input, 0, charIndex, input.Length + 20); - else - sb = new StringBuilder(input.Length + 20); + sb = charIndex > 0 ? new StringBuilder(input, 0, charIndex, input.Length + 20) : new StringBuilder(input.Length + 20); } sb.Append("&#"); @@ -335,10 +332,7 @@ namespace Server.Engines.MyRunUO { if (sb == null) { - if (charIndex > 0) - sb = new StringBuilder(input, 0, charIndex, input.Length + 20); - else - sb = new StringBuilder(input.Length + 20); + sb = charIndex > 0 ? new StringBuilder(input, 0, charIndex, input.Length + 20) : new StringBuilder(input.Length + 20); } sb.Append(ent); @@ -387,10 +381,7 @@ namespace Server.Engines.MyRunUO } } - if (sb != null) - return sb.ToString(); - - return input; + return sb != null ? sb.ToString() : input; } public void InsertMobile(Mobile mob) @@ -504,7 +495,7 @@ namespace Server.Engines.MyRunUO public void InsertItems(Mobile mob) { - ArrayList items = m_Items; + List items = m_Items; items.AddRange(mob.Items); string serial = mob.Serial.Value.ToString(); @@ -518,7 +509,7 @@ namespace Server.Engines.MyRunUO for (int i = 0; i < items.Count; ++i) { - Item item = (Item)items[i]; + Item item = items[i]; if (!LayerComparer.IsValid(item)) break; @@ -541,7 +532,7 @@ namespace Server.Engines.MyRunUO InsertItem(serial, index++, mob.FacialHairItemID, mob.FacialHairHue); if (mob.HairItemID != 0 && !hideHair) - InsertItem(serial, index++, mob.HairItemID, mob.HairHue); + InsertItem(serial, index, mob.HairItemID, mob.HairHue); items.Clear(); } @@ -573,6 +564,7 @@ namespace Server.Engines.MyRunUO } catch { + // ignored } } diff --git a/Scripts/Engines/MyRunUO/MyRunUOStatus.cs b/Scripts/Engines/MyRunUO/MyRunUOStatus.cs index 034ec06b6..1dfc107df 100644 --- a/Scripts/Engines/MyRunUO/MyRunUOStatus.cs +++ b/Scripts/Engines/MyRunUO/MyRunUOStatus.cs @@ -39,7 +39,6 @@ namespace Server.Engines.MyRunUO if (m_Command != null && !m_Command.HasCompleted) return; - DateTime start = DateTime.UtcNow; Console.WriteLine("MyRunUO: Updating status database"); try diff --git a/Scripts/Engines/Party/AddPartyTarget.cs b/Scripts/Engines/Party/AddPartyTarget.cs index f52152a77..b54f92379 100644 --- a/Scripts/Engines/Party/AddPartyTarget.cs +++ b/Scripts/Engines/Party/AddPartyTarget.cs @@ -21,7 +21,8 @@ namespace Server.Engines.PartySystem else if (p != null && p.Leader != from) from.SendLocalizedMessage(1005453); // You may only add members to the party if you are the leader. else if (m.Party is Mobile) - return; + { + } else if (p != null && p.Members.Count + p.Candidates.Count >= Party.Capacity) from.SendLocalizedMessage(1008095); // You may only have 10 in your party (this includes candidates). else if (!m.Player && m.Body.IsHuman) diff --git a/Scripts/Engines/Party/DeclineTimer.cs b/Scripts/Engines/Party/DeclineTimer.cs index 15d7a5ebe..198696ea6 100644 --- a/Scripts/Engines/Party/DeclineTimer.cs +++ b/Scripts/Engines/Party/DeclineTimer.cs @@ -1,11 +1,12 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Engines.PartySystem { public class DeclineTimer : Timer { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); private Mobile m_Mobile, m_Leader; private DeclineTimer(Mobile m, Mobile leader) : base(TimeSpan.FromSeconds(30.0)) @@ -16,7 +17,7 @@ namespace Server.Engines.PartySystem public static void Start(Mobile m, Mobile leader) { - DeclineTimer t = (DeclineTimer)m_Table[m]; + DeclineTimer t = m_Table[m]; t?.Stop(); @@ -32,4 +33,4 @@ namespace Server.Engines.PartySystem PartyCommands.Handler.OnDecline(m_Mobile, m_Leader); } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Pathing/FastAStarAlgorithm.cs b/Scripts/Engines/Pathing/FastAStarAlgorithm.cs index d50b81506..d0ecc65b2 100644 --- a/Scripts/Engines/Pathing/FastAStarAlgorithm.cs +++ b/Scripts/Engines/Pathing/FastAStarAlgorithm.cs @@ -247,7 +247,6 @@ namespace Server.PathAlgorithms.FastAStar int px = p % AreaSize; int py = p / AreaSize % AreaSize; int pz = m_Nodes[p].z; - int x, y, z; Point3D p3D = new Point3D(px + m_xOffset, py + m_yOffset, pz); @@ -256,6 +255,8 @@ namespace Server.PathAlgorithms.FastAStar for (int i = 0; i < 8; ++i) { + int x; + int y; switch (i) { default: @@ -299,7 +300,7 @@ namespace Server.PathAlgorithms.FastAStar if (x < 0 || x >= AreaSize || y < 0 || y >= AreaSize) continue; - if (CalcMoves.CheckMovement(m, map, p3D, (Direction)i, out z)) + if (CalcMoves.CheckMovement(m, map, p3D, (Direction)i, out int z)) { int idx = GetIndex(x + m_xOffset, y + m_yOffset, z); diff --git a/Scripts/Engines/Pathing/FastMovement.cs b/Scripts/Engines/Pathing/FastMovement.cs index ba079494d..5c764a4ae 100644 --- a/Scripts/Engines/Pathing/FastMovement.cs +++ b/Scripts/Engines/Pathing/FastMovement.cs @@ -53,8 +53,6 @@ namespace Server.Movement return false; } - int startZ, startTop; - IEnumerable itemsStart, itemsForward, itemsLeft, itemsRight; bool ignoreMovableImpassables = MovementImpl.IgnoreMovableImpassables; @@ -85,7 +83,7 @@ namespace Server.Movement itemsRight = Enumerable.Empty(); } - GetStartZ(m, map, loc, itemsStart, out startZ, out startTop); + GetStartZ(m, map, loc, itemsStart, out int startZ, out int startTop); List list = null; @@ -95,13 +93,11 @@ namespace Server.Movement if (moveIsOk && checkDiagonals) { - int hold; - if (m.Player && m.AccessLevel < AccessLevel.GameMaster) { MovementPool.AcquireMoveCache(ref list, itemsLeft); - if (!Check(map, m, list, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, out hold)) + if (!Check(map, m, list, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, out _)) { moveIsOk = false; } @@ -109,7 +105,7 @@ namespace Server.Movement { MovementPool.AcquireMoveCache(ref list, itemsRight); - if (!Check(map, m, list, xRight, yRight, startTop, startZ, m.CanSwim, m.CantWalk, out hold)) + if (!Check(map, m, list, xRight, yRight, startTop, startZ, m.CanSwim, m.CantWalk, out _)) moveIsOk = false; } } @@ -117,11 +113,11 @@ namespace Server.Movement { MovementPool.AcquireMoveCache(ref list, itemsLeft); - if (!Check(map, m, list, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, out hold)) + if (!Check(map, m, list, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, out _)) { MovementPool.AcquireMoveCache(ref list, itemsRight); - if (!Check(map, m, list, xRight, yRight, startTop, startZ, m.CanSwim, m.CantWalk, out hold)) + if (!Check(map, m, list, xRight, yRight, startTop, startZ, m.CanSwim, m.CantWalk, out _)) moveIsOk = false; } } @@ -136,7 +132,8 @@ namespace Server.Movement public bool CheckMovement(Mobile m, Direction d, out int newZ) { - if (!Enabled && _Successor != null) return _Successor.CheckMovement(m, d, out newZ); + if (!Enabled && _Successor != null) + return _Successor.CheckMovement(m, d, out newZ); return CheckMovement(m, m.Map, m.Location, d, out newZ); } diff --git a/Scripts/Engines/Pathing/Movement.cs b/Scripts/Engines/Pathing/Movement.cs index ef466e6b2..4c84e8eb5 100644 --- a/Scripts/Engines/Pathing/Movement.cs +++ b/Scripts/Engines/Pathing/Movement.cs @@ -12,14 +12,12 @@ namespace Server.Movement private const TileFlag ImpassableSurface = TileFlag.Impassable | TileFlag.Surface; - private List[] m_MobPools = new List[3] - { + private List[] m_MobPools = { new List(), new List(), new List() }; - private List[] m_Pools = new List[4] - { + private List[] m_Pools = { new List(), new List(), new List(), new List() }; @@ -64,8 +62,6 @@ namespace Server.Movement return false; } - int startZ, startTop; - List itemsStart = m_Pools[0]; List itemsForward = m_Pools[1]; List itemsLeft = m_Pools[2]; @@ -217,27 +213,25 @@ namespace Server.Movement } } - GetStartZ(m, map, loc, itemsStart, out startZ, out startTop); + GetStartZ(m, map, loc, itemsStart, out int startZ, out int startTop); bool moveIsOk = Check(map, m, itemsForward, mobsForward, xForward, yForward, startTop, startZ, m.CanSwim, m.CantWalk, out newZ); if (moveIsOk && checkDiagonals) { - int hold; - if (m.Player && m.AccessLevel < AccessLevel.GameMaster) { if (!Check(map, m, itemsLeft, mobsLeft, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, - out hold) || !Check(map, m, itemsRight, mobsRight, xRight, yRight, startTop, startZ, m.CanSwim, - m.CantWalk, out hold)) + out _) || !Check(map, m, itemsRight, mobsRight, xRight, yRight, startTop, startZ, m.CanSwim, + m.CantWalk, out _)) moveIsOk = false; } else { if (!Check(map, m, itemsLeft, mobsLeft, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, - out hold) && !Check(map, m, itemsRight, mobsRight, xRight, yRight, startTop, startZ, m.CanSwim, - m.CantWalk, out hold)) + out _) && !Check(map, m, itemsRight, mobsRight, xRight, yRight, startTop, startZ, m.CanSwim, + m.CantWalk, out _)) moveIsOk = false; } } @@ -358,7 +352,6 @@ namespace Server.Movement int itemZ = tile.Z; int itemTop = itemZ; int ourZ = itemZ + itemData.CalcHeight; - int ourTop = ourZ + PersonHeight; int testTop = checkTop; if (moveIsOk) @@ -415,7 +408,6 @@ namespace Server.Movement int itemZ = item.Z; int itemTop = itemZ; int ourZ = itemZ + itemData.CalcHeight; - int ourTop = ourZ + PersonHeight; int testTop = checkTop; if (moveIsOk) @@ -458,7 +450,6 @@ namespace Server.Movement if (considerLand && !landBlocks && stepTop >= landZ) { int ourZ = landCenter; - int ourTop = ourZ + PersonHeight; int testTop = checkTop; if (ourZ + PersonHeight > testTop) diff --git a/Scripts/Engines/Pathing/MovementPath.cs b/Scripts/Engines/Pathing/MovementPath.cs index 4f2abb218..cf70fd71c 100644 --- a/Scripts/Engines/Pathing/MovementPath.cs +++ b/Scripts/Engines/Pathing/MovementPath.cs @@ -94,9 +94,9 @@ namespace Server } } - public static void Path_OnTarget(Mobile from, object obj) + public static void Path_OnTarget(Mobile from, object targeted) { - if (!(obj is IPoint3D p)) + if (!(targeted is IPoint3D p)) return; SpellHelper.GetSurfaceTop(ref p); @@ -104,47 +104,6 @@ namespace Server Path(from, p, FastAStarAlgorithm.Instance, "Fast", 0); Path(from, p, SlowAStarAlgorithm.Instance, "Slow", 2); OverrideAlgorithm = null; - - /*MovementPath path = new MovementPath( from, new Point3D( p ) ); - - if ( !path.Success ) - { - from.SendMessage( "No path to there could be found." ); - } - else - { - //for ( int i = 0; i < path.Directions.Length; ++i ) - // Timer.DelayCall( TimeSpan.FromSeconds( 0.1 + (i * 0.3) ), new TimerStateCallback( Pathfind ), new object[]{ from, path.Directions[i] } ); - int x = from.X; - int y = from.Y; - int z = from.Z; - - for ( int i = 0; i < path.Directions.Length; ++i ) - { - Movement.Movement.Offset( path.Directions[i], ref x, ref y ); - - new Items.RecallRune().MoveToWorld( new Point3D( x, y, z ), from.Map ); - } - }*/ - } - - public static void Pathfind(object state) - { - object[] states = (object[])state; - Mobile from = (Mobile)states[0]; - Direction d = (Direction)states[1]; - - try - { - from.Direction = d; - from.NetState.BlockAllPackets = true; - from.Move(d); - from.NetState.BlockAllPackets = false; - from.ProcessDelta(); - } - catch - { - } } } } \ No newline at end of file diff --git a/Scripts/Engines/Pathing/PathAlgorithm.cs b/Scripts/Engines/Pathing/PathAlgorithm.cs index a3edcf4aa..07500b988 100644 --- a/Scripts/Engines/Pathing/PathAlgorithm.cs +++ b/Scripts/Engines/Pathing/PathAlgorithm.cs @@ -2,8 +2,7 @@ namespace Server.PathAlgorithms { public abstract class PathAlgorithm { - private static Direction[] m_CalcDirections = new Direction[9] - { + private static Direction[] m_CalcDirections = { Direction.Up, Direction.North, Direction.Right, diff --git a/Scripts/Engines/Pathing/SlowAStarAlgorithm.cs b/Scripts/Engines/Pathing/SlowAStarAlgorithm.cs index 5a6511f90..c0221c02a 100644 --- a/Scripts/Engines/Pathing/SlowAStarAlgorithm.cs +++ b/Scripts/Engines/Pathing/SlowAStarAlgorithm.cs @@ -65,20 +65,19 @@ namespace Server.PathAlgorithms.SlowAStar PathNode[] closed = m_Closed, open = m_Open, successors = m_Successors; Direction[] path = m_Path; - int closedCount = 0, openCount = 0, sucCount = 0, pathCount = 0; - int popIndex, curF; - int x, y, z; + int closedCount = 0, openCount = 0; + int pathCount = 0; int depth = 0; - int xBacktrack, yBacktrack, zBacktrack, iBacktrack = 0; + int iBacktrack = 0; open[openCount++] = startNode; while (openCount > 0) { curNode = open[0]; - curF = curNode.g + curNode.h; - popIndex = 0; + int curF = curNode.g + curNode.h; + int popIndex = 0; for (int i = 1; i < openCount; ++i) if (open[i].g + open[i].h < curF) @@ -95,9 +94,9 @@ namespace Server.PathAlgorithms.SlowAStar closed[closedCount++] = curNode; - xBacktrack = curNode.px; - yBacktrack = curNode.py; - zBacktrack = curNode.pz; + int xBacktrack = curNode.px; + int yBacktrack = curNode.py; + int zBacktrack = curNode.pz; if (pathCount == MaxNodes) break; @@ -148,7 +147,7 @@ namespace Server.PathAlgorithms.SlowAStar for (int i = popIndex; i < openCount; ++i) open[i] = open[i + 1]; - sucCount = 0; + int sucCount = 0; if (bc != null) { @@ -158,6 +157,9 @@ namespace Server.PathAlgorithms.SlowAStar MoveImpl.Goal = goal; + int x; + int y; + int z; for (int i = 0; i < 8; ++i) { switch (i) diff --git a/Scripts/Engines/Plants/MainPlantGump.cs b/Scripts/Engines/Plants/MainPlantGump.cs index b7e97ae40..dfb8bf22c 100644 --- a/Scripts/Engines/Plants/MainPlantGump.cs +++ b/Scripts/Engines/Plants/MainPlantGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Server.Gumps; using Server.Items; using Server.Network; @@ -381,8 +380,7 @@ namespace Server.Engines.Plants } else { - int message; - if (m_Plant.ApplyPotion(effects[0], true, out message)) + if (m_Plant.ApplyPotion(effects[0], true, out int message)) { from.SendLocalizedMessage(1061884); // You don't have any strong potions of that type in your pack. diff --git a/Scripts/Engines/Plants/MiscItems/GreenThorns.cs b/Scripts/Engines/Plants/MiscItems/GreenThorns.cs index df0633400..39b335a81 100644 --- a/Scripts/Engines/Plants/MiscItems/GreenThorns.cs +++ b/Scripts/Engines/Plants/MiscItems/GreenThorns.cs @@ -35,7 +35,7 @@ namespace Server.Items return; } - if (!from.CanBeginAction(typeof(GreenThorns))) + if (!from.CanBeginAction()) { from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1061908); // * You must wait a while before planting another thorn. * @@ -80,7 +80,7 @@ namespace Server.Items return; } - if (!from.CanBeginAction(typeof(GreenThorns))) + if (!from.CanBeginAction()) { from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1061908); // * You must wait a while before planting another thorn. * @@ -117,7 +117,7 @@ namespace Server.Items from.NonlocalOverheadMessage(MessageType.Emote, 0x961, 1061915, from.Name); // * ~1_PLAYER_NAME~ pushes a strange green thorn into the ground. * - from.BeginAction(typeof(GreenThorns)); + from.BeginAction(); new EndActionTimer(from).Start(); effect.Start(); @@ -143,7 +143,7 @@ namespace Server.Items protected override void OnTick() { - m_From.EndAction(typeof(GreenThorns)); + m_From.EndAction(); } } } diff --git a/Scripts/Engines/Plants/MiscItems/OrangePetals.cs b/Scripts/Engines/Plants/MiscItems/OrangePetals.cs index a640d6f66..8f89e3569 100644 --- a/Scripts/Engines/Plants/MiscItems/OrangePetals.cs +++ b/Scripts/Engines/Plants/MiscItems/OrangePetals.cs @@ -1,12 +1,13 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Network; namespace Server.Items { public class OrangePetals : Item { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public OrangePetals() : this(1) @@ -137,4 +138,4 @@ namespace Server.Items public Timer Timer{ get; } } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Plants/PlantItem.cs b/Scripts/Engines/Plants/PlantItem.cs index 7fa9ce307..e65d970a4 100644 --- a/Scripts/Engines/Plants/PlantItem.cs +++ b/Scripts/Engines/Plants/PlantItem.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using Server.ContextMenus; using Server.Gumps; @@ -150,14 +149,7 @@ namespace Server.Engines.Plants if (!(RootParent is Mobile owner)) return false; - if (owner.Backpack != null && IsChildOf(owner.Backpack)) - return true; - - BankBox bank = owner.FindBankNoCreate(); - if (bank != null && IsChildOf(bank)) - return true; - - return false; + return IsChildOf(owner.Backpack) || IsChildOf(owner.FindBankNoCreate()); } } @@ -170,7 +162,7 @@ namespace Server.Engines.Plants [CommandProperty(AccessLevel.GameMaster)] public bool Reproduces => PlantHueInfo.CanReproduce(PlantHue) && PlantTypeInfo.CanReproduce(PlantType); - public static ArrayList Plants{ get; } = new ArrayList(); + public static List Plants{ get; } = new List(); [CommandProperty(AccessLevel.GameMaster)] public SecureLevel Level{ get; set; } diff --git a/Scripts/Engines/Plants/PlantPourTarget.cs b/Scripts/Engines/Plants/PlantPourTarget.cs index 0fd47354b..292746970 100644 --- a/Scripts/Engines/Plants/PlantPourTarget.cs +++ b/Scripts/Engines/Plants/PlantPourTarget.cs @@ -22,8 +22,8 @@ namespace Server.Engines.Plants if (!m_Plant.Deleted && m_Plant.PlantStatus < PlantStatus.DecorativePlant && from.InRange(m_Plant.GetWorldLocation(), 3) && m_Plant.IsUsableBy(from)) { - if (from.HasGump(typeof(MainPlantGump))) - from.CloseGump(typeof(MainPlantGump)); + if (from.HasGump()) + from.CloseGump(); from.SendGump(new MainPlantGump(m_Plant)); } diff --git a/Scripts/Engines/Plants/PlantSystem.cs b/Scripts/Engines/Plants/PlantSystem.cs index 7e49a696d..2ad368e9a 100644 --- a/Scripts/Engines/Plants/PlantSystem.cs +++ b/Scripts/Engines/Plants/PlantSystem.cs @@ -1,7 +1,5 @@ using System; -using System.Collections; using System.Collections.Generic; -using Server.Items; using Server.Misc; namespace Server.Engines.Plants @@ -428,12 +426,12 @@ namespace Server.Engines.Plants public static void GrowAll() { - ArrayList plants = PlantItem.Plants; + List plants = PlantItem.Plants; DateTime now = DateTime.UtcNow; for (int i = plants.Count - 1; i >= 0; --i) { - PlantItem plant = (PlantItem)plants[i]; + PlantItem plant = plants[i]; if (plant.IsGrowable && !(plant.RootParent is Mobile) && now >= plant.PlantSystem.NextGrowth) plant.PlantSystem.DoGrowthCheck(); @@ -476,7 +474,7 @@ namespace Server.Engines.Plants return; } - ApplyBeneficEffects(); + ApplyBeneficialEffects(); if (!ApplyMaladiesEffects()) // Dead return; @@ -486,7 +484,7 @@ namespace Server.Engines.Plants UpdateMaladies(); } - private void ApplyBeneficEffects() + private void ApplyBeneficialEffects() { if (PoisonPotion >= Infestation) { diff --git a/Scripts/Engines/Quests/Ambitious Solen Queen/Mobiles/AmbitiousSolenQueen.cs b/Scripts/Engines/Quests/Ambitious Solen Queen/Mobiles/AmbitiousSolenQueen.cs index cdbdf3038..f4e262ea6 100644 --- a/Scripts/Engines/Quests/Ambitious Solen Queen/Mobiles/AmbitiousSolenQueen.cs +++ b/Scripts/Engines/Quests/Ambitious Solen Queen/Mobiles/AmbitiousSolenQueen.cs @@ -44,9 +44,9 @@ namespace Server.Engines.Quests.Ambitious } else { - QuestObjective obj = qs.FindObjective(typeof(ReturnAfterKillsObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } @@ -56,7 +56,9 @@ namespace Server.Engines.Quests.Ambitious } else { - if (qs.FindObjective(typeof(GetRewardObjective)) is GetRewardObjective lastObj && !lastObj.Completed) + GetRewardObjective lastObj = qs.FindObjective(); + + if (lastObj?.Completed == false) { bool bagOfSending = lastObj.BagOfSending; bool powderOfTranslocation = lastObj.PowderOfTranslocation; @@ -95,9 +97,9 @@ namespace Server.Engines.Quests.Ambitious if (from is PlayerMobile player) if (player.Quest is AmbitiousQueenQuest qs && qs.RedSolen == RedSolen) { - QuestObjective obj = qs.FindObjective(typeof(GatherFungiObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) if (dropped is ZoogiFungus fungi) { if (fungi.Amount >= 50) diff --git a/Scripts/Engines/Quests/Collector/Items/EnchantedPaints.cs b/Scripts/Engines/Quests/Collector/Items/EnchantedPaints.cs index 102b9351c..7ef2a1df1 100644 --- a/Scripts/Engines/Quests/Collector/Items/EnchantedPaints.cs +++ b/Scripts/Engines/Quests/Collector/Items/EnchantedPaints.cs @@ -77,49 +77,53 @@ namespace Server.Engines.Quests.Collector { QuestSystem qs = player.Quest; - if (qs is CollectorQuest) - if (qs.FindObjective(typeof(CaptureImagesObjective)) is CaptureImagesObjective obj && !obj.Completed) + if (!(qs is CollectorQuest)) + return; + + CaptureImagesObjective obj = qs.FindObjective(); + + if (obj?.Completed != false) + return; + + if (targeted is Mobile) + { + CaptureResponse response = obj.CaptureImage( + targeted.GetType().Name == "GreaterMongbat" + ? new Mongbat().GetType() + : targeted.GetType(), out ImageType image); + + switch (response) { - if (targeted is Mobile) + case CaptureResponse.Valid: { - CaptureResponse response = obj.CaptureImage( - targeted.GetType().Name == "GreaterMongbat" - ? new Mongbat().GetType() - : targeted.GetType(), out ImageType image); + player.SendLocalizedMessage( + 1055125); // The enchanted paints swirl for a moment then an image begins to take shape. *Click* + player.AddToBackpack(new PaintedImage(image)); - switch (response) - { - case CaptureResponse.Valid: - { - player.SendLocalizedMessage( - 1055125); // The enchanted paints swirl for a moment then an image begins to take shape. *Click* - player.AddToBackpack(new PaintedImage(image)); - - break; - } - case CaptureResponse.AlreadyDone: - { - player.SendAsciiMessage(0x2C, - "You have already captured the image of this creature"); - - break; - } - case CaptureResponse.Invalid: - { - player.SendLocalizedMessage( - 1055124); // You have no interest in capturing the image of this creature. - - break; - } - } + break; } - else + case CaptureResponse.AlreadyDone: { - player.SendAsciiMessage(0x35, "You have no interest in that."); - } + player.SendAsciiMessage(0x2C, + "You have already captured the image of this creature"); - return; + break; + } + case CaptureResponse.Invalid: + { + player.SendLocalizedMessage( + 1055124); // You have no interest in capturing the image of this creature. + + break; + } } + } + else + { + player.SendAsciiMessage(0x35, "You have no interest in that."); + } + + return; } from.SendLocalizedMessage(1010085); // You cannot use this. diff --git a/Scripts/Engines/Quests/Collector/Items/ImageType.cs b/Scripts/Engines/Quests/Collector/Items/ImageTypeInfo.cs similarity index 78% rename from Scripts/Engines/Quests/Collector/Items/ImageType.cs rename to Scripts/Engines/Quests/Collector/Items/ImageTypeInfo.cs index 8b8bb405a..6df35d442 100644 --- a/Scripts/Engines/Quests/Collector/Items/ImageType.cs +++ b/Scripts/Engines/Quests/Collector/Items/ImageTypeInfo.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Linq; using Server.Mobiles; namespace Server.Engines.Quests.Collector @@ -56,6 +56,8 @@ namespace Server.Engines.Quests.Collector new ImageTypeInfo(9746, typeof(Juggernaut), 55, 38) }; + private static ImageType[] m_ImageTypeList; + public ImageTypeInfo(int figurine, Type type, int x, int y) { Figurine = figurine; @@ -70,34 +72,26 @@ namespace Server.Engines.Quests.Collector public int Name => Figurine < 0x4000 ? 1020000 + Figurine : 1078872 + Figurine; public int X{ get; } - public int Y{ get; } public static ImageTypeInfo Get(ImageType image) { int index = (int)image; - if (index >= 0 && index < m_Table.Length) - return m_Table[index]; - return m_Table[0]; + return m_Table[index >= 0 && index < m_Table.Length ? index : 0]; } public static ImageType[] RandomList(int count) { - ArrayList list = new ArrayList(m_Table.Length); - for (int i = 0; i < m_Table.Length; i++) - list.Add((ImageType)i); - - ImageType[] images = new ImageType[count]; - - for (int i = 0; i < images.Length; i++) + if (m_ImageTypeList == null) { - int index = Utility.Random(list.Count); - images[i] = (ImageType)list[index]; - - list.RemoveAt(index); + m_ImageTypeList = new ImageType[m_Table.Length]; + for (int i = 0; i < m_Table.Length; i++) + m_ImageTypeList[i] = (ImageType)i; } - - return images; + + ImageType[] array = m_ImageTypeList.ToArray(); + Utility.Shuffle(array); + return array.Take(count).ToArray(); } } } \ No newline at end of file diff --git a/Scripts/Engines/Quests/Collector/Mobiles/AlbertaGiacco.cs b/Scripts/Engines/Quests/Collector/Mobiles/AlbertaGiacco.cs index b46c7569e..9248be5fe 100644 --- a/Scripts/Engines/Quests/Collector/Mobiles/AlbertaGiacco.cs +++ b/Scripts/Engines/Quests/Collector/Mobiles/AlbertaGiacco.cs @@ -58,9 +58,9 @@ namespace Server.Engines.Quests.Collector { Direction = GetDirectionTo(player); - QuestObjective obj = qs.FindObjective(typeof(FindAlbertaObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); else if (qs.IsObjectiveInProgress(typeof(SitOnTheStoolObjective))) qs.AddConversation(new AlbertaStoolConversation()); diff --git a/Scripts/Engines/Quests/Collector/Mobiles/ElwoodMcCarrin.cs b/Scripts/Engines/Quests/Collector/Mobiles/ElwoodMcCarrin.cs index 56a640fba..f2a3bc31e 100644 --- a/Scripts/Engines/Quests/Collector/Mobiles/ElwoodMcCarrin.cs +++ b/Scripts/Engines/Quests/Collector/Mobiles/ElwoodMcCarrin.cs @@ -55,9 +55,9 @@ namespace Server.Engines.Quests.Collector } else { - QuestObjective obj = qs.FindObjective(typeof(ReturnPearlsObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } @@ -71,9 +71,9 @@ namespace Server.Engines.Quests.Collector } else { - obj = qs.FindObjective(typeof(ReturnPaintingObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } @@ -91,9 +91,9 @@ namespace Server.Engines.Quests.Collector } else { - obj = qs.FindObjective(typeof(ReturnAutographObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } @@ -111,9 +111,9 @@ namespace Server.Engines.Quests.Collector } else { - obj = qs.FindObjective(typeof(ReturnToysObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); @@ -124,9 +124,9 @@ namespace Server.Engines.Quests.Collector } else { - obj = qs.FindObjective(typeof(MakeRoomObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { if (GiveReward(player)) { diff --git a/Scripts/Engines/Quests/Collector/Mobiles/GabrielPiete.cs b/Scripts/Engines/Quests/Collector/Mobiles/GabrielPiete.cs index a83e4f81f..183728207 100644 --- a/Scripts/Engines/Quests/Collector/Mobiles/GabrielPiete.cs +++ b/Scripts/Engines/Quests/Collector/Mobiles/GabrielPiete.cs @@ -60,9 +60,9 @@ namespace Server.Engines.Quests.Collector { Direction = GetDirectionTo(player); - QuestObjective obj = qs.FindObjective(typeof(FindGabrielObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } @@ -72,9 +72,9 @@ namespace Server.Engines.Quests.Collector } else { - obj = qs.FindObjective(typeof(ReturnSheetMusicObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); else if (qs.IsObjectiveInProgress(typeof(ReturnAutographObjective))) qs.AddConversation(new GabrielIgnoreConversation()); diff --git a/Scripts/Engines/Quests/Collector/Mobiles/Impresario.cs b/Scripts/Engines/Quests/Collector/Mobiles/Impresario.cs index bd9c4073b..30d9de6f6 100644 --- a/Scripts/Engines/Quests/Collector/Mobiles/Impresario.cs +++ b/Scripts/Engines/Quests/Collector/Mobiles/Impresario.cs @@ -20,7 +20,7 @@ namespace Server.Engines.Quests.Collector { InitStats(100, 100, 25); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = false; Body = 0x190; @@ -51,21 +51,25 @@ namespace Server.Engines.Quests.Collector { QuestSystem qs = player.Quest; - if (qs is CollectorQuest) - if (qs.FindObjective(typeof(FindSheetMusicObjective)) is FindSheetMusicObjective obj && !obj.Completed) - { - Direction = GetDirectionTo(player); + if (!(qs is CollectorQuest)) + return; - if (obj.IsInRightTheater()) - { - player.CloseGump(typeof(SheetMusicOfferGump)); - player.SendGump(new SheetMusicOfferGump()); - } - else - { - qs.AddConversation(new NoSheetMusicConversation()); - } + FindSheetMusicObjective obj = qs.FindObjective(); + + if (obj?.Completed == false) + { + Direction = GetDirectionTo(player); + + if (obj.IsInRightTheater()) + { + player.CloseGump(); + player.SendGump(new SheetMusicOfferGump()); } + else + { + qs.AddConversation(new NoSheetMusicConversation()); + } + } } public override void Serialize(GenericWriter writer) @@ -132,25 +136,28 @@ namespace Server.Engines.Quests.Collector { QuestSystem qs = player.Quest; - if (qs is CollectorQuest) - if (qs.FindObjective(typeof(FindSheetMusicObjective)) is FindSheetMusicObjective obj && - !obj.Completed) - { - if (player.Backpack != null && player.Backpack.ConsumeTotal(typeof(Gold), 10)) - { - obj.Complete(); - } - else - { - BankBox bank = player.FindBankNoCreate(); - if (bank != null && bank.ConsumeTotal(typeof(Gold), 10)) - obj.Complete(); + if (!(qs is CollectorQuest)) + return; - else - player.SendLocalizedMessage( - 1055108); // You don't have enough gold to buy the sheet music. - } - } + FindSheetMusicObjective obj = qs.FindObjective(); + + if (obj?.Completed != false) + return; + + if (player.Backpack != null && player.Backpack.ConsumeTotal(typeof(Gold), 10)) + { + obj.Complete(); + } + else + { + BankBox bank = player.FindBankNoCreate(); + if (bank != null && bank.ConsumeTotal(typeof(Gold), 10)) + obj.Complete(); + + else + player.SendLocalizedMessage( + 1055108); // You don't have enough gold to buy the sheet music. + } } } } diff --git a/Scripts/Engines/Quests/Collector/Mobiles/TomasONeerlan.cs b/Scripts/Engines/Quests/Collector/Mobiles/TomasONeerlan.cs index df40f2434..c02534a9a 100644 --- a/Scripts/Engines/Quests/Collector/Mobiles/TomasONeerlan.cs +++ b/Scripts/Engines/Quests/Collector/Mobiles/TomasONeerlan.cs @@ -57,9 +57,9 @@ namespace Server.Engines.Quests.Collector { Direction = GetDirectionTo(player); - QuestObjective obj = qs.FindObjective(typeof(FindTomasObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Item paints = new EnchantedPaints(); @@ -80,9 +80,9 @@ namespace Server.Engines.Quests.Collector } else { - obj = qs.FindObjective(typeof(ReturnImagesObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { player.Backpack?.ConsumeUpTo(typeof(EnchantedPaints), 1); diff --git a/Scripts/Engines/Quests/Core/Items/HornOfRetreat.cs b/Scripts/Engines/Quests/Core/Items/HornOfRetreat.cs index 48eacd7e9..87f9b33c5 100644 --- a/Scripts/Engines/Quests/Core/Items/HornOfRetreat.cs +++ b/Scripts/Engines/Quests/Core/Items/HornOfRetreat.cs @@ -77,8 +77,7 @@ namespace Server.Engines.Quests --Charges; - m_PlayTimer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(PlayTimer_Callback), - from); + m_PlayTimer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => PlayTimer_Callback(from)); } else { @@ -91,10 +90,8 @@ namespace Server.Engines.Quests } } - public virtual void PlayTimer_Callback(object state) + public virtual void PlayTimer_Callback(Mobile from) { - Mobile from = (Mobile)state; - m_PlayTimer = null; HornOfRetreatMoongate gate = new HornOfRetreatMoongate(DestLoc, DestMap, from, Hue); @@ -168,7 +165,7 @@ namespace Server.Engines.Quests public override void UseGate(Mobile m) { - if (m.Region.IsPartOf(typeof(Jail))) + if (m.Region.IsPartOf()) { m.SendLocalizedMessage(1114345); // You'll need a better jailbreak plan than that! } diff --git a/Scripts/Engines/Quests/Core/QuestConversation.cs b/Scripts/Engines/Quests/Core/QuestConversation.cs index 876745dee..ee69935ec 100644 --- a/Scripts/Engines/Quests/Core/QuestConversation.cs +++ b/Scripts/Engines/Quests/Core/QuestConversation.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Network; @@ -58,13 +58,13 @@ namespace Server.Engines.Quests public class QuestConversationsGump : BaseQuestGump { - private ArrayList m_Conversations; + private List m_Conversations; - public QuestConversationsGump(QuestConversation conv) : this(BuildList(conv)) + public QuestConversationsGump(QuestConversation conv) : this(new List{ conv }) { } - public QuestConversationsGump(ArrayList conversations) : base(30, 50) + public QuestConversationsGump(List conversations) : base(30, 50) { m_Conversations = conversations; @@ -101,7 +101,7 @@ namespace Server.Engines.Quests for (int i = 0; i < conversations.Count; ++i) { - QuestConversation conv = (QuestConversation)conversations[conversations.Count - 1 - i]; + QuestConversation conv = conversations[conversations.Count - 1 - i]; if (i > 0) { @@ -125,7 +125,7 @@ namespace Server.Engines.Quests { for (int i = m_Conversations.Count - 1; i >= 0; --i) { - QuestConversation qc = (QuestConversation)m_Conversations[i]; + QuestConversation qc = m_Conversations[i]; if (!qc.HasBeenRead) { diff --git a/Scripts/Engines/Quests/Core/QuestObjective.cs b/Scripts/Engines/Quests/Core/QuestObjective.cs index ca0c819d0..b8d5b24e5 100644 --- a/Scripts/Engines/Quests/Core/QuestObjective.cs +++ b/Scripts/Engines/Quests/Core/QuestObjective.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Items; using Server.Mobiles; @@ -164,13 +164,13 @@ namespace Server.Engines.Quests public class QuestObjectivesGump : BaseQuestGump { - private ArrayList m_Objectives; + private List m_Objectives; - public QuestObjectivesGump(QuestObjective obj) : this(BuildList(obj)) + public QuestObjectivesGump(QuestObjective obj) : this(new List{ obj }) { } - public QuestObjectivesGump(ArrayList objectives) : base(90, 50) + public QuestObjectivesGump(List objectives) : base(90, 50) { m_Objectives = objectives; @@ -217,7 +217,7 @@ namespace Server.Engines.Quests for (int i = 0; i < objectives.Count; ++i) { - QuestObjective obj = (QuestObjective)objectives[objectives.Count - 1 - i]; + QuestObjective obj = objectives[objectives.Count - 1 - i]; if (i > 0) { @@ -242,7 +242,7 @@ namespace Server.Engines.Quests { for (int i = m_Objectives.Count - 1; i >= 0; --i) { - QuestObjective obj = (QuestObjective)m_Objectives[i]; + QuestObjective obj = m_Objectives[i]; if (!obj.HasBeenRead) { diff --git a/Scripts/Engines/Quests/Core/QuestSerializer.cs b/Scripts/Engines/Quests/Core/QuestSerializer.cs index d37999176..427df976a 100644 --- a/Scripts/Engines/Quests/Core/QuestSerializer.cs +++ b/Scripts/Engines/Quests/Core/QuestSerializer.cs @@ -44,7 +44,6 @@ namespace Server.Engines.Quests switch (encoding) { default: - case 0x00: // null { return null; } @@ -76,7 +75,6 @@ namespace Server.Engines.Quests switch (encoding) { default: - case 0x00: // null { return null; } @@ -116,7 +114,6 @@ namespace Server.Engines.Quests switch (encoding) { default: - case 0x00: // null { return null; } @@ -156,7 +153,6 @@ namespace Server.Engines.Quests switch (encoding) { default: - case 0x00: // null { return null; } diff --git a/Scripts/Engines/Quests/Core/QuestSystem.cs b/Scripts/Engines/Quests/Core/QuestSystem.cs index d925daca0..975a08b40 100644 --- a/Scripts/Engines/Quests/Core/QuestSystem.cs +++ b/Scripts/Engines/Quests/Core/QuestSystem.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using Server.ContextMenus; using Server.Engines.Quests.Ambitious; @@ -44,8 +43,8 @@ namespace Server.Engines.Quests public QuestSystem(PlayerMobile from) { From = from; - Objectives = new ArrayList(); - Conversations = new ArrayList(); + Objectives = new List(); + Conversations = new List(); } public QuestSystem() @@ -64,9 +63,9 @@ namespace Server.Engines.Quests public PlayerMobile From{ get; set; } - public ArrayList Objectives{ get; set; } + public List Objectives{ get; set; } - public ArrayList Conversations{ get; set; } + public List Conversations{ get; set; } public virtual void StartTimer() { @@ -87,7 +86,7 @@ namespace Server.Engines.Quests { for (int i = Objectives.Count - 1; i >= 0; --i) { - QuestObjective obj = (QuestObjective)Objectives[i]; + QuestObjective obj = Objectives[i]; if (obj.GetTimerEvent()) obj.CheckProgress(); @@ -98,7 +97,7 @@ namespace Server.Engines.Quests { for (int i = Objectives.Count - 1; i >= 0; --i) { - QuestObjective obj = (QuestObjective)Objectives[i]; + QuestObjective obj = Objectives[i]; if (obj.GetKillEvent(creature, corpse)) obj.OnKill(creature, corpse); @@ -109,7 +108,7 @@ namespace Server.Engines.Quests { for (int i = Objectives.Count - 1; i >= 0; --i) { - QuestObjective obj = (QuestObjective)Objectives[i]; + QuestObjective obj = Objectives[i]; if (obj.IgnoreYoungProtection(from)) return true; @@ -130,7 +129,7 @@ namespace Server.Engines.Quests { int count = reader.ReadEncodedInt(); - Objectives = new ArrayList(count); + Objectives = new List(count); for (int i = 0; i < count; ++i) { @@ -145,7 +144,7 @@ namespace Server.Engines.Quests count = reader.ReadEncodedInt(); - Conversations = new ArrayList(count); + Conversations = new List(count); for (int i = 0; i < count; ++i) { @@ -179,12 +178,12 @@ namespace Server.Engines.Quests writer.WriteEncodedInt(Objectives.Count); for (int i = 0; i < Objectives.Count; ++i) - QuestSerializer.Serialize(referenceTable, (QuestObjective)Objectives[i], writer); + QuestSerializer.Serialize(referenceTable, Objectives[i], writer); writer.WriteEncodedInt(Conversations.Count); for (int i = 0; i < Conversations.Count; ++i) - QuestSerializer.Serialize(referenceTable, (QuestConversation)Conversations[i], writer); + QuestSerializer.Serialize(referenceTable, Conversations[i], writer); ChildSerialize(writer); } @@ -198,14 +197,27 @@ namespace Server.Engines.Quests { QuestObjective obj = FindObjective(type); - return obj != null && !obj.Completed; + return obj?.Completed == false; + } + + public T FindObjective() where T : QuestObjective + { + for (int i = Objectives.Count - 1; i >= 0; --i) + { + QuestObjective obj = Objectives[i]; + + if (obj is T t) + return t; + } + + return null; } public QuestObjective FindObjective(Type type) { for (int i = Objectives.Count - 1; i >= 0; --i) { - QuestObjective obj = (QuestObjective)Objectives[i]; + QuestObjective obj = Objectives[i]; if (obj.GetType() == type) return obj; @@ -232,7 +244,7 @@ namespace Server.Engines.Quests public virtual void ShowQuestLogUpdated() { - From.CloseGump(typeof(QuestLogUpdatedGump)); + From.CloseGump(); From.SendGump(new QuestLogUpdatedGump(this)); } @@ -240,14 +252,14 @@ namespace Server.Engines.Quests { if (Objectives.Count > 0) { - From.CloseGump(typeof(QuestItemInfoGump)); - From.CloseGump(typeof(QuestLogUpdatedGump)); - From.CloseGump(typeof(QuestObjectivesGump)); - From.CloseGump(typeof(QuestConversationsGump)); + From.CloseGump(); + From.CloseGump(); + From.CloseGump(); + From.CloseGump(); From.SendGump(new QuestObjectivesGump(Objectives)); - QuestObjective last = (QuestObjective)Objectives[Objectives.Count - 1]; + QuestObjective last = Objectives[Objectives.Count - 1]; if (last.Info != null) From.SendGump(new QuestItemInfoGump(last.Info)); @@ -258,13 +270,13 @@ namespace Server.Engines.Quests { if (Conversations.Count > 0) { - From.CloseGump(typeof(QuestItemInfoGump)); - From.CloseGump(typeof(QuestObjectivesGump)); - From.CloseGump(typeof(QuestConversationsGump)); + From.CloseGump(); + From.CloseGump(); + From.CloseGump(); From.SendGump(new QuestConversationsGump(Conversations)); - QuestConversation last = (QuestConversation)Conversations[Conversations.Count - 1]; + QuestConversation last = Conversations[Conversations.Count - 1]; if (last.Info != null) From.SendGump(new QuestItemInfoGump(last.Info)); @@ -348,14 +360,10 @@ namespace Server.Engines.Quests if (conv.Logged) Conversations.Add(conv); - From.CloseGump(typeof(QuestItemInfoGump)); - From.CloseGump(typeof(QuestObjectivesGump)); - From.CloseGump(typeof(QuestConversationsGump)); - - if (conv.Logged) - From.SendGump(new QuestConversationsGump(Conversations)); - else - From.SendGump(new QuestConversationsGump(conv)); + From.CloseGump(); + From.CloseGump(); + From.CloseGump(); + From.SendGump(conv.Logged ? new QuestConversationsGump(Conversations) : new QuestConversationsGump(conv)); if (conv.Info != null) From.SendGump(new QuestItemInfoGump(conv.Info)); @@ -387,9 +395,7 @@ namespace Server.Engines.Quests public static bool CanOfferQuest(Mobile check, Type questType) { - bool inRestartPeriod; - - return CanOfferQuest(check, questType, out inRestartPeriod); + return CanOfferQuest(check, questType, out _); } public static bool CanOfferQuest(Mobile check, Type questType, out bool inRestartPeriod) @@ -399,7 +405,7 @@ namespace Server.Engines.Quests if (!(check is PlayerMobile pm)) return false; - if (pm.HasGump(typeof(QuestOfferGump))) + if (pm.HasGump()) return false; if (questType == typeof(DarkTidesQuest) && pm.Profession != 4) // necromancer @@ -653,11 +659,6 @@ namespace Server.Engines.Quests return $"{text}"; } - public static ArrayList BuildList(object obj) - { - return new ArrayList { obj }; - } - public void AddHtmlObject(int x, int y, int width, int height, object message, int color, bool back, bool scroll) { if (message is int html) @@ -666,4 +667,4 @@ namespace Server.Engines.Quests AddHtml(x, y, width, height, Color(message.ToString(), C16232(color)), back, scroll); } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Quests/Core/Regions/CancelQuestRegion.cs b/Scripts/Engines/Quests/Core/Regions/CancelQuestRegion.cs index 34674fc1c..8f94a2528 100644 --- a/Scripts/Engines/Quests/Core/Regions/CancelQuestRegion.cs +++ b/Scripts/Engines/Quests/Core/Regions/CancelQuestRegion.cs @@ -29,7 +29,7 @@ namespace Server.Engines.Quests if (m is PlayerMobile player && player.Quest != null && player.Quest.GetType() == m_Quest) { - if (!player.HasGump(typeof(QuestCancelGump))) + if (!player.HasGump()) player.Quest.BeginCancelQuest(); return false; diff --git a/Scripts/Engines/Quests/Core/Regions/QuestCompleteObjectiveRegion.cs b/Scripts/Engines/Quests/Core/Regions/QuestCompleteObjectiveRegion.cs index ac739751b..787827427 100644 --- a/Scripts/Engines/Quests/Core/Regions/QuestCompleteObjectiveRegion.cs +++ b/Scripts/Engines/Quests/Core/Regions/QuestCompleteObjectiveRegion.cs @@ -30,7 +30,7 @@ namespace Server.Engines.Quests { QuestObjective obj = player.Quest.FindObjective(m_Objective); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); } } diff --git a/Scripts/Engines/Quests/Dark Tides/Items/CrystalCaveBarrier.cs b/Scripts/Engines/Quests/Dark Tides/Items/CrystalCaveBarrier.cs index 3e86329d2..667cd1421 100644 --- a/Scripts/Engines/Quests/Dark Tides/Items/CrystalCaveBarrier.cs +++ b/Scripts/Engines/Quests/Dark Tides/Items/CrystalCaveBarrier.cs @@ -30,7 +30,7 @@ namespace Server.Engines.Quests.Necro if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(SpeakCavePasswordObjective)); + QuestObjective obj = qs.FindObjective(); if (obj != null && obj.Completed) { diff --git a/Scripts/Engines/Quests/Dark Tides/Items/KronusScroll.cs b/Scripts/Engines/Quests/Dark Tides/Items/KronusScroll.cs index 134a41119..1127ead5c 100644 --- a/Scripts/Engines/Quests/Dark Tides/Items/KronusScroll.cs +++ b/Scripts/Engines/Quests/Dark Tides/Items/KronusScroll.cs @@ -58,9 +58,9 @@ namespace Server.Engines.Quests.Necro { if (pm.Map == m_WellOfTearsMap && m_WellOfTearsArea.Contains(pm)) { - QuestObjective obj = qs.FindObjective(typeof(UseCallingScrollObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); Delete(); diff --git a/Scripts/Engines/Quests/Dark Tides/Items/KronusScrollBox.cs b/Scripts/Engines/Quests/Dark Tides/Items/KronusScrollBox.cs index 56d464e7f..7e39df564 100644 --- a/Scripts/Engines/Quests/Dark Tides/Items/KronusScrollBox.cs +++ b/Scripts/Engines/Quests/Dark Tides/Items/KronusScrollBox.cs @@ -31,9 +31,9 @@ namespace Server.Engines.Quests.Necro if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(FindCallingScrollObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed || DarkTidesQuest.HasLostCallingScroll(from)) + if (obj?.Completed == false || DarkTidesQuest.HasLostCallingScroll(from)) { Item scroll = new KronusScroll(); @@ -42,7 +42,7 @@ namespace Server.Engines.Quests.Necro pm.SendLocalizedMessage(1060120, "", 0x41); // You rummage through the scrolls until you find the Scroll of Calling. You quickly put it in your pack. - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); } else diff --git a/Scripts/Engines/Quests/Dark Tides/Items/MaabusCoffin.cs b/Scripts/Engines/Quests/Dark Tides/Items/MaabusCoffin.cs index fc1b34f6b..d1e311a1d 100644 --- a/Scripts/Engines/Quests/Dark Tides/Items/MaabusCoffin.cs +++ b/Scripts/Engines/Quests/Dark Tides/Items/MaabusCoffin.cs @@ -34,14 +34,10 @@ namespace Server.Engines.Quests.Necro if (Maabus != null || SpawnLocation == Point3D.Zero) return; - foreach (MaabusCoffinComponent c in Components) - c.TurnToEmpty(); - - Maabus = new Maabus(); - - Maabus.Location = SpawnLocation; - Maabus.Map = Map; + foreach (AddonComponent c in Components) + (c as MaabusCoffinComponent)?.TurnToEmpty(); + Maabus = new Maabus { Location = SpawnLocation, Map = Map }; Maabus.Direction = Maabus.GetDirectionTo(caller); Timer.DelayCall(TimeSpan.FromSeconds(7.5), BeginSleep); diff --git a/Scripts/Engines/Quests/Dark Tides/Items/ScrollOfAbraxus.cs b/Scripts/Engines/Quests/Dark Tides/Items/ScrollOfAbraxus.cs index 23c90491c..f77e9d7ab 100644 --- a/Scripts/Engines/Quests/Dark Tides/Items/ScrollOfAbraxus.cs +++ b/Scripts/Engines/Quests/Dark Tides/Items/ScrollOfAbraxus.cs @@ -34,9 +34,9 @@ namespace Server.Engines.Quests.Necro if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(RetrieveAbraxusScrollObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); } } @@ -54,9 +54,9 @@ namespace Server.Engines.Quests.Necro if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(ReadAbraxusScrollObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); } } diff --git a/Scripts/Engines/Quests/Dark Tides/Mobiles/Horus.cs b/Scripts/Engines/Quests/Dark Tides/Mobiles/Horus.cs index e2e3ad9a6..3453b7957 100644 --- a/Scripts/Engines/Quests/Dark Tides/Mobiles/Horus.cs +++ b/Scripts/Engines/Quests/Dark Tides/Mobiles/Horus.cs @@ -62,9 +62,9 @@ namespace Server.Engines.Quests.Necro if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(FindCrystalCaveObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); } } @@ -79,17 +79,17 @@ namespace Server.Engines.Quests.Necro if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(ReturnToCrystalCaveObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } else { - obj = qs.FindObjective(typeof(FindHorusAboutRewardObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); @@ -127,8 +127,8 @@ namespace Server.Engines.Quests.Necro if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(SpeakCavePasswordObjective)); - bool enabled = obj != null && !obj.Completed; + QuestObjective obj = qs.FindObjective(); + bool enabled = obj?.Completed == false; list.Add(new SpeakPasswordEntry(this, pm, enabled)); } @@ -141,9 +141,9 @@ namespace Server.Engines.Quests.Necro if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(SpeakCavePasswordObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); return; diff --git a/Scripts/Engines/Quests/Dark Tides/Mobiles/Mardoth.cs b/Scripts/Engines/Quests/Dark Tides/Mobiles/Mardoth.cs index 8b5e4e59e..8de629eee 100644 --- a/Scripts/Engines/Quests/Dark Tides/Mobiles/Mardoth.cs +++ b/Scripts/Engines/Quests/Dark Tides/Mobiles/Mardoth.cs @@ -90,7 +90,7 @@ namespace Server.Engines.Quests.Necro if (!(to.Quest is DarkTidesQuest qs)) return to.Quest == null && QuestSystem.CanOfferQuest(to, typeof(DarkTidesQuest)); - return qs.FindObjective(typeof(FindMardothAboutVaultObjective)) != null; + return qs.FindObjective() != null; } public override void OnTalk(PlayerMobile player, bool contextMenu) @@ -105,25 +105,25 @@ namespace Server.Engines.Quests.Necro } else { - QuestObjective obj = qs.FindObjective(typeof(FindMardothAboutVaultObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } else { - obj = qs.FindObjective(typeof(FindMardothAboutKronusObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } else { - obj = qs.FindObjective(typeof(FindMardothEndObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); @@ -196,7 +196,7 @@ namespace Server.Engines.Quests.Necro m.PlaySound(0x214); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, ResurrectMessage.Healer)); } } diff --git a/Scripts/Engines/Quests/Dark Tides/Mobiles/SummonedPaladin.cs b/Scripts/Engines/Quests/Dark Tides/Mobiles/SummonedPaladin.cs index 9d0450234..adf7eec48 100644 --- a/Scripts/Engines/Quests/Dark Tides/Mobiles/SummonedPaladin.cs +++ b/Scripts/Engines/Quests/Dark Tides/Mobiles/SummonedPaladin.cs @@ -78,7 +78,7 @@ namespace Server.Engines.Quests.Necro { QuestSystem qs = m_Necromancer.Quest; - if (qs is DarkTidesQuest && qs.FindObjective(typeof(FindMardothEndObjective)) == null) + if (qs is DarkTidesQuest && qs.FindObjective() == null) qs.AddObjective(new FindMardothEndObjective(false)); Say(1060139, m_Necromancer.Name); // You have made my work easy for me, ~1_NAME~. My task here is done. @@ -113,7 +113,7 @@ namespace Server.Engines.Quests.Necro QuestSystem qs = m_Necromancer.Quest; - if (qs is DarkTidesQuest && qs.FindObjective(typeof(FindMardothEndObjective)) == null) + if (qs is DarkTidesQuest && qs.FindObjective() == null) qs.AddObjective(new FindMardothEndObjective(true)); } diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Items/BlueNinjaQuestTeleporter.cs b/Scripts/Engines/Quests/Emino's Undertaking/Items/BlueNinjaQuestTeleporter.cs index 1932f200a..cf583339d 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Items/BlueNinjaQuestTeleporter.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Items/BlueNinjaQuestTeleporter.cs @@ -21,7 +21,7 @@ namespace Server.Engines.Quests.Ninja { QuestSystem qs = player.Quest; - if (qs is EminosUndertakingQuest && qs.FindObjective(typeof(GainInnInformationObjective)) != null) + if (qs is EminosUndertakingQuest && qs.FindObjective() != null) { loc = new Point3D(411, 1116, 0); map = Map.Malas; diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Items/EminosKatanaChest.cs b/Scripts/Engines/Quests/Emino's Undertaking/Items/EminosKatanaChest.cs index c4ea46d37..eb7982f40 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Items/EminosKatanaChest.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Items/EminosKatanaChest.cs @@ -62,9 +62,9 @@ namespace Server.Engines.Quests.Ninja } else { - QuestObjective obj = qs.FindObjective(typeof(HallwayWalkObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Item katana = new EminosKatana(); @@ -103,14 +103,14 @@ namespace Server.Engines.Quests.Ninja return true; if (from is PlayerMobile player && player.Quest is EminosUndertakingQuest) - if (player.Quest.FindObjective(typeof(HallwayWalkObjective)) is HallwayWalkObjective obj) - { - if (obj.StolenTreasure) - from.SendLocalizedMessage( - 1063247); // The guard is watching you carefully! It would be unwise to remove another item from here. - else - return true; - } + { + HallwayWalkObjective obj = player.Quest.FindObjective(); + if (obj?.StolenTreasure == true) + from.SendLocalizedMessage( + 1063247); // The guard is watching you carefully! It would be unwise to remove another item from here. + else + return true; + } return false; } @@ -118,8 +118,11 @@ namespace Server.Engines.Quests.Ninja public override void OnItemLifted(Mobile from, Item item) { if (from is PlayerMobile player && player.Quest is EminosUndertakingQuest) - if (player.Quest.FindObjective(typeof(HallwayWalkObjective)) is HallwayWalkObjective obj) + { + HallwayWalkObjective obj = player.Quest.FindObjective(); + if (obj != null) obj.StolenTreasure = true; + } } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Items/GreenNinjaQuestTeleporter.cs b/Scripts/Engines/Quests/Emino's Undertaking/Items/GreenNinjaQuestTeleporter.cs index 08a4ed0d2..3aaebc575 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Items/GreenNinjaQuestTeleporter.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Items/GreenNinjaQuestTeleporter.cs @@ -21,7 +21,7 @@ namespace Server.Engines.Quests.Ninja { QuestSystem qs = player.Quest; - if (qs is EminosUndertakingQuest && qs.FindObjective(typeof(UseTeleporterObjective)) != null) + if (qs is EminosUndertakingQuest && qs.FindObjective() != null) { loc = new Point3D(410, 1125, 0); map = Map.Malas; diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Items/GuardianBarrier.cs b/Scripts/Engines/Quests/Emino's Undertaking/Items/GuardianBarrier.cs index 41f967fd7..8bcc1f3ad 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Items/GuardianBarrier.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Items/GuardianBarrier.cs @@ -32,19 +32,21 @@ namespace Server.Engines.Quests.Ninja return master != null && Y >= master.Y && master.InRange(this, 4); } - if (m is PlayerMobile pm) - if (pm.Quest is EminosUndertakingQuest qs) - if (qs.FindObjective(typeof(SneakPastGuardiansObjective)) is SneakPastGuardiansObjective obj) - { - if (m.Hidden) - return true; // Hidden ninjas can pass + if (m is PlayerMobile pm && pm.Quest is EminosUndertakingQuest qs) + { + SneakPastGuardiansObjective obj = qs.FindObjective(); + if (obj != null) + { + if (m.Hidden) + return true; // Hidden ninjas can pass - if (!obj.TaughtHowToUseSkills) - { - obj.TaughtHowToUseSkills = true; - qs.AddConversation(new NeedToHideConversation()); - } + if (!obj.TaughtHowToUseSkills) + { + obj.TaughtHowToUseSkills = true; + qs.AddConversation(new NeedToHideConversation()); } + } + } return false; } diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Items/WhiteNinjaQuestTeleporter.cs b/Scripts/Engines/Quests/Emino's Undertaking/Items/WhiteNinjaQuestTeleporter.cs index 688b16c05..928f54ff5 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Items/WhiteNinjaQuestTeleporter.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Items/WhiteNinjaQuestTeleporter.cs @@ -23,7 +23,7 @@ namespace Server.Engines.Quests.Ninja if (qs is EminosUndertakingQuest) { - QuestObjective obj = qs.FindObjective(typeof(SearchForSwordObjective)); + QuestObjective obj = qs.FindObjective(); if (obj != null) { diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Emino.cs b/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Emino.cs index c81675c92..a4f9aa28f 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Emino.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Emino.cs @@ -79,17 +79,17 @@ namespace Server.Engines.Quests.Ninja } else { - QuestObjective obj = qs.FindObjective(typeof(FindEminoBeginObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } else { - obj = qs.FindObjective(typeof(UseTeleporterObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Item note = new NoteForZoel(); @@ -109,9 +109,9 @@ namespace Server.Engines.Quests.Ninja } else { - obj = qs.FindObjective(typeof(ReturnFromInnObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); @@ -140,9 +140,9 @@ namespace Server.Engines.Quests.Ninja } else { - obj = qs.FindObjective(typeof(GiveEminoSwordObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Item katana = null; @@ -153,7 +153,9 @@ namespace Server.Engines.Quests.Ninja { bool stolenTreasure = false; - if (qs.FindObjective(typeof(HallwayWalkObjective)) is HallwayWalkObjective walk) + HallwayWalkObjective walk = qs.FindObjective(); + + if (walk != null) stolenTreasure = walk.StolenTreasure; Kama kama = new Kama(); @@ -206,7 +208,7 @@ namespace Server.Engines.Quests.Ninja m.PlaySound(0x214); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, ResurrectMessage.Healer)); } } diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Henchman.cs b/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Henchman.cs index 0549f5bc0..f61d29de3 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Henchman.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Henchman.cs @@ -10,7 +10,7 @@ namespace Server.Engines.Quests.Ninja { InitStats(45, 30, 5); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Body = 0x190; Utility.AssignRandomHair(this); diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/HiddenFigure.cs b/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/HiddenFigure.cs index ea2f34ed1..23448112e 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/HiddenFigure.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/HiddenFigure.cs @@ -31,7 +31,7 @@ namespace Server.Engines.Quests.Ninja { InitStats(100, 100, 25); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = Utility.RandomBool(); diff --git a/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Zoel.cs b/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Zoel.cs index 780584f51..4b89ab260 100644 --- a/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Zoel.cs +++ b/Scripts/Engines/Quests/Emino's Undertaking/Mobiles/Zoel.cs @@ -62,9 +62,9 @@ namespace Server.Engines.Quests.Ninja if (qs is EminosUndertakingQuest) { - QuestObjective obj = qs.FindObjective(typeof(FindZoelObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); } } @@ -78,9 +78,9 @@ namespace Server.Engines.Quests.Ninja if (qs is EminosUndertakingQuest) if (dropped is NoteForZoel) { - QuestObjective obj = qs.FindObjective(typeof(GiveZoelNoteObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { dropped.Delete(); obj.Complete(); @@ -109,7 +109,7 @@ namespace Server.Engines.Quests.Ninja m.PlaySound(0x214); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, ResurrectMessage.Healer)); } } diff --git a/Scripts/Engines/Quests/Haochi's Trials/Items/HaochisKatanaGenerator.cs b/Scripts/Engines/Quests/Haochi's Trials/Items/HaochisKatanaGenerator.cs index f5279a449..8b237493a 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Items/HaochisKatanaGenerator.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Items/HaochisKatanaGenerator.cs @@ -38,9 +38,9 @@ namespace Server.Engines.Quests.Samurai } else { - QuestObjective obj = qs.FindObjective(typeof(FifthTrialIntroObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Item katana = new HaochisKatana(); diff --git a/Scripts/Engines/Quests/Haochi's Trials/Items/HaochisTreasureChest.cs b/Scripts/Engines/Quests/Haochi's Trials/Items/HaochisTreasureChest.cs index a01f64893..9387233cc 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Items/HaochisTreasureChest.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Items/HaochisTreasureChest.cs @@ -57,14 +57,14 @@ namespace Server.Engines.Quests.Samurai return true; if (from is PlayerMobile player && player.Quest is HaochisTrialsQuest) - if (player.Quest.FindObjective(typeof(FifthTrialIntroObjective)) is FifthTrialIntroObjective obj) - { - if (obj.StolenTreasure) - from.SendLocalizedMessage( - 1063247); // The guard is watching you carefully! It would be unwise to remove another item from here. - else - return true; - } + { + FifthTrialIntroObjective obj = player.Quest.FindObjective(); + if (obj?.StolenTreasure == true) + from.SendLocalizedMessage( + 1063247); // The guard is watching you carefully! It would be unwise to remove another item from here. + else + return true; + } return false; } @@ -72,8 +72,11 @@ namespace Server.Engines.Quests.Samurai public override void OnItemLifted(Mobile from, Item item) { if (from is PlayerMobile player && player.Quest is HaochisTrialsQuest) - if (player.Quest.FindObjective(typeof(FifthTrialIntroObjective)) is FifthTrialIntroObjective obj) + { + FifthTrialIntroObjective obj = player.Quest.FindObjective(); + if (obj != null) obj.StolenTreasure = true; + } Timer.DelayCall(TimeSpan.FromMinutes(2.0), GenerateTreasure); } diff --git a/Scripts/Engines/Quests/Haochi's Trials/Items/HonorCandle.cs b/Scripts/Engines/Quests/Haochi's Trials/Items/HonorCandle.cs index 14bb83669..0c432c080 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Items/HonorCandle.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Items/HonorCandle.cs @@ -37,9 +37,9 @@ namespace Server.Engines.Quests.Samurai if (qs is HaochisTrialsQuest) { - QuestObjective obj = qs.FindObjective(typeof(SixthTrialIntroObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); SendLocalizedMessageTo(from, 1063251); // You light a candle in honor. diff --git a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/DeadlyImp.cs b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/DeadlyImp.cs index de304084a..8e6201185 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/DeadlyImp.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/DeadlyImp.cs @@ -52,8 +52,8 @@ namespace Server.Engines.Quests.Samurai QuestSystem qs = player.Quest; if (qs is HaochisTrialsQuest) { - QuestObjective obj = qs.FindObjective(typeof(SecondTrialAttackObjective)); - if (obj != null && !obj.Completed) + QuestObjective obj = qs.FindObjective(); + if (obj?.Completed == false) { obj.Complete(); qs.AddObjective(new SecondTrialReturnObjective(false)); diff --git a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/FierceDragon.cs b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/FierceDragon.cs index 66f92cee8..afd52d4c8 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/FierceDragon.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/FierceDragon.cs @@ -74,8 +74,8 @@ namespace Server.Engines.Quests.Samurai QuestSystem qs = player.Quest; if (qs is HaochisTrialsQuest) { - QuestObjective obj = qs.FindObjective(typeof(SecondTrialAttackObjective)); - if (obj != null && !obj.Completed) + QuestObjective obj = qs.FindObjective(); + if (obj?.Completed == false) { obj.Complete(); qs.AddObjective(new SecondTrialReturnObjective(true)); diff --git a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Haochi.cs b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Haochi.cs index ccd9ee459..89000e68c 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Haochi.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Haochi.cs @@ -60,26 +60,26 @@ namespace Server.Engines.Quests.Samurai return; } - QuestObjective obj = qs.FindObjective(typeof(FindHaochiObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); return; } - obj = qs.FindObjective(typeof(FirstTrialReturnObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { player.AddToBackpack(new LeatherDo()); obj.Complete(); return; } - obj = qs.FindObjective(typeof(SecondTrialReturnObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { if (((SecondTrialReturnObjective)obj).Dragon) player.AddToBackpack(new LeatherSuneate()); @@ -88,18 +88,18 @@ namespace Server.Engines.Quests.Samurai return; } - obj = qs.FindObjective(typeof(ThirdTrialReturnObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { player.AddToBackpack(new LeatherHiroSode()); obj.Complete(); return; } - obj = qs.FindObjective(typeof(FourthTrialReturnObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { if (!((FourthTrialReturnObjective)obj).KilledCat) { @@ -113,9 +113,9 @@ namespace Server.Engines.Quests.Samurai return; } - obj = qs.FindObjective(typeof(FifthTrialReturnObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { HaochisKatana katana = player.Backpack?.FindItemByType(); if (katana == null) @@ -124,24 +124,24 @@ namespace Server.Engines.Quests.Samurai katana.Delete(); obj.Complete(); - obj = qs.FindObjective(typeof(FifthTrialIntroObjective)); + obj = qs.FindObjective(); if (obj != null && ((FifthTrialIntroObjective)obj).StolenTreasure) qs.AddConversation(new SixthTrialIntroConversation(true)); else qs.AddConversation(new SixthTrialIntroConversation(false)); } - obj = qs.FindObjective(typeof(SixthTrialReturnObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); return; } - obj = qs.FindObjective(typeof(SeventhTrialReturnObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { BaseWeapon weapon = new Daisho(); BaseRunicTool.ApplyAttributesTo(weapon, Utility.Random(1, 3), 10, 30); diff --git a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Relnia.cs b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Relnia.cs index dbcd3bb3e..7d37039f3 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Relnia.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Relnia.cs @@ -52,9 +52,9 @@ namespace Server.Engines.Quests.Samurai if (qs is HaochisTrialsQuest) { - QuestObjective obj = qs.FindObjective(typeof(FourthTrialCatsObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) if (dropped is Gold gold) { obj.Complete(); diff --git a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/YoungNinja.cs b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/YoungNinja.cs index 78a04e931..327954b1c 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/YoungNinja.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/YoungNinja.cs @@ -11,7 +11,7 @@ namespace Server.Engines.Quests.Samurai InitStats(45, 30, 5); SetHits(20, 30); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Body = 0x190; Utility.AssignRandomHair(this); diff --git a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/YoungRonin.cs b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/YoungRonin.cs index 6b963d337..1effa3c6e 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/YoungRonin.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/YoungRonin.cs @@ -11,7 +11,7 @@ namespace Server.Engines.Quests.Samurai InitStats(45, 30, 5); SetHits(10, 20); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Body = 0x190; Utility.AssignRandomHair(this); diff --git a/Scripts/Engines/Quests/Solen Matriarch/Mobiles/SolenMatriarch.cs b/Scripts/Engines/Quests/Solen Matriarch/Mobiles/SolenMatriarch.cs index 228bd781e..b12ea4516 100644 --- a/Scripts/Engines/Quests/Solen Matriarch/Mobiles/SolenMatriarch.cs +++ b/Scripts/Engines/Quests/Solen Matriarch/Mobiles/SolenMatriarch.cs @@ -52,9 +52,9 @@ namespace Server.Engines.Quests.Matriarch } else { - QuestObjective obj = qs.FindObjective(typeof(ReturnAfterKillsObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } @@ -64,9 +64,9 @@ namespace Server.Engines.Quests.Matriarch } else { - obj = qs.FindObjective(typeof(ReturnAfterWaterObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } @@ -76,9 +76,9 @@ namespace Server.Engines.Quests.Matriarch } else { - obj = qs.FindObjective(typeof(GetRewardObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { if (SolenMatriarchQuest.GiveRewardTo(player)) obj.Complete(); @@ -153,9 +153,9 @@ namespace Server.Engines.Quests.Matriarch if (player.Quest is SolenMatriarchQuest qs && qs.RedSolen == RedSolen) { - QuestObjective obj = qs.FindObjective(typeof(ProcessFungiObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { int amount = fungi.Amount / 2; diff --git a/Scripts/Engines/Quests/Study of the Solen Hive/Mobiles/Naturalist.cs b/Scripts/Engines/Quests/Study of the Solen Hive/Mobiles/Naturalist.cs index e30ed0088..3b1a5c347 100644 --- a/Scripts/Engines/Quests/Study of the Solen Hive/Mobiles/Naturalist.cs +++ b/Scripts/Engines/Quests/Study of the Solen Hive/Mobiles/Naturalist.cs @@ -19,7 +19,7 @@ namespace Server.Engines.Quests.Naturalist { InitStats(100, 100, 25); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = false; Body = 0x190; @@ -41,119 +41,119 @@ namespace Server.Engines.Quests.Naturalist { if (player.Quest is StudyOfSolenQuest qs && qs.Naturalist == this) { - if (qs.FindObjective(typeof(StudyNestsObjective)) is StudyNestsObjective study) + StudyNestsObjective study = qs.FindObjective(); + if (study == null) + return; + + if (!study.Completed) { - if (!study.Completed) + PlaySound(0x41F); + qs.AddConversation(new NaturalistDuringStudyConversation()); + return; + } + + QuestObjective obj = qs.FindObjective(); + + if (obj?.Completed == false) + { + Seed reward; + + PlantType type; + switch (Utility.Random(17)) { - PlaySound(0x41F); - qs.AddConversation(new NaturalistDuringStudyConversation()); + case 0: + type = PlantType.CampionFlowers; + break; + case 1: + type = PlantType.Poppies; + break; + case 2: + type = PlantType.Snowdrops; + break; + case 3: + type = PlantType.Bulrushes; + break; + case 4: + type = PlantType.Lilies; + break; + case 5: + type = PlantType.PampasGrass; + break; + case 6: + type = PlantType.Rushes; + break; + case 7: + type = PlantType.ElephantEarPlant; + break; + case 8: + type = PlantType.Fern; + break; + case 9: + type = PlantType.PonytailPalm; + break; + case 10: + type = PlantType.SmallPalm; + break; + case 11: + type = PlantType.CenturyPlant; + break; + case 12: + type = PlantType.WaterPlant; + break; + case 13: + type = PlantType.SnakePlant; + break; + case 14: + type = PlantType.PricklyPearCactus; + break; + case 15: + type = PlantType.BarrelCactus; + break; + default: + type = PlantType.TribarrelCactus; + break; + } + + if (study.StudiedSpecialNest) + { + reward = new Seed(type, PlantHue.FireRed, false); } else { - QuestObjective obj = qs.FindObjective(typeof(ReturnToNaturalistObjective)); - - if (obj != null && !obj.Completed) + PlantHue hue; + switch (Utility.Random(3)) { - Seed reward; - - PlantType type; - switch (Utility.Random(17)) - { - case 0: - type = PlantType.CampionFlowers; - break; - case 1: - type = PlantType.Poppies; - break; - case 2: - type = PlantType.Snowdrops; - break; - case 3: - type = PlantType.Bulrushes; - break; - case 4: - type = PlantType.Lilies; - break; - case 5: - type = PlantType.PampasGrass; - break; - case 6: - type = PlantType.Rushes; - break; - case 7: - type = PlantType.ElephantEarPlant; - break; - case 8: - type = PlantType.Fern; - break; - case 9: - type = PlantType.PonytailPalm; - break; - case 10: - type = PlantType.SmallPalm; - break; - case 11: - type = PlantType.CenturyPlant; - break; - case 12: - type = PlantType.WaterPlant; - break; - case 13: - type = PlantType.SnakePlant; - break; - case 14: - type = PlantType.PricklyPearCactus; - break; - case 15: - type = PlantType.BarrelCactus; - break; - default: - type = PlantType.TribarrelCactus; - break; - } - - if (study.StudiedSpecialNest) - { - reward = new Seed(type, PlantHue.FireRed, false); - } - else - { - PlantHue hue; - switch (Utility.Random(3)) - { - case 0: - hue = PlantHue.Pink; - break; - case 1: - hue = PlantHue.Magenta; - break; - default: - hue = PlantHue.Aqua; - break; - } - - reward = new Seed(type, hue, false); - } - - if (player.PlaceInBackpack(reward)) - { - obj.Complete(); - - PlaySound(0x449); - PlaySound(0x41B); - - if (study.StudiedSpecialNest) - qs.AddConversation(new SpecialEndConversation()); - else - qs.AddConversation(new EndConversation()); - } - else - { - reward.Delete(); - - qs.AddConversation(new FullBackpackConversation()); - } + case 0: + hue = PlantHue.Pink; + break; + case 1: + hue = PlantHue.Magenta; + break; + default: + hue = PlantHue.Aqua; + break; } + + reward = new Seed(type, hue, false); + } + + if (player.PlaceInBackpack(reward)) + { + obj.Complete(); + + PlaySound(0x449); + PlaySound(0x41B); + + if (study.StudiedSpecialNest) + qs.AddConversation(new SpecialEndConversation()); + else + qs.AddConversation(new EndConversation()); + } + else + { + reward.Delete(); + + qs.AddConversation(new FullBackpackConversation()); } } } diff --git a/Scripts/Engines/Quests/Study of the Solen Hive/Objectives.cs b/Scripts/Engines/Quests/Study of the Solen Hive/Objectives.cs index ddcaa35ba..f949f97f5 100644 --- a/Scripts/Engines/Quests/Study of the Solen Hive/Objectives.cs +++ b/Scripts/Engines/Quests/Study of the Solen Hive/Objectives.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server.Mobiles; namespace Server.Engines.Quests.Naturalist @@ -8,15 +8,10 @@ namespace Server.Engines.Quests.Naturalist { private NestArea m_CurrentNest; - private ArrayList m_StudiedNests; + private List m_StudiedNests = new List(); private DateTime m_StudyBegin; private StudyState m_StudyState; - public StudyNestsObjective() - { - m_StudiedNests = new ArrayList(); - } - public override object Message => 1054044; public override int MaxProgress => NestArea.NonSpecialCount; @@ -154,7 +149,8 @@ namespace Server.Engines.Quests.Naturalist writer.WriteEncodedInt(0); // version writer.WriteEncodedInt(m_StudiedNests.Count); - foreach (NestArea nest in m_StudiedNests) writer.WriteEncodedInt(nest.ID); + foreach (NestArea nest in m_StudiedNests) + writer.WriteEncodedInt(nest.ID); writer.Write(StudiedSpecialNest); } diff --git a/Scripts/Engines/Quests/Terrible Hatchlings/Mobiles/AnsellaGryen.cs b/Scripts/Engines/Quests/Terrible Hatchlings/Mobiles/AnsellaGryen.cs index 387c6e729..364d0815b 100644 --- a/Scripts/Engines/Quests/Terrible Hatchlings/Mobiles/AnsellaGryen.cs +++ b/Scripts/Engines/Quests/Terrible Hatchlings/Mobiles/AnsellaGryen.cs @@ -62,9 +62,9 @@ namespace Server.Engines.Quests.Zento } else { - QuestObjective obj = qs.FindObjective(typeof(ReturnObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); @@ -103,7 +103,6 @@ namespace Server.Engines.Quests.Zento else { TerribleHatchlingsQuest newQuest = new TerribleHatchlingsQuest(player); - bool inRestartPeriod = false; if (qs != null) { @@ -111,7 +110,7 @@ namespace Server.Engines.Quests.Zento SayTo(player, 1063322); // Before you can help me with the Terrible Hatchlings, you'll need to finish the quest you've already taken! } - else if (QuestSystem.CanOfferQuest(player, typeof(TerribleHatchlingsQuest), out inRestartPeriod)) + else if (QuestSystem.CanOfferQuest(player, typeof(TerribleHatchlingsQuest), out bool inRestartPeriod)) { newQuest.SendOffer(); } diff --git a/Scripts/Engines/Quests/The Summoning/Items/BellOfTheDead.cs b/Scripts/Engines/Quests/The Summoning/Items/BellOfTheDead.cs index ed1c0ee08..2fadd414d 100644 --- a/Scripts/Engines/Quests/The Summoning/Items/BellOfTheDead.cs +++ b/Scripts/Engines/Quests/The Summoning/Items/BellOfTheDead.cs @@ -55,20 +55,18 @@ namespace Server.Engines.Quests.Doom Effects.PlaySound(GetWorldLocation(), Map, 0x100); - Timer.DelayCall(TimeSpan.FromSeconds(8.0), new TimerStateCallback(EndSummon), from); + Timer.DelayCall(TimeSpan.FromSeconds(8.0), () => EndSummon(from)); } } - public virtual void EndSummon(object state) + public virtual void EndSummon(Mobile from) { - Mobile from = (Mobile)state; - - if (Chyloth != null && !Chyloth.Deleted) + if (Chyloth?.Deleted == false) { from.SendLocalizedMessage( 1050010); // The ferry man has already been summoned. There is no need to ring for him again. } - else if (Dragon != null && !Dragon.Deleted) + else if (Dragon?.Deleted == false) { from.SendLocalizedMessage( 1050017); // The ferryman has recently been summoned already. You decide against ringing the bell again so soon. diff --git a/Scripts/Engines/Quests/The Summoning/Mobiles/Chyloth.cs b/Scripts/Engines/Quests/The Summoning/Mobiles/Chyloth.cs index e7405c843..0db94c93e 100644 --- a/Scripts/Engines/Quests/The Summoning/Mobiles/Chyloth.cs +++ b/Scripts/Engines/Quests/The Summoning/Mobiles/Chyloth.cs @@ -188,7 +188,7 @@ namespace Server.Engines.Quests.Doom if (AngryAt == member) AngryAt = null; - member.CloseGump(typeof(ChylothPartyGump)); + member.CloseGump(); member.SendGump(new ChylothPartyGump(from, member)); } } diff --git a/Scripts/Engines/Quests/The Summoning/Mobiles/Victoria.cs b/Scripts/Engines/Quests/The Summoning/Mobiles/Victoria.cs index 4f54a7bd0..85fdeec52 100644 --- a/Scripts/Engines/Quests/The Summoning/Mobiles/Victoria.cs +++ b/Scripts/Engines/Quests/The Summoning/Mobiles/Victoria.cs @@ -76,9 +76,9 @@ namespace Server.Engines.Quests.Doom if (qs is TheSummoningQuest) if (dropped is DaemonBone bones) { - QuestObjective obj = qs.FindObjective(typeof(CollectBonesObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { int need = obj.MaxProgress - obj.CurProgress; diff --git a/Scripts/Engines/Quests/The Summoning/TheSummoningQuest.cs b/Scripts/Engines/Quests/The Summoning/TheSummoningQuest.cs index c30a2ec83..b83a0697c 100644 --- a/Scripts/Engines/Quests/The Summoning/TheSummoningQuest.cs +++ b/Scripts/Engines/Quests/The Summoning/TheSummoningQuest.cs @@ -75,7 +75,7 @@ namespace Server.Engines.Quests.Doom { base.Cancel(); - QuestObjective obj = FindObjective(typeof(CollectBonesObjective)); + QuestObjective obj = FindObjective(); if (obj != null && obj.CurProgress > 0) { diff --git a/Scripts/Engines/Quests/Uzeraan Turmoil/Items/DaemonBloodChest.cs b/Scripts/Engines/Quests/Uzeraan Turmoil/Items/DaemonBloodChest.cs index dfa2cfac5..e098cee9a 100644 --- a/Scripts/Engines/Quests/Uzeraan Turmoil/Items/DaemonBloodChest.cs +++ b/Scripts/Engines/Quests/Uzeraan Turmoil/Items/DaemonBloodChest.cs @@ -23,9 +23,9 @@ namespace Server.Engines.Quests.Haven if (qs is UzeraanTurmoilQuest) { - QuestObjective obj = qs.FindObjective(typeof(GetDaemonBloodObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed || UzeraanTurmoilQuest.HasLostDaemonBlood(player)) + if (obj?.Completed == false || UzeraanTurmoilQuest.HasLostDaemonBlood(player)) { Item vial = new QuestDaemonBlood(); @@ -34,7 +34,7 @@ namespace Server.Engines.Quests.Haven player.SendLocalizedMessage(1049331, "", 0x22); // You take a vial of blood from the chest and put it in your pack. - if (obj != null && !obj.Completed) + if (obj?.Completed == false) obj.Complete(); } else diff --git a/Scripts/Engines/Quests/Uzeraan Turmoil/Items/SchmendrickApprenticeCorpse.cs b/Scripts/Engines/Quests/Uzeraan Turmoil/Items/SchmendrickApprenticeCorpse.cs index d5907641c..85c2f043f 100644 --- a/Scripts/Engines/Quests/Uzeraan Turmoil/Items/SchmendrickApprenticeCorpse.cs +++ b/Scripts/Engines/Quests/Uzeraan Turmoil/Items/SchmendrickApprenticeCorpse.cs @@ -17,11 +17,10 @@ namespace Server.Engines.Quests.Haven { Direction = Direction.West; - foreach (Item item in EquipItems) DropItem(item); + foreach (Item item in EquipItems) + DropItem(item); - m_Lantern = new Lantern(); - m_Lantern.Movable = false; - m_Lantern.Protected = true; + m_Lantern = new Lantern { Movable = false, Protected = true }; m_Lantern.Ignite(); } @@ -29,11 +28,12 @@ namespace Server.Engines.Quests.Haven { } + // TODO: What is this? Why are we creating and deleting a mobile? private static Mobile GetOwner() { Mobile apprentice = new Mobile(); - apprentice.Hue = Utility.RandomSkinHue(); + apprentice.Hue = Race.Human.RandomSkinHue(); apprentice.Female = false; apprentice.Body = 0x190; apprentice.Name = NameList.RandomName("male"); @@ -50,32 +50,6 @@ namespace Server.Engines.Quests.Haven list.Add(new Robe(QuestSystem.RandomBrightHue())); list.Add(new WizardsHat(Utility.RandomNeutralHue())); list.Add(new Shoes(Utility.RandomNeutralHue())); - - /* - int hairHue = Utility.RandomHairHue(); - - switch ( Utility.Random( 8 ) ) - { - case 0: list.Add( new Afro( hairHue ) ); break; - case 1: list.Add( new KrisnaHair( hairHue ) ); break; - case 2: list.Add( new PageboyHair( hairHue ) ); break; - case 3: list.Add( new PonyTail( hairHue ) ); break; - case 4: list.Add( new ReceedingHair( hairHue ) ); break; - case 5: list.Add( new TwoPigTails( hairHue ) ); break; - case 6: list.Add( new ShortHair( hairHue ) ); break; - case 7: list.Add( new LongHair( hairHue ) ); break; - } - - switch ( Utility.Random( 5 ) ) - { - case 0: list.Add( new LongBeard( hairHue ) ); break; - case 1: list.Add( new MediumLongBeard( hairHue ) ); break; - case 2: list.Add( new Vandyke( hairHue ) ); break; - case 3: list.Add( new Mustache( hairHue ) ); break; - case 4: list.Add( new Goatee( hairHue ) ); break; - } - * */ - list.Add(new Spellbook()); return list; @@ -84,7 +58,6 @@ namespace Server.Engines.Quests.Haven private static HairInfo GetHair() { m_HairHue = Race.Human.RandomHairHue(); - return new HairInfo(Race.Human.RandomHair(false), m_HairHue); } @@ -131,9 +104,9 @@ namespace Server.Engines.Quests.Haven if (qs is UzeraanTurmoilQuest) { - QuestObjective obj = qs.FindObjective(typeof(FindApprenticeObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Item scroll = new SchmendrickScrollOfPower(); diff --git a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Dryad.cs b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Dryad.cs index 3970a7e46..ca65e6ada 100644 --- a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Dryad.cs +++ b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Dryad.cs @@ -63,7 +63,7 @@ namespace Server.Engines.Quests.Haven public override bool CanTalkTo(PlayerMobile to) { - return to.Quest is UzeraanTurmoilQuest qs && qs.FindObjective(typeof(FindDryadObjective)) != null; + return to.Quest is UzeraanTurmoilQuest qs && qs.FindObjective() != null; } public override void OnTalk(PlayerMobile player, bool contextMenu) @@ -79,9 +79,9 @@ namespace Server.Engines.Quests.Haven } else { - QuestObjective obj = qs.FindObjective(typeof(FindDryadObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { FocusTo(player); diff --git a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MansionGuard.cs b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MansionGuard.cs index e41f3fadc..da6b8951d 100644 --- a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MansionGuard.cs +++ b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MansionGuard.cs @@ -18,7 +18,7 @@ namespace Server.Engines.Quests.Haven { InitStats(100, 100, 25); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = false; Body = 0x190; diff --git a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MilitiaCanoneer.cs b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MilitiaCanoneer.cs index a0dab7480..5f06d86e3 100644 --- a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MilitiaCanoneer.cs +++ b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MilitiaCanoneer.cs @@ -22,7 +22,7 @@ namespace Server.Engines.Quests.Haven { InitStats(100, 125, 25); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = false; Body = 0x190; diff --git a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MilitiaFighter.cs b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MilitiaFighter.cs index 5bcabf4a4..ff495ebac 100644 --- a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MilitiaFighter.cs +++ b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/MilitiaFighter.cs @@ -16,7 +16,7 @@ namespace Server.Engines.Quests.Haven SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = false; Body = 0x190; diff --git a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Schmendrick.cs b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Schmendrick.cs index 31430e533..27081888f 100644 --- a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Schmendrick.cs +++ b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Schmendrick.cs @@ -55,7 +55,7 @@ namespace Server.Engines.Quests.Haven public override bool CanTalkTo(PlayerMobile to) { - return to.Quest is UzeraanTurmoilQuest qs && qs.FindObjective(typeof(FindSchmendrickObjective)) != null; + return to.Quest is UzeraanTurmoilQuest qs && qs.FindObjective() != null; } public override void OnTalk(PlayerMobile player, bool contextMenu) @@ -71,9 +71,9 @@ namespace Server.Engines.Quests.Haven } else { - QuestObjective obj = qs.FindObjective(typeof(FindSchmendrickObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { FocusTo(player); obj.Complete(); @@ -129,7 +129,7 @@ namespace Server.Engines.Quests.Haven m.PlaySound(0x214); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, ResurrectMessage.Healer)); } } diff --git a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Uzeraan.cs b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Uzeraan.cs index a5f45ac87..cd5a098ba 100644 --- a/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Uzeraan.cs +++ b/Scripts/Engines/Quests/Uzeraan Turmoil/Mobiles/Uzeraan.cs @@ -94,25 +94,25 @@ namespace Server.Engines.Quests.Haven qs.AddConversation(new FewReagentsConversation()); } - QuestObjective obj = qs.FindObjective(typeof(FindUzeraanBeginObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } else { - obj = qs.FindObjective(typeof(FindUzeraanFirstTaskObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { obj.Complete(); } else { - obj = qs.FindObjective(typeof(FindUzeraanAboutReportObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); @@ -145,36 +145,36 @@ namespace Server.Engines.Quests.Haven } else { - obj = qs.FindObjective(typeof(ReturnScrollOfPowerObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { FocusTo(player); SayTo(player, 1049378); // Hand me the scroll, if you have it. } else { - obj = qs.FindObjective(typeof(ReturnFertileDirtObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { FocusTo(player); SayTo(player, 1049381); // Hand me the Fertile Dirt, if you have it. } else { - obj = qs.FindObjective(typeof(ReturnDaemonBloodObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { FocusTo(player); SayTo(player, 1049379); // Hand me the Vial of Blood, if you have it. } else { - obj = qs.FindObjective(typeof(ReturnDaemonBoneObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { FocusTo(player); SayTo(player, 1049380); // Hand me the Daemon Bone, if you have it. @@ -225,9 +225,9 @@ namespace Server.Engines.Quests.Haven if (dropped is SchmendrickScrollOfPower) { - QuestObjective obj = qs.FindObjective(typeof(ReturnScrollOfPowerObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); @@ -250,9 +250,9 @@ namespace Server.Engines.Quests.Haven } else if (dropped is QuestFertileDirt) { - QuestObjective obj = qs.FindObjective(typeof(ReturnFertileDirtObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); @@ -294,9 +294,9 @@ namespace Server.Engines.Quests.Haven } else if (dropped is QuestDaemonBlood) { - QuestObjective obj = qs.FindObjective(typeof(ReturnDaemonBloodObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Item reward; @@ -365,9 +365,9 @@ namespace Server.Engines.Quests.Haven } else if (dropped is QuestDaemonBone) { - QuestObjective obj = qs.FindObjective(typeof(ReturnDaemonBoneObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); cont.DropItem(new BankCheck(2000)); @@ -409,7 +409,7 @@ namespace Server.Engines.Quests.Haven m.PlaySound(0x214); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, ResurrectMessage.Healer)); } } diff --git a/Scripts/Engines/Quests/Witch Apprentice/Conversations.cs b/Scripts/Engines/Quests/Witch Apprentice/Conversations.cs index 25f430f33..31b8a9dba 100644 --- a/Scripts/Engines/Quests/Witch Apprentice/Conversations.cs +++ b/Scripts/Engines/Quests/Witch Apprentice/Conversations.cs @@ -119,7 +119,8 @@ namespace Server.Engines.Quests.Hag public override void OnRead() { - if (System.FindObjective(typeof(FindIngredientObjective)) is FindIngredientObjective obj) + FindIngredientObjective obj = System.FindObjective(); + if (obj != null) System.AddObjective(new FindIngredientObjective(obj.Ingredients, true)); } } @@ -253,8 +254,7 @@ namespace Server.Engines.Quests.Hag public override void OnRead() { - if (System.FindObjective(typeof(FindIngredientObjective)) is FindIngredientObjective obj) - obj.NextStep(); + System.FindObjective()?.NextStep(); } public override void ChildDeserialize(GenericReader reader) diff --git a/Scripts/Engines/Quests/Witch Apprentice/Items/HagApprenticeCorpse.cs b/Scripts/Engines/Quests/Witch Apprentice/Items/HagApprenticeCorpse.cs index ea47aed2e..b45f08259 100644 --- a/Scripts/Engines/Quests/Witch Apprentice/Items/HagApprenticeCorpse.cs +++ b/Scripts/Engines/Quests/Witch Apprentice/Items/HagApprenticeCorpse.cs @@ -13,18 +13,20 @@ namespace Server.Engines.Quests.Hag { Direction = Direction.South; - foreach (Item item in EquipItems) DropItem(item); + foreach (Item item in EquipItems) + DropItem(item); } public HagApprenticeCorpse(Serial serial) : base(serial) { } + // TODO: What is this? Why are we creating a mobile and deleting it? private static Mobile GetOwner() { Mobile apprentice = new Mobile(); - apprentice.Hue = Utility.RandomSkinHue(); + apprentice.Hue = Race.Human.RandomSkinHue(); apprentice.Female = false; apprentice.Body = 0x190; @@ -60,7 +62,9 @@ namespace Server.Engines.Quests.Hag QuestSystem qs = player.Quest; if (qs is WitchApprenticeQuest) - if (qs.FindObjective(typeof(FindApprenticeObjective)) is FindApprenticeObjective obj && !obj.Completed) + { + FindApprenticeObjective obj = qs.FindObjective(); + if (obj?.Completed == false) { if (obj.Corpse == this) { @@ -75,6 +79,7 @@ namespace Server.Engines.Quests.Hag return; } + } } SendLocalizedMessageTo(from, 1055048); // You examine the corpse, but find nothing of interest. diff --git a/Scripts/Engines/Quests/Witch Apprentice/Items/MagicFlute.cs b/Scripts/Engines/Quests/Witch Apprentice/Items/MagicFlute.cs index 10affb8da..86034c4d5 100644 --- a/Scripts/Engines/Quests/Witch Apprentice/Items/MagicFlute.cs +++ b/Scripts/Engines/Quests/Witch Apprentice/Items/MagicFlute.cs @@ -31,7 +31,9 @@ namespace Server.Engines.Quests.Hag QuestSystem qs = player.Quest; if (qs is WitchApprenticeQuest) - if (qs.FindObjective(typeof(FindZeefzorpulObjective)) is FindZeefzorpulObjective obj && !obj.Completed) + { + FindZeefzorpulObjective obj = qs.FindObjective(); + if (obj?.Completed == false) { if (player.Map != Map.Trammel && player.Map != Map.Felucca || !player.InRange(obj.ImpLocation, 8)) { @@ -50,6 +52,7 @@ namespace Server.Engines.Quests.Hag 1055052); // The flute sparkles. Zeefzorpul must be in a good hiding place nearby. } } + } } } diff --git a/Scripts/Engines/Quests/Witch Apprentice/Mobiles/Blackheart.cs b/Scripts/Engines/Quests/Witch Apprentice/Mobiles/Blackheart.cs index 1d5ae827a..87934f604 100644 --- a/Scripts/Engines/Quests/Witch Apprentice/Mobiles/Blackheart.cs +++ b/Scripts/Engines/Quests/Witch Apprentice/Mobiles/Blackheart.cs @@ -56,8 +56,9 @@ namespace Server.Engines.Quests.Hag QuestSystem qs = player.Quest; if (qs is WitchApprenticeQuest) - if (qs.FindObjective(typeof(FindIngredientObjective)) is FindIngredientObjective obj && !obj.Completed && - obj.Ingredient == Ingredient.Whiskey) + { + FindIngredientObjective obj = qs.FindObjective(); + if (obj?.Completed == false && obj.Ingredient == Ingredient.Whiskey) { PlaySound(Utility.RandomBool() ? 0x42E : 0x43F); @@ -83,6 +84,7 @@ namespace Server.Engines.Quests.Hag return; } + } PlaySound(0x42C); SayTo(player, 1055041); // The drunken pirate shakes his fist at you and goes back to drinking. diff --git a/Scripts/Engines/Quests/Witch Apprentice/Mobiles/Grizelda.cs b/Scripts/Engines/Quests/Witch Apprentice/Mobiles/Grizelda.cs index 3f50e97bc..461651ef0 100644 --- a/Scripts/Engines/Quests/Witch Apprentice/Mobiles/Grizelda.cs +++ b/Scripts/Engines/Quests/Witch Apprentice/Mobiles/Grizelda.cs @@ -57,9 +57,9 @@ namespace Server.Engines.Quests.Hag } else { - QuestObjective obj = qs.FindObjective(typeof(FindGrizeldaAboutMurderObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { PlaySound(0x420); PlaySound(0x20); @@ -74,9 +74,9 @@ namespace Server.Engines.Quests.Hag } else { - obj = qs.FindObjective(typeof(ReturnRecipeObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { PlaySound(0x258); PlaySound(0x41B); @@ -90,9 +90,9 @@ namespace Server.Engines.Quests.Hag } else { - obj = qs.FindObjective(typeof(ReturnIngredientsObjective)); + obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { Container cont = GetNewContainer(); @@ -181,13 +181,12 @@ namespace Server.Engines.Quests.Hag else { QuestSystem newQuest = new WitchApprenticeQuest(player); - bool inRestartPeriod = false; if (qs != null) { newQuest.AddConversation(new DontOfferConversation()); } - else if (QuestSystem.CanOfferQuest(player, typeof(WitchApprenticeQuest), out inRestartPeriod)) + else if (QuestSystem.CanOfferQuest(player, typeof(WitchApprenticeQuest), out bool inRestartPeriod)) { PlaySound(0x20); PlaySound(0x206); diff --git a/Scripts/Engines/Quests/Witch Apprentice/Objectives.cs b/Scripts/Engines/Quests/Witch Apprentice/Objectives.cs index 60cae8b05..584c00ac3 100644 --- a/Scripts/Engines/Quests/Witch Apprentice/Objectives.cs +++ b/Scripts/Engines/Quests/Witch Apprentice/Objectives.cs @@ -58,13 +58,13 @@ namespace Server.Engines.Quests.Hag // * You see a strange imp stealing a scrap of paper from the bloodied corpse * Corpse.SendLocalizedMessageTo(player, 1055049); - Timer.DelayCall(TimeSpan.FromSeconds(3.0), new TimerStateCallback(DeleteImp), imp); + Timer.DelayCall(TimeSpan.FromSeconds(3.0), () => DeleteImp(imp)); } } - private void DeleteImp(object imp) + private void DeleteImp(Mobile m) { - if (imp is Mobile m && !m.Deleted) + if (m?.Deleted == false) { Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10, 10); Effects.PlaySound(m.Location, m.Map, 0x1FE); @@ -215,7 +215,7 @@ namespace Server.Engines.Quests.Hag imp.Direction = imp.GetDirectionTo(from); - Timer.DelayCall(TimeSpan.FromSeconds(3.0), new TimerStateCallback(DeleteImp), imp); + Timer.DelayCall(TimeSpan.FromSeconds(3.0), () => DeleteImp(imp)); } private void DeleteImp(object imp) diff --git a/Scripts/Engines/RemoteAdmin/Network.cs b/Scripts/Engines/RemoteAdmin/Network.cs index d16eb52d4..16ee46cc3 100644 --- a/Scripts/Engines/RemoteAdmin/Network.cs +++ b/Scripts/Engines/RemoteAdmin/Network.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using System.Text; using Server.Accounting; @@ -15,7 +15,7 @@ namespace Server.RemoteAdmin private const string DateFormat = "MMMM dd hh:mm:ss.f tt"; - private static ArrayList m_Auth = new ArrayList(); + private static List m_Auth = new List(); private static bool m_NewLine = true; private static StringBuilder m_ConsoleData = new StringBuilder(); @@ -99,7 +99,7 @@ namespace Server.RemoteAdmin { packet.Acquire(); for (int i = 0; i < m_Auth.Count; i++) - ((NetState)m_Auth[i]).Send(packet); + m_Auth[i].Send(packet); packet.Release(); } @@ -146,15 +146,15 @@ namespace Server.RemoteAdmin } } - private static void DelayedDisconnect(NetState state) + private static void DelayedDisconnect(NetState ns) { - Timer.DelayCall(TimeSpan.FromSeconds(15.0), new TimerStateCallback(Disconnect), state); + Timer.DelayCall(TimeSpan.FromSeconds(15.0), () => Disconnect(ns)); } - private static void Disconnect(object state) + private static void Disconnect(NetState ns) { - m_Auth.Remove(state); - ((NetState)state).Dispose(); + m_Auth.Remove(ns); + ns.Dispose(); } public static void Authenticate(NetState state, PacketReader pvSrc) @@ -208,10 +208,10 @@ namespace Server.RemoteAdmin private static void CleanUp() { //remove dead instances from m_Auth - ArrayList list = new ArrayList(); + List list = new List(); for (int i = 0; i < m_Auth.Count; i++) { - NetState ns = (NetState)m_Auth[i]; + NetState ns = m_Auth[i]; if (ns.Running) list.Add(ns); } @@ -221,8 +221,7 @@ namespace Server.RemoteAdmin public static Packet Compress(Packet p) { - int length; - byte[] source = p.Compile(false, out length); + byte[] source = p.Compile(false, out int length); if (length > 100 && length < 60000) { diff --git a/Scripts/Engines/RemoteAdmin/PacketHandlers.cs b/Scripts/Engines/RemoteAdmin/PacketHandlers.cs index 4f3c526fc..45242a2cd 100644 --- a/Scripts/Engines/RemoteAdmin/PacketHandlers.cs +++ b/Scripts/Engines/RemoteAdmin/PacketHandlers.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server.Accounting; using Server.Network; @@ -59,7 +59,7 @@ namespace Server.RemoteAdmin term = term.ToUpper(); - ArrayList list = new ArrayList(); + List list = new List(); foreach (Account a in Accounts.GetAccounts()) { @@ -212,7 +212,7 @@ namespace Server.RemoteAdmin "Editing Own Account")); } - ArrayList list = new ArrayList(); + List list = new List(); ushort length = pvSrc.ReadUInt16(); bool invalid = false; for (int i = 0; i < length; i++) @@ -224,10 +224,7 @@ namespace Server.RemoteAdmin invalid = true; } - if (list.Count > 0) - a.IPRestrictions = (string[])list.ToArray(typeof(string)); - else - a.IPRestrictions = new string[0]; + a.IPRestrictions = list.ToArray(); if (invalid) state.Send(new MessageBoxMessage( diff --git a/Scripts/Engines/RemoteAdmin/Packets.cs b/Scripts/Engines/RemoteAdmin/Packets.cs index dfe6b0788..5125686e0 100644 --- a/Scripts/Engines/RemoteAdmin/Packets.cs +++ b/Scripts/Engines/RemoteAdmin/Packets.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server.Accounting; using Server.Items; using Server.Network; @@ -89,7 +89,7 @@ namespace Server.RemoteAdmin public sealed class AccountSearchResults : Packet { - public AccountSearchResults(ArrayList results) : base(0x05) + public AccountSearchResults(List results) : base(0x05) { EnsureCapacity(1 + 2 + 2); diff --git a/Scripts/Engines/Reports/Objects/Charts/BarGraph.cs b/Scripts/Engines/Reports/Objects/Charts/BarGraph.cs index 0cc9931a0..9814480de 100644 --- a/Scripts/Engines/Reports/Objects/Charts/BarGraph.cs +++ b/Scripts/Engines/Reports/Objects/Charts/BarGraph.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Engines.Reports { @@ -154,14 +154,14 @@ namespace Server.Engines.Reports DateTime startPeriod = history.Snapshots[0].TimeStamp.Date + TimeSpan.FromDays(1.0); DateTime endPeriod = history.Snapshots[history.Snapshots.Count - 1].TimeStamp.Date; - ArrayList regions = new ArrayList(); + List regions = new List(); DateTime curDate = DateTime.MinValue; int curPeak = -1; int curLow = 1000; int curTotl = 0; int curCont = 0; - int curValu = 0; + int curValu; for (int i = 0; i < history.Snapshots.Count; ++i) { @@ -195,7 +195,7 @@ namespace Server.Engines.Reports } else { - BarRegion region = (BarRegion)regions[regions.Count - 1]; + BarRegion region = regions[regions.Count - 1]; if (region.m_Name == mnthName) region.m_RangeTo = barGraph.Items.Count; @@ -220,7 +220,7 @@ namespace Server.Engines.Reports curDate = thisDate; } - barGraph.Regions = (BarRegion[])regions.ToArray(typeof(BarRegion)); + barGraph.Regions = regions.ToArray(); return barGraph; } @@ -239,7 +239,7 @@ namespace Server.Engines.Reports barGraph.FontSize = 6; barGraph.Interval = ival; - ArrayList regions = new ArrayList(); + List regions = new List(); for (int i = 0; i < history.Snapshots.Count; ++i) { @@ -275,7 +275,7 @@ namespace Server.Engines.Reports } else { - BarRegion region = (BarRegion)regions[regions.Count - 1]; + BarRegion region = regions[regions.Count - 1]; if (region.m_Name == dayName) region.m_RangeTo = barGraph.Items.Count; @@ -286,7 +286,7 @@ namespace Server.Engines.Reports barGraph.Items.Add(hours + (realHours >= 12 ? " PM" : " AM"), val); } - barGraph.Regions = (BarRegion[])regions.ToArray(typeof(BarRegion)); + barGraph.Regions = regions.ToArray(); return barGraph; } diff --git a/Scripts/Engines/Reports/Objects/Staffing/PageInfo.cs b/Scripts/Engines/Reports/Objects/Staffing/PageInfo.cs index f76a1daa3..9b6ecabec 100644 --- a/Scripts/Engines/Reports/Objects/Staffing/PageInfo.cs +++ b/Scripts/Engines/Reports/Objects/Staffing/PageInfo.cs @@ -127,9 +127,7 @@ namespace Server.Engines.Reports public void UpdateResolver() { - string resolvedBy; - DateTime timeResolved; - PageResolution res = GetResolution(out resolvedBy, out timeResolved); + PageResolution res = GetResolution(out string resolvedBy, out DateTime timeResolved); if (m_History != null && IsStaffResolution(res)) Resolver = m_History.GetStaffInfo(resolvedBy); diff --git a/Scripts/Engines/Reports/Objects/Staffing/StaffHistory.cs b/Scripts/Engines/Reports/Objects/Staffing/StaffHistory.cs index 78ea3be9d..b614bd78f 100644 --- a/Scripts/Engines/Reports/Objects/Staffing/StaffHistory.cs +++ b/Scripts/Engines/Reports/Objects/Staffing/StaffHistory.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.IO; namespace Server.Engines.Reports @@ -15,17 +16,17 @@ namespace Server.Engines.Reports Pages = new PageInfoCollection(); QueueStats = new QueueStatusCollection(); - UserInfo = new Hashtable(StringComparer.OrdinalIgnoreCase); - StaffInfo = new Hashtable(StringComparer.OrdinalIgnoreCase); + UserInfo = new Dictionary(StringComparer.OrdinalIgnoreCase); + StaffInfo = new Dictionary(StringComparer.OrdinalIgnoreCase); } public PageInfoCollection Pages{ get; set; } public QueueStatusCollection QueueStats{ get; set; } - public Hashtable UserInfo{ get; set; } + public Dictionary UserInfo{ get; set; } - public Hashtable StaffInfo{ get; set; } + public Dictionary StaffInfo{ get; set; } public void AddPage(PageInfo info) { @@ -221,7 +222,6 @@ namespace Server.Engines.Reports if (ts >= min && ts < max) { - DateTime date = ts.Date; TimeSpan time = ts.TimeOfDay; int hour = time.Hours; @@ -232,9 +232,8 @@ namespace Server.Engines.Reports } BarGraph barGraph = new BarGraph("Average pages in queue", "graph_pagequeue_avg", 10, "Time", "Pages", - BarGraphRenderMode.Lines); + BarGraphRenderMode.Lines) { FontSize = 6 }; - barGraph.FontSize = 6; for (int i = 7; i <= totals.Length + 7; ++i) { @@ -303,9 +302,8 @@ namespace Server.Engines.Reports } } - BarGraph barGraph = new BarGraph(title, fname, 10, "Time", "Pages", BarGraphRenderMode.Lines); + BarGraph barGraph = new BarGraph(title, fname, 10, "Time", "Pages", BarGraphRenderMode.Lines) { FontSize = 6 }; - barGraph.FontSize = 6; for (int i = 7; i <= totals.Length + 7; ++i) { @@ -348,7 +346,7 @@ namespace Server.Engines.Reports return report; } - private PieChart[] ChartTotalPages(StaffInfo[] staff, TimeSpan ts, string title, string fname) + private PersistableObject[] ChartTotalPages(StaffInfo[] staff, TimeSpan ts, string title, string fname) { DateTime max = DateTime.UtcNow; DateTime min = max - ts; @@ -385,7 +383,7 @@ namespace Server.Engines.Reports resChart.Items.Add("Logged Out", countLogged); resChart.Items.Add("Unresolved", countUnres); - return new[] { staffChart, resChart }; + return new PersistableObject[] { staffChart, resChart }; } #region Type Identification @@ -399,4 +397,4 @@ namespace Server.Engines.Reports #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Reports/Persistance/PersistableObjectCollection.cs b/Scripts/Engines/Reports/Persistance/PersistableObjectCollection.cs index b0b77b560..0d0c7e68d 100644 --- a/Scripts/Engines/Reports/Persistance/PersistableObjectCollection.cs +++ b/Scripts/Engines/Reports/Persistance/PersistableObjectCollection.cs @@ -1,13 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 1.1.4322.573 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - using System; using System.Collections; diff --git a/Scripts/Engines/Reports/Persistance/PersistableType.cs b/Scripts/Engines/Reports/Persistance/PersistableType.cs index 9d1233d16..b65af48bb 100644 --- a/Scripts/Engines/Reports/Persistance/PersistableType.cs +++ b/Scripts/Engines/Reports/Persistance/PersistableType.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Engines.Reports { @@ -7,11 +8,11 @@ namespace Server.Engines.Reports public sealed class PersistableTypeRegistry { - private static Hashtable m_Table; + private static Dictionary m_Table; static PersistableTypeRegistry() { - m_Table = new Hashtable(StringComparer.OrdinalIgnoreCase); + m_Table = new Dictionary(StringComparer.OrdinalIgnoreCase); Register(Report.ThisTypeID); Register(BarGraph.ThisTypeID); @@ -31,7 +32,7 @@ namespace Server.Engines.Reports public static PersistableType Find(string name) { - return m_Table[name] as PersistableType; + return m_Table[name]; } public static void Register(PersistableType type) @@ -53,4 +54,4 @@ namespace Server.Engines.Reports public ConstructCallback Constructor{ get; } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Reports/Persistance/PersistanceReader.cs b/Scripts/Engines/Reports/Persistance/PersistanceReader.cs index 46b1c77d6..877fe6ec8 100644 --- a/Scripts/Engines/Reports/Persistance/PersistanceReader.cs +++ b/Scripts/Engines/Reports/Persistance/PersistanceReader.cs @@ -41,12 +41,12 @@ namespace Server.Engines.Reports public override int GetInt32(string key) { - return XmlConvert.ToInt32(m_Xml.GetAttribute(key)); + return XmlConvert.ToInt32(m_Xml.GetAttribute(key) ?? ""); } public override bool GetBoolean(string key) { - return XmlConvert.ToBoolean(m_Xml.GetAttribute(key)); + return XmlConvert.ToBoolean(m_Xml.GetAttribute(key) ?? ""); } public override string GetString(string key) diff --git a/Scripts/Engines/Reports/Persistance/PersistanceWriter.cs b/Scripts/Engines/Reports/Persistance/PersistanceWriter.cs index 45f9be8c4..876598b0b 100644 --- a/Scripts/Engines/Reports/Persistance/PersistanceWriter.cs +++ b/Scripts/Engines/Reports/Persistance/PersistanceWriter.cs @@ -102,7 +102,7 @@ namespace Server.Engines.Reports try { - string renamed = null; + string renamed; if (File.Exists(m_RealFilePath)) { diff --git a/Scripts/Engines/Reports/Rendering/BarGraphRenderer.cs b/Scripts/Engines/Reports/Rendering/BarGraphRenderer.cs index 8abb67f31..ad5e8c2da 100644 --- a/Scripts/Engines/Reports/Rendering/BarGraphRenderer.cs +++ b/Scripts/Engines/Reports/Rendering/BarGraphRenderer.cs @@ -516,7 +516,7 @@ namespace Server.Engines.Reports for (int i = 0; i < VerticalTickCount; i++) { float currentY = _topBuffer + i * _yTickValue / _scaleFactor; // Position for tick mark - float labelY = currentY - lblFont.Height / 2; // Place label in the middle of tick + float labelY = currentY - lblFont.Height / 2.0f; // Place label in the middle of tick RectangleF lblRec = new RectangleF(_spacer + fo - 6, labelY, _maxTickValueWidth, lblFont.Height); float currentTick = _maxValue - i * _yTickValue; // Calculate tick value from top to bottom diff --git a/Scripts/Engines/Reports/Rendering/DataItem.cs b/Scripts/Engines/Reports/Rendering/DataItem.cs index 35e617564..f3fa982b1 100644 --- a/Scripts/Engines/Reports/Rendering/DataItem.cs +++ b/Scripts/Engines/Reports/Rendering/DataItem.cs @@ -3,16 +3,6 @@ using System.Drawing; namespace Server.Engines.Reports { - // Modified from MS sample - - //********************************************************************* - // - // ChartItem Class - // - // This class represents a data point in a chart - // - //********************************************************************* - public class DataItem { private DataItem() @@ -42,12 +32,6 @@ namespace Server.Engines.Reports public float SweepSize{ get; set; } } - //********************************************************************* - // - // Custom Collection for ChartItems - // - //********************************************************************* - public class ChartItemsCollection : CollectionBase { public DataItem this[int index] diff --git a/Scripts/Engines/Reports/Rendering/HtmlRenderer.cs b/Scripts/Engines/Reports/Rendering/HtmlRenderer.cs index 98107e488..c982c058f 100644 --- a/Scripts/Engines/Reports/Rendering/HtmlRenderer.cs +++ b/Scripts/Engines/Reports/Rendering/HtmlRenderer.cs @@ -116,10 +116,11 @@ namespace Server.Engines.Reports { Process p = Process.Start(psi); - p.WaitForExit(); + p?.WaitForExit(); } catch { + // ignored } Console.WriteLine("Reports: {0}: Upload complete", m_Title); @@ -130,6 +131,7 @@ namespace Server.Engines.Reports } catch { + // ignored } } @@ -192,8 +194,6 @@ namespace Server.Engines.Reports html.RenderBeginTag(HtmlTag.Center); TimeZone tz = TimeZone.CurrentTimeZone; - bool isDaylight = tz.IsDaylightSavingTime(m_TimeStamp); - TimeSpan utcOffset = tz.GetUtcOffset(m_TimeStamp); html.Write("Snapshot taken at {0:d} {0:t}. All times are {1}.", m_TimeStamp, tz.StandardName); html.RenderEndTag(); @@ -258,8 +258,6 @@ namespace Server.Engines.Reports html.Write("
"); TimeZone tz = TimeZone.CurrentTimeZone; - bool isDaylight = tz.IsDaylightSavingTime(m_TimeStamp); - TimeSpan utcOffset = tz.GetUtcOffset(m_TimeStamp); html.Write("Snapshot taken at {0:d} {0:t}. All times are {1}.", m_TimeStamp, tz.StandardName); html.RenderEndTag(); diff --git a/Scripts/Engines/Reports/Rendering/PieChartRenderer.cs b/Scripts/Engines/Reports/Rendering/PieChartRenderer.cs index 7e8da47fc..9ecf48e04 100644 --- a/Scripts/Engines/Reports/Rendering/PieChartRenderer.cs +++ b/Scripts/Engines/Reports/Rendering/PieChartRenderer.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; @@ -20,7 +20,7 @@ namespace Server.Engines.Reports private const int _bufferSpace = 125; private Color _backgroundColor; private Color _borderColor; - private ArrayList _chartItems; + private List _chartItems; private int _legendFontHeight; private float _legendFontSize; private string _legendFontStyle; @@ -29,19 +29,13 @@ namespace Server.Engines.Reports private int _perimeter; private float _total; - public PieChartRenderer() + public PieChartRenderer() : this(Color.White) { - _chartItems = new ArrayList(); - _perimeter = 250; - _backgroundColor = Color.White; - _borderColor = Color.FromArgb(63, 63, 63); - _legendFontSize = 8; - _legendFontStyle = "Verdana"; } public PieChartRenderer(Color bgColor) { - _chartItems = new ArrayList(); + _chartItems = new List(); _perimeter = 250; _backgroundColor = bgColor; _borderColor = Color.FromArgb(63, 63, 63); @@ -118,7 +112,7 @@ namespace Server.Engines.Reports //Draw all wedges and legends for (int i = 0; i < _chartItems.Count; i++) { - DataItem item = (DataItem)_chartItems[i]; + DataItem item = _chartItems[i]; SolidBrush brs = null; try { @@ -188,7 +182,7 @@ namespace Server.Engines.Reports for (int i = 0; i < _chartItems.Count; i++) { - DataItem item = (DataItem)_chartItems[i]; + DataItem item = _chartItems[i]; try { grp.DrawPie(new Pen(_borderColor, 0.5f), pieRect, item.StartPos, item.SweepSize); diff --git a/Scripts/Engines/Reports/Reports.cs b/Scripts/Engines/Reports/Reports.cs index 2350a3ba8..6031133b4 100644 --- a/Scripts/Engines/Reports/Reports.cs +++ b/Scripts/Engines/Reports/Reports.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Threading; using Server.Accounting; @@ -132,24 +131,24 @@ namespace Server.Engines.Reports Ladder ladder = Ladder.Instance; - if (ladder != null) + if (ladder == null) + return chart; + + List entries = ladder.Entries; + + for (int i = entries.Count - 1; i >= 0; --i) { - ArrayList entries = ladder.ToArrayList(); + LadderEntry entry = entries[i]; + int level = Ladder.GetLevel(entry.Experience); - for (int i = entries.Count - 1; i >= 0; --i) + if (lastItem == null || level != lastLevel) { - LadderEntry entry = (LadderEntry)entries[i]; - int level = Ladder.GetLevel(entry.Experience); - - if (lastItem == null || level != lastLevel) - { - chart.Items.Add(lastItem = new ChartItem(level.ToString(), 1)); - lastLevel = level; - } - else - { - lastItem.Value++; - } + chart.Items.Add(lastItem = new ChartItem(level.ToString(), 1)); + lastLevel = level; + } + else + { + lastItem.Value++; } } @@ -171,11 +170,11 @@ namespace Server.Engines.Reports if (ladder != null) { - ArrayList entries = ladder.ToArrayList(); + List entries = ladder.Entries; for (int i = 0; i < entries.Count && i < 15; ++i) { - LadderEntry entry = (LadderEntry)entries[i]; + LadderEntry entry = entries[i]; int level = Ladder.GetLevel(entry.Experience); string guild = ""; @@ -204,40 +203,40 @@ namespace Server.Engines.Reports Preferences prefs = Preferences.Instance; - if (prefs != null) + if (prefs == null) + return chart; + + List arenas = Arena.Arenas; + + for (int i = 0; i < arenas.Count; ++i) { - List arenas = Arena.Arenas; + Arena arena = arenas[i]; - for (int i = 0; i < arenas.Count; ++i) + string name = arena.Name; + + if (name != null) + chart.Items.Add(name, 0); + } + + List entries = prefs.Entries; + + for (int i = 0; i < entries.Count; ++i) + { + PreferencesEntry entry = entries[i]; + List list = entry.Disliked; + + for (int j = 0; j < list.Count; ++j) { - Arena arena = arenas[i]; + string disliked = list[j]; - string name = arena.Name; - - if (name != null) - chart.Items.Add(name, 0); - } - - ArrayList entries = prefs.Entries; - - for (int i = 0; i < entries.Count; ++i) - { - PreferencesEntry entry = (PreferencesEntry)entries[i]; - ArrayList list = entry.Disliked; - - for (int j = 0; j < list.Count; ++j) + for (int k = 0; k < chart.Items.Count; ++k) { - string disliked = (string)list[j]; + ChartItem item = chart.Items[k]; - for (int k = 0; k < chart.Items.Count; ++k) + if (item.Name == disliked) { - ChartItem item = chart.Items[k]; - - if (item.Name == disliked) - { - ++item.Value; - break; - } + ++item.Value; + break; } } } @@ -364,7 +363,7 @@ namespace Server.Engines.Reports report.Columns.Add("28%", "center", "Office"); report.Columns.Add("16%", "center", "Kill Points"); - ArrayList list = new ArrayList(); + List list = new List(); List factions = Faction.Factions; @@ -380,7 +379,7 @@ namespace Server.Engines.Reports for (int i = 0; i < list.Count && i < 15; ++i) { - PlayerState pl = (PlayerState)list[i]; + PlayerState pl = list[i]; string office; diff --git a/Scripts/Engines/Spawner/Spawner.cs b/Scripts/Engines/Spawner/Spawner.cs index 6725a3701..09cdf19a2 100644 --- a/Scripts/Engines/Spawner/Spawner.cs +++ b/Scripts/Engines/Spawner/Spawner.cs @@ -593,7 +593,7 @@ namespace Server.Mobiles } catch (Exception e) { - Console.WriteLine("EXCEPTION CAUGHT: {0:X}", Serial); + Console.WriteLine($"EXCEPTION CAUGHT: {Serial}"); Console.WriteLine(e); return false; } @@ -639,8 +639,7 @@ namespace Server.Mobiles { int x = Location.X + (Utility.Random(m_HomeRange * 2 + 1) - m_HomeRange); int y = Location.Y + (Utility.Random(m_HomeRange * 2 + 1) - m_HomeRange); - int z = Map.GetAverageZ(x, y); - + int mapZ = map.GetAverageZ(x, y); if (waterMob) diff --git a/Scripts/Engines/Treasures of Tokuno/BasePigmentsOfTokuno.cs b/Scripts/Engines/Treasures of Tokuno/BasePigmentsOfTokuno.cs index 2730ab765..d697082db 100644 --- a/Scripts/Engines/Treasures of Tokuno/BasePigmentsOfTokuno.cs +++ b/Scripts/Engines/Treasures of Tokuno/BasePigmentsOfTokuno.cs @@ -114,7 +114,7 @@ namespace Server.Items if (IsAccessibleTo(from) && from.InRange(GetWorldLocation(), 3)) { from.SendLocalizedMessage(1070929); // Select the artifact or enhanced magic item to dye. - from.BeginTarget(3, false, TargetFlags.None, new TargetStateCallback(InternalCallback), this); + from.BeginTarget(3, false, TargetFlags.None, InternalCallback); } else { @@ -122,12 +122,11 @@ namespace Server.Items } } - private void InternalCallback(Mobile from, object targeted, object state) + private void InternalCallback(Mobile from, object targeted) { - BasePigmentsOfTokuno pigment = (BasePigmentsOfTokuno)state; - - if (pigment.Deleted || pigment.UsesRemaining <= 0 || !from.InRange(pigment.GetWorldLocation(), 3) || - !pigment.IsAccessibleTo(from)) + + if (Deleted || UsesRemaining <= 0 || !from.InRange(GetWorldLocation(), 3) || + !IsAccessibleTo(from)) return; if (!(targeted is Item i)) @@ -173,8 +172,8 @@ namespace Server.Items //Notes: on OSI there IS no hue check to see if it's already hued. and no messages on successful hue either i.Hue = Hue; - if (--pigment.UsesRemaining <= 0) - pigment.Delete(); + if (--UsesRemaining <= 0) + Delete(); from.PlaySound(0x23E); // As per OSI TC1 } @@ -278,7 +277,7 @@ namespace Server.Items } } - public bool ShowUsesRemaining + bool IUsesRemaining.ShowUsesRemaining { get => true; set { } diff --git a/Scripts/Engines/Treasures of Tokuno/TreasuresOfTokuno.cs b/Scripts/Engines/Treasures of Tokuno/TreasuresOfTokuno.cs index efc3a5c66..730d50ae6 100644 --- a/Scripts/Engines/Treasures of Tokuno/TreasuresOfTokuno.cs +++ b/Scripts/Engines/Treasures of Tokuno/TreasuresOfTokuno.cs @@ -1,6 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Linq; using Server.Gumps; using Server.Items; using Server.Misc; @@ -110,7 +110,7 @@ namespace Server.Misc { Region r = m.Region; - if (r.IsPartOf(typeof(HouseRegion)) || BaseBoat.FindBoatAt(m, m.Map) != null) + if (r.IsPartOf() || BaseBoat.FindBoatAt(m, m.Map) != null) return false; //TODO: a CanReach of something check as opposed to above? @@ -159,6 +159,7 @@ namespace Server.Misc } catch { + // ignored } if (i != null) @@ -261,9 +262,9 @@ namespace Server.Mobiles SayTo(pm, 1070980); // Congratulations! You have turned in enough minor treasures to earn a greater reward. - pm.CloseGump(typeof(ToTTurnInGump)); //Sanity + pm.CloseGump(); //Sanity - if (!pm.HasGump(typeof(ToTRedeemGump))) + if (!pm.HasGump()) pm.SendGump(new ToTRedeemGump(this, false)); } else @@ -275,9 +276,9 @@ namespace Server.Mobiles SayTo(pm, 1070981, $"{pm.ToTItemsTurnedIn}\t{TreasuresOfTokuno.ItemsPerReward}"); // You have turned in ~1_COUNT~ minor artifacts. Turn in ~2_NUM~ to receive a reward. - ArrayList buttons = ToTTurnInGump.FindRedeemableItems(pm); + List buttons = ToTTurnInGump.FindRedeemableItems(pm); - if (buttons.Count > 0 && !pm.HasGump(typeof(ToTTurnInGump))) + if (buttons.Count > 0 && !pm.HasGump()) pm.SendGump(new ToTTurnInGump(this, buttons)); } } @@ -286,8 +287,8 @@ namespace Server.Mobiles if (!InRange(m, leaveRange) && InRange(oldLocation, leaveRange)) { - pm.CloseGump(typeof(ToTRedeemGump)); - pm.CloseGump(typeof(ToTTurnInGump)); + pm.CloseGump(); + pm.CloseGump(); } } } @@ -315,30 +316,25 @@ namespace Server.Gumps { private Mobile m_Collector; - public ToTTurnInGump(Mobile collector, ArrayList buttons) : - base(1071012, buttons) // Click a minor artifact to give it to Ihara Soko. + public ToTTurnInGump(Mobile collector, List buttons) : + base(1071012, Utility.CastListContravariant(buttons)) // Click a minor artifact to give it to Ihara Soko. { m_Collector = collector; } - public ToTTurnInGump(Mobile collector, ItemTileButtonInfo[] buttons) : - base(1071012, buttons) // Click a minor artifact to give it to Ihara Soko. + public static List FindRedeemableItems(Mobile m) { - m_Collector = collector; - } - - public static ArrayList FindRedeemableItems(Mobile m) - { - Backpack pack = (Backpack)m.Backpack; + Container pack = m.Backpack; if (pack == null) - return new ArrayList(); + return new List(); - ArrayList items = new ArrayList(pack.FindItemsByType(TreasuresOfTokuno.LesserArtifactsTotal)); - ArrayList buttons = new ArrayList(); + List buttons = new List(); - for (int i = 0; i < items.Count; i++) + Item[] items = pack.FindItemsByType(TreasuresOfTokuno.LesserArtifactsTotal); + + for (int i = 0; i < items.Length; i++) { - Item item = (Item)items[i]; + Item item = items[i]; if (item is ChestOfHeirlooms heirlooms && !heirlooms.Locked) continue; @@ -370,9 +366,9 @@ namespace Server.Gumps m_Collector.SayTo(pm, 1070980); // Congratulations! You have turned in enough minor treasures to earn a greater reward. - pm.CloseGump(typeof(ToTTurnInGump)); //Sanity + pm.CloseGump(); //Sanity - if (!pm.HasGump(typeof(ToTRedeemGump))) + if (!pm.HasGump()) pm.SendGump(new ToTRedeemGump(m_Collector, false)); } else @@ -380,9 +376,9 @@ namespace Server.Gumps m_Collector.SayTo(pm, 1070981, $"{pm.ToTItemsTurnedIn}\t{TreasuresOfTokuno.ItemsPerReward}"); // You have turned in ~1_COUNT~ minor artifacts. Turn in ~2_NUM~ to receive a reward. - ArrayList buttons = FindRedeemableItems(pm); + List buttons = FindRedeemableItems(pm); - pm.CloseGump(typeof(ToTTurnInGump)); //Sanity + pm.CloseGump(); //Sanity if (buttons.Count > 0) pm.SendGump(new ToTTurnInGump(m_Collector, buttons)); @@ -415,8 +411,9 @@ namespace Server.Gumps public ToTRedeemGump(Mobile collector, bool pigments) : base(pigments ? 1070986 : 1070985, pigments - ? PigmentRewards[(int)TreasuresOfTokuno.RewardEra - 1] - : (ImageTileButtonInfo[])NormalRewards[(int)TreasuresOfTokuno.RewardEra - 1]) + ? PigmentRewards[(int)TreasuresOfTokuno.RewardEra - 1].ToArray() + : NormalRewards[(int)TreasuresOfTokuno.RewardEra - 1].ToArray() + ) { m_Collector = collector; } @@ -517,24 +514,20 @@ namespace Server.Gumps !(pm.ToTItemsTurnedIn >= TreasuresOfTokuno.ItemsPerReward)) return; - bool pigments = buttonInfo is PigmentsTileButtonInfo; - Item item = null; - if (pigments) + if (buttonInfo is PigmentsTileButtonInfo p) { - PigmentsTileButtonInfo p = (PigmentsTileButtonInfo)buttonInfo; - item = new PigmentsOfTokuno(p.Pigment); } else { - TypeTileButtonInfo t = buttonInfo as TypeTileButtonInfo; + TypeTileButtonInfo t = (TypeTileButtonInfo)buttonInfo; if (t.Type == typeof(PigmentsOfTokuno)) //Special case of course. { - pm.CloseGump(typeof(ToTTurnInGump)); //Sanity - pm.CloseGump(typeof(ToTRedeemGump)); + pm.CloseGump(); //Sanity + pm.CloseGump(); pm.SendGump(new ToTRedeemGump(m_Collector, true)); @@ -547,6 +540,7 @@ namespace Server.Gumps } catch { + // ignored } } diff --git a/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs b/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs index 3909ec5e3..33e3dfd8d 100644 --- a/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs +++ b/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using Server.Accounting; using Server.ContextMenus; @@ -615,7 +614,7 @@ namespace Server.Mobiles m_Maker.Delete(); statue.Sculpt(from); - from.CloseGump(typeof(CharacterStatueGump)); + from.CloseGump(); from.SendGump(new CharacterStatueGump(m_Maker, statue, from)); } else if (result == AddonFitResult.Blocked) @@ -640,7 +639,7 @@ namespace Server.Mobiles public static AddonFitResult CouldFit(Point3D p, Map map, Mobile from, ref BaseHouse house) { - if (!map.CanFit(p.X, p.Y, p.Z, 20, true, true, true)) + if (!map.CanFit(p.X, p.Y, p.Z, 20, true)) return AddonFitResult.Blocked; if (!BaseAddon.CheckHouse(from, p, map, 20, ref house)) return AddonFitResult.NotInHouse; @@ -650,11 +649,11 @@ namespace Server.Mobiles public static AddonFitResult CheckDoors(Point3D p, int height, BaseHouse house) { - ArrayList doors = house.Doors; + List doors = house.Doors; for (int i = 0; i < doors.Count; i++) { - BaseDoor door = doors[i] as BaseDoor; + BaseDoor door = doors[i]; Point3D doorLoc = door.GetWorldLocation(); int doorHeight = door.ItemData.CalcHeight; diff --git a/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatuePlinth.cs b/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatuePlinth.cs index 225aa39e0..f35f30a94 100644 --- a/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatuePlinth.cs +++ b/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatuePlinth.cs @@ -101,7 +101,7 @@ namespace Server.Items { Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Engines/VeteranRewards/Character Statue Maker/Gumps/CharacterStatueGump.cs b/Scripts/Engines/VeteranRewards/Character Statue Maker/Gumps/CharacterStatueGump.cs index 2589661b2..4d163d145 100644 --- a/Scripts/Engines/VeteranRewards/Character Statue Maker/Gumps/CharacterStatueGump.cs +++ b/Scripts/Engines/VeteranRewards/Character Statue Maker/Gumps/CharacterStatueGump.cs @@ -20,7 +20,7 @@ namespace Server.Gumps Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Engines/VeteranRewards/RewardChoiceGump.cs b/Scripts/Engines/VeteranRewards/RewardChoiceGump.cs index 6efec0e1d..f2d2fb499 100644 --- a/Scripts/Engines/VeteranRewards/RewardChoiceGump.cs +++ b/Scripts/Engines/VeteranRewards/RewardChoiceGump.cs @@ -13,7 +13,7 @@ namespace Server.Engines.VeteranRewards { m_From = from; - from.CloseGump(typeof(RewardChoiceGump)); + from.CloseGump(); RenderBackground(); RenderCategories(); @@ -59,9 +59,7 @@ namespace Server.Engines.VeteranRewards "To read more about these rewards before making a selection, feel free to visit the uo.com site at " + "http://www.uo.com/rewards.", true, true); - int cur, max; - - RewardSystem.ComputeRewardInfo(m_From, out cur, out max); + RewardSystem.ComputeRewardInfo(m_From, out int cur, out int max); AddHtmlLocalized(60, 105, 300, 35, 1006006, false, false); // Your current total of rewards to choose: AddLabel(370, 107, 50, (max - cur).ToString()); @@ -100,9 +98,9 @@ namespace Server.Engines.VeteranRewards private int PagesPerCategory(RewardCategory category) { List entries = category.Entries; - int j = 0, i = 0; + int i = 0; - for (j = 0; j < entries.Count; j++) + for (int j = 0; j < entries.Count; j++) if (RewardSystem.HasAccess(m_From, entries[j])) i++; @@ -160,9 +158,7 @@ namespace Server.Engines.VeteranRewards if (buttonID == 0) { - int cur, max; - - RewardSystem.ComputeRewardInfo(m_From, out cur, out max); + RewardSystem.ComputeRewardInfo(m_From, out int cur, out int max); if (cur < max) m_From.SendGump(new RewardNoticeGump(m_From)); diff --git a/Scripts/Engines/VeteranRewards/RewardConfirmGump.cs b/Scripts/Engines/VeteranRewards/RewardConfirmGump.cs index 2e7a8fa24..046692279 100644 --- a/Scripts/Engines/VeteranRewards/RewardConfirmGump.cs +++ b/Scripts/Engines/VeteranRewards/RewardConfirmGump.cs @@ -14,7 +14,7 @@ namespace Server.Engines.VeteranRewards m_From = from; m_Entry = entry; - from.CloseGump(typeof(RewardConfirmGump)); + from.CloseGump(); AddPage(0); @@ -61,9 +61,7 @@ namespace Server.Engines.VeteranRewards } } - int cur, max; - - RewardSystem.ComputeRewardInfo(m_From, out cur, out max); + RewardSystem.ComputeRewardInfo(m_From, out int cur, out int max); if (cur < max) m_From.SendGump(new RewardNoticeGump(m_From)); diff --git a/Scripts/Engines/VeteranRewards/RewardDemolitionGump.cs b/Scripts/Engines/VeteranRewards/RewardDemolitionGump.cs index b3029325f..e434ad546 100644 --- a/Scripts/Engines/VeteranRewards/RewardDemolitionGump.cs +++ b/Scripts/Engines/VeteranRewards/RewardDemolitionGump.cs @@ -14,7 +14,7 @@ namespace Server.Gumps Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddBackground(0, 0, 220, 170, 0x13BE); diff --git a/Scripts/Engines/VeteranRewards/RewardEntry.cs b/Scripts/Engines/VeteranRewards/RewardEntry.cs index 61798575a..7a67c04d3 100644 --- a/Scripts/Engines/VeteranRewards/RewardEntry.cs +++ b/Scripts/Engines/VeteranRewards/RewardEntry.cs @@ -73,6 +73,7 @@ namespace Server.Engines.VeteranRewards } catch { + // ignored } return null; diff --git a/Scripts/Engines/VeteranRewards/RewardNoticeGump.cs b/Scripts/Engines/VeteranRewards/RewardNoticeGump.cs index d2c72c640..14e1d085a 100644 --- a/Scripts/Engines/VeteranRewards/RewardNoticeGump.cs +++ b/Scripts/Engines/VeteranRewards/RewardNoticeGump.cs @@ -11,7 +11,7 @@ namespace Server.Engines.VeteranRewards { m_From = from; - from.CloseGump(typeof(RewardNoticeGump)); + from.CloseGump(); AddPage(0); diff --git a/Scripts/Engines/VeteranRewards/RewardSystem.cs b/Scripts/Engines/VeteranRewards/RewardSystem.cs index 0f07dd0c5..0be464dc8 100644 --- a/Scripts/Engines/VeteranRewards/RewardSystem.cs +++ b/Scripts/Engines/VeteranRewards/RewardSystem.cs @@ -54,10 +54,10 @@ namespace Server.Engines.VeteranRewards public static bool HasAccess(Mobile mob, RewardEntry entry) { - if (Core.Expansion < entry.RequiredExpansion) return false; + if (Core.Expansion < entry.RequiredExpansion) + return false; - TimeSpan ts; - return HasAccess(mob, entry.List, out ts); + return HasAccess(mob, entry.List, out TimeSpan _); } public static bool HasAccess(Mobile mob, RewardList list, out TimeSpan ts) @@ -184,45 +184,43 @@ namespace Server.Engines.VeteranRewards { RewardList list = m_Lists[i]; RewardEntry[] entries = list.Entries; - TimeSpan ts; for (int j = 0; j < entries.Length; ++j) - if (entries[j].ItemType == type) + { + if (entries[j].ItemType != type) + continue; + + if (args == null && entries[j].Args.Length == 0) { - if (args == null && entries[j].Args.Length == 0) - { - if ((!isRelaxedRules || i > 0) && !HasAccess(from, list, out ts)) - { - from.SendLocalizedMessage(1008126, true, - Math.Ceiling(ts.TotalDays / 30.0) - .ToString()); // Your account is not old enough to use this item. Months until you can use this item : - return false; - } - + if (isRelaxedRules && i <= 0 || HasAccess(from, list, out TimeSpan ts)) return true; - } + + from.SendLocalizedMessage(1008126, true, + Math.Ceiling(ts.TotalDays / 30.0) + .ToString()); // Your account is not old enough to use this item. Months until you can use this item : + return false; - if (args.Length == entries[j].Args.Length) - { - bool match = true; - - for (int k = 0; match && k < args.Length; ++k) - match = args[k].Equals(entries[j].Args[k]); - - if (match) - { - if ((!isRelaxedRules || i > 0) && !HasAccess(from, list, out ts)) - { - from.SendLocalizedMessage(1008126, true, - Math.Ceiling(ts.TotalDays / 30.0) - .ToString()); // Your account is not old enough to use this item. Months until you can use this item : - return false; - } - - return true; - } - } } + + if (args?.Length != entries[j].Args.Length) + continue; + + bool match = true; + + for (int k = 0; match && k < args.Length; ++k) + match = args[k].Equals(entries[j].Args[k]); + + if (match) + { + if (isRelaxedRules && i <= 0 || HasAccess(from, list, out TimeSpan ts)) + return true; + + from.SendLocalizedMessage(1008126, true, + Math.Ceiling(ts.TotalDays / 30.0) + .ToString()); // Your account is not old enough to use this item. Months until you can use this item : + return false; + } + } } // no entry? @@ -474,9 +472,7 @@ namespace Server.Engines.VeteranRewards if (!e.Mobile.Alive) return; - int cur, max, level; - - ComputeRewardInfo(e.Mobile, out cur, out max, out level); + ComputeRewardInfo(e.Mobile, out int cur, out int max, out int level); if (e.Mobile.SkillsCap == 7000 || e.Mobile.SkillsCap == 7050 || e.Mobile.SkillsCap == 7100 || e.Mobile.SkillsCap == 7150 || e.Mobile.SkillsCap == 7200) diff --git a/Scripts/Engines/Virtues/Compassion.cs b/Scripts/Engines/Virtues/Compassion.cs index 3d5d66efc..362989d4b 100644 --- a/Scripts/Engines/Virtues/Compassion.cs +++ b/Scripts/Engines/Virtues/Compassion.cs @@ -34,6 +34,7 @@ namespace Server } catch { + // ignored } } } diff --git a/Scripts/Engines/Virtues/Honor.cs b/Scripts/Engines/Virtues/Honor.cs index 91a792460..908561a7c 100644 --- a/Scripts/Engines/Virtues/Honor.cs +++ b/Scripts/Engines/Virtues/Honor.cs @@ -93,7 +93,7 @@ namespace Server private static void Honor(PlayerMobile source, Mobile target) { IHonorTarget honorTarget = target as IHonorTarget; - GuardedRegion reg = (GuardedRegion)source.Region.GetRegion(typeof(GuardedRegion)); + GuardedRegion reg = source.Region.GetRegion(); Map map = source.Map; if (honorTarget == null) @@ -343,7 +343,7 @@ namespace Server return; double dGain = - targetFame / 100 * (m_HonorDamage / m_TotalDamage); //Initial honor gain is 100th of the monsters honor + targetFame / 100.0 * (m_HonorDamage / m_TotalDamage); //Initial honor gain is 100th of the monsters honor if (m_HonorDamage == m_TotalDamage && m_FirstHit == FirstHit.Granted) dGain = dGain * 1.5; //honor gain is increased alot more if the combat was fully honorable diff --git a/Scripts/Engines/Virtues/Justice.cs b/Scripts/Engines/Virtues/Justice.cs index 84d904a68..c726b790a 100644 --- a/Scripts/Engines/Virtues/Justice.cs +++ b/Scripts/Engines/Virtues/Justice.cs @@ -52,7 +52,7 @@ namespace Server { protector.SendLocalizedMessage(1049610); // You must reach the first path in this virtue to invoke it. } - else if (!protector.CanBeginAction(typeof(JusticeVirtue))) + else if (!protector.CanBeginAction()) { protector.SendLocalizedMessage(1049370); // You must wait a while before offering your protection again. } @@ -81,7 +81,7 @@ namespace Server if (!VirtueHelper.IsSeeker(protector, VirtueName.Justice)) protector.SendLocalizedMessage(1049610); // You must reach the first path in this virtue to invoke it. - else if (!protector.CanBeginAction(typeof(JusticeVirtue))) + else if (!protector.CanBeginAction()) protector.SendLocalizedMessage(1049370); // You must wait a while before offering your protection again. else if (protector.JusticeProtectors.Count > 0) protector.SendLocalizedMessage(1049542); // You cannot protect someone while being protected. @@ -95,7 +95,7 @@ namespace Server protector.SendLocalizedMessage(1049436); // That player cannot be protected. else if (pm.JusticeProtectors.Count > 0) protector.SendLocalizedMessage(1049369); // You cannot protect that player right now. - else if (pm.HasGump(typeof(AcceptProtectorGump))) + else if (pm.HasGump()) protector.SendLocalizedMessage(1049369); // You cannot protect that player right now. else pm.SendGump(new AcceptProtectorGump(protector, pm)); @@ -107,7 +107,7 @@ namespace Server { protector.SendLocalizedMessage(1049610); // You must reach the first path in this virtue to invoke it. } - else if (!protector.CanBeginAction(typeof(JusticeVirtue))) + else if (!protector.CanBeginAction()) { protector.SendLocalizedMessage(1049370); // You must wait a while before offering your protection again. } @@ -149,14 +149,8 @@ namespace Server protectee.SendLocalizedMessage(1049453, args); // You have declined protection from ~1_NAME~. protector.SendLocalizedMessage(1049454, args); // ~2_NAME~ has declined your protection. - if (protector.BeginAction(typeof(JusticeVirtue))) - Timer.DelayCall(TimeSpan.FromMinutes(15.0), new TimerStateCallback(RejectDelay_Callback), protector); - } - - public static void RejectDelay_Callback(object state) - { - if (state is Mobile m) - m.EndAction(typeof(JusticeVirtue)); + if (protector.BeginAction()) + Timer.DelayCall(TimeSpan.FromMinutes(15.0), protector.EndAction); } public static void CheckAtrophy(Mobile from) @@ -176,6 +170,7 @@ namespace Server } catch { + // ignored } } } diff --git a/Scripts/Engines/Virtues/Sacrifice.cs b/Scripts/Engines/Virtues/Sacrifice.cs index d427105a5..02f362c76 100644 --- a/Scripts/Engines/Virtues/Sacrifice.cs +++ b/Scripts/Engines/Virtues/Sacrifice.cs @@ -52,6 +52,7 @@ namespace Server } catch { + // ignored } } @@ -81,7 +82,7 @@ namespace Server * We need to wait for them to accept the gump or they can just use * Sacrifice and cancel to have items in their backpack for free. */ - from.CloseGump(typeof(ResurrectGump)); + from.CloseGump(); from.SendGump(new ResurrectGump(from, true)); } } diff --git a/Scripts/Engines/Virtues/Valor.cs b/Scripts/Engines/Virtues/Valor.cs index 6d3b92957..20ad8e050 100644 --- a/Scripts/Engines/Virtues/Valor.cs +++ b/Scripts/Engines/Virtues/Valor.cs @@ -41,6 +41,7 @@ namespace Server } catch { + // ignored } } diff --git a/Scripts/Engines/Virtues/VirtueGump.cs b/Scripts/Engines/Virtues/VirtueGump.cs index 344dbeb44..ebc2f2556 100644 --- a/Scripts/Engines/Virtues/VirtueGump.cs +++ b/Scripts/Engines/Virtues/VirtueGump.cs @@ -10,8 +10,7 @@ namespace Server { private static Dictionary m_Callbacks = new Dictionary(); - private static int[] m_Table = new int[24] - { + private static int[] m_Table = { 0x0481, 0x0963, 0x0965, 0x060A, 0x060F, 0x002A, 0x08A4, 0x08A7, 0x0034, @@ -70,7 +69,7 @@ namespace Server if (e.Beholder != e.Beheld) return; - e.Beholder.CloseGump(typeof(VirtueGump)); + e.Beholder.CloseGump(); if (e.Beholder.Kills >= 5) { @@ -118,7 +117,7 @@ namespace Server } else if (beholder.Map == beheld.Map && beholder.InRange(beheld, 12)) { - beholder.CloseGump(typeof(VirtueGump)); + beholder.CloseGump(); beholder.SendGump(new VirtueGump(beholder, beheld)); } } diff --git a/Scripts/Gumps/AddGump.cs b/Scripts/Gumps/AddGump.cs index 9c87f5542..b253721e5 100644 --- a/Scripts/Gumps/AddGump.cs +++ b/Scripts/Gumps/AddGump.cs @@ -20,7 +20,7 @@ namespace Server.Gumps m_SearchResults = searchResults; m_Page = page; - from.CloseGump(typeof(AddGump)); + from.CloseGump(); AddPage(0); diff --git a/Scripts/Gumps/AdminGump.cs b/Scripts/Gumps/AdminGump.cs index d067857f5..cb384470b 100644 --- a/Scripts/Gumps/AdminGump.cs +++ b/Scripts/Gumps/AdminGump.cs @@ -1,6 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Text; using System.Threading; @@ -69,15 +69,15 @@ namespace Server.Gumps }; private Mobile m_From; - private ArrayList m_List; + private List m_List; private int m_ListPage; private AdminGumpPage m_PageType; private object m_State; - public AdminGump(Mobile from, AdminGumpPage pageType, int listPage, ArrayList list, string notice, - object state) : base(50, 40) + public AdminGump(Mobile from, AdminGumpPage pageType, int listPage = 0, List list = null, string notice = null, + object state = null) : base(50, 40) { - from.CloseGump(typeof(AdminGump)); + from.CloseGump(); m_From = from; m_PageType = pageType; @@ -192,11 +192,8 @@ namespace Server.Gumps StringBuilder sb = new StringBuilder(); - int curUser, maxUser; - int curIOCP, maxIOCP; - - ThreadPool.GetAvailableThreads(out curUser, out curIOCP); - ThreadPool.GetMaxThreads(out maxUser, out maxIOCP); + ThreadPool.GetAvailableThreads(out int curUser, out int curIOCP); + ThreadPool.GetMaxThreads(out int maxUser, out int maxIOCP); sb.Append("Worker Threads:
Capacity: "); sb.Append(maxUser); @@ -219,7 +216,7 @@ namespace Server.Gumps for (int i = 0; i < pools.Count; ++i) { BufferPool pool = pools[i]; - pool.GetInfo(out string name, out int freeCount, out int initialCapacity, + pool.GetInfo(out string name, out int freeCount, out _, out int currentCapacity, out int bufferSize, out int misses); if (sb.Length > 0) @@ -416,8 +413,10 @@ namespace Server.Gumps { if (m_List == null) { - m_List = new ArrayList(NetState.Instances); - m_List.Sort(NetStateComparer.Instance); + List states = NetState.Instances.ToList(); + states.Sort(NetStateComparer.Instance); + + m_List = states.ToList(); } AddClientHeader(); @@ -544,14 +543,22 @@ namespace Server.Gumps AddButtonLabeled(20, y, GetButtonID(7, 12), "Kill"); AddButtonLabeled(200, y, GetButtonID(7, 13), "Resurrect"); - y += 20; break; } case AdminGumpPage.Accounts_Shared: { + List>> sharedAccounts; + if (m_List == null) - m_List = GetAllSharedAccounts(); + { + sharedAccounts = GetAllSharedAccounts(); + m_List = Utility.CastListContravariant>, object>(sharedAccounts); + } + else + { + sharedAccounts = Utility.CastListCovariant>>(m_List); + } AddLabelCropped(12, 120, 60, 20, LabelHue, "Count"); AddLabelCropped(72, 120, 120, 20, LabelHue, "Address"); @@ -562,22 +569,22 @@ namespace Server.Gumps else AddImage(375, 122, 0x25EA); - if ((listPage + 1) * 12 < m_List.Count) + if ((listPage + 1) * 12 < sharedAccounts.Count) AddButton(392, 122, 0x15E1, 0x15E5, GetButtonID(1, 1), GumpButtonType.Reply, 0); else AddImage(392, 122, 0x25E6); - if (m_List.Count == 0) + if (sharedAccounts.Count == 0) AddLabel(12, 140, LabelHue, "There are no accounts to display."); StringBuilder sb = new StringBuilder(); - for (int i = 0, index = listPage * 12; i < 12 && index >= 0 && index < m_List.Count; ++i, ++index) + for (int i = 0, index = listPage * 12; i < 12 && index >= 0 && index < sharedAccounts.Count; ++i, ++index) { - DictionaryEntry de = (DictionaryEntry)m_List[index]; + KeyValuePair> kvp = sharedAccounts[index]; - IPAddress ipAddr = (IPAddress)de.Key; - ArrayList accts = (ArrayList)de.Value; + IPAddress ipAddr = kvp.Key; + List accts = kvp.Value; int offset = 140 + i * 20; @@ -594,7 +601,7 @@ namespace Server.Gumps if (j < 4) { - Account acct = (Account)accts[j]; + Account acct = accts[j]; sb.Append(acct.Username); } @@ -614,9 +621,10 @@ namespace Server.Gumps } case AdminGumpPage.Accounts: { - if (m_List == null) m_List = new ArrayList(); // new ArrayList( (ICollection)Accounts.GetAccounts() ); + if (m_List == null) + m_List = new List(); - ArrayList rads = state as ArrayList; + List rads = state as List; AddAccountHeader(); @@ -847,8 +855,15 @@ namespace Server.Gumps if (!(state is Account a)) break; + List ipAddresses; + if (m_List == null) - m_List = new ArrayList(a.LoginIPs); + { + ipAddresses = a.LoginIPs.ToList(); + m_List = Utility.CastListContravariant(ipAddresses); + } + else + ipAddresses = Utility.CastListCovariant(m_List); AddHtml(10, 195, 400, 20, Color(Center("Client Addresses"), LabelColor32), false, false); @@ -870,18 +885,18 @@ namespace Server.Gumps else AddImage(184, 223, 0x25EA); - if ((listPage + 1) * 6 < m_List.Count) + if ((listPage + 1) * 6 < ipAddresses.Count) AddButton(201, 223, 0x15E1, 0x15E5, GetButtonID(1, 1), GumpButtonType.Reply, 0); else AddImage(201, 223, 0x25E6); - if (m_List.Count == 0) + if (ipAddresses.Count == 0) AddHtml(18, 243, 200, 60, Color("This account has not yet been accessed.", LabelColor32), false, false); - for (int i = 0, index = listPage * 6; i < 6 && index >= 0 && index < m_List.Count; ++i, ++index) + for (int i = 0, index = listPage * 6; i < 6 && index >= 0 && index < ipAddresses.Count; ++i, ++index) { - AddHtml(18, 243 + i * 22, 114, 20, Color(m_List[index].ToString(), LabelColor32), false, false); + AddHtml(18, 243 + i * 22, 114, 20, Color(ipAddresses[index].ToString(), LabelColor32), false, false); AddButton(130, 242 + i * 22, 0xFA2, 0xFA4, GetButtonID(8, index), GumpButtonType.Reply, 0); AddButton(160, 242 + i * 22, 0xFA8, 0xFAA, GetButtonID(9, index), GumpButtonType.Reply, 0); AddButton(190, 242 + i * 22, 0xFB1, 0xFB3, GetButtonID(10, index), GumpButtonType.Reply, 0); @@ -894,8 +909,15 @@ namespace Server.Gumps if (!(state is Account a)) break; + List ipRestrictions; + if (m_List == null) - m_List = new ArrayList(a.IPRestrictions); + { + ipRestrictions = a.IPRestrictions.ToList(); + m_List = Utility.CastListContravariant(ipRestrictions); + } + else + ipRestrictions = Utility.CastListCovariant(m_List); AddHtml(10, 195, 400, 20, Color(Center("Address Restrictions"), LabelColor32), false, false); @@ -918,17 +940,17 @@ namespace Server.Gumps else AddImage(184, 223, 0x25EA); - if ((listPage + 1) * 6 < m_List.Count) + if ((listPage + 1) * 6 < ipRestrictions.Count) AddButton(201, 223, 0x15E1, 0x15E5, GetButtonID(1, 1), GumpButtonType.Reply, 0); else AddImage(201, 223, 0x25E6); - if (m_List.Count == 0) + if (ipRestrictions.Count == 0) AddHtml(18, 243, 200, 60, Color("There are no addresses in this list.", LabelColor32), false, false); - for (int i = 0, index = listPage * 6; i < 6 && index >= 0 && index < m_List.Count; ++i, ++index) + for (int i = 0, index = listPage * 6; i < 6 && index >= 0 && index < ipRestrictions.Count; ++i, ++index) { - AddHtml(18, 243 + i * 22, 114, 20, Color(m_List[index].ToString(), LabelColor32), false, false); + AddHtml(18, 243 + i * 22, 114, 20, Color(ipRestrictions[index].ToString(), LabelColor32), false, false); AddButton(190, 242 + i * 22, 0xFB1, 0xFB3, GetButtonID(8, index), GumpButtonType.Reply, 0); } @@ -1034,8 +1056,15 @@ namespace Server.Gumps { AddFirewallHeader(); + List firewallEntries; + if (m_List == null) - m_List = new ArrayList(Firewall.List); + { + firewallEntries = Firewall.List; + m_List = Utility.CastListContravariant(firewallEntries); + } + else + firewallEntries = Utility.CastListCovariant(m_List); AddLabelCropped(12, 120, 358, 20, LabelHue, "IP Address"); @@ -1044,24 +1073,21 @@ namespace Server.Gumps else AddImage(375, 122, 0x25EA); - if ((listPage + 1) * 12 < m_List.Count) + if ((listPage + 1) * 12 < firewallEntries.Count) AddButton(392, 122, 0x15E1, 0x15E5, GetButtonID(1, 1), GumpButtonType.Reply, 0); else AddImage(392, 122, 0x25E6); - if (m_List.Count == 0) + if (firewallEntries.Count == 0) AddLabel(12, 140, LabelHue, "The firewall list is empty."); - for (int i = 0, index = listPage * 12; i < 12 && index >= 0 && index < m_List.Count; ++i, ++index) + for (int i = 0, index = listPage * 12; i < 12 && index >= 0 && index < firewallEntries.Count; ++i, ++index) { - object obj = m_List[index]; - - if (!(obj is Firewall.IFirewallEntry)) - break; + Firewall.IFirewallEntry firewallEntry = firewallEntries[index]; int offset = 140 + i * 20; - AddLabelCropped(12, offset, 358, 20, LabelHue, obj.ToString()); + AddLabelCropped(12, offset, 358, 20, LabelHue, firewallEntry.ToString()); AddButton(380, offset - 1, 0xFA5, 0xFA7, GetButtonID(6, index + 4), GumpButtonType.Reply, 0); } @@ -1071,58 +1097,59 @@ namespace Server.Gumps { AddFirewallHeader(); - if (!(state is Firewall.IFirewallEntry)) + if (!(state is Firewall.IFirewallEntry firewallEntry)) break; - AddHtml(10, 125, 400, 20, Color(Center(state.ToString()), LabelColor32), false, false); + AddHtml(10, 125, 400, 20, Color(Center(firewallEntry.ToString()), LabelColor32), false, false); AddButtonLabeled(20, 150, GetButtonID(6, 3), "Remove"); AddHtml(10, 175, 400, 20, Color(Center("Potentially Affected Accounts"), LabelColor32), false, false); + List blockedAccts; + if (m_List == null) { - m_List = new ArrayList(); + blockedAccts = new List(); foreach (IAccount ia in Accounts.GetAccounts()) { - if (!(ia is Account acct)) - continue; + Account acct = (Account)ia; IPAddress[] loginList = acct.LoginIPs; bool contains = false; for (int i = 0; !contains && i < loginList.Length; ++i) - if (((Firewall.IFirewallEntry)state).IsBlocked(loginList[i])) + if (firewallEntry.IsBlocked(loginList[i])) { - m_List.Add(acct); + blockedAccts.Add(acct); break; } } - m_List.Sort(AccountComparer.Instance); + blockedAccts.Sort(AccountComparer.Instance); + m_List = Utility.CastListContravariant(blockedAccts); } + else + blockedAccts = Utility.CastListCovariant(m_List); if (listPage > 0) AddButton(375, 177, 0x15E3, 0x15E7, GetButtonID(1, 0), GumpButtonType.Reply, 0); else AddImage(375, 177, 0x25EA); - if ((listPage + 1) * 12 < m_List.Count) + if ((listPage + 1) * 12 < blockedAccts.Count) AddButton(392, 177, 0x15E1, 0x15E5, GetButtonID(1, 1), GumpButtonType.Reply, 0); else AddImage(392, 177, 0x25E6); - if (m_List.Count == 0) + if (blockedAccts.Count == 0) AddLabelCropped(12, 200, 398, 20, LabelHue, "No accounts found."); - for (int i = 0, index = listPage * 9; i < 9 && index >= 0 && index < m_List.Count; ++i, ++index) + for (int i = 0, index = listPage * 9; i < 9 && index >= 0 && index < blockedAccts.Count; ++i, ++index) { - Account a = m_List[index] as Account; - - if (a == null) - continue; + Account a = blockedAccts[index]; int offset = 200 + i * 20; @@ -1219,7 +1246,7 @@ namespace Server.Gumps "Opens an interface providing server information and administration features including client, account, and firewall management.")] public static void Admin_OnCommand(CommandEventArgs e) { - e.Mobile.SendGump(new AdminGump(e.Mobile, AdminGumpPage.Clients, 0, null, null, null)); + e.Mobile.SendGump(new AdminGump(e.Mobile, AdminGumpPage.Clients)); } public static int GetHueFor(Mobile m) @@ -1304,10 +1331,9 @@ namespace Server.Gumps AddButtonLabeled(200, 80, GetButtonID(6, 2), "Add (Target)"); } - private static ArrayList GetAllSharedAccounts() + private static List>> GetAllSharedAccounts() { - Hashtable table = new Hashtable(); - ArrayList list; + Dictionary> table = new Dictionary>(); foreach (Account acct in Accounts.GetAccounts()) { @@ -1315,40 +1341,38 @@ namespace Server.Gumps for (int i = 0; i < theirAddresses.Length; ++i) { - list = (ArrayList)table[theirAddresses[i]]; - - if (list == null) - table[theirAddresses[i]] = list = new ArrayList(); - - list.Add(acct); + if (!table.ContainsKey(theirAddresses[i])) + table[theirAddresses[i]] = new List{ acct }; } } - list = new ArrayList(table); + List>> tableEntries = table.ToList(); - for (int i = 0; i < list.Count; ++i) + for (int i = 0; i < tableEntries.Count; ++i) { - DictionaryEntry de = (DictionaryEntry)list[i]; - ArrayList accts = (ArrayList)de.Value; - - if (accts.Count == 1) + KeyValuePair> kvp = tableEntries[i]; + List list = kvp.Value; + + if (kvp.Value.Count == 1) list.RemoveAt(i--); else - accts.Sort(AccountComparer.Instance); + list.Sort(AccountComparer.Instance); } - list.Sort(SharedAccountComparer.Instance); + tableEntries.Sort(SharedAccountComparer.Instance); - return list; + return tableEntries; } - private static ArrayList GetSharedAccounts(IPAddress ipAddress) + private static List GetSharedAccounts(IPAddress ipAddress) { - ArrayList list = new ArrayList(); + List list = new List(); - foreach (Account acct in Accounts.GetAccounts()) + foreach (IAccount account in Accounts.GetAccounts()) { + Account acct = (Account)account; + IPAddress[] theirAddresses = acct.LoginIPs; bool contains = false; @@ -1363,9 +1387,9 @@ namespace Server.Gumps return list; } - private static ArrayList GetSharedAccounts(IPAddress[] ipAddresses) + private static List GetSharedAccounts(IPAddress[] ipAddresses) { - ArrayList list = new ArrayList(); + List list = new List(); foreach (Account acct in Accounts.GetAccounts()) { @@ -1388,23 +1412,22 @@ namespace Server.Gumps return list; } - public static void BanShared_Callback(Mobile from, bool okay, object state) + public static void BanShared_Callback(Mobile from, bool okay, Account a) { if (from.AccessLevel < AccessLevel.Administrator) return; string notice; - ArrayList list = null; + List list = null; if (okay) { - Account a = (Account)state; list = GetSharedAccounts(a.LoginIPs); for (int i = 0; i < list.Count; ++i) { - ((Account)list[i]).SetUnspecifiedBan(from); - ((Account)list[i]).Banned = true; + list[i].SetUnspecifiedBan(from); + list[i].Banned = true; } notice = "All addresses in the list have been banned."; @@ -1414,59 +1437,46 @@ namespace Server.Gumps notice = "You have chosen not to ban all shared accounts."; } - from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, notice, state)); + from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, notice, a)); if (okay) from.SendGump(new BanDurationGump(list)); } - public static void AccountDelete_Callback(Mobile from, bool okay, object state) + public static void AccountDelete_Callback(Mobile from, bool okay, Account a) { if (from.AccessLevel < AccessLevel.Administrator) return; if (okay) { - Account a = (Account)state; - CommandLogging.WriteLine(from, "{0} {1} deleting account {2}", from.AccessLevel, CommandLogging.Format(from), a.Username); a.Delete(); from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, null, - $"{a.Username} : The account has been deleted.", null)); + $"{a.Username} : The account has been deleted.")); } else { from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Information, 0, null, - "You have chosen not to delete the account.", state)); + "You have chosen not to delete the account.", a)); } } - public static void ResendGump_Callback(Mobile from, object state) + public static void ResendGump_Callback(Mobile from, List list, List rads, int page) { if (from.AccessLevel < AccessLevel.Administrator) return; - object[] states = (object[])state; - ArrayList list = (ArrayList)states[0]; - ArrayList rads = (ArrayList)states[1]; - int page = (int)states[2]; - from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, page, list, null, rads)); } - public static void Marked_Callback(Mobile from, bool okay, object state) + public static void Marked_Callback(Mobile from, bool okay, bool ban, List list, List rads, int page) { if (from.AccessLevel < AccessLevel.Administrator) return; - object[] states = (object[])state; - bool ban = (bool)states[0]; - ArrayList list = (ArrayList)states[1]; - ArrayList rads = (ArrayList)states[2]; - int page = (int)states[3]; - if (okay) { if (!ban) @@ -1474,7 +1484,7 @@ namespace Server.Gumps for (int i = 0; i < rads.Count; ++i) { - Account acct = (Account)rads[i]; + Account acct = rads[i]; if (ban) { @@ -1498,7 +1508,7 @@ namespace Server.Gumps from.SendGump(new NoticeGump(1060637, 30720, $"You have {(ban ? "banned" : "deleted")} the account{(rads.Count == 1 ? "" : "s")}.", 0xFFC000, 420, - 280, ResendGump_Callback, new object[] { list, rads, ban ? page : 0 })); + 280, () => ResendGump_Callback(from, list, rads, ban ? page : 0))); if (ban) from.SendGump(new BanDurationGump(rads)); @@ -1507,11 +1517,11 @@ namespace Server.Gumps { from.SendGump(new NoticeGump(1060637, 30720, $"You have chosen not to {(ban ? "ban" : "delete")} the account{(rads.Count == 1 ? "" : "s")}.", - 0xFFC000, 420, 280, ResendGump_Callback, new object[] { list, rads, page })); + 0xFFC000, 420, 280, () => ResendGump_Callback(from, list, rads, page ))); } } - public static void FirewallShared_Callback(Mobile from, bool okay, object state) + public static void FirewallShared_Callback(Mobile from, bool okay, Account a) { if (from.AccessLevel < AccessLevel.Administrator) return; @@ -1520,8 +1530,6 @@ namespace Server.Gumps if (okay) { - Account a = (Account)state; - for (int i = 0; i < a.LoginIPs.Length; ++i) Firewall.Add(a.LoginIPs[i]); @@ -1532,19 +1540,14 @@ namespace Server.Gumps notice = "You have chosen not to firewall all addresses."; } - from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, notice, state)); + from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, notice, a)); } - public static void Firewall_Callback(Mobile from, bool okay, object state) + public static void Firewall_Callback(Mobile from, bool okay, Account a, object toFirewall) { if (from.AccessLevel < AccessLevel.Administrator) return; - object[] states = (object[])state; - - Account a = (Account)states[0]; - object toFirewall = states[1]; - string notice; if (okay) @@ -1561,16 +1564,11 @@ namespace Server.Gumps from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, notice, a)); } - public static void RemoveLoginIP_Callback(Mobile from, bool okay, object state) + public static void RemoveLoginIP_Callback(Mobile from, bool okay, Account a, IPAddress ip) { if (from.AccessLevel < AccessLevel.Administrator) return; - object[] states = (object[])state; - - Account a = (Account)states[0]; - IPAddress ip = (IPAddress)states[1]; - string notice; if (okay) @@ -1594,13 +1592,11 @@ namespace Server.Gumps from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, notice, a)); } - public static void RemoveLoginIPs_Callback(Mobile from, bool okay, object state) + public static void RemoveLoginIPs_Callback(Mobile from, bool okay, Account a) { if (from.AccessLevel < AccessLevel.Administrator) return; - Account a = (Account)state; - string notice; if (okay) @@ -1636,12 +1632,12 @@ namespace Server.Gumps if (m_PageType == AdminGumpPage.Accounts) { - ArrayList list = m_List; + List list = Utility.CastListCovariant(m_List); - if (list != null && m_State is ArrayList rads) + if (list != null && m_State is List rads) for (int i = 0, v = m_ListPage * 12; i < 12 && v < list.Count; ++i, ++v) { - object obj = list[v]; + Account obj = list[v]; if (info.IsSwitched(v)) { @@ -1687,7 +1683,7 @@ namespace Server.Gumps default: return; } - from.SendGump(new AdminGump(from, page, 0, null, null, null)); + from.SendGump(new AdminGump(from, page)); break; } case 1: @@ -2033,7 +2029,7 @@ namespace Server.Gumps } } - from.SendGump(new AdminGump(from, page, 0, null, notice, null)); + from.SendGump(new AdminGump(from, page, 0, null, notice)); switch (index) { @@ -2065,7 +2061,7 @@ namespace Server.Gumps { bool forName = index == 0; - ArrayList results = new ArrayList(); + List results = new List(); string match = info.GetTextEntry(0)?.Text.Trim().ToLower(); string notice = null; @@ -2106,9 +2102,9 @@ namespace Server.Gumps if (results.Count == 1) { - NetState ns = (NetState)results[0]; + NetState ns = results[0]; object state = ns.Mobile; - + if (state == null) state = ns.Account; @@ -2119,13 +2115,14 @@ namespace Server.Gumps from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Information, 0, null, "One match found.", state)); else - from.SendGump(new AdminGump(from, AdminGumpPage.Clients, 0, results, "One match found.", - null)); + from.SendGump(new AdminGump(from, AdminGumpPage.Clients, 0, + Utility.CastListContravariant(results), "One match found.")); } else { - from.SendGump(new AdminGump(from, AdminGumpPage.Clients, 0, results, - notice ?? (results.Count == 0 ? "Nothing matched your search terms." : null), null)); + from.SendGump(new AdminGump(from, AdminGumpPage.Clients, 0, + Utility.CastListContravariant(results), + notice ?? (results.Count == 0 ? "Nothing matched your search terms." : null))); } break; @@ -2233,25 +2230,19 @@ namespace Server.Gumps } case 7: { - ArrayList results; + List results; TextRelay matchEntry = info.GetTextEntry(0); string match = matchEntry?.Text.Trim().ToLower(); - string notice = null; if (string.IsNullOrEmpty(match)) { - results = new ArrayList((ICollection)Accounts.GetAccounts()); + results = Accounts.GetAccounts().ToList(); results.Sort(AccountComparer.Instance); - //notice = "You must enter a username to search."; } else { - results = new ArrayList(); - foreach (IAccount acct in Accounts.GetAccounts()) - if (acct.Username.ToLower().IndexOf(match) >= 0) - results.Add(acct); - + results = Accounts.GetAccounts().Where(acct => acct.Username.ToLower().IndexOf(match) >= 0).ToList(); results.Sort(AccountComparer.Instance); } @@ -2259,9 +2250,10 @@ namespace Server.Gumps from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Information, 0, null, "One match found.", results[0])); else - from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, results, - notice ?? (results.Count == 0 ? "Nothing matched your search terms." : null), - new ArrayList())); + from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, + Utility.CastListContravariant(results), + results.Count == 0 ? "Nothing matched your search terms." : null, + new List())); break; } @@ -2332,10 +2324,11 @@ namespace Server.Gumps if (!(m_State is Account a)) break; - ArrayList list = GetSharedAccounts(a.LoginIPs); + List list = GetSharedAccounts(a.LoginIPs); if (list.Count > 1 || list.Count == 1 && !list.Contains(a)) - from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, list, null, new ArrayList())); + from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, + Utility.CastListContravariant(list), null, new List())); else if (a.LoginIPs.Length > 0) from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, "There are no other accounts which share an address with this one.", m_State)); @@ -2350,7 +2343,7 @@ namespace Server.Gumps if (!(m_State is Account a)) break; - ArrayList list = GetSharedAccounts(a.LoginIPs); + List list = GetSharedAccounts(a.LoginIPs); if (list.Count > 0) { @@ -2360,10 +2353,10 @@ namespace Server.Gumps list.Count != 1 ? "s" : ""); for (int i = 0; i < list.Count; ++i) - sb.AppendFormat("
- {0}", ((Account)list[i]).Username); + sb.AppendFormat("
- {0}", list[i].Username); from.SendGump(new WarningGump(1060635, 30720, sb.ToString(), 0xFFC000, 420, 400, - BanShared_Callback, a)); + okay => BanShared_Callback(from, okay, a))); } else if (a.LoginIPs.Length > 0) { @@ -2386,7 +2379,7 @@ namespace Server.Gumps if (a.LoginIPs.Length > 0) from.SendGump(new WarningGump(1060635, 30720, $"You are about to firewall {a.LoginIPs.Length} address{(a.LoginIPs.Length != 1 ? "s" : "")}. Do you wish to continue?", - 0xFFC000, 420, 400, FirewallShared_Callback, a)); + 0xFFC000, 420, 400, okay => FirewallShared_Callback(from, okay, a))); else from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, "This account has not yet been accessed.", m_State)); @@ -2495,69 +2488,66 @@ namespace Server.Gumps from.SendGump(new WarningGump(1060635, 30720, $"
Account of {a.Username}

You are about to permanently delete the account. Likewise, all characters on the account will be deleted, including equipped, inventory, and banked items. Any houses tied to the account will be demolished.

Do you wish to continue?", - 0xFFC000, 420, 280, AccountDelete_Callback, m_State)); + 0xFFC000, 420, 280, okay => AccountDelete_Callback(from, okay, a))); break; } case 26: // View all shared accounts { - from.SendGump(new AdminGump(from, AdminGumpPage.Accounts_Shared, 0, null, null, null)); + from.SendGump(new AdminGump(from, AdminGumpPage.Accounts_Shared)); break; } case 27: // Ban marked { - ArrayList list = m_List; + List list = m_List; - if (list == null || !(m_State is ArrayList rads)) + if (list == null || !(m_State is List rads)) break; if (rads.Count > 0) from.SendGump(new WarningGump(1060635, 30720, $"You are about to ban {rads.Count} marked account{(rads.Count == 1 ? "" : "s")}. Be cautioned, the only way to reverse this is by hand--manually unbanning each account.

Do you wish to continue?", - 0xFFC000, 420, 280, Marked_Callback, new object[] { true, list, rads, m_ListPage })); + 0xFFC000, 420, 280, okay => Marked_Callback(from, okay, true, list, rads, m_ListPage ))); else from.SendGump(new NoticeGump(1060637, 30720, "You have not yet marked any accounts. Place a check mark next to the accounts you wish to ban and then try again.", - 0xFFC000, 420, 280, ResendGump_Callback, new object[] { list, rads, m_ListPage })); + 0xFFC000, 420, 280, () => ResendGump_Callback(from, list, rads, m_ListPage))); break; } case 28: // Delete marked { - ArrayList list = m_List; + List list = m_List; - if (list == null || !(m_State is ArrayList rads)) + if (list == null || !(m_State is List rads)) break; if (rads.Count > 0) from.SendGump(new WarningGump(1060635, 30720, string.Format( "You are about to permanently delete {0} marked account{1}. Likewise, all characters on the account{1} will be deleted, including equipped, inventory, and banked items. Any houses tied to the account{1} will be demolished.

Do you wish to continue?", - rads.Count, rads.Count == 1 ? "" : "s"), 0xFFC000, 420, 280, Marked_Callback, - new object[] { false, list, rads, m_ListPage })); + rads.Count, rads.Count == 1 ? "" : "s"), 0xFFC000, 420, 280, okay => Marked_Callback(from, okay, false, list, rads, m_ListPage ))); else from.SendGump(new NoticeGump(1060637, 30720, "You have not yet marked any accounts. Place a check mark next to the accounts you wish to ban and then try again.", - 0xFFC000, 420, 280, ResendGump_Callback, new object[] { list, rads, m_ListPage })); + 0xFFC000, 420, 280, () => ResendGump_Callback(from, list, rads, m_ListPage))); break; } case 29: // Mark all { - ArrayList list = m_List; - - if (list == null || !(m_State is ArrayList rads)) + if (m_List == null || !(m_State is List)) break; from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, m_ListPage, m_List, null, - new ArrayList(list))); + m_List.ToList())); break; } case 30: // View all empty accounts { - ArrayList results = new ArrayList(); + List results = new List(); - foreach (IAccount acct in Accounts.GetAccounts()) + foreach (Account acct in Accounts.GetAccounts()) { bool empty = true; @@ -2573,16 +2563,16 @@ namespace Server.Gumps "One match found.", results[0])); else from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, results, - results.Count == 0 ? "Nothing matched your search terms." : null, new ArrayList())); + results.Count == 0 ? "Nothing matched your search terms." : null, new List())); break; } case 31: // View all inactive accounts { - ArrayList results = new ArrayList(); + List results = new List(); - foreach (IAccount acct in Accounts.GetAccounts()) - if ((acct as Account)?.Inactive == true) + foreach (Account acct in Accounts.GetAccounts()) + if (acct.Inactive) results.Add(acct); if (results.Count == 1) @@ -2590,16 +2580,16 @@ namespace Server.Gumps "One match found.", results[0])); else from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, results, - results.Count == 0 ? "Nothing matched your search terms." : null, new ArrayList())); + results.Count == 0 ? "Nothing matched your search terms." : null, new List())); break; } case 32: // View all banned accounts { - ArrayList results = new ArrayList(); + List results = new List(); - foreach (IAccount acct in Accounts.GetAccounts()) - if ((acct as Account)?.Banned == true) + foreach (Account acct in Accounts.GetAccounts()) + if (acct.Banned) results.Add(acct); if (results.Count == 1) @@ -2607,7 +2597,7 @@ namespace Server.Gumps "One match found.", results[0])); else from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, results, - results.Count == 0 ? "Nothing matched your search terms." : null, new ArrayList())); + results.Count == 0 ? "Nothing matched your search terms." : null, new List())); break; } @@ -2618,13 +2608,13 @@ namespace Server.Gumps } case 35: // Unmark house owners { - ArrayList list = m_List; - ArrayList rads = m_State as ArrayList; + List list = m_List; + List rads = m_State as List; if (list == null || rads == null) break; - ArrayList newRads = new ArrayList(); + List newRads = new List(); foreach (Account acct in rads) { @@ -2644,9 +2634,7 @@ namespace Server.Gumps } case 36: // Clear login addresses { - Account a = m_State as Account; - - if (a == null) + if (!(m_State is Account a)) break; IPAddress[] ips = a.LoginIPs; @@ -2657,7 +2645,7 @@ namespace Server.Gumps else from.SendGump(new WarningGump(1060635, 30720, $"You are about to clear the address list for account {a} containing {ips.Length} {(ips.Length == 1 ? "entry" : "entries")}. Do you wish to continue?", - 0xFFC000, 420, 280, RemoveLoginIPs_Callback, a)); + 0xFFC000, 420, 280, okay => RemoveLoginIPs_Callback(from, okay, a))); break; } @@ -2681,9 +2669,9 @@ namespace Server.Gumps if (m_List[index] is Account) from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Information, 0, null, null, m_List[index])); - else if (m_List[index] is DictionaryEntry) + else if (m_List[index] is KeyValuePair> kvp) from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, - (ArrayList)((DictionaryEntry)m_List[index]).Value, null, new ArrayList())); + Utility.CastListContravariant(kvp.Value), null, new List())); } } @@ -2703,7 +2691,7 @@ namespace Server.Gumps string match = matchEntry?.Text.Trim(); string notice = null; - ArrayList results = new ArrayList(); + List results = new List(); if (string.IsNullOrEmpty(match)) notice = "You must enter a username to search."; @@ -2733,7 +2721,7 @@ namespace Server.Gumps TextRelay relay = info.GetTextEntry(0); string text = relay?.Text.Trim(); - if (text == null || text.Length == 0) + if (string.IsNullOrEmpty(text)) { from.SendGump(new AdminGump(from, m_PageType, m_ListPage, m_List, "You must enter an address or pattern to add.", m_State)); @@ -2773,7 +2761,7 @@ namespace Server.Gumps Firewall.Remove(m_State); from.SendGump(new AdminGump(from, AdminGumpPage.Firewall, 0, null, - $"{m_State} : Removed from firewall.", null)); + $"{m_State} : Removed from firewall.")); } break; @@ -2793,9 +2781,7 @@ namespace Server.Gumps } case 7: { - Mobile m = m_State as Mobile; - - if (m == null) + if (!(m_State is Mobile m)) break; string notice = null; @@ -2954,24 +2940,20 @@ namespace Server.Gumps { if (m_List != null && index >= 0 && index < m_List.Count) { - Account a = m_State as Account; - - if (a == null) + if (!(m_State is Account a)) break; if (m_PageType == AdminGumpPage.AccountDetails_Access_ClientIPs) { from.SendGump(new WarningGump(1060635, 30720, $"You are about to firewall {m_List[index]}. All connection attempts from a matching IP will be refused. Are you sure?", - 0xFFC000, 420, 280, Firewall_Callback, new[] { a, m_List[index] })); + 0xFFC000, 420, 280, okay => Firewall_Callback(from, okay, a, m_List[index] ))); } else if (m_PageType == AdminGumpPage.AccountDetails_Access_Restrictions) { - ArrayList list = new ArrayList(a.IPRestrictions); - - list.Remove(m_List[index]); - - a.IPRestrictions = (string[])list.ToArray(typeof(string)); + List list = a.IPRestrictions.ToList(); + list.Remove(m_List[index] as string); + a.IPRestrictions = list.ToArray(); from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_Restrictions, 0, null, $"{m_List[index]} : Removed from list.", a)); @@ -2987,21 +2969,20 @@ namespace Server.Gumps { object obj = m_List[index]; - if (!(obj is IPAddress)) + if (!(obj is IPAddress ip)) break; - Account a = m_State as Account; - - if (a == null) + if (!(m_State is Account a)) break; - ArrayList list = GetSharedAccounts((IPAddress)obj); + List list = GetSharedAccounts(ip); if (list.Count > 1 || list.Count == 1 && !list.Contains(a)) - from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, list, null, new ArrayList())); + from.SendGump(new AdminGump(from, AdminGumpPage.Accounts, 0, + Utility.CastListContravariant(list), null, new List())); else from.SendGump(new AdminGump(from, AdminGumpPage.AccountDetails_Access_ClientIPs, 0, null, - "There are no other accounts which share that address.", m_State)); + "There are no other accounts which share that address.", a)); } break; @@ -3016,14 +2997,12 @@ namespace Server.Gumps if (ip == null) break; - Account a = m_State as Account; - - if (a == null) + if (!(m_State is Account a)) break; from.SendGump(new WarningGump(1060635, 30720, $"You are about to remove address {ip} from account {a}. Do you wish to continue?", 0xFFC000, - 420, 280, RemoveLoginIP_Callback, new object[] { a, ip })); + 420, 280, okay => RemoveLoginIP_Callback(from, okay, a, ip))); } break; @@ -3047,7 +3026,7 @@ namespace Server.Gumps CommandSystem.Handle(m_From, $"{CommandSystem.Prefix}{c}"); } - public static void GetAccountInfo(Account a, out AccessLevel accessLevel, out bool online) + public static void GetAccountInfo(IAccount a, out AccessLevel accessLevel, out bool online) { accessLevel = a.AccessLevel; online = false; @@ -3067,19 +3046,13 @@ namespace Server.Gumps } } - private class SharedAccountComparer : IComparer + private class SharedAccountComparer : IComparer>> { - public static readonly IComparer Instance = new SharedAccountComparer(); + public static readonly IComparer>> Instance = new SharedAccountComparer(); - public int Compare(object x, object y) + public int Compare(KeyValuePair> x, KeyValuePair> y) { - DictionaryEntry a = (DictionaryEntry)x; - DictionaryEntry b = (DictionaryEntry)y; - - ArrayList aList = (ArrayList)a.Value; - ArrayList bList = (ArrayList)b.Value; - - return bList.Count - aList.Count; + return x.Value.Count - y.Value.Count; } } @@ -3158,11 +3131,11 @@ namespace Server.Gumps } } - private class NetStateComparer : IComparer + private class NetStateComparer : IComparer { - public static readonly IComparer Instance = new NetStateComparer(); + public static readonly IComparer Instance = new NetStateComparer(); - public int Compare(object x, object y) + public int Compare(NetState x, NetState y) { if (x == null && y == null) return 0; @@ -3171,11 +3144,8 @@ namespace Server.Gumps if (y == null) return 1; - if (!(x is NetState a) || !(y is NetState b)) - throw new ArgumentException(); - - Mobile aMob = a.Mobile; - Mobile bMob = b.Mobile; + Mobile aMob = x.Mobile; + Mobile bMob = y.Mobile; if (aMob == null && bMob == null) return 0; @@ -3186,17 +3156,16 @@ namespace Server.Gumps if (aMob.AccessLevel > bMob.AccessLevel) return -1; - if (aMob.AccessLevel < bMob.AccessLevel) - return 1; - return Insensitive.Compare(aMob.Name, bMob.Name); + + return aMob.AccessLevel < bMob.AccessLevel ? 1 : Insensitive.Compare(aMob.Name, bMob.Name); } } - private class AccountComparer : IComparer + private class AccountComparer : IComparer { - public static readonly IComparer Instance = new AccountComparer(); + public static readonly IComparer Instance = new AccountComparer(); - public int Compare(object x, object y) + public int Compare(IAccount x, IAccount y) { if (x == null && y == null) return 0; @@ -3205,11 +3174,8 @@ namespace Server.Gumps if (y == null) return 1; - if (!(x is Account a) || !(y is Account b)) - throw new ArgumentException(); - - GetAccountInfo(a, out AccessLevel aLevel, out bool aOnline); - GetAccountInfo(b, out AccessLevel bLevel, out bool bOnline); + GetAccountInfo(x, out AccessLevel aLevel, out bool aOnline); + GetAccountInfo(y, out AccessLevel bLevel, out bool bOnline); if (aOnline && !bOnline) return -1; @@ -3217,9 +3183,8 @@ namespace Server.Gumps return 1; if (aLevel > bLevel) return -1; - if (aLevel < bLevel) - return 1; - return Insensitive.Compare(a.Username, b.Username); + + return aLevel < bLevel ? 1 : Insensitive.Compare(x.Username, y.Username); } } } diff --git a/Scripts/Gumps/BanDurationGump.cs b/Scripts/Gumps/BanDurationGump.cs index e25e9a2c7..55852e64d 100644 --- a/Scripts/Gumps/BanDurationGump.cs +++ b/Scripts/Gumps/BanDurationGump.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server.Accounting; using Server.Network; @@ -7,13 +7,13 @@ namespace Server.Gumps { public class BanDurationGump : Gump { - private ArrayList m_List; + private List m_List; - public BanDurationGump(Account a) : this(MakeList(a)) + public BanDurationGump(Account a) : this(new List{ a }) { } - public BanDurationGump(ArrayList list) : base((640 - 500) / 2, (480 - 305) / 2) + public BanDurationGump(List list) : base((640 - 500) / 2, (480 - 305) / 2) { m_List = list; @@ -55,13 +55,6 @@ namespace Server.Gumps AddTextEntry(x + 2, y + 2, width - 4, height - 4, 0, index, ""); } - public static ArrayList MakeList(object obj) - { - ArrayList list = new ArrayList(1); - list.Add(obj); - return list; - } - public void AddInput(int bid, int idx, string name) { int x = 15; @@ -88,15 +81,13 @@ namespace Server.Gumps TimeSpan duration; bool shouldSet; - string fromString = from.ToString(); - switch (info.ButtonID) { case 0: { for (int i = 0; i < m_List.Count; ++i) { - Account a = (Account)m_List[i]; + Account a = m_List[i]; a.SetUnspecifiedBan(from); } @@ -123,6 +114,7 @@ namespace Server.Gumps } catch { + // ignored } duration = TimeSpan.Zero; @@ -142,6 +134,7 @@ namespace Server.Gumps } catch { + // ignored } duration = TimeSpan.Zero; @@ -161,6 +154,7 @@ namespace Server.Gumps } catch { + // ignored } duration = TimeSpan.Zero; @@ -180,6 +174,7 @@ namespace Server.Gumps } catch { + // ignored } duration = TimeSpan.Zero; @@ -199,6 +194,7 @@ namespace Server.Gumps } catch { + // ignored } duration = TimeSpan.Zero; @@ -223,7 +219,7 @@ namespace Server.Gumps for (int i = 0; i < m_List.Count; ++i) { - Account a = (Account)m_List[i]; + Account a = m_List[i]; a.SetBanTags(from, DateTime.UtcNow, duration); diff --git a/Scripts/Gumps/BaseConfirmGump.cs b/Scripts/Gumps/BaseConfirmGump.cs index b623f0c24..08278b122 100644 --- a/Scripts/Gumps/BaseConfirmGump.cs +++ b/Scripts/Gumps/BaseConfirmGump.cs @@ -8,7 +8,7 @@ namespace Server.Gumps { Closable = false; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Gumps/BaseImageTileButtonsGump.cs b/Scripts/Gumps/BaseImageTileButtonsGump.cs index c0af72931..207934f07 100644 --- a/Scripts/Gumps/BaseImageTileButtonsGump.cs +++ b/Scripts/Gumps/BaseImageTileButtonsGump.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; using Server.Network; namespace Server.Gumps @@ -50,13 +50,12 @@ namespace Server.Gumps public class BaseImageTileButtonsGump : Gump { - public BaseImageTileButtonsGump(TextDefinition header, ArrayList buttons) : this(header, - (ImageTileButtonInfo[])buttons.ToArray(typeof(ImageTileButtonInfo))) + public BaseImageTileButtonsGump(TextDefinition header, List buttons) : + this(header, buttons.ToArray()) { } - public BaseImageTileButtonsGump(TextDefinition header, ImageTileButtonInfo[] buttons) : - base(10, 10) //Coords are 0, o on OSI, intentional difference + public BaseImageTileButtonsGump(TextDefinition header, ImageTileButtonInfo[] buttons) : base(10, 10) //Coords are 0, o on OSI, intentional difference { Buttons = buttons; AddPage(0); diff --git a/Scripts/Gumps/CategorizedAddGump.cs b/Scripts/Gumps/CategorizedAddGump.cs index b9e5c528e..8fb342971 100644 --- a/Scripts/Gumps/CategorizedAddGump.cs +++ b/Scripts/Gumps/CategorizedAddGump.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using System.Xml; using Server.Commands; @@ -82,7 +82,7 @@ namespace Server.Gumps } else { - ArrayList nodes = new ArrayList(); + List nodes = new List(); while (xml.Read() && xml.NodeType != XmlNodeType.EndElement) if (xml.NodeType == XmlNodeType.Element && xml.Name == "object") @@ -99,7 +99,7 @@ namespace Server.Gumps xml.Skip(); } - Nodes = (CAGNode[])nodes.ToArray(typeof(CAGNode)); + Nodes = nodes.ToArray(); } } @@ -131,9 +131,8 @@ namespace Server.Gumps { if (File.Exists(path)) { - XmlTextReader xml = new XmlTextReader(path); + XmlTextReader xml = new XmlTextReader(path) { WhitespaceHandling = WhitespaceHandling.None }; - xml.WhitespaceHandling = WhitespaceHandling.None; while (xml.Read()) if (xml.Name == "category" && xml.NodeType == XmlNodeType.Element) @@ -222,7 +221,7 @@ namespace Server.Gumps public CategorizedAddGump(Mobile owner, CAGCategory category, int page) : base(GumpOffsetX, GumpOffsetY) { - owner.CloseGump(typeof(WhoGump)); + owner.CloseGump(); m_Owner = owner; m_Category = category; diff --git a/Scripts/Gumps/ClientGump.cs b/Scripts/Gumps/ClientGump.cs index 48d1f2f56..6b58e0bda 100644 --- a/Scripts/Gumps/ClientGump.cs +++ b/Scripts/Gumps/ClientGump.cs @@ -185,7 +185,7 @@ namespace Server.Gumps if (!BaseCommand.IsAccessible(from, focus)) { - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. } else { diff --git a/Scripts/Gumps/CommentsGump.cs b/Scripts/Gumps/CommentsGump.cs index e03f9f389..588ac6d58 100644 --- a/Scripts/Gumps/CommentsGump.cs +++ b/Scripts/Gumps/CommentsGump.cs @@ -99,7 +99,7 @@ namespace Server.Gumps public override void OnCancel(Mobile from) { - from.CloseGump(typeof(CommentsGump)); + from.CloseGump(); from.SendGump(new CommentsGump(m_Acct)); base.OnCancel(from); } @@ -110,7 +110,7 @@ namespace Server.Gumps from.SendMessage("Comment added."); //m_Acct.AddComment( from.Name, text ); m_Acct.Comments.Add(new AccountComment(from.Name, text)); - from.CloseGump(typeof(CommentsGump)); + from.CloseGump(); from.SendGump(new CommentsGump(m_Acct)); } } diff --git a/Scripts/Gumps/ConfirmHouseResize.cs b/Scripts/Gumps/ConfirmHouseResize.cs index 0d5bbbeac..6667026c9 100644 --- a/Scripts/Gumps/ConfirmHouseResize.cs +++ b/Scripts/Gumps/ConfirmHouseResize.cs @@ -15,7 +15,7 @@ namespace Server.Gumps m_Mobile = mobile; m_House = house; - mobile.CloseGump(typeof(ConfirmHouseResize)); + mobile.CloseGump(); Closable = false; @@ -150,7 +150,7 @@ namespace Server.Gumps } else if (info.ButtonID == 0) { - m_Mobile.CloseGump(typeof(ConfirmHouseResize)); + m_Mobile.CloseGump(); m_Mobile.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Customize, m_Mobile, m_House)); } } diff --git a/Scripts/Gumps/ConfirmReleaseGump.cs b/Scripts/Gumps/ConfirmReleaseGump.cs index 3457099fb..7369a5013 100644 --- a/Scripts/Gumps/ConfirmReleaseGump.cs +++ b/Scripts/Gumps/ConfirmReleaseGump.cs @@ -13,7 +13,7 @@ namespace Server.Gumps m_From = from; m_Pet = pet; - m_From.CloseGump(typeof(ConfirmReleaseGump)); + m_From.CloseGump(); AddPage(0); diff --git a/Scripts/Gumps/Go/ChildNode.cs b/Scripts/Gumps/Go/ChildNode.cs index 99e29f666..dc4eda4a9 100644 --- a/Scripts/Gumps/Go/ChildNode.cs +++ b/Scripts/Gumps/Go/ChildNode.cs @@ -2,7 +2,7 @@ using System.Xml; namespace Server.Gumps { - public class ChildNode + public class ChildNode : IGoNode { public ChildNode(XmlTextReader xml, ParentNode parent) { @@ -19,10 +19,7 @@ namespace Server.Gumps private void Parse(XmlTextReader xml) { - if (xml.MoveToAttribute("name")) - Name = xml.Value; - else - Name = "empty"; + Name = xml.MoveToAttribute("name") ? xml.Value : "empty"; int x = 0, y = 0, z = 0; diff --git a/Scripts/Gumps/Go/GoGump.cs b/Scripts/Gumps/Go/GoGump.cs index ee200e8d1..437fdcac9 100644 --- a/Scripts/Gumps/Go/GoGump.cs +++ b/Scripts/Gumps/Go/GoGump.cs @@ -67,7 +67,7 @@ namespace Server.Gumps private GoGump(int page, Mobile from, LocationTree tree, ParentNode node) : base(50, 50) { - from.CloseGump(typeof(GoGump)); + from.CloseGump(); tree.LastBranch[from] = node; @@ -151,13 +151,8 @@ namespace Server.Gumps x = BorderSize + OffsetSize; y += EntryHeight + OffsetSize; - object child = node.Children[index]; - string name = ""; - - if (child is ParentNode parentNode) - name = parentNode.Name; - else if (child is ChildNode childNode) - name = childNode.Name; + IGoNode child = node.Children[index]; + string name = child.Name; AddImageTiled(x, y, EntryWidth, EntryHeight, EntryGumpID); AddLabelCropped(x + TextOffsetX, y, EntryWidth - TextOffsetX, EntryHeight, TextHue, name); @@ -228,7 +223,7 @@ namespace Server.Gumps if (index >= 0 && index < m_Node.Children.Length) { - object o = m_Node.Children[index]; + IGoNode o = m_Node.Children[index]; if (o is ParentNode node) from.SendGump(new GoGump(0, from, m_Tree, node)); diff --git a/Scripts/Gumps/Go/ParentNode.cs b/Scripts/Gumps/Go/ParentNode.cs index 1bda990ad..f58b767aa 100644 --- a/Scripts/Gumps/Go/ParentNode.cs +++ b/Scripts/Gumps/Go/ParentNode.cs @@ -1,37 +1,38 @@ -using System.Collections; +using System.Collections.Generic; using System.Xml; namespace Server.Gumps { - public class ParentNode + public interface IGoNode + { + ParentNode Parent{ get; } + string Name{ get; } + } + + public class ParentNode : IGoNode { public ParentNode(XmlTextReader xml, ParentNode parent) { Parent = parent; - + Parse(xml); } public ParentNode Parent{ get; } - public object[] Children{ get; private set; } + public IGoNode[] Children{ get; private set; } public string Name{ get; private set; } private void Parse(XmlTextReader xml) { - if (xml.MoveToAttribute("name")) - Name = xml.Value; - else - Name = "empty"; + Name = xml.MoveToAttribute("name") ? xml.Value : "empty"; if (xml.IsEmptyElement) - { - Children = new object[0]; - } + Children = new IGoNode[0]; else { - ArrayList children = new ArrayList(); + List children = new List(); while (xml.Read() && (xml.NodeType == XmlNodeType.Element || xml.NodeType == XmlNodeType.Comment)) { @@ -39,15 +40,9 @@ namespace Server.Gumps continue; if (xml.Name == "child") - { - ChildNode n = new ChildNode(xml, this); - - children.Add(n); - } + children.Add(new ChildNode(xml, this)); else - { children.Add(new ParentNode(xml, this)); - } } Children = children.ToArray(); diff --git a/Scripts/Gumps/Guilds/GuildChangeTypeGump.cs b/Scripts/Gumps/Guilds/GuildChangeTypeGump.cs index 5c0533337..79211a6dd 100644 --- a/Scripts/Gumps/Guilds/GuildChangeTypeGump.cs +++ b/Scripts/Gumps/Guilds/GuildChangeTypeGump.cs @@ -16,7 +16,7 @@ namespace Server.Gumps m_Mobile = from; m_Guild = guild; - Dragable = false; + Draggable = false; AddPage(0); AddBackground(0, 0, 550, 400, 5054); diff --git a/Scripts/Gumps/Guilds/GuildCharterGump.cs b/Scripts/Gumps/Guilds/GuildCharterGump.cs index bc4c884bd..6615bd15f 100644 --- a/Scripts/Gumps/Guilds/GuildCharterGump.cs +++ b/Scripts/Gumps/Guilds/GuildCharterGump.cs @@ -14,7 +14,7 @@ namespace Server.Gumps m_Mobile = from; m_Guild = guild; - Dragable = false; + Draggable = false; AddPage(0); AddBackground(0, 0, 550, 400, 5054); diff --git a/Scripts/Gumps/Guilds/GuildDeclareWarPrompt.cs b/Scripts/Gumps/Guilds/GuildDeclareWarPrompt.cs index fbd03c56a..9b17dbaa0 100644 --- a/Scripts/Gumps/Guilds/GuildDeclareWarPrompt.cs +++ b/Scripts/Gumps/Guilds/GuildDeclareWarPrompt.cs @@ -33,7 +33,7 @@ namespace Server.Gumps if (text.Length >= 3) { - List guilds = Utility.CastConvertList(BaseGuild.Search(text)); + List guilds = Utility.CastListCovariant(BaseGuild.Search(text)); GuildGump.EnsureClosed(m_Mobile); diff --git a/Scripts/Gumps/Guilds/GuildGump.cs b/Scripts/Gumps/Guilds/GuildGump.cs index 96d847501..8adeb835f 100644 --- a/Scripts/Gumps/Guilds/GuildGump.cs +++ b/Scripts/Gumps/Guilds/GuildGump.cs @@ -13,7 +13,7 @@ namespace Server.Gumps m_Mobile = beholder; m_Guild = guild; - Dragable = false; + Draggable = false; AddPage(0); AddBackground(0, 0, 550, 400, 5054); @@ -110,17 +110,17 @@ namespace Server.Gumps public static void EnsureClosed(Mobile m) { - m.CloseGump(typeof(DeclareFealtyGump)); - m.CloseGump(typeof(GrantGuildTitleGump)); - m.CloseGump(typeof(GuildAdminCandidatesGump)); - m.CloseGump(typeof(GuildCandidatesGump)); - m.CloseGump(typeof(GuildChangeTypeGump)); - m.CloseGump(typeof(GuildCharterGump)); - m.CloseGump(typeof(GuildDismissGump)); - m.CloseGump(typeof(GuildGump)); - m.CloseGump(typeof(GuildmasterGump)); - m.CloseGump(typeof(GuildRosterGump)); - m.CloseGump(typeof(GuildWarGump)); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); + m.CloseGump(); } public static bool BadLeader(Mobile m, Guild g) diff --git a/Scripts/Gumps/Guilds/GuildListGump.cs b/Scripts/Gumps/Guilds/GuildListGump.cs index 7b9b4e4d6..aa1cd119e 100644 --- a/Scripts/Gumps/Guilds/GuildListGump.cs +++ b/Scripts/Gumps/Guilds/GuildListGump.cs @@ -14,7 +14,7 @@ namespace Server.Gumps m_Mobile = from; m_Guild = guild; - Dragable = false; + Draggable = false; AddPage(0); AddBackground(0, 0, 550, 440, 5054); diff --git a/Scripts/Gumps/Guilds/GuildMobileListGump.cs b/Scripts/Gumps/Guilds/GuildMobileListGump.cs index 62c57aa72..59158549c 100644 --- a/Scripts/Gumps/Guilds/GuildMobileListGump.cs +++ b/Scripts/Gumps/Guilds/GuildMobileListGump.cs @@ -15,7 +15,7 @@ namespace Server.Gumps m_Mobile = from; m_Guild = guild; - Dragable = false; + Draggable = false; AddPage(0); AddBackground(0, 0, 550, 440, 5054); diff --git a/Scripts/Gumps/Guilds/GuildWarAdminGump.cs b/Scripts/Gumps/Guilds/GuildWarAdminGump.cs index 636841ea3..116649a0a 100644 --- a/Scripts/Gumps/Guilds/GuildWarAdminGump.cs +++ b/Scripts/Gumps/Guilds/GuildWarAdminGump.cs @@ -13,7 +13,7 @@ namespace Server.Gumps m_Mobile = from; m_Guild = guild; - Dragable = false; + Draggable = false; AddPage(0); AddBackground(0, 0, 550, 440, 5054); diff --git a/Scripts/Gumps/Guilds/GuildWarGump.cs b/Scripts/Gumps/Guilds/GuildWarGump.cs index 37884f348..eb7bd2ae6 100644 --- a/Scripts/Gumps/Guilds/GuildWarGump.cs +++ b/Scripts/Gumps/Guilds/GuildWarGump.cs @@ -14,7 +14,7 @@ namespace Server.Gumps m_Mobile = from; m_Guild = guild; - Dragable = false; + Draggable = false; AddPage(0); AddBackground(0, 0, 550, 440, 5054); diff --git a/Scripts/Gumps/Guilds/GuildmasterGump.cs b/Scripts/Gumps/Guilds/GuildmasterGump.cs index 0554c09b4..acefc2a13 100644 --- a/Scripts/Gumps/Guilds/GuildmasterGump.cs +++ b/Scripts/Gumps/Guilds/GuildmasterGump.cs @@ -14,7 +14,7 @@ namespace Server.Gumps m_Mobile = from; m_Guild = guild; - Dragable = false; + Draggable = false; AddPage(0); AddBackground(0, 0, 550, 400, 5054); diff --git a/Scripts/Gumps/Guilds/New Guild System/BaseGuildGump.cs b/Scripts/Gumps/Guilds/New Guild System/BaseGuildGump.cs index 739658001..33bd4845c 100644 --- a/Scripts/Gumps/Guilds/New Guild System/BaseGuildGump.cs +++ b/Scripts/Gumps/Guilds/New Guild System/BaseGuildGump.cs @@ -16,7 +16,7 @@ namespace Server.Guilds guild = g; player = pm; - pm.CloseGump(typeof(BaseGuildGump)); + pm.CloseGump(); } protected Guild guild{ get; } diff --git a/Scripts/Gumps/Guilds/New Guild System/Create Guild Gump.cs b/Scripts/Gumps/Guilds/New Guild System/Create Guild Gump.cs index f021c3d6e..bed1487c1 100644 --- a/Scripts/Gumps/Guilds/New Guild System/Create Guild Gump.cs +++ b/Scripts/Gumps/Guilds/New Guild System/Create Guild Gump.cs @@ -8,8 +8,8 @@ namespace Server.Guilds { public CreateGuildGump(PlayerMobile pm, string guildName = "Guild Name", string guildAbbrev = "") : base(10, 10) { - pm.CloseGump(typeof(CreateGuildGump)); - pm.CloseGump(typeof(BaseGuildGump)); + pm.CloseGump(); + pm.CloseGump(); AddPage(0); diff --git a/Scripts/Gumps/Guilds/New Guild System/DiplomacyGump.cs b/Scripts/Gumps/Guilds/New Guild System/DiplomacyGump.cs index c711a90cb..12a3408ab 100644 --- a/Scripts/Gumps/Guilds/New Guild System/DiplomacyGump.cs +++ b/Scripts/Gumps/Guilds/New Guild System/DiplomacyGump.cs @@ -19,7 +19,7 @@ namespace Server.Guilds public GuildDiplomacyGump(PlayerMobile pm, Guild g) : this(pm, g, NameComparer.Instance, true, "", 0, GuildDisplayType.All, - Utility.CastConvertList(new List(BaseGuild.List.Values)), + Utility.CastListCovariant(new List(BaseGuild.List.Values)), 1063136 + (int)GuildDisplayType.All) { } @@ -27,7 +27,7 @@ namespace Server.Guilds public GuildDiplomacyGump(PlayerMobile pm, Guild g, IComparer currentComparer, bool ascending, string filter, int startNumber, GuildDisplayType display) : this(pm, g, currentComparer, ascending, filter, startNumber, display, - Utility.CastConvertList(new List(BaseGuild.List.Values)), + Utility.CastListCovariant(new List(BaseGuild.List.Values)), 1063136 + (int)display) { } diff --git a/Scripts/Gumps/Guilds/New Guild System/GuildInfoGump.cs b/Scripts/Gumps/Guilds/New Guild System/GuildInfoGump.cs index 5792612f3..4d97213e6 100644 --- a/Scripts/Gumps/Guilds/New Guild System/GuildInfoGump.cs +++ b/Scripts/Gumps/Guilds/New Guild System/GuildInfoGump.cs @@ -148,7 +148,7 @@ namespace Server.Guilds // Guild Faction if (Guild.OrderChaos && IsLeader(pm, guild)) { - pm.CloseGump(typeof(GuildChangeTypeGump)); + pm.CloseGump(); pm.SendGump(new GuildChangeTypeGump(pm, guild)); } diff --git a/Scripts/Gumps/Guilds/New Guild System/GuildRosterGump.cs b/Scripts/Gumps/Guilds/New Guild System/GuildRosterGump.cs index 97df6a2a0..538a8e356 100644 --- a/Scripts/Gumps/Guilds/New Guild System/GuildRosterGump.cs +++ b/Scripts/Gumps/Guilds/New Guild System/GuildRosterGump.cs @@ -95,7 +95,7 @@ namespace Server.Guilds if (pm.GuildRank.GetFlag(RankFlags.CanInvitePlayer)) { pm.SendLocalizedMessage(1063048); // Whom do you wish to invite into your guild? - pm.BeginTarget(-1, false, TargetFlags.None, new TargetStateCallback(InvitePlayer_Callback), guild); + pm.BeginTarget(-1, false, TargetFlags.None, InvitePlayer_Callback, guild); } else { @@ -104,13 +104,11 @@ namespace Server.Guilds } } - public void InvitePlayer_Callback(Mobile from, object targeted, object state) + public void InvitePlayer_Callback(Mobile from, object targeted, Guild g) { PlayerMobile pm = from as PlayerMobile; PlayerMobile targ = targeted as PlayerMobile; - Guild g = state as Guild; - PlayerState guildState = PlayerState.Find(g.Leader); PlayerState targetState = PlayerState.Find(targ); @@ -137,7 +135,7 @@ namespace Server.Guilds { pm.SendLocalizedMessage(1063051, targ.Name); // ~1_val~ is already a member of a guild. } - else if (targ.HasGump(typeof(BaseGuildGump)) || targ.HasGump(typeof(CreateGuildGump)) + else if (targ.HasGump() || targ.HasGump() ) //TODO: Check message if CreateGuildGump Open { pm.SendLocalizedMessage(1063052, targ.Name); // ~1_val~ is currently considering another guild invitation. diff --git a/Scripts/Gumps/HeritageTokenGump.cs b/Scripts/Gumps/HeritageTokenGump.cs index 5f731b4d9..a648af760 100644 --- a/Scripts/Gumps/HeritageTokenGump.cs +++ b/Scripts/Gumps/HeritageTokenGump.cs @@ -564,7 +564,7 @@ namespace Server.Gumps if (types.Count > 0 && cliloc > 0) { - sender.Mobile.CloseGump(typeof(ConfirmHeritageGump)); + sender.Mobile.CloseGump(); sender.Mobile.SendGump(new ConfirmHeritageGump(m_Token, types.ToArray(), cliloc)); } else diff --git a/Scripts/Gumps/HouseDemolishGump.cs b/Scripts/Gumps/HouseDemolishGump.cs index 18e376e01..966df450a 100644 --- a/Scripts/Gumps/HouseDemolishGump.cs +++ b/Scripts/Gumps/HouseDemolishGump.cs @@ -16,7 +16,7 @@ namespace Server.Gumps m_Mobile = mobile; m_House = house; - mobile.CloseGump(typeof(HouseDemolishGump)); + mobile.CloseGump(); Closable = false; diff --git a/Scripts/Gumps/HouseGump.cs b/Scripts/Gumps/HouseGump.cs index 2bdbc83b8..8d51777e0 100644 --- a/Scripts/Gumps/HouseGump.cs +++ b/Scripts/Gumps/HouseGump.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; using Server.Guilds; using Server.Multis; using Server.Network; @@ -10,7 +10,7 @@ namespace Server.Gumps { private BaseHouse m_House; - public HouseListGump(int number, ArrayList list, BaseHouse house, bool accountOf) : base(20, 30) + public HouseListGump(int number, List list, BaseHouse house, bool accountOf) : base(20, 30) { if (house.Deleted) return; @@ -27,29 +27,31 @@ namespace Server.Gumps AddHtmlLocalized(20, 20, 350, 20, number, false, false); - if (list != null) - for (int i = 0; i < list.Count; ++i) + if (list == null) + return; + + for (int i = 0; i < list.Count; ++i) + { + if (i % 16 == 0) { - if (i % 16 == 0) - { - if (i != 0) AddButton(370, 20, 4005, 4007, 0, GumpButtonType.Page, i / 16 + 1); + if (i != 0) AddButton(370, 20, 4005, 4007, 0, GumpButtonType.Page, i / 16 + 1); - AddPage(i / 16 + 1); + AddPage(i / 16 + 1); - if (i != 0) AddButton(340, 20, 4014, 4016, 0, GumpButtonType.Page, i / 16); - } - - Mobile m = (Mobile)list[i]; - - string name; - - if (m == null || (name = m.Name) == null || (name = name.Trim()).Length <= 0) - continue; - - AddLabel(55, 55 + i % 16 * 20, 0, accountOf && m.Player && m.Account != null - ? $"Account of {name}" - : name); + if (i != 0) AddButton(340, 20, 4014, 4016, 0, GumpButtonType.Page, i / 16); } + + Mobile m = list[i]; + + string name; + + if (m == null || (name = m.Name) == null || (name = name.Trim()).Length <= 0) + continue; + + AddLabel(55, 55 + i % 16 * 20, 0, accountOf && m.Player && m.Account != null + ? $"Account of {name}" + : name); + } } public override void OnResponse(NetState state, RelayInfo info) @@ -67,10 +69,10 @@ namespace Server.Gumps { private bool m_AccountOf; private BaseHouse m_House; - private ArrayList m_List, m_Copy; + private List m_List, m_Copy; private int m_Number; - public HouseRemoveGump(int number, ArrayList list, BaseHouse house, bool accountOf) : base(20, 30) + public HouseRemoveGump(int number, List list, BaseHouse house, bool accountOf) : base(20, 30) { if (house.Deleted) return; @@ -93,33 +95,33 @@ namespace Server.Gumps AddHtmlLocalized(20, 20, 350, 20, number, false, false); - if (list != null) + if (list == null) + return; + + m_Copy = new List(list); + + for (int i = 0; i < list.Count; ++i) { - m_Copy = new ArrayList(list); - - for (int i = 0; i < list.Count; ++i) + if (i % 15 == 0) { - if (i % 15 == 0) - { - if (i != 0) AddButton(370, 20, 4005, 4007, 0, GumpButtonType.Page, i / 15 + 1); + if (i != 0) AddButton(370, 20, 4005, 4007, 0, GumpButtonType.Page, i / 15 + 1); - AddPage(i / 15 + 1); + AddPage(i / 15 + 1); - if (i != 0) AddButton(340, 20, 4014, 4016, 0, GumpButtonType.Page, i / 15); - } - - Mobile m = (Mobile)list[i]; - - string name; - - if (m == null || (name = m.Name) == null || (name = name.Trim()).Length <= 0) - continue; - - AddCheck(34, 52 + i % 15 * 20, 0xD2, 0xD3, false, i); - AddLabel(55, 52 + i % 15 * 20, 0, accountOf && m.Player && m.Account != null - ? $"Account of {name}" - : name); + if (i != 0) AddButton(340, 20, 4014, 4016, 0, GumpButtonType.Page, i / 15); } + + Mobile m = list[i]; + + string name; + + if (m == null || (name = m.Name) == null || (name = name.Trim()).Length <= 0) + continue; + + AddCheck(34, 52 + i % 15 * 20, 0xD2, 0xD3, false, i); + AddLabel(55, 52 + i % 15 * 20, 0, accountOf && m.Player && m.Account != null + ? $"Account of {name}" + : name); } } @@ -146,9 +148,9 @@ namespace Server.Gumps if (m_List.Count > 0) { - from.CloseGump(typeof(HouseGump)); - from.CloseGump(typeof(HouseListGump)); - from.CloseGump(typeof(HouseRemoveGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); from.SendGump(new HouseRemoveGump(m_Number, m_List, m_House, m_AccountOf)); return; } @@ -170,9 +172,9 @@ namespace Server.Gumps m_House = house; - from.CloseGump(typeof(HouseGump)); - from.CloseGump(typeof(HouseListGump)); - from.CloseGump(typeof(HouseRemoveGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); bool isCombatRestricted = house.IsCombatRestricted(from); @@ -195,15 +197,14 @@ namespace Server.Gumps if (m_House.Sign != null) { - ArrayList lines = Wrap(m_House.Sign.GetName()); + List lines = Wrap(m_House.Sign.GetName()); - if (lines != null) - for (int i = 0, y = (101 - lines.Count * 14) / 2; i < lines.Count; ++i, y += 14) - { - string s = (string)lines[i]; + for (int i = 0, y = (101 - lines.Count * 14) / 2; i < lines.Count; ++i, y += 14) + { + string s = lines[i]; - AddLabel(130 + (143 - s.Length * 8) / 2, y, 0, s); - } + AddLabel(130 + (143 - s.Length * 8) / 2, y, 0, s); + } } if (!isFriend) @@ -349,13 +350,13 @@ namespace Server.Gumps } } - private ArrayList Wrap(string value) + private List Wrap(string value) { if (value == null || (value = value.Trim()).Length <= 0) return null; string[] values = value.Split(' '); - ArrayList list = new ArrayList(); + List list = new List(); string current = ""; for (int i = 0; i < values.Length; ++i) @@ -458,9 +459,9 @@ namespace Server.Gumps } case 2: // List of co-owners { - from.CloseGump(typeof(HouseGump)); - from.CloseGump(typeof(HouseListGump)); - from.CloseGump(typeof(HouseRemoveGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); from.SendGump(new HouseListGump(1011275, m_House.CoOwners, m_House, false)); break; @@ -484,9 +485,9 @@ namespace Server.Gumps { if (isOwner) { - from.CloseGump(typeof(HouseGump)); - from.CloseGump(typeof(HouseListGump)); - from.CloseGump(typeof(HouseRemoveGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); from.SendGump(new HouseRemoveGump(1011274, m_House.CoOwners, m_House, false)); } else @@ -513,9 +514,9 @@ namespace Server.Gumps } case 6: // List friends { - from.CloseGump(typeof(HouseGump)); - from.CloseGump(typeof(HouseListGump)); - from.CloseGump(typeof(HouseRemoveGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); from.SendGump(new HouseListGump(1011273, m_House.Friends, m_House, false)); break; @@ -538,9 +539,9 @@ namespace Server.Gumps { if (isCoOwner) { - from.CloseGump(typeof(HouseGump)); - from.CloseGump(typeof(HouseListGump)); - from.CloseGump(typeof(HouseRemoveGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); from.SendGump(new HouseRemoveGump(1011272, m_House.Friends, m_House, false)); } else @@ -581,18 +582,18 @@ namespace Server.Gumps } case 12: // List bans { - from.CloseGump(typeof(HouseGump)); - from.CloseGump(typeof(HouseListGump)); - from.CloseGump(typeof(HouseRemoveGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); from.SendGump(new HouseListGump(1011271, m_House.Bans, m_House, true)); break; } case 13: // Remove ban { - from.CloseGump(typeof(HouseGump)); - from.CloseGump(typeof(HouseListGump)); - from.CloseGump(typeof(HouseRemoveGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); from.SendGump(new HouseRemoveGump(1011269, m_House.Bans, m_House, true)); break; @@ -621,7 +622,7 @@ namespace Server.Gumps } else { - from.CloseGump(typeof(HouseDemolishGump)); + from.CloseGump(); from.SendGump(new HouseDemolishGump(from, m_House)); } } diff --git a/Scripts/Gumps/HouseGumpAOS.cs b/Scripts/Gumps/HouseGumpAOS.cs index af244b7ca..104294f65 100644 --- a/Scripts/Gumps/HouseGumpAOS.cs +++ b/Scripts/Gumps/HouseGumpAOS.cs @@ -1,6 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Linq; using Server.Guilds; using Server.Items; using Server.Mobiles; @@ -71,7 +71,7 @@ namespace Server.Gumps private static List _HouseSigns = new List(); private BaseHouse m_House; - private ArrayList m_List; + private List m_List; private HouseGumpPageAOS m_Page; public HouseGumpAOS(HouseGumpPageAOS page, Mobile from, BaseHouse house) : base(50, 40) @@ -79,7 +79,7 @@ namespace Server.Gumps m_House = house; m_Page = page; - from.CloseGump(typeof(HouseGumpAOS)); + from.CloseGump(); //from.CloseGump( typeof( HouseListGump ) ); //from.CloseGump( typeof( HouseRemoveGump ) ); @@ -114,15 +114,14 @@ namespace Server.Gumps if (m_House.Sign != null) { - ArrayList lines = Wrap(m_House.Sign.GetName()); + List lines = Wrap(m_House.Sign.GetName()); - if (lines != null) - for (int i = 0, y = (114 - lines.Count * 14) / 2; i < lines.Count; ++i, y += 14) - { - string s = (string)lines[i]; + for (int i = 0, y = (114 - lines.Count * 14) / 2; i < lines.Count; ++i, y += 14) + { + string s = (string)lines[i]; - AddLabel(10 + (160 - s.Length * 8) / 2, y, 0, s); - } + AddLabel(10 + (160 - s.Length * 8) / 2, y, 0, s); + } } if (page == HouseGumpPageAOS.Vendors) @@ -506,10 +505,7 @@ namespace Server.Gumps private string GetDateTime(DateTime val) { - if (val == DateTime.MinValue) - return ""; - - return val.ToString("yyyy'-'MM'-'dd HH':'mm':'ss"); + return val == DateTime.MinValue ? "" : val.ToString("yyyy'-'MM'-'dd HH':'mm':'ss"); } public void AddPageButton(int x, int y, int buttonID, int number, HouseGumpPageAOS page) @@ -533,12 +529,12 @@ namespace Server.Gumps AddHtmlLocalized(x + 35, y, 240, 20, number, enabled ? LabelColor : DisabledColor, false, false); } - public void AddList(ArrayList list, int button, bool accountOf, bool leadingStar, Mobile from) + public void AddList(List list, int button, bool accountOf, bool leadingStar, Mobile from) { if (list == null) return; - m_List = new ArrayList(list); + m_List = new List(list); int lastPage = 0; int index = 0; @@ -563,7 +559,7 @@ namespace Server.Gumps } - Mobile m = (Mobile)list[i]; + Mobile m = list[i]; string name; int labelHue = LabelHue; @@ -606,26 +602,20 @@ namespace Server.Gumps return 1 + index * 15 + type; } - public static void PublicPrivateNotice_Callback(Mobile from, object state) + public static void PublicPrivateNotice_Callback(Mobile from, BaseHouse house) { - BaseHouse house = (BaseHouse)state; - if (!house.Deleted) from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Security, from, house)); } - public static void CustomizeNotice_Callback(Mobile from, object state) + public static void CustomizeNotice_Callback(Mobile from, BaseHouse house) { - BaseHouse house = (BaseHouse)state; - if (!house.Deleted) from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Customize, from, house)); } - public static void ClearCoOwners_Callback(Mobile from, bool okay, object state) + public static void ClearCoOwners_Callback(Mobile from, bool okay, BaseHouse house) { - BaseHouse house = (BaseHouse)state; - if (house.Deleted) return; @@ -639,10 +629,8 @@ namespace Server.Gumps from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Security, from, house)); } - public static void ClearFriends_Callback(Mobile from, bool okay, object state) + public static void ClearFriends_Callback(Mobile from, bool okay, BaseHouse house) { - BaseHouse house = (BaseHouse)state; - if (house.Deleted) return; @@ -656,10 +644,8 @@ namespace Server.Gumps from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Security, from, house)); } - public static void ClearBans_Callback(Mobile from, bool okay, object state) + public static void ClearBans_Callback(Mobile from, bool okay, BaseHouse house) { - BaseHouse house = (BaseHouse)state; - if (house.Deleted) return; @@ -673,22 +659,20 @@ namespace Server.Gumps from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Security, from, house)); } - public static void ClearAccess_Callback(Mobile from, bool okay, object state) + public static void ClearAccess_Callback(Mobile from, bool okay, BaseHouse house) { - BaseHouse house = (BaseHouse)state; - if (house.Deleted) return; if (okay && house.IsFriend(from)) { - ArrayList list = new ArrayList(house.Access); + List list = house.Access.ToList(); house.Access?.Clear(); for (int i = 0; i < list.Count; ++i) { - Mobile m = (Mobile)list[i]; + Mobile m = list[i]; if (!house.HasAccess(m) && house.IsInside(m)) { @@ -703,10 +687,8 @@ namespace Server.Gumps from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Security, from, house)); } - public static void ConvertHouse_Callback(Mobile from, bool okay, object state) + public static void ConvertHouse_Callback(Mobile from, bool okay, BaseHouse house) { - BaseHouse house = (BaseHouse)state; - if (house.Deleted) return; @@ -714,8 +696,9 @@ namespace Server.Gumps { HousePlacementEntry e = house.ConvertEntry; - if (e != null) - { + if (e == null) + return; + int cost = e.Cost - house.Price; if (cost > 0) @@ -749,10 +732,10 @@ namespace Server.Gumps house.MoveAllToCrate(); - newHouse.Friends = new ArrayList(house.Friends); - newHouse.CoOwners = new ArrayList(house.CoOwners); - newHouse.Bans = new ArrayList(house.Bans); - newHouse.Access = new ArrayList(house.Access); + newHouse.Friends = new List(house.Friends); + newHouse.CoOwners = new List(house.CoOwners); + newHouse.Bans = new List(house.Bans); + newHouse.Access = new List(house.Access); newHouse.BuiltOn = house.BuiltOn; newHouse.LastTraded = house.LastTraded; newHouse.Public = house.Public; @@ -799,10 +782,9 @@ namespace Server.Gumps * These containers can be used to re-create the vendor in a new location. * Any barkeepers have been converted into deeds. */ - from.SendGump(new NoticeGump(1060637, 30720, 1060012, 32512, 420, 280, null, null)); + from.SendGump(new NoticeGump(1060637, 30720, 1060012, 32512, 420, 280)); return; } - } } from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Security, from, house)); @@ -971,7 +953,7 @@ namespace Server.Gumps { if (isOwner) from.SendGump(new WarningGump(1060635, 30720, 1060736, 32512, 420, 280, - ClearCoOwners_Callback, m_House)); + okay => ClearCoOwners_Callback(from, okay, m_House))); break; } @@ -1003,7 +985,7 @@ namespace Server.Gumps { if (isCoOwner) from.SendGump(new WarningGump(1060635, 30720, 1018039, 32512, 420, 280, - ClearFriends_Callback, m_House)); + okay => ClearFriends_Callback(from, okay, m_House))); break; } @@ -1015,8 +997,8 @@ namespace Server.Gumps } case 9: // Clear Ban List { - from.SendGump(new WarningGump(1060635, 30720, 1060753, 32512, 420, 280, ClearBans_Callback, - m_House)); + from.SendGump(new WarningGump(1060635, 30720, 1060753, 32512, 420, 280, + okay => ClearBans_Callback(from, okay, m_House))); break; } @@ -1028,8 +1010,8 @@ namespace Server.Gumps } case 11: // Clear Access List { - from.SendGump(new WarningGump(1060635, 30720, 1061842, 32512, 420, 280, ClearAccess_Callback, - m_House)); + from.SendGump(new WarningGump(1060635, 30720, 1061842, 32512, 420, 280, + okay => ClearAccess_Callback(from, okay, m_House))); break; } @@ -1041,7 +1023,7 @@ namespace Server.Gumps { // You have vendors working out of this building. It cannot be declared private until there are no vendors in place. from.SendGump(new NoticeGump(1060637, 30720, 501887, 32512, 320, 180, - PublicPrivateNotice_Callback, m_House)); + () => PublicPrivateNotice_Callback(from, m_House))); break; } @@ -1049,7 +1031,7 @@ namespace Server.Gumps { // You cannot currently take this action because you have vendor contracts locked down in your home. You must remove them first. from.SendGump(new NoticeGump(1060637, 30720, 1062351, 32512, 320, 180, - PublicPrivateNotice_Callback, m_House)); + () => PublicPrivateNotice_Callback(from, m_House))); break; } @@ -1059,7 +1041,7 @@ namespace Server.Gumps // This house is now private. from.SendGump(new NoticeGump(1060637, 30720, 501888, 32512, 320, 180, - PublicPrivateNotice_Callback, m_House)); + () => PublicPrivateNotice_Callback(from, m_House))); Region r = m_House.Region; List list = r.GetMobiles(); @@ -1086,11 +1068,11 @@ namespace Server.Gumps if (BaseHouse.NewVendorSystem) from.SendGump(new NoticeGump(1060637, 30720, 501886, 32512, 320, 180, - PublicPrivateNotice_Callback, m_House)); + () => PublicPrivateNotice_Callback(from, m_House))); else from.SendGump(new NoticeGump(1060637, 30720, "This house is now public. Friends of the house may now have vendors working out of this building.", - 0xF8C000, 320, 180, PublicPrivateNotice_Callback, m_House)); + 0xF8C000, 320, 180, () => PublicPrivateNotice_Callback(from, m_House))); Region r = m_House.Region; List list = r.GetMobiles(); @@ -1122,7 +1104,7 @@ namespace Server.Gumps { // You cannot perform this action while you still have vendors rented out in this house. from.SendGump(new NoticeGump(1060637, 30720, 1062395, 32512, 320, 180, - CustomizeNotice_Callback, m_House)); + () => CustomizeNotice_Callback(from, m_House))); } else { @@ -1130,7 +1112,7 @@ namespace Server.Gumps if (e != null) from.SendGump(new WarningGump(1060635, 30720, 1060013, 32512, 420, 280, - ConvertHouse_Callback, m_House)); + okay => ConvertHouse_Callback(from, okay, m_House))); } } @@ -1142,13 +1124,13 @@ namespace Server.Gumps { if (m_House.HasRentedVendors) from.SendGump(new NoticeGump(1060637, 30720, 1062395, 32512, 320, 180, - CustomizeNotice_Callback, m_House)); + () => CustomizeNotice_Callback(from, m_House))); #region Mondain's Legacy else if (m_House.HasAddonContainers) from.SendGump(new NoticeGump(1060637, 30720, 1074863, 32512, 320, 180, - CustomizeNotice_Callback, m_House)); + () => CustomizeNotice_Callback(from, m_House))); #endregion @@ -1239,7 +1221,7 @@ namespace Server.Gumps } else { - from.CloseGump(typeof(HouseDemolishGump)); + from.CloseGump(); from.SendGump(new HouseDemolishGump(from, m_House)); } } @@ -1436,13 +1418,13 @@ namespace Server.Gumps } } - private ArrayList Wrap(string value) + private List Wrap(string value) { if (value == null || (value = value.Trim()).Length <= 0) return null; string[] values = value.Split(' '); - ArrayList list = new ArrayList(); + List list = new List(); string current = ""; for (int i = 0; i < values.Length; ++i) diff --git a/Scripts/Gumps/NoticeGump.cs b/Scripts/Gumps/NoticeGump.cs index 024b08c14..9214929ea 100644 --- a/Scripts/Gumps/NoticeGump.cs +++ b/Scripts/Gumps/NoticeGump.cs @@ -2,18 +2,16 @@ using Server.Network; namespace Server.Gumps { - public delegate void NoticeGumpCallback(Mobile from, object state); + public delegate void NoticeGumpCallback(); public class NoticeGump : Gump { private NoticeGumpCallback m_Callback; - private object m_State; public NoticeGump(int header, int headerColor, object content, int contentColor, int width, int height, - NoticeGumpCallback callback, object state) : base((640 - width) / 2, (480 - height) / 2) + NoticeGumpCallback callback = null) : base((640 - width) / 2, (480 - height) / 2) { m_Callback = callback; - m_State = state; Closable = false; @@ -43,7 +41,7 @@ namespace Server.Gumps public override void OnResponse(NetState sender, RelayInfo info) { if (info.ButtonID == 1) - m_Callback?.Invoke(sender.Mobile, m_State); + m_Callback?.Invoke(); } } } \ No newline at end of file diff --git a/Scripts/Gumps/PetResurrectGump.cs b/Scripts/Gumps/PetResurrectGump.cs index 84540a9f1..bee72baf4 100644 --- a/Scripts/Gumps/PetResurrectGump.cs +++ b/Scripts/Gumps/PetResurrectGump.cs @@ -15,7 +15,7 @@ namespace Server.Gumps public PetResurrectGump(Mobile from, BaseCreature pet, double hitsScalar) : base(50, 50) { - from.CloseGump(typeof(PetResurrectGump)); + from.CloseGump(); m_Pet = pet; m_HitsScalar = hitsScalar; @@ -54,8 +54,7 @@ namespace Server.Gumps return; } - if (m_Pet.Region != null && m_Pet.Region.IsPartOf("Khaldun") - ) //TODO: Confirm for pets, as per Bandage's script. + if (m_Pet.Region?.IsPartOf("Khaldun") == true) //TODO: Confirm for pets, as per Bandage's script. { from.SendLocalizedMessage( 1010395); // The veil of death in this area is too strong and resists thy efforts to restore life. diff --git a/Scripts/Gumps/PlayerVendorGumps.cs b/Scripts/Gumps/PlayerVendorGumps.cs index b4e9a400e..eecd64f4b 100644 --- a/Scripts/Gumps/PlayerVendorGumps.cs +++ b/Scripts/Gumps/PlayerVendorGumps.cs @@ -426,7 +426,7 @@ namespace Server.Gumps m_Vendor = v; int x, y; - from.CloseGump(typeof(PlayerVendorCustomizeGump)); + from.CloseGump(); AddPage(0); AddBackground(0, 0, 585, 393, 5054); diff --git a/Scripts/Gumps/Props/PropsGump.cs b/Scripts/Gumps/Props/PropsGump.cs index 260c3e998..1d0d3e606 100644 --- a/Scripts/Gumps/Props/PropsGump.cs +++ b/Scripts/Gumps/Props/PropsGump.cs @@ -1,6 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Reflection; using Server.Commands.Generic; using Server.Network; @@ -125,7 +125,7 @@ namespace Server.Gumps private static Type typeofCPA = typeof(CPA); private static Type typeofObject = typeof(object); - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; @@ -162,7 +162,7 @@ namespace Server.Gumps Initialize(0); } - public PropertiesGump(Mobile mobile, object o, Stack stack, ArrayList list, int page) : base(GumpOffsetX, + public PropertiesGump(Mobile mobile, object o, Stack stack, List list, int page) : base(GumpOffsetX, GumpOffsetY) { m_Mobile = mobile; @@ -385,7 +385,7 @@ namespace Server.Gumps else if (IsType(type, typeofMap)) { from.SendGump(new SetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, - Map.GetMapNames(), Map.GetMapValues())); + Map.GetMapNames(), Map.GetMapValues().ToArray())); } else if (IsType(type, typeofSkills) && m_Object is Mobile mobile) { @@ -513,30 +513,29 @@ namespace Server.Gumps return o.ToString(); } - private ArrayList BuildList() + private List BuildList() { - ArrayList list = new ArrayList(); + List list = new List(); if (m_Type == null) return list; PropertyInfo[] props = m_Type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public); - ArrayList groups = GetGroups(m_Type, props); + List>> groups = GetGroups(m_Type, props); for (int i = 0; i < groups.Count; ++i) { - DictionaryEntry de = (DictionaryEntry)groups[i]; - ArrayList groupList = (ArrayList)de.Value; + KeyValuePair> kvp = groups[i]; - if (!HasAttribute((Type)de.Key, typeofNoSort, false)) - groupList.Sort(PropertySorter.Instance); + if (!HasAttribute(kvp.Key, typeofNoSort, false)) + kvp.Value.Sort(PropertySorter.Instance); if (i != 0) list.Add(null); - list.Add(de.Key); - list.AddRange(groupList); + list.Add(kvp.Key); + list.AddRange(kvp.Value); } return list; @@ -551,9 +550,9 @@ namespace Server.Gumps return null; } - private ArrayList GetGroups(Type objectType, PropertyInfo[] props) + private List>> GetGroups(Type objectType, PropertyInfo[] props) { - Hashtable groups = new Hashtable(); + Dictionary> groups = new Dictionary>(); for (int i = 0; i < props.Length; ++i) { @@ -569,32 +568,24 @@ namespace Server.Gumps while (true) { - Type baseType = type.BaseType; + Type baseType = type?.BaseType; - if (baseType == null || baseType == typeofObject) - break; - - if (baseType.GetProperty(prop.Name, prop.PropertyType) != null) - type = baseType; - else + if (baseType == typeofObject || baseType?.GetProperty(prop.Name, prop.PropertyType) == null) break; + + type = baseType; } - - ArrayList list = (ArrayList)groups[type]; - - if (list == null) - groups[type] = list = new ArrayList(); - - list.Add(prop); + + if (type != null && !groups.ContainsKey(type)) + groups[type] = new List{ prop }; } } } - ArrayList sorted = new ArrayList(groups); + List>> list = groups.ToList(); + list.Sort(new GroupComparer(objectType)); - sorted.Sort(new GroupComparer(objectType)); - - return sorted; + return list; } public static object GetObjectFromString(Type t, string s) @@ -652,7 +643,7 @@ namespace Server.Gumps return o.ToString(); } - private class PropertySorter : IComparer + private class PropertySorter : IComparer { public static readonly PropertySorter Instance = new PropertySorter(); @@ -660,28 +651,19 @@ namespace Server.Gumps { } - public int Compare(object x, object y) + public int Compare(PropertyInfo x, PropertyInfo y) { if (x == null && y == null) return 0; if (x == null) return -1; - if (y == null) - return 1; - - PropertyInfo a = x as PropertyInfo; - PropertyInfo b = y as PropertyInfo; - - if (a == null || b == null) - throw new ArgumentException(); - - return a.Name.CompareTo(b.Name); + + return y == null ? 1 : x.Name.CompareTo(x.Name); } } - private class GroupComparer : IComparer - { - private static Type typeofObject = typeof(object); + private class GroupComparer : IComparer>> + { private Type m_Start; public GroupComparer(Type start) @@ -689,22 +671,9 @@ namespace Server.Gumps m_Start = start; } - public int Compare(object x, object y) + public int Compare(KeyValuePair> x, KeyValuePair> y) { - if (x == null && y == null) - return 0; - if (x == null) - return -1; - if (y == null) - return 1; - - if (!(x is DictionaryEntry) || !(y is DictionaryEntry)) - throw new ArgumentException(); - - DictionaryEntry de1 = (DictionaryEntry)x; - DictionaryEntry de2 = (DictionaryEntry)y; - - return GetDistance((Type)de1.Key).CompareTo(GetDistance((Type)de2.Key)); + return GetDistance(x.Key).CompareTo(GetDistance(y.Key)); } private int GetDistance(Type type) diff --git a/Scripts/Gumps/Props/SetBodyGump.cs b/Scripts/Gumps/Props/SetBodyGump.cs index 75f0ade06..a4008a793 100644 --- a/Scripts/Gumps/Props/SetBodyGump.cs +++ b/Scripts/Gumps/Props/SetBodyGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -13,24 +12,19 @@ namespace Server.Gumps private const int SelectedColor32 = 0x8080FF; private const int TextColor32 = 0xFFFFFF; - private static ArrayList m_Monster, m_Animal, m_Sea, m_Human; - private ArrayList m_List; + private static List m_Monster, m_Animal, m_Sea, m_Human; + private List m_List; private Mobile m_Mobile; private object m_Object; - private ArrayList m_OurList; + private List m_OurList; private int m_OurPage; private ModelBodyType m_OurType; private int m_Page; private PropertyInfo m_Property; private Stack m_Stack; - public SetBodyGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list) - : this(prop, mobile, o, stack, page, list, 0, null, ModelBodyType.Invalid) - { - } - - public SetBodyGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list, - int ourPage, ArrayList ourList, ModelBodyType ourType) + public SetBodyGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list, + int ourPage = 0, List ourList = null, ModelBodyType ourType = ModelBodyType.Invalid) : base(20, 30) { m_Property = prop; @@ -73,7 +67,7 @@ namespace Server.Gumps { for (int i = 0, index = ourPage * 12; i < 12 && index >= 0 && index < ourList.Count; ++i, ++index) { - InternalEntry entry = (InternalEntry)ourList[index]; + InternalEntry entry = ourList[index]; int itemID = entry.ItemID; Rectangle2D bounds = ItemBounds.Table[itemID & 0x3FFF]; @@ -134,7 +128,7 @@ namespace Server.Gumps LoadLists(); ModelBodyType type; - ArrayList list; + List list; switch (index) { @@ -181,7 +175,7 @@ namespace Server.Gumps { try { - InternalEntry entry = (InternalEntry)m_OurList[index]; + InternalEntry entry = m_OurList[index]; CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, entry.Body.ToString()); m_Property.SetValue(m_Object, entry.Body, null); @@ -201,10 +195,10 @@ namespace Server.Gumps private static void LoadLists() { - m_Monster = new ArrayList(); - m_Animal = new ArrayList(); - m_Sea = new ArrayList(); - m_Human = new ArrayList(); + m_Monster = new List(); + m_Animal = new List(); + m_Sea = new List(); + m_Human = new List(); List entries = Docs.LoadBodies(); @@ -216,10 +210,11 @@ namespace Server.Gumps if (((Body)bodyID).IsEmpty) continue; - ArrayList list = null; + List list; switch (oldEntry.BodyType) { + default: continue; case ModelBodyType.Monsters: list = m_Monster; break; @@ -234,9 +229,6 @@ namespace Server.Gumps break; } - if (list == null) - continue; - int itemID = ShrinkTable.Lookup(bodyID, -1); if (itemID != -1) @@ -249,7 +241,7 @@ namespace Server.Gumps m_Human.Sort(); } - private class InternalEntry : IComparable + public class InternalEntry : IComparable { private static string[] m_GroupNames = { @@ -296,10 +288,8 @@ namespace Server.Gumps public string DisplayName{ get; } - public int CompareTo(object obj) + public int CompareTo(InternalEntry comp) { - InternalEntry comp = (InternalEntry)obj; - int v = Name.CompareTo(comp.Name); if (v == 0) diff --git a/Scripts/Gumps/Props/SetCustomEnumGump.cs b/Scripts/Gumps/Props/SetCustomEnumGump.cs index 3813c33aa..63601c9ac 100644 --- a/Scripts/Gumps/Props/SetCustomEnumGump.cs +++ b/Scripts/Gumps/Props/SetCustomEnumGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -12,7 +11,7 @@ namespace Server.Gumps private string[] m_Names; public SetCustomEnumGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int propspage, - ArrayList list, string[] names) : base(prop, mobile, o, stack, propspage, list, names, null) + List list, string[] names) : base(prop, mobile, o, stack, propspage, list, names, null) { m_Names = names; } @@ -26,7 +25,7 @@ namespace Server.Gumps { MethodInfo info = m_Property.PropertyType.GetMethod("Parse", new[] { typeof(string) }); - string result = ""; + string result; if (info != null) result = Properties.SetDirect(m_Mobile, m_Object, m_Object, m_Property, m_Property.Name, @@ -34,6 +33,8 @@ namespace Server.Gumps else if (m_Property.PropertyType == typeof(Enum) || m_Property.PropertyType.IsSubclassOf(typeof(Enum))) result = Properties.SetDirect(m_Mobile, m_Object, m_Object, m_Property, m_Property.Name, Enum.Parse(m_Property.PropertyType, m_Names[index], false), true); + else + result = ""; m_Mobile.SendMessage(result); diff --git a/Scripts/Gumps/Props/SetGump.cs b/Scripts/Gumps/Props/SetGump.cs index 7019b2ab3..ad8873f01 100644 --- a/Scripts/Gumps/Props/SetGump.cs +++ b/Scripts/Gumps/Props/SetGump.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -50,14 +49,14 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; private PropertyInfo m_Property; private Stack m_Stack; - public SetGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list) : base( + public SetGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list) : base( GumpOffsetX, GumpOffsetY) { m_Property = prop; @@ -246,7 +245,7 @@ namespace Server.Gumps private class InternalPicker : HuePicker { - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; @@ -254,7 +253,7 @@ namespace Server.Gumps private Stack m_Stack; public InternalPicker(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, - ArrayList list) : base(((IHued)o).HuedItemID) + List list) : base(((IHued)o).HuedItemID) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Props/SetListOptionGump.cs b/Scripts/Gumps/Props/SetListOptionGump.cs index a541cbaf1..17f66786f 100644 --- a/Scripts/Gumps/Props/SetListOptionGump.cs +++ b/Scripts/Gumps/Props/SetListOptionGump.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -56,17 +55,17 @@ namespace Server.Gumps private static readonly int NextLabelOffsetX = -29; private static readonly int NextLabelOffsetY = 0; - protected ArrayList m_List; + protected List m_List; protected Mobile m_Mobile; protected object m_Object; protected int m_Page; protected PropertyInfo m_Property; protected Stack m_Stack; - protected object[] m_Values; + private object[] m_Values; public SetListOptionGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int propspage, - ArrayList list, string[] names, object[] values) : base(GumpOffsetX, GumpOffsetY) + List list, string[] names, object[] values) : base(GumpOffsetX, GumpOffsetY) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Props/SetObjectGump.cs b/Scripts/Gumps/Props/SetObjectGump.cs index ec42c913f..122b725b9 100644 --- a/Scripts/Gumps/Props/SetObjectGump.cs +++ b/Scripts/Gumps/Props/SetObjectGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -52,7 +51,7 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; @@ -61,7 +60,7 @@ namespace Server.Gumps private Type m_Type; public SetObjectGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, - ArrayList list) : base(GumpOffsetX, GumpOffsetY) + List list) : base(GumpOffsetX, GumpOffsetY) { m_Property = prop; m_Mobile = mobile; @@ -204,7 +203,7 @@ namespace Server.Gumps private class InternalPrompt : Prompt { - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; @@ -213,7 +212,7 @@ namespace Server.Gumps private Type m_Type; public InternalPrompt(PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, - ArrayList list) + List list) { m_Property = prop; m_Mobile = mobile; @@ -233,7 +232,7 @@ namespace Server.Gumps { try { - int serial = Utility.ToInt32(text); + uint serial = Utility.ToUInt32(text); IEntity toSet = World.FindEntity(serial); diff --git a/Scripts/Gumps/Props/SetObjectTarget.cs b/Scripts/Gumps/Props/SetObjectTarget.cs index b8ca0cfa9..4cc256154 100644 --- a/Scripts/Gumps/Props/SetObjectTarget.cs +++ b/Scripts/Gumps/Props/SetObjectTarget.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -10,7 +9,7 @@ namespace Server.Gumps { public class SetObjectTarget : Target { - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; @@ -19,7 +18,7 @@ namespace Server.Gumps private Type m_Type; public SetObjectTarget(PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, - ArrayList list) : base(-1, false, TargetFlags.None) + List list) : base(-1, false, TargetFlags.None) { m_Property = prop; m_Mobile = mobile; @@ -37,8 +36,8 @@ namespace Server.Gumps if (m_Type == typeof(Type)) targeted = targeted.GetType(); else if ((m_Type == typeof(BaseAddon) || m_Type.IsAssignableFrom(typeof(BaseAddon))) && - targeted is AddonComponent) - targeted = ((AddonComponent)targeted).Addon; + targeted is AddonComponent addonComponent) + targeted = addonComponent.Addon; if (m_Type.IsInstanceOfType(targeted)) { diff --git a/Scripts/Gumps/Props/SetPoint2DGump.cs b/Scripts/Gumps/Props/SetPoint2DGump.cs index 94b860e36..c0192c3d1 100644 --- a/Scripts/Gumps/Props/SetPoint2DGump.cs +++ b/Scripts/Gumps/Props/SetPoint2DGump.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -51,14 +50,14 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; private PropertyInfo m_Property; private Stack m_Stack; - public SetPoint2DGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list) + public SetPoint2DGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list) : base(GumpOffsetX, GumpOffsetY) { m_Property = prop; @@ -190,7 +189,7 @@ namespace Server.Gumps private class InternalTarget : Target { - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; @@ -198,7 +197,7 @@ namespace Server.Gumps private Stack m_Stack; public InternalTarget(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, - ArrayList list) : base(-1, true, TargetFlags.None) + List list) : base(-1, true, TargetFlags.None) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Props/SetPoint3DGump.cs b/Scripts/Gumps/Props/SetPoint3DGump.cs index ec8e07e7e..8539cfbca 100644 --- a/Scripts/Gumps/Props/SetPoint3DGump.cs +++ b/Scripts/Gumps/Props/SetPoint3DGump.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -51,14 +50,14 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; private PropertyInfo m_Property; private Stack m_Stack; - public SetPoint3DGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list) + public SetPoint3DGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list) : base(GumpOffsetX, GumpOffsetY) { m_Property = prop; @@ -197,7 +196,7 @@ namespace Server.Gumps private class InternalTarget : Target { - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; @@ -205,7 +204,7 @@ namespace Server.Gumps private Stack m_Stack; public InternalTarget(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, - ArrayList list) : base(-1, true, TargetFlags.None) + List list) : base(-1, true, TargetFlags.None) { m_Property = prop; m_Mobile = mobile; diff --git a/Scripts/Gumps/Props/SetTimeSpanGump.cs b/Scripts/Gumps/Props/SetTimeSpanGump.cs index 5abf216cb..fef434dfd 100644 --- a/Scripts/Gumps/Props/SetTimeSpanGump.cs +++ b/Scripts/Gumps/Props/SetTimeSpanGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Reflection; using Server.Commands; @@ -50,14 +49,14 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private ArrayList m_List; + private List m_List; private Mobile m_Mobile; private object m_Object; private int m_Page; private PropertyInfo m_Property; private Stack m_Stack; - public SetTimeSpanGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list) + public SetTimeSpanGump(PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list) : base(GumpOffsetX, GumpOffsetY) { m_Property = prop; @@ -127,7 +126,7 @@ namespace Server.Gumps { bool successfulParse = false; if (h != null && m != null && s != null) - successfulParse = TimeSpan.TryParse(h.Text + ":" + m.Text + ":" + s.Text, out toSet); + successfulParse = TimeSpan.TryParse($"{h.Text}:{m.Text}:{s.Text}", out toSet); else toSet = TimeSpan.Zero; @@ -148,6 +147,7 @@ namespace Server.Gumps } catch { + // ignored } toSet = TimeSpan.Zero; @@ -169,6 +169,7 @@ namespace Server.Gumps } catch { + // ignored } toSet = TimeSpan.Zero; @@ -190,6 +191,7 @@ namespace Server.Gumps } catch { + // ignored } toSet = TimeSpan.Zero; diff --git a/Scripts/Gumps/ReclaimVendorGump.cs b/Scripts/Gumps/ReclaimVendorGump.cs index acbd837e3..2651619b3 100644 --- a/Scripts/Gumps/ReclaimVendorGump.cs +++ b/Scripts/Gumps/ReclaimVendorGump.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System.Collections.Generic; +using System.Linq; using Server.Multis; using Server.Network; @@ -7,12 +8,12 @@ namespace Server.Gumps public class ReclaimVendorGump : Gump { private BaseHouse m_House; - private ArrayList m_Vendors; + private List m_Vendors; public ReclaimVendorGump(BaseHouse house) : base(50, 50) { m_House = house; - m_Vendors = new ArrayList(house.InternalizedVendors); + m_Vendors = house.InternalizedVendors.ToList(); AddBackground(0, 0, 170, 50 + m_Vendors.Count * 20, 0x13BE); @@ -23,7 +24,7 @@ namespace Server.Gumps for (int i = 0; i < m_Vendors.Count; i++) { - Mobile m = (Mobile)m_Vendors[i]; + Mobile m = m_Vendors[i]; int y = 40 + i * 20; @@ -45,7 +46,7 @@ namespace Server.Gumps if (index < 0 || index >= m_Vendors.Count) return; - Mobile mob = (Mobile)m_Vendors[index]; + Mobile mob = m_Vendors[index]; if (!m_House.InternalizedVendors.Contains(mob)) return; @@ -56,8 +57,7 @@ namespace Server.Gumps } else { - bool vendor, contract; - BaseHouse.IsThereVendor(from.Location, from.Map, out vendor, out contract); + BaseHouse.IsThereVendor(from.Location, from.Map, out bool vendor, out bool contract); if (vendor) { diff --git a/Scripts/Gumps/ReportMurderer.cs b/Scripts/Gumps/ReportMurderer.cs index fdfdd713c..f5436f61f 100644 --- a/Scripts/Gumps/ReportMurderer.cs +++ b/Scripts/Gumps/ReportMurderer.cs @@ -131,22 +131,15 @@ namespace Server.Gumps AddHtmlLocalized( 400, 300, 300, 50, 1046363, false, false ); // No } - public static void ReportedListExpiry_Callback( object state ) + public static void ReportedListExpiry_Callback( PlayerMobile from, Mobile killer ) { - object[] states = (object[])state; - - PlayerMobile from = (PlayerMobile)states[0]; - Mobile killer = (Mobile)states[1]; - if (from.RecentlyReported.Contains(killer)) - { from.RecentlyReported.Remove(killer); - } } public override void OnResponse( NetState state, RelayInfo info ) { - Mobile from = state.Mobile; + PlayerMobile from = (PlayerMobile)state.Mobile; switch ( info.ButtonID ) { @@ -160,8 +153,8 @@ namespace Server.Gumps if (Core.SE) { - ((PlayerMobile)from).RecentlyReported.Add(killer); - Timer.DelayCall(TimeSpan.FromMinutes(10), new TimerStateCallback(ReportedListExpiry_Callback), new object[] { from, killer }); + from.RecentlyReported.Add(killer); + Timer.DelayCall(TimeSpan.FromMinutes(10), () => ReportedListExpiry_Callback(from, killer)); } if (killer is PlayerMobile pk) diff --git a/Scripts/Gumps/ResurrectGump.cs b/Scripts/Gumps/ResurrectGump.cs index 2367cdf3c..0808100e0 100644 --- a/Scripts/Gumps/ResurrectGump.cs +++ b/Scripts/Gumps/ResurrectGump.cs @@ -140,7 +140,7 @@ namespace Server.Gumps { Mobile from = state.Mobile; - from.CloseGump( typeof( ResurrectGump ) ); + from.CloseGump(); if ( info.ButtonID == 1 || info.ButtonID == 2 ) { diff --git a/Scripts/Gumps/RunebookGump.cs b/Scripts/Gumps/RunebookGump.cs index 54df01b19..c14411952 100644 --- a/Scripts/Gumps/RunebookGump.cs +++ b/Scripts/Gumps/RunebookGump.cs @@ -251,7 +251,7 @@ namespace Server.Gumps { if (Book.CurCharges <= 0) { - from.CloseGump(typeof(RunebookGump)); + from.CloseGump(); from.SendGump(new RunebookGump(from, Book)); from.SendLocalizedMessage(502412); // There are no charges left on that item. @@ -284,7 +284,7 @@ namespace Server.Gumps { Book.DropRune(from, e, index); - from.CloseGump(typeof(RunebookGump)); + from.CloseGump(); if (!Core.ML) from.SendGump(new RunebookGump(from, Book)); } @@ -304,7 +304,7 @@ namespace Server.Gumps { Book.Default = e; - from.CloseGump(typeof(RunebookGump)); + from.CloseGump(); from.SendGump(new RunebookGump(from, Book)); from.SendLocalizedMessage(502417); // New default location set. @@ -329,7 +329,7 @@ namespace Server.Gumps } Book.OnTravel(); - new RecallSpell(from, null, e, null).Cast(); + new RecallSpell(from, null, e).Cast(); } else { @@ -387,7 +387,7 @@ namespace Server.Gumps } Book.OnTravel(); - new SacredJourneySpell(from, null, e, null).Cast(); + new SacredJourneySpell(from, null, e).Cast(); } else { @@ -426,7 +426,7 @@ namespace Server.Gumps { m_Book.Description = Utility.FixHtml(text.Trim()); - from.CloseGump(typeof(RunebookGump)); + from.CloseGump(); from.SendGump(new RunebookGump(from, m_Book)); from.SendMessage("The book's title has been changed."); @@ -445,7 +445,7 @@ namespace Server.Gumps if (!m_Book.Deleted && from.InRange(m_Book.GetWorldLocation(), Core.ML ? 3 : 1)) { - from.CloseGump(typeof(RunebookGump)); + from.CloseGump(); from.SendGump(new RunebookGump(from, m_Book)); } } diff --git a/Scripts/Gumps/ToTAdminGump.cs b/Scripts/Gumps/ToTAdminGump.cs index 7ffb8bd5d..1e8e64410 100644 --- a/Scripts/Gumps/ToTAdminGump.cs +++ b/Scripts/Gumps/ToTAdminGump.cs @@ -36,7 +36,7 @@ namespace Server.Gumps { Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; m_ToTEras = Enum.GetValues(typeof(TreasuresOfTokunoEra)).Length - 1; @@ -128,7 +128,7 @@ namespace Server.Gumps ToTAdminGump tg; tg = new ToTAdminGump(); - e.Mobile.CloseGump(typeof(ToTAdminGump)); + e.Mobile.CloseGump(); e.Mobile.SendGump(tg); } } diff --git a/Scripts/Gumps/VendorInventoryGump.cs b/Scripts/Gumps/VendorInventoryGump.cs index 8d700600a..b6f728825 100644 --- a/Scripts/Gumps/VendorInventoryGump.cs +++ b/Scripts/Gumps/VendorInventoryGump.cs @@ -1,5 +1,6 @@ using System; -using System.Collections; +using System.Collections.Generic; +using System.Linq; using Server.Mobiles; using Server.Multis; using Server.Network; @@ -9,12 +10,12 @@ namespace Server.Gumps public class VendorInventoryGump : Gump { private BaseHouse m_House; - private ArrayList m_Inventories; + private List m_Inventories; public VendorInventoryGump(BaseHouse house, Mobile from) : base(50, 50) { m_House = house; - m_Inventories = new ArrayList(house.VendorInventories); + m_Inventories = house.VendorInventories.ToList(); AddBackground(0, 0, 420, 50 + 20 * m_Inventories.Count, 0x13BE); @@ -26,7 +27,7 @@ namespace Server.Gumps for (int i = 0; i < m_Inventories.Count; i++) { - VendorInventory inventory = (VendorInventory)m_Inventories[i]; + VendorInventory inventory = m_Inventories[i]; int y = 40 + 20 * i; @@ -64,7 +65,7 @@ namespace Server.Gumps if (index < 0 || index >= m_Inventories.Count) return; - VendorInventory inventory = (VendorInventory)m_Inventories[index]; + VendorInventory inventory = m_Inventories[index]; if (inventory.Owner != from || !m_House.VendorInventories.Contains(inventory)) return; diff --git a/Scripts/Gumps/ViewHousesGump.cs b/Scripts/Gumps/ViewHousesGump.cs index 678343a6e..ccd70cf44 100644 --- a/Scripts/Gumps/ViewHousesGump.cs +++ b/Scripts/Gumps/ViewHousesGump.cs @@ -23,7 +23,7 @@ namespace Server.Gumps m_List = list; m_Selection = sel; - from.CloseGump(typeof(ViewHousesGump)); + from.CloseGump(); AddPage(0); diff --git a/Scripts/Gumps/WarningGump.cs b/Scripts/Gumps/WarningGump.cs index 9e1f6be1b..98dfa89ed 100644 --- a/Scripts/Gumps/WarningGump.cs +++ b/Scripts/Gumps/WarningGump.cs @@ -1,25 +1,14 @@ -using System; - namespace Server.Gumps { - public delegate void WarningGumpCallback( Mobile from, bool okay, object state ); + public delegate void WarningGumpCallback( bool okay ); public class WarningGump : Gump { private WarningGumpCallback m_Callback; - private object m_State; - private bool m_CancelButton; - public WarningGump( int header, int headerColor, object content, int contentColor, int width, int height, WarningGumpCallback callback, object state ) - : this( header, headerColor, content, contentColor, width, height, callback, state, true ) - { - } - - public WarningGump( int header, int headerColor, object content, int contentColor, int width, int height, WarningGumpCallback callback, object state, bool cancelButton ) : base( (640 - width) / 2, (480 - height) / 2 ) + public WarningGump( int header, int headerColor, object content, int contentColor, int width, int height, WarningGumpCallback callback = null, bool cancelButton = true) : base( (640 - width) / 2, (480 - height) / 2 ) { m_Callback = callback; - m_State = state; - m_CancelButton = cancelButton; Closable = false; @@ -45,7 +34,7 @@ namespace Server.Gumps AddButton( 10, height - 30, 4005, 4007, 1, GumpButtonType.Reply, 0 ); AddHtmlLocalized( 40, height - 30, 170, 20, 1011036, 32767, false, false ); // OKAY - if ( m_CancelButton ) + if ( cancelButton ) { AddButton( 10 + ((width - 20) / 2), height - 30, 4005, 4007, 0, GumpButtonType.Reply, 0 ); AddHtmlLocalized( 40 + ((width - 20) / 2), height - 30, 170, 20, 1011012, 32767, false, false ); // CANCEL @@ -58,9 +47,9 @@ namespace Server.Gumps return; if ( info.ButtonID == 1) - m_Callback( sender.Mobile, true, m_State ); + m_Callback( true ); else - m_Callback.Invoke( sender.Mobile, false, m_State ); + m_Callback.Invoke( false ); } } } diff --git a/Scripts/Gumps/WhoGump.cs b/Scripts/Gumps/WhoGump.cs index c845cf51b..0f81d166b 100644 --- a/Scripts/Gumps/WhoGump.cs +++ b/Scripts/Gumps/WhoGump.cs @@ -104,7 +104,7 @@ namespace Server.Gumps public WhoGump( Mobile owner, List list, int page ) : base( GumpOffsetX, GumpOffsetY ) { - owner.CloseGump( typeof( WhoGump ) ); + owner.CloseGump(); m_Owner = owner; m_Mobiles = list; diff --git a/Scripts/Holiday Stuff/Christmas/2010/Addons/FireFliesDeed.cs b/Scripts/Holiday Stuff/Christmas/2010/Addons/FireFliesDeed.cs index 7c3cdd94d..065b3b9ee 100644 --- a/Scripts/Holiday Stuff/Christmas/2010/Addons/FireFliesDeed.cs +++ b/Scripts/Holiday Stuff/Christmas/2010/Addons/FireFliesDeed.cs @@ -67,7 +67,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(RewardDemolitionGump)); + from.CloseGump(); from.SendGump(new RewardDemolitionGump(this, 1049783)); // Do you wish to re-deed this decoration? } else @@ -122,7 +122,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(FacingGump)); + from.CloseGump(); if (!from.SendGump(new FacingGump(this, from))) from.SendLocalizedMessage(1150062); // You fail to re-deed the holiday fireflies. @@ -165,7 +165,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Holiday Stuff/Halloween/2006/Engines/TrickOrTreat.cs b/Scripts/Holiday Stuff/Halloween/2006/Engines/TrickOrTreat.cs index 554fbe0c1..2784cea48 100644 --- a/Scripts/Holiday Stuff/Halloween/2006/Engines/TrickOrTreat.cs +++ b/Scripts/Holiday Stuff/Halloween/2006/Engines/TrickOrTreat.cs @@ -252,8 +252,7 @@ namespace Server.Engines.Events m_From = from; Name = $"{from.Name}\'s Naughty Twin"; - Timer.DelayCall(TrickOrTreat.OneSecond, - Utility.RandomBool() ? StealCandy : new TimerStateCallback(ToGate), m_From); + Timer.DelayCall(TrickOrTreat.OneSecond, StealCandyOrGate, m_From); } } @@ -278,25 +277,24 @@ namespace Server.Engines.Events return null; } - public static void StealCandy(Mobile target) + public static void StealCandyOrGate(Mobile target) { if (TrickOrTreat.CheckMobile(target)) { - Item item = FindCandyTypes(target); + if (Utility.RandomBool()) + { + Item item = FindCandyTypes(target); - target.SendLocalizedMessage(1113967); /* Your naughty twin steals some of your candy. */ + target.SendLocalizedMessage(1113967); /* Your naughty twin steals some of your candy. */ - if (item != null && !item.Deleted) item.Delete(); - } - } - - public static void ToGate(Mobile target) - { - if (TrickOrTreat.CheckMobile(target)) - { - target.SendLocalizedMessage(1113972); /* Your naughty twin teleports you away with a naughty laugh! */ - - target.MoveToWorld(RandomMoongate(target), target.Map); + if (item != null && !item.Deleted) + item.Delete(); + } + else + { + target.SendLocalizedMessage(1113972); /* Your naughty twin teleports you away with a naughty laugh! */ + target.MoveToWorld(RandomMoongate(target), target.Map); + } } } diff --git a/Scripts/Items/Addons/ArcheryButteAddon.cs b/Scripts/Items/Addons/ArcheryButteAddon.cs index 87376c535..b65bda7be 100644 --- a/Scripts/Items/Addons/ArcheryButteAddon.cs +++ b/Scripts/Items/Addons/ArcheryButteAddon.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Network; namespace Server.Items @@ -87,14 +88,14 @@ namespace Server.Items } } - private Hashtable m_Entries; + private Dictionary m_Entries; private ScoreEntry GetEntryFor( Mobile from ) { if ( m_Entries == null ) - m_Entries = new Hashtable(); + m_Entries = new Dictionary(); - ScoreEntry e = (ScoreEntry)m_Entries[from]; + ScoreEntry e = m_Entries[from]; if ( e == null ) m_Entries[from] = e = new ScoreEntry(); diff --git a/Scripts/Items/Addons/BaseAddon.cs b/Scripts/Items/Addons/BaseAddon.cs index 893c33ff5..9c0d0558d 100644 --- a/Scripts/Items/Addons/BaseAddon.cs +++ b/Scripts/Items/Addons/BaseAddon.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using Server.Multis; @@ -140,11 +139,11 @@ namespace Server.Items } } - ArrayList doors = house.Doors; + List doors = house.Doors; for (int i = 0; i < doors.Count; ++i) { - BaseDoor door = doors[i] as BaseDoor; + BaseDoor door = doors[i]; Point3D doorLoc = door.GetWorldLocation(); int doorHeight = door.ItemData.CalcHeight; diff --git a/Scripts/Items/Addons/BaseAddonContainer.cs b/Scripts/Items/Addons/BaseAddonContainer.cs index 50439fc96..2677e4c06 100644 --- a/Scripts/Items/Addons/BaseAddonContainer.cs +++ b/Scripts/Items/Addons/BaseAddonContainer.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using Server.Multis; @@ -250,11 +249,11 @@ namespace Server.Items if (house != null) { - ArrayList doors = house.Doors; + List doors = house.Doors; for (int i = 0; i < doors.Count; ++i) { - BaseDoor door = doors[i] as BaseDoor; + BaseDoor door = doors[i]; if (door != null && door.Open) return AddonFitResult.DoorsNotClosed; diff --git a/Scripts/Items/Addons/FlourMillEastAddon.cs b/Scripts/Items/Addons/FlourMillEastAddon.cs index 85c895f65..e5c597386 100644 --- a/Scripts/Items/Addons/FlourMillEastAddon.cs +++ b/Scripts/Items/Addons/FlourMillEastAddon.cs @@ -71,11 +71,11 @@ namespace Server.Items if (IsWorking) return; - m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(FinishWorking_Callback), from); + m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), FinishWorking_Callback, from); UpdateStage(); } - private void FinishWorking_Callback(object state) + private void FinishWorking_Callback(Mobile from) { if (m_Timer != null) { @@ -83,11 +83,10 @@ namespace Server.Items m_Timer = null; } - if (state is Mobile from && !from.Deleted && !Deleted && IsFull) + if (from?.Deleted == false && !Deleted && IsFull) { - SackFlour flour = new SackFlour(); + SackFlour flour = new SackFlour { ItemID = Utility.RandomBool() ? 4153 : 4165 }; - flour.ItemID = Utility.RandomBool() ? 4153 : 4165; if (from.PlaceInBackpack(flour)) { diff --git a/Scripts/Items/Addons/FlourMillSouthAddon.cs b/Scripts/Items/Addons/FlourMillSouthAddon.cs index 31917916d..a158ec628 100644 --- a/Scripts/Items/Addons/FlourMillSouthAddon.cs +++ b/Scripts/Items/Addons/FlourMillSouthAddon.cs @@ -58,11 +58,11 @@ namespace Server.Items if (IsWorking) return; - m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(FinishWorking_Callback), from); + m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), FinishWorking_Callback, from); UpdateStage(); } - private void FinishWorking_Callback(object state) + private void FinishWorking_Callback(Mobile from) { if (m_Timer != null) { @@ -70,7 +70,7 @@ namespace Server.Items m_Timer = null; } - if (state is Mobile from && !from.Deleted && !Deleted && IsFull) + if (from?.Deleted == false && !Deleted && IsFull) { SackFlour flour = new SackFlour(); diff --git a/Scripts/Items/Addons/PickpocketDips.cs b/Scripts/Items/Addons/PickpocketDips.cs index c548fc90e..1e5cc6364 100644 --- a/Scripts/Items/Addons/PickpocketDips.cs +++ b/Scripts/Items/Addons/PickpocketDips.cs @@ -78,7 +78,7 @@ namespace Server.Items SendLocalizedMessageTo(from, 501816); // You are too far away to do that. else if (Swinging) SendLocalizedMessageTo(from, 501815); // You have to wait until it stops swinging. - else if (from.Skills[SkillName.Stealing].Base >= MaxSkill) + else if (from.Skills.Stealing.Base >= MaxSkill) SendLocalizedMessageTo(from, 501830); // Your ability to steal cannot improve any further by simply practicing on a dummy. else if (from.Mounted) diff --git a/Scripts/Items/Addons/RejuvinationAnkhs.cs b/Scripts/Items/Addons/RejuvinationAnkhs.cs index 46975eb2d..b2cd92031 100644 --- a/Scripts/Items/Addons/RejuvinationAnkhs.cs +++ b/Scripts/Items/Addons/RejuvinationAnkhs.cs @@ -14,7 +14,7 @@ namespace Server.Items public override void OnDoubleClick(Mobile from) { - if (from.BeginAction(typeof(RejuvinationAddonComponent))) + if (from.BeginAction()) { from.FixedEffect(0x373A, 1, 16); @@ -38,19 +38,13 @@ namespace Server.Items SendLocalizedMessageTo(from, 500803); // You feel as though you've slept for days! } - Timer.DelayCall(TimeSpan.FromHours(2.0), new TimerStateCallback(ReleaseUseLock_Callback), - new object[] { from, random }); + Timer.DelayCall(TimeSpan.FromHours(2.0), () => ReleaseUseLock_Callback(from, random)); } } - public virtual void ReleaseUseLock_Callback(object state) + public virtual void ReleaseUseLock_Callback(Mobile from, int random) { - object[] states = (object[])state; - - Mobile from = (Mobile)states[0]; - int random = (int)states[1]; - - from.EndAction(typeof(RejuvinationAddonComponent)); + from.EndAction(); if (random == 4) { diff --git a/Scripts/Items/Addons/WaterTroughEastAddon.cs b/Scripts/Items/Addons/WaterTroughEastAddon.cs index e8b071550..4a6e941eb 100644 --- a/Scripts/Items/Addons/WaterTroughEastAddon.cs +++ b/Scripts/Items/Addons/WaterTroughEastAddon.cs @@ -15,7 +15,7 @@ namespace Server.Items public override BaseAddonDeed Deed => new WaterTroughEastDeed(); - public int Quantity + int IHasQuantity.Quantity { get => 500; set { } diff --git a/Scripts/Items/Addons/WaterTroughSouthAddon.cs b/Scripts/Items/Addons/WaterTroughSouthAddon.cs index 7a51e85eb..46f616bac 100644 --- a/Scripts/Items/Addons/WaterTroughSouthAddon.cs +++ b/Scripts/Items/Addons/WaterTroughSouthAddon.cs @@ -15,7 +15,7 @@ namespace Server.Items public override BaseAddonDeed Deed => new WaterTroughSouthDeed(); - public int Quantity + int IHasQuantity.Quantity { get => 500; set { } diff --git a/Scripts/Items/Aquarium/Aquarium.cs b/Scripts/Items/Aquarium/Aquarium.cs index f3df612f3..d5cefdcc0 100644 --- a/Scripts/Items/Aquarium/Aquarium.cs +++ b/Scripts/Items/Aquarium/Aquarium.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.ContextMenus; using Server.Multis; using Server.Network; @@ -253,7 +252,7 @@ namespace Server.Items takeItem = false; } - from.CloseGump(typeof(AquariumGump)); + from.CloseGump(); InvalidateProperties(); @@ -821,7 +820,7 @@ namespace Server.Items return; } - from.CloseGump(typeof(AquariumGump)); + from.CloseGump(); from.SendGump(new AquariumGump(this, HasAccess(from))); from.PlaySound(0x5A4); diff --git a/Scripts/Items/Aquarium/AquariumGump.cs b/Scripts/Items/Aquarium/AquariumGump.cs index acb3a91e1..3e80470dc 100644 --- a/Scripts/Items/Aquarium/AquariumGump.cs +++ b/Scripts/Items/Aquarium/AquariumGump.cs @@ -13,7 +13,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Armor/BaseArmor.cs b/Scripts/Items/Armor/BaseArmor.cs index bf6c3785d..2be6dea12 100644 --- a/Scripts/Items/Armor/BaseArmor.cs +++ b/Scripts/Items/Armor/BaseArmor.cs @@ -12,11 +12,6 @@ namespace Server.Items { public abstract class BaseArmor : Item, IScissorable, IFactionItem, ICraftable, IWearableDurability { - private AosArmorAttributes m_AosArmorAttributes; - - private AosAttributes m_AosAttributes; - private AosSkillBonuses m_AosSkillBonuses; - // Overridable values. These values are provided to override the defaults which get defined in the individual armor scripts. private int m_ArmorBase = -1; private Mobile m_Crafter; @@ -67,9 +62,9 @@ namespace Server.Items Layer = (Layer)ItemData.Quality; - m_AosAttributes = new AosAttributes(this); - m_AosArmorAttributes = new AosArmorAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); + Attributes = new AosAttributes(this); + ArmorAttributes = new AosArmorAttributes(this); + SkillBonuses = new AosSkillBonuses(this); } @@ -357,25 +352,13 @@ namespace Server.Items } [CommandProperty(AccessLevel.GameMaster)] - public AosAttributes Attributes - { - get => m_AosAttributes; - set { } - } + public AosAttributes Attributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosArmorAttributes ArmorAttributes - { - get => m_AosArmorAttributes; - set { } - } + public AosArmorAttributes ArmorAttributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosSkillBonuses SkillBonuses - { - get => m_AosSkillBonuses; - set { } - } + public AosSkillBonuses SkillBonuses{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] public int PhysicalBonus @@ -664,7 +647,7 @@ namespace Server.Items if (25 > Utility.Random(100)) // 25% chance to lower durability { - if (Core.AOS && m_AosArmorAttributes.SelfRepair > Utility.Random(10)) + if (Core.AOS && ArmorAttributes.SelfRepair > Utility.Random(10)) { HitPoints += 2; } @@ -717,9 +700,9 @@ namespace Server.Items if (!(newItem is BaseArmor armor)) return; - armor.m_AosAttributes = new AosAttributes(newItem, m_AosAttributes); - armor.m_AosArmorAttributes = new AosArmorAttributes(newItem, m_AosArmorAttributes); - armor.m_AosSkillBonuses = new AosSkillBonuses(newItem, m_AosSkillBonuses); + armor.Attributes = new AosAttributes(newItem, Attributes); + armor.ArmorAttributes = new AosArmorAttributes(newItem, ArmorAttributes); + armor.SkillBonuses = new AosSkillBonuses(newItem, SkillBonuses); } public int ComputeStatReq(StatType type) @@ -821,7 +804,7 @@ namespace Server.Items if (Core.AOS) { - bonus += m_AosArmorAttributes.DurabilityBonus; + bonus += ArmorAttributes.DurabilityBonus; CraftResourceInfo resInfo = CraftResources.GetInfo(m_Resource); CraftAttributeInfo attrInfo = null; @@ -883,7 +866,7 @@ namespace Server.Items if (!Core.AOS) return 0; - int v = m_AosArmorAttributes.LowerStatReq; + int v = ArmorAttributes.LowerStatReq; CraftResourceInfo info = CraftResources.GetInfo(m_Resource); @@ -903,7 +886,7 @@ namespace Server.Items if (parent is Mobile from) { if (Core.AOS) - m_AosSkillBonuses.AddTo(from); + SkillBonuses.AddTo(from); from.Delta(MobileDelta.Armor); // Tell them armor rating has changed } @@ -943,8 +926,8 @@ namespace Server.Items SaveFlag flags = SaveFlag.None; - SetSaveFlag(ref flags, SaveFlag.Attributes, !m_AosAttributes.IsEmpty); - SetSaveFlag(ref flags, SaveFlag.ArmorAttributes, !m_AosArmorAttributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.Attributes, !Attributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.ArmorAttributes, !ArmorAttributes.IsEmpty); SetSaveFlag(ref flags, SaveFlag.PhysicalBonus, m_PhysicalBonus != 0); SetSaveFlag(ref flags, SaveFlag.FireBonus, m_FireBonus != 0); SetSaveFlag(ref flags, SaveFlag.ColdBonus, m_ColdBonus != 0); @@ -966,16 +949,16 @@ namespace Server.Items SetSaveFlag(ref flags, SaveFlag.DexReq, m_DexReq != -1); SetSaveFlag(ref flags, SaveFlag.IntReq, m_IntReq != -1); SetSaveFlag(ref flags, SaveFlag.MedAllowance, m_Meditate != (AMA)(-1)); - SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !m_AosSkillBonuses.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !SkillBonuses.IsEmpty); SetSaveFlag(ref flags, SaveFlag.PlayerConstructed, PlayerConstructed); writer.WriteEncodedInt((int)flags); if (GetSaveFlag(flags, SaveFlag.Attributes)) - m_AosAttributes.Serialize(writer); + Attributes.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.ArmorAttributes)) - m_AosArmorAttributes.Serialize(writer); + ArmorAttributes.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.PhysicalBonus)) writer.WriteEncodedInt(m_PhysicalBonus); @@ -1038,7 +1021,7 @@ namespace Server.Items writer.WriteEncodedInt((int)m_Meditate); if (GetSaveFlag(flags, SaveFlag.SkillBonuses)) - m_AosSkillBonuses.Serialize(writer); + SkillBonuses.Serialize(writer); } public override void Deserialize(GenericReader reader) @@ -1056,14 +1039,14 @@ namespace Server.Items SaveFlag flags = (SaveFlag)reader.ReadEncodedInt(); if (GetSaveFlag(flags, SaveFlag.Attributes)) - m_AosAttributes = new AosAttributes(this, reader); + Attributes = new AosAttributes(this, reader); else - m_AosAttributes = new AosAttributes(this); + Attributes = new AosAttributes(this); if (GetSaveFlag(flags, SaveFlag.ArmorAttributes)) - m_AosArmorAttributes = new AosArmorAttributes(this, reader); + ArmorAttributes = new AosArmorAttributes(this, reader); else - m_AosArmorAttributes = new AosArmorAttributes(this); + ArmorAttributes = new AosArmorAttributes(this); if (GetSaveFlag(flags, SaveFlag.PhysicalBonus)) m_PhysicalBonus = reader.ReadEncodedInt(); @@ -1165,7 +1148,7 @@ namespace Server.Items m_Meditate = (AMA)(-1); if (GetSaveFlag(flags, SaveFlag.SkillBonuses)) - m_AosSkillBonuses = new AosSkillBonuses(this, reader); + SkillBonuses = new AosSkillBonuses(this, reader); if (GetSaveFlag(flags, SaveFlag.PlayerConstructed)) PlayerConstructed = true; @@ -1174,8 +1157,8 @@ namespace Server.Items } case 4: { - m_AosAttributes = new AosAttributes(this, reader); - m_AosArmorAttributes = new AosArmorAttributes(this, reader); + Attributes = new AosAttributes(this, reader); + ArmorAttributes = new AosArmorAttributes(this, reader); goto case 3; } case 3: @@ -1213,8 +1196,8 @@ namespace Server.Items if (version < 4) { - m_AosAttributes = new AosAttributes(this); - m_AosArmorAttributes = new AosArmorAttributes(this); + Attributes = new AosAttributes(this); + ArmorAttributes = new AosArmorAttributes(this); } if (version < 3 && m_Quality == ArmorQuality.Exceptional) @@ -1314,13 +1297,13 @@ namespace Server.Items } } - if (m_AosSkillBonuses == null) - m_AosSkillBonuses = new AosSkillBonuses(this); + if (SkillBonuses == null) + SkillBonuses = new AosSkillBonuses(this); Mobile m = Parent as Mobile; if (Core.AOS && m != null) - m_AosSkillBonuses.AddTo(m); + SkillBonuses.AddTo(m); int strBonus = ComputeStatBonus(StatType.Str); int dexBonus = ComputeStatBonus(StatType.Dex); @@ -1467,7 +1450,7 @@ namespace Server.Items m.RemoveStatMod(modName + "Int"); if (Core.AOS) - m_AosSkillBonuses.Remove(); + SkillBonuses.Remove(); m.Delta(MobileDelta.Armor); // Tell them armor rating has changed m.CheckStatTimers(); @@ -1571,7 +1554,7 @@ namespace Server.Items if (base.AllowEquippedCast(from)) return true; - return m_AosAttributes.SpellChanneling != 0; + return Attributes.SpellChanneling != 0; } public virtual int GetLuckBonus() @@ -1603,92 +1586,92 @@ namespace Server.Items if (RequiredRace == Race.Elf) list.Add(1075086); // Elves Only - m_AosSkillBonuses.GetProperties(list); + SkillBonuses.GetProperties(list); int prop; if ((prop = ArtifactRarity) > 0) list.Add(1061078, prop.ToString()); // artifact rarity ~1_val~ - if ((prop = m_AosAttributes.WeaponDamage) != 0) + if ((prop = Attributes.WeaponDamage) != 0) list.Add(1060401, prop.ToString()); // damage increase ~1_val~% - if ((prop = m_AosAttributes.DefendChance) != 0) + if ((prop = Attributes.DefendChance) != 0) list.Add(1060408, prop.ToString()); // defense chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusDex) != 0) + if ((prop = Attributes.BonusDex) != 0) list.Add(1060409, prop.ToString()); // dexterity bonus ~1_val~ - if ((prop = m_AosAttributes.EnhancePotions) != 0) + if ((prop = Attributes.EnhancePotions) != 0) list.Add(1060411, prop.ToString()); // enhance potions ~1_val~% - if ((prop = m_AosAttributes.CastRecovery) != 0) + if ((prop = Attributes.CastRecovery) != 0) list.Add(1060412, prop.ToString()); // faster cast recovery ~1_val~ - if ((prop = m_AosAttributes.CastSpeed) != 0) + if ((prop = Attributes.CastSpeed) != 0) list.Add(1060413, prop.ToString()); // faster casting ~1_val~ - if ((prop = m_AosAttributes.AttackChance) != 0) + if ((prop = Attributes.AttackChance) != 0) list.Add(1060415, prop.ToString()); // hit chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusHits) != 0) + if ((prop = Attributes.BonusHits) != 0) list.Add(1060431, prop.ToString()); // hit point increase ~1_val~ - if ((prop = m_AosAttributes.BonusInt) != 0) + if ((prop = Attributes.BonusInt) != 0) list.Add(1060432, prop.ToString()); // intelligence bonus ~1_val~ - if ((prop = m_AosAttributes.LowerManaCost) != 0) + if ((prop = Attributes.LowerManaCost) != 0) list.Add(1060433, prop.ToString()); // lower mana cost ~1_val~% - if ((prop = m_AosAttributes.LowerRegCost) != 0) + if ((prop = Attributes.LowerRegCost) != 0) list.Add(1060434, prop.ToString()); // lower reagent cost ~1_val~% if ((prop = GetLowerStatReq()) != 0) list.Add(1060435, prop.ToString()); // lower requirements ~1_val~% - if ((prop = GetLuckBonus() + m_AosAttributes.Luck) != 0) + if ((prop = GetLuckBonus() + Attributes.Luck) != 0) list.Add(1060436, prop.ToString()); // luck ~1_val~ - if ((prop = m_AosArmorAttributes.MageArmor) != 0) + if ((prop = ArmorAttributes.MageArmor) != 0) list.Add(1060437); // mage armor - if ((prop = m_AosAttributes.BonusMana) != 0) + if ((prop = Attributes.BonusMana) != 0) list.Add(1060439, prop.ToString()); // mana increase ~1_val~ - if ((prop = m_AosAttributes.RegenMana) != 0) + if ((prop = Attributes.RegenMana) != 0) list.Add(1060440, prop.ToString()); // mana regeneration ~1_val~ - if ((prop = m_AosAttributes.NightSight) != 0) + if ((prop = Attributes.NightSight) != 0) list.Add(1060441); // night sight - if ((prop = m_AosAttributes.ReflectPhysical) != 0) + if ((prop = Attributes.ReflectPhysical) != 0) list.Add(1060442, prop.ToString()); // reflect physical damage ~1_val~% - if ((prop = m_AosAttributes.RegenStam) != 0) + if ((prop = Attributes.RegenStam) != 0) list.Add(1060443, prop.ToString()); // stamina regeneration ~1_val~ - if ((prop = m_AosAttributes.RegenHits) != 0) + if ((prop = Attributes.RegenHits) != 0) list.Add(1060444, prop.ToString()); // hit point regeneration ~1_val~ - if ((prop = m_AosArmorAttributes.SelfRepair) != 0) + if ((prop = ArmorAttributes.SelfRepair) != 0) list.Add(1060450, prop.ToString()); // self repair ~1_val~ - if ((prop = m_AosAttributes.SpellChanneling) != 0) + if ((prop = Attributes.SpellChanneling) != 0) list.Add(1060482); // spell channeling - if ((prop = m_AosAttributes.SpellDamage) != 0) + if ((prop = Attributes.SpellDamage) != 0) list.Add(1060483, prop.ToString()); // spell damage increase ~1_val~% - if ((prop = m_AosAttributes.BonusStam) != 0) + if ((prop = Attributes.BonusStam) != 0) list.Add(1060484, prop.ToString()); // stamina increase ~1_val~ - if ((prop = m_AosAttributes.BonusStr) != 0) + if ((prop = Attributes.BonusStr) != 0) list.Add(1060485, prop.ToString()); // strength bonus ~1_val~ - if ((prop = m_AosAttributes.WeaponSpeed) != 0) + if ((prop = Attributes.WeaponSpeed) != 0) list.Add(1060486, prop.ToString()); // swing speed increase ~1_val~% - if (Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0) + if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0) list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~% base.AddResistanceProperties(list); diff --git a/Scripts/Items/Armor/Glasses/ElvenGlasses.cs b/Scripts/Items/Armor/Glasses/ElvenGlasses.cs index 80a321fb7..923d0a861 100644 --- a/Scripts/Items/Armor/Glasses/ElvenGlasses.cs +++ b/Scripts/Items/Armor/Glasses/ElvenGlasses.cs @@ -2,13 +2,11 @@ namespace Server.Items { public class ElvenGlasses : BaseArmor { - private AosWeaponAttributes m_AosWeaponAttributes; - [Constructible] public ElvenGlasses() : base(0x2FB8) { Weight = 2; - m_AosWeaponAttributes = new AosWeaponAttributes(this); + WeaponAttributes = new AosWeaponAttributes(this); } public ElvenGlasses(Serial serial) : base(serial) @@ -36,11 +34,7 @@ namespace Server.Items public override ArmorMeditationAllowance DefMedAllowance => ArmorMeditationAllowance.All; [CommandProperty(AccessLevel.GameMaster)] - public AosWeaponAttributes WeaponAttributes - { - get => m_AosWeaponAttributes; - set { } - } + public AosWeaponAttributes WeaponAttributes{ get; private set; } public override void AppendChildNameProperties(ObjectPropertyList list) { @@ -48,49 +42,49 @@ namespace Server.Items int prop; - if ((prop = m_AosWeaponAttributes.HitColdArea) != 0) + if ((prop = WeaponAttributes.HitColdArea) != 0) list.Add(1060416, prop.ToString()); // hit cold area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitDispel) != 0) + if ((prop = WeaponAttributes.HitDispel) != 0) list.Add(1060417, prop.ToString()); // hit dispel ~1_val~% - if ((prop = m_AosWeaponAttributes.HitEnergyArea) != 0) + if ((prop = WeaponAttributes.HitEnergyArea) != 0) list.Add(1060418, prop.ToString()); // hit energy area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitFireArea) != 0) + if ((prop = WeaponAttributes.HitFireArea) != 0) list.Add(1060419, prop.ToString()); // hit fire area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitFireball) != 0) + if ((prop = WeaponAttributes.HitFireball) != 0) list.Add(1060420, prop.ToString()); // hit fireball ~1_val~% - if ((prop = m_AosWeaponAttributes.HitHarm) != 0) + if ((prop = WeaponAttributes.HitHarm) != 0) list.Add(1060421, prop.ToString()); // hit harm ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLeechHits) != 0) + if ((prop = WeaponAttributes.HitLeechHits) != 0) list.Add(1060422, prop.ToString()); // hit life leech ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLightning) != 0) + if ((prop = WeaponAttributes.HitLightning) != 0) list.Add(1060423, prop.ToString()); // hit lightning ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLowerAttack) != 0) + if ((prop = WeaponAttributes.HitLowerAttack) != 0) list.Add(1060424, prop.ToString()); // hit lower attack ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLowerDefend) != 0) + if ((prop = WeaponAttributes.HitLowerDefend) != 0) list.Add(1060425, prop.ToString()); // hit lower defense ~1_val~% - if ((prop = m_AosWeaponAttributes.HitMagicArrow) != 0) + if ((prop = WeaponAttributes.HitMagicArrow) != 0) list.Add(1060426, prop.ToString()); // hit magic arrow ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLeechMana) != 0) + if ((prop = WeaponAttributes.HitLeechMana) != 0) list.Add(1060427, prop.ToString()); // hit mana leech ~1_val~% - if ((prop = m_AosWeaponAttributes.HitPhysicalArea) != 0) + if ((prop = WeaponAttributes.HitPhysicalArea) != 0) list.Add(1060428, prop.ToString()); // hit physical area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitPoisonArea) != 0) + if ((prop = WeaponAttributes.HitPoisonArea) != 0) list.Add(1060429, prop.ToString()); // hit poison area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLeechStam) != 0) + if ((prop = WeaponAttributes.HitLeechStam) != 0) list.Add(1060430, prop.ToString()); // hit stamina leech ~1_val~% } @@ -113,12 +107,12 @@ namespace Server.Items SaveFlag flags = SaveFlag.None; - SetSaveFlag(ref flags, SaveFlag.WeaponAttributes, !m_AosWeaponAttributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.WeaponAttributes, !WeaponAttributes.IsEmpty); writer.Write((int)flags); if (GetSaveFlag(flags, SaveFlag.WeaponAttributes)) - m_AosWeaponAttributes.Serialize(writer); + WeaponAttributes.Serialize(writer); } public override void Deserialize(GenericReader reader) @@ -130,9 +124,9 @@ namespace Server.Items SaveFlag flags = (SaveFlag)reader.ReadInt(); if (GetSaveFlag(flags, SaveFlag.WeaponAttributes)) - m_AosWeaponAttributes = new AosWeaponAttributes(this, reader); + WeaponAttributes = new AosWeaponAttributes(this, reader); else - m_AosWeaponAttributes = new AosWeaponAttributes(this); + WeaponAttributes = new AosWeaponAttributes(this); } private enum SaveFlag diff --git a/Scripts/Items/Books/BaseBook.cs b/Scripts/Items/Books/BaseBook.cs index 2bc618875..29563da15 100644 --- a/Scripts/Items/Books/BaseBook.cs +++ b/Scripts/Items/Books/BaseBook.cs @@ -347,7 +347,7 @@ namespace Server.Items { Mobile from = state.Mobile; - if (!(World.FindItem(pvSrc.ReadInt32()) is BaseBook book) || !book.Writable || + if (!(World.FindItem(pvSrc.ReadUInt32()) is BaseBook book) || !book.Writable || !from.InRange(book.GetWorldLocation(), 1) || !book.IsAccessibleTo(from)) return; @@ -364,7 +364,7 @@ namespace Server.Items { Mobile from = state.Mobile; - if (!(World.FindItem(pvSrc.ReadInt32()) is BaseBook book) || !book.Writable || + if (!(World.FindItem(pvSrc.ReadUInt32()) is BaseBook book) || !book.Writable || !from.InRange(book.GetWorldLocation(), 1) || !book.IsAccessibleTo(from)) return; @@ -392,7 +392,7 @@ namespace Server.Items { Mobile from = state.Mobile; - if (!(World.FindItem(pvSrc.ReadInt32()) is BaseBook book) || !book.Writable || + if (!(World.FindItem(pvSrc.ReadUInt32()) is BaseBook book) || !book.Writable || !from.InRange(book.GetWorldLocation(), 1) || !book.IsAccessibleTo(from)) return; diff --git a/Scripts/Items/Clothing/BaseClothing.cs b/Scripts/Items/Clothing/BaseClothing.cs index eecc9df01..e0958c126 100644 --- a/Scripts/Items/Clothing/BaseClothing.cs +++ b/Scripts/Items/Clothing/BaseClothing.cs @@ -23,10 +23,6 @@ namespace Server.Items public abstract class BaseClothing : Item, IDyable, IScissorable, IFactionItem, ICraftable, IWearableDurability { - private AosAttributes m_AosAttributes; - private AosArmorAttributes m_AosClothingAttributes; - private AosElementAttributes m_AosResistances; - private AosSkillBonuses m_AosSkillBonuses; private Mobile m_Crafter; private int m_HitPoints; @@ -49,10 +45,10 @@ namespace Server.Items m_HitPoints = m_MaxHitPoints = Utility.RandomMinMax(InitMinHits, InitMaxHits); - m_AosAttributes = new AosAttributes(this); - m_AosClothingAttributes = new AosArmorAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); - m_AosResistances = new AosElementAttributes(this); + Attributes = new AosAttributes(this); + ClothingAttributes = new AosArmorAttributes(this); + SkillBonuses = new AosSkillBonuses(this); + Resistances = new AosElementAttributes(this); } public BaseClothing(Serial serial) : base(serial) @@ -110,32 +106,16 @@ namespace Server.Items } [CommandProperty(AccessLevel.GameMaster)] - public AosAttributes Attributes - { - get => m_AosAttributes; - set { } - } + public AosAttributes Attributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosArmorAttributes ClothingAttributes - { - get => m_AosClothingAttributes; - set { } - } + public AosArmorAttributes ClothingAttributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosSkillBonuses SkillBonuses - { - get => m_AosSkillBonuses; - set { } - } + public AosSkillBonuses SkillBonuses{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosElementAttributes Resistances - { - get => m_AosResistances; - set { } - } + public AosElementAttributes Resistances{ get; private set; } public virtual int BasePhysicalResistance => 0; public virtual int BaseFireResistance => 0; @@ -143,11 +123,11 @@ namespace Server.Items public virtual int BasePoisonResistance => 0; public virtual int BaseEnergyResistance => 0; - public override int PhysicalResistance => BasePhysicalResistance + m_AosResistances.Physical; - public override int FireResistance => BaseFireResistance + m_AosResistances.Fire; - public override int ColdResistance => BaseColdResistance + m_AosResistances.Cold; - public override int PoisonResistance => BasePoisonResistance + m_AosResistances.Poison; - public override int EnergyResistance => BaseEnergyResistance + m_AosResistances.Energy; + public override int PhysicalResistance => BasePhysicalResistance + Resistances.Physical; + public override int FireResistance => BaseFireResistance + Resistances.Fire; + public override int ColdResistance => BaseColdResistance + Resistances.Cold; + public override int PoisonResistance => BasePoisonResistance + Resistances.Poison; + public override int EnergyResistance => BaseEnergyResistance + Resistances.Energy; public virtual int ArtifactRarity => 0; @@ -253,6 +233,7 @@ namespace Server.Items } catch { + // ignored } from.SendLocalizedMessage(502440); // Scissors can not be used on that to produce anything. @@ -306,7 +287,7 @@ namespace Server.Items if (25 > Utility.Random(100)) // 25% chance to lower durability { - if (Core.AOS && m_AosClothingAttributes.SelfRepair > Utility.Random(10)) + if (Core.AOS && ClothingAttributes.SelfRepair > Utility.Random(10)) { HitPoints += 2; } @@ -355,7 +336,7 @@ namespace Server.Items public void UnscaleDurability() { - int scale = 100 + m_AosClothingAttributes.DurabilityBonus; + int scale = 100 + ClothingAttributes.DurabilityBonus; m_HitPoints = (m_HitPoints * 100 + (scale - 1)) / scale; m_MaxHitPoints = (m_MaxHitPoints * 100 + (scale - 1)) / scale; @@ -365,7 +346,7 @@ namespace Server.Items public void ScaleDurability() { - int scale = 100 + m_AosClothingAttributes.DurabilityBonus; + int scale = 100 + ClothingAttributes.DurabilityBonus; m_HitPoints = (m_HitPoints * scale + 99) / 100; m_MaxHitPoints = (m_MaxHitPoints * scale + 99) / 100; @@ -521,7 +502,7 @@ namespace Server.Items if (!Core.AOS) return 0; - return m_AosClothingAttributes.LowerStatReq; + return ClothingAttributes.LowerStatReq; } public override void OnAdded(IEntity parent) @@ -529,7 +510,7 @@ namespace Server.Items if (parent is Mobile mob) { if (Core.AOS) - m_AosSkillBonuses.AddTo(mob); + SkillBonuses.AddTo(mob); AddStatBonuses(mob); mob.CheckStatTimers(); @@ -543,7 +524,7 @@ namespace Server.Items if (parent is Mobile mob) { if (Core.AOS) - m_AosSkillBonuses.Remove(); + SkillBonuses.Remove(); string modName = Serial.ToString(); @@ -562,10 +543,10 @@ namespace Server.Items if (!(newItem is BaseClothing clothing)) return; - clothing.m_AosAttributes = new AosAttributes(newItem, m_AosAttributes); - clothing.m_AosResistances = new AosElementAttributes(newItem, m_AosResistances); - clothing.m_AosSkillBonuses = new AosSkillBonuses(newItem, m_AosSkillBonuses); - clothing.m_AosClothingAttributes = new AosArmorAttributes(newItem, m_AosClothingAttributes); + clothing.Attributes = new AosAttributes(newItem, Attributes); + clothing.Resistances = new AosElementAttributes(newItem, Resistances); + clothing.SkillBonuses = new AosSkillBonuses(newItem, SkillBonuses); + clothing.ClothingAttributes = new AosArmorAttributes(newItem, ClothingAttributes); } public override bool AllowEquippedCast(Mobile from) @@ -573,7 +554,7 @@ namespace Server.Items if (base.AllowEquippedCast(from)) return true; - return m_AosAttributes.SpellChanneling != 0; + return Attributes.SpellChanneling != 0; } public override bool CheckPropertyConfliction(Mobile m) @@ -690,97 +671,97 @@ namespace Server.Items if (RequiredRace == Race.Elf) list.Add(1075086); // Elves Only - m_AosSkillBonuses?.GetProperties(list); + SkillBonuses?.GetProperties(list); int prop; if ((prop = ArtifactRarity) > 0) list.Add(1061078, prop.ToString()); // artifact rarity ~1_val~ - if ((prop = m_AosAttributes.WeaponDamage) != 0) + if ((prop = Attributes.WeaponDamage) != 0) list.Add(1060401, prop.ToString()); // damage increase ~1_val~% - if ((prop = m_AosAttributes.DefendChance) != 0) + if ((prop = Attributes.DefendChance) != 0) list.Add(1060408, prop.ToString()); // defense chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusDex) != 0) + if ((prop = Attributes.BonusDex) != 0) list.Add(1060409, prop.ToString()); // dexterity bonus ~1_val~ - if ((prop = m_AosAttributes.EnhancePotions) != 0) + if ((prop = Attributes.EnhancePotions) != 0) list.Add(1060411, prop.ToString()); // enhance potions ~1_val~% - if ((prop = m_AosAttributes.CastRecovery) != 0) + if ((prop = Attributes.CastRecovery) != 0) list.Add(1060412, prop.ToString()); // faster cast recovery ~1_val~ - if ((prop = m_AosAttributes.CastSpeed) != 0) + if ((prop = Attributes.CastSpeed) != 0) list.Add(1060413, prop.ToString()); // faster casting ~1_val~ - if ((prop = m_AosAttributes.AttackChance) != 0) + if ((prop = Attributes.AttackChance) != 0) list.Add(1060415, prop.ToString()); // hit chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusHits) != 0) + if ((prop = Attributes.BonusHits) != 0) list.Add(1060431, prop.ToString()); // hit point increase ~1_val~ - if ((prop = m_AosAttributes.BonusInt) != 0) + if ((prop = Attributes.BonusInt) != 0) list.Add(1060432, prop.ToString()); // intelligence bonus ~1_val~ - if ((prop = m_AosAttributes.LowerManaCost) != 0) + if ((prop = Attributes.LowerManaCost) != 0) list.Add(1060433, prop.ToString()); // lower mana cost ~1_val~% - if ((prop = m_AosAttributes.LowerRegCost) != 0) + if ((prop = Attributes.LowerRegCost) != 0) list.Add(1060434, prop.ToString()); // lower reagent cost ~1_val~% - if ((prop = m_AosClothingAttributes.LowerStatReq) != 0) + if ((prop = ClothingAttributes.LowerStatReq) != 0) list.Add(1060435, prop.ToString()); // lower requirements ~1_val~% - if ((prop = m_AosAttributes.Luck) != 0) + if ((prop = Attributes.Luck) != 0) list.Add(1060436, prop.ToString()); // luck ~1_val~ - if ((prop = m_AosClothingAttributes.MageArmor) != 0) + if ((prop = ClothingAttributes.MageArmor) != 0) list.Add(1060437); // mage armor - if ((prop = m_AosAttributes.BonusMana) != 0) + if ((prop = Attributes.BonusMana) != 0) list.Add(1060439, prop.ToString()); // mana increase ~1_val~ - if ((prop = m_AosAttributes.RegenMana) != 0) + if ((prop = Attributes.RegenMana) != 0) list.Add(1060440, prop.ToString()); // mana regeneration ~1_val~ - if ((prop = m_AosAttributes.NightSight) != 0) + if ((prop = Attributes.NightSight) != 0) list.Add(1060441); // night sight - if ((prop = m_AosAttributes.ReflectPhysical) != 0) + if ((prop = Attributes.ReflectPhysical) != 0) list.Add(1060442, prop.ToString()); // reflect physical damage ~1_val~% - if ((prop = m_AosAttributes.RegenStam) != 0) + if ((prop = Attributes.RegenStam) != 0) list.Add(1060443, prop.ToString()); // stamina regeneration ~1_val~ - if ((prop = m_AosAttributes.RegenHits) != 0) + if ((prop = Attributes.RegenHits) != 0) list.Add(1060444, prop.ToString()); // hit point regeneration ~1_val~ - if ((prop = m_AosClothingAttributes.SelfRepair) != 0) + if ((prop = ClothingAttributes.SelfRepair) != 0) list.Add(1060450, prop.ToString()); // self repair ~1_val~ - if ((prop = m_AosAttributes.SpellChanneling) != 0) + if ((prop = Attributes.SpellChanneling) != 0) list.Add(1060482); // spell channeling - if ((prop = m_AosAttributes.SpellDamage) != 0) + if ((prop = Attributes.SpellDamage) != 0) list.Add(1060483, prop.ToString()); // spell damage increase ~1_val~% - if ((prop = m_AosAttributes.BonusStam) != 0) + if ((prop = Attributes.BonusStam) != 0) list.Add(1060484, prop.ToString()); // stamina increase ~1_val~ - if ((prop = m_AosAttributes.BonusStr) != 0) + if ((prop = Attributes.BonusStr) != 0) list.Add(1060485, prop.ToString()); // strength bonus ~1_val~ - if ((prop = m_AosAttributes.WeaponSpeed) != 0) + if ((prop = Attributes.WeaponSpeed) != 0) list.Add(1060486, prop.ToString()); // swing speed increase ~1_val~% - if (Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0) + if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0) list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~% base.AddResistanceProperties(list); - if ((prop = m_AosClothingAttributes.DurabilityBonus) > 0) + if ((prop = ClothingAttributes.DurabilityBonus) > 0) list.Add(1060410, prop.ToString()); // durability ~1_val~% if ((prop = ComputeStatReq(StatType.Str)) > 0) @@ -843,19 +824,19 @@ namespace Server.Items switch (Utility.Random(5)) { case 0: - ++m_AosResistances.Physical; + ++Resistances.Physical; break; case 1: - ++m_AosResistances.Fire; + ++Resistances.Fire; break; case 2: - ++m_AosResistances.Cold; + ++Resistances.Cold; break; case 3: - ++m_AosResistances.Poison; + ++Resistances.Poison; break; case 4: - ++m_AosResistances.Energy; + ++Resistances.Energy; break; } @@ -921,10 +902,10 @@ namespace Server.Items SaveFlag flags = SaveFlag.None; SetSaveFlag(ref flags, SaveFlag.Resource, m_Resource != DefaultResource); - SetSaveFlag(ref flags, SaveFlag.Attributes, !m_AosAttributes.IsEmpty); - SetSaveFlag(ref flags, SaveFlag.ClothingAttributes, !m_AosClothingAttributes.IsEmpty); - SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !m_AosSkillBonuses.IsEmpty); - SetSaveFlag(ref flags, SaveFlag.Resistances, !m_AosResistances.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.Attributes, !Attributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.ClothingAttributes, !ClothingAttributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !SkillBonuses.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.Resistances, !Resistances.IsEmpty); SetSaveFlag(ref flags, SaveFlag.MaxHitPoints, m_MaxHitPoints != 0); SetSaveFlag(ref flags, SaveFlag.HitPoints, m_HitPoints != 0); SetSaveFlag(ref flags, SaveFlag.PlayerConstructed, PlayerConstructed); @@ -938,16 +919,16 @@ namespace Server.Items writer.WriteEncodedInt((int)m_Resource); if (GetSaveFlag(flags, SaveFlag.Attributes)) - m_AosAttributes.Serialize(writer); + Attributes.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.ClothingAttributes)) - m_AosClothingAttributes.Serialize(writer); + ClothingAttributes.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.SkillBonuses)) - m_AosSkillBonuses.Serialize(writer); + SkillBonuses.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.Resistances)) - m_AosResistances.Serialize(writer); + Resistances.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.MaxHitPoints)) writer.WriteEncodedInt(m_MaxHitPoints); @@ -983,24 +964,24 @@ namespace Server.Items m_Resource = DefaultResource; if (GetSaveFlag(flags, SaveFlag.Attributes)) - m_AosAttributes = new AosAttributes(this, reader); + Attributes = new AosAttributes(this, reader); else - m_AosAttributes = new AosAttributes(this); + Attributes = new AosAttributes(this); if (GetSaveFlag(flags, SaveFlag.ClothingAttributes)) - m_AosClothingAttributes = new AosArmorAttributes(this, reader); + ClothingAttributes = new AosArmorAttributes(this, reader); else - m_AosClothingAttributes = new AosArmorAttributes(this); + ClothingAttributes = new AosArmorAttributes(this); if (GetSaveFlag(flags, SaveFlag.SkillBonuses)) - m_AosSkillBonuses = new AosSkillBonuses(this, reader); + SkillBonuses = new AosSkillBonuses(this, reader); else - m_AosSkillBonuses = new AosSkillBonuses(this); + SkillBonuses = new AosSkillBonuses(this); if (GetSaveFlag(flags, SaveFlag.Resistances)) - m_AosResistances = new AosElementAttributes(this, reader); + Resistances = new AosElementAttributes(this, reader); else - m_AosResistances = new AosElementAttributes(this); + Resistances = new AosElementAttributes(this); if (GetSaveFlag(flags, SaveFlag.MaxHitPoints)) m_MaxHitPoints = reader.ReadEncodedInt(); @@ -1034,10 +1015,10 @@ namespace Server.Items } case 3: { - m_AosAttributes = new AosAttributes(this, reader); - m_AosClothingAttributes = new AosArmorAttributes(this, reader); - m_AosSkillBonuses = new AosSkillBonuses(this, reader); - m_AosResistances = new AosElementAttributes(this, reader); + Attributes = new AosAttributes(this, reader); + ClothingAttributes = new AosArmorAttributes(this, reader); + SkillBonuses = new AosSkillBonuses(this, reader); + Resistances = new AosElementAttributes(this, reader); goto case 2; } @@ -1065,10 +1046,10 @@ namespace Server.Items if (version < 3) { - m_AosAttributes = new AosAttributes(this); - m_AosClothingAttributes = new AosArmorAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); - m_AosResistances = new AosElementAttributes(this); + Attributes = new AosAttributes(this); + ClothingAttributes = new AosArmorAttributes(this); + SkillBonuses = new AosSkillBonuses(this); + Resistances = new AosElementAttributes(this); } if (version < 4) @@ -1080,7 +1061,7 @@ namespace Server.Items if (Parent is Mobile parent) { if (Core.AOS) - m_AosSkillBonuses.AddTo(parent); + SkillBonuses.AddTo(parent); AddStatBonuses(parent); parent.CheckStatTimers(); diff --git a/Scripts/Items/Construction/Ankhs.cs b/Scripts/Items/Construction/Ankhs.cs index 11593d4bc..a5d0d1df2 100644 --- a/Scripts/Items/Construction/Ankhs.cs +++ b/Scripts/Items/Construction/Ankhs.cs @@ -33,7 +33,7 @@ namespace Server.Items } else if (m.Map != null && m.Map.CanFit(m.Location, 16, false, false)) { - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, ResurrectMessage.VirtueShrine)); } else diff --git a/Scripts/Items/Construction/Doors/BaseDoor.cs b/Scripts/Items/Construction/Doors/BaseDoor.cs index 5781c1c80..b86749317 100644 --- a/Scripts/Items/Construction/Doors/BaseDoor.cs +++ b/Scripts/Items/Construction/Doors/BaseDoor.cs @@ -144,18 +144,16 @@ namespace Server.Items } else { - from.BeginTarget(-1, false, TargetFlags.None, new TargetStateCallback(Link_OnSecondTarget), door); + from.BeginTarget(-1, false, TargetFlags.None, Link_OnSecondTarget, door); from.SendMessage("Target the second door to link."); } } - private static void Link_OnSecondTarget(Mobile from, object targeted, object state) + private static void Link_OnSecondTarget(Mobile from, object targeted, BaseDoor first) { - BaseDoor first = (BaseDoor)state; - if (!(targeted is BaseDoor second)) { - from.BeginTarget(-1, false, TargetFlags.None, new TargetStateCallback(Link_OnSecondTarget), first); + from.BeginTarget(-1, false, TargetFlags.None, Link_OnSecondTarget, first); from.SendMessage("That is not a door. Try again."); } else @@ -170,22 +168,19 @@ namespace Server.Items [Description("Chain-links two or more targeted doors together.")] private static void ChainLink_OnCommand(CommandEventArgs e) { - e.Mobile.BeginTarget(-1, false, TargetFlags.None, new TargetStateCallback(ChainLink_OnTarget), - new List()); + e.Mobile.BeginTarget(-1, false, TargetFlags.None, ChainLink_OnTarget, new List()); e.Mobile.SendMessage("Target the first of a sequence of doors to link."); } - private static void ChainLink_OnTarget(Mobile from, object targeted, object state) + private static void ChainLink_OnTarget(Mobile from, object targeted, List list) { if (!(targeted is BaseDoor door)) { - from.BeginTarget(-1, false, TargetFlags.None, new TargetStateCallback(ChainLink_OnTarget), state); + from.BeginTarget(-1, false, TargetFlags.None, ChainLink_OnTarget, list); from.SendMessage("That is not a door. Try again."); } else { - List list = (List)state; - if (list.Count > 0 && list[0] == door) { if (list.Count >= 2) @@ -197,13 +192,13 @@ namespace Server.Items } else { - from.BeginTarget(-1, false, TargetFlags.None, new TargetStateCallback(ChainLink_OnTarget), state); + from.BeginTarget(-1, false, TargetFlags.None, ChainLink_OnTarget, list); from.SendMessage("You have not yet targeted two unique doors. Target the second door to link."); } } else if (list.Contains(door)) { - from.BeginTarget(-1, false, TargetFlags.None, new TargetStateCallback(ChainLink_OnTarget), state); + from.BeginTarget(-1, false, TargetFlags.None, ChainLink_OnTarget, list); from.SendMessage( "You have already targeted that door. Target another door, or retarget the first door to complete the chain."); } @@ -211,7 +206,7 @@ namespace Server.Items { list.Add(door); - from.BeginTarget(-1, false, TargetFlags.None, new TargetStateCallback(ChainLink_OnTarget), state); + from.BeginTarget(-1, false, TargetFlags.None, ChainLink_OnTarget, list); if (list.Count == 1) from.SendMessage("Target the second door to link."); diff --git a/Scripts/Items/Containers/FillableContainers.cs b/Scripts/Items/Containers/FillableContainers.cs index b288c3065..599f79ca8 100644 --- a/Scripts/Items/Containers/FillableContainers.cs +++ b/Scripts/Items/Containers/FillableContainers.cs @@ -199,7 +199,7 @@ namespace Server.Items if (item == null) continue; - + List list = Items; for (int j = 0; j < list.Count; ++j) @@ -1430,7 +1430,7 @@ namespace Server.Items new FillableEntry(1, typeof(Arrow)) }); - private static Hashtable m_AcquireTable; + private static Dictionary m_AcquireTable; private static FillableContent[] m_ContentTypes = { @@ -1509,7 +1509,7 @@ namespace Server.Items if (m_AcquireTable == null) { - m_AcquireTable = new Hashtable(); + m_AcquireTable = new Dictionary(); for (int i = 0; i < m_ContentTypes.Length; ++i) { @@ -1539,4 +1539,4 @@ namespace Server.Items return content; } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Containers/LockableContainer.cs b/Scripts/Items/Containers/LockableContainer.cs index f1f3bbd5a..0212a6716 100644 --- a/Scripts/Items/Containers/LockableContainer.cs +++ b/Scripts/Items/Containers/LockableContainer.cs @@ -38,7 +38,7 @@ namespace Server.Items KeyValue = key.KeyValue; DropItem(key); - double tinkering = from.Skills[SkillName.Tinkering].Value; + double tinkering = from.Skills.Tinkering.Value; int level = (int)(tinkering * 0.8); RequiredSkill = level - 4; diff --git a/Scripts/Items/Containers/SalvageBag.cs b/Scripts/Items/Containers/SalvageBag.cs index 4be389398..aea19b987 100644 --- a/Scripts/Items/Containers/SalvageBag.cs +++ b/Scripts/Items/Containers/SalvageBag.cs @@ -100,7 +100,7 @@ namespace Server.Items item is BaseWeapon weapon && weapon.PlayerConstructed || item is BaseClothing clothing && clothing.PlayerConstructed) { - double mining = from.Skills[SkillName.Mining].Value; + double mining = from.Skills.Mining.Value; if (mining > 100.0) mining = 100.0; double amount = ((4 + mining) * craftResource.Amount - 4) * 0.0068; @@ -114,7 +114,7 @@ namespace Server.Items ingot.Amount = 2; } - if (difficulty > from.Skills[SkillName.Mining].Value) + if (difficulty > from.Skills.Mining.Value) { m_Failure = true; ingot.Delete(); diff --git a/Scripts/Items/Containers/TreasureMapChest.cs b/Scripts/Items/Containers/TreasureMapChest.cs index 402979173..33d26b29a 100644 --- a/Scripts/Items/Containers/TreasureMapChest.cs +++ b/Scripts/Items/Containers/TreasureMapChest.cs @@ -488,7 +488,7 @@ namespace Server.Items if (!from.Alive) return; - from.CloseGump(typeof(RemoveGump)); + from.CloseGump(); from.SendGump(new RemoveGump(from, this)); } diff --git a/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs b/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs index 59f56a06f..f114f68c3 100644 --- a/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs +++ b/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Commands; namespace Server.Items @@ -10,16 +11,17 @@ namespace Server.Items private StealableInstance[] m_Artifacts; private Timer m_RespawnTimer; - private Hashtable m_Table; + private Dictionary m_Table; private StealableArtifactsSpawner() : base(1) { Movable = false; m_Artifacts = new StealableInstance[Entries.Length]; - m_Table = new Hashtable(Entries.Length); + m_Table = new Dictionary(Entries.Length); - for (int i = 0; i < Entries.Length; i++) m_Artifacts[i] = new StealableInstance(Entries[i]); + for (int i = 0; i < Entries.Length; i++) + m_Artifacts[i] = new StealableInstance(Entries[i]); m_RespawnTimer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromMinutes(15.0), CheckRespawn); } @@ -264,7 +266,7 @@ namespace Server.Items int version = reader.ReadEncodedInt(); m_Artifacts = new StealableInstance[Entries.Length]; - m_Table = new Hashtable(Entries.Length); + m_Table = new Dictionary(Entries.Length); int length = reader.ReadEncodedInt(); @@ -290,12 +292,7 @@ namespace Server.Items public class StealableEntry { - public StealableEntry(Map map, Point3D location, int minDelay, int maxDelay, Type type) : this(map, location, - minDelay, maxDelay, type, 0) - { - } - - public StealableEntry(Map map, Point3D location, int minDelay, int maxDelay, Type type, int hue) + public StealableEntry(Map map, Point3D location, int minDelay, int maxDelay, Type type, int hue = 0) { Map = map; Location = location; @@ -384,4 +381,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Deeds/BarkeepContract.cs b/Scripts/Items/Deeds/BarkeepContract.cs index f50059af0..afd9c239f 100644 --- a/Scripts/Items/Deeds/BarkeepContract.cs +++ b/Scripts/Items/Deeds/BarkeepContract.cs @@ -66,8 +66,7 @@ namespace Server.Items } else { - bool vendor, contract; - BaseHouse.IsThereVendor(from.Location, from.Map, out vendor, out contract); + BaseHouse.IsThereVendor(from.Location, from.Map, out bool vendor, out bool contract); if (vendor) { diff --git a/Scripts/Items/Deeds/HairRestylingDeed.cs b/Scripts/Items/Deeds/HairRestylingDeed.cs index c1359e2cb..8bddc8238 100644 --- a/Scripts/Items/Deeds/HairRestylingDeed.cs +++ b/Scripts/Items/Deeds/HairRestylingDeed.cs @@ -100,7 +100,7 @@ namespace Server.Items m_From = from; m_Deed = deed; - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); AddBackground(100, 10, 400, 385, 0xA28); diff --git a/Scripts/Items/Deeds/HolidayTreeDeed.cs b/Scripts/Items/Deeds/HolidayTreeDeed.cs index 46a255f80..efe1970ab 100644 --- a/Scripts/Items/Deeds/HolidayTreeDeed.cs +++ b/Scripts/Items/Deeds/HolidayTreeDeed.cs @@ -80,10 +80,10 @@ namespace Server.Items public void BeginPlace(Mobile from, HolidayTreeType type) { - from.BeginTarget(-1, true, TargetFlags.None, new TargetStateCallback(Placement_OnTarget), type); + from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget, type); } - public void Placement_OnTarget(Mobile from, object targeted, object state) + public void Placement_OnTarget(Mobile from, object targeted, HolidayTreeType type) { if (!(targeted is IPoint3D p)) return; @@ -98,7 +98,7 @@ namespace Server.Items */ if (ValidatePlacement(from, loc)) - EndPlace(from, (HolidayTreeType)state, loc); + EndPlace(from, type, loc); } public void EndPlace(Mobile from, HolidayTreeType type, Point3D loc) @@ -110,7 +110,7 @@ namespace Server.Items public override void OnDoubleClick(Mobile from) { - from.CloseGump(typeof(HolidayTreeChoiceGump)); + from.CloseGump(); from.SendGump(new HolidayTreeChoiceGump(from, this)); } } diff --git a/Scripts/Items/Deeds/NameChangeDeed.cs b/Scripts/Items/Deeds/NameChangeDeed.cs index 8dee3b2bb..b37842fa9 100644 --- a/Scripts/Items/Deeds/NameChangeDeed.cs +++ b/Scripts/Items/Deeds/NameChangeDeed.cs @@ -36,7 +36,7 @@ namespace Server.Items { if (RootParent == from) { - from.CloseGump(typeof(NameChangeDeedGump)); + from.CloseGump(); from.SendGump(new NameChangeDeedGump(this)); } else @@ -55,7 +55,7 @@ namespace Server.Items m_Sender = sender; Closable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Deeds/VendorRentalContract.cs b/Scripts/Items/Deeds/VendorRentalContract.cs index 6dac4f299..426a0e5ca 100644 --- a/Scripts/Items/Deeds/VendorRentalContract.cs +++ b/Scripts/Items/Deeds/VendorRentalContract.cs @@ -176,7 +176,7 @@ namespace Server.Items { if (from.InRange(this, 5)) { - from.CloseGump(typeof(VendorRentalContractGump)); + from.CloseGump(); from.SendGump(new VendorRentalContractGump(this, from)); } else @@ -236,7 +236,7 @@ namespace Server.Items if (m_Contract.IsUsableBy(from, true, true, true, true)) { - from.CloseGump(typeof(VendorRentalContractGump)); + from.CloseGump(); from.SendGump(new VendorRentalContractGump(m_Contract, from)); } } @@ -339,7 +339,7 @@ namespace Server.Items if (offeree != null) { - offeree.CloseGump(typeof(VendorRentalOfferGump)); + offeree.CloseGump(); m_Contract.Offeree = null; } diff --git a/Scripts/Items/Facial/Beard.cs b/Scripts/Items/Facial/Beard.cs index 55f805476..443ea43f5 100644 --- a/Scripts/Items/Facial/Beard.cs +++ b/Scripts/Items/Facial/Beard.cs @@ -1,270 +1,14 @@ namespace Server.Items { - public abstract class Beard : Item + public static class Beard { - /*public static Beard CreateByID( int id, int hue ) - { - switch ( id ) - { - case 0x203E: return new LongBeard( hue ); - case 0x203F: return new ShortBeard( hue ); - case 0x2040: return new Goatee( hue ); - case 0x2041: return new Mustache( hue ); - case 0x204B: return new MediumShortBeard( hue ); - case 0x204C: return new MediumLongBeard( hue ); - case 0x204D: return new Vandyke( hue ); - default: return new GenericBeard( id, hue ); - } - }*/ - - protected Beard(int itemID, int hue = 0) : base(itemID) - { - LootType = LootType.Blessed; - Layer = Layer.FacialHair; - Hue = hue; - } - - public Beard(Serial serial) : base(serial) - { - } - - public override bool DisplayLootType => false; - - public override bool VerifyMove(Mobile from) - { - return from.AccessLevel >= AccessLevel.GameMaster; - } - - public override DeathMoveResult OnParentDeath(Mobile parent) - { - //Dupe( Amount ); - - parent.FacialHairItemID = ItemID; - parent.FacialHairHue = Hue; - - return DeathMoveResult.MoveToCorpse; - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - LootType = LootType.Blessed; - - int version = reader.ReadInt(); - } - } - - public class GenericBeard : Beard - { - private GenericBeard(int itemID, int hue = 0) : base(itemID, hue) - { - } - - public GenericBeard(Serial serial) : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class LongBeard : Beard - { - private LongBeard(int hue = 0) - : base(0x203E, hue) - { - } - - public LongBeard(Serial serial) : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class ShortBeard : Beard - { - private ShortBeard(int hue = 0) - : base(0x203f, hue) - { - } - - public ShortBeard(Serial serial) : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class Goatee : Beard - { - private Goatee(int hue = 0) - : base(0x2040, hue) - { - } - - public Goatee(Serial serial) : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class Mustache : Beard - { - private Mustache(int hue = 0) - : base(0x2041, hue) - { - } - - public Mustache(Serial serial) : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class MediumShortBeard : Beard - { - private MediumShortBeard(int hue = 0) - : base(0x204B, hue) - { - } - - public MediumShortBeard(Serial serial) : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class MediumLongBeard : Beard - { - private MediumLongBeard(int hue = 0) - : base(0x204C, hue) - { - } - - public MediumLongBeard(Serial serial) : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class Vandyke : Beard - { - private Vandyke(int hue = 0) - : base(0x204D, hue) - { - } - - public Vandyke(Serial serial) : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } + public static int LongBeard = 0x203E; + public static int ShortBeard = 0x203f; + public static int Goatee = 0x2040; + public static int Mustache = 0x2041; + + public static int MediumShortBeard = 0x204B; + public static int MediumLongBeard = 0x204C; + public static int Vandyke = 0x204D; } } \ No newline at end of file diff --git a/Scripts/Items/Facial/Hair.cs b/Scripts/Items/Facial/Hair.cs index a78da945b..e5e1e1349 100644 --- a/Scripts/Items/Facial/Hair.cs +++ b/Scripts/Items/Facial/Hair.cs @@ -1,407 +1,31 @@ namespace Server.Items { - public abstract class Hair : Item + public static class Hair { - /* - - public static Hair GetRandomHair( bool female ) - { - return GetRandomHair( female, Utility.RandomHairHue() ); - } - - public static Hair GetRandomHair( bool female, int hairHue ) - { - if ( female ) - { - switch ( Utility.Random( 9 ) ) - { - case 0: return new Afro( hairHue ); - case 1: return new KrisnaHair( hairHue ); - case 2: return new PageboyHair( hairHue ); - case 3: return new PonyTail( hairHue ); - case 4: return new ReceedingHair( hairHue ); - case 5: return new TwoPigTails( hairHue ); - case 6: return new ShortHair( hairHue ); - case 7: return new LongHair( hairHue ); - default: return new BunsHair( hairHue ); - } - } - else - { - switch ( Utility.Random( 8 ) ) - { - case 0: return new Afro( hairHue ); - case 1: return new KrisnaHair( hairHue ); - case 2: return new PageboyHair( hairHue ); - case 3: return new PonyTail( hairHue ); - case 4: return new ReceedingHair( hairHue ); - case 5: return new TwoPigTails( hairHue ); - case 6: return new ShortHair( hairHue ); - default: return new LongHair( hairHue ); - } - } - } - - - public static Hair CreateByID( int id, int hue ) - { - switch ( id ) - { - case 0x203B: return new ShortHair( hue ); - case 0x203C: return new LongHair( hue ); - case 0x203D: return new PonyTail( hue ); - case 0x2044: return new Mohawk( hue ); - case 0x2045: return new PageboyHair( hue ); - case 0x2046: return new BunsHair( hue ); - case 0x2047: return new Afro( hue ); - case 0x2048: return new ReceedingHair( hue ); - case 0x2049: return new TwoPigTails( hue ); - case 0x204A: return new KrisnaHair( hue ); - default: return new GenericHair( id, hue ); - } - } - * */ - - protected Hair(int itemID, int hue = 0) - : base(itemID) - { - LootType = LootType.Blessed; - Layer = Layer.Hair; - Hue = hue; - } - - public Hair(Serial serial) - : base(serial) - { - } - - public override bool DisplayLootType => false; - - public override bool VerifyMove(Mobile from) - { - return from.AccessLevel >= AccessLevel.GameMaster; - } - - public override DeathMoveResult OnParentDeath(Mobile parent) - { -// Dupe( Amount ); - - parent.HairItemID = ItemID; - parent.HairHue = Hue; - - return DeathMoveResult.MoveToCorpse; - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - LootType = LootType.Blessed; - - int version = reader.ReadInt(); - } - } - - public class GenericHair : Hair - { - private GenericHair(int itemID, int hue = 0) - : base(itemID, hue) - { - } - - public GenericHair(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class Mohawk : Hair - { - private Mohawk(int hue = 0) - : base(0x2044, hue) - { - } - - public Mohawk(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class PageboyHair : Hair - { - private PageboyHair(int hue = 0) - : base(0x2045, hue) - { - } - - public PageboyHair(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class BunsHair : Hair - { - private BunsHair(int hue = 0) - : base(0x2046, hue) - { - } - - public BunsHair(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class LongHair : Hair - { - private LongHair(int hue = 0) - : base(0x203C, hue) - { - } - - public LongHair(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class ShortHair : Hair - { - private ShortHair(int hue = 0) - : base(0x203B, hue) - { - } - - public ShortHair(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class PonyTail : Hair - { - private PonyTail(int hue = 0) - : base(0x203D, hue) - { - } - - public PonyTail(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class Afro : Hair - { - private Afro(int hue = 0) - : base(0x2047, hue) - { - } - - public Afro(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class ReceedingHair : Hair - { - private ReceedingHair(int hue = 0) - : base(0x2048, hue) - { - } - - public ReceedingHair(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class TwoPigTails : Hair - { - private TwoPigTails(int hue = 0) - : base(0x2049, hue) - { - } - - public TwoPigTails(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } - } - - public class KrisnaHair : Hair - { - private KrisnaHair(int hue = 0) - : base(0x204A, hue) - { - } - - public KrisnaHair(Serial serial) - : base(serial) - { - } - - public override void Serialize(GenericWriter writer) - { - base.Serialize(writer); - - writer.Write(0); // version - } - - public override void Deserialize(GenericReader reader) - { - base.Deserialize(reader); - - int version = reader.ReadInt(); - } + // Human + public static int Long = 0x203C; + public static int Shor = 0x203B; + public static int PonyTail = 0x203D; + + public static int Mohawk = 0x2044; + public static int Pageboy = 0x2045; + public static int Bun = 0x2046; // Female Only + public static int Afro = 0x2047; + public static int Receding = 0x2048; // Male Only + public static int TwoPigTails = 0x2049; + public static int Krisna = 0x204A; + + // Elf + public static int MidLongElf = 0x2FBF; // Male Only + public static int LongFeather = 0x2FC0; + public static int ShortElf = 0x2FC1; + public static int Mullet = 0x2FC2; + + public static int Flower = 0x2FCC; // Female only + public static int LongElf = 0x2FCD; // Male Only + public static int Knob = 0x2FCE; + public static int Braided = 0x2FCF; + public static int BunElf = 0x2FD0; // Female Only + public static int Spiked = 0x2FD1; } } \ No newline at end of file diff --git a/Scripts/Items/Food/Beverage.cs b/Scripts/Items/Food/Beverage.cs index 3d155aa55..3e3c4f386 100644 --- a/Scripts/Items/Food/Beverage.cs +++ b/Scripts/Items/Food/Beverage.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Engines.Quests; using Server.Engines.Quests.Hag; @@ -808,24 +809,27 @@ namespace Server.Items { QuestSystem qs = player.Quest; - if (qs is WitchApprenticeQuest) - if (qs.FindObjective(typeof(FindIngredientObjective)) is FindIngredientObjective obj && - !obj.Completed && obj.Ingredient == Ingredient.SwampWater) + if (!(qs is WitchApprenticeQuest)) + return; + + FindIngredientObjective obj = qs.FindObjective(); + + if (obj?.Completed == true && obj.Ingredient == Ingredient.SwampWater) + { + bool contains = false; + + for (int i = 0; !contains && i < m_SwampTiles.Length; i += 2) + contains = tileID >= m_SwampTiles[i] && tileID <= m_SwampTiles[i + 1]; + + if (contains) { - bool contains = false; + Delete(); - for (int i = 0; !contains && i < m_SwampTiles.Length; i += 2) - contains = tileID >= m_SwampTiles[i] && tileID <= m_SwampTiles[i + 1]; - - if (contains) - { - Delete(); - - player.SendLocalizedMessage( - 1055035); // You dip the container into the disgusting swamp water, collecting enough for the Hag's vile stew. - obj.Complete(); - } + player.SendLocalizedMessage( + 1055035); // You dip the container into the disgusting swamp water, collecting enough for the Hag's vile stew. + obj.Complete(); } + } } } } @@ -942,9 +946,9 @@ namespace Server.Items if (from is PlayerMobile player) if (player.Quest is SolenMatriarchQuest qs) { - QuestObjective obj = qs.FindObjective(typeof(GatherWaterObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { BaseAddon vat = component.Addon; @@ -1086,7 +1090,7 @@ namespace Server.Items #region Effects of achohol - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public static void Initialize() { @@ -1102,7 +1106,7 @@ namespace Server.Items { if (from.BAC > 0 && from.Map != Map.Internal && !from.Deleted) { - Timer t = (Timer)m_Table[from]; + Timer t = m_Table[from]; if (t == null) { @@ -1117,7 +1121,7 @@ namespace Server.Items } else { - Timer t = (Timer)m_Table[from]; + Timer t = m_Table[from]; if (t != null) { @@ -1189,4 +1193,4 @@ namespace Server.Items #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Items/Food/CookableFood.cs b/Scripts/Items/Food/CookableFood.cs index 1f2127913..8594d683e 100644 --- a/Scripts/Items/Food/CookableFood.cs +++ b/Scripts/Items/Food/CookableFood.cs @@ -99,7 +99,7 @@ namespace Server.Items if (IsHeatSource(targeted)) { - if (from.BeginAction(typeof(CookableFood))) + if (from.BeginAction()) { from.PlaySound(0x225); @@ -133,7 +133,7 @@ namespace Server.Items protected override void OnTick() { - m_From.EndAction(typeof(CookableFood)); + m_From.EndAction(); if (m_From.Map != m_Map || m_Point != null && m_From.GetDistanceToSqrt(m_Point) > 3) { diff --git a/Scripts/Items/Food/Cooking.cs b/Scripts/Items/Food/Cooking.cs index aa0660c3b..cad1684b3 100644 --- a/Scripts/Items/Food/Cooking.cs +++ b/Scripts/Items/Food/Cooking.cs @@ -548,7 +548,7 @@ namespace Server.Items } else if ( targeted is TribalBerry ) { - if ( from.Skills[SkillName.Cooking].Base >= 80.0 ) + if ( from.Skills.Cooking.Base >= 80.0 ) { m_Item.Delete(); ((TribalBerry)targeted).Delete(); diff --git a/Scripts/Items/Games/Mahjong/MahjongGame.cs b/Scripts/Items/Games/Mahjong/MahjongGame.cs index d6cfe7103..17b9edd1e 100644 --- a/Scripts/Items/Games/Mahjong/MahjongGame.cs +++ b/Scripts/Items/Games/Mahjong/MahjongGame.cs @@ -117,9 +117,9 @@ namespace Server.Engines.Mahjong private void BuildWalls() { - Tiles = new MahjongTile[17 * 8]; + Tiles = new MahjongTile[136]; - MahjongTileTypeGenerator typeGenerator = new MahjongTileTypeGenerator(4); + MahjongTileTypeGenerator typeGenerator = new MahjongTileTypeGenerator(); int i = 0; diff --git a/Scripts/Items/Games/Mahjong/MahjongPacketHandlers.cs b/Scripts/Items/Games/Mahjong/MahjongPacketHandlers.cs index e5124a73c..f2cf92560 100644 --- a/Scripts/Items/Games/Mahjong/MahjongPacketHandlers.cs +++ b/Scripts/Items/Games/Mahjong/MahjongPacketHandlers.cs @@ -40,7 +40,7 @@ namespace Server.Engines.Mahjong public static void OnPacket(NetState state, PacketReader pvSrc) { - MahjongGame game = World.FindItem(pvSrc.ReadInt32()) as MahjongGame; + MahjongGame game = World.FindItem(pvSrc.ReadUInt32()) as MahjongGame; game?.Players.CheckPlayers(); diff --git a/Scripts/Items/Games/Mahjong/MahjongPlayers.cs b/Scripts/Items/Games/Mahjong/MahjongPlayers.cs index 8c9c6c55f..c3899aef8 100644 --- a/Scripts/Items/Games/Mahjong/MahjongPlayers.cs +++ b/Scripts/Items/Games/Mahjong/MahjongPlayers.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; namespace Server.Engines.Mahjong { @@ -8,12 +8,12 @@ namespace Server.Engines.Mahjong private Mobile[] m_Players; private bool[] m_PublicHand; private int[] m_Scores; - private ArrayList m_Spectators; + private List m_Spectators; public MahjongPlayers(MahjongGame game, int maxPlayers, int baseScore) { Game = game; - m_Spectators = new ArrayList(); + m_Spectators = new List(); m_Players = new Mobile[maxPlayers]; m_InGame = new bool[maxPlayers]; @@ -27,7 +27,7 @@ namespace Server.Engines.Mahjong public MahjongPlayers(MahjongGame game, GenericReader reader) { Game = game; - m_Spectators = new ArrayList(); + m_Spectators = new List(); int version = reader.ReadInt(); @@ -121,16 +121,17 @@ namespace Server.Engines.Mahjong m_Players[index].SendLocalizedMessage(value ? 1062775 : 1062776); // Your hand is [not] publicly viewable. } - public ArrayList GetInGameMobiles(bool players, bool spectators) + public List GetInGameMobiles(bool players, bool spectators) { - ArrayList list = new ArrayList(); + List list = new List(); if (players) for (int i = 0; i < m_Players.Length; i++) if (IsInGamePlayer(i)) list.Add(m_Players[i]); - if (spectators) list.AddRange(m_Spectators); + if (spectators) + list.AddRange(m_Spectators); return list; } @@ -429,7 +430,7 @@ namespace Server.Engines.Mahjong public void SendGeneralPacket(bool players, bool spectators) { - ArrayList mobiles = GetInGameMobiles(players, spectators); + List mobiles = GetInGameMobiles(players, spectators); if (mobiles.Count == 0) return; @@ -438,24 +439,27 @@ namespace Server.Engines.Mahjong generalInfo.Acquire(); - foreach (Mobile mobile in mobiles) mobile.Send(generalInfo); + foreach (Mobile mobile in mobiles) + mobile.Send(generalInfo); generalInfo.Release(); } public void SendTilesPacket(bool players, bool spectators) { - foreach (Mobile mobile in GetInGameMobiles(players, spectators)) mobile.Send(new MahjongTilesInfo(Game, mobile)); + foreach (Mobile mobile in GetInGameMobiles(players, spectators)) + mobile.Send(new MahjongTilesInfo(Game, mobile)); } public void SendTilePacket(MahjongTile tile, bool players, bool spectators) { - foreach (Mobile mobile in GetInGameMobiles(players, spectators)) mobile.Send(new MahjongTileInfo(tile, mobile)); + foreach (Mobile mobile in GetInGameMobiles(players, spectators)) + mobile.Send(new MahjongTileInfo(tile, mobile)); } public void SendRelievePacket(bool players, bool spectators) { - ArrayList mobiles = GetInGameMobiles(players, spectators); + List mobiles = GetInGameMobiles(players, spectators); if (mobiles.Count == 0) return; @@ -464,19 +468,22 @@ namespace Server.Engines.Mahjong relieve.Acquire(); - foreach (Mobile mobile in mobiles) mobile.Send(relieve); + foreach (Mobile mobile in mobiles) + mobile.Send(relieve); relieve.Release(); } public void SendLocalizedMessage(int number) { - foreach (Mobile mobile in GetInGameMobiles(true, true)) mobile.SendLocalizedMessage(number); + foreach (Mobile mobile in GetInGameMobiles(true, true)) + mobile.SendLocalizedMessage(number); } public void SendLocalizedMessage(int number, string args) { - foreach (Mobile mobile in GetInGameMobiles(true, true)) mobile.SendLocalizedMessage(number, args); + foreach (Mobile mobile in GetInGameMobiles(true, true)) + mobile.SendLocalizedMessage(number, args); } public void Save(GenericWriter writer) diff --git a/Scripts/Items/Games/Mahjong/MahjongTileTypeGenerator.cs b/Scripts/Items/Games/Mahjong/MahjongTileTypeGenerator.cs index dbb1a1d45..b65dff705 100644 --- a/Scripts/Items/Games/Mahjong/MahjongTileTypeGenerator.cs +++ b/Scripts/Items/Games/Mahjong/MahjongTileTypeGenerator.cs @@ -1,24 +1,29 @@ -using System.Collections; +using System.Collections.Generic; namespace Server.Engines.Mahjong { public class MahjongTileTypeGenerator { - public MahjongTileTypeGenerator(int count) + public MahjongTileTypeGenerator() { - LeftTileTypes = new ArrayList(34 * count); + LeftTileTypes = new List(136); for (int i = 1; i <= 34; i++) - for (int j = 0; j < count; j++) - LeftTileTypes.Add((MahjongTileType)i); + { + MahjongTileType tile = (MahjongTileType)i; + LeftTileTypes.Add(tile); + LeftTileTypes.Add(tile); + LeftTileTypes.Add(tile); + LeftTileTypes.Add(tile); + } } - public ArrayList LeftTileTypes{ get; } + public List LeftTileTypes{ get; } public MahjongTileType Next() { int random = Utility.Random(LeftTileTypes.Count); - MahjongTileType next = (MahjongTileType)LeftTileTypes[random]; + MahjongTileType next = LeftTileTypes[random]; LeftTileTypes.RemoveAt(random); return next; diff --git a/Scripts/Items/Guilds/Guildstone.cs b/Scripts/Items/Guilds/Guildstone.cs index 9682db78d..dd30f47f9 100644 --- a/Scripts/Items/Guilds/Guildstone.cs +++ b/Scripts/Items/Guilds/Guildstone.cs @@ -399,7 +399,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { from.SendLocalizedMessage(1062838); // Where would you like to place this decoration? - from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget, null); + from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget); } else { @@ -412,7 +412,7 @@ namespace Server.Items } } - public void Placement_OnTarget(Mobile from, object targeted, object state) + public void Placement_OnTarget(Mobile from, object targeted) { if (!(targeted is IPoint3D p) || Deleted) return; diff --git a/Scripts/Items/Jewels/BaseJewel.cs b/Scripts/Items/Jewels/BaseJewel.cs index 6220d68ef..aadf71d57 100644 --- a/Scripts/Items/Jewels/BaseJewel.cs +++ b/Scripts/Items/Jewels/BaseJewel.cs @@ -19,9 +19,6 @@ namespace Server.Items public abstract class BaseJewel : Item, ICraftable { - private AosAttributes m_AosAttributes; - private AosElementAttributes m_AosResistances; - private AosSkillBonuses m_AosSkillBonuses; private GemType m_GemType; private int m_HitPoints; private int m_MaxHitPoints; @@ -29,9 +26,9 @@ namespace Server.Items public BaseJewel(int itemID, Layer layer) : base(itemID) { - m_AosAttributes = new AosAttributes(this); - m_AosResistances = new AosElementAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); + Attributes = new AosAttributes(this); + Resistances = new AosElementAttributes(this); + SkillBonuses = new AosSkillBonuses(this); m_Resource = CraftResource.Iron; m_GemType = GemType.None; @@ -76,25 +73,13 @@ namespace Server.Items } [CommandProperty(AccessLevel.Player)] - public AosAttributes Attributes - { - get => m_AosAttributes; - set { } - } + public AosAttributes Attributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosElementAttributes Resistances - { - get => m_AosResistances; - set { } - } + public AosElementAttributes Resistances{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosSkillBonuses SkillBonuses - { - get => m_AosSkillBonuses; - set { } - } + public AosSkillBonuses SkillBonuses{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] public CraftResource Resource @@ -118,11 +103,11 @@ namespace Server.Items } } - public override int PhysicalResistance => m_AosResistances.Physical; - public override int FireResistance => m_AosResistances.Fire; - public override int ColdResistance => m_AosResistances.Cold; - public override int PoisonResistance => m_AosResistances.Poison; - public override int EnergyResistance => m_AosResistances.Energy; + public override int PhysicalResistance => Resistances.Physical; + public override int FireResistance => Resistances.Fire; + public override int ColdResistance => Resistances.Cold; + public override int PoisonResistance => Resistances.Poison; + public override int EnergyResistance => Resistances.Energy; public virtual int BaseGemTypeNumber => 0; public virtual int InitMinHits => 0; @@ -192,20 +177,20 @@ namespace Server.Items if (!(newItem is BaseJewel jewel)) return; - jewel.m_AosAttributes = new AosAttributes(newItem, m_AosAttributes); - jewel.m_AosResistances = new AosElementAttributes(newItem, m_AosResistances); - jewel.m_AosSkillBonuses = new AosSkillBonuses(newItem, m_AosSkillBonuses); + jewel.Attributes = new AosAttributes(newItem, Attributes); + jewel.Resistances = new AosElementAttributes(newItem, Resistances); + jewel.SkillBonuses = new AosSkillBonuses(newItem, SkillBonuses); } public override void OnAdded(IEntity parent) { if (Core.AOS && parent is Mobile from) { - m_AosSkillBonuses.AddTo(from); + SkillBonuses.AddTo(from); - int strBonus = m_AosAttributes.BonusStr; - int dexBonus = m_AosAttributes.BonusDex; - int intBonus = m_AosAttributes.BonusInt; + int strBonus = Attributes.BonusStr; + int dexBonus = Attributes.BonusDex; + int intBonus = Attributes.BonusInt; if (strBonus != 0 || dexBonus != 0 || intBonus != 0) { @@ -229,7 +214,7 @@ namespace Server.Items { if (Core.AOS && parent is Mobile from) { - m_AosSkillBonuses.Remove(); + SkillBonuses.Remove(); string modName = Serial.ToString(); @@ -245,83 +230,83 @@ namespace Server.Items { base.GetProperties(list); - m_AosSkillBonuses.GetProperties(list); + SkillBonuses.GetProperties(list); int prop; if ((prop = ArtifactRarity) > 0) list.Add(1061078, prop.ToString()); // artifact rarity ~1_val~ - if ((prop = m_AosAttributes.WeaponDamage) != 0) + if ((prop = Attributes.WeaponDamage) != 0) list.Add(1060401, prop.ToString()); // damage increase ~1_val~% - if ((prop = m_AosAttributes.DefendChance) != 0) + if ((prop = Attributes.DefendChance) != 0) list.Add(1060408, prop.ToString()); // defense chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusDex) != 0) + if ((prop = Attributes.BonusDex) != 0) list.Add(1060409, prop.ToString()); // dexterity bonus ~1_val~ - if ((prop = m_AosAttributes.EnhancePotions) != 0) + if ((prop = Attributes.EnhancePotions) != 0) list.Add(1060411, prop.ToString()); // enhance potions ~1_val~% - if ((prop = m_AosAttributes.CastRecovery) != 0) + if ((prop = Attributes.CastRecovery) != 0) list.Add(1060412, prop.ToString()); // faster cast recovery ~1_val~ - if ((prop = m_AosAttributes.CastSpeed) != 0) + if ((prop = Attributes.CastSpeed) != 0) list.Add(1060413, prop.ToString()); // faster casting ~1_val~ - if ((prop = m_AosAttributes.AttackChance) != 0) + if ((prop = Attributes.AttackChance) != 0) list.Add(1060415, prop.ToString()); // hit chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusHits) != 0) + if ((prop = Attributes.BonusHits) != 0) list.Add(1060431, prop.ToString()); // hit point increase ~1_val~ - if ((prop = m_AosAttributes.BonusInt) != 0) + if ((prop = Attributes.BonusInt) != 0) list.Add(1060432, prop.ToString()); // intelligence bonus ~1_val~ - if ((prop = m_AosAttributes.LowerManaCost) != 0) + if ((prop = Attributes.LowerManaCost) != 0) list.Add(1060433, prop.ToString()); // lower mana cost ~1_val~% - if ((prop = m_AosAttributes.LowerRegCost) != 0) + if ((prop = Attributes.LowerRegCost) != 0) list.Add(1060434, prop.ToString()); // lower reagent cost ~1_val~% - if ((prop = m_AosAttributes.Luck) != 0) + if ((prop = Attributes.Luck) != 0) list.Add(1060436, prop.ToString()); // luck ~1_val~ - if ((prop = m_AosAttributes.BonusMana) != 0) + if ((prop = Attributes.BonusMana) != 0) list.Add(1060439, prop.ToString()); // mana increase ~1_val~ - if ((prop = m_AosAttributes.RegenMana) != 0) + if ((prop = Attributes.RegenMana) != 0) list.Add(1060440, prop.ToString()); // mana regeneration ~1_val~ - if ((prop = m_AosAttributes.NightSight) != 0) + if ((prop = Attributes.NightSight) != 0) list.Add(1060441); // night sight - if ((prop = m_AosAttributes.ReflectPhysical) != 0) + if ((prop = Attributes.ReflectPhysical) != 0) list.Add(1060442, prop.ToString()); // reflect physical damage ~1_val~% - if ((prop = m_AosAttributes.RegenStam) != 0) + if ((prop = Attributes.RegenStam) != 0) list.Add(1060443, prop.ToString()); // stamina regeneration ~1_val~ - if ((prop = m_AosAttributes.RegenHits) != 0) + if ((prop = Attributes.RegenHits) != 0) list.Add(1060444, prop.ToString()); // hit point regeneration ~1_val~ - if ((prop = m_AosAttributes.SpellChanneling) != 0) + if ((prop = Attributes.SpellChanneling) != 0) list.Add(1060482); // spell channeling - if ((prop = m_AosAttributes.SpellDamage) != 0) + if ((prop = Attributes.SpellDamage) != 0) list.Add(1060483, prop.ToString()); // spell damage increase ~1_val~% - if ((prop = m_AosAttributes.BonusStam) != 0) + if ((prop = Attributes.BonusStam) != 0) list.Add(1060484, prop.ToString()); // stamina increase ~1_val~ - if ((prop = m_AosAttributes.BonusStr) != 0) + if ((prop = Attributes.BonusStr) != 0) list.Add(1060485, prop.ToString()); // strength bonus ~1_val~ - if ((prop = m_AosAttributes.WeaponSpeed) != 0) + if ((prop = Attributes.WeaponSpeed) != 0) list.Add(1060486, prop.ToString()); // swing speed increase ~1_val~% - if (Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0) + if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0) list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~% base.AddResistanceProperties(list); @@ -342,9 +327,9 @@ namespace Server.Items writer.WriteEncodedInt((int)m_Resource); writer.WriteEncodedInt((int)m_GemType); - m_AosAttributes.Serialize(writer); - m_AosResistances.Serialize(writer); - m_AosSkillBonuses.Serialize(writer); + Attributes.Serialize(writer); + Resistances.Serialize(writer); + SkillBonuses.Serialize(writer); } public override void Deserialize(GenericReader reader) @@ -371,18 +356,18 @@ namespace Server.Items } case 1: { - m_AosAttributes = new AosAttributes(this, reader); - m_AosResistances = new AosElementAttributes(this, reader); - m_AosSkillBonuses = new AosSkillBonuses(this, reader); + Attributes = new AosAttributes(this, reader); + Resistances = new AosElementAttributes(this, reader); + SkillBonuses = new AosSkillBonuses(this, reader); Mobile m = Parent as Mobile; if (Core.AOS && m != null) - m_AosSkillBonuses.AddTo(m); + SkillBonuses.AddTo(m); - int strBonus = m_AosAttributes.BonusStr; - int dexBonus = m_AosAttributes.BonusDex; - int intBonus = m_AosAttributes.BonusInt; + int strBonus = Attributes.BonusStr; + int dexBonus = Attributes.BonusDex; + int intBonus = Attributes.BonusInt; if (m != null && (strBonus != 0 || dexBonus != 0 || intBonus != 0)) { @@ -404,9 +389,9 @@ namespace Server.Items } case 0: { - m_AosAttributes = new AosAttributes(this); - m_AosResistances = new AosElementAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); + Attributes = new AosAttributes(this); + Resistances = new AosElementAttributes(this); + SkillBonuses = new AosSkillBonuses(this); break; } diff --git a/Scripts/Items/Maps/CityMap.cs b/Scripts/Items/Maps/CityMap.cs index 146a7e2d9..02307dc50 100644 --- a/Scripts/Items/Maps/CityMap.cs +++ b/Scripts/Items/Maps/CityMap.cs @@ -16,7 +16,7 @@ namespace Server.Items public override void CraftInit(Mobile from) { - double skillValue = from.Skills[SkillName.Cartography].Value; + double skillValue = from.Skills.Cartography.Value; int dist = 64 + (int)(skillValue * 4); if (dist < 200) diff --git a/Scripts/Items/Maps/LocalMap.cs b/Scripts/Items/Maps/LocalMap.cs index 995492377..4ca7aaef4 100644 --- a/Scripts/Items/Maps/LocalMap.cs +++ b/Scripts/Items/Maps/LocalMap.cs @@ -16,7 +16,7 @@ namespace Server.Items public override void CraftInit(Mobile from) { - double skillValue = from.Skills[SkillName.Cartography].Value; + double skillValue = from.Skills.Cartography.Value; int dist = 64 + (int)(skillValue * 2); SetDisplay(from.X - dist, from.Y - dist, from.X + dist, from.Y + dist, 200, 200); diff --git a/Scripts/Items/Maps/MapItem.cs b/Scripts/Items/Maps/MapItem.cs index c4ccac327..2930e9533 100644 --- a/Scripts/Items/Maps/MapItem.cs +++ b/Scripts/Items/Maps/MapItem.cs @@ -196,9 +196,7 @@ namespace Server.Items public virtual void AddWorldPin(int x, int y) { - int mapX, mapY; - ConvertToMap(x, y, out mapX, out mapY); - + ConvertToMap(x, y, out int mapX, out int mapY); AddPin(mapX, mapY); } @@ -285,7 +283,7 @@ namespace Server.Items { Mobile from = state.Mobile; - if (!(World.FindItem(pvSrc.ReadInt32()) is MapItem map)) + if (!(World.FindItem(pvSrc.ReadUInt32()) is MapItem map)) return; int command = pvSrc.ReadByte(); diff --git a/Scripts/Items/Maps/SeaChart.cs b/Scripts/Items/Maps/SeaChart.cs index bda8ae3f2..ed017173a 100644 --- a/Scripts/Items/Maps/SeaChart.cs +++ b/Scripts/Items/Maps/SeaChart.cs @@ -16,7 +16,7 @@ namespace Server.Items public override void CraftInit(Mobile from) { - double skillValue = from.Skills[SkillName.Cartography].Value; + double skillValue = from.Skills.Cartography.Value; int dist = 64 + (int)(skillValue * 10); if (dist < 200) diff --git a/Scripts/Items/Maps/TreasureMap.cs b/Scripts/Items/Maps/TreasureMap.cs index 05d271d06..41824e61d 100644 --- a/Scripts/Items/Maps/TreasureMap.cs +++ b/Scripts/Items/Maps/TreasureMap.cs @@ -326,7 +326,7 @@ namespace Server.Items from.SendLocalizedMessage( 503031); // You did not decode this map and have no clue where to look for the treasure. } - else if (!from.CanBeginAction(typeof(TreasureMap))) + else if (!from.CanBeginAction()) { from.SendLocalizedMessage(503020); // You are already digging treasure. } @@ -390,7 +390,7 @@ namespace Server.Items private bool HasRequiredSkill(Mobile from) { - return from.Skills[SkillName.Cartography].Value >= GetMinSkillLevel(); + return from.Skills.Cartography.Value >= GetMinSkillLevel(); } public void Decode(Mobile from) @@ -410,7 +410,7 @@ namespace Server.Items { double minSkill = GetMinSkillLevel(); - if (from.Skills[SkillName.Cartography].Value < minSkill) + if (from.Skills.Cartography.Value < minSkill) from.SendLocalizedMessage(503013); // The map is too difficult to attempt to decode. double maxSkill = minSkill + 60.0; @@ -591,7 +591,7 @@ namespace Server.Items from.SendLocalizedMessage( 503031); // You did not decode this map and have no clue where to look for the treasure. } - else if (!from.CanBeginAction(typeof(TreasureMap))) + else if (!from.CanBeginAction()) { from.SendLocalizedMessage(503020); // You are already digging treasure. } @@ -610,7 +610,7 @@ namespace Server.Items Point3D targ3D = (p as Item)?.GetWorldLocation() ?? new Point3D(p); int maxRange; - double skillValue = from.Skills[SkillName.Mining].Value; + double skillValue = from.Skills.Mining.Value; if (skillValue >= 100.0) maxRange = 4; @@ -637,10 +637,10 @@ namespace Server.Items { int z = map.GetAverageZ(x, y); - if (!map.CanFit(x, y, z, 16, true, true)) + if (!map.CanFit(x, y, z, 16, true)) from.SendLocalizedMessage( 503021); // You have found the treasure chest but something is keeping it from being dug up. - else if (from.BeginAction(typeof(TreasureMap))) + else if (from.BeginAction()) new DigTimer(from, m_Map, new Point3D(x, y, z), map).Start(); else from.SendLocalizedMessage(503020); // You are already digging treasure. @@ -738,7 +738,7 @@ namespace Server.Items private void Terminate() { Stop(); - m_From.EndAction(typeof(TreasureMap)); + m_From.EndAction(); m_Chest?.Delete(); @@ -823,7 +823,7 @@ namespace Server.Items if (m_Chest != null && m_Chest.Location.Z >= m_Location.Z) { Stop(); - m_From.EndAction(typeof(TreasureMap)); + m_From.EndAction(); m_Chest.Temporary = false; m_TreasureMap.Completed = true; diff --git a/Scripts/Items/Maps/WorldMap.cs b/Scripts/Items/Maps/WorldMap.cs index 24a92e7b1..f8f7032f5 100644 --- a/Scripts/Items/Maps/WorldMap.cs +++ b/Scripts/Items/Maps/WorldMap.cs @@ -18,7 +18,7 @@ namespace Server.Items { // Unlike the others, world map is not based on crafted location - double skillValue = from.Skills[SkillName.Cartography].Value; + double skillValue = from.Skills.Cartography.Value; int x20 = (int)(skillValue * 20); int size = 25 + (int)(skillValue * 6.6); diff --git a/Scripts/Items/Misc/ArcaneGem.cs b/Scripts/Items/Misc/ArcaneGem.cs index 78795391b..665c2998a 100644 --- a/Scripts/Items/Misc/ArcaneGem.cs +++ b/Scripts/Items/Misc/ArcaneGem.cs @@ -35,7 +35,7 @@ namespace Server.Items public int GetChargesFor(Mobile m) { - int v = (int)(m.Skills[SkillName.Tailoring].Value / 5); + int v = (int)(m.Skills.Tailoring.Value / 5); if (v < 16) return 16; @@ -104,7 +104,7 @@ namespace Server.Items else Amount--; } } - else if (from.Skills[SkillName.Tailoring].Value >= 80.0) + else if (from.Skills.Tailoring.Value >= 80.0) { bool isExceptional = clothing?.Quality == ClothingQuality.Exceptional || armor?.Quality == ArmorQuality.Exceptional || diff --git a/Scripts/Items/Misc/BankCheck.cs b/Scripts/Items/Misc/BankCheck.cs index 154ed86dd..cd713bc83 100644 --- a/Scripts/Items/Misc/BankCheck.cs +++ b/Scripts/Items/Misc/BankCheck.cs @@ -233,16 +233,16 @@ namespace Server.Items if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(CashBankCheckObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) obj.Complete(); + if (obj?.Completed == false) obj.Complete(); } if (qs is UzeraanTurmoilQuest) { QuestObjective obj = qs.FindObjective(typeof(Engines.Quests.Haven.CashBankCheckObjective)); - if (obj != null && !obj.Completed) obj.Complete(); + if (obj?.Completed == false) obj.Complete(); } } } diff --git a/Scripts/Items/Misc/Bola.cs b/Scripts/Items/Misc/Bola.cs index e25b7bd0b..b3c2464ec 100644 --- a/Scripts/Items/Misc/Bola.cs +++ b/Scripts/Items/Misc/Bola.cs @@ -31,7 +31,7 @@ namespace Server.Items { from.SendLocalizedMessage(1040019); // The bola must be in your pack to use it. } - else if (!from.CanBeginAction(typeof(Bola))) + else if (!from.CanBeginAction()) { from.SendLocalizedMessage(1049624); // You have to wait a few moments before you can use another bola! } @@ -62,18 +62,8 @@ namespace Server.Items } } - private static void ReleaseBolaLock(object state) + private static void FinishThrow(Mobile from, Mobile to) { - ((Mobile)state).EndAction(typeof(Bola)); - } - - private static void FinishThrow(object state) - { - object[] states = (object[])state; - - Mobile from = (Mobile)states[0]; - Mobile to = (Mobile)states[1]; - if (Core.AOS) new Bola().MoveToWorld(to.Location, to.Map); @@ -99,7 +89,7 @@ namespace Server.Items to.Damage(1); - Timer.DelayCall(TimeSpan.FromSeconds(2.0), new TimerStateCallback(ReleaseBolaLock), from); + Timer.DelayCall(TimeSpan.FromSeconds(2.0), () => from.EndAction()); } private static bool HasFreeHands(Mobile from) @@ -197,7 +187,7 @@ namespace Server.Items else if (!from.CanBeHarmful(to)) { } - else if (from.BeginAction(typeof(Bola))) + else if (from.BeginAction()) { EtherealMount.StopMounting(from); @@ -209,8 +199,7 @@ namespace Server.Items from.Animate(11, 5, 1, true, false, 0); from.MovingEffect(to, 0x26AC, 10, 0, false, false); - Timer.DelayCall(TimeSpan.FromSeconds(0.5), new TimerStateCallback(FinishThrow), - new object[] { from, to }); + Timer.DelayCall(TimeSpan.FromSeconds(0.5), () => FinishThrow(from, to)); } else { diff --git a/Scripts/Items/Misc/BulletinBoards.cs b/Scripts/Items/Misc/BulletinBoards.cs index f11a49f72..eb1b421e3 100644 --- a/Scripts/Items/Misc/BulletinBoards.cs +++ b/Scripts/Items/Misc/BulletinBoards.cs @@ -213,7 +213,7 @@ namespace Server.Items int packetID = pvSrc.ReadByte(); - if (!(World.FindItem(pvSrc.ReadInt32()) is BaseBulletinBoard board) || !board.CheckRange(from)) + if (!(World.FindItem(pvSrc.ReadUInt32()) is BaseBulletinBoard board) || !board.CheckRange(from)) return; switch (packetID) @@ -235,7 +235,7 @@ namespace Server.Items public static void BBRequestContent(Mobile from, BaseBulletinBoard board, PacketReader pvSrc) { - if (!(World.FindItem(pvSrc.ReadInt32()) is BulletinMessage msg) || msg.Parent != board) + if (!(World.FindItem(pvSrc.ReadUInt32()) is BulletinMessage msg) || msg.Parent != board) return; from.Send(new BBMessageContent(board, msg)); @@ -243,7 +243,7 @@ namespace Server.Items public static void BBRequestHeader(Mobile from, BaseBulletinBoard board, PacketReader pvSrc) { - if (!(World.FindItem(pvSrc.ReadInt32()) is BulletinMessage msg) || msg.Parent != board) + if (!(World.FindItem(pvSrc.ReadUInt32()) is BulletinMessage msg) || msg.Parent != board) return; from.Send(new BBMessageHeader(board, msg)); @@ -251,7 +251,7 @@ namespace Server.Items public static void BBPostMessage(Mobile from, BaseBulletinBoard board, PacketReader pvSrc) { - BulletinMessage thread = World.FindItem(pvSrc.ReadInt32()) as BulletinMessage; + BulletinMessage thread = World.FindItem(pvSrc.ReadUInt32()) as BulletinMessage; if (thread != null && thread.Parent != board) thread = null; @@ -292,7 +292,7 @@ namespace Server.Items public static void BBRemoveMessage(Mobile from, BaseBulletinBoard board, PacketReader pvSrc) { - if (!(World.FindItem(pvSrc.ReadInt32()) is BulletinMessage msg) || msg.Parent != board) + if (!(World.FindItem(pvSrc.ReadUInt32()) is BulletinMessage msg) || msg.Parent != board) return; if (from.AccessLevel < AccessLevel.GameMaster && msg.Poster != from) diff --git a/Scripts/Items/Misc/ClockworkAssembly.cs b/Scripts/Items/Misc/ClockworkAssembly.cs index b88c21635..a161bbb55 100644 --- a/Scripts/Items/Misc/ClockworkAssembly.cs +++ b/Scripts/Items/Misc/ClockworkAssembly.cs @@ -25,7 +25,7 @@ namespace Server.Items return; } - double tinkerSkill = from.Skills[SkillName.Tinkering].Value; + double tinkerSkill = from.Skills.Tinkering.Value; if (tinkerSkill < 60.0) { diff --git a/Scripts/Items/Misc/Corpses/Corpse.cs b/Scripts/Items/Misc/Corpses/Corpse.cs index 3f3651ff9..f47ad21c0 100644 --- a/Scripts/Items/Misc/Corpses/Corpse.cs +++ b/Scripts/Items/Misc/Corpses/Corpse.cs @@ -861,10 +861,7 @@ namespace Server.Items public bool GetRestoreInfo(Item item, ref Point3D loc) { - if (m_RestoreTable == null || item == null) - return false; - - return m_RestoreTable.TryGetValue(item, out loc); + return item != null && m_RestoreTable?.TryGetValue(item, out loc) == true; } public void SetRestoreInfo(Item item, Point3D loc) @@ -1026,8 +1023,8 @@ namespace Server.Items if (qs is UzeraanTurmoilQuest) { - if (qs.FindObjective(typeof(GetDaemonBoneObjective)) is GetDaemonBoneObjective obj && - obj.CorpseWithBone == this && (!obj.Completed || UzeraanTurmoilQuest.HasLostDaemonBone(player))) + GetDaemonBoneObjective obj = qs.FindObjective(); + if (obj?.CorpseWithBone == this && (!obj.Completed || UzeraanTurmoilQuest.HasLostDaemonBone(player))) { Item bone = new QuestDaemonBone(); @@ -1052,8 +1049,8 @@ namespace Server.Items } else if (qs is TheSummoningQuest) { - if (qs.FindObjective(typeof(VanquishDaemonObjective)) is VanquishDaemonObjective obj && - obj.Completed && obj.CorpseWithSkull == this) + VanquishDaemonObjective obj = qs.FindObjective(); + if (obj?.Completed == true && obj.CorpseWithSkull == this) { GoldenSkull sk = new GoldenSkull(); diff --git a/Scripts/Items/Misc/EffectController.cs b/Scripts/Items/Misc/EffectController.cs index e8a2e6c72..22b49ef0b 100644 --- a/Scripts/Items/Misc/EffectController.cs +++ b/Scripts/Items/Misc/EffectController.cs @@ -216,7 +216,7 @@ namespace Server.Items private IEntity ReadEntity(GenericReader reader) { - return World.FindEntity(reader.ReadInt()); + return World.FindEntity(reader.ReadUInt()); } public override void Deserialize(GenericReader reader) diff --git a/Scripts/Items/Misc/Firebomb.cs b/Scripts/Items/Misc/Firebomb.cs index a96b41010..a148214c0 100644 --- a/Scripts/Items/Misc/Firebomb.cs +++ b/Scripts/Items/Misc/Firebomb.cs @@ -173,22 +173,17 @@ namespace Server.Items IEntity to = p as IEntity ?? new Entity(Serial.Zero, new Point3D(p), Map); - Effects.SendMovingEffect(from, to, ItemID, 7, 0, false, false, Hue, 0); + Effects.SendMovingEffect(from, to, ItemID, 7, 0, false, false, Hue); - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(FirebombReposition_OnTick), - new object[] { p, Map }); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => FirebombReposition_OnTick(p, Map)); Internalize(); } - private void FirebombReposition_OnTick(object state) + private void FirebombReposition_OnTick(IPoint3D p, Map map) { if (Deleted) return; - object[] states = (object[])state; - IPoint3D p = (IPoint3D)states[0]; - Map map = (Map)states[1]; - MoveToWorld(new Point3D(p), map); } diff --git a/Scripts/Items/Misc/Guillotine.cs b/Scripts/Items/Misc/Guillotine.cs index b6104fa30..c490d14d6 100644 --- a/Scripts/Items/Misc/Guillotine.cs +++ b/Scripts/Items/Misc/Guillotine.cs @@ -71,15 +71,17 @@ namespace Server.Items int y = p.Y - 2 + Utility.Random(5); int z = p.Z; - if (!f.CanFit(x, y, z, 1, false, false, true)) + if (!f.CanFit(x, y, z, 1, false, false)) { z = f.GetAverageZ(x, y); - if (!f.CanFit(x, y, z, 1, false, false, true)) + if (!f.CanFit(x, y, z, 1, false, false)) continue; } - new Blood().MoveToWorld(new Point3D(x, y, z), f); + Point3D loc = f.GetRandomNearbyLocation(p, 2, -2, 4, 1); + + new Blood().MoveToWorld(loc, f); } } @@ -110,4 +112,4 @@ namespace Server.Items ItemID = 4702; } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Misc/HairDye.cs b/Scripts/Items/Misc/HairDye.cs index d4736fe6e..238afe195 100644 --- a/Scripts/Items/Misc/HairDye.cs +++ b/Scripts/Items/Misc/HairDye.cs @@ -35,7 +35,7 @@ namespace Server.Items { if (from.InRange(GetWorldLocation(), 1)) { - from.CloseGump(typeof(HairDyeGump)); + from.CloseGump(); from.SendGump(new HairDyeGump(this)); } else diff --git a/Scripts/Items/Misc/InteriorDecorator.cs b/Scripts/Items/Misc/InteriorDecorator.cs index 3bc18b5d9..d6b543d33 100644 --- a/Scripts/Items/Misc/InteriorDecorator.cs +++ b/Scripts/Items/Misc/InteriorDecorator.cs @@ -68,7 +68,7 @@ namespace Server.Items if (!CheckUse(this, from)) return; - if (from.FindGump(typeof(InternalGump)) == null) + if (!from.HasGump()) from.SendGump(new InternalGump(this)); if (m_Command != DecorateCommand.None) @@ -252,7 +252,7 @@ namespace Server.Items protected override void OnTargetCancel(Mobile from, TargetCancelType cancelType) { if (cancelType == TargetCancelType.Canceled) - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); } private static void Turn(Item item, Mobile from) diff --git a/Scripts/Items/Misc/PlayerBulletinBoards.cs b/Scripts/Items/Misc/PlayerBulletinBoards.cs index b60970067..c78840c83 100644 --- a/Scripts/Items/Misc/PlayerBulletinBoards.cs +++ b/Scripts/Items/Misc/PlayerBulletinBoards.cs @@ -523,7 +523,7 @@ namespace Server.Items public PlayerBBGump( Mobile from, BaseHouse house, BasePlayerBB board, int page ) : base( 50, 10 ) { - from.CloseGump( typeof( PlayerBBGump ) ); + from.CloseGump(); m_Page = page; m_From = from; diff --git a/Scripts/Items/Misc/PlayerVendorDeed.cs b/Scripts/Items/Misc/PlayerVendorDeed.cs index 034f28bf3..c52bd9d21 100644 --- a/Scripts/Items/Misc/PlayerVendorDeed.cs +++ b/Scripts/Items/Misc/PlayerVendorDeed.cs @@ -76,8 +76,7 @@ namespace Server.Items } else { - bool vendor, contract; - BaseHouse.IsThereVendor(from.Location, from.Map, out vendor, out contract); + BaseHouse.IsThereVendor(from.Location, from.Map, out bool vendor, out bool contract); if (vendor) { diff --git a/Scripts/Items/Misc/PowerGenerator.cs b/Scripts/Items/Misc/PowerGenerator.cs index 9e22f6c35..1a8bc34ef 100644 --- a/Scripts/Items/Misc/PowerGenerator.cs +++ b/Scripts/Items/Misc/PowerGenerator.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Network; @@ -57,7 +58,7 @@ namespace Server.Items { private static readonly TimeSpan m_UseTimeout = TimeSpan.FromMinutes(2.0); - private Hashtable m_DamageTable = new Hashtable(); + private Dictionary m_DamageTable = new Dictionary(); private DateTime m_LastUse; private int m_SideLength; @@ -167,7 +168,7 @@ namespace Server.Items if (m_User != null) { - m_User.CloseGump(typeof(GameGump)); + m_User.CloseGump(); m_User = null; } } @@ -188,7 +189,7 @@ namespace Server.Items if (m_User.Deleted || m_User.Map != Map || !m_User.InRange(this, 3) || m_User.NetState == null || DateTime.UtcNow - m_LastUse >= m_UseTimeout) { - m_User.CloseGump(typeof(GameGump)); + m_User.CloseGump(); } else { @@ -546,4 +547,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Misc/PromotionalToken.cs b/Scripts/Items/Misc/PromotionalToken.cs index a16b45301..924fe2d48 100644 --- a/Scripts/Items/Misc/PromotionalToken.cs +++ b/Scripts/Items/Misc/PromotionalToken.cs @@ -37,7 +37,7 @@ namespace Server.Items } else { - from.CloseGump( typeof( PromotionalTokenGump ) ); + from.CloseGump(); from.SendGump( new PromotionalTokenGump( this ) ); } } @@ -51,7 +51,7 @@ namespace Server.Items else if ( parent is Mobile mobile ) m = mobile; - m?.CloseGump( typeof( PromotionalTokenGump ) ); + m?.CloseGump(); } public override void Serialize( GenericWriter writer ) diff --git a/Scripts/Items/Misc/PublicMoongate.cs b/Scripts/Items/Misc/PublicMoongate.cs index 76d1f40b5..8fe043e74 100644 --- a/Scripts/Items/Misc/PublicMoongate.cs +++ b/Scripts/Items/Misc/PublicMoongate.cs @@ -50,7 +50,7 @@ namespace Server.Items { if (m is PlayerMobile) if (!Utility.InRange(m.Location, Location, 1) && Utility.InRange(oldLocation, Location, 1)) - m.CloseGump(typeof(MoongateGump)); + m.CloseGump(); } public bool UseGate(Mobile m) @@ -73,7 +73,7 @@ namespace Server.Items return false; } - m.CloseGump(typeof(MoongateGump)); + m.CloseGump(); m.SendGump(new MoongateGump(m, this)); if (!m.Hidden || m.AccessLevel == AccessLevel.Player) diff --git a/Scripts/Items/Misc/SpecialBeardDye.cs b/Scripts/Items/Misc/SpecialBeardDye.cs index 0928dec51..b50f9324a 100644 --- a/Scripts/Items/Misc/SpecialBeardDye.cs +++ b/Scripts/Items/Misc/SpecialBeardDye.cs @@ -36,7 +36,7 @@ namespace Server.Items { if (from.InRange(GetWorldLocation(), 1)) { - from.CloseGump(typeof(SpecialBeardDyeGump)); + from.CloseGump(); from.SendGump(new SpecialBeardDyeGump(this)); } else diff --git a/Scripts/Items/Misc/SpecialHairDye.cs b/Scripts/Items/Misc/SpecialHairDye.cs index 745c54ed4..9fa12c19f 100644 --- a/Scripts/Items/Misc/SpecialHairDye.cs +++ b/Scripts/Items/Misc/SpecialHairDye.cs @@ -36,7 +36,7 @@ namespace Server.Items { if (from.InRange(GetWorldLocation(), 1)) { - from.CloseGump(typeof(SpecialHairDyeGump)); + from.CloseGump(); from.SendGump(new SpecialHairDyeGump(this)); } else diff --git a/Scripts/Items/Misc/Teleporter.cs b/Scripts/Items/Misc/Teleporter.cs index c8efaff8f..5bd858038 100644 --- a/Scripts/Items/Misc/Teleporter.cs +++ b/Scripts/Items/Misc/Teleporter.cs @@ -392,11 +392,6 @@ namespace Server.Items } } - private void EndMessageLock(object state) - { - ((Mobile)state).EndAction(this); - } - public override bool CanTeleport(Mobile m) { if (!base.CanTeleport(m)) @@ -415,7 +410,7 @@ namespace Server.Items m.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, m_MessageNumber, null, "")); - Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(EndMessageLock), m); + Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => m.EndAction(this)); } return false; diff --git a/Scripts/Items/Misc/TribalPaint.cs b/Scripts/Items/Misc/TribalPaint.cs index 55daaf9a8..f91b1b64a 100644 --- a/Scripts/Items/Misc/TribalPaint.cs +++ b/Scripts/Items/Misc/TribalPaint.cs @@ -32,11 +32,11 @@ namespace Server.Items { from.SendLocalizedMessage(1010465); // You cannot disguise yourself while holding a sigil. } - else if (!from.CanBeginAction(typeof(IncognitoSpell))) + else if (!from.CanBeginAction()) { from.SendLocalizedMessage(501698); // You cannot disguise yourself while incognitoed. } - else if (!from.CanBeginAction(typeof(PolymorphSpell))) + else if (!from.CanBeginAction()) { from.SendLocalizedMessage(501699); // You cannot disguise yourself while polymorphed. } diff --git a/Scripts/Items/Quivers/BaseQuiver.cs b/Scripts/Items/Quivers/BaseQuiver.cs index bf1e1207e..f339b2ea1 100644 --- a/Scripts/Items/Quivers/BaseQuiver.cs +++ b/Scripts/Items/Quivers/BaseQuiver.cs @@ -10,7 +10,6 @@ namespace Server.Items typeof(Arrow), typeof(Bolt) }; - private AosAttributes m_Attributes; private int m_Capacity; private Mobile m_Crafter; @@ -29,7 +28,7 @@ namespace Server.Items Capacity = 500; Layer = Layer.Cloak; - m_Attributes = new AosAttributes(this); + Attributes = new AosAttributes(this); DamageIncrease = 10; } @@ -44,11 +43,7 @@ namespace Server.Items public override double DefaultWeight => 2.0; [CommandProperty(AccessLevel.GameMaster)] - public AosAttributes Attributes - { - get => m_Attributes; - set { } - } + public AosAttributes Attributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] public int Capacity @@ -138,7 +133,7 @@ namespace Server.Items if (!(newItem is BaseQuiver quiver)) return; - quiver.m_Attributes = new AosAttributes(newItem, m_Attributes); + quiver.Attributes = new AosAttributes(newItem, Attributes); } public override void UpdateTotal(Item sender, TotalType type, int delta) @@ -226,12 +221,12 @@ namespace Server.Items public override void OnAdded(IEntity parent) { - if (parent is Mobile mob) m_Attributes.AddStatBonuses(mob); + if (parent is Mobile mob) Attributes.AddStatBonuses(mob); } public override void OnRemoved(IEntity parent) { - if (parent is Mobile mob) m_Attributes.RemoveStatBonuses(mob); + if (parent is Mobile mob) Attributes.RemoveStatBonuses(mob); } public override void GetProperties(ObjectPropertyList list) @@ -291,67 +286,67 @@ namespace Server.Items list.Add(1075085); // Requirement: Mondain's Legacy - if ((prop = m_Attributes.DefendChance) != 0) + if ((prop = Attributes.DefendChance) != 0) list.Add(1060408, prop.ToString()); // defense chance increase ~1_val~% - if ((prop = m_Attributes.BonusDex) != 0) + if ((prop = Attributes.BonusDex) != 0) list.Add(1060409, prop.ToString()); // dexterity bonus ~1_val~ - if ((prop = m_Attributes.EnhancePotions) != 0) + if ((prop = Attributes.EnhancePotions) != 0) list.Add(1060411, prop.ToString()); // enhance potions ~1_val~% - if ((prop = m_Attributes.CastRecovery) != 0) + if ((prop = Attributes.CastRecovery) != 0) list.Add(1060412, prop.ToString()); // faster cast recovery ~1_val~ - if ((prop = m_Attributes.CastSpeed) != 0) + if ((prop = Attributes.CastSpeed) != 0) list.Add(1060413, prop.ToString()); // faster casting ~1_val~ - if ((prop = m_Attributes.AttackChance) != 0) + if ((prop = Attributes.AttackChance) != 0) list.Add(1060415, prop.ToString()); // hit chance increase ~1_val~% - if ((prop = m_Attributes.BonusHits) != 0) + if ((prop = Attributes.BonusHits) != 0) list.Add(1060431, prop.ToString()); // hit point increase ~1_val~ - if ((prop = m_Attributes.BonusInt) != 0) + if ((prop = Attributes.BonusInt) != 0) list.Add(1060432, prop.ToString()); // intelligence bonus ~1_val~ - if ((prop = m_Attributes.LowerManaCost) != 0) + if ((prop = Attributes.LowerManaCost) != 0) list.Add(1060433, prop.ToString()); // lower mana cost ~1_val~% - if ((prop = m_Attributes.LowerRegCost) != 0) + if ((prop = Attributes.LowerRegCost) != 0) list.Add(1060434, prop.ToString()); // lower reagent cost ~1_val~% - if ((prop = m_Attributes.Luck) != 0) + if ((prop = Attributes.Luck) != 0) list.Add(1060436, prop.ToString()); // luck ~1_val~ - if ((prop = m_Attributes.BonusMana) != 0) + if ((prop = Attributes.BonusMana) != 0) list.Add(1060439, prop.ToString()); // mana increase ~1_val~ - if ((prop = m_Attributes.RegenMana) != 0) + if ((prop = Attributes.RegenMana) != 0) list.Add(1060440, prop.ToString()); // mana regeneration ~1_val~ - if ((prop = m_Attributes.NightSight) != 0) + if ((prop = Attributes.NightSight) != 0) list.Add(1060441); // night sight - if ((prop = m_Attributes.ReflectPhysical) != 0) + if ((prop = Attributes.ReflectPhysical) != 0) list.Add(1060442, prop.ToString()); // reflect physical damage ~1_val~% - if ((prop = m_Attributes.RegenStam) != 0) + if ((prop = Attributes.RegenStam) != 0) list.Add(1060443, prop.ToString()); // stamina regeneration ~1_val~ - if ((prop = m_Attributes.RegenHits) != 0) + if ((prop = Attributes.RegenHits) != 0) list.Add(1060444, prop.ToString()); // hit point regeneration ~1_val~ - if ((prop = m_Attributes.SpellDamage) != 0) + if ((prop = Attributes.SpellDamage) != 0) list.Add(1060483, prop.ToString()); // spell damage increase ~1_val~% - if ((prop = m_Attributes.BonusStam) != 0) + if ((prop = Attributes.BonusStam) != 0) list.Add(1060484, prop.ToString()); // stamina increase ~1_val~ - if ((prop = m_Attributes.BonusStr) != 0) + if ((prop = Attributes.BonusStr) != 0) list.Add(1060485, prop.ToString()); // strength bonus ~1_val~ - if ((prop = m_Attributes.WeaponSpeed) != 0) + if ((prop = Attributes.WeaponSpeed) != 0) list.Add(1060486, prop.ToString()); // swing speed increase ~1_val~% if ((prop = m_LowerAmmoCost) > 0) @@ -388,7 +383,7 @@ namespace Server.Items SaveFlag flags = SaveFlag.None; - SetSaveFlag(ref flags, SaveFlag.Attributes, !m_Attributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.Attributes, !Attributes.IsEmpty); SetSaveFlag(ref flags, SaveFlag.LowerAmmoCost, m_LowerAmmoCost != 0); SetSaveFlag(ref flags, SaveFlag.WeightReduction, m_WeightReduction != 0); SetSaveFlag(ref flags, SaveFlag.DamageIncrease, m_DamageIncrease != 0); @@ -399,7 +394,7 @@ namespace Server.Items writer.WriteEncodedInt((int)flags); if (GetSaveFlag(flags, SaveFlag.Attributes)) - m_Attributes.Serialize(writer); + Attributes.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.LowerAmmoCost)) writer.Write(m_LowerAmmoCost); @@ -429,9 +424,9 @@ namespace Server.Items SaveFlag flags = (SaveFlag)reader.ReadEncodedInt(); if (GetSaveFlag(flags, SaveFlag.Attributes)) - m_Attributes = new AosAttributes(this, reader); + Attributes = new AosAttributes(this, reader); else - m_Attributes = new AosAttributes(this); + Attributes = new AosAttributes(this); if (GetSaveFlag(flags, SaveFlag.LowerAmmoCost)) m_LowerAmmoCost = reader.ReadInt(); diff --git a/Scripts/Items/Resources/Blacksmithing/Ore.cs b/Scripts/Items/Resources/Blacksmithing/Ore.cs index 0f9a7d423..5228ade52 100644 --- a/Scripts/Items/Resources/Blacksmithing/Ore.cs +++ b/Scripts/Items/Resources/Blacksmithing/Ore.cs @@ -342,7 +342,7 @@ namespace Server.Items double minSkill = difficulty - 25.0; double maxSkill = difficulty + 25.0; - if (difficulty > 50.0 && difficulty > from.Skills[SkillName.Mining].Value) + if (difficulty > 50.0 && difficulty > from.Skills.Mining.Value) { from.SendLocalizedMessage(501986); // You have no idea how to smelt this strange ore! return; diff --git a/Scripts/Items/Shields/BaseShield.cs b/Scripts/Items/Shields/BaseShield.cs index 443985d63..2dbbed652 100644 --- a/Scripts/Items/Shields/BaseShield.cs +++ b/Scripts/Items/Shields/BaseShield.cs @@ -22,7 +22,7 @@ namespace Server.Items double ar = base.ArmorRating; if (m != null) - return m.Skills[SkillName.Parry].Value * ar / 200.0 + 1.0; + return m.Skills.Parry.Value * ar / 200.0 + 1.0; return ar; } } @@ -115,7 +115,7 @@ namespace Server.Items return damage; double ar = ArmorRating; - double chance = (owner.Skills[SkillName.Parry].Value - ar * 2.0) / 100.0; + double chance = (owner.Skills.Parry.Value - ar * 2.0) / 100.0; if (chance < 0.01) chance = 0.01; diff --git a/Scripts/Items/Skill Items/Camping/Bedroll.cs b/Scripts/Items/Skill Items/Camping/Bedroll.cs index 8853ba9d7..01d225ef7 100644 --- a/Scripts/Items/Skill Items/Camping/Bedroll.cs +++ b/Scripts/Items/Skill Items/Camping/Bedroll.cs @@ -42,7 +42,7 @@ namespace Server.Items { ItemID = 0xA57; - if (!from.HasGump(typeof(LogoutGump))) + if (!from.HasGump()) { CampfireEntry entry = Campfire.GetEntry(from); @@ -123,7 +123,7 @@ namespace Server.Items private void CloseGump() { Campfire.RemoveEntry(m_Entry); - m_Entry.Player.CloseGump(typeof(LogoutGump)); + m_Entry.Player.CloseGump(); } } } diff --git a/Scripts/Items/Skill Items/Camping/Campfire.cs b/Scripts/Items/Skill Items/Camping/Campfire.cs index 8a116ce72..81035850d 100644 --- a/Scripts/Items/Skill Items/Camping/Campfire.cs +++ b/Scripts/Items/Skill Items/Camping/Campfire.cs @@ -1,5 +1,6 @@ using System; -using System.Collections; +using System.Collections.Generic; +using System.Linq; using Server.Mobiles; using Server.Network; @@ -16,9 +17,9 @@ namespace Server.Items { public static readonly int SecureRange = 7; - private static readonly Hashtable m_Table = new Hashtable(); + private static readonly Dictionary m_Table = new Dictionary(); - private ArrayList m_Entries; + private List m_Entries; private Timer m_Timer; @@ -27,7 +28,7 @@ namespace Server.Items Movable = false; Light = LightType.Circle300; - m_Entries = new ArrayList(); + m_Entries = new List(); Created = DateTime.UtcNow; m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnTick); @@ -85,7 +86,7 @@ namespace Server.Items public static CampfireEntry GetEntry(Mobile player) { - return (CampfireEntry)m_Table[player]; + return m_Table[player]; } public static void RemoveEntry(CampfireEntry entry) @@ -109,11 +110,9 @@ namespace Server.Items if (Status == CampfireStatus.Off || Deleted) return; - foreach (CampfireEntry entry in new ArrayList(m_Entries)) + foreach (CampfireEntry entry in m_Entries.ToList()) if (!entry.Valid || entry.Player.NetState == null) - { RemoveEntry(entry); - } else if (!entry.Safe && now - entry.Start >= TimeSpan.FromSeconds(30.0)) { entry.Safe = true; @@ -141,7 +140,8 @@ namespace Server.Items if (m_Entries == null) return; - foreach (CampfireEntry entry in new ArrayList(m_Entries)) RemoveEntry(entry); + foreach (CampfireEntry entry in m_Entries.ToList()) + RemoveEntry(entry); } public override void OnAfterDelete() diff --git a/Scripts/Items/Skill Items/Camping/Kindling.cs b/Scripts/Items/Skill Items/Camping/Kindling.cs index 20cbc7c4b..c4cb3075d 100644 --- a/Scripts/Items/Skill Items/Camping/Kindling.cs +++ b/Scripts/Items/Skill Items/Camping/Kindling.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; using Server.Network; using Server.Regions; @@ -72,13 +72,13 @@ namespace Server.Items private Point3D GetFireLocation(Mobile from) { - if (from.Region.IsPartOf(typeof(DungeonRegion))) + if (from.Region.IsPartOf()) return Point3D.Zero; if (Parent == null) return Location; - ArrayList list = new ArrayList(4); + List list = new List(4); AddOffsetLocation(from, 0, -1, list); AddOffsetLocation(from, -1, 0, list); @@ -89,10 +89,10 @@ namespace Server.Items return Point3D.Zero; int idx = Utility.Random(list.Count); - return (Point3D)list[idx]; + return list[idx]; } - private void AddOffsetLocation(Mobile from, int offsetX, int offsetY, ArrayList list) + private void AddOffsetLocation(Mobile from, int offsetX, int offsetY, List list) { Map map = from.Map; diff --git a/Scripts/Items/Skill Items/Carpenter Items/TaxidermyKit.cs b/Scripts/Items/Skill Items/Carpenter Items/TaxidermyKit.cs index 5b88738de..b04a39072 100644 --- a/Scripts/Items/Skill Items/Carpenter Items/TaxidermyKit.cs +++ b/Scripts/Items/Skill Items/Carpenter Items/TaxidermyKit.cs @@ -51,7 +51,7 @@ namespace Server.Items { from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it. } - else if (from.Skills[SkillName.Carpentry].Base < 90.0) + else if (from.Skills.Carpentry.Base < 90.0) { from.SendLocalizedMessage(1042594); // You do not understand how to use this. } @@ -108,7 +108,7 @@ namespace Server.Items { from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it. } - else if (from.Skills[SkillName.Carpentry].Base < 90.0) + else if (from.Skills.Carpentry.Base < 90.0) { from.SendLocalizedMessage(1042603); // You would not understand how to use the kit. } diff --git a/Scripts/Items/Skill Items/Fishing/Misc/Sextant.cs b/Scripts/Items/Skill Items/Fishing/Misc/Sextant.cs index ce0fd986b..d2326362d 100644 --- a/Scripts/Items/Skill Items/Fishing/Misc/Sextant.cs +++ b/Scripts/Items/Skill Items/Fishing/Misc/Sextant.cs @@ -86,10 +86,7 @@ namespace Server.Items if (map == null || map == Map.Internal) return Point3D.Zero; - int xCenter, yCenter; - int xWidth, yHeight; - - if (!ComputeMapDetails(map, 0, 0, out xCenter, out yCenter, out xWidth, out yHeight)) + if (!ComputeMapDetails(map, 0, 0, out int xCenter, out int yCenter, out int xWidth, out int yHeight)) return Point3D.Zero; double absLong = xLong + (double)xMins / 60; @@ -101,10 +98,8 @@ namespace Server.Items if (!ySouth) absLat = 360.0 - absLat; - int x, y, z; - - x = xCenter + (int)(absLong * xWidth / 360); - y = yCenter + (int)(absLat * yHeight / 360); + int x = xCenter + (int)(absLong * xWidth / 360); + int y = yCenter + (int)(absLat * yHeight / 360); if (x < 0) x += xWidth; @@ -116,7 +111,7 @@ namespace Server.Items else if (y >= yHeight) y -= yHeight; - z = map.GetAverageZ(x, y); + int z = map.GetAverageZ(x, y); return new Point3D(x, y, z); } @@ -128,10 +123,8 @@ namespace Server.Items return false; int x = p.X, y = p.Y; - int xCenter, yCenter; - int xWidth, yHeight; - if (!ComputeMapDetails(map, x, y, out xCenter, out yCenter, out xWidth, out yHeight)) + if (!ComputeMapDetails(map, x, y, out int xCenter, out int yCenter, out int xWidth, out int yHeight)) return false; double absLong = (double)((x - xCenter) * 360) / xWidth; diff --git a/Scripts/Items/Skill Items/Fishing/Misc/ShipwreckedItem.cs b/Scripts/Items/Skill Items/Fishing/Misc/ShipwreckedItem.cs index d219748d5..673cd4d48 100644 --- a/Scripts/Items/Skill Items/Fishing/Misc/ShipwreckedItem.cs +++ b/Scripts/Items/Skill Items/Fishing/Misc/ShipwreckedItem.cs @@ -38,7 +38,7 @@ namespace Server.Items #region IShipwreckedItem Members - public bool IsShipwreckedItem + bool IShipwreckedItem.IsShipwreckedItem { get => true; set { } diff --git a/Scripts/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs b/Scripts/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs index 4585897ea..0b9e50b33 100644 --- a/Scripts/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs +++ b/Scripts/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs @@ -163,8 +163,10 @@ namespace Server.Items Effects.SendLocationEffect(p, map, 0x352D, 16, 4); Effects.PlaySound(p, map, 0x364); - Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.25), 14, new TimerStateCallback(DoEffect), - new object[] { p, 0, from }); + int index = 0; + + Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.25), 14, + () => DoEffect(from, p, index++)); from.SendLocalizedMessage(RequireDeepWater ? 1010487 @@ -178,19 +180,11 @@ namespace Server.Items } } - private void DoEffect(object state) + private void DoEffect(Mobile from, Point3D p, int index) { if (Deleted) return; - object[] states = (object[])state; - - Point3D p = (Point3D)states[0]; - int index = (int)states[1]; - Mobile from = (Mobile)states[2]; - - states[1] = ++index; - if (index == 1) { Effects.SendLocationEffect(p, Map, 0x352D, 16, 4); diff --git a/Scripts/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs b/Scripts/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs index fdd1e01ce..d35f7aa06 100644 --- a/Scripts/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs +++ b/Scripts/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs @@ -86,7 +86,7 @@ namespace Server.Items } } - public bool ShowUsesRemaining + bool IUsesRemaining.ShowUsesRemaining { get => true; set { } @@ -215,7 +215,7 @@ namespace Server.Items m_Mobile = mobile; m_Value = value; - bool stoneMining = mobile.StoneMining && mobile.Skills[SkillName.Mining].Base >= 100.0; + bool stoneMining = mobile.StoneMining && mobile.Skills.Mining.Base >= 100.0; if (mobile.ToggleMiningStone == value || value && !stoneMining) Flags |= CMEFlags.Disabled; @@ -231,7 +231,7 @@ namespace Server.Items { m_Mobile.SendLocalizedMessage(1054023); // You are already set to mine both ore and stone! } - else if (!m_Mobile.StoneMining || m_Mobile.Skills[SkillName.Mining].Base < 100.0) + else if (!m_Mobile.StoneMining || m_Mobile.Skills.Mining.Base < 100.0) { m_Mobile.SendLocalizedMessage( 1054024); // You have not learned how to mine stone or you do not have enough skill! diff --git a/Scripts/Items/Skill Items/Harvest Tools/ProspectorsTool.cs b/Scripts/Items/Skill Items/Harvest Tools/ProspectorsTool.cs index e230f8219..8a7c12968 100644 --- a/Scripts/Items/Skill Items/Harvest Tools/ProspectorsTool.cs +++ b/Scripts/Items/Skill Items/Harvest Tools/ProspectorsTool.cs @@ -45,7 +45,7 @@ namespace Server.Items } } - public bool ShowUsesRemaining + bool IUsesRemaining.ShowUsesRemaining { get => true; set { } @@ -69,11 +69,7 @@ namespace Server.Items HarvestSystem system = Mining.System; - int tileID; - Map map; - Point3D loc; - - if (!system.GetHarvestDetails(from, this, toProspect, out tileID, out map, out loc)) + if (!system.GetHarvestDetails(from, this, toProspect, out int tileID, out Map map, out Point3D loc)) { from.SendLocalizedMessage(1049048); // You cannot use your prospector tool on that. return; diff --git a/Scripts/Items/Skill Items/Magical/Misc/Moongate.cs b/Scripts/Items/Skill Items/Magical/Misc/Moongate.cs index 0eb3fcbe3..c31bb4189 100644 --- a/Scripts/Items/Skill Items/Magical/Misc/Moongate.cs +++ b/Scripts/Items/Skill Items/Magical/Misc/Moongate.cs @@ -172,7 +172,7 @@ namespace Server.Items { if (from.AccessLevel == AccessLevel.Player || !from.Hidden) from.Send(new PlaySound(0x20E, from.Location)); - from.CloseGump(typeof(MoongateConfirmGump)); + from.CloseGump(); from.SendGump(new MoongateConfirmGump(from, this)); } else @@ -205,7 +205,7 @@ namespace Server.Items if (map == null) return false; - GuardedRegion reg = (GuardedRegion)Region.Find(p, map).GetRegion(typeof(GuardedRegion)); + GuardedRegion reg = Region.Find(p, map).GetRegion(); return reg != null && !reg.IsDisabled(); } @@ -267,7 +267,7 @@ namespace Server.Items [CommandProperty(AccessLevel.GameMaster)] public string MessageString{ get; set; } - public virtual void Warning_Callback(Mobile from, bool okay, object state) + public virtual void Warning_Callback(Mobile from, bool okay) { if (okay) EndConfirmation(from); @@ -277,10 +277,10 @@ namespace Server.Items { if (GumpWidth > 0 && GumpHeight > 0 && TitleNumber > 0 && (MessageNumber > 0 || MessageString != null)) { - from.CloseGump(typeof(WarningGump)); + from.CloseGump(); from.SendGump(new WarningGump(TitleNumber, TitleColor, MessageString == null ? MessageNumber : (object)MessageString, MessageColor, GumpWidth, GumpHeight, - Warning_Callback, from)); + okay => Warning_Callback(from, okay))); } else { diff --git a/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs index c15fd916f..a8bafc707 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs @@ -66,13 +66,6 @@ namespace Server.Items int version = reader.ReadInt(); } - public void Explode_Callback(object state) - { - object[] states = (object[])state; - - Explode((Mobile)states[0], (Point3D)states[1], (Map)states[2]); - } - public virtual void Explode(Mobile from, Point3D loc, Map map) { if (Deleted || map == null) @@ -129,9 +122,8 @@ namespace Server.Items else to = new Entity(Serial.Zero, new Point3D(p), from.Map); - Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue, 0); - Timer.DelayCall(TimeSpan.FromSeconds(1.5), new TimerStateCallback(Potion.Explode_Callback), - new object[] { from, new Point3D(p), from.Map }); + Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue); + Timer.DelayCall(TimeSpan.FromSeconds(1.5), () => Potion.Explode(from, new Point3D(p), from.Map)); } } @@ -292,33 +284,28 @@ namespace Server.Items #region Delay - private static Hashtable m_Delay = new Hashtable(); + private static Dictionary m_Delay = new Dictionary(); public static void AddDelay(Mobile m) { - if (m_Delay[m] is Timer timer) - timer.Stop(); - - m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), new TimerStateCallback(EndDelay_Callback), m); + m_Delay[m]?.Stop(); + m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), EndDelay, m); } public static int GetDelay(Mobile m) { - if (m_Delay[m] is Timer timer && timer.Next > DateTime.UtcNow) + Timer timer = m_Delay[m]; + if (timer?.Next > DateTime.UtcNow) return (int)(timer.Next - DateTime.UtcNow).TotalSeconds; return 0; } - private static void EndDelay_Callback(object obj) - { - if (obj is Mobile mobile) - EndDelay(mobile); - } - public static void EndDelay(Mobile m) { - if (m_Delay[m] is Timer timer) + Timer timer = m_Delay[m]; + + if (timer != null) { timer.Stop(); m_Delay.Remove(m); @@ -327,4 +314,4 @@ namespace Server.Items #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs index bae86f129..f227e36ab 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs @@ -67,13 +67,6 @@ namespace Server.Items int version = reader.ReadInt(); } - public void Explode_Callback(object state) - { - object[] states = (object[])state; - - Explode((Mobile)states[0], (Point3D)states[1], (Map)states[2]); - } - public virtual void Explode(Mobile from, Point3D loc, Map map) { if (Deleted || map == null) @@ -91,7 +84,7 @@ namespace Server.Items Geometry.Circle2D(loc, map, Radius, BlastEffect, 270, 90); - Timer.DelayCall(TimeSpan.FromSeconds(0.3), new TimerStateCallback(CircleEffect2), new object[] { loc, map }); + Timer.DelayCall(TimeSpan.FromSeconds(0.3), () => CircleEffect2(loc, map)); foreach (Mobile mobile in map.GetMobilesInRange(loc, Radius)) if (mobile is BaseCreature mon) @@ -134,9 +127,8 @@ namespace Server.Items else to = new Entity(Serial.Zero, new Point3D(p), from.Map); - Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue, 0); - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(Potion.Explode_Callback), - new object[] { from, new Point3D(p), from.Map }); + Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => Potion.Explode(from, new Point3D(p), from.Map)); } } @@ -148,44 +140,36 @@ namespace Server.Items Effects.SendLocationEffect(p, map, 0x376A, 4, 9); } - public void CircleEffect2(object state) + public void CircleEffect2(Point3D p, Map m) { - object[] states = (object[])state; - - Geometry.Circle2D((Point3D)states[0], (Map)states[1], Radius, BlastEffect, 90, 270); + Geometry.Circle2D(p, m, Radius, BlastEffect, 90, 270); } #endregion #region Delay - private static Hashtable m_Delay = new Hashtable(); + private static Dictionary m_Delay = new Dictionary(); public static void AddDelay(Mobile m) { - if (m_Delay[m] is Timer timer) - timer.Stop(); - - m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(60), new TimerStateCallback(EndDelay_Callback), m); + m_Delay[m]?.Stop(); + m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(60), EndDelay, m); } public static int GetDelay(Mobile m) { - if (m_Delay[m] is Timer timer && timer.Next > DateTime.UtcNow) + Timer timer = m_Delay[m]; + if (timer?.Next > DateTime.UtcNow) return (int)(timer.Next - DateTime.UtcNow).TotalSeconds; return 0; } - private static void EndDelay_Callback(object obj) - { - if (obj is Mobile mobile) - EndDelay(mobile); - } - public static void EndDelay(Mobile m) { - if (m_Delay[m] is Timer timer) + Timer timer = m_Delay[m]; + if (timer != null) { timer.Stop(); m_Delay.Remove(m); @@ -194,4 +178,4 @@ namespace Server.Items #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs index 3982742c6..11331c9ef 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs @@ -91,24 +91,22 @@ namespace Server.Items { from.SendLocalizedMessage(500236); // You should throw it now! + int timer = 3; + if (Core.ML) m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.25), 5, - new TimerStateCallback(Detonate_OnTick), new object[] { from, 3 }); // 3.6 seconds explosion delay + () => Detonate_OnTick(from, timer--)); // 3.6 seconds explosion delay else m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(0.75), TimeSpan.FromSeconds(1.0), 4, - new TimerStateCallback(Detonate_OnTick), new object[] { from, 3 }); // 2.6 seconds explosion delay + () => Detonate_OnTick(from, timer--)); // 2.6 seconds explosion delay } } - private void Detonate_OnTick(object state) + private void Detonate_OnTick(Mobile from, int timer) { if (Deleted) return; - object[] states = (object[])state; - Mobile from = (Mobile)states[0]; - int timer = (int)states[1]; - object parent = FindParent(from); if (timer == 0) @@ -140,23 +138,14 @@ namespace Server.Items item.PublicOverheadMessage(MessageType.Regular, 0x22, false, timer.ToString()); else if (parent is Mobile mobile) mobile.PublicOverheadMessage(MessageType.Regular, 0x22, false, timer.ToString()); - - states[1] = timer - 1; } } - private void Reposition_OnTick(object state) + private void Reposition_OnTick(Mobile from, Point3D loc, Map map) { if (Deleted) return; - object[] states = (object[])state; - Mobile from = (Mobile)states[0]; - IPoint3D p = (IPoint3D)states[1]; - Map map = (Map)states[2]; - - Point3D loc = new Point3D(p); - if (InstantExplosion) Explode(from, true, loc, map); else @@ -189,7 +178,7 @@ namespace Server.Items if (direct) alchemyBonus = (int)(from.Skills.Alchemy.Value / (Core.AOS ? 5 : 10)); - IPooledEnumerable eable = map.GetObjectsInRange(loc, ExplosionRange, LeveledExplosion, true); + IPooledEnumerable eable = map.GetObjectsInRange(loc, ExplosionRange, LeveledExplosion); List toExplode = new List(); int toDamage = 0; @@ -274,13 +263,12 @@ namespace Server.Items to = m; } - Effects.SendMovingEffect(from, to, Potion.ItemID, 7, 0, false, false, Potion.Hue, 0); + Effects.SendMovingEffect(from, to, Potion.ItemID, 7, 0, false, false, Potion.Hue); if (Potion.Amount > 1) Mobile.LiftItemDupe(Potion, 1); Potion.Internalize(); - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(Potion.Reposition_OnTick), - new object[] { from, p, map }); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => Potion.Reposition_OnTick(from, new Point3D(p), map)); } } } diff --git a/Scripts/Items/Skill Items/Magical/Potions/Heal Potions/BaseHealPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Heal Potions/BaseHealPotion.cs index 2ce8507fb..773ce4fad 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Heal Potions/BaseHealPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Heal Potions/BaseHealPotion.cs @@ -51,7 +51,7 @@ namespace Server.Items } else { - if (from.BeginAction(typeof(BaseHealPotion))) + if (from.BeginAction()) { DoHeal(from); @@ -60,7 +60,7 @@ namespace Server.Items if (!DuelContext.IsFreeConsume(from)) Consume(); - Timer.DelayCall(TimeSpan.FromSeconds(Delay), new TimerStateCallback(ReleaseHealLock), from); + Timer.DelayCall(TimeSpan.FromSeconds(Delay), from.EndAction); } else { @@ -75,10 +75,5 @@ namespace Server.Items 1049547); // You decide against drinking this potion, as you are already at full health. } } - - private static void ReleaseHealLock(object state) - { - ((Mobile)state).EndAction(typeof(BaseHealPotion)); - } } } \ No newline at end of file diff --git a/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs index c0e7d99f6..66ae1b945 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs @@ -1,11 +1,12 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Items { public class InvisibilityPotion : BasePotion { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public InvisibilityPotion() : base(0xF0A, PotionEffect.Invisibility) @@ -34,16 +35,10 @@ namespace Server.Items } Consume(); - m_Table[from] = Timer.DelayCall(TimeSpan.FromSeconds(2), new TimerStateCallback(Hide_Callback), from); + m_Table[from] = Timer.DelayCall(TimeSpan.FromSeconds(2), Hide, from); PlayDrinkEffect(from); } - private static void Hide_Callback(object obj) - { - if (obj is Mobile mobile) - Hide(mobile); - } - public static void Hide(Mobile m) { Effects.SendLocationParticles( @@ -57,13 +52,7 @@ namespace Server.Items RemoveTimer(m); - Timer.DelayCall(TimeSpan.FromSeconds(30), new TimerStateCallback(EndHide_Callback), m); - } - - private static void EndHide_Callback(object obj) - { - if (obj is Mobile mobile) - EndHide(mobile); + Timer.DelayCall(TimeSpan.FromSeconds(30), EndHide, m); } public static void EndHide(Mobile m) @@ -79,11 +68,11 @@ namespace Server.Items public static void RemoveTimer(Mobile m) { - Timer t = (Timer)m_Table[m]; + Timer timer = m_Table[m]; - if (t != null) + if (timer != null) { - t.Stop(); + timer.Stop(); m_Table.Remove(m); } } @@ -108,4 +97,4 @@ namespace Server.Items int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Magical/Potions/NightSight.cs b/Scripts/Items/Skill Items/Magical/Potions/NightSight.cs index e9ba57ebd..c4bc72042 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/NightSight.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/NightSight.cs @@ -29,7 +29,7 @@ namespace Server.Items public override void Drink(Mobile from) { - if (from.BeginAction(typeof(LightCycle))) + if (from.BeginAction()) { new LightCycle.NightSightTimer(from).Start(); from.LightLevel = LightCycle.DungeonLevel / 2; diff --git a/Scripts/Items/Skill Items/Magical/Runebook.cs b/Scripts/Items/Skill Items/Magical/Runebook.cs index 5b1ec9bb4..a5252a05d 100644 --- a/Scripts/Items/Skill Items/Magical/Runebook.cs +++ b/Scripts/Items/Skill Items/Magical/Runebook.cs @@ -119,7 +119,7 @@ namespace Server.Items public int OnCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CraftItem craftItem, int resHue) { - int charges = 5 + quality + (int)(from.Skills[SkillName.Inscribe].Value / 30); + int charges = 5 + quality + (int)(from.Skills.Inscribe.Value / 30); if (charges > 10) charges = 10; @@ -272,7 +272,7 @@ namespace Server.Items public override bool OnDragLift(Mobile from) { - if (from.HasGump(typeof(RunebookGump))) + if (from.HasGump()) { from.SendLocalizedMessage(500169); // You cannot pick that up. return false; @@ -280,7 +280,7 @@ namespace Server.Items foreach (Mobile m in Openers) if (IsOpen(m)) - m.CloseGump(typeof(RunebookGump)); + m.CloseGump(); Openers.Clear(); @@ -314,7 +314,7 @@ namespace Server.Items return; } - from.CloseGump(typeof(RunebookGump)); + from.CloseGump(); from.SendGump(new RunebookGump(from, this)); Openers.Add(from); diff --git a/Scripts/Items/Skill Items/Magical/Spellbook.cs b/Scripts/Items/Skill Items/Magical/Spellbook.cs index 16da7bab9..4ca10e5df 100644 --- a/Scripts/Items/Skill Items/Magical/Spellbook.cs +++ b/Scripts/Items/Skill Items/Magical/Spellbook.cs @@ -69,9 +69,6 @@ namespace Server.Items 1 // 1 property : 1/4 : 25% }; - private AosAttributes m_AosAttributes; - private AosSkillBonuses m_AosSkillBonuses; - private ulong m_Content; private Mobile m_Crafter; @@ -94,8 +91,8 @@ namespace Server.Items public Spellbook(ulong content, int itemID) : base(itemID) { - m_AosAttributes = new AosAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); + Attributes = new AosAttributes(this); + SkillBonuses = new AosSkillBonuses(this); Weight = 3.0; Layer = Layer.OneHanded; @@ -133,18 +130,10 @@ namespace Server.Items public override bool DisplayWeight => false; [CommandProperty(AccessLevel.GameMaster)] - public AosAttributes Attributes - { - get => m_AosAttributes; - set { } - } + public AosAttributes Attributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosSkillBonuses SkillBonuses - { - get => m_AosSkillBonuses; - set { } - } + public AosSkillBonuses SkillBonuses{ get; private set; } public virtual SpellbookType SpellbookType => SpellbookType.Regular; public virtual int BookOffset => 0; @@ -535,7 +524,7 @@ namespace Server.Items { if (!Ethic.CheckEquip(from, this)) return false; - if (!from.CanBeginAction(typeof(BaseWeapon))) return false; + if (!from.CanBeginAction()) return false; return base.CanEquip(from); } @@ -583,19 +572,19 @@ namespace Server.Items if (!(newItem is Spellbook book)) return; - book.m_AosAttributes = new AosAttributes(newItem, m_AosAttributes); - book.m_AosSkillBonuses = new AosSkillBonuses(newItem, m_AosSkillBonuses); + book.Attributes = new AosAttributes(newItem, Attributes); + book.SkillBonuses = new AosSkillBonuses(newItem, SkillBonuses); } public override void OnAdded(IEntity parent) { if (Core.AOS && parent is Mobile from) { - m_AosSkillBonuses.AddTo(from); + SkillBonuses.AddTo(from); - int strBonus = m_AosAttributes.BonusStr; - int dexBonus = m_AosAttributes.BonusDex; - int intBonus = m_AosAttributes.BonusInt; + int strBonus = Attributes.BonusStr; + int dexBonus = Attributes.BonusDex; + int intBonus = Attributes.BonusInt; if (strBonus != 0 || dexBonus != 0 || intBonus != 0) { @@ -619,7 +608,7 @@ namespace Server.Items { if (Core.AOS && parent is Mobile from) { - m_AosSkillBonuses.Remove(); + SkillBonuses.Remove(); string modName = Serial.ToString(); @@ -706,7 +695,7 @@ namespace Server.Items if (m_Crafter != null) list.Add(1050043, m_Crafter.Name); // crafted by ~1_NAME~ - m_AosSkillBonuses.GetProperties(list); + SkillBonuses.GetProperties(list); if (m_Slayer != SlayerName.None) { @@ -724,76 +713,76 @@ namespace Server.Items int prop; - if ((prop = m_AosAttributes.WeaponDamage) != 0) + if ((prop = Attributes.WeaponDamage) != 0) list.Add(1060401, prop.ToString()); // damage increase ~1_val~% - if ((prop = m_AosAttributes.DefendChance) != 0) + if ((prop = Attributes.DefendChance) != 0) list.Add(1060408, prop.ToString()); // defense chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusDex) != 0) + if ((prop = Attributes.BonusDex) != 0) list.Add(1060409, prop.ToString()); // dexterity bonus ~1_val~ - if ((prop = m_AosAttributes.EnhancePotions) != 0) + if ((prop = Attributes.EnhancePotions) != 0) list.Add(1060411, prop.ToString()); // enhance potions ~1_val~% - if ((prop = m_AosAttributes.CastRecovery) != 0) + if ((prop = Attributes.CastRecovery) != 0) list.Add(1060412, prop.ToString()); // faster cast recovery ~1_val~ - if ((prop = m_AosAttributes.CastSpeed) != 0) + if ((prop = Attributes.CastSpeed) != 0) list.Add(1060413, prop.ToString()); // faster casting ~1_val~ - if ((prop = m_AosAttributes.AttackChance) != 0) + if ((prop = Attributes.AttackChance) != 0) list.Add(1060415, prop.ToString()); // hit chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusHits) != 0) + if ((prop = Attributes.BonusHits) != 0) list.Add(1060431, prop.ToString()); // hit point increase ~1_val~ - if ((prop = m_AosAttributes.BonusInt) != 0) + if ((prop = Attributes.BonusInt) != 0) list.Add(1060432, prop.ToString()); // intelligence bonus ~1_val~ - if ((prop = m_AosAttributes.LowerManaCost) != 0) + if ((prop = Attributes.LowerManaCost) != 0) list.Add(1060433, prop.ToString()); // lower mana cost ~1_val~% - if ((prop = m_AosAttributes.LowerRegCost) != 0) + if ((prop = Attributes.LowerRegCost) != 0) list.Add(1060434, prop.ToString()); // lower reagent cost ~1_val~% - if ((prop = m_AosAttributes.Luck) != 0) + if ((prop = Attributes.Luck) != 0) list.Add(1060436, prop.ToString()); // luck ~1_val~ - if ((prop = m_AosAttributes.BonusMana) != 0) + if ((prop = Attributes.BonusMana) != 0) list.Add(1060439, prop.ToString()); // mana increase ~1_val~ - if ((prop = m_AosAttributes.RegenMana) != 0) + if ((prop = Attributes.RegenMana) != 0) list.Add(1060440, prop.ToString()); // mana regeneration ~1_val~ - if ((prop = m_AosAttributes.NightSight) != 0) + if ((prop = Attributes.NightSight) != 0) list.Add(1060441); // night sight - if ((prop = m_AosAttributes.ReflectPhysical) != 0) + if ((prop = Attributes.ReflectPhysical) != 0) list.Add(1060442, prop.ToString()); // reflect physical damage ~1_val~% - if ((prop = m_AosAttributes.RegenStam) != 0) + if ((prop = Attributes.RegenStam) != 0) list.Add(1060443, prop.ToString()); // stamina regeneration ~1_val~ - if ((prop = m_AosAttributes.RegenHits) != 0) + if ((prop = Attributes.RegenHits) != 0) list.Add(1060444, prop.ToString()); // hit point regeneration ~1_val~ - if ((prop = m_AosAttributes.SpellChanneling) != 0) + if ((prop = Attributes.SpellChanneling) != 0) list.Add(1060482); // spell channeling - if ((prop = m_AosAttributes.SpellDamage) != 0) + if ((prop = Attributes.SpellDamage) != 0) list.Add(1060483, prop.ToString()); // spell damage increase ~1_val~% - if ((prop = m_AosAttributes.BonusStam) != 0) + if ((prop = Attributes.BonusStam) != 0) list.Add(1060484, prop.ToString()); // stamina increase ~1_val~ - if ((prop = m_AosAttributes.BonusStr) != 0) + if ((prop = Attributes.BonusStr) != 0) list.Add(1060485, prop.ToString()); // strength bonus ~1_val~ - if ((prop = m_AosAttributes.WeaponSpeed) != 0) + if ((prop = Attributes.WeaponSpeed) != 0) list.Add(1060486, prop.ToString()); // swing speed increase ~1_val~% - if (Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0) + if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0) list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~% list.Add(1042886, SpellCount.ToString()); // ~1_NUMBERS_OF_SPELLS~ Spells @@ -835,8 +824,8 @@ namespace Server.Items writer.Write((int)m_Slayer); writer.Write((int)m_Slayer2); - m_AosAttributes.Serialize(writer); - m_AosSkillBonuses.Serialize(writer); + Attributes.Serialize(writer); + SkillBonuses.Serialize(writer); writer.Write(m_Content); writer.Write(SpellCount); @@ -875,8 +864,8 @@ namespace Server.Items } case 1: { - m_AosAttributes = new AosAttributes(this, reader); - m_AosSkillBonuses = new AosSkillBonuses(this, reader); + Attributes = new AosAttributes(this, reader); + SkillBonuses = new AosSkillBonuses(this, reader); goto case 0; } @@ -889,18 +878,18 @@ namespace Server.Items } } - if (m_AosAttributes == null) - m_AosAttributes = new AosAttributes(this); + if (Attributes == null) + Attributes = new AosAttributes(this); - if (m_AosSkillBonuses == null) - m_AosSkillBonuses = new AosSkillBonuses(this); + if (SkillBonuses == null) + SkillBonuses = new AosSkillBonuses(this); if (Core.AOS && Parent is Mobile mobile) - m_AosSkillBonuses.AddTo(mobile); + SkillBonuses.AddTo(mobile); - int strBonus = m_AosAttributes.BonusStr; - int dexBonus = m_AosAttributes.BonusDex; - int intBonus = m_AosAttributes.BonusInt; + int strBonus = Attributes.BonusStr; + int dexBonus = Attributes.BonusDex; + int intBonus = Attributes.BonusInt; if (Parent is Mobile m) { diff --git a/Scripts/Items/Skill Items/Misc/Bandage.cs b/Scripts/Items/Skill Items/Misc/Bandage.cs index da94c05f4..534f5e7dd 100644 --- a/Scripts/Items/Skill Items/Misc/Bandage.cs +++ b/Scripts/Items/Skill Items/Misc/Bandage.cs @@ -253,7 +253,7 @@ namespace Server.Items healerNumber = 501042; // Target can not be resurrected at that location. patientNumber = 502391; // Thou can not be resurrected there! } - else if (Patient.Region != null && Patient.Region.IsPartOf("Khaldun")) + else if (Patient.Region?.IsPartOf("Khaldun") == true) { healerNumber = 1010395; // The veil of death in this area is too strong and resists thy efforts to restore life. @@ -281,7 +281,7 @@ namespace Server.Items { healerNumber = 503255; // You are able to resurrect the creature. - master.CloseGump(typeof(PetResurrectGump)); + master.CloseGump(); master.SendGump(new PetResurrectGump(Healer, petPatient)); } else @@ -298,7 +298,7 @@ namespace Server.Items { healerNumber = 503255; // You are able to resurrect the creature. - friend.CloseGump(typeof(PetResurrectGump)); + friend.CloseGump(); friend.SendGump(new PetResurrectGump(Healer, petPatient)); found = true; @@ -312,7 +312,7 @@ namespace Server.Items } else { - Patient.CloseGump(typeof(ResurrectGump)); + Patient.CloseGump(); Patient.SendGump(new ResurrectGump(Patient, Healer)); } } diff --git a/Scripts/Items/Skill Items/Misc/FireHorn.cs b/Scripts/Items/Skill Items/Misc/FireHorn.cs index 15e4f167d..5bc95ba17 100644 --- a/Scripts/Items/Skill Items/Misc/FireHorn.cs +++ b/Scripts/Items/Skill Items/Misc/FireHorn.cs @@ -32,7 +32,7 @@ namespace Server.Items return false; } - if (!from.CanBeginAction(typeof(FireHorn))) + if (!from.CanBeginAction()) { from.SendLocalizedMessage(1049615); // You must take a moment to catch your breath. return false; @@ -62,11 +62,10 @@ namespace Server.Items if (!CheckUse(from)) return; - from.BeginAction(typeof(FireHorn)); - Timer.DelayCall(Core.AOS ? TimeSpan.FromSeconds(6.0) : TimeSpan.FromSeconds(12.0), - new TimerStateCallback(EndAction), from); + from.BeginAction(); + Timer.DelayCall(Core.AOS ? TimeSpan.FromSeconds(6.0) : TimeSpan.FromSeconds(12.0), EndAction, from); - int music = from.Skills[SkillName.Musicianship].Fixed; + int music = from.Skills.Musicianship.Fixed; int sucChance = 500 + (music - 775) * 2; double dSucChance = sucChance / 1000.0; @@ -107,9 +106,9 @@ namespace Server.Items if (targets.Count > 0) { - int prov = from.Skills[SkillName.Provocation].Fixed; - int disc = from.Skills[SkillName.Discordance].Fixed; - int peace = from.Skills[SkillName.Peacemaking].Fixed; + int prov = from.Skills.Provocation.Fixed; + int disc = from.Skills.Discordance.Fixed; + int peace = from.Skills.Peacemaking.Fixed; int minDamage, maxDamage; @@ -176,12 +175,10 @@ namespace Server.Items } } - private static void EndAction(object state) + private static void EndAction(Mobile m) { - Mobile m = (Mobile)state; - - m.EndAction(typeof(FireHorn)); - m.SendLocalizedMessage(1049621); // You catch your breath. + m?.EndAction(); + m?.SendLocalizedMessage(1049621); // You catch your breath. } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Items/Skill Items/Misc/RepairDeed.cs b/Scripts/Items/Skill Items/Misc/RepairDeed.cs index b864d33a3..a9ee0fd13 100644 --- a/Scripts/Items/Skill Items/Misc/RepairDeed.cs +++ b/Scripts/Items/Skill Items/Misc/RepairDeed.cs @@ -172,11 +172,7 @@ namespace Server.Items public bool VerifyRegion(Mobile m) { //TODO: When the entire region system data is in, convert to that instead of a proximity thing. - - if (!m.Region.IsPartOf(typeof(TownRegion))) - return false; - - return Faction.IsNearType(m, RepairSkillInfo.GetInfo(m_Skill).NearbyTypes, 6); + return m.Region.IsPartOf() && Faction.IsNearType(m, RepairSkillInfo.GetInfo(m_Skill).NearbyTypes, 6); } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs index 7d7c3a928..1efe7492b 100644 --- a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs +++ b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Craft; using Server.Mobiles; using Server.Network; @@ -18,7 +19,7 @@ namespace Server.Items public abstract class BaseInstrument : Item, ICraftable, ISlayer { - private static Hashtable m_Instruments = new Hashtable(); + private static Dictionary m_Instruments = new Dictionary(); private Mobile m_Crafter; private DateTime m_LastReplenished; @@ -150,12 +151,7 @@ namespace Server.Items } } - public void CheckReplenishUses() - { - CheckReplenishUses(true); - } - - public void CheckReplenishUses(bool invalidate) + public void CheckReplenishUses(bool invalidate = true) { if (!m_ReplenishesCharges || m_UsesRemaining >= InitMaxUses) return; @@ -186,10 +182,7 @@ namespace Server.Items public int GetUsesScalar() { - if (m_Quality == InstrumentQuality.Exceptional) - return 200; - - return 100; + return m_Quality == InstrumentQuality.Exceptional ? 200 : 100; } public void ConsumeUse(Mobile from) @@ -210,16 +203,15 @@ namespace Server.Items public static BaseInstrument GetInstrument(Mobile from) { - if (!(m_Instruments[from] is BaseInstrument item)) + BaseInstrument item = m_Instruments[from]; + if (item == null) return null; - if (!item.IsChildOf(from.Backpack)) - { - m_Instruments.Remove(from); - return null; - } + if (item.IsChildOf(from.Backpack)) + return item; - return item; + m_Instruments.Remove(from); + return null; } public static int GetBardRange(Mobile bard, SkillName skill) @@ -238,11 +230,11 @@ namespace Server.Items else { from.SendLocalizedMessage(500617); // What instrument shall you play? - from.BeginTarget(1, false, TargetFlags.None, new TargetStateCallback(OnPickedInstrument), callback); + from.BeginTarget(1, false, TargetFlags.None, OnPickedInstrument, callback); } } - public static void OnPickedInstrument(Mobile from, object targeted, object state) + public static void OnPickedInstrument(Mobile from, object targeted, InstrumentPickedCallback callback) { if (!(targeted is BaseInstrument instrument)) { @@ -251,24 +243,18 @@ namespace Server.Items else { SetInstrument(from, instrument); - - InstrumentPickedCallback callback = state as InstrumentPickedCallback; - callback?.Invoke(from, instrument); } } public static bool IsMageryCreature(BaseCreature bc) { - return bc != null && bc.AI == AIType.AI_Mage && bc.Skills[SkillName.Magery].Base > 5.0; + return bc?.AI == AIType.AI_Mage && bc.Skills.Magery.Base > 5.0; } public static bool IsFireBreathingCreature(BaseCreature bc) { - if (bc == null) - return false; - - return bc.HasBreath; + return bc?.HasBreath == true; } public static bool IsPoisonImmune(BaseCreature bc) @@ -278,12 +264,7 @@ namespace Server.Items public static int GetPoisonLevel(BaseCreature bc) { - Poison p = bc?.HitPoison; - - if (p == null) - return 0; - - return p.Level + 1; + return (bc?.HitPoison.Level ?? -1) + 1; } public static double GetBaseDifficulty(Mobile targ) @@ -295,7 +276,7 @@ namespace Server.Items double val = targ.HitsMax * 1.6 + targ.StamMax + targ.ManaMax; - val += targ.SkillsTotal / 10; + val += targ.SkillsTotal / 10.0; if (val > 700) val = 700 + (int)((val - 700) * (3.0 / 11)); @@ -406,7 +387,7 @@ namespace Server.Items public override void OnSingleClick(Mobile from) { - ArrayList attrs = new ArrayList(); + List attrs = new List(); if (DisplayLootType) { @@ -453,7 +434,7 @@ namespace Server.Items return; EquipmentInfo eqInfo = new EquipmentInfo(number, m_Crafter, false, - (EquipInfoAttribute[])attrs.ToArray(typeof(EquipInfoAttribute))); + attrs.ToArray()); from.Send(new DisplayEquipmentInfo(this, eqInfo)); } @@ -546,7 +527,7 @@ namespace Server.Items { from.SendLocalizedMessage(500446); // That is too far away. } - else if (from.BeginAction(typeof(BaseInstrument))) + else if (from.BeginAction()) { SetInstrument(from, this); @@ -568,7 +549,7 @@ namespace Server.Items { m.CheckSkill(SkillName.Musicianship, 0.0, 120.0); - return m.Skills[SkillName.Musicianship].Value / 100 > Utility.RandomDouble(); + return m.Skills.Musicianship.Value / 100 > Utility.RandomDouble(); } public void PlayInstrumentWell(Mobile from) @@ -593,8 +574,8 @@ namespace Server.Items protected override void OnTick() { - m_From.EndAction(typeof(BaseInstrument)); + m_From.EndAction(); } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Ninjitsu/Fukiya.cs b/Scripts/Items/Skill Items/Ninjitsu/Fukiya.cs index 24e8dd0d2..9ed9fe2f0 100644 --- a/Scripts/Items/Skill Items/Ninjitsu/Fukiya.cs +++ b/Scripts/Items/Skill Items/Ninjitsu/Fukiya.cs @@ -70,7 +70,7 @@ namespace Server.Items } } - public bool ShowUsesRemaining + bool IUsesRemaining.ShowUsesRemaining { get => true; set { } diff --git a/Scripts/Items/Skill Items/Ninjitsu/FukiyaDarts.cs b/Scripts/Items/Skill Items/Ninjitsu/FukiyaDarts.cs index 1776d4c41..3a0ffd626 100644 --- a/Scripts/Items/Skill Items/Ninjitsu/FukiyaDarts.cs +++ b/Scripts/Items/Skill Items/Ninjitsu/FukiyaDarts.cs @@ -68,7 +68,7 @@ namespace Server.Items } } - public bool ShowUsesRemaining + bool IUsesRemaining.ShowUsesRemaining { get => true; set { } diff --git a/Scripts/Items/Skill Items/Ninjitsu/Shuriken.cs b/Scripts/Items/Skill Items/Ninjitsu/Shuriken.cs index bcb2cee93..1e522ab6f 100644 --- a/Scripts/Items/Skill Items/Ninjitsu/Shuriken.cs +++ b/Scripts/Items/Skill Items/Ninjitsu/Shuriken.cs @@ -69,7 +69,7 @@ namespace Server.Items } } - public bool ShowUsesRemaining + bool IUsesRemaining.ShowUsesRemaining { get => true; set { } diff --git a/Scripts/Items/Skill Items/Specialized/GlassblowingBook.cs b/Scripts/Items/Skill Items/Specialized/GlassblowingBook.cs index 8757df7df..e6fff9baf 100644 --- a/Scripts/Items/Skill Items/Specialized/GlassblowingBook.cs +++ b/Scripts/Items/Skill Items/Specialized/GlassblowingBook.cs @@ -38,7 +38,7 @@ namespace Server.Items { from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it. } - else if (pm == null || from.Skills[SkillName.Alchemy].Base < 100.0) + else if (pm == null || from.Skills.Alchemy.Base < 100.0) { pm.SendMessage("Only a Grandmaster Alchemist can learn from this book."); } diff --git a/Scripts/Items/Skill Items/Specialized/MasonryBook.cs b/Scripts/Items/Skill Items/Specialized/MasonryBook.cs index 05bd2acb7..47b8ca4c6 100644 --- a/Scripts/Items/Skill Items/Specialized/MasonryBook.cs +++ b/Scripts/Items/Skill Items/Specialized/MasonryBook.cs @@ -38,7 +38,7 @@ namespace Server.Items { from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it. } - else if (pm == null || from.Skills[SkillName.Carpentry].Base < 100.0) + else if (pm == null || from.Skills.Carpentry.Base < 100.0) { pm.SendMessage("Only a Grandmaster Carpenter can learn from this book."); } diff --git a/Scripts/Items/Skill Items/Specialized/SandMiningBook.cs b/Scripts/Items/Skill Items/Specialized/SandMiningBook.cs index 9e3927abb..1d983a0bf 100644 --- a/Scripts/Items/Skill Items/Specialized/SandMiningBook.cs +++ b/Scripts/Items/Skill Items/Specialized/SandMiningBook.cs @@ -38,7 +38,7 @@ namespace Server.Items { from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it. } - else if (pm == null || from.Skills[SkillName.Mining].Base < 100.0) + else if (pm == null || from.Skills.Mining.Base < 100.0) { pm.SendMessage("Only a Grandmaster Miner can learn from this book."); } diff --git a/Scripts/Items/Skill Items/Specialized/StoneMiningBook.cs b/Scripts/Items/Skill Items/Specialized/StoneMiningBook.cs index e8fe5a2b8..26350217c 100644 --- a/Scripts/Items/Skill Items/Specialized/StoneMiningBook.cs +++ b/Scripts/Items/Skill Items/Specialized/StoneMiningBook.cs @@ -38,7 +38,7 @@ namespace Server.Items { from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it. } - else if (pm == null || from.Skills[SkillName.Mining].Base < 100.0) + else if (pm == null || from.Skills.Mining.Base < 100.0) { from.SendMessage("Only a Grandmaster Miner can learn from this book."); } diff --git a/Scripts/Items/Skill Items/Tailor Items/Dyetubs/CustomHuePicker.cs b/Scripts/Items/Skill Items/Tailor Items/Dyetubs/CustomHuePicker.cs index 287b29287..2d03683c0 100644 --- a/Scripts/Items/Skill Items/Tailor Items/Dyetubs/CustomHuePicker.cs +++ b/Scripts/Items/Skill Items/Tailor Items/Dyetubs/CustomHuePicker.cs @@ -103,16 +103,16 @@ namespace Server.Items public string TitleString{ get; } } - public delegate void CustomHuePickerCallback(Mobile from, object state, int hue); + public delegate void CustomHuePickerCallback(Mobile from, T state, int hue); - public class CustomHuePickerGump : Gump + public class CustomHuePickerGump : Gump { - private CustomHuePickerCallback m_Callback; + private CustomHuePickerCallback m_Callback; private CustomHuePicker m_Definition; private Mobile m_From; - private object m_State; + private T m_State; - public CustomHuePickerGump(Mobile from, CustomHuePicker definition, CustomHuePickerCallback callback, object state) : + public CustomHuePickerGump(Mobile from, CustomHuePicker definition, CustomHuePickerCallback callback, T state) : base(50, 50) { m_From = from; diff --git a/Scripts/Items/Skill Items/Tailor Items/Dyetubs/MetallicHuePicker.cs b/Scripts/Items/Skill Items/Tailor Items/Dyetubs/MetallicHuePicker.cs index e20a80df9..16ef79bca 100644 --- a/Scripts/Items/Skill Items/Tailor Items/Dyetubs/MetallicHuePicker.cs +++ b/Scripts/Items/Skill Items/Tailor Items/Dyetubs/MetallicHuePicker.cs @@ -2,17 +2,15 @@ using Server.Gumps; using Server.Network; namespace Server.Items -{ - public class MetallicHuePicker : Gump +{ + public class MetallicHuePicker : Gump { - public delegate void MetallicHuePickerCallback(Mobile from, object state, int hue); - - private MetallicHuePickerCallback m_Callback; + private CustomHuePickerCallback m_Callback; private Mobile m_From; - private object m_State; + private T m_State; - public MetallicHuePicker(Mobile from, MetallicHuePickerCallback callback, object state) + public MetallicHuePicker(Mobile from, CustomHuePickerCallback callback, T state) : base(450, 450) { m_From = from; diff --git a/Scripts/Items/Skill Items/Tailor Items/Misc/Dyes.cs b/Scripts/Items/Skill Items/Tailor Items/Misc/Dyes.cs index ee2e9e81e..3e7e45065 100644 --- a/Scripts/Items/Skill Items/Tailor Items/Misc/Dyes.cs +++ b/Scripts/Items/Skill Items/Tailor Items/Misc/Dyes.cs @@ -59,9 +59,9 @@ namespace Server.Items { } - public virtual void SetTubHue(Mobile from, object state, int hue) + public virtual void SetTubHue(Mobile from, DyeTub tub, int hue) { - if (state is DyeTub tub) tub.DyedHue = hue; + tub.DyedHue = hue; } protected override void OnTarget(Mobile from, object targeted) @@ -71,9 +71,9 @@ namespace Server.Items if (tub.Redyable) { if (tub.MetallicHues) /* OSI has three metallic tubs now */ - from.SendGump(new MetallicHuePicker(from, SetTubHue, tub)); + from.SendGump(new MetallicHuePicker(from, SetTubHue, tub)); else if (tub.CustomHuePicker != null) - from.SendGump(new CustomHuePickerGump(from, tub.CustomHuePicker, SetTubHue, tub)); + from.SendGump(new CustomHuePickerGump(from, tub.CustomHuePicker, SetTubHue, tub)); else from.SendHuePicker(new InternalPicker(tub)); } diff --git a/Scripts/Items/Skill Items/Thief/DisguiseKit.cs b/Scripts/Items/Skill Items/Thief/DisguiseKit.cs index 71d371275..39ec80f1e 100644 --- a/Scripts/Items/Skill Items/Thief/DisguiseKit.cs +++ b/Scripts/Items/Skill Items/Thief/DisguiseKit.cs @@ -49,7 +49,7 @@ namespace Server.Items from.SendLocalizedMessage(501702); else if (Stealing.SuspendOnMurder && pm.Kills > 0) from.SendLocalizedMessage(501703); - else if (!from.CanBeginAction(typeof(IncognitoSpell))) + else if (!from.CanBeginAction()) from.SendLocalizedMessage(501704); else if (Sigil.ExistsOn(from)) from.SendLocalizedMessage(1010465); // You cannot disguise yourself while holding a sigil @@ -57,7 +57,7 @@ namespace Server.Items from.SendLocalizedMessage(1061634); else if (from.BodyMod == 183 || from.BodyMod == 184) from.SendLocalizedMessage(1040002); - else if (!from.CanBeginAction(typeof(PolymorphSpell)) || from.IsBodyMod) + else if (!from.CanBeginAction() || from.IsBodyMod) from.SendLocalizedMessage(501705); else return true; @@ -110,7 +110,7 @@ namespace Server.Items m_Kit = kit; m_Used = used; - from.CloseGump(typeof(DisguiseGump)); + from.CloseGump(); AddPage(0); diff --git a/Scripts/Items/Skill Items/Thief/LockPick.cs b/Scripts/Items/Skill Items/Thief/LockPick.cs index a7f7913be..989a624de 100644 --- a/Scripts/Items/Skill Items/Thief/LockPick.cs +++ b/Scripts/Items/Skill Items/Thief/LockPick.cs @@ -138,7 +138,7 @@ namespace Server.Items return; } - if (m_From.Skills[SkillName.Lockpicking].Value < m_Item.RequiredSkill) + if (m_From.Skills.Lockpicking.Value < m_Item.RequiredSkill) { /* // Do some training to gain skills diff --git a/Scripts/Items/Skill Items/Tinkering/Clocks.cs b/Scripts/Items/Skill Items/Tinkering/Clocks.cs index dcab00610..fc53ffded 100644 --- a/Scripts/Items/Skill Items/Tinkering/Clocks.cs +++ b/Scripts/Items/Skill Items/Tinkering/Clocks.cs @@ -46,9 +46,7 @@ namespace Server.Items public static MoonPhase GetMoonPhase(Map map, int x, int y) { - int hours, minutes, totalMinutes; - - GetTime(map, x, y, out hours, out minutes, out totalMinutes); + GetTime(map, x, y, out _, out _, out int totalMinutes); if (map != null) totalMinutes /= 10 + map.MapIndex * 20; @@ -58,9 +56,7 @@ namespace Server.Items public static void GetTime(Map map, int x, int y, out int hours, out int minutes) { - int totalMinutes; - - GetTime(map, x, y, out hours, out minutes, out totalMinutes); + GetTime(map, x, y, out hours, out minutes, out _); } public static void GetTime(Map map, int x, int y, out int hours, out int minutes, out int totalMinutes) @@ -91,9 +87,7 @@ namespace Server.Items public static void GetTime(Map map, int x, int y, out int generalNumber, out string exactTime) { - int hours, minutes; - - GetTime(map, x, y, out hours, out minutes); + GetTime(map, x, y, out int hours, out int minutes); // 00:00 AM - 00:59 AM : Witching hour // 01:00 AM - 03:59 AM : Middle of night @@ -131,10 +125,7 @@ namespace Server.Items public override void OnDoubleClick(Mobile from) { - int genericNumber; - string exactTime; - - GetTime(from, out genericNumber, out exactTime); + GetTime(from, out int genericNumber, out string exactTime); SendLocalizedMessageTo(from, genericNumber); SendLocalizedMessageTo(from, 1042958, exactTime); // ~1_TIME~ to be exact @@ -152,9 +143,6 @@ namespace Server.Items base.Deserialize(reader); int version = reader.ReadInt(); - - if (Weight == 2.0) - Weight = 3.0; } } diff --git a/Scripts/Items/Skill Items/Tinkering/Spyglass.cs b/Scripts/Items/Skill Items/Tinkering/Spyglass.cs index f426b1e05..85824e3c3 100644 --- a/Scripts/Items/Skill Items/Tinkering/Spyglass.cs +++ b/Scripts/Items/Skill Items/Tinkering/Spyglass.cs @@ -32,25 +32,28 @@ namespace Server.Items { QuestSystem qs = player.Quest; - if (qs is WitchApprenticeQuest) - if (qs.FindObjective(typeof(FindIngredientObjective)) is FindIngredientObjective obj && !obj.Completed && - obj.Ingredient == Ingredient.StarChart) + if (!(qs is WitchApprenticeQuest)) + return; + + FindIngredientObjective obj = qs.FindObjective(); + + if (obj?.Completed == false && obj.Ingredient == Ingredient.StarChart) + { + Clock.GetTime(from.Map, from.X, from.Y, out int hours, out int _); + + if (hours < 5 || hours > 17) { - Clock.GetTime(from.Map, from.X, from.Y, out int hours, out int _); + player.SendLocalizedMessage( + 1055040); // You gaze up into the glittering night sky. With great care, you compose a chart of the most prominent star patterns. - if (hours < 5 || hours > 17) - { - player.SendLocalizedMessage( - 1055040); // You gaze up into the glittering night sky. With great care, you compose a chart of the most prominent star patterns. - - obj.Complete(); - } - else - { - player.SendLocalizedMessage( - 1055039); // You gaze up into the sky, but it is not dark enough to see any stars. - } + obj.Complete(); } + else + { + player.SendLocalizedMessage( + 1055039); // You gaze up into the sky, but it is not dark enough to see any stars. + } + } } } diff --git a/Scripts/Items/Skill Items/Tools/BaseRunicTool.cs b/Scripts/Items/Skill Items/Tools/BaseRunicTool.cs index 49d255175..1d9dc0593 100644 --- a/Scripts/Items/Skill Items/Tools/BaseRunicTool.cs +++ b/Scripts/Items/Skill Items/Tools/BaseRunicTool.cs @@ -196,8 +196,7 @@ namespace Server.Items new List(attrs.Owner is Spellbook ? m_PossibleSpellbookSkills : m_PossibleBonusSkills); int count = Core.SE ? possibleSkills.Count : possibleSkills.Count - 2; - SkillName sk, check; - double bonus; + SkillName sk; bool found; do @@ -207,7 +206,7 @@ namespace Server.Items possibleSkills.Remove(sk); for (int i = 0; !found && i < 5; ++i) - found = attrs.GetValues(i, out check, out bonus) && check == sk; + found = attrs.GetValues(i, out SkillName check, out _) && check == sk; } while (found && count > 0); attrs.SetValues(index, sk, Scale(min, max, low, high)); @@ -431,7 +430,7 @@ namespace Server.Items public static void GetElementalDamages(BaseWeapon weapon, bool randomizeOrder) { - weapon.GetDamageTypes(null, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct); + weapon.GetDamageTypes(null, out int phys, out _, out _, out _, out _, out _, out _); int totalDamage = phys; diff --git a/Scripts/Items/Skill Items/Tools/BaseTool.cs b/Scripts/Items/Skill Items/Tools/BaseTool.cs index 861e052b6..bbeb337b2 100644 --- a/Scripts/Items/Skill Items/Tools/BaseTool.cs +++ b/Scripts/Items/Skill Items/Tools/BaseTool.cs @@ -85,10 +85,12 @@ namespace Server.Items } } - public bool ShowUsesRemaining + private bool ShowUsesRemaining{ get; set; } = true; + + bool IUsesRemaining.ShowUsesRemaining { - get => true; - set { } + get => ShowUsesRemaining; + set => ShowUsesRemaining = value; } public void ScaleUses() diff --git a/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs b/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs index 69ecbd4a7..6d174e2da 100644 --- a/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs +++ b/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs @@ -144,7 +144,7 @@ namespace Server.Items } else { - from.CloseGump(typeof(DawnsMusicBoxGump)); + from.CloseGump(); from.SendGump(new DawnsMusicBoxGump(this)); } } diff --git a/Scripts/Items/Special/Broken Furniture Collection/BrokenBed.cs b/Scripts/Items/Special/Broken Furniture Collection/BrokenBed.cs index 26b06e78c..6c5d084ee 100644 --- a/Scripts/Items/Special/Broken Furniture Collection/BrokenBed.cs +++ b/Scripts/Items/Special/Broken Furniture Collection/BrokenBed.cs @@ -66,7 +66,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Broken Furniture Collection/BrokenVanity.cs b/Scripts/Items/Special/Broken Furniture Collection/BrokenVanity.cs index e1c511d13..172891113 100644 --- a/Scripts/Items/Special/Broken Furniture Collection/BrokenVanity.cs +++ b/Scripts/Items/Special/Broken Furniture Collection/BrokenVanity.cs @@ -62,7 +62,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/PowderOfTemperament.cs b/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/PowderOfTemperament.cs index 962085c15..c8d9115fe 100644 --- a/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/PowderOfTemperament.cs +++ b/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/PowderOfTemperament.cs @@ -37,7 +37,7 @@ namespace Server.Items } } - public bool ShowUsesRemaining + bool IUsesRemaining.ShowUsesRemaining { get => true; set { } diff --git a/Scripts/Items/Special/Evil Home Decor Collection/AwesomeDisturbingPortrait.cs b/Scripts/Items/Special/Evil Home Decor Collection/AwesomeDisturbingPortrait.cs index 1306ee92e..2e593a33f 100644 --- a/Scripts/Items/Special/Evil Home Decor Collection/AwesomeDisturbingPortrait.cs +++ b/Scripts/Items/Special/Evil Home Decor Collection/AwesomeDisturbingPortrait.cs @@ -25,10 +25,7 @@ namespace Server.Items { if (Utility.InRange(Location, from.Location, 2)) { - int hours; - int minutes; - - Clock.GetTime(Map, X, Y, out hours, out minutes); + Clock.GetTime(Map, X, Y, out int hours, out int _); if (hours < 4 || hours > 20) Effects.PlaySound(Location, Map, 0x569); @@ -68,10 +65,7 @@ namespace Server.Items private void UpdateImage() { - int hours; - int minutes; - - Clock.GetTime(Map, X, Y, out hours, out minutes); + Clock.GetTime(Map, X, Y, out int hours, out int _); if (FacingSouth) { diff --git a/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs b/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs index ed9599e3e..dba94692e 100644 --- a/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs +++ b/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs @@ -140,11 +140,12 @@ namespace Server.Items int y = m_Mobile.Y + Utility.RandomMinMax(-1, 1); int z = m_Mobile.Z; - if (!m_Mobile.Map.CanFit(x, y, z, 1, false, false, true)) + if (!m_Mobile.Map.CanFit(x, y, z, 1, false, false)) { z = m_Mobile.Map.GetAverageZ(x, y); - if (!m_Mobile.Map.CanFit(x, y, z, 1, false, false, true)) continue; + if (!m_Mobile.Map.CanFit(x, y, z, 1, false, false)) + continue; } Blood blood = new Blood(Utility.RandomMinMax(0x122C, 0x122F)); diff --git a/Scripts/Items/Special/Gifts/HearthOfHomeFire.cs b/Scripts/Items/Special/Gifts/HearthOfHomeFire.cs index 19de05473..312025ba7 100644 --- a/Scripts/Items/Special/Gifts/HearthOfHomeFire.cs +++ b/Scripts/Items/Special/Gifts/HearthOfHomeFire.cs @@ -70,7 +70,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Gifts/TapestryOfSosaria.cs b/Scripts/Items/Special/Gifts/TapestryOfSosaria.cs index ea607dad7..7cf476ecb 100644 --- a/Scripts/Items/Special/Gifts/TapestryOfSosaria.cs +++ b/Scripts/Items/Special/Gifts/TapestryOfSosaria.cs @@ -36,7 +36,7 @@ namespace Server.Items { if (from.InRange(GetWorldLocation(), 2)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump()); } else diff --git a/Scripts/Items/Special/Heritage Items/Curtains.cs b/Scripts/Items/Special/Heritage Items/Curtains.cs index 2c006008d..131ba7d28 100644 --- a/Scripts/Items/Special/Heritage Items/Curtains.cs +++ b/Scripts/Items/Special/Heritage Items/Curtains.cs @@ -135,7 +135,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Heritage Items/Guillotine.cs b/Scripts/Items/Special/Heritage Items/Guillotine.cs index 71f1a54db..4bfd83c0b 100644 --- a/Scripts/Items/Special/Heritage Items/Guillotine.cs +++ b/Scripts/Items/Special/Heritage Items/Guillotine.cs @@ -54,7 +54,7 @@ namespace Server.Items { from.Location = Location; - Timer.DelayCall(TimeSpan.FromSeconds(0.5), new TimerStateCallback(Activate), new object[] { c, from }); + Timer.DelayCall(TimeSpan.FromSeconds(0.5), () => Activate(c, from)); } else { @@ -82,14 +82,6 @@ namespace Server.Items int version = reader.ReadEncodedInt(); } - private void Activate(object obj) - { - object[] param = (object[])obj; - - if (param[0] is AddonComponent component && param[1] is Mobile mobile) - Activate(component, mobile); - } - public virtual void Activate(AddonComponent c, Mobile from) { if (c.ItemID == 0x125E || c.ItemID == 0x1269 || c.ItemID == 0x1260) @@ -106,11 +98,11 @@ namespace Server.Items int y = c.Y + Utility.RandomMinMax(-1, 1); int z = c.Z; - if (!c.Map.CanFit(x, y, z, 1, false, false, true)) + if (!c.Map.CanFit(x, y, z, 1, false, false)) { z = c.Map.GetAverageZ(x, y); - if (!c.Map.CanFit(x, y, z, 1, false, false, true)) + if (!c.Map.CanFit(x, y, z, 1, false, false)) continue; } @@ -127,22 +119,19 @@ namespace Server.Items 501777); // Hmm... you suspect that if you used this again, it might hurt. SpellHelper.Damage(TimeSpan.Zero, from, Utility.Dice(2, 10, 5)); - Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 2, new TimerStateCallback(Deactivate), c); + Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 2, Deactivate, c); } - private void Deactivate(object obj) + private void Deactivate(AddonComponent c) { - if (obj is AddonComponent c) - { - if (c.ItemID == 0x1269) - c.ItemID = 0x1260; - else if (c.ItemID == 0x1260) - c.ItemID = 0x125E; - else if (c.ItemID == 0x1247) - c.ItemID = 0x1246; - else if (c.ItemID == 0x1246) - c.ItemID = 0x1230; - } + if (c.ItemID == 0x1269) + c.ItemID = 0x1260; + else if (c.ItemID == 0x1260) + c.ItemID = 0x125E; + else if (c.ItemID == 0x1247) + c.ItemID = 0x1246; + else if (c.ItemID == 0x1246) + c.ItemID = 0x1230; } } diff --git a/Scripts/Items/Special/Heritage Items/HangingAxes.cs b/Scripts/Items/Special/Heritage Items/HangingAxes.cs index ff322f2db..f682f4c0a 100644 --- a/Scripts/Items/Special/Heritage Items/HangingAxes.cs +++ b/Scripts/Items/Special/Heritage Items/HangingAxes.cs @@ -62,7 +62,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Heritage Items/HangingSwords.cs b/Scripts/Items/Special/Heritage Items/HangingSwords.cs index 6969722ee..c22df3f02 100644 --- a/Scripts/Items/Special/Heritage Items/HangingSwords.cs +++ b/Scripts/Items/Special/Heritage Items/HangingSwords.cs @@ -62,7 +62,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Heritage Items/HouseLadder.cs b/Scripts/Items/Special/Heritage Items/HouseLadder.cs index 7fbf47927..03d19c397 100644 --- a/Scripts/Items/Special/Heritage Items/HouseLadder.cs +++ b/Scripts/Items/Special/Heritage Items/HouseLadder.cs @@ -87,7 +87,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Heritage Items/IronMaiden.cs b/Scripts/Items/Special/Heritage Items/IronMaiden.cs index 023909312..3d8889f0a 100644 --- a/Scripts/Items/Special/Heritage Items/IronMaiden.cs +++ b/Scripts/Items/Special/Heritage Items/IronMaiden.cs @@ -26,8 +26,7 @@ namespace Server.Items from.Location = Location; c.ItemID = 0x124A; - Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 3, - new TimerStateCallback(Activate), new object[] { c, from }); + Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 3, () => Activate(c, from)); } else { @@ -55,58 +54,44 @@ namespace Server.Items int version = reader.ReadEncodedInt(); } - private void Activate(object obj) - { - object[] param = (object[])obj; - - if (param[0] is AddonComponent component && param[1] is Mobile mobile) - Activate(component, mobile); - } - public virtual void Activate(AddonComponent c, Mobile from) { c.ItemID += 1; - if (c.ItemID >= 0x124D) + if (c.ItemID < 0x124D) + return; + + // blood + int amount = Utility.RandomMinMax(3, 7); + + for (int i = 0; i < amount; i++) { - // blood - int amount = Utility.RandomMinMax(3, 7); + int x = c.X + Utility.RandomMinMax(-1, 1); + int y = c.Y + Utility.RandomMinMax(-1, 1); + int z = c.Z; - for (int i = 0; i < amount; i++) + if (!c.Map.CanFit(x, y, z, 1, false, false)) { - int x = c.X + Utility.RandomMinMax(-1, 1); - int y = c.Y + Utility.RandomMinMax(-1, 1); - int z = c.Z; + z = c.Map.GetAverageZ(x, y); - if (!c.Map.CanFit(x, y, z, 1, false, false, true)) - { - z = c.Map.GetAverageZ(x, y); - - if (!c.Map.CanFit(x, y, z, 1, false, false, true)) - continue; - } - - Blood blood = new Blood(Utility.RandomMinMax(0x122C, 0x122F)); - blood.MoveToWorld(new Point3D(x, y, z), c.Map); + if (!c.Map.CanFit(x, y, z, 1, false, false)) + continue; } - if (from.Female) - from.PlaySound(Utility.RandomMinMax(0x150, 0x153)); - else - from.PlaySound(Utility.RandomMinMax(0x15A, 0x15D)); - - from.LocalOverheadMessage(MessageType.Regular, 0, - 501777); // Hmm... you suspect that if you used this again, it might hurt. - SpellHelper.Damage(TimeSpan.Zero, from, Utility.Dice(2, 10, 5)); - - Timer.DelayCall(TimeSpan.FromSeconds(1), new TimerStateCallback(Deactivate), c); + Blood blood = new Blood(Utility.RandomMinMax(0x122C, 0x122F)); + blood.MoveToWorld(new Point3D(x, y, z), c.Map); } - } - private void Deactivate(object obj) - { - if (obj is AddonComponent component) - component.ItemID = 0x1249; + if (from.Female) + from.PlaySound(Utility.RandomMinMax(0x150, 0x153)); + else + from.PlaySound(Utility.RandomMinMax(0x15A, 0x15D)); + + from.LocalOverheadMessage(MessageType.Regular, 0, + 501777); // Hmm... you suspect that if you used this again, it might hurt. + SpellHelper.Damage(TimeSpan.Zero, from, Utility.Dice(2, 10, 5)); + + Timer.DelayCall(TimeSpan.FromSeconds(1), () => c.ItemID = 0x1249); } } diff --git a/Scripts/Items/Special/Heritage Items/Statue.cs b/Scripts/Items/Special/Heritage Items/Statue.cs index 829e04735..8148f5aa6 100644 --- a/Scripts/Items/Special/Heritage Items/Statue.cs +++ b/Scripts/Items/Special/Heritage Items/Statue.cs @@ -64,7 +64,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Heritage Items/UnmadeBed.cs b/Scripts/Items/Special/Heritage Items/UnmadeBed.cs index 0f1d4c785..72d89fcfa 100644 --- a/Scripts/Items/Special/Heritage Items/UnmadeBed.cs +++ b/Scripts/Items/Special/Heritage Items/UnmadeBed.cs @@ -66,7 +66,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Heritage Items/Vanity.cs b/Scripts/Items/Special/Heritage Items/Vanity.cs index c61bb25f0..1ac5570b4 100644 --- a/Scripts/Items/Special/Heritage Items/Vanity.cs +++ b/Scripts/Items/Special/Heritage Items/Vanity.cs @@ -59,7 +59,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/Heritage Items/WoodenCoffin.cs b/Scripts/Items/Special/Heritage Items/WoodenCoffin.cs index 9a6d233ca..ae377e151 100644 --- a/Scripts/Items/Special/Heritage Items/WoodenCoffin.cs +++ b/Scripts/Items/Special/Heritage Items/WoodenCoffin.cs @@ -91,7 +91,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else diff --git a/Scripts/Items/Special/HeritageToken.cs b/Scripts/Items/Special/HeritageToken.cs index 76fa9767d..c101446aa 100644 --- a/Scripts/Items/Special/HeritageToken.cs +++ b/Scripts/Items/Special/HeritageToken.cs @@ -25,7 +25,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(HeritageTokenGump)); + from.CloseGump(); from.SendGump(new HeritageTokenGump(this)); } else diff --git a/Scripts/Items/Special/Holiday/Christmas/HolidayTree.cs b/Scripts/Items/Special/Holiday/Christmas/HolidayTree.cs index e58012b65..4707cb735 100644 --- a/Scripts/Items/Special/Holiday/Christmas/HolidayTree.cs +++ b/Scripts/Items/Special/Holiday/Christmas/HolidayTree.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Multis; namespace Server.Items @@ -12,7 +13,7 @@ namespace Server.Items public class HolidayTree : Item, IAddon { - private ArrayList m_Components; + private List m_Components; public HolidayTree(Mobile from, HolidayTreeType type, Point3D loc) : base(1) { @@ -20,7 +21,7 @@ namespace Server.Items MoveToWorld(loc, from.Map); Placer = from; - m_Components = new ArrayList(); + m_Components = new List(); switch (type) { @@ -112,7 +113,7 @@ namespace Server.Items public override void OnAfterDelete() { for (int i = 0; i < m_Components.Count; ++i) - ((Item)m_Components[i]).Delete(); + m_Components[i].Delete(); } private void AddOrnament(int x, int y, int z, int itemID) @@ -138,7 +139,7 @@ namespace Server.Items writer.Write(m_Components.Count); for (int i = 0; i < m_Components.Count; ++i) - writer.Write((Item)m_Components[i]); + writer.Write(m_Components[i]); } public override void Deserialize(GenericReader reader) @@ -159,7 +160,7 @@ namespace Server.Items { int count = reader.ReadInt(); - m_Components = new ArrayList(count); + m_Components = new List(count); for (int i = 0; i < count; ++i) { @@ -178,9 +179,7 @@ namespace Server.Items public void ValidatePlacement() { - BaseHouse house = BaseHouse.FindHouseAt(this); - - if (house == null) + if (BaseHouse.FindHouseAt(this) == null) { HolidayTreeDeed deed = new HolidayTreeDeed(); deed.MoveToWorld(Location, Map); @@ -201,7 +200,8 @@ namespace Server.Items BaseHouse house = BaseHouse.FindHouseAt(this); - if (house != null && house.Addons.Contains(this)) house.Addons.Remove(this); + if (house?.Addons.Contains(this) == true) + house.Addons.Remove(this); from.SendLocalizedMessage(503393); // A deed for the tree has been placed in your backpack. } diff --git a/Scripts/Items/Special/Holiday/HolidayPottedPlant.cs b/Scripts/Items/Special/Holiday/HolidayPottedPlant.cs index 8bf3dfeaf..29333aafa 100644 --- a/Scripts/Items/Special/Holiday/HolidayPottedPlant.cs +++ b/Scripts/Items/Special/Holiday/HolidayPottedPlant.cs @@ -60,7 +60,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -93,7 +93,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Special/Holiday/IcyPatch.cs b/Scripts/Items/Special/Holiday/IcyPatch.cs index a14d765dc..f1aa2b058 100644 --- a/Scripts/Items/Special/Holiday/IcyPatch.cs +++ b/Scripts/Items/Special/Holiday/IcyPatch.cs @@ -48,60 +48,51 @@ namespace Server.Items public virtual void RunSequence(Mobile m, int message, bool freeze) { - object[] arg = null; - if (freeze) { m.Frozen = true; - Timer.DelayCall(TimeSpan.FromSeconds(message == 1095162 ? 2.0 : 1.25), - new TimerStateCallback(EndFall_Callback), m); + Timer.DelayCall(TimeSpan.FromSeconds(message == 1095162 ? 2.0 : 1.25), EndFall_Callback, m); } m.SendLocalizedMessage(message); + + int action = 0; + int sound = 0; if (message == 1095162) { - if (m.Mounted) m.Mount.Rider = null; + if (m.Mounted) + m.Mount.Rider = null; Point3D p = new Point3D(Location); if (SpellHelper.FindValidSpawnLocation(Map, ref p, true)) - Timer.DelayCall(TimeSpan.FromSeconds(0), new TimerStateCallback(Relocate_Callback), - new object[] { m, p }); + Timer.DelayCall(TimeSpan.FromSeconds(0), () => m.MoveToWorld(p, m.Map)); - arg = new object[] { m, 21 + Utility.Random(2), !m.Female ? 0x426 : 0x317 }; + action = 21 + Utility.Random(2); + sound = m.Female ? 0x317 : 0x426; } else if (message == 1095161) { - arg = new object[] { m, 17, !m.Female ? 0x429 : 0x319 }; + action = 17; + sound = m.Female ? 0x319 : 0x429; } - if (arg != null) Timer.DelayCall(TimeSpan.FromSeconds(.4), new TimerStateCallback(BeginFall_Callback), arg); + if (action > 0) + Timer.DelayCall(TimeSpan.FromSeconds(0.4), from => BeginFall_Callback(from, action, sound), m); } - private static void Relocate_Callback(object state) + private static void BeginFall_Callback(Mobile m, int action, int sound) { - object[] states = (object[])state; - Mobile m = (Mobile)states[0]; - Point3D to = (Point3D)states[1]; - - m.MoveToWorld(to, m.Map); - } - - private static void BeginFall_Callback(object state) - { - object[] states = (object[])state; - - Mobile m = (Mobile)states[0]; - int action = (int)states[1]; - int sound = (int)states[2]; - if (!m.Mounted) m.Animate(action, 1, 1, false, true, 0); + if (!m.Mounted) + m.Animate(action, 1, 1, false, true, 0); + m.PlaySound(sound); } - private static void EndFall_Callback(object state) + private static void EndFall_Callback(Mobile m) { - ((Mobile)state).Frozen = false; + m.Frozen = false; } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Items/Special/Holiday/SnowStatue.cs b/Scripts/Items/Special/Holiday/SnowStatue.cs index c3238c1a6..6f91c3460 100644 --- a/Scripts/Items/Special/Holiday/SnowStatue.cs +++ b/Scripts/Items/Special/Holiday/SnowStatue.cs @@ -148,7 +148,7 @@ namespace Server.Items { if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -181,7 +181,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Special/Holiday/Wreath.cs b/Scripts/Items/Special/Holiday/Wreath.cs index 3465edbc9..76adde2ae 100644 --- a/Scripts/Items/Special/Holiday/Wreath.cs +++ b/Scripts/Items/Special/Holiday/Wreath.cs @@ -105,7 +105,7 @@ namespace Server.Items { if (from.InRange(GetWorldLocation(), 3)) { - from.CloseGump(typeof(WreathAddonGump)); + from.CloseGump(); from.SendGump(new WreathAddonGump(from, this)); } else @@ -202,7 +202,7 @@ namespace Server.Items if (house != null && house.IsCoOwner(from)) { from.SendLocalizedMessage(1062838); // Where would you like to place this decoration? - from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget, null); + from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget); } else { @@ -215,7 +215,7 @@ namespace Server.Items } } - public void Placement_OnTarget(Mobile from, object targeted, object state) + public void Placement_OnTarget(Mobile from, object targeted) { if (!(targeted is IPoint3D p)) return; diff --git a/Scripts/Items/Special/House Raffle/HouseRaffleDeed.cs b/Scripts/Items/Special/House Raffle/HouseRaffleDeed.cs index 8e7fbb7e7..8832dc86c 100644 --- a/Scripts/Items/Special/House Raffle/HouseRaffleDeed.cs +++ b/Scripts/Items/Special/House Raffle/HouseRaffleDeed.cs @@ -118,7 +118,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(WritOfLeaseGump)); + from.CloseGump(); from.SendGump(new WritOfLeaseGump(this)); } else diff --git a/Scripts/Items/Special/House Raffle/HouseRaffleRegion.cs b/Scripts/Items/Special/House Raffle/HouseRaffleRegion.cs index 954427ce2..ced944ec7 100644 --- a/Scripts/Items/Special/House Raffle/HouseRaffleRegion.cs +++ b/Scripts/Items/Special/House Raffle/HouseRaffleRegion.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Linq; using Server.Items; using Server.Spells.Sixth; diff --git a/Scripts/Items/Special/House Raffle/HouseRaffleStone.cs b/Scripts/Items/Special/House Raffle/HouseRaffleStone.cs index 441ba9da8..e12da6ef0 100644 --- a/Scripts/Items/Special/House Raffle/HouseRaffleStone.cs +++ b/Scripts/Items/Special/House Raffle/HouseRaffleStone.cs @@ -447,10 +447,10 @@ namespace Server.Items else from.SendGump(new WarningGump(1150470, 0x7F00, $"You are about to purchase a raffle ticket for the house plot located at {FormatLocation()}. The ticket price is {FormatPrice()}. Tickets are non-refundable and you can only purchase one ticket per account. Do you wish to continue?", - 0xFFFFFF, 420, 280, Purchase_Callback, null)); // CONFIRM TICKET PURCHASE + 0xFFFFFF, 420, 280, okay => Purchase_Callback(from, okay))); // CONFIRM TICKET PURCHASE } - public void Purchase_Callback(Mobile from, bool okay, object state) + public void Purchase_Callback(Mobile from, bool okay) { if (Deleted || m_State != HouseRaffleState.Active || !from.CheckAlive() || HasEntered(from) || IsAtIPLimit(from)) return; diff --git a/Scripts/Items/Special/Solen Items/BagOfSending.cs b/Scripts/Items/Special/Solen Items/BagOfSending.cs index a8240b0fb..fc5733db4 100644 --- a/Scripts/Items/Special/Solen Items/BagOfSending.cs +++ b/Scripts/Items/Special/Solen Items/BagOfSending.cs @@ -143,7 +143,7 @@ namespace Server.Items public override void OnDoubleClick(Mobile from) { - if (from.Region.IsPartOf(typeof(Jail))) + if (from.Region.IsPartOf()) from.SendMessage("You may not do that in jail."); else if (!IsChildOf(from.Backpack)) MessageHelper.SendLocalizedMessageTo(this, from, 1062334, @@ -226,7 +226,7 @@ namespace Server.Items if (m_Bag.Deleted) return; - if (from.Region.IsPartOf(typeof(Jail))) + if (from.Region.IsPartOf()) { from.SendMessage("You may not do that in jail."); } diff --git a/Scripts/Items/Special/Solen Items/BallOfSummoning.cs b/Scripts/Items/Special/Solen Items/BallOfSummoning.cs index cf562c1f8..562712cfc 100644 --- a/Scripts/Items/Special/Solen Items/BallOfSummoning.cs +++ b/Scripts/Items/Special/Solen Items/BallOfSummoning.cs @@ -201,8 +201,8 @@ namespace Server.Items MessageHelper.SendLocalizedMessageTo(this, from, 1054127, 0x22); // The Crystal Ball fills with a red mist. You appear to have let your bond to your pet deteriorate. } - else if (from.Map == Map.Ilshenar || from.Region.IsPartOf(typeof(DungeonRegion)) || - from.Region.IsPartOf(typeof(Jail)) || from.Region.IsPartOf(typeof(SafeZone))) + else if (from.Map == Map.Ilshenar || from.Region.IsPartOf() || + from.Region.IsPartOf() || from.Region.IsPartOf()) { from.Send(new AsciiMessage(Serial, ItemID, MessageType.Regular, 0x22, 3, "", "You cannot summon your pet to this location.")); @@ -438,7 +438,7 @@ namespace Server.Items public void Stop() { m_Stop = true; - Disturb(DisturbType.Hurt, false, false); + Disturb(DisturbType.Hurt, false); } public override bool CheckDisturb(DisturbType type, bool checkFirst, bool resistable) diff --git a/Scripts/Items/Special/Solen Items/BraceletOfBinding.cs b/Scripts/Items/Special/Solen Items/BraceletOfBinding.cs index 0a431e1bb..716a60512 100644 --- a/Scripts/Items/Special/Solen Items/BraceletOfBinding.cs +++ b/Scripts/Items/Special/Solen Items/BraceletOfBinding.cs @@ -255,13 +255,13 @@ namespace Server.Items return false; } - if (from.Region.IsPartOf(typeof(Jail))) + if (from.Region.IsPartOf()) { from.SendLocalizedMessage(1114345, "", 0x35); // You'll need a better jailbreak plan than that! return false; } - if (boundRoot.Region.IsPartOf(typeof(Jail))) + if (boundRoot.Region.IsPartOf()) { from.SendLocalizedMessage(1019004); // You are not allowed to travel there. return false; diff --git a/Scripts/Items/Special/SoulStone.cs b/Scripts/Items/Special/SoulStone.cs index 79127461c..fd7cd28a7 100644 --- a/Scripts/Items/Special/SoulStone.cs +++ b/Scripts/Items/Special/SoulStone.cs @@ -248,11 +248,11 @@ namespace Server.Items if (!CheckUse(from)) return; - from.CloseGump(typeof(SelectSkillGump)); - from.CloseGump(typeof(ConfirmSkillGump)); - from.CloseGump(typeof(ConfirmTransferGump)); - from.CloseGump(typeof(ConfirmRemovalGump)); - from.CloseGump(typeof(ErrorGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); if (IsEmpty) from.SendGump(new SelectSkillGump(this, from)); @@ -877,7 +877,7 @@ namespace Server.Items } - public bool ShowUsesRemaining + bool IUsesRemaining.ShowUsesRemaining { get => true; set { } diff --git a/Scripts/Items/Special/Special Scrolls/ScrollofAlacrity.cs b/Scripts/Items/Special/Special Scrolls/ScrollofAlacrity.cs index bd4ba6543..710d2764a 100644 --- a/Scripts/Items/Special/Special Scrolls/ScrollofAlacrity.cs +++ b/Scripts/Items/Special/Special Scrolls/ScrollofAlacrity.cs @@ -1,39 +1,14 @@ -/*************************************************************************** -* ScrollofAlacrity.cs -* ------------------- -* begin : June 1, 2009 -* copyright : (C) Shai'Tan Malkier aka Callandor2k -* email : ShaiTanMalkier@gmail.com -* -* $Id: ScrollofAlacrity.cs 1 2009-06-1 04:28:39Z Callandor2k $ -* -***************************************************************************/ - -/*************************************************************************** -* -* This Script/File is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -***************************************************************************/ - using System; -using System.Collections; +using Server.Engines.MLQuests; +using Server.Engines.MLQuests.Objectives; using Server.Mobiles; namespace Server.Items { public class ScrollofAlacrity : SpecialScroll { - private static Hashtable m_Table = new Hashtable(); - - public ScrollofAlacrity() : this(SkillName.Alchemy) - { - } - [Constructible] - public ScrollofAlacrity(SkillName skill) : base(skill, 0.0) + public ScrollofAlacrity(SkillName skill = SkillName.Alchemy) : base(skill, 0.0) { ItemID = 0x14EF; Hue = 0x4AB; @@ -61,55 +36,41 @@ namespace Server.Items public override bool CanUse(Mobile from) { - if (!base.CanUse(from)) - return false; - - if (!(from is PlayerMobile pm)) + if (!(base.CanUse(from) && from is PlayerMobile pm)) return false; #region Mondain's Legacy + MLQuestContext context = MLQuestSystem.GetContext(pm); - /* to add when skillgain quests will be implemented - - for (int i = pm.Quests.Count - 1; i >= 0; i--) + if (context != null) { - BaseQuest quest = pm.Quests[i]; - - for (int j = quest.Objectives.Count - 1; j >= 0; j--) + foreach (MLQuestInstance instance in context.QuestInstances) { - BaseObjective objective = quest.Objectives[j]; - - if (objective is ApprenticeObjective) + foreach (BaseObjectiveInstance objective in instance.Objectives) { - from.SendMessage("You are already under the effect of an enhanced skillgain quest."); - return false; + if (!objective.Expired && objective is GainSkillObjectiveInstance objectiveInstance && + objectiveInstance.Handles(Skill)) + { + from.SendMessage("You are already under the effect of an enhanced skillgain quest."); + return false; + } } } } - - */ - #endregion - #region Scroll of Alacrity - if (pm.AcceleratedStart > DateTime.UtcNow) { from.SendLocalizedMessage(1077951); // You are already under the effect of an accelerated skillgain scroll. return false; } - #endregion - return true; } public override void Use(Mobile from) { - if (!CanUse(from)) - return; - - if (!(from is PlayerMobile pm)) + if (!(CanUse(from) && from is PlayerMobile pm)) return; double tskill = from.Skills[Skill].Base; @@ -130,21 +91,17 @@ namespace Server.Items Effects.SendTargetParticles(from, 0x373A, 35, 45, 0x00, 0x00, 9502, (EffectLayer)255, 0x100); pm.AcceleratedStart = DateTime.UtcNow + TimeSpan.FromMinutes(15); - m_Table[from] = Timer.DelayCall(TimeSpan.FromMinutes(15), new TimerStateCallback(Expire_Callback), from); + Timer.DelayCall(TimeSpan.FromMinutes(15), Expire_Callback, from); pm.AcceleratedSkill = Skill; Delete(); } - private static void Expire_Callback(object state) + // TODO: Handle this upon deserialization. Create Dictionary and serialize Mobile/Timers? + private static void Expire_Callback(Mobile m) { - Mobile m = (Mobile)state; - - m_Table.Remove(m); - m.PlaySound(0x1F8); - m.SendLocalizedMessage( 1077957); // The intense energy dissipates. You are no longer under the effects of an accelerated skillgain scroll. } @@ -166,4 +123,4 @@ namespace Server.Items Insured = false; } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Special/Special Scrolls/ScrollofTranscendence.cs b/Scripts/Items/Special/Special Scrolls/ScrollofTranscendence.cs index 45eef49a6..281962fcd 100644 --- a/Scripts/Items/Special/Special Scrolls/ScrollofTranscendence.cs +++ b/Scripts/Items/Special/Special Scrolls/ScrollofTranscendence.cs @@ -1,16 +1,14 @@ using System; +using Server.Engines.MLQuests; +using Server.Engines.MLQuests.Objectives; using Server.Mobiles; namespace Server.Items { public class ScrollofTranscendence : SpecialScroll { - public ScrollofTranscendence() : this(SkillName.Alchemy, 0.0) - { - } - [Constructible] - public ScrollofTranscendence(SkillName skill, double value) : base(skill, value) + public ScrollofTranscendence(SkillName skill = SkillName.Alchemy, double value = 0.0) : base(skill, value) { ItemID = 0x14EF; Hue = 0x490; @@ -49,46 +47,35 @@ namespace Server.Items public override bool CanUse(Mobile from) { - if (!base.CanUse(from)) - return false; - - if (!(from is PlayerMobile pm)) + if (!(base.CanUse(from) && from is PlayerMobile pm)) return false; #region Mondain's Legacy + MLQuestContext context = MLQuestSystem.GetContext(pm); - /* to add when skillgain quests will be implemented - - for (int i = pm.Quests.Count - 1; i >= 0; i--) + if (context != null) { - BaseQuest quest = pm.Quests[i]; - - for (int j = quest.Objectives.Count - 1; j >= 0; j--) + foreach (MLQuestInstance instance in context.QuestInstances) { - BaseObjective objective = quest.Objectives[j]; - - if (objective is ApprenticeObjective) + foreach (BaseObjectiveInstance objective in instance.Objectives) { - from.SendMessage("You are already under the effect of an enhanced skillgain quest."); - return false; + if (!objective.Expired && objective is GainSkillObjectiveInstance objectiveInstance && + objectiveInstance.Handles(Skill)) + { + from.SendMessage("You are already under the effect of an enhanced skillgain quest."); + return false; + } } } } - - */ - #endregion - #region Scroll of Alacrity - if (pm.AcceleratedStart > DateTime.UtcNow) { from.SendLocalizedMessage(1077951); // You are already under the effect of an accelerated skillgain scroll. return false; } - #endregion - return true; } @@ -167,4 +154,4 @@ namespace Server.Items Hue = 0x490; } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Special/Special Scrolls/SpecialScroll.cs b/Scripts/Items/Special/Special Scrolls/SpecialScroll.cs index 0313e104e..dd11d3a0a 100644 --- a/Scripts/Items/Special/Special Scrolls/SpecialScroll.cs +++ b/Scripts/Items/Special/Special Scrolls/SpecialScroll.cs @@ -74,7 +74,7 @@ namespace Server.Items if (!CanUse(from)) return; - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(from, this)); } diff --git a/Scripts/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs b/Scripts/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs index 89392930e..9b77fb989 100644 --- a/Scripts/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs +++ b/Scripts/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs @@ -73,7 +73,7 @@ namespace Server.Items } else { - m.CloseGump(typeof(AnkhResurrectGump)); + m.CloseGump(); m.SendGump(new AnkhResurrectGump(m, ResurrectMessage.VirtueShrine)); } } @@ -310,7 +310,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(RewardOptionGump)); + from.CloseGump(); from.SendGump(new RewardOptionGump(this)); } else diff --git a/Scripts/Items/Special/Veteran Rewards/Banner.cs b/Scripts/Items/Special/Veteran Rewards/Banner.cs index 2348304d7..295770fcf 100644 --- a/Scripts/Items/Special/Veteran Rewards/Banner.cs +++ b/Scripts/Items/Special/Veteran Rewards/Banner.cs @@ -83,7 +83,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(RewardDemolitionGump)); + from.CloseGump(); from.SendGump(new RewardDemolitionGump(this, 1018318)); // Do you wish to re-deed this banner? } else @@ -164,7 +164,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -209,7 +209,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); @@ -296,7 +296,7 @@ namespace Server.Items if (north && west) { - from.CloseGump(typeof(FacingGump)); + from.CloseGump(); from.SendGump(new FacingGump(m_Banner, m_ItemID, p3d, house)); } else if (north || west) @@ -352,7 +352,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Special/Veteran Rewards/Brazier.cs b/Scripts/Items/Special/Veteran Rewards/Brazier.cs index 9ffb87013..e3b826dfd 100644 --- a/Scripts/Items/Special/Veteran Rewards/Brazier.cs +++ b/Scripts/Items/Special/Veteran Rewards/Brazier.cs @@ -168,7 +168,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -213,7 +213,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Special/Veteran Rewards/Cannon.cs b/Scripts/Items/Special/Veteran Rewards/Cannon.cs index 3cc4cabaf..a530d5cd5 100644 --- a/Scripts/Items/Special/Veteran Rewards/Cannon.cs +++ b/Scripts/Items/Special/Veteran Rewards/Cannon.cs @@ -334,7 +334,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); @@ -455,7 +455,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(RewardOptionGump)); + from.CloseGump(); from.SendGump(new RewardOptionGump(this)); } else diff --git a/Scripts/Items/Special/Veteran Rewards/DecorativeShield.cs b/Scripts/Items/Special/Veteran Rewards/DecorativeShield.cs index 8cff94aea..c31a93d34 100644 --- a/Scripts/Items/Special/Veteran Rewards/DecorativeShield.cs +++ b/Scripts/Items/Special/Veteran Rewards/DecorativeShield.cs @@ -86,7 +86,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(RewardDemolitionGump)); + from.CloseGump(); from.SendGump(new RewardDemolitionGump(this, 1049783)); // Do you wish to re-deed this decoration? } else @@ -163,7 +163,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -217,7 +217,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); @@ -312,7 +312,7 @@ namespace Server.Items if (north && west) { - from.CloseGump(typeof(FacingGump)); + from.CloseGump(); from.SendGump(new FacingGump(m_Shield, m_ItemID, p3d, house)); } else if (north || west) @@ -368,7 +368,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Special/Veteran Rewards/FlamingHead.cs b/Scripts/Items/Special/Veteran Rewards/FlamingHead.cs index a6451bb21..764c9098f 100644 --- a/Scripts/Items/Special/Veteran Rewards/FlamingHead.cs +++ b/Scripts/Items/Special/Veteran Rewards/FlamingHead.cs @@ -84,7 +84,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(RewardDemolitionGump)); + from.CloseGump(); from.SendGump(new RewardDemolitionGump(this, 1018329)); // Do you wish to re-deed this skull? } else diff --git a/Scripts/Items/Special/Veteran Rewards/HangingSkeleton.cs b/Scripts/Items/Special/Veteran Rewards/HangingSkeleton.cs index 204dcd8d9..a2ff0091d 100644 --- a/Scripts/Items/Special/Veteran Rewards/HangingSkeleton.cs +++ b/Scripts/Items/Special/Veteran Rewards/HangingSkeleton.cs @@ -88,7 +88,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(RewardDemolitionGump)); + from.CloseGump(); from.SendGump(new RewardDemolitionGump(this, 1049783)); // Do you wish to re-deed this decoration? } else @@ -169,7 +169,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -221,7 +221,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); @@ -304,7 +304,7 @@ namespace Server.Items if (north && west) { - from.CloseGump(typeof(FacingGump)); + from.CloseGump(); from.SendGump(new FacingGump(m_Skeleton, m_ItemID, p3d, house)); } else if (north || west) @@ -360,7 +360,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Special/Veteran Rewards/MiningCart.cs b/Scripts/Items/Special/Veteran Rewards/MiningCart.cs index 0e4b6d36d..3a5a775a1 100644 --- a/Scripts/Items/Special/Veteran Rewards/MiningCart.cs +++ b/Scripts/Items/Special/Veteran Rewards/MiningCart.cs @@ -409,7 +409,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(RewardOptionGump)); + from.CloseGump(); from.SendGump(new RewardOptionGump(this)); } else diff --git a/Scripts/Items/Special/Veteran Rewards/MinotaurStatue.cs b/Scripts/Items/Special/Veteran Rewards/MinotaurStatue.cs index 9386e8b38..53dede4a0 100644 --- a/Scripts/Items/Special/Veteran Rewards/MinotaurStatue.cs +++ b/Scripts/Items/Special/Veteran Rewards/MinotaurStatue.cs @@ -150,7 +150,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(RewardOptionGump)); + from.CloseGump(); from.SendGump(new RewardOptionGump(this)); } else diff --git a/Scripts/Items/Special/Veteran Rewards/PottedCactus.cs b/Scripts/Items/Special/Veteran Rewards/PottedCactus.cs index 9884cacac..d1d2ac356 100644 --- a/Scripts/Items/Special/Veteran Rewards/PottedCactus.cs +++ b/Scripts/Items/Special/Veteran Rewards/PottedCactus.cs @@ -95,7 +95,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -141,7 +141,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Special/Veteran Rewards/StoneAnkh.cs b/Scripts/Items/Special/Veteran Rewards/StoneAnkh.cs index e26a9ab32..fb3acdc51 100644 --- a/Scripts/Items/Special/Veteran Rewards/StoneAnkh.cs +++ b/Scripts/Items/Special/Veteran Rewards/StoneAnkh.cs @@ -112,7 +112,7 @@ namespace Server.Items if (house != null && house.IsOwner(from)) { - from.CloseGump(typeof(RewardDemolitionGump)); + from.CloseGump(); from.SendGump(new RewardDemolitionGump(this, 1049783)); // Do you wish to re-deed this decoration? } else @@ -192,7 +192,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -242,7 +242,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Special/Veteran Rewards/TreeStump.cs b/Scripts/Items/Special/Veteran Rewards/TreeStump.cs index cc72e9796..38ec47364 100644 --- a/Scripts/Items/Special/Veteran Rewards/TreeStump.cs +++ b/Scripts/Items/Special/Veteran Rewards/TreeStump.cs @@ -280,7 +280,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(RewardOptionGump)); + from.CloseGump(); from.SendGump(new RewardOptionGump(this)); } else diff --git a/Scripts/Items/Special/Veteran Rewards/WallBanner.cs b/Scripts/Items/Special/Veteran Rewards/WallBanner.cs index b1a01a789..48bcd1fce 100644 --- a/Scripts/Items/Special/Veteran Rewards/WallBanner.cs +++ b/Scripts/Items/Special/Veteran Rewards/WallBanner.cs @@ -317,7 +317,7 @@ namespace Server.Items if (IsChildOf(from.Backpack)) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(this)); } else @@ -361,7 +361,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddBackground(25, 0, 500, 265, 0xA28); diff --git a/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs b/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs index c5f3c9422..cb4566041 100644 --- a/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs +++ b/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs @@ -54,7 +54,7 @@ namespace Server.Items } } - public virtual bool ShowUsesRemaining + public bool ShowUsesRemaining { get => true; set { } @@ -211,7 +211,7 @@ namespace Server.Items if (targeted is BaseWeapon item) { - from.CloseGump(typeof(InternalGump)); + from.CloseGump(); from.SendGump(new InternalGump(m_Tool, item)); } else @@ -233,7 +233,7 @@ namespace Server.Items Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddBackground(50, 50, 400, 300, 0xA28); @@ -310,7 +310,7 @@ namespace Server.Items Closable = false; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; AddPage(0); diff --git a/Scripts/Items/Talismans/BaseTalisman.cs b/Scripts/Items/Talismans/BaseTalisman.cs index 579091b0f..be0f82ae3 100644 --- a/Scripts/Items/Talismans/BaseTalisman.cs +++ b/Scripts/Items/Talismans/BaseTalisman.cs @@ -42,8 +42,8 @@ namespace Server.Items m_Protection = new TalismanAttribute(); m_Killer = new TalismanAttribute(); m_Summoner = new TalismanAttribute(); - m_AosAttributes = new AosAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); + Attributes = new AosAttributes(this); + SkillBonuses = new AosSkillBonuses(this); } public BaseTalisman(Serial serial) @@ -135,8 +135,8 @@ namespace Server.Items talisman.m_Summoner = new TalismanAttribute(m_Summoner); talisman.m_Protection = new TalismanAttribute(m_Protection); talisman.m_Killer = new TalismanAttribute(m_Killer); - talisman.m_AosAttributes = new AosAttributes(newItem, m_AosAttributes); - talisman.m_AosSkillBonuses = new AosSkillBonuses(newItem, m_AosSkillBonuses); + talisman.Attributes = new AosAttributes(newItem, Attributes); + talisman.SkillBonuses = new AosSkillBonuses(newItem, SkillBonuses); } public override bool CanEquip(Mobile from) @@ -154,8 +154,8 @@ namespace Server.Items { if (parent is Mobile from) { - m_AosSkillBonuses.AddTo(from); - m_AosAttributes.AddStatBonuses(from); + SkillBonuses.AddTo(from); + Attributes.AddStatBonuses(from); if (m_Blessed && BlessedFor == null) { @@ -177,8 +177,8 @@ namespace Server.Items { if (parent is Mobile from) { - m_AosSkillBonuses.Remove(); - m_AosAttributes.RemoveStatBonuses(from); + SkillBonuses.Remove(); + Attributes.RemoveStatBonuses(from); if (m_Creature != null && !m_Creature.Deleted) { @@ -348,80 +348,80 @@ namespace Server.Items list.Add(1072394, "#{0}\t{1}", AosSkillBonuses.GetLabel(m_Skill), m_SuccessBonus); // ~1_NAME~ Bonus: ~2_val~% - m_AosSkillBonuses.GetProperties(list); + SkillBonuses.GetProperties(list); int prop; - if ((prop = m_AosAttributes.WeaponDamage) != 0) + if ((prop = Attributes.WeaponDamage) != 0) list.Add(1060401, prop.ToString()); // damage increase ~1_val~% - if ((prop = m_AosAttributes.DefendChance) != 0) + if ((prop = Attributes.DefendChance) != 0) list.Add(1060408, prop.ToString()); // defense chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusDex) != 0) + if ((prop = Attributes.BonusDex) != 0) list.Add(1060409, prop.ToString()); // dexterity bonus ~1_val~ - if ((prop = m_AosAttributes.EnhancePotions) != 0) + if ((prop = Attributes.EnhancePotions) != 0) list.Add(1060411, prop.ToString()); // enhance potions ~1_val~% - if ((prop = m_AosAttributes.CastRecovery) != 0) + if ((prop = Attributes.CastRecovery) != 0) list.Add(1060412, prop.ToString()); // faster cast recovery ~1_val~ - if ((prop = m_AosAttributes.CastSpeed) != 0) + if ((prop = Attributes.CastSpeed) != 0) list.Add(1060413, prop.ToString()); // faster casting ~1_val~ - if ((prop = m_AosAttributes.AttackChance) != 0) + if ((prop = Attributes.AttackChance) != 0) list.Add(1060415, prop.ToString()); // hit chance increase ~1_val~% - if ((prop = m_AosAttributes.BonusHits) != 0) + if ((prop = Attributes.BonusHits) != 0) list.Add(1060431, prop.ToString()); // hit point increase ~1_val~ - if ((prop = m_AosAttributes.BonusInt) != 0) + if ((prop = Attributes.BonusInt) != 0) list.Add(1060432, prop.ToString()); // intelligence bonus ~1_val~ - if ((prop = m_AosAttributes.LowerManaCost) != 0) + if ((prop = Attributes.LowerManaCost) != 0) list.Add(1060433, prop.ToString()); // lower mana cost ~1_val~% - if ((prop = m_AosAttributes.LowerRegCost) != 0) + if ((prop = Attributes.LowerRegCost) != 0) list.Add(1060434, prop.ToString()); // lower reagent cost ~1_val~% - if ((prop = m_AosAttributes.Luck) != 0) + if ((prop = Attributes.Luck) != 0) list.Add(1060436, prop.ToString()); // luck ~1_val~ - if ((prop = m_AosAttributes.BonusMana) != 0) + if ((prop = Attributes.BonusMana) != 0) list.Add(1060439, prop.ToString()); // mana increase ~1_val~ - if ((prop = m_AosAttributes.RegenMana) != 0) + if ((prop = Attributes.RegenMana) != 0) list.Add(1060440, prop.ToString()); // mana regeneration ~1_val~ - if ((prop = m_AosAttributes.NightSight) != 0) + if ((prop = Attributes.NightSight) != 0) list.Add(1060441); // night sight - if ((prop = m_AosAttributes.ReflectPhysical) != 0) + if ((prop = Attributes.ReflectPhysical) != 0) list.Add(1060442, prop.ToString()); // reflect physical damage ~1_val~% - if ((prop = m_AosAttributes.RegenStam) != 0) + if ((prop = Attributes.RegenStam) != 0) list.Add(1060443, prop.ToString()); // stamina regeneration ~1_val~ - if ((prop = m_AosAttributes.RegenHits) != 0) + if ((prop = Attributes.RegenHits) != 0) list.Add(1060444, prop.ToString()); // hit point regeneration ~1_val~ - if ((prop = m_AosAttributes.SpellChanneling) != 0) + if ((prop = Attributes.SpellChanneling) != 0) list.Add(1060482); // spell channeling - if ((prop = m_AosAttributes.SpellDamage) != 0) + if ((prop = Attributes.SpellDamage) != 0) list.Add(1060483, prop.ToString()); // spell damage increase ~1_val~% - if ((prop = m_AosAttributes.BonusStam) != 0) + if ((prop = Attributes.BonusStam) != 0) list.Add(1060484, prop.ToString()); // stamina increase ~1_val~ - if ((prop = m_AosAttributes.BonusStr) != 0) + if ((prop = Attributes.BonusStr) != 0) list.Add(1060485, prop.ToString()); // strength bonus ~1_val~ - if ((prop = m_AosAttributes.WeaponSpeed) != 0) + if ((prop = Attributes.WeaponSpeed) != 0) list.Add(1060486, prop.ToString()); // swing speed increase ~1_val~% - if (Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0) + if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0) list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~% if (m_MaxCharges > 0) @@ -450,8 +450,8 @@ namespace Server.Items SaveFlag flags = SaveFlag.None; - SetSaveFlag(ref flags, SaveFlag.Attributes, !m_AosAttributes.IsEmpty); - SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !m_AosSkillBonuses.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.Attributes, !Attributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !SkillBonuses.IsEmpty); SetSaveFlag(ref flags, SaveFlag.Protection, m_Protection != null && !m_Protection.IsEmpty); SetSaveFlag(ref flags, SaveFlag.Killer, m_Killer != null && !m_Killer.IsEmpty); SetSaveFlag(ref flags, SaveFlag.Summoner, m_Summoner != null && !m_Summoner.IsEmpty); @@ -469,10 +469,10 @@ namespace Server.Items writer.WriteEncodedInt((int)flags); if (GetSaveFlag(flags, SaveFlag.Attributes)) - m_AosAttributes.Serialize(writer); + Attributes.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.SkillBonuses)) - m_AosSkillBonuses.Serialize(writer); + SkillBonuses.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.Protection)) m_Protection.Serialize(writer); @@ -524,14 +524,14 @@ namespace Server.Items SaveFlag flags = (SaveFlag)reader.ReadEncodedInt(); if (GetSaveFlag(flags, SaveFlag.Attributes)) - m_AosAttributes = new AosAttributes(this, reader); + Attributes = new AosAttributes(this, reader); else - m_AosAttributes = new AosAttributes(this); + Attributes = new AosAttributes(this); if (GetSaveFlag(flags, SaveFlag.SkillBonuses)) - m_AosSkillBonuses = new AosSkillBonuses(this, reader); + SkillBonuses = new AosSkillBonuses(this, reader); else - m_AosSkillBonuses = new AosSkillBonuses(this); + SkillBonuses = new AosSkillBonuses(this); // Backward compatibility if (GetSaveFlag(flags, SaveFlag.Owner)) @@ -556,7 +556,7 @@ namespace Server.Items m_Removal = (TalismanRemoval)reader.ReadEncodedInt(); if (GetSaveFlag(flags, SaveFlag.OldKarmaLoss)) - m_AosAttributes.IncreasedKarmaLoss = reader.ReadEncodedInt(); + Attributes.IncreasedKarmaLoss = reader.ReadEncodedInt(); if (GetSaveFlag(flags, SaveFlag.Skill)) m_Skill = (SkillName)reader.ReadEncodedInt(); @@ -590,8 +590,8 @@ namespace Server.Items if (Parent is Mobile m) { - m_AosAttributes.AddStatBonuses(m); - m_AosSkillBonuses.AddTo(m); + Attributes.AddStatBonuses(m); + SkillBonuses.AddTo(m); if (m_ChargeTime > 0) StartTimer(); @@ -898,22 +898,11 @@ namespace Server.Items #region AOS bonuses - private AosAttributes m_AosAttributes; - private AosSkillBonuses m_AosSkillBonuses; + [CommandProperty(AccessLevel.GameMaster)] + public AosAttributes Attributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosAttributes Attributes - { - get => m_AosAttributes; - set { } - } - - [CommandProperty(AccessLevel.GameMaster)] - public AosSkillBonuses SkillBonuses - { - get => m_AosSkillBonuses; - set { } - } + public AosSkillBonuses SkillBonuses{ get; private set; } #endregion @@ -1150,26 +1139,17 @@ namespace Server.Items public static bool GetRandomBlessed() { - if (0.02 > Utility.RandomDouble()) - return true; - - return false; + return 0.02 > Utility.RandomDouble(); } public static TalismanSlayerName GetRandomSlayer() { - if (0.01 > Utility.RandomDouble()) - return (TalismanSlayerName)Utility.RandomMinMax(1, 9); - - return TalismanSlayerName.None; + return 0.01 > Utility.RandomDouble() ? (TalismanSlayerName)Utility.RandomMinMax(1, 9) : TalismanSlayerName.None; } public static int GetRandomCharges() { - if (0.5 > Utility.RandomDouble()) - return Utility.RandomMinMax(10, 50); - - return 0; + return 0.5 > Utility.RandomDouble() ? Utility.RandomMinMax(10, 50) : 0; } #endregion diff --git a/Scripts/Items/Traps/MushroomTrap.cs b/Scripts/Items/Traps/MushroomTrap.cs index 568c65a5f..3f119062d 100644 --- a/Scripts/Items/Traps/MushroomTrap.cs +++ b/Scripts/Items/Traps/MushroomTrap.cs @@ -35,7 +35,7 @@ namespace Server.Items public virtual void OnMushroomReset() { - if (Region.Find(Location, Map).IsPartOf(typeof(DungeonRegion))) + if (Region.Find(Location, Map).IsPartOf()) ItemID = 0x1125; // reset else Delete(); diff --git a/Scripts/Items/Wands/BaseWand.cs b/Scripts/Items/Wands/BaseWand.cs index bcca61469..d73d741d4 100644 --- a/Scripts/Items/Wands/BaseWand.cs +++ b/Scripts/Items/Wands/BaseWand.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Network; using Server.Spells; using Server.Targeting; @@ -95,18 +96,18 @@ namespace Server.Items public virtual void ApplyDelayTo(Mobile from) { - from.BeginAction(typeof(BaseWand)); + from.BeginAction(); Timer.DelayCall(GetUseDelay, ReleaseWandLock_Callback, from); } public virtual void ReleaseWandLock_Callback(Mobile state) { - state.EndAction(typeof(BaseWand)); + state.EndAction(); } public override void OnDoubleClick(Mobile from) { - if (!from.CanBeginAction(typeof(BaseWand))) + if (!from.CanBeginAction()) { from.SendLocalizedMessage(1070860); // You must wait a moment for the wand to recharge. return; @@ -197,7 +198,7 @@ namespace Server.Items public override void OnSingleClick(Mobile from) { - ArrayList attrs = new ArrayList(); + List attrs = new List(); if (DisplayLootType) { @@ -272,7 +273,7 @@ namespace Server.Items return; EquipmentInfo eqInfo = new EquipmentInfo(number, Crafter, false, - (EquipInfoAttribute[])attrs.ToArray(typeof(EquipInfoAttribute))); + attrs.ToArray()); from.Send(new DisplayEquipmentInfo(this, eqInfo)); } diff --git a/Scripts/Items/Wands/WandTarget.cs b/Scripts/Items/Wands/WandTarget.cs index cdb675e96..783d4cf1e 100644 --- a/Scripts/Items/Wands/WandTarget.cs +++ b/Scripts/Items/Wands/WandTarget.cs @@ -13,7 +13,7 @@ namespace Server.Targeting private static int GetOffset(Mobile caster) { - return 5 + (int)(caster.Skills[SkillName.Magery].Value * 0.02); + return 5 + (int)(caster.Skills.Magery.Value * 0.02); } protected override void OnTarget(Mobile from, object targeted) diff --git a/Scripts/Items/Weapons/Abilities/BleedAttack.cs b/Scripts/Items/Weapons/Abilities/BleedAttack.cs index 12cb1af16..3d4396de3 100644 --- a/Scripts/Items/Weapons/Abilities/BleedAttack.cs +++ b/Scripts/Items/Weapons/Abilities/BleedAttack.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Mobiles; using Server.Network; using Server.Spells; @@ -14,7 +15,7 @@ namespace Server.Items /// public class BleedAttack : WeaponAbility { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 30; @@ -53,17 +54,15 @@ namespace Server.Items public static bool IsBleeding(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public static void BeginBleed(Mobile m, Mobile from) { - Timer t = (Timer)m_Table[m]; - + Timer t = m_Table[m]; t?.Stop(); - t = new InternalTimer(from, m); - m_Table[m] = t; + m_Table[m] = t = new InternalTimer(from, m); t.Start(); } @@ -80,10 +79,7 @@ namespace Server.Items m.PlaySound(0x133); m.Damage(damage, from); - Blood blood = new Blood(); - - blood.ItemID = Utility.Random(0x122A, 5); - + Blood blood = new Blood { ItemID = Utility.Random(0x122A, 5) }; blood.MoveToWorld(m.Location, m.Map); } else @@ -94,7 +90,7 @@ namespace Server.Items public static void EndBleed(Mobile m, bool message) { - Timer t = (Timer)m_Table[m]; + Timer t = m_Table[m]; if (t == null) return; @@ -128,4 +124,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/Block.cs b/Scripts/Items/Weapons/Abilities/Block.cs index a7b672e1e..74880f21c 100644 --- a/Scripts/Items/Weapons/Abilities/Block.cs +++ b/Scripts/Items/Weapons/Abilities/Block.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Items { @@ -8,7 +9,7 @@ namespace Server.Items /// public class Block : WeaponAbility { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 30; @@ -36,15 +37,16 @@ namespace Server.Items attacker.FixedParticles(0x37C4, 1, 16, 0x251D, 0x39D, 0x3, EffectLayer.RightHand); - int bonus = (int)(10.0 * ((Math.Max(attacker.Skills[SkillName.Bushido].Value, - attacker.Skills[SkillName.Ninjitsu].Value) - 50.0) / 70.0 + 5)); + int bonus = (int)(10.0 * ((Math.Max(attacker.Skills.Bushido.Value, + attacker.Skills.Ninjitsu.Value) - 50.0) / 70.0 + 5)); BeginBlock(attacker, bonus); } public static bool GetBonus(Mobile targ, ref int bonus) { - if (!(m_Table[targ] is BlockInfo info)) + BlockInfo info = m_Table[targ]; + if (info == null) return false; bonus = info.m_Bonus; @@ -54,33 +56,29 @@ namespace Server.Items public static void BeginBlock(Mobile m, int bonus) { EndBlock(m); - - BlockInfo info = new BlockInfo(m, bonus); - info.m_Timer = new InternalTimer(m); - - m_Table[m] = info; + m_Table[m] = new BlockInfo(m, bonus); } public static void EndBlock(Mobile m) { - if (m_Table[m] is BlockInfo info) - { - info.m_Timer?.Stop(); + BlockInfo info = m_Table[m]; - m_Table.Remove(m); - } + if (info == null) + return; + + info.m_Timer?.Stop(); + m_Table.Remove(m); } private class BlockInfo { public int m_Bonus; - public Mobile m_Target; public Timer m_Timer; public BlockInfo(Mobile target, int bonus) { - m_Target = target; m_Bonus = bonus; + m_Timer = new InternalTimer(target); } } @@ -100,4 +98,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/DefenseMastery.cs b/Scripts/Items/Weapons/Abilities/DefenseMastery.cs index 0a2695618..eca17aafc 100644 --- a/Scripts/Items/Weapons/Abilities/DefenseMastery.cs +++ b/Scripts/Items/Weapons/Abilities/DefenseMastery.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Items { @@ -9,7 +9,7 @@ namespace Server.Items /// public class DefenseMastery : WeaponAbility { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 30; @@ -38,17 +38,19 @@ namespace Server.Items int modifier = (int)(30.0 * - ((Math.Max(attacker.Skills[SkillName.Bushido].Value, attacker.Skills[SkillName.Ninjitsu].Value) - + ((Math.Max(attacker.Skills.Bushido.Value, attacker.Skills.Ninjitsu.Value) - 50.0) / 70.0)); - if (m_Table[attacker] is DefenseMasteryInfo info) + DefenseMasteryInfo info = m_Table[attacker]; + + if (info != null) EndDefense(info); ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, 50 + modifier); attacker.AddResistanceMod(mod); info = new DefenseMasteryInfo(attacker, 80 - modifier, mod); - info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(3.0), new TimerStateCallback(EndDefense), info); + info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(3.0), EndDefense, info); m_Table[attacker] = info; @@ -57,17 +59,17 @@ namespace Server.Items public static bool GetMalus(Mobile targ, ref int damageMalus) { - if (!(m_Table[targ] is DefenseMasteryInfo info)) + DefenseMasteryInfo info = m_Table[targ]; + + if (info == null) return false; damageMalus = info.m_DamageMalus; return true; } - private static void EndDefense(object state) + private static void EndDefense(DefenseMasteryInfo info) { - DefenseMasteryInfo info = (DefenseMasteryInfo)state; - if (info.m_Mod != null) info.m_From.RemoveResistanceMod(info.m_Mod); @@ -95,4 +97,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/Disarm.cs b/Scripts/Items/Weapons/Abilities/Disarm.cs index 1efaa9e5a..5074d6124 100644 --- a/Scripts/Items/Weapons/Abilities/Disarm.cs +++ b/Scripts/Items/Weapons/Abilities/Disarm.cs @@ -21,7 +21,7 @@ namespace Server.Items if ( !(from.Weapon is Fists) ) return true; - Skill skill = from.Skills[SkillName.ArmsLore]; + Skill skill = from.Skills.ArmsLore; if ( skill != null && skill.Base >= 80.0 ) return true; diff --git a/Scripts/Items/Weapons/Abilities/DualWield.cs b/Scripts/Items/Weapons/Abilities/DualWield.cs index 551425b5f..6375bbe11 100644 --- a/Scripts/Items/Weapons/Abilities/DualWield.cs +++ b/Scripts/Items/Weapons/Abilities/DualWield.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Items { @@ -8,7 +9,7 @@ namespace Server.Items /// public class DualWield : WeaponAbility { - public static Hashtable Registry{ get; } = new Hashtable(); + public static Dictionary Registry{ get; } = new Dictionary(); public override int BaseMana => 30; @@ -29,24 +30,23 @@ namespace Server.Items if (!Validate(attacker) || !CheckMana(attacker, true)) return; - if (Registry.Contains(attacker)) + DualWieldTimer timer = Registry[attacker]; + if (timer != null) { - DualWieldTimer existingtimer = (DualWieldTimer)Registry[attacker]; - existingtimer.Stop(); + timer.Stop(); Registry.Remove(attacker); } ClearCurrentAbility(attacker); attacker.SendLocalizedMessage(1063362); // You dually wield for increased speed! - attacker.FixedParticles(0x3779, 1, 15, 0x7F6, 0x3E8, 3, EffectLayer.LeftHand); - Timer t = new DualWieldTimer(attacker, - (int)(20.0 + 3.0 * (attacker.Skills[SkillName.Ninjitsu].Value - 50.0) / 7.0)); //20-50 % increase + timer = new DualWieldTimer(attacker, + (int)(20.0 + 3.0 * (attacker.Skills.Ninjitsu.Value - 50.0) / 7.0)); //20-50 % increase - t.Start(); - Registry.Add(attacker, t); + timer.Start(); + Registry.Add(attacker, timer); } public class DualWieldTimer : Timer @@ -69,4 +69,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/Feint.cs b/Scripts/Items/Weapons/Abilities/Feint.cs index 771353201..3c9878b4e 100644 --- a/Scripts/Items/Weapons/Abilities/Feint.cs +++ b/Scripts/Items/Weapons/Abilities/Feint.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Items { @@ -8,7 +9,7 @@ namespace Server.Items /// public class Feint : WeaponAbility { - public static Hashtable Registry{ get; } = new Hashtable(); + public static Dictionary Registry{ get; } = new Dictionary(); public override int BaseMana => 30; @@ -29,10 +30,10 @@ namespace Server.Items if (!Validate(attacker) || !CheckMana(attacker, true)) return; - if (Registry.Contains(defender)) + FeintTimer timer = Registry[defender]; + if (timer != null) { - FeintTimer existingtimer = (FeintTimer)Registry[defender]; - existingtimer.Stop(); + timer.Stop(); Registry.Remove(defender); } @@ -43,12 +44,12 @@ namespace Server.Items attacker.FixedParticles(0x3728, 1, 13, 0x7F3, 0x962, 0, EffectLayer.Waist); - Timer t = new FeintTimer(defender, - (int)(20.0 + 3.0 * (Math.Max(attacker.Skills[SkillName.Ninjitsu].Value, - attacker.Skills[SkillName.Bushido].Value) - 50.0) / 7.0)); //20-50 % decrease + timer = new FeintTimer(defender, + (int)(20.0 + 3.0 * (Math.Max(attacker.Skills.Ninjitsu.Value, + attacker.Skills.Bushido.Value) - 50.0) / 7.0)); //20-50 % decrease - t.Start(); - Registry.Add(defender, t); + timer.Start(); + Registry.Add(defender, timer); } public class FeintTimer : Timer @@ -71,4 +72,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs b/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs index 246a98c91..3ec95780b 100644 --- a/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs +++ b/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Spells; namespace Server.Items @@ -11,7 +12,7 @@ namespace Server.Items { public override int BaseMana => 30; - public static Hashtable Registry{ get; } = new Hashtable(); + public static Dictionary Registry{ get; } = new Dictionary(); public override bool CheckSkills(Mobile from) { @@ -34,22 +35,19 @@ namespace Server.Items Map map = attacker.Map; - if (map == null) + if (!(map != null && attacker.Weapon is BaseWeapon weapon)) return; - if (!(attacker.Weapon is BaseWeapon weapon)) - return; - - ArrayList list = new ArrayList(); + List list = new List(); foreach (Mobile m in attacker.GetMobilesInRange(1)) list.Add(m); - ArrayList targets = new ArrayList(); + List targets = new List(); for (int i = 0; i < list.Count; ++i) { - Mobile m = (Mobile)list[i]; + Mobile m = list[i]; if (m != defender && m != attacker && SpellHelper.ValidIndirectTarget(attacker, m)) { @@ -65,47 +63,44 @@ namespace Server.Items } } - if (targets.Count > 0) + if (targets.Count == 0 || !CheckMana(attacker, true)) + return; + + attacker.FixedEffect(0x3728, 10, 15); + attacker.PlaySound(0x2A1); + + // 5-15 damage + int amount = (int)(10.0 * ((Math.Max(attacker.Skills.Bushido.Value, + attacker.Skills.Ninjitsu.Value) - 50.0) / 70.0 + 5)); + + for (int i = 0; i < targets.Count; ++i) { - if (!CheckMana(attacker, true)) - return; + Mobile m = targets[i]; + attacker.DoHarmful(m, true); - attacker.FixedEffect(0x3728, 10, 15); - attacker.PlaySound(0x2A1); + FrenziedWirlwindTimer timer = Registry[m]; - // 5-15 damage - int amount = (int)(10.0 * ((Math.Max(attacker.Skills[SkillName.Bushido].Value, - attacker.Skills[SkillName.Ninjitsu].Value) - 50.0) / 70.0 + 5)); - - for (int i = 0; i < targets.Count; ++i) + if (timer != null) { - Mobile m = (Mobile)targets[i]; - attacker.DoHarmful(m, true); - - if (Registry[m] is Timer t) - { - t.Stop(); - Registry.Remove(m); - } - - t = new InternalTimer(attacker, m, amount); - t.Start(); - Registry.Add(m, t); + timer.Stop(); + Registry.Remove(m); } - Timer.DelayCall(TimeSpan.FromSeconds(2.0), new TimerStateCallback(RepeatEffect), attacker); + timer = new FrenziedWirlwindTimer(attacker, m, amount); + timer.Start(); + Registry.Add(m, timer); } + + Timer.DelayCall(TimeSpan.FromSeconds(2.0), RepeatEffect, attacker); } - private void RepeatEffect(object state) + private void RepeatEffect(Mobile attacker) { - Mobile attacker = (Mobile)state; - attacker.FixedEffect(0x3728, 10, 15); attacker.PlaySound(0x2A1); } - private class InternalTimer : Timer + public class FrenziedWirlwindTimer : Timer { private readonly double DamagePerTick; private Mobile m_Attacker; @@ -113,9 +108,9 @@ namespace Server.Items private double m_DamageToDo; private Mobile m_Defender; - public InternalTimer(Mobile attacker, Mobile defender, int totalDamage) + public FrenziedWirlwindTimer(Mobile attacker, Mobile defender, int totalDamage) : base(TimeSpan.Zero, TimeSpan.FromSeconds(0.25), - 12) // 3 seconds at .25 seconds apart = 12. Confirm delay inbetween of .25 each. + 12) // 3 seconds at .25 seconds apart = 12. Confirm delay in between of .25 each. { m_Attacker = attacker; m_Defender = defender; @@ -157,4 +152,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/InfectiousStrike.cs b/Scripts/Items/Weapons/Abilities/InfectiousStrike.cs index b73922459..174559345 100644 --- a/Scripts/Items/Weapons/Abilities/InfectiousStrike.cs +++ b/Scripts/Items/Weapons/Abilities/InfectiousStrike.cs @@ -47,11 +47,11 @@ namespace Server.Items --weapon.PoisonCharges; // Infectious strike special move now uses poisoning skill to help determine potency - int maxLevel = attacker.Skills[SkillName.Poisoning].Fixed / 200; + int maxLevel = attacker.Skills.Poisoning.Fixed / 200; if (maxLevel < 0) maxLevel = 0; if (p.Level > maxLevel) p = Poison.GetPoison(maxLevel); - if (attacker.Skills[SkillName.Poisoning].Value / 100.0 > Utility.RandomDouble()) + if (attacker.Skills.Poisoning.Value / 100.0 > Utility.RandomDouble()) { int level = p.Level + 1; Poison newPoison = Poison.GetPoison(level); diff --git a/Scripts/Items/Weapons/Abilities/MortalStrike.cs b/Scripts/Items/Weapons/Abilities/MortalStrike.cs index 5e004a313..39a5bd362 100644 --- a/Scripts/Items/Weapons/Abilities/MortalStrike.cs +++ b/Scripts/Items/Weapons/Abilities/MortalStrike.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Items { @@ -13,7 +13,7 @@ namespace Server.Items public static readonly TimeSpan PlayerDuration = TimeSpan.FromSeconds(6.0); public static readonly TimeSpan NPCDuration = TimeSpan.FromSeconds(12.0); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 30; @@ -36,33 +36,29 @@ namespace Server.Items public static bool IsWounded(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public static void BeginWound(Mobile m, TimeSpan duration) { - Timer t = (Timer)m_Table[m]; + InternalTimer timer = m_Table[m]; + timer?.Stop(); - t?.Stop(); - - t = new InternalTimer(m, duration); - m_Table[m] = t; - - t.Start(); + m_Table[m] = timer = new InternalTimer(m, duration); + timer.Start(); m.YellowHealthbar = true; } public static void EndWound(Mobile m) { - if (!IsWounded(m)) - return; + Timer timer = m_Table[m]; - Timer t = (Timer)m_Table[m]; - - t?.Stop(); - - m_Table.Remove(m); + if (timer != null) + { + timer.Stop(); + m_Table.Remove(m); + } m.YellowHealthbar = false; m.SendLocalizedMessage(1060208); // You are no longer mortally wounded. @@ -84,4 +80,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/NerveStrike.cs b/Scripts/Items/Weapons/Abilities/NerveStrike.cs index ccf737ac8..e83c1448e 100644 --- a/Scripts/Items/Weapons/Abilities/NerveStrike.cs +++ b/Scripts/Items/Weapons/Abilities/NerveStrike.cs @@ -59,10 +59,10 @@ namespace Server.Items if (Core.ML) { AOS.Damage(defender, attacker, - (int)(15.0 * (attacker.Skills[SkillName.Bushido].Value - 50.0) / 70.0 + Utility.Random(10)), true, 100, + (int)(15.0 * (attacker.Skills.Bushido.Value - 50.0) / 70.0 + Utility.Random(10)), true, 100, 0, 0, 0, 0); //0-25 - if (!cantpara && (150.0 / 7.0 + 4.0 * attacker.Skills[SkillName.Bushido].Value / 7.0) / 100.0 > + if (!cantpara && (150.0 / 7.0 + 4.0 * attacker.Skills.Bushido.Value / 7.0) / 100.0 > Utility.RandomDouble()) { defender.Paralyze(TimeSpan.FromSeconds(2.0)); @@ -71,7 +71,7 @@ namespace Server.Items } else if (!cantpara) { - AOS.Damage(defender, attacker, (int)(15.0 * (attacker.Skills[SkillName.Bushido].Value - 50.0) / 70.0 + 10), + AOS.Damage(defender, attacker, (int)(15.0 * (attacker.Skills.Bushido.Value - 50.0) / 70.0 + 10), true, 100, 0, 0, 0, 0); //10-25 defender.Freeze(TimeSpan.FromSeconds(2.0)); Items.ParalyzingBlow.BeginImmunity(defender, Items.ParalyzingBlow.FreezeDelayDuration); diff --git a/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs b/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs index 50fe0c5b2..479c0f1a1 100644 --- a/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs +++ b/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Items { @@ -13,7 +14,7 @@ namespace Server.Items public static readonly TimeSpan FreezeDelayDuration = TimeSpan.FromSeconds(8.0); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 30; @@ -26,7 +27,7 @@ namespace Server.Items if ( !(from.Weapon is Fists) ) return true; - Skill skill = from.Skills[SkillName.Anatomy]; + Skill skill = from.Skills.Anatomy; if ( skill != null && skill.Base >= 80.0 ) return true; @@ -38,10 +39,7 @@ namespace Server.Items public override bool RequiresTactics(Mobile from) { - if (!(from.Weapon is BaseWeapon weapon)) - return true; - - return weapon.Skill != SkillName.Wrestling; + return !(from.Weapon is BaseWeapon weapon && weapon.Skill == SkillName.Wrestling); } public override bool OnBeforeSwing(Mobile attacker, Mobile defender) @@ -85,27 +83,22 @@ namespace Server.Items public static bool IsImmune(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public static void BeginImmunity(Mobile m, TimeSpan duration) { - Timer t = (Timer)m_Table[m]; + InternalTimer timer = m_Table[m]; - t?.Stop(); - - t = new InternalTimer(m, duration); - m_Table[m] = t; - - t.Start(); + timer?.Stop(); + m_Table[m] = timer = new InternalTimer(m, duration); + timer.Start(); } public static void EndImmunity(Mobile m) { - Timer t = (Timer)m_Table[m]; - - t?.Stop(); - + InternalTimer timer = m_Table[m]; + timer?.Stop(); m_Table.Remove(m); } @@ -125,4 +118,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/RidingSwipe.cs b/Scripts/Items/Weapons/Abilities/RidingSwipe.cs index 4a2bb1e17..eb5daa97f 100644 --- a/Scripts/Items/Weapons/Abilities/RidingSwipe.cs +++ b/Scripts/Items/Weapons/Abilities/RidingSwipe.cs @@ -47,7 +47,7 @@ namespace Server.Items if (mount != null) //Ethy mounts don't take damage { - int amount = 10 + (int)(10.0 * (attacker.Skills[SkillName.Bushido].Value - 50.0) / 70.0 + 5); + int amount = 10 + (int)(10.0 * (attacker.Skills.Bushido.Value - 50.0) / 70.0 + 5); AOS.Damage(mount, null, amount, 100, 0, 0, 0, 0); //The mount just takes damage, there's no flagging as if it was attacking the mount directly @@ -57,7 +57,7 @@ namespace Server.Items } else { - int amount = 10 + (int)(10.0 * (attacker.Skills[SkillName.Bushido].Value - 50.0) / 70.0 + 5); + int amount = 10 + (int)(10.0 * (attacker.Skills.Bushido.Value - 50.0) / 70.0 + 5); AOS.Damage(defender, attacker, amount, 100, 0, 0, 0, 0); diff --git a/Scripts/Items/Weapons/Abilities/ShadowStrike.cs b/Scripts/Items/Weapons/Abilities/ShadowStrike.cs index 872841fc7..5a5cb0d65 100644 --- a/Scripts/Items/Weapons/Abilities/ShadowStrike.cs +++ b/Scripts/Items/Weapons/Abilities/ShadowStrike.cs @@ -20,7 +20,7 @@ namespace Server.Items if (!base.CheckSkills(from)) return false; - Skill skill = from.Skills[SkillName.Stealth]; + Skill skill = from.Skills.Stealth; if (skill != null && skill.Value >= 80.0) return true; diff --git a/Scripts/Items/Weapons/Abilities/TalonStrike.cs b/Scripts/Items/Weapons/Abilities/TalonStrike.cs index 08c7d17e0..7d2fbfd21 100644 --- a/Scripts/Items/Weapons/Abilities/TalonStrike.cs +++ b/Scripts/Items/Weapons/Abilities/TalonStrike.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; namespace Server.Items { @@ -8,7 +8,7 @@ namespace Server.Items /// public class TalonStrike : WeaponAbility { - public static Hashtable Registry{ get; } = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 30; public override double DamageScalar => 1.2; @@ -27,7 +27,7 @@ namespace Server.Items public override void OnHit(Mobile attacker, Mobile defender, int damage) { - if (Registry.Contains(defender) || !Validate(attacker) || !CheckMana(attacker, true)) + if (m_Table.ContainsKey(defender) || !Validate(attacker) || !CheckMana(attacker, true)) return; ClearCurrentAbility(attacker); @@ -37,23 +37,22 @@ namespace Server.Items defender.FixedParticles(0x373A, 1, 17, 0x26BC, 0x662, 0, EffectLayer.Waist); - Timer t = new InternalTimer(defender, - (int)(10.0 * (attacker.Skills[SkillName.Ninjitsu].Value - 50.0) / 70.0 + 5), attacker); //5 - 15 damage + InternalTimer timer = new InternalTimer(defender, + (int)(10.0 * (attacker.Skills.Ninjitsu.Value - 50.0) / 70.0 + 5)); //5 - 15 damage - t.Start(); + timer.Start(); - Registry.Add(defender, t); + m_Table.Add(defender, timer); } private class InternalTimer : Timer { private readonly double DamagePerTick; - private Mobile m_Attacker; private double m_DamageRemaining; private double m_DamageToDo; private Mobile m_Defender; - public InternalTimer(Mobile defender, int totalDamage, Mobile attacker) + public InternalTimer(Mobile defender, int totalDamage) : base(TimeSpan.Zero, TimeSpan.FromSeconds(0.25), 12) // 3 seconds at .25 seconds apart = 12. Confirm delay inbetween of .25 each. { @@ -61,8 +60,6 @@ namespace Server.Items m_DamageRemaining = totalDamage; Priority = TimerPriority.TwentyFiveMS; - m_Attacker = attacker; - DamagePerTick = (double)totalDamage / 12 + .01; } @@ -71,7 +68,7 @@ namespace Server.Items if (!m_Defender.Alive || m_DamageRemaining <= 0) { Stop(); - Registry.Remove(m_Defender); + m_Table.Remove(m_Defender); return; } @@ -93,9 +90,9 @@ namespace Server.Items if (!m_Defender.Alive || m_DamageRemaining <= 0) { Stop(); - Registry.Remove(m_Defender); + m_Table.Remove(m_Defender); } } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/WeaponAbility.cs b/Scripts/Items/Weapons/Abilities/WeaponAbility.cs index f3a967999..2a1cc8026 100644 --- a/Scripts/Items/Weapons/Abilities/WeaponAbility.cs +++ b/Scripts/Items/Weapons/Abilities/WeaponAbility.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.ConPVP; using Server.Mobiles; using Server.Network; @@ -12,52 +13,7 @@ namespace Server.Items { public abstract class WeaponAbility { - public static readonly WeaponAbility ArmorIgnore = Abilities[1]; - public static readonly WeaponAbility BleedAttack = Abilities[2]; - public static readonly WeaponAbility ConcussionBlow = Abilities[3]; - public static readonly WeaponAbility CrushingBlow = Abilities[4]; - public static readonly WeaponAbility Disarm = Abilities[5]; - public static readonly WeaponAbility Dismount = Abilities[6]; - public static readonly WeaponAbility DoubleStrike = Abilities[7]; - public static readonly WeaponAbility InfectiousStrike = Abilities[8]; - public static readonly WeaponAbility MortalStrike = Abilities[9]; - public static readonly WeaponAbility MovingShot = Abilities[10]; - public static readonly WeaponAbility ParalyzingBlow = Abilities[11]; - public static readonly WeaponAbility ShadowStrike = Abilities[12]; - public static readonly WeaponAbility WhirlwindAttack = Abilities[13]; - - public static readonly WeaponAbility RidingSwipe = Abilities[14]; - public static readonly WeaponAbility FrenziedWhirlwind = Abilities[15]; - public static readonly WeaponAbility Block = Abilities[16]; - public static readonly WeaponAbility DefenseMastery = Abilities[17]; - public static readonly WeaponAbility NerveStrike = Abilities[18]; - public static readonly WeaponAbility TalonStrike = Abilities[19]; - public static readonly WeaponAbility Feint = Abilities[20]; - public static readonly WeaponAbility DualWield = Abilities[21]; - public static readonly WeaponAbility DoubleShot = Abilities[22]; - public static readonly WeaponAbility ArmorPierce = Abilities[23]; - - public static readonly WeaponAbility Bladeweave = Abilities[24]; - public static readonly WeaponAbility ForceArrow = Abilities[25]; - public static readonly WeaponAbility LightningArrow = Abilities[26]; - public static readonly WeaponAbility PsychicAttack = Abilities[27]; - public static readonly WeaponAbility SerpentArrow = Abilities[28]; - public static readonly WeaponAbility ForceOfNature = Abilities[29]; - - public static readonly WeaponAbility Disrobe = Abilities[30]; - - - private static Hashtable m_PlayersTable = new Hashtable(); - - public virtual int BaseMana => 0; - - public virtual int AccuracyBonus => 0; - public virtual double DamageScalar => 1.0; - - public virtual bool RequiresSE => false; - - public static WeaponAbility[] Abilities{ get; } = new WeaponAbility[31] - { + public static WeaponAbility[] Abilities{ get; } = { null, new ArmorIgnore(), new BleedAttack(), @@ -92,7 +48,50 @@ namespace Server.Items new Disrobe() }; - public static Hashtable Table{ get; } = new Hashtable(); + public static readonly WeaponAbility ArmorIgnore = Abilities[1]; + public static readonly WeaponAbility BleedAttack = Abilities[2]; + public static readonly WeaponAbility ConcussionBlow = Abilities[3]; + public static readonly WeaponAbility CrushingBlow = Abilities[4]; + public static readonly WeaponAbility Disarm = Abilities[5]; + public static readonly WeaponAbility Dismount = Abilities[6]; + public static readonly WeaponAbility DoubleStrike = Abilities[7]; + public static readonly WeaponAbility InfectiousStrike = Abilities[8]; + public static readonly WeaponAbility MortalStrike = Abilities[9]; + public static readonly WeaponAbility MovingShot = Abilities[10]; + public static readonly WeaponAbility ParalyzingBlow = Abilities[11]; + public static readonly WeaponAbility ShadowStrike = Abilities[12]; + public static readonly WeaponAbility WhirlwindAttack = Abilities[13]; + + public static readonly WeaponAbility RidingSwipe = Abilities[14]; + public static readonly WeaponAbility FrenziedWhirlwind = Abilities[15]; + public static readonly WeaponAbility Block = Abilities[16]; + public static readonly WeaponAbility DefenseMastery = Abilities[17]; + public static readonly WeaponAbility NerveStrike = Abilities[18]; + public static readonly WeaponAbility TalonStrike = Abilities[19]; + public static readonly WeaponAbility Feint = Abilities[20]; + public static readonly WeaponAbility DualWield = Abilities[21]; + public static readonly WeaponAbility DoubleShot = Abilities[22]; + public static readonly WeaponAbility ArmorPierce = Abilities[23]; + + public static readonly WeaponAbility Bladeweave = Abilities[24]; + public static readonly WeaponAbility ForceArrow = Abilities[25]; + public static readonly WeaponAbility LightningArrow = Abilities[26]; + public static readonly WeaponAbility PsychicAttack = Abilities[27]; + public static readonly WeaponAbility SerpentArrow = Abilities[28]; + public static readonly WeaponAbility ForceOfNature = Abilities[29]; + + public static readonly WeaponAbility Disrobe = Abilities[30]; + + private static Dictionary m_PlayersTable = new Dictionary(); + + public virtual int BaseMana => 0; + + public virtual int AccuracyBonus => 0; + public virtual double DamageScalar => 1.0; + + public virtual bool RequiresSE => false; + + public static Dictionary Table{ get; } = new Dictionary(); public virtual bool ValidatesDuringHit => true; @@ -122,12 +121,13 @@ namespace Server.Items public virtual double GetRequiredSkill(Mobile from) { - BaseWeapon weapon = from.Weapon as BaseWeapon; - - if (weapon != null && weapon.PrimaryAbility == this) - return 70.0; - if (weapon != null && weapon.SecondaryAbility == this) - return 90.0; + if (from.Weapon is BaseWeapon weapon) + { + if (weapon.PrimaryAbility == this) + return 70.0; + if (weapon.SecondaryAbility == this) + return 90.0; + } return 200.0; } @@ -177,7 +177,7 @@ namespace Server.Items double reqSkill = GetRequiredSkill(from); bool reqTactics = Core.ML && RequiresTactics(from); - if (Core.ML && reqTactics && from.Skills[SkillName.Tactics].Base < reqSkill) + if (Core.ML && reqTactics && from.Skills.Tactics.Base < reqSkill) { from.SendLocalizedMessage(1079308, reqSkill.ToString()); // You need ~1_SKILL_REQUIREMENT~ weapon and tactics skill to perform that attack @@ -188,9 +188,9 @@ namespace Server.Items return true; /* */ - if (weapon.WeaponAttributes.UseBestSkill > 0 && (from.Skills[SkillName.Swords].Base >= reqSkill || - from.Skills[SkillName.Macing].Base >= reqSkill || - from.Skills[SkillName.Fencing].Base >= reqSkill)) + if (weapon.WeaponAttributes.UseBestSkill > 0 && (from.Skills.Swords.Base >= reqSkill || + from.Skills.Macing.Base >= reqSkill || + from.Skills.Fencing.Base >= reqSkill)) return true; /* */ @@ -338,13 +338,8 @@ namespace Server.Items public static bool IsWeaponAbility(Mobile m, WeaponAbility a) { - if (a == null) - return true; - - if (!m.Player) - return true; - - return m.Weapon is BaseWeapon weapon && (weapon.PrimaryAbility == a || weapon.SecondaryAbility == a); + return a == null || !m.Player || m.Weapon is BaseWeapon weapon && + (weapon.PrimaryAbility == a || weapon.SecondaryAbility == a); } public static WeaponAbility GetCurrentAbility(Mobile m) @@ -355,7 +350,7 @@ namespace Server.Items return null; } - WeaponAbility a = (WeaponAbility)Table[m]; + WeaponAbility a = Table[m]; if (!IsWeaponAbility(m, a)) { @@ -363,7 +358,7 @@ namespace Server.Items return null; } - if (a != null && a.ValidatesDuringHit && !a.Validate(m)) + if (a?.ValidatesDuringHit == true && !a.Validate(m)) { ClearCurrentAbility(m); return null; @@ -451,7 +446,7 @@ namespace Server.Items private static WeaponAbilityContext GetContext(Mobile m) { - return m_PlayersTable[m] as WeaponAbilityContext; + return m_PlayersTable[m]; } private class WeaponAbilityTimer : Timer @@ -481,4 +476,4 @@ namespace Server.Items public Timer Timer{ get; } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/WhirlwindAttack.cs b/Scripts/Items/Weapons/Abilities/WhirlwindAttack.cs index 085eda9e0..0be076f81 100644 --- a/Scripts/Items/Weapons/Abilities/WhirlwindAttack.cs +++ b/Scripts/Items/Weapons/Abilities/WhirlwindAttack.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Spells; namespace Server.Items @@ -33,16 +34,16 @@ namespace Server.Items attacker.FixedEffect(0x3728, 10, 15); attacker.PlaySound(0x2A1); - ArrayList list = new ArrayList(); + List list = new List(); foreach (Mobile m in attacker.GetMobilesInRange(1)) list.Add(m); - ArrayList targets = new ArrayList(); + List targets = new List(); for (int i = 0; i < list.Count; ++i) { - Mobile m = (Mobile)list[i]; + Mobile m = list[i]; if (m != defender && m != attacker && SpellHelper.ValidIndirectTarget(attacker, m)) { @@ -70,7 +71,7 @@ namespace Server.Items for (int i = 0; i < targets.Count; ++i) { - Mobile m = (Mobile)targets[i]; + Mobile m = targets[i]; attacker.SendLocalizedMessage(1060161); // The whirling attack strikes a target! m.SendLocalizedMessage(1060162); // You are struck by the whirling attack and take damage! diff --git a/Scripts/Items/Weapons/Axes/BaseAxe.cs b/Scripts/Items/Weapons/Axes/BaseAxe.cs index 26efe7e93..340b8651d 100644 --- a/Scripts/Items/Weapons/Axes/BaseAxe.cs +++ b/Scripts/Items/Weapons/Axes/BaseAxe.cs @@ -163,8 +163,8 @@ namespace Server.Items base.OnHit(attacker, defender, damageBonus); if (!Core.AOS && (attacker.Player || attacker.Body.IsHuman) && Layer == Layer.TwoHanded && - attacker.Skills[SkillName.Anatomy].Value >= 80 && - attacker.Skills[SkillName.Anatomy].Value / 400.0 >= Utility.RandomDouble() && + attacker.Skills.Anatomy.Value >= 80 && + attacker.Skills.Anatomy.Value / 400.0 >= Utility.RandomDouble() && DuelContext.AllowSpecialAbility(attacker, "Concussion Blow", false)) { StatMod mod = defender.GetStatMod("Concussion"); diff --git a/Scripts/Items/Weapons/BaseWeapon.cs b/Scripts/Items/Weapons/BaseWeapon.cs index 927e7d480..39467ce37 100644 --- a/Scripts/Items/Weapons/BaseWeapon.cs +++ b/Scripts/Items/Weapons/BaseWeapon.cs @@ -48,10 +48,10 @@ namespace Server.Items m_Resource = CraftResource.Iron; - m_AosAttributes = new AosAttributes(this); - m_AosWeaponAttributes = new AosWeaponAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); - m_AosElementDamages = new AosElementAttributes(this); + Attributes = new AosAttributes(this); + WeaponAttributes = new AosWeaponAttributes(this); + SkillBonuses = new AosSkillBonuses(this); + AosElementDamages = new AosElementAttributes(this); } public BaseWeapon(Serial serial) : base(serial) @@ -284,10 +284,10 @@ namespace Server.Items if (!(newItem is BaseWeapon weap)) return; - weap.m_AosAttributes = new AosAttributes(newItem, m_AosAttributes); - weap.m_AosElementDamages = new AosElementAttributes(newItem, m_AosElementDamages); - weap.m_AosSkillBonuses = new AosSkillBonuses(newItem, m_AosSkillBonuses); - weap.m_AosWeaponAttributes = new AosWeaponAttributes(newItem, m_AosWeaponAttributes); + weap.Attributes = new AosAttributes(newItem, Attributes); + weap.AosElementDamages = new AosElementAttributes(newItem, AosElementDamages); + weap.SkillBonuses = new AosSkillBonuses(newItem, SkillBonuses); + weap.WeaponAttributes = new AosWeaponAttributes(newItem, WeaponAttributes); } public int GetDurabilityBonus() @@ -318,7 +318,7 @@ namespace Server.Items if (Core.AOS) { - bonus += m_AosWeaponAttributes.DurabilityBonus; + bonus += WeaponAttributes.DurabilityBonus; CraftResourceInfo resInfo = CraftResources.GetInfo(m_Resource); CraftAttributeInfo attrInfo = null; @@ -338,7 +338,7 @@ namespace Server.Items if (!Core.AOS) return 0; - int v = m_AosWeaponAttributes.LowerStatReq; + int v = WeaponAttributes.LowerStatReq; CraftAttributeInfo attrInfo = CraftResources.GetInfo(m_Resource)?.AttributeInfo; @@ -353,7 +353,7 @@ namespace Server.Items public static void BlockEquip(Mobile m, TimeSpan duration) { - if (m.BeginAction(typeof(BaseWeapon))) + if (m.BeginAction()) new ResetEquipTimer(m, duration).Start(); } @@ -419,16 +419,16 @@ namespace Server.Items return false; } - if (!from.CanBeginAction(typeof(BaseWeapon))) return false; + if (!from.CanBeginAction()) return false; return base.CanEquip(from); } public override bool OnEquip(Mobile from) { - int strBonus = m_AosAttributes.BonusStr; - int dexBonus = m_AosAttributes.BonusDex; - int intBonus = m_AosAttributes.BonusInt; + int strBonus = Attributes.BonusStr; + int dexBonus = Attributes.BonusDex; + int intBonus = Attributes.BonusInt; if (strBonus != 0 || dexBonus != 0 || intBonus != 0) { @@ -456,11 +456,11 @@ namespace Server.Items from.AddSkillMod(m_SkillMod); } - if (Core.AOS && m_AosWeaponAttributes.MageWeapon != 0 && m_AosWeaponAttributes.MageWeapon != 30) + if (Core.AOS && WeaponAttributes.MageWeapon != 0 && WeaponAttributes.MageWeapon != 30) { m_MageMod?.Remove(); - m_MageMod = new DefaultSkillMod(SkillName.Magery, true, -30 + m_AosWeaponAttributes.MageWeapon); + m_MageMod = new DefaultSkillMod(SkillName.Magery, true, -30 + WeaponAttributes.MageWeapon); from.AddSkillMod(m_MageMod); } @@ -474,7 +474,7 @@ namespace Server.Items if (parent is Mobile from) { if (Core.AOS) - m_AosSkillBonuses.AddTo(from); + SkillBonuses.AddTo(from); from.CheckStatTimers(); from.Delta(MobileDelta.WeaponDamage); @@ -509,7 +509,7 @@ namespace Server.Items } if (Core.AOS) - m_AosSkillBonuses.Remove(); + SkillBonuses.Remove(); ImmolatingWeaponSpell.StopImmolating(this); @@ -523,11 +523,11 @@ namespace Server.Items { SkillName sk; - if (checkSkillAttrs && m_AosWeaponAttributes.UseBestSkill != 0) + if (checkSkillAttrs && WeaponAttributes.UseBestSkill != 0) { - double swrd = m.Skills[SkillName.Swords].Value; - double fenc = m.Skills[SkillName.Fencing].Value; - double mcng = m.Skills[SkillName.Macing].Value; + double swrd = m.Skills.Swords.Value; + double fenc = m.Skills.Fencing.Value; + double mcng = m.Skills.Macing.Value; double val; sk = SkillName.Swords; @@ -541,9 +541,9 @@ namespace Server.Items if (mcng > val) sk = SkillName.Macing; } - else if (m_AosWeaponAttributes.MageWeapon != 0) + else if (WeaponAttributes.MageWeapon != 0) { - if (m.Skills[SkillName.Magery].Value > m.Skills[Skill].Value) + if (m.Skills.Magery.Value > m.Skills[Skill].Value) sk = SkillName.Magery; else sk = Skill; @@ -553,7 +553,7 @@ namespace Server.Items sk = Skill; if (sk != SkillName.Wrestling && !m.Player && !m.Body.IsHuman && - m.Skills[SkillName.Wrestling].Value > m.Skills[sk].Value) + m.Skills.Wrestling.Value > m.Skills[sk].Value) sk = SkillName.Wrestling; } @@ -704,11 +704,11 @@ namespace Server.Items // Bonus granted by successful use of Honorable Execution. bonus += HonorableExecution.GetSwingBonus(m); - if (DualWield.Registry.Contains(m)) - bonus += ((DualWield.DualWieldTimer)DualWield.Registry[m]).BonusSwingSpeed; + if (DualWield.Registry.ContainsKey(m)) + bonus += DualWield.Registry[m].BonusSwingSpeed; - if (Feint.Registry.Contains(m)) - bonus -= ((Feint.FeintTimer)Feint.Registry[m]).SwingSpeedReduction; + if (Feint.Registry.ContainsKey(m)) + bonus -= Feint.Registry[m].SwingSpeedReduction; TransformContext context = TransformationSpellHelper.GetContext(m); @@ -849,9 +849,9 @@ namespace Server.Items BaseShield shield = defender.FindItemOnLayer(Layer.TwoHanded) as BaseShield; - double parry = defender.Skills[SkillName.Parry].Value; - double bushidoNonRacial = defender.Skills[SkillName.Bushido].NonRacialValue; - double bushido = defender.Skills[SkillName.Bushido].Value; + double parry = defender.Skills.Parry.Value; + double bushidoNonRacial = defender.Skills.Bushido.NonRacialValue; + double bushido = defender.Skills.Bushido.Value; if (shield != null) { @@ -1261,7 +1261,6 @@ namespace Server.Items if (nrgy < low) { - low = nrgy; type = 4; } @@ -1295,7 +1294,7 @@ namespace Server.Items bool ignoreArmor = a is ArmorIgnore || move != null && move.IgnoreArmor(attacker); damageGiven = AOS.Damage(defender, attacker, damage, ignoreArmor, phys, fire, cold, pois, nrgy, chaos, direct, - false, this is BaseRanged, false); + false, this is BaseRanged); double propertyBonus = move?.GetPropertyBonus(attacker) ?? 1.0; @@ -1357,7 +1356,7 @@ namespace Server.Items if (MaxRange <= 1 && (defender is Slime || defender is AcidElemental)) attacker.LocalOverheadMessage(MessageType.Regular, 0x3B2, 500263); // *Acid blood scars your weapon!* - if (Core.AOS && m_AosWeaponAttributes.SelfRepair > Utility.Random(10)) + if (Core.AOS && WeaponAttributes.SelfRepair > Utility.Random(10)) { HitPoints += 2; } @@ -1482,7 +1481,7 @@ namespace Server.Items int damageBonus = 0; // Inscription bonus - int inscribeSkill = attacker.Skills[SkillName.Inscribe].Fixed; + int inscribeSkill = attacker.Skills.Inscribe.Fixed; damageBonus += inscribeSkill / 200; @@ -1575,12 +1574,12 @@ namespace Server.Items } else { - fire = m_AosElementDamages.Fire; - cold = m_AosElementDamages.Cold; - pois = m_AosElementDamages.Poison; - nrgy = m_AosElementDamages.Energy; - chaos = m_AosElementDamages.Chaos; - direct = m_AosElementDamages.Direct; + fire = AosElementDamages.Fire; + cold = AosElementDamages.Cold; + pois = AosElementDamages.Poison; + nrgy = AosElementDamages.Energy; + chaos = AosElementDamages.Chaos; + direct = AosElementDamages.Direct; phys = 100 - fire - cold - pois - nrgy - chaos - direct; @@ -1765,9 +1764,9 @@ namespace Server.Items if (checkSkills) { attacker.CheckSkill(SkillName.Tactics, 0.0, - attacker.Skills[SkillName.Tactics].Cap); // Passively check tactics for gain + attacker.Skills.Tactics.Cap); // Passively check tactics for gain attacker.CheckSkill(SkillName.Anatomy, 0.0, - attacker.Skills[SkillName.Anatomy].Cap); // Passively check Anatomy for gain + attacker.Skills.Anatomy.Cap); // Passively check Anatomy for gain if (Type == WeaponType.Axe) attacker.CheckSkill(SkillName.Lumberjacking, 0.0, 100.0); // Passively check Lumberjacking for gain @@ -1780,9 +1779,9 @@ namespace Server.Items * No caps apply. */ double strengthBonus = GetBonus(attacker.Str, 0.300, 100.0, 5.00); - double anatomyBonus = GetBonus(attacker.Skills[SkillName.Anatomy].Value, 0.500, 100.0, 5.00); - double tacticsBonus = GetBonus(attacker.Skills[SkillName.Tactics].Value, 0.625, 100.0, 6.25); - double lumberBonus = GetBonus(attacker.Skills[SkillName.Lumberjacking].Value, 0.200, 100.0, 10.00); + double anatomyBonus = GetBonus(attacker.Skills.Anatomy.Value, 0.500, 100.0, 5.00); + double tacticsBonus = GetBonus(attacker.Skills.Tactics.Value, 0.625, 100.0, 6.25); + double lumberBonus = GetBonus(attacker.Skills.Lumberjacking.Value, 0.200, 100.0, 10.00); if (Type != WeaponType.Axe) lumberBonus = 0.0; @@ -1838,9 +1837,9 @@ namespace Server.Items if (checkSkills) { attacker.CheckSkill(SkillName.Tactics, 0.0, - attacker.Skills[SkillName.Tactics].Cap); // Passively check tactics for gain + attacker.Skills.Tactics.Cap); // Passively check tactics for gain attacker.CheckSkill(SkillName.Anatomy, 0.0, - attacker.Skills[SkillName.Anatomy].Cap); // Passively check Anatomy for gain + attacker.Skills.Anatomy.Cap); // Passively check Anatomy for gain if (Type == WeaponType.Axe) attacker.CheckSkill(SkillName.Lumberjacking, 0.0, 100.0); // Passively check Lumberjacking for gain @@ -1851,7 +1850,7 @@ namespace Server.Items * : 50.0 = unchanged * : 100.0 = 50% bonus */ - damage += damage * ((attacker.Skills[SkillName.Tactics].Value - 50.0) / 100.0); + damage += damage * ((attacker.Skills.Tactics.Value - 50.0) / 100.0); /* Compute strength modifier @@ -1863,7 +1862,7 @@ namespace Server.Items * : 1% bonus for every 5 points of anatomy * : +10% bonus at Grandmaster or higher */ - double anatomyValue = attacker.Skills[SkillName.Anatomy].Value; + double anatomyValue = attacker.Skills.Anatomy.Value; modifiers += anatomyValue / 5.0 / 100.0; if (anatomyValue >= 100.0) @@ -1875,7 +1874,7 @@ namespace Server.Items */ if (Type == WeaponType.Axe) { - double lumberValue = attacker.Skills[SkillName.Lumberjacking].Value; + double lumberValue = attacker.Skills.Lumberjacking.Value; modifiers += lumberValue / 5.0 / 100.0; @@ -2035,8 +2034,7 @@ namespace Server.Items public int GetElementalDamageHue() { - GetDamageTypes(null, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, - out int direct); + GetDamageTypes(null, out _, out int fire, out int cold, out int pois, out int nrgy, out _, out _); //Order is Cold, Energy, Fire, Poison, Physical left int currentMax = 50; @@ -2158,7 +2156,7 @@ namespace Server.Items if (base.AllowEquippedCast(from)) return true; - return m_AosAttributes.SpellChanneling != 0; + return Attributes.SpellChanneling != 0; } public virtual int GetLuckBonus() @@ -2187,7 +2185,7 @@ namespace Server.Items #endregion - m_AosSkillBonuses?.GetProperties(list); + SkillBonuses?.GetProperties(list); if (m_Quality == WeaponQuality.Exceptional) list.Add(1060636); // exceptional @@ -2228,70 +2226,70 @@ namespace Server.Items if (Core.ML && ranged?.Balanced == true) list.Add(1072792); // Balanced - if ((prop = m_AosWeaponAttributes.UseBestSkill) != 0) + if ((prop = WeaponAttributes.UseBestSkill) != 0) list.Add(1060400); // use best weapon skill - if ((prop = GetDamageBonus() + m_AosAttributes.WeaponDamage) != 0) + if ((prop = GetDamageBonus() + Attributes.WeaponDamage) != 0) list.Add(1060401, prop.ToString()); // damage increase ~1_val~% - if ((prop = m_AosAttributes.DefendChance) != 0) + if ((prop = Attributes.DefendChance) != 0) list.Add(1060408, prop.ToString()); // defense chance increase ~1_val~% - if ((prop = m_AosAttributes.EnhancePotions) != 0) + if ((prop = Attributes.EnhancePotions) != 0) list.Add(1060411, prop.ToString()); // enhance potions ~1_val~% - if ((prop = m_AosAttributes.CastRecovery) != 0) + if ((prop = Attributes.CastRecovery) != 0) list.Add(1060412, prop.ToString()); // faster cast recovery ~1_val~ - if ((prop = m_AosAttributes.CastSpeed) != 0) + if ((prop = Attributes.CastSpeed) != 0) list.Add(1060413, prop.ToString()); // faster casting ~1_val~ - if ((prop = GetHitChanceBonus() + m_AosAttributes.AttackChance) != 0) + if ((prop = GetHitChanceBonus() + Attributes.AttackChance) != 0) list.Add(1060415, prop.ToString()); // hit chance increase ~1_val~% - if ((prop = m_AosWeaponAttributes.HitColdArea) != 0) + if ((prop = WeaponAttributes.HitColdArea) != 0) list.Add(1060416, prop.ToString()); // hit cold area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitDispel) != 0) + if ((prop = WeaponAttributes.HitDispel) != 0) list.Add(1060417, prop.ToString()); // hit dispel ~1_val~% - if ((prop = m_AosWeaponAttributes.HitEnergyArea) != 0) + if ((prop = WeaponAttributes.HitEnergyArea) != 0) list.Add(1060418, prop.ToString()); // hit energy area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitFireArea) != 0) + if ((prop = WeaponAttributes.HitFireArea) != 0) list.Add(1060419, prop.ToString()); // hit fire area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitFireball) != 0) + if ((prop = WeaponAttributes.HitFireball) != 0) list.Add(1060420, prop.ToString()); // hit fireball ~1_val~% - if ((prop = m_AosWeaponAttributes.HitHarm) != 0) + if ((prop = WeaponAttributes.HitHarm) != 0) list.Add(1060421, prop.ToString()); // hit harm ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLeechHits) != 0) + if ((prop = WeaponAttributes.HitLeechHits) != 0) list.Add(1060422, prop.ToString()); // hit life leech ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLightning) != 0) + if ((prop = WeaponAttributes.HitLightning) != 0) list.Add(1060423, prop.ToString()); // hit lightning ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLowerAttack) != 0) + if ((prop = WeaponAttributes.HitLowerAttack) != 0) list.Add(1060424, prop.ToString()); // hit lower attack ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLowerDefend) != 0) + if ((prop = WeaponAttributes.HitLowerDefend) != 0) list.Add(1060425, prop.ToString()); // hit lower defense ~1_val~% - if ((prop = m_AosWeaponAttributes.HitMagicArrow) != 0) + if ((prop = WeaponAttributes.HitMagicArrow) != 0) list.Add(1060426, prop.ToString()); // hit magic arrow ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLeechMana) != 0) + if ((prop = WeaponAttributes.HitLeechMana) != 0) list.Add(1060427, prop.ToString()); // hit mana leech ~1_val~% - if ((prop = m_AosWeaponAttributes.HitPhysicalArea) != 0) + if ((prop = WeaponAttributes.HitPhysicalArea) != 0) list.Add(1060428, prop.ToString()); // hit physical area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitPoisonArea) != 0) + if ((prop = WeaponAttributes.HitPoisonArea) != 0) list.Add(1060429, prop.ToString()); // hit poison area ~1_val~% - if ((prop = m_AosWeaponAttributes.HitLeechStam) != 0) + if ((prop = WeaponAttributes.HitLeechStam) != 0) list.Add(1060430, prop.ToString()); // hit stamina leech ~1_val~% if (ImmolatingWeaponSpell.IsImmolating(this)) @@ -2300,67 +2298,67 @@ namespace Server.Items if (Core.ML && (ranged?.Velocity ?? 0) != 0) list.Add(1072793, prop.ToString()); // Velocity ~1_val~% - if ((prop = m_AosAttributes.BonusDex) != 0) + if ((prop = Attributes.BonusDex) != 0) list.Add(1060409, prop.ToString()); // dexterity bonus ~1_val~ - if ((prop = m_AosAttributes.BonusHits) != 0) + if ((prop = Attributes.BonusHits) != 0) list.Add(1060431, prop.ToString()); // hit point increase ~1_val~ - if ((prop = m_AosAttributes.BonusInt) != 0) + if ((prop = Attributes.BonusInt) != 0) list.Add(1060432, prop.ToString()); // intelligence bonus ~1_val~ - if ((prop = m_AosAttributes.LowerManaCost) != 0) + if ((prop = Attributes.LowerManaCost) != 0) list.Add(1060433, prop.ToString()); // lower mana cost ~1_val~% - if ((prop = m_AosAttributes.LowerRegCost) != 0) + if ((prop = Attributes.LowerRegCost) != 0) list.Add(1060434, prop.ToString()); // lower reagent cost ~1_val~% if ((prop = GetLowerStatReq()) != 0) list.Add(1060435, prop.ToString()); // lower requirements ~1_val~% - if ((prop = GetLuckBonus() + m_AosAttributes.Luck) != 0) + if ((prop = GetLuckBonus() + Attributes.Luck) != 0) list.Add(1060436, prop.ToString()); // luck ~1_val~ - if ((prop = m_AosWeaponAttributes.MageWeapon) != 0) + if ((prop = WeaponAttributes.MageWeapon) != 0) list.Add(1060438, (30 - prop).ToString()); // mage weapon -~1_val~ skill - if ((prop = m_AosAttributes.BonusMana) != 0) + if ((prop = Attributes.BonusMana) != 0) list.Add(1060439, prop.ToString()); // mana increase ~1_val~ - if ((prop = m_AosAttributes.RegenMana) != 0) + if ((prop = Attributes.RegenMana) != 0) list.Add(1060440, prop.ToString()); // mana regeneration ~1_val~ - if ((prop = m_AosAttributes.NightSight) != 0) + if ((prop = Attributes.NightSight) != 0) list.Add(1060441); // night sight - if ((prop = m_AosAttributes.ReflectPhysical) != 0) + if ((prop = Attributes.ReflectPhysical) != 0) list.Add(1060442, prop.ToString()); // reflect physical damage ~1_val~% - if ((prop = m_AosAttributes.RegenStam) != 0) + if ((prop = Attributes.RegenStam) != 0) list.Add(1060443, prop.ToString()); // stamina regeneration ~1_val~ - if ((prop = m_AosAttributes.RegenHits) != 0) + if ((prop = Attributes.RegenHits) != 0) list.Add(1060444, prop.ToString()); // hit point regeneration ~1_val~ - if ((prop = m_AosWeaponAttributes.SelfRepair) != 0) + if ((prop = WeaponAttributes.SelfRepair) != 0) list.Add(1060450, prop.ToString()); // self repair ~1_val~ - if ((prop = m_AosAttributes.SpellChanneling) != 0) + if ((prop = Attributes.SpellChanneling) != 0) list.Add(1060482); // spell channeling - if ((prop = m_AosAttributes.SpellDamage) != 0) + if ((prop = Attributes.SpellDamage) != 0) list.Add(1060483, prop.ToString()); // spell damage increase ~1_val~% - if ((prop = m_AosAttributes.BonusStam) != 0) + if ((prop = Attributes.BonusStam) != 0) list.Add(1060484, prop.ToString()); // stamina increase ~1_val~ - if ((prop = m_AosAttributes.BonusStr) != 0) + if ((prop = Attributes.BonusStr) != 0) list.Add(1060485, prop.ToString()); // strength bonus ~1_val~ - if ((prop = m_AosAttributes.WeaponSpeed) != 0) + if ((prop = Attributes.WeaponSpeed) != 0) list.Add(1060486, prop.ToString()); // swing speed increase ~1_val~% - if (Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0) + if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0) list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~% GetDamageTypes(null, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, @@ -2407,7 +2405,7 @@ namespace Server.Items else list.Add(1061824); // one-handed weapon - if (Core.SE || m_AosWeaponAttributes.UseBestSkill == 0) + if (Core.SE || WeaponAttributes.UseBestSkill == 0) switch (Skill) { case SkillName.Swords: @@ -2516,7 +2514,7 @@ namespace Server.Items protected override void OnTick() { - m_Mobile.EndAction(typeof(BaseWeapon)); + m_Mobile.EndAction(); } } @@ -2574,11 +2572,6 @@ namespace Server.Items private SkillMod m_SkillMod, m_MageMod; private CraftResource m_Resource; - private AosAttributes m_AosAttributes; - private AosWeaponAttributes m_AosWeaponAttributes; - private AosSkillBonuses m_AosSkillBonuses; - private AosElementAttributes m_AosElementDamages; - // Overridable values. These values are provided to override the defaults which get defined in the individual weapon scripts. private int m_StrReq, m_DexReq, m_IntReq; private int m_MinDamage, m_MaxDamage; @@ -2635,11 +2628,11 @@ namespace Server.Items public virtual bool CanFortify => true; - public override int PhysicalResistance => m_AosWeaponAttributes.ResistPhysicalBonus; - public override int FireResistance => m_AosWeaponAttributes.ResistFireBonus; - public override int ColdResistance => m_AosWeaponAttributes.ResistColdBonus; - public override int PoisonResistance => m_AosWeaponAttributes.ResistPoisonBonus; - public override int EnergyResistance => m_AosWeaponAttributes.ResistEnergyBonus; + public override int PhysicalResistance => WeaponAttributes.ResistPhysicalBonus; + public override int FireResistance => WeaponAttributes.ResistFireBonus; + public override int ColdResistance => WeaponAttributes.ResistColdBonus; + public override int PoisonResistance => WeaponAttributes.ResistPoisonBonus; + public override int EnergyResistance => WeaponAttributes.ResistEnergyBonus; public virtual SkillName AccuracySkill => SkillName.Tactics; @@ -2648,32 +2641,16 @@ namespace Server.Items #region Getters & Setters [CommandProperty(AccessLevel.GameMaster)] - public AosAttributes Attributes - { - get => m_AosAttributes; - set { } - } + public AosAttributes Attributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosWeaponAttributes WeaponAttributes - { - get => m_AosWeaponAttributes; - set { } - } + public AosWeaponAttributes WeaponAttributes{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosSkillBonuses SkillBonuses - { - get => m_AosSkillBonuses; - set { } - } + public AosSkillBonuses SkillBonuses{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] - public AosElementAttributes AosElementDamages - { - get => m_AosElementDamages; - set { } - } + public AosElementAttributes AosElementDamages{ get; private set; } [CommandProperty(AccessLevel.GameMaster)] public bool Cursed{ get; set; } @@ -3217,12 +3194,12 @@ namespace Server.Items SetSaveFlag(ref flags, SaveFlag.Type, m_Type != (WeaponType)(-1)); SetSaveFlag(ref flags, SaveFlag.Animation, m_Animation != (WeaponAnimation)(-1)); SetSaveFlag(ref flags, SaveFlag.Resource, m_Resource != CraftResource.Iron); - SetSaveFlag(ref flags, SaveFlag.xAttributes, !m_AosAttributes.IsEmpty); - SetSaveFlag(ref flags, SaveFlag.xWeaponAttributes, !m_AosWeaponAttributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.xAttributes, !Attributes.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.xWeaponAttributes, !WeaponAttributes.IsEmpty); SetSaveFlag(ref flags, SaveFlag.PlayerConstructed, PlayerConstructed); - SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !m_AosSkillBonuses.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.SkillBonuses, !SkillBonuses.IsEmpty); SetSaveFlag(ref flags, SaveFlag.Slayer2, m_Slayer2 != SlayerName.None); - SetSaveFlag(ref flags, SaveFlag.ElementalDamages, !m_AosElementDamages.IsEmpty); + SetSaveFlag(ref flags, SaveFlag.ElementalDamages, !AosElementDamages.IsEmpty); SetSaveFlag(ref flags, SaveFlag.EngravedText, !string.IsNullOrEmpty(m_EngravedText)); writer.Write((int)flags); @@ -3297,19 +3274,19 @@ namespace Server.Items writer.Write((int)m_Resource); if (GetSaveFlag(flags, SaveFlag.xAttributes)) - m_AosAttributes.Serialize(writer); + Attributes.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.xWeaponAttributes)) - m_AosWeaponAttributes.Serialize(writer); + WeaponAttributes.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.SkillBonuses)) - m_AosSkillBonuses.Serialize(writer); + SkillBonuses.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.Slayer2)) writer.Write((int)m_Slayer2); if (GetSaveFlag(flags, SaveFlag.ElementalDamages)) - m_AosElementDamages.Serialize(writer); + AosElementDamages.Serialize(writer); if (GetSaveFlag(flags, SaveFlag.EngravedText)) writer.Write(m_EngravedText); @@ -3493,14 +3470,14 @@ namespace Server.Items m_Resource = CraftResource.Iron; if (GetSaveFlag(flags, SaveFlag.xAttributes)) - m_AosAttributes = new AosAttributes(this, reader); + Attributes = new AosAttributes(this, reader); else - m_AosAttributes = new AosAttributes(this); + Attributes = new AosAttributes(this); if (GetSaveFlag(flags, SaveFlag.xWeaponAttributes)) - m_AosWeaponAttributes = new AosWeaponAttributes(this, reader); + WeaponAttributes = new AosWeaponAttributes(this, reader); else - m_AosWeaponAttributes = new AosWeaponAttributes(this); + WeaponAttributes = new AosWeaponAttributes(this); if (UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular && parentMobile != null) { @@ -3508,13 +3485,13 @@ namespace Server.Items parentMobile.AddSkillMod(m_SkillMod); } - if (version < 7 && m_AosWeaponAttributes.MageWeapon != 0) - m_AosWeaponAttributes.MageWeapon = 30 - m_AosWeaponAttributes.MageWeapon; + if (version < 7 && WeaponAttributes.MageWeapon != 0) + WeaponAttributes.MageWeapon = 30 - WeaponAttributes.MageWeapon; - if (Core.AOS && m_AosWeaponAttributes.MageWeapon != 0 && m_AosWeaponAttributes.MageWeapon != 30 && + if (Core.AOS && WeaponAttributes.MageWeapon != 0 && WeaponAttributes.MageWeapon != 30 && parentMobile != null) { - m_MageMod = new DefaultSkillMod(SkillName.Magery, true, -30 + m_AosWeaponAttributes.MageWeapon); + m_MageMod = new DefaultSkillMod(SkillName.Magery, true, -30 + WeaponAttributes.MageWeapon); parentMobile.AddSkillMod(m_MageMod); } @@ -3522,17 +3499,17 @@ namespace Server.Items PlayerConstructed = true; if (GetSaveFlag(flags, SaveFlag.SkillBonuses)) - m_AosSkillBonuses = new AosSkillBonuses(this, reader); + SkillBonuses = new AosSkillBonuses(this, reader); else - m_AosSkillBonuses = new AosSkillBonuses(this); + SkillBonuses = new AosSkillBonuses(this); if (GetSaveFlag(flags, SaveFlag.Slayer2)) m_Slayer2 = (SlayerName)reader.ReadInt(); if (GetSaveFlag(flags, SaveFlag.ElementalDamages)) - m_AosElementDamages = new AosElementAttributes(this, reader); + AosElementDamages = new AosElementAttributes(this, reader); else - m_AosElementDamages = new AosElementAttributes(this); + AosElementDamages = new AosElementAttributes(this); if (GetSaveFlag(flags, SaveFlag.EngravedText)) m_EngravedText = reader.ReadString(); @@ -3573,10 +3550,10 @@ namespace Server.Items if (version < 5) { m_Resource = CraftResource.Iron; - m_AosAttributes = new AosAttributes(this); - m_AosWeaponAttributes = new AosWeaponAttributes(this); - m_AosElementDamages = new AosElementAttributes(this); - m_AosSkillBonuses = new AosSkillBonuses(this); + Attributes = new AosAttributes(this); + WeaponAttributes = new AosWeaponAttributes(this); + AosElementDamages = new AosElementAttributes(this); + SkillBonuses = new AosSkillBonuses(this); } m_MinDamage = reader.ReadInt(); @@ -3647,11 +3624,11 @@ namespace Server.Items } if (Core.AOS && parentMobile != null) - m_AosSkillBonuses.AddTo(parentMobile); + SkillBonuses.AddTo(parentMobile); - int strBonus = m_AosAttributes.BonusStr; - int dexBonus = m_AosAttributes.BonusDex; - int intBonus = m_AosAttributes.BonusInt; + int strBonus = Attributes.BonusStr; + int dexBonus = Attributes.BonusDex; + int intBonus = Attributes.BonusInt; if (parentMobile != null && (strBonus != 0 || dexBonus != 0 || intBonus != 0)) { @@ -3684,4 +3661,4 @@ namespace Server.Items Slayer, Opposition } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Fists.cs b/Scripts/Items/Weapons/Fists.cs index 9f84c3f31..f2f146475 100644 --- a/Scripts/Items/Weapons/Fists.cs +++ b/Scripts/Items/Weapons/Fists.cs @@ -47,9 +47,9 @@ namespace Server.Items public override double GetDefendSkillValue(Mobile attacker, Mobile defender) { - double wresValue = defender.Skills[SkillName.Wrestling].Value; - double anatValue = defender.Skills[SkillName.Anatomy].Value; - double evalValue = defender.Skills[SkillName.EvalInt].Value; + double wresValue = defender.Skills.Wrestling.Value; + double anatValue = defender.Skills.Anatomy.Value; + double evalValue = defender.Skills.EvalInt.Value; double incrValue = (anatValue + evalValue + 20.0) * 0.5; if (incrValue > 120.0) @@ -64,10 +64,10 @@ namespace Server.Items { if (attacker.StunReady) { - if (attacker.CanBeginAction(typeof(Fists))) + if (attacker.CanBeginAction()) { - if (attacker.Skills[SkillName.Anatomy].Value >= 80.0 && - attacker.Skills[SkillName.Wrestling].Value >= 80.0) + if (attacker.Skills.Anatomy.Value >= 80.0 && + attacker.Skills.Wrestling.Value >= 80.0) { if (attacker.Stam >= 15) { @@ -104,12 +104,12 @@ namespace Server.Items } else if (attacker.DisarmReady) { - if (attacker.CanBeginAction(typeof(Fists))) + if (attacker.CanBeginAction()) { if (defender.Player || defender.Body.IsHuman) { - if (attacker.Skills[SkillName.ArmsLore].Value >= 80.0 && - attacker.Skills[SkillName.Wrestling].Value >= 80.0) + if (attacker.Skills.ArmsLore.Value >= 80.0 && + attacker.Skills.Wrestling.Value >= 80.0) { if (attacker.Stam >= 15) { @@ -196,7 +196,7 @@ namespace Server.Items private static bool CheckMove(Mobile m, SkillName other) { - double wresValue = m.Skills[SkillName.Wrestling].Value; + double wresValue = m.Skills.Wrestling.Value; double scndValue = m.Skills[other].Value; /* 40% chance at 80, 80 @@ -233,8 +233,8 @@ namespace Server.Items #endregion - double armsValue = m.Skills[SkillName.ArmsLore].Value; - double wresValue = m.Skills[SkillName.Wrestling].Value; + double armsValue = m.Skills.ArmsLore.Value; + double wresValue = m.Skills.Wrestling.Value; if (!HasFreeHands(m)) { @@ -268,8 +268,8 @@ namespace Server.Items #endregion - double anatValue = m.Skills[SkillName.Anatomy].Value; - double wresValue = m.Skills[SkillName.Wrestling].Value; + double anatValue = m.Skills.Anatomy.Value; + double wresValue = m.Skills.Wrestling.Value; if (!HasFreeHands(m)) { @@ -304,12 +304,12 @@ namespace Server.Items Priority = TimerPriority.TwoFiftyMS; - m_Mobile.BeginAction(typeof(Fists)); + m_Mobile.BeginAction(); } protected override void OnTick() { - m_Mobile.EndAction(typeof(Fists)); + m_Mobile.EndAction(); } } } diff --git a/Scripts/Items/Weapons/HitLower.cs b/Scripts/Items/Weapons/HitLower.cs index a8cc9386f..aab3a262f 100644 --- a/Scripts/Items/Weapons/HitLower.cs +++ b/Scripts/Items/Weapons/HitLower.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Items { @@ -8,13 +9,12 @@ namespace Server.Items public static readonly TimeSpan AttackEffectDuration = TimeSpan.FromSeconds(10.0); public static readonly TimeSpan DefenseEffectDuration = TimeSpan.FromSeconds(8.0); - private static Hashtable m_AttackTable = new Hashtable(); - - private static Hashtable m_DefenseTable = new Hashtable(); + private static Dictionary m_AttackTable = new Dictionary(); + private static Dictionary m_DefenseTable = new Dictionary(); public static bool IsUnderAttackEffect(Mobile m) { - return m_AttackTable.Contains(m); + return m_AttackTable.ContainsKey(m); } public static bool ApplyAttack(Mobile m) @@ -35,7 +35,7 @@ namespace Server.Items public static bool IsUnderDefenseEffect(Mobile m) { - return m_DefenseTable.Contains(m); + return m_DefenseTable.ContainsKey(m); } public static bool ApplyDefense(Mobile m) @@ -92,4 +92,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Maces/BaseBashing.cs b/Scripts/Items/Weapons/Maces/BaseBashing.cs index 612a69819..c943a6762 100644 --- a/Scripts/Items/Weapons/Maces/BaseBashing.cs +++ b/Scripts/Items/Weapons/Maces/BaseBashing.cs @@ -45,8 +45,8 @@ namespace Server.Items double damage = base.GetBaseDamage(attacker); if (!Core.AOS && (attacker.Player || attacker.Body.IsHuman) && Layer == Layer.TwoHanded && - attacker.Skills[SkillName.Anatomy].Value >= 80 && - attacker.Skills[SkillName.Anatomy].Value / 400.0 >= Utility.RandomDouble() && + attacker.Skills.Anatomy.Value >= 80 && + attacker.Skills.Anatomy.Value / 400.0 >= Utility.RandomDouble() && DuelContext.AllowSpecialAbility(attacker, "Crushing Blow", false)) { damage *= 1.5; diff --git a/Scripts/Items/Weapons/Maces/FireworksWand.cs b/Scripts/Items/Weapons/Maces/FireworksWand.cs index 2946c633a..5c6a17527 100644 --- a/Scripts/Items/Weapons/Maces/FireworksWand.cs +++ b/Scripts/Items/Weapons/Maces/FireworksWand.cs @@ -78,18 +78,11 @@ namespace Server.Items Effects.SendMovingEffect(new Entity(Serial.Zero, startLoc, map), new Entity(Serial.Zero, endLoc, map), 0x36E4, 5, 0, false, false); - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(FinishLaunch), - new object[] { from, endLoc, map }); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => FinishLaunch(endLoc, map)); } - private void FinishLaunch(object state) + private void FinishLaunch(Point3D endLoc, Map map) { - object[] states = (object[])state; - - Mobile from = (Mobile)states[0]; - Point3D endLoc = (Point3D)states[1]; - Map map = (Map)states[2]; - int hue = Utility.Random(40); if (hue < 8) diff --git a/Scripts/Items/Weapons/PoleArms/BasePoleArm.cs b/Scripts/Items/Weapons/PoleArms/BasePoleArm.cs index e7628763a..abe653266 100644 --- a/Scripts/Items/Weapons/PoleArms/BasePoleArm.cs +++ b/Scripts/Items/Weapons/PoleArms/BasePoleArm.cs @@ -115,8 +115,8 @@ namespace Server.Items base.OnHit(attacker, defender, damageBonus); if (!Core.AOS && (attacker.Player || attacker.Body.IsHuman) && Layer == Layer.TwoHanded && - attacker.Skills[SkillName.Anatomy].Value >= 80 && - attacker.Skills[SkillName.Anatomy].Value / 400.0 >= Utility.RandomDouble() && + attacker.Skills.Anatomy.Value >= 80 && + attacker.Skills.Anatomy.Value / 400.0 >= Utility.RandomDouble() && DuelContext.AllowSpecialAbility(attacker, "Concussion Blow", false)) { StatMod mod = defender.GetStatMod("Concussion"); diff --git a/Scripts/Items/Weapons/Ranged/JukaBow.cs b/Scripts/Items/Weapons/Ranged/JukaBow.cs index bba29c71f..0636ceb74 100644 --- a/Scripts/Items/Weapons/Ranged/JukaBow.cs +++ b/Scripts/Items/Weapons/Ranged/JukaBow.cs @@ -33,7 +33,7 @@ namespace Server.Items { from.SendMessage("This must be in your backpack to modify it."); } - else if (from.Skills[SkillName.Fletching].Base < 100.0) + else if (from.Skills.Fletching.Base < 100.0) { from.SendMessage("Only a grandmaster bowcrafter can modify this weapon."); } @@ -59,7 +59,7 @@ namespace Server.Items { from.SendMessage("This must be in your backpack to modify it."); } - else if (from.Skills[SkillName.Fletching].Base < 100.0) + else if (from.Skills.Fletching.Base < 100.0) { from.SendMessage("Only a grandmaster bowcrafter can modify this weapon."); } diff --git a/Scripts/Items/Weapons/SpearsAndForks/BaseSpear.cs b/Scripts/Items/Weapons/SpearsAndForks/BaseSpear.cs index 3bc11185e..3d6df7197 100644 --- a/Scripts/Items/Weapons/SpearsAndForks/BaseSpear.cs +++ b/Scripts/Items/Weapons/SpearsAndForks/BaseSpear.cs @@ -39,7 +39,7 @@ namespace Server.Items base.OnHit(attacker, defender, damageBonus); if (!Core.AOS && Layer == Layer.TwoHanded && - attacker.Skills[SkillName.Anatomy].Value / 400.0 >= Utility.RandomDouble() && + attacker.Skills.Anatomy.Value / 400.0 >= Utility.RandomDouble() && DuelContext.AllowSpecialAbility(attacker, "Paralyzing Blow", false)) { defender.SendMessage("You receive a paralyzing blow!"); // Is this not localized? diff --git a/Scripts/Items/Weapons/Staves/ShepherdsCrook.cs b/Scripts/Items/Weapons/Staves/ShepherdsCrook.cs index aebf9be52..95896f455 100644 --- a/Scripts/Items/Weapons/Staves/ShepherdsCrook.cs +++ b/Scripts/Items/Weapons/Staves/ShepherdsCrook.cs @@ -145,7 +145,7 @@ namespace Server.Items double min = m_Creature.MinTameSkill - 30; double max = m_Creature.MinTameSkill + 30 + Utility.Random(10); - if (max <= from.Skills[SkillName.Herding].Value) + if (max <= from.Skills.Herding.Value) m_Creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502471, from.NetState); // That wasn't even challenging. diff --git a/Scripts/Misc/AOS.cs b/Scripts/Misc/AOS.cs index 86b44e957..702445c02 100644 --- a/Scripts/Misc/AOS.cs +++ b/Scripts/Misc/AOS.cs @@ -1019,12 +1019,10 @@ namespace Server public void GetProperties(ObjectPropertyList list) { + SkillName skill; for (int i = 0; i < 5; ++i) { - SkillName skill; - double bonus; - - if (!GetValues(i, out skill, out bonus)) + if (!GetValues(i, out skill, out double bonus)) continue; list.Add(1060451 + i, "#{0}\t{1}", GetLabel(skill), bonus); @@ -1123,10 +1121,7 @@ namespace Server public SkillName GetSkill(int index) { - SkillName skill; - double bonus; - - GetValues(index, out skill, out bonus); + GetValues(index, out SkillName skill, out double _); return skill; } @@ -1138,10 +1133,7 @@ namespace Server public double GetBonus(int index) { - SkillName skill; - double bonus; - - GetValues(index, out skill, out bonus); + GetValues(index, out SkillName _, out double bonus); return bonus; } @@ -1161,15 +1153,12 @@ namespace Server if (m == null) return; - double minSkill, maxSkill; - AnimalFormContext acontext = AnimalForm.GetContext(m); TransformContext context = TransformationSpellHelper.GetContext(m); - if (context != null) + if (context?.Spell is Spell spell) { - Spell spell = context.Spell as Spell; - spell.GetCastSkills(out minSkill, out maxSkill); + spell.GetCastSkills(out double minSkill, out _); if (m.Skills[spell.CastSkill].Value < minSkill) TransformationSpellHelper.RemoveContext(m, context, true); } @@ -1180,28 +1169,28 @@ namespace Server for (i = 0; i < AnimalForm.Entries.Length; ++i) if (AnimalForm.Entries[i].Type == acontext.Type) break; - if (m.Skills[SkillName.Ninjitsu].Value < AnimalForm.Entries[i].ReqSkill) + if (m.Skills.Ninjitsu.Value < AnimalForm.Entries[i].ReqSkill) AnimalForm.RemoveContext(m, true); } - if (!m.CanBeginAction(typeof(PolymorphSpell)) && m.Skills[SkillName.Magery].Value < 66.1) + if (!m.CanBeginAction() && m.Skills.Magery.Value < 66.1) { m.BodyMod = 0; m.HueMod = -1; m.NameMod = null; - m.EndAction(typeof(PolymorphSpell)); + m.EndAction(); BaseArmor.ValidateMobile(m); BaseClothing.ValidateMobile(m); } - if (!m.CanBeginAction(typeof(IncognitoSpell)) && m.Skills[SkillName.Magery].Value < 38.1) + if (!m.CanBeginAction() && m.Skills.Magery.Value < 38.1) { if (m is PlayerMobile mobile) mobile.SetHairMods(-1, -1); m.BodyMod = 0; m.HueMod = -1; m.NameMod = null; - m.EndAction(typeof(IncognitoSpell)); + m.EndAction(); BaseArmor.ValidateMobile(m); BaseClothing.ValidateMobile(m); BuffInfo.RemoveBuff(m, BuffIcon.Incognito); diff --git a/Scripts/Misc/Assistants.cs b/Scripts/Misc/Assistants.cs index b18b97e34..561b791b2 100644 --- a/Scripts/Misc/Assistants.cs +++ b/Scripts/Misc/Assistants.cs @@ -86,9 +86,6 @@ namespace Server.Misc { private static Dictionary m_Dictionary = new Dictionary(); - private static TimerStateCallback OnHandshakeTimeout_Callback = OnHandshakeTimeout; - private static TimerStateCallback OnForceDisconnect_Callback = OnForceDisconnect; - public static void Initialize() { if (Settings.Enabled) @@ -112,7 +109,7 @@ namespace Server.Misc if (m_Dictionary.TryGetValue(m, out Timer t)) t?.Stop(); - m_Dictionary[m] = t = Timer.DelayCall(Settings.HandshakeTimeout, OnHandshakeTimeout_Callback, m); + m_Dictionary[m] = t = Timer.DelayCall(Settings.HandshakeTimeout, OnHandshakeTimeout, m); t.Start(); } } @@ -133,9 +130,9 @@ namespace Server.Misc } } - private static void OnHandshakeTimeout(object state) + private static void OnHandshakeTimeout(Mobile m) { - if (!(state is Mobile m)) + if (m == null) return; m_Dictionary.Remove(m); @@ -145,30 +142,30 @@ namespace Server.Misc // Console.WriteLine("Player '{0}' failed to negotiate features.", m); // } - if (m.NetState != null && m.NetState.Running) + if (m.NetState?.Running == true) { - m.SendGump(new WarningGump(1060635, 30720, Settings.WarningMessage, 0xFFC000, 420, 250, null, null)); + m.SendGump(new WarningGump(1060635, 30720, Settings.WarningMessage, 0xFFC000, 420, 250)); if (m.AccessLevel <= AccessLevel.Player) { Timer t; - m_Dictionary[m] = t = Timer.DelayCall(Settings.DisconnectDelay, OnForceDisconnect_Callback, m); + m_Dictionary[m] = t = Timer.DelayCall(Settings.DisconnectDelay, OnForceDisconnect, m); t.Start(); } } } - private static void OnForceDisconnect(object state) + private static void OnForceDisconnect(Mobile m) { - if (state is Mobile m) - { - if (m.NetState != null && m.NetState.Running) - m.NetState.Dispose(); + if (m == null) + return; + + if (m.NetState != null && m.NetState.Running) + m.NetState.Dispose(); - m_Dictionary.Remove(m); + m_Dictionary.Remove(m); - Console.WriteLine("Player {0} kicked (Failed assistant handshake)", m); - } + Console.WriteLine("Player {0} kicked (Failed assistant handshake)", m); } private sealed class BeginHandshake : ProtocolExtension diff --git a/Scripts/Misc/ClientVerification.cs b/Scripts/Misc/ClientVerification.cs index f7d1050b9..ea24ae0e5 100644 --- a/Scripts/Misc/ClientVerification.cs +++ b/Scripts/Misc/ClientVerification.cs @@ -136,26 +136,27 @@ namespace Server.Misc } } + private static void KickMessage(Mobile from, bool okay) + { + from.SendMessage("You will be reminded of this again."); + + if (m_OldClientResponse == OldClientResponse.LenientKick) + from.SendMessage( + "Old clients will be kicked after {0} days of character age and {1} hours of play time", + m_AgeLeniency, m_GameTimeLeniency); + + Timer.DelayCall(TimeSpan.FromMinutes(Utility.Random(5, 15)), () => SendAnnoyGump(from)); + } + private static void SendAnnoyGump(Mobile m) { if (m.NetState != null && m.NetState.Version < Required) { Gump g = new WarningGump(1060637, 30720, $"Your client is out of date. Please update your client.
This server recommends that your client version be at least {Required}.

You are currently using version {m.NetState.Version}.

To patch, run UOPatch.exe inside your Ultima Online folder.", - 0xFFC000, 480, 360, - delegate - { - m.SendMessage("You will be reminded of this again."); + 0xFFC000, 480, 360, okay => KickMessage(m, okay), false); - if (m_OldClientResponse == OldClientResponse.LenientKick) - m.SendMessage( - "Old clients will be kicked after {0} days of character age and {1} hours of play time", - m_AgeLeniency, m_GameTimeLeniency); - - Timer.DelayCall(TimeSpan.FromMinutes(Utility.Random(5, 15)), delegate { SendAnnoyGump(m); }); - }, null, false); - - g.Dragable = false; + g.Draggable = false; g.Closable = false; g.Resizable = false; diff --git a/Scripts/Misc/Gifts/Winter2004/Mistletoe.cs b/Scripts/Misc/Gifts/Winter2004/Mistletoe.cs index b451de605..3bc58969b 100644 --- a/Scripts/Misc/Gifts/Winter2004/Mistletoe.cs +++ b/Scripts/Misc/Gifts/Winter2004/Mistletoe.cs @@ -105,7 +105,7 @@ namespace Server.Items { if (from.InRange(GetWorldLocation(), 3)) { - from.CloseGump(typeof(MistletoeAddonGump)); + from.CloseGump(); from.SendGump(new MistletoeAddonGump(from, this)); } else @@ -216,7 +216,7 @@ namespace Server.Items if (house != null && house.IsCoOwner(from)) { from.SendLocalizedMessage(1062838); // Where would you like to place this decoration? - from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget, null); + from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget); } else { @@ -229,7 +229,7 @@ namespace Server.Items } } - public void Placement_OnTarget(Mobile from, object targeted, object state) + public void Placement_OnTarget(Mobile from, object targeted) { if (!(targeted is IPoint3D p)) return; diff --git a/Scripts/Misc/Gifts/Winter2004/PileOfGlacialSnow.cs b/Scripts/Misc/Gifts/Winter2004/PileOfGlacialSnow.cs index b4883b1d3..596e0b145 100644 --- a/Scripts/Misc/Gifts/Winter2004/PileOfGlacialSnow.cs +++ b/Scripts/Misc/Gifts/Winter2004/PileOfGlacialSnow.cs @@ -65,7 +65,7 @@ namespace Server.Items from.SendLocalizedMessage(1010097); // You cannot use this while mounted. } - else if (from.CanBeginAction(typeof(SnowPile))) + else if (from.CanBeginAction()) { from.SendLocalizedMessage(1005575); // You carefully pack the snow into a ball... from.Target = new SnowTarget(from, this); @@ -87,7 +87,7 @@ namespace Server.Items protected override void OnTick() { - m_From.EndAction(typeof(SnowPile)); + m_From.EndAction(); } } @@ -112,13 +112,13 @@ namespace Server.Items { Container pack = targ.Backpack; - if (from.Region.IsPartOf(typeof(SafeZone)) || targ.Region.IsPartOf(typeof(SafeZone))) + if (from.Region.IsPartOf() || targ.Region.IsPartOf()) { from.SendMessage("You may not throw snow here."); } else if (pack?.FindItemByType(new[] { typeof(SnowPile), typeof(PileOfGlacialSnow) }) != null) { - if (from.BeginAction(typeof(SnowPile))) + if (from.BeginAction()) { new InternalTimer(from).Start(); @@ -129,7 +129,7 @@ namespace Server.Items targ.SendLocalizedMessage(1010572); // You have just been hit by a snowball! from.SendLocalizedMessage(1010573); // You throw the snowball and hit the target! - Effects.SendMovingEffect(from, targ, 0x36E4, 7, 0, false, true, 0x47F, 0); + Effects.SendMovingEffect(from, targ, 0x36E4, 7, 0, false, true, 0x47F); } else { diff --git a/Scripts/Misc/Gifts/Winter2004/SnowPile.cs b/Scripts/Misc/Gifts/Winter2004/SnowPile.cs index c6efeacdc..4f98d1f0a 100644 --- a/Scripts/Misc/Gifts/Winter2004/SnowPile.cs +++ b/Scripts/Misc/Gifts/Winter2004/SnowPile.cs @@ -51,7 +51,7 @@ namespace Server.Items from.SendLocalizedMessage(1010097); // You cannot use this while mounted. } - else if (from.CanBeginAction(typeof(SnowPile))) + else if (from.CanBeginAction()) { from.SendLocalizedMessage(1005575); // You carefully pack the snow into a ball... from.Target = new SnowTarget(from, this); @@ -73,7 +73,7 @@ namespace Server.Items protected override void OnTick() { - m_From.EndAction(typeof(SnowPile)); + m_From.EndAction(); } } @@ -98,13 +98,13 @@ namespace Server.Items { Container pack = targ.Backpack; - if (from.Region.IsPartOf(typeof(SafeZone)) || targ.Region.IsPartOf(typeof(SafeZone))) + if (from.Region.IsPartOf() || targ.Region.IsPartOf()) { from.SendMessage("You may not throw snow here."); } else if (pack?.FindItemByType(new[] { typeof(SnowPile), typeof(PileOfGlacialSnow) }) != null) { - if (from.BeginAction(typeof(SnowPile))) + if (from.BeginAction()) { new InternalTimer(from).Start(); @@ -115,7 +115,7 @@ namespace Server.Items targ.SendLocalizedMessage(1010572); // You have just been hit by a snowball! from.SendLocalizedMessage(1010573); // You throw the snowball and hit the target! - Effects.SendMovingEffect(from, targ, 0x36E4, 7, 0, false, true, 0x480, 0); + Effects.SendMovingEffect(from, targ, 0x36E4, 7, 0, false, true, 0x480); } else { diff --git a/Scripts/Misc/Guild.cs b/Scripts/Misc/Guild.cs index 5ecba0867..336fe334b 100644 --- a/Scripts/Misc/Guild.cs +++ b/Scripts/Misc/Guild.cs @@ -314,28 +314,13 @@ namespace Server.Guilds m_Members[i].GuildMessage(number); } - public void AllianceMessage(int number, string args) - { - AllianceMessage(number, args, 0x3B2); - } - - public void AllianceMessage(int number, string args, int hue) + public void AllianceMessage(int number, string args, int hue = 0x3B2) { for (int i = 0; i < m_Members.Count; ++i) m_Members[i].GuildMessage(number, args, hue); } - public void AllianceMessage(int number, bool append, string affix) - { - AllianceMessage(number, append, affix, "", 0x3B2); - } - - public void AllianceMessage(int number, bool append, string affix, string args) - { - AllianceMessage(number, append, affix, args, 0x3B2); - } - - public void AllianceMessage(int number, bool append, string affix, string args, int hue) + public void AllianceMessage(int number, bool append, string affix, string args = "", int hue = 0x3B2) { for (int i = 0; i < m_Members.Count; ++i) m_Members[i].GuildMessage(number, append, affix, args, hue); @@ -483,9 +468,8 @@ namespace Server.Guilds { if (Kills > w.Kills) return WarStatus.Win; - if (Kills < w.Kills) - return WarStatus.Lose; - return WarStatus.Draw; + + return Kills < w.Kills ? WarStatus.Lose : WarStatus.Draw; } if (MaxKills > 0) @@ -534,8 +518,8 @@ namespace Server.Guilds protected override void OnTick() { - foreach (Guild g in BaseGuild.List.Values) - g.CheckExpiredWars(); + foreach (BaseGuild g in BaseGuild.List.Values) + (g as Guild)?.CheckExpiredWars(); } } @@ -583,7 +567,7 @@ namespace Server.Guilds #endregion } - public Guild(int id) : base(id) //serialization ctor + public Guild(uint id) : base(id) //serialization ctor { } @@ -674,7 +658,6 @@ namespace Server.Guilds RemoveMember(mob); } - public void Disband() { m_Leader = null; @@ -727,7 +710,7 @@ namespace Server.Guilds } else { - Guild g = int.TryParse(arg, out int id) + Guild g = uint.TryParse(arg, out uint id) ? Find(id) as Guild : FindByAbbrev(arg) as Guild ?? FindByName(arg) as Guild; @@ -751,7 +734,7 @@ namespace Server.Guilds { if (!BaseCommand.IsAccessible(from, o)) { - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. return; } @@ -970,12 +953,7 @@ namespace Server.Guilds } } - public static void HandleDeath(Mobile victim) - { - HandleDeath(victim, null); - } - - public static void HandleDeath(Mobile victim, Mobile killer) + public static void HandleDeath(Mobile victim, Mobile killer = null) { if (!NewGuildSystem) return; @@ -1264,10 +1242,7 @@ namespace Server.Guilds Members.Add(m); m.Guild = this; - if (!NewGuildSystem) - m.GuildFealty = m_Leader; - else - m.GuildFealty = null; + m.GuildFealty = !NewGuildSystem ? m_Leader : null; if (m is PlayerMobile mobile) mobile.GuildRank = RankDefinition.Lowest; @@ -1276,12 +1251,7 @@ namespace Server.Guilds } } - public void RemoveMember(Mobile m) - { - RemoveMember(m, 1018028); // You have been dismissed from your guild. - } - - public void RemoveMember(Mobile m, int message) + public void RemoveMember(Mobile m, int message = 1018028) // You have been dismissed from your guild. { if (Members.Contains(m)) { @@ -1599,4 +1569,4 @@ namespace Server.Guilds #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Misc/Keywords.cs b/Scripts/Misc/Keywords.cs index 5f0fc9554..6c4ac05e6 100644 --- a/Scripts/Misc/Keywords.cs +++ b/Scripts/Misc/Keywords.cs @@ -43,7 +43,7 @@ namespace Server.Misc } case 0x0035: // i renounce my young player status* { - if (from is PlayerMobile mobile && mobile.Young && !mobile.HasGump(typeof(RenounceYoungGump))) + if (from is PlayerMobile mobile && mobile.Young && !mobile.HasGump()) mobile.SendGump(new RenounceYoungGump()); break; diff --git a/Scripts/Misc/LightCycle.cs b/Scripts/Misc/LightCycle.cs index 8b815b234..331da6b85 100644 --- a/Scripts/Misc/LightCycle.cs +++ b/Scripts/Misc/LightCycle.cs @@ -67,9 +67,7 @@ namespace Server if (m_LevelOverride > int.MinValue) return m_LevelOverride; - int hours, minutes; - - Clock.GetTime(from.Map, from.X, from.Y, out hours, out minutes); + Clock.GetTime(from.Map, from.X, from.Y, out int hours, out int minutes); /* OSI times: * @@ -130,7 +128,7 @@ namespace Server protected override void OnTick() { - m_Owner.EndAction(typeof(LightCycle)); + m_Owner.EndAction(); m_Owner.LightLevel = 0; BuffInfo.RemoveBuff(m_Owner, BuffIcon.NightSight); } diff --git a/Scripts/Misc/Notoriety.cs b/Scripts/Misc/Notoriety.cs index 634839762..2b76f63ee 100644 --- a/Scripts/Misc/Notoriety.cs +++ b/Scripts/Misc/Notoriety.cs @@ -105,14 +105,9 @@ namespace Server.Misc pmTarg?.DuelContext != null && pmTarg.DuelContext.Started) return false; - if (from.Region.GetRegion(typeof(SafeZone)) is SafeZone sz /*&& sz.IsDisabled()*/) + if (from.Region.IsPartOf() || target.Region.IsPartOf()) return false; - - sz = target.Region.GetRegion(typeof(SafeZone)) as SafeZone; - - if (sz != null /*&& sz.IsDisabled()*/) - return false; - + #endregion Map map = from.Map; @@ -191,12 +186,7 @@ namespace Server.Misc pmTarg?.DuelContext != null && pmTarg.DuelContext.Started) return false; - if (from.Region.GetRegion(typeof(SafeZone)) is SafeZone sz /*&& sz.IsDisabled()*/) - return false; - - sz = target.Region.GetRegion(typeof(SafeZone)) as SafeZone; - - if (sz != null /*&& sz.IsDisabled()*/) + if (from.Region.IsPartOf() || target.Region.IsPartOf()) return false; #endregion @@ -408,7 +398,7 @@ namespace Server.Misc if (bcTarg?.InitialInnocent != true) if (!target.Body.IsHuman && !target.Body.IsGhost && !IsPet(bcTarg) && pmTarg == null || - !Core.ML && !target.CanBeginAction(typeof(PolymorphSpell))) + !Core.ML && !target.CanBeginAction()) return Notoriety.CanBeAttacked; if (CheckAggressor(source.Aggressors, target)) diff --git a/Scripts/Misc/RaceDefinitions.cs b/Scripts/Misc/RaceDefinitions.cs index a686169b6..29f53df3e 100644 --- a/Scripts/Misc/RaceDefinitions.cs +++ b/Scripts/Misc/RaceDefinitions.cs @@ -36,7 +36,7 @@ namespace Server.Misc return true; if (female && itemID == 0x2048 || !female && itemID == 0x2046) - return false; //Buns & Receeding Hair + return false; //Buns & Receding Hair if (itemID >= 0x203B && itemID <= 0x203D) return true; @@ -59,7 +59,7 @@ namespace Server.Misc case 5: return 0x2047; //Afro case 6: return 0x2049; //Pig tails case 7: return 0x204A; //Krisna - default: return female ? 0x2046 : 0x2048; //Buns or Receeding Hair + default: return female ? 0x2046 : 0x2048; //Buns or Receding Hair } } @@ -284,16 +284,12 @@ namespace Server.Misc public override bool ValidateFacialHair(bool female, int itemID) { - if (female) - return false; - return itemID >= 0x42AD && itemID <= 0x42B0; + return !female && itemID >= 0x42AD && itemID <= 0x42B0; } public override int RandomFacialHair(bool female) { - if (female) - return 0; - return Utility.RandomList(0, 0x42AD, 0x42AE, 0x42AF, 0x42B0); + return female ? 0 : Utility.RandomList(0, 0x42AD, 0x42AE, 0x42AF, 0x42B0); } public override int ClipSkinHue(int hue) diff --git a/Scripts/Misc/RegenRates.cs b/Scripts/Misc/RegenRates.cs index 66662164d..1cfa1bce5 100644 --- a/Scripts/Misc/RegenRates.cs +++ b/Scripts/Misc/RegenRates.cs @@ -74,7 +74,7 @@ namespace Server.Misc points += 20; if (CheckAnimal(from, typeof(Dog)) || CheckAnimal(from, typeof(Cat))) - points += from.Skills[SkillName.Ninjitsu].Fixed / 30; + points += from.Skills.Ninjitsu.Fixed / 30; return TimeSpan.FromSeconds(1.0 / (0.1 * (1 + points))); } @@ -86,7 +86,7 @@ namespace Server.Misc CheckBonusSkill(from, from.Stam, from.StamMax, SkillName.Focus); - int points = (int)(from.Skills[SkillName.Focus].Value * 0.1); + int points = (int)(from.Skills.Focus.Value * 0.1); if (from is BaseCreature creature && creature.IsParagon || from is Leviathan) points += 40; @@ -123,13 +123,13 @@ namespace Server.Misc if (Core.AOS) { - double medPoints = from.Int + from.Skills[SkillName.Meditation].Value * 3; + double medPoints = from.Int + from.Skills.Meditation.Value * 3; - medPoints *= from.Skills[SkillName.Meditation].Value < 100.0 ? 0.025 : 0.0275; + medPoints *= from.Skills.Meditation.Value < 100.0 ? 0.025 : 0.0275; CheckBonusSkill(from, from.Mana, from.ManaMax, SkillName.Focus); - double focusPoints = from.Skills[SkillName.Focus].Value * 0.05; + double focusPoints = from.Skills.Focus.Value * 0.05; if (armorPenalty > 0) medPoints = 0; // In AOS, wearing any meditation-blocking armor completely removes meditation bonus @@ -161,7 +161,7 @@ namespace Server.Misc } else { - double medPoints = (from.Int + from.Skills[SkillName.Meditation].Value) * 0.5; + double medPoints = (from.Int + from.Skills.Meditation.Value) * 0.5; if (medPoints <= 0) rate = 7.0; diff --git a/Scripts/Misc/ShardPoller.cs b/Scripts/Misc/ShardPoller.cs index 6bb1ea099..7aa424694 100644 --- a/Scripts/Misc/ShardPoller.cs +++ b/Scripts/Misc/ShardPoller.cs @@ -147,14 +147,13 @@ namespace Server.Misc if (m_ActivePollers.Count == 0) return; - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(EventSink_Login_Callback), e.Mobile); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), EventSink_Login_Callback, e.Mobile); } - private static void EventSink_Login_Callback(object state) + private static void EventSink_Login_Callback(Mobile from) { - Mobile from = (Mobile)state; NetState ns = from.NetState; - + if (ns == null) return; @@ -189,15 +188,6 @@ namespace Server.Misc } } - public void SendQueuedPoll_Callback(object state) - { - object[] states = (object[])state; - Mobile from = (Mobile)states[0]; - Queue queue = (Queue)states[1]; - - from.SendGump(new ShardPollGump(from, this, false, queue)); - } - public override void OnDoubleClick(Mobile from) { if (from.AccessLevel >= AccessLevel.Administrator) @@ -493,13 +483,13 @@ namespace Server.Misc public override void OnResponse(NetState sender, RelayInfo info) { - if (m_Polls != null && m_Polls.Count > 0) + if (m_Polls?.Count > 0) { ShardPoller poller = m_Polls.Dequeue(); if (poller != null) - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(poller.SendQueuedPoll_Callback), - new object[] { m_From, m_Polls }); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), + () => m_From.SendGump(new ShardPollGump(m_From, poller, false, m_Polls))); } if (info.ButtonID == 1) diff --git a/Scripts/Misc/SkillCheck.cs b/Scripts/Misc/SkillCheck.cs index 482750c38..db0db8148 100644 --- a/Scripts/Misc/SkillCheck.cs +++ b/Scripts/Misc/SkillCheck.cs @@ -206,7 +206,7 @@ namespace Server.Misc public static void Gain(Mobile from, Skill skill) { - if (from.Region.IsPartOf(typeof(Jail))) + if (from.Region.IsPartOf()) return; if (from is BaseCreature creature && creature.IsDeadPet) diff --git a/Scripts/Misc/VendorGenerator.cs b/Scripts/Misc/VendorGenerator.cs index b9a826bfe..8bd7af4af 100644 --- a/Scripts/Misc/VendorGenerator.cs +++ b/Scripts/Misc/VendorGenerator.cs @@ -34,8 +34,8 @@ namespace Server new Rectangle2D(new Point2D(0, 0), new Point2D(288 * 8, 200 * 8)) }; - private static Hashtable m_ShopTable; - private static ArrayList m_ShopList; + private static Dictionary m_ShopTable; + private static List m_ShopList; public static void Initialize() { @@ -122,19 +122,19 @@ namespace Server private static void Process(Map map, Rectangle2D[] regions) { - m_ShopTable = new Hashtable(); - m_ShopList = new ArrayList(); + m_ShopTable = new Dictionary(); + m_ShopList = new List(); World.Broadcast(0x35, true, "Generating vendor spawns for {0}, please wait.", map); for (int i = 0; i < regions.Length; ++i) - for (int x = 0; x < map.Width; ++x) - for (int y = 0; y < map.Height; ++y) - CheckPoint(map, regions[i].X + x, regions[i].Y + y); + for (int x = 0; x < map.Width; ++x) + for (int y = 0; y < map.Height; ++y) + CheckPoint(map, regions[i].X + x, regions[i].Y + y); for (int i = 0; i < m_ShopList.Count; ++i) { - ShopInfo si = (ShopInfo)m_ShopList[i]; + ShopInfo si = m_ShopList[i]; int xTotal = 0; int yTotal = 0; @@ -143,7 +143,7 @@ namespace Server for (int j = 0; j < si.m_Floor.Count; ++j) { - Point2D fp = (Point2D)si.m_Floor[j]; + Point2D fp = si.m_Floor[j]; xTotal += fp.X; yTotal += fp.Y; @@ -162,7 +162,7 @@ namespace Server int xAvg = xTotal / si.m_Floor.Count; int yAvg = yTotal / si.m_Floor.Count; - ArrayList names = new ArrayList(); + List names = new List(); ShopFlags flags = si.m_Flags; if ((flags & ShopFlags.Armor) != 0) @@ -209,11 +209,10 @@ namespace Server { Point2D cp = Point2D.Zero; int dist = 100000; - int tz; for (int k = 0; k < si.m_Floor.Count; ++k) { - Point2D fp = (Point2D)si.m_Floor[k]; + Point2D fp = si.m_Floor[k]; int rx = fp.X - xAvg; int ry = fp.Y - yAvg; @@ -222,7 +221,7 @@ namespace Server if (fd > 0 && fd < 5) fd -= Utility.Random(10); - if (fd < dist && GetFloorZ(map, fp.X, fp.Y, out tz)) + if (fd < dist && GetFloorZ(map, fp.X, fp.Y, out _)) { dist = fd; cp = fp; @@ -235,7 +234,7 @@ namespace Server if (!GetFloorZ(map, cp.X, cp.Y, out int z)) continue; - new Spawner(1, 1, 1, 0, 4, (string)names[j]).MoveToWorld(new Point3D(cp.X, cp.Y, z), map); + new Spawner(1, 1, 1, 0, 4, names[j]).MoveToWorld(new Point3D(cp.X, cp.Y, z), map); } } @@ -393,24 +392,22 @@ namespace Server if (flags != ShopFlags.None) { Point2D p = new Point2D(x, y); - ShopInfo si = (ShopInfo)m_ShopTable[p]; + ShopInfo si = m_ShopTable[p]; if (si == null) { - ArrayList floor = new ArrayList(); + List floor = new List(); RecurseFindFloor(map, x, y, floor); if (floor.Count == 0) return; - si = new ShopInfo(); - si.m_Flags = flags; - si.m_Floor = floor; + si = new ShopInfo { m_Flags = flags, m_Floor = floor }; m_ShopList.Add(si); for (int i = 0; i < floor.Count; ++i) - m_ShopTable[(Point2D)floor[i]] = si; + m_ShopTable[floor[i]] = si; } else { @@ -477,7 +474,7 @@ namespace Server return hasSurface; } - private static void RecurseFindFloor(Map map, int x, int y, ArrayList floor) + private static void RecurseFindFloor(Map map, int x, int y, List floor) { Point2D p = new Point2D(x, y); @@ -511,7 +508,7 @@ namespace Server private class ShopInfo { public ShopFlags m_Flags; - public ArrayList m_Floor; + public List m_Floor; } } -} \ No newline at end of file +} diff --git a/Scripts/Misc/uoamVendors.cs b/Scripts/Misc/uoamVendors.cs index ab6a64645..998d96ee0 100644 --- a/Scripts/Misc/uoamVendors.cs +++ b/Scripts/Misc/uoamVendors.cs @@ -280,15 +280,15 @@ namespace Server { int z = map.GetAverageZ(x, y); - if (map.CanFit(x, y, z, 16, false, false, true)) + if (map.CanFit(x, y, z, 16, false, false)) return z; for (int i = 1; i <= 20; ++i) { - if (map.CanFit(x, y, z + i, 16, false, false, true)) + if (map.CanFit(x, y, z + i, 16, false, false)) return z + i; - if (map.CanFit(x, y, z - i, 16, false, false, true)) + if (map.CanFit(x, y, z - i, 16, false, false)) return z - i; } diff --git a/Scripts/Mobiles/AI/AnimalAI.cs b/Scripts/Mobiles/AI/AnimalAI.cs index b621aef16..a1e69315c 100644 --- a/Scripts/Mobiles/AI/AnimalAI.cs +++ b/Scripts/Mobiles/AI/AnimalAI.cs @@ -1,6 +1,6 @@ // Ideas // When you run on animals the panic -// When if ( distance < 8 && Utility.RandomDouble() * Math.Sqrt( (8 - distance) / 6 ) >= incoming.Skills[SkillName.AnimalTaming].Value ) +// When if ( distance < 8 && Utility.RandomDouble() * Math.Sqrt( (8 - distance) / 6 ) >= incoming.Skills.AnimalTaming.Value ) // More your close, the more it can panic /* * AnimalHunterAI, AnimalHidingAI, AnimalDomesticAI... diff --git a/Scripts/Mobiles/AI/BaseAI.cs b/Scripts/Mobiles/AI/BaseAI.cs index 95c353ef6..6d3ba83f5 100644 --- a/Scripts/Mobiles/AI/BaseAI.cs +++ b/Scripts/Mobiles/AI/BaseAI.cs @@ -140,7 +140,7 @@ namespace Server.Mobiles public long NextMove{ get; set; } - public virtual bool CanDetectHidden => m_Mobile.Skills[SkillName.DetectHidden].Value > 0; + public virtual bool CanDetectHidden => m_Mobile.Skills.DetectHidden.Value > 0; public virtual bool WasNamed(string speech) { @@ -1171,9 +1171,9 @@ namespace Server.Mobiles if (qs is DarkTidesQuest) { - QuestObjective obj = qs.FindObjective(typeof(FetchAbraxusScrollObjective)); + QuestObjective obj = qs.FindObjective(); - if (obj != null && !obj.Completed) + if (obj?.Completed == false) { m_Mobile.AddToBackpack(new ScrollOfAbraxus()); obj.Complete(); @@ -2380,7 +2380,7 @@ namespace Server.Mobiles m_Mobile.DebugSay("Checking for hidden players"); - double srcSkill = m_Mobile.Skills[SkillName.DetectHidden].Value; + double srcSkill = m_Mobile.Skills.DetectHidden.Value; if (srcSkill <= 0) return; @@ -2392,8 +2392,8 @@ namespace Server.Mobiles { m_Mobile.DebugSay("Trying to detect {0}", trg.Name); - double trgHiding = trg.Skills[SkillName.Hiding].Value / 2.9; - double trgStealth = trg.Skills[SkillName.Stealth].Value / 1.8; + double trgHiding = trg.Skills.Hiding.Value / 2.9; + double trgStealth = trg.Skills.Stealth.Value / 1.8; double chance = srcSkill / 1.2 - Math.Min(trgHiding, trgStealth); diff --git a/Scripts/Mobiles/AI/MageAI.cs b/Scripts/Mobiles/AI/MageAI.cs index c0627c6d4..cec77c5c8 100644 --- a/Scripts/Mobiles/AI/MageAI.cs +++ b/Scripts/Mobiles/AI/MageAI.cs @@ -64,7 +64,7 @@ namespace Server.Mobiles public virtual bool SmartAI => m_Mobile is BaseVendor || m_Mobile is BaseEscortable || m_Mobile is Changeling; - public virtual bool IsNecromancer => Core.AOS && m_Mobile.Skills[SkillName.Necromancy].Value > 50; + public virtual bool IsNecromancer => Core.AOS && m_Mobile.Skills.Necromancy.Value > 50; public override bool Think() { @@ -245,9 +245,9 @@ namespace Server.Mobiles public virtual bool UseNecromancy() { if (IsNecromancer) - return Utility.Random(m_Mobile.Skills[SkillName.Magery].BaseFixedPoint + - m_Mobile.Skills[SkillName.Necromancy].BaseFixedPoint) >= - m_Mobile.Skills[SkillName.Magery].BaseFixedPoint; + return Utility.Random(m_Mobile.Skills.Magery.BaseFixedPoint + + m_Mobile.Skills.Necromancy.BaseFixedPoint) >= + m_Mobile.Skills.Magery.BaseFixedPoint; return false; } @@ -259,7 +259,7 @@ namespace Server.Mobiles public virtual Spell GetRandomDamageSpellNecro() { - int bound = m_Mobile.Skills[SkillName.Necromancy].Value >= 100 ? 5 : 3; + int bound = m_Mobile.Skills.Necromancy.Value >= 100 ? 5 : 3; switch (Utility.Random(bound)) { @@ -283,7 +283,7 @@ namespace Server.Mobiles public virtual Spell GetRandomDamageSpellMage() { - int maxCircle = (int)((m_Mobile.Skills[SkillName.Magery].Value + 20.0) / (100.0 / 7.0)); + int maxCircle = (int)((m_Mobile.Skills.Magery.Value + 20.0) / (100.0 / 7.0)); if (maxCircle < 1) maxCircle = 1; @@ -334,7 +334,7 @@ namespace Server.Mobiles public virtual Spell GetRandomCurseSpellMage() { - if (m_Mobile.Skills[SkillName.Magery].Value >= 40.0 && Utility.Random(4) == 0) + if (m_Mobile.Skills.Magery.Value >= 40.0 && Utility.Random(4) == 0) return new CurseSpell(m_Mobile, null); switch (Utility.Random(3)) @@ -347,7 +347,7 @@ namespace Server.Mobiles public virtual Spell GetRandomManaDrainSpell() { - if (m_Mobile.Skills[SkillName.Magery].Value >= 80.0 && Utility.RandomBool()) + if (m_Mobile.Skills.Magery.Value >= 80.0 && Utility.RandomBool()) return new ManaVampireSpell(m_Mobile, null); return new ManaDrainSpell(m_Mobile, null); @@ -392,7 +392,7 @@ namespace Server.Mobiles if (IsNecromancer) { double psDamage = - (m_Mobile.Skills[SkillName.SpiritSpeak].Value - c.Skills[SkillName.MagicResist].Value) / 10 + + (m_Mobile.Skills.SpiritSpeak.Value - c.Skills.MagicResist.Value) / 10 + (c.Player ? 18 : 30); if (psDamage > c.Hits) @@ -429,7 +429,7 @@ namespace Server.Mobiles } case 5: // Paralyze them { - if (c.Paralyzed || m_Mobile.Skills[SkillName.Magery].Value <= 50.0) + if (c.Paralyzed || m_Mobile.Skills.Magery.Value <= 50.0) goto default; m_Mobile.DebugSay("Attempting to paralyze"); @@ -641,8 +641,8 @@ namespace Server.Mobiles } } - if (!Core.AOS && SmartAI && !m_Mobile.StunReady && m_Mobile.Skills[SkillName.Wrestling].Value >= 80.0 && - m_Mobile.Skills[SkillName.Anatomy].Value >= 80.0) + if (!Core.AOS && SmartAI && !m_Mobile.StunReady && m_Mobile.Skills.Wrestling.Value >= 80.0 && + m_Mobile.Skills.Anatomy.Value >= 80.0) EventSink.InvokeStunRequest(new StunRequestEventArgs(m_Mobile)); if (!m_Mobile.InRange(c, m_Mobile.RangePerception)) diff --git a/Scripts/Mobiles/AI/ThiefAI.cs b/Scripts/Mobiles/AI/ThiefAI.cs index 7e6c6ca5c..e24ce828b 100644 --- a/Scripts/Mobiles/AI/ThiefAI.cs +++ b/Scripts/Mobiles/AI/ThiefAI.cs @@ -63,8 +63,8 @@ namespace Server.Mobiles m_toDisarm = combatant.FindItemOnLayer(Layer.TwoHanded); } - if (!Core.AOS && !m_Mobile.DisarmReady && m_Mobile.Skills[SkillName.Wrestling].Value >= 80.0 && - m_Mobile.Skills[SkillName.ArmsLore].Value >= 80.0 && m_toDisarm != null) + if (!Core.AOS && !m_Mobile.DisarmReady && m_Mobile.Skills.Wrestling.Value >= 80.0 && + m_Mobile.Skills.ArmsLore.Value >= 80.0 && m_toDisarm != null) EventSink.InvokeDisarmRequest(new DisarmRequestEventArgs(m_Mobile)); if (m_toDisarm != null && m_toDisarm.IsChildOf(combatant.Backpack) && diff --git a/Scripts/Mobiles/Animals/Mounts/Ethereals.cs b/Scripts/Mobiles/Animals/Mounts/Ethereals.cs index 507b55e40..4c1e6edd4 100644 --- a/Scripts/Mobiles/Animals/Mounts/Ethereals.cs +++ b/Scripts/Mobiles/Animals/Mounts/Ethereals.cs @@ -377,7 +377,7 @@ namespace Server.Mobiles public void Stop() { m_Stop = true; - Disturb(DisturbType.Hurt, false, false); + Disturb(DisturbType.Hurt, false); } public override bool CheckDisturb(DisturbType type, bool checkFirst, bool resistable) diff --git a/Scripts/Mobiles/Animals/Mounts/FrenziedOstard.cs b/Scripts/Mobiles/Animals/Mounts/FrenziedOstard.cs index 51384bc67..feeab5f15 100644 --- a/Scripts/Mobiles/Animals/Mounts/FrenziedOstard.cs +++ b/Scripts/Mobiles/Animals/Mounts/FrenziedOstard.cs @@ -10,7 +10,7 @@ namespace Server.Mobiles [Constructible] public FrenziedOstard(string name) : base(name, 0xDA, 0x3EA4, AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) { - Hue = Utility.RandomHairHue() | 0x8000; + Hue = Race.Human.RandomHairHue() | 0x8000; BaseSoundID = 0x275; diff --git a/Scripts/Mobiles/Animals/Mounts/Hiryu.cs b/Scripts/Mobiles/Animals/Mounts/Hiryu.cs index 53b663966..fd705bc4e 100644 --- a/Scripts/Mobiles/Animals/Mounts/Hiryu.cs +++ b/Scripts/Mobiles/Animals/Mounts/Hiryu.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Items; @@ -7,7 +8,7 @@ namespace Server.Mobiles { public class Hiryu : BaseMount { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public Hiryu() @@ -175,7 +176,7 @@ namespace Server.Mobiles * Effect: Type: "3" - From: "0x57D4F5B" (player) - To: "0x0" - ItemId: "0x37B9" - ItemIdName: "glow" - FromLocation: "(1149 808, 32)" - ToLocation: "(1149 808, 32)" - Speed: "10" - Duration: "5" - FixedDirection: "True" - Explode: "False" */ - ExpireTimer timer = (ExpireTimer)m_Table[defender]; + ExpireTimer timer = m_Table[defender]; if (timer != null) { @@ -257,4 +258,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs b/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs index 32b83fdd4..2e3e0de8b 100644 --- a/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs +++ b/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Items; @@ -7,7 +8,7 @@ namespace Server.Mobiles { public class LesserHiryu : BaseMount { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public LesserHiryu() @@ -102,7 +103,7 @@ namespace Server.Mobiles public override bool OverrideBondingReqs() { - if (ControlMaster.Skills[SkillName.Bushido].Base >= 90.0) + if (ControlMaster.Skills.Bushido.Base >= 90.0) return true; return false; } @@ -169,7 +170,7 @@ namespace Server.Mobiles * Effect: Type: "3" - From: "0x57D4F5B" (player) - To: "0x0" - ItemId: "0x37B9" - ItemIdName: "glow" - FromLocation: "(1149 808, 32)" - ToLocation: "(1149 808, 32)" - Speed: "10" - Duration: "5" - FixedDirection: "True" - Explode: "False" */ - ExpireTimer timer = (ExpireTimer)m_Table[defender]; + ExpireTimer timer = m_Table[defender]; if (timer != null) { @@ -251,4 +252,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Animals/Mounts/SeaHorse.cs b/Scripts/Mobiles/Animals/Mounts/SeaHorse.cs index 5ce90c09b..cbc0d2809 100644 --- a/Scripts/Mobiles/Animals/Mounts/SeaHorse.cs +++ b/Scripts/Mobiles/Animals/Mounts/SeaHorse.cs @@ -11,9 +11,9 @@ namespace Server.Mobiles public SeaHorse(string name) : base(name, 0x90, 0x3EB3, AIType.AI_Animal, FightMode.Aggressor, 10, 1, 0.2, 0.4) { InitStats(Utility.Random(50, 30), Utility.Random(50, 30), 10); - Skills[SkillName.MagicResist].Base = 25.0 + Utility.RandomDouble() * 5.0; - Skills[SkillName.Wrestling].Base = 35.0 + Utility.RandomDouble() * 10.0; - Skills[SkillName.Tactics].Base = 30.0 + Utility.RandomDouble() * 15.0; + Skills.MagicResist.Base = 25.0 + Utility.RandomDouble() * 5.0; + Skills.Wrestling.Base = 35.0 + Utility.RandomDouble() * 10.0; + Skills.Tactics.Base = 30.0 + Utility.RandomDouble() * 15.0; } public SeaHorse(Serial serial) : base(serial) diff --git a/Scripts/Mobiles/Animals/Mounts/SilverSteed.cs b/Scripts/Mobiles/Animals/Mounts/SilverSteed.cs index fac33d9c6..a4b536a8c 100644 --- a/Scripts/Mobiles/Animals/Mounts/SilverSteed.cs +++ b/Scripts/Mobiles/Animals/Mounts/SilverSteed.cs @@ -11,9 +11,9 @@ namespace Server.Mobiles public SilverSteed(string name) : base(name, 0x75, 0x3EA8, AIType.AI_Animal, FightMode.Aggressor, 10, 1, 0.2, 0.4) { InitStats(Utility.Random(50, 30), Utility.Random(50, 30), 10); - Skills[SkillName.MagicResist].Base = 25.0 + Utility.RandomDouble() * 5.0; - Skills[SkillName.Wrestling].Base = 35.0 + Utility.RandomDouble() * 10.0; - Skills[SkillName.Tactics].Base = 30.0 + Utility.RandomDouble() * 15.0; + Skills.MagicResist.Base = 25.0 + Utility.RandomDouble() * 5.0; + Skills.Wrestling.Base = 35.0 + Utility.RandomDouble() * 10.0; + Skills.Tactics.Base = 30.0 + Utility.RandomDouble() * 15.0; ControlSlots = 1; Tamable = true; diff --git a/Scripts/Mobiles/Animals/Mounts/Unicorn.cs b/Scripts/Mobiles/Animals/Mounts/Unicorn.cs index bfbe7d5f7..b4ec80f75 100644 --- a/Scripts/Mobiles/Animals/Mounts/Unicorn.cs +++ b/Scripts/Mobiles/Animals/Mounts/Unicorn.cs @@ -84,7 +84,7 @@ namespace Server.Mobiles if (p != null) { - int chanceToCure = 10000 + (int)(Skills[SkillName.Magery].Value * 75) - + int chanceToCure = 10000 + (int)(Skills.Magery.Value * 75) - (p.Level + 1) * (Core.AOS ? p.Level < 4 ? 3300 : 3100 : 1750); chanceToCure /= 100; diff --git a/Scripts/Mobiles/Animals/Slimes/Jwilson.cs b/Scripts/Mobiles/Animals/Slimes/Jwilson.cs index 3b3242c26..536f1c208 100644 --- a/Scripts/Mobiles/Animals/Slimes/Jwilson.cs +++ b/Scripts/Mobiles/Animals/Slimes/Jwilson.cs @@ -11,10 +11,10 @@ namespace Server.Mobiles InitStats(Utility.Random(22, 13), Utility.Random(16, 6), Utility.Random(16, 5)); - Skills[SkillName.Wrestling].Base = Utility.Random(24, 17); - Skills[SkillName.Tactics].Base = Utility.Random(18, 14); - Skills[SkillName.MagicResist].Base = Utility.Random(15, 6); - Skills[SkillName.Poisoning].Base = Utility.Random(31, 20); + Skills.Wrestling.Base = Utility.Random(24, 17); + Skills.Tactics.Base = Utility.Random(18, 14); + Skills.MagicResist.Base = Utility.Random(15, 6); + Skills.Poisoning.Base = Utility.Random(31, 20); Fame = Utility.Random(0, 1249); Karma = Utility.Random(0, -624); diff --git a/Scripts/Mobiles/Animals/Town Critters/(UO 3D Only) Parrot.cs b/Scripts/Mobiles/Animals/Town Critters/(UO 3D Only) Parrot.cs index b8f356b91..0af534bf6 100644 --- a/Scripts/Mobiles/Animals/Town Critters/(UO 3D Only) Parrot.cs +++ b/Scripts/Mobiles/Animals/Town Critters/(UO 3D Only) Parrot.cs @@ -10,9 +10,9 @@ namespace Server.Mobiles InitStats(10, Utility.Random(25, 16), 10); - Skills[SkillName.Wrestling].Base = 6; - Skills[SkillName.Tactics].Base = 6; - Skills[SkillName.MagicResist].Base = 5; + Skills.Wrestling.Base = 6; + Skills.Tactics.Base = 6; + Skills.MagicResist.Base = 5; Fame = Utility.Random(0, 1249); Karma = Utility.Random(0, -624); diff --git a/Scripts/Mobiles/BaseCreature.cs b/Scripts/Mobiles/BaseCreature.cs index 83fd4a36b..1a0d4675e 100644 --- a/Scripts/Mobiles/BaseCreature.cs +++ b/Scripts/Mobiles/BaseCreature.cs @@ -131,7 +131,8 @@ namespace Server.Mobiles public int CompareTo(object obj) { - DamageStore ds = (DamageStore)obj; + if (!(obj is DamageStore ds)) + return -1; return ds.m_Damage - m_Damage; } @@ -158,7 +159,7 @@ namespace Server.Mobiles { FriendlyNameAttribute friendly = objs[0] as FriendlyNameAttribute; - return friendly.FriendlyName; + return friendly?.FriendlyName ?? ""; } } @@ -292,13 +293,7 @@ namespace Server.Mobiles return base.Name; } - set - { - if (value == DefaultName) - base.Name = null; - else - base.Name = value; - } + set { base.Name = value == DefaultName ? null : value; } } public virtual InhumanSpeech SpeechType => null; @@ -420,20 +415,7 @@ namespace Server.Mobiles } } - public virtual bool IsNecroFamiliar - { - get - { - if (!Summoned) - return false; - - if (m_ControlMaster != null && SummonFamiliarSpell.Table.Contains(m_ControlMaster)) - return SummonFamiliarSpell.Table[m_ControlMaster] == this; - - return false; - } - } - + public virtual bool IsNecroFamiliar => Summoned && m_ControlMaster != null && SummonFamiliarSpell.Table[m_ControlMaster] == this; public virtual bool DeleteCorpseOnDeath => !Core.AOS && m_bSummoned; [CommandProperty(AccessLevel.GameMaster)] @@ -578,7 +560,8 @@ namespace Server.Mobiles { m_CurrentAI = value; - if (m_CurrentAI == AIType.AI_Use_Default) m_CurrentAI = m_DefaultAI; + if (m_CurrentAI == AIType.AI_Use_Default) + m_CurrentAI = m_DefaultAI; ChangeAIType(m_CurrentAI); } @@ -786,7 +769,6 @@ namespace Server.Mobiles public virtual bool CanDrop => IsBonded; - public virtual double TreasureMapChance => TreasureMap.LootChance; public virtual int TreasureMapLevel => -1; public virtual bool IgnoreYoungProtection => false; @@ -843,9 +825,7 @@ namespace Server.Mobiles public virtual bool IsEnemy(Mobile m) { - OppositionGroup g = OppositionGroup; - - if (g != null && g.IsEnemy(this, m)) + if (OppositionGroup?.IsEnemy(this, m) == true) return true; if (m is BaseGuard) @@ -879,10 +859,7 @@ namespace Server.Mobiles { if (IsParagon && !GivesMLMinorArtifact) { - if (suffix.Length == 0) - suffix = "(Paragon)"; - else - suffix = string.Concat(suffix, " (Paragon)"); + suffix = suffix.Length == 0 ? "(Paragon)" : $"{suffix} (Paragon)"; } return base.ApplyNameSuffix(suffix); @@ -923,9 +900,9 @@ namespace Server.Mobiles dMinTameSkill = -24.9; int taming = - (int)((useBaseSkill ? m.Skills[SkillName.AnimalTaming].Base : m.Skills[SkillName.AnimalTaming].Value) * 10); + (int)((useBaseSkill ? m.Skills.AnimalTaming.Base : m.Skills.AnimalTaming.Value) * 10); int lore = - (int)((useBaseSkill ? m.Skills[SkillName.AnimalLore].Base : m.Skills[SkillName.AnimalLore].Value) * 10); + (int)((useBaseSkill ? m.Skills.AnimalLore.Base : m.Skills.AnimalLore.Value) * 10); int bonus = 0, chance = 700; if (Core.ML) @@ -989,10 +966,9 @@ namespace Server.Mobiles base.Damage(amount, from); - if (SubdueBeforeTame && !Controlled) - if (oldHits > HitsMax / 10 && Hits <= HitsMax / 10) - PublicOverheadMessage(MessageType.Regular, 0x3B2, false, - "* The creature has been beaten into subjugation! *"); + if (SubdueBeforeTame && !Controlled && oldHits > HitsMax / 10 && Hits <= HitsMax / 10) + PublicOverheadMessage(MessageType.Regular, 0x3B2, false, + "* The creature has been beaten into subjugation! *"); } public override void SetLocation(Point3D newLocation, bool isTeleport) @@ -1620,7 +1596,7 @@ namespace Server.Mobiles public virtual bool IsHumanInTown() { - return Body.IsHuman && Region.IsPartOf(typeof(GuardedRegion)); + return Body.IsHuman && Region.IsPartOf(); } public virtual bool CheckGold(Mobile from, Item dropped) @@ -1647,10 +1623,7 @@ namespace Server.Mobiles SpeechHue = 0x23F; SayTo(from, "Thou art giving me gold?"); - if (dropped.Amount >= 400) - SayTo(from, "'Tis a noble gift."); - else - SayTo(from, "Money is always welcome."); + SayTo(from, dropped.Amount >= 400 ? "'Tis a noble gift." : "Money is always welcome."); SpeechHue = 0x3B2; SayTo(from, 501548); // I thank thee. @@ -1733,11 +1706,6 @@ namespace Server.Mobiles } } - public void ChangeAIToDefault() - { - ChangeAIType(m_DefaultAI); - } - public virtual void OnTeamChange() { } @@ -1806,17 +1774,14 @@ namespace Server.Mobiles public virtual void OnGaveMeleeAttack(Mobile defender) { - Poison p = HitPoison; - - if (m_Paragon) - p = PoisonImpl.IncreaseLevel(p); + Poison p = m_Paragon ? PoisonImpl.IncreaseLevel(HitPoison) : HitPoison; if (p != null && HitPoisonChance >= Utility.RandomDouble()) { defender.ApplyPoison(this, p); if (Controlled) - CheckSkill(SkillName.Poisoning, 0, Skills[SkillName.Poisoning].Cap); + CheckSkill(SkillName.Poisoning, 0, Skills.Poisoning.Cap); } if (AutoDispel && defender is BaseCreature creature && creature.IsDispellable && @@ -1865,7 +1830,7 @@ namespace Server.Mobiles /* * This function can be overridden.. so a "Strongest" mobile, can have a different definition depending * on who check for value - * -Could add a FightMode.Prefered + * -Could add a FightMode.Preferred * */ @@ -1875,7 +1840,7 @@ namespace Server.Mobiles switch (acqType) { case FightMode.Strongest: - return m.Skills[SkillName.Tactics].Value + m.Str; //returns strongest mobile + return m.Skills.Tactics.Value + m.Str; //returns strongest mobile case FightMode.Weakest: return -m.Hits; // returns weakest mobile @@ -1983,10 +1948,10 @@ namespace Server.Mobiles #region Dueling - if (Region.IsPartOf(typeof(SafeZone)) && m is PlayerMobile pm) - if (pm.DuelContext == null || pm.DuelPlayer == null || !pm.DuelContext.Started || pm.DuelContext.Finished || - pm.DuelPlayer.Eliminated) - return true; + if (Region.IsPartOf() && m is PlayerMobile pm && + (pm.DuelContext == null || pm.DuelPlayer == null || !pm.DuelContext.Started || pm.DuelContext.Finished || + pm.DuelPlayer.Eliminated)) + return true; #endregion @@ -2121,7 +2086,7 @@ namespace Server.Mobiles public void ReleaseGuardLock() { - EndAction(typeof(GuardedRegion)); + EndAction(); } public virtual bool CheckIdle() @@ -2277,17 +2242,18 @@ namespace Server.Mobiles !m.InRange(Location, 12) || !m.Alive) return; - if (Region.GetRegion(typeof(GuardedRegion)) is GuardedRegion guardedRegion) - if (!guardedRegion.IsDisabled() && guardedRegion.IsGuardCandidate(m) && BeginAction(typeof(GuardedRegion))) - { - Say(1013037 + Utility.Random(16)); - guardedRegion.CallGuards(Location); + GuardedRegion guardedRegion = Region.GetRegion(); - Timer.DelayCall(TimeSpan.FromSeconds(5.0), ReleaseGuardLock); + if (guardedRegion?.IsDisabled() == false && guardedRegion.IsGuardCandidate(m) && BeginAction()) + { + Say(1013037 + Utility.Random(16)); + guardedRegion.CallGuards(Location); - m_NoDupeGuards = m; - Timer.DelayCall(TimeSpan.Zero, ReleaseGuardDupeLock); - } + Timer.DelayCall(TimeSpan.FromSeconds(5.0), ReleaseGuardLock); + + m_NoDupeGuards = m; + Timer.DelayCall(TimeSpan.Zero, ReleaseGuardDupeLock); + } } public void AddSpellAttack(Type type) @@ -2850,7 +2816,7 @@ namespace Server.Mobiles public override bool CanBeRenamedBy(Mobile from) { - return Controlled && from == ControlMaster && !from.Region.IsPartOf(typeof(Jail)) || + return Controlled && from == ControlMaster && !from.Region.IsPartOf() || base.CanBeRenamedBy(from); } @@ -2909,12 +2875,11 @@ namespace Server.Mobiles { base.OnRegionChange(Old, New); - if (Controlled) - if (Spawner is SpawnEntry se && !se.UnlinkOnTaming && (New == null || !New.AcceptsSpawnsFrom(se.Region))) - { - Spawner.Remove(this); - Spawner = null; - } + if (Controlled && Spawner is SpawnEntry se && !se.UnlinkOnTaming && (New == null || !New.AcceptsSpawnsFrom(se.Region))) + { + Spawner.Remove(this); + Spawner = null; + } } public static bool Summon(BaseCreature creature, Mobile caster, Point3D p, int sound, TimeSpan duration) @@ -3334,7 +3299,7 @@ namespace Server.Mobiles if (!(SummonFamiliarSpell.Table[from] is DeathAdder da) || da.Deleted) return; - if (!(targeted is Mobile targ) || !from.CanBeHarmful(targ, false)) + if (!(targeted is Mobile targ && from.CanBeHarmful(targ, false))) return; from.RevealingAction(); @@ -3479,11 +3444,7 @@ namespace Server.Mobiles private bool m_IsBonded; [CommandProperty(AccessLevel.GameMaster)] - public Spawner MySpawner - { - get => Spawner as Spawner; - set { } - } + public Spawner MySpawner => Spawner as Spawner; [CommandProperty(AccessLevel.GameMaster)] public Mobile LastOwner @@ -3716,7 +3677,7 @@ namespace Server.Mobiles Direction = GetDirectionTo(target); - Timer.DelayCall(TimeSpan.FromSeconds(BreathEffectDelay), new TimerStateCallback(BreathEffect_Callback), target); + Timer.DelayCall(TimeSpan.FromSeconds(BreathEffectDelay), BreathEffect_Callback, target); } public virtual void BreathStallMovement() @@ -3735,17 +3696,15 @@ namespace Server.Mobiles Animate(BreathAngerAnimation, 5, 1, true, false, 0); } - public virtual void BreathEffect_Callback(object state) + public virtual void BreathEffect_Callback(Mobile target) { - Mobile target = (Mobile)state; - if (!target.Alive || !CanBeHarmful(target)) return; BreathPlayEffectSound(); BreathPlayEffect(target); - Timer.DelayCall(TimeSpan.FromSeconds(BreathDamageDelay), new TimerStateCallback(BreathDamage_Callback), target); + Timer.DelayCall(TimeSpan.FromSeconds(BreathDamageDelay), BreathDamage_Callback, target); } public virtual void BreathPlayEffectSound() @@ -3760,13 +3719,11 @@ namespace Server.Mobiles BreathEffectExplodes, BreathEffectHue, BreathEffectRenderMode); } - public virtual void BreathDamage_Callback(object state) + public virtual void BreathDamage_Callback(Mobile target) { - if (state is BaseCreature creature && creature.BreathImmune) + if (target is BaseCreature creature && creature.BreathImmune) return; - Mobile target = (Mobile)state; - if (CanBeHarmful(target)) { DoHarmful(target); @@ -3829,41 +3786,30 @@ namespace Server.Mobiles #region Spill Acid - public void SpillAcid(int Amount) + public void SpillAcid(int amount) { - SpillAcid(null, Amount); + SpillAcid(null, amount); } - public void SpillAcid(Mobile target, int Amount) + public void SpillAcid(Mobile target, int amount) { if (target != null && target.Map == null || Map == null) return; - for (int i = 0; i < Amount; ++i) + for (int i = 0; i < amount; ++i) { - Point3D loc = Location; + Point3D loc; Map map = Map; - Item acid = NewHarmfulItem(); - if (target?.Map != null && Amount == 1) + if (target != null && amount == 1) { loc = target.Location; map = target.Map; } else - { - bool validLocation = false; - for (int j = 0; !validLocation && j < 10; ++j) - { - loc = new Point3D( - loc.X + (Utility.Random(0, 3) - 2), - loc.Y + (Utility.Random(0, 3) - 2), - loc.Z); - loc.Z = map.GetAverageZ(loc.X, loc.Y); - validLocation = map.CanFit(loc, 16, false, false); - } - } + loc = map.GetRandomNearbyLocation(Location); + Item acid = NewHarmfulItem(); acid.MoveToWorld(loc, map); } } @@ -4152,9 +4098,9 @@ namespace Server.Mobiles if (master != null && master == from) //So friends can't start the bonding process { - if (MinTameSkill <= 29.1 || master.Skills[SkillName.AnimalTaming].Base >= MinTameSkill || + if (MinTameSkill <= 29.1 || master.Skills.AnimalTaming.Base >= MinTameSkill || OverrideBondingReqs() || - Core.ML && master.Skills[SkillName.AnimalTaming].Value >= MinTameSkill) + Core.ML && master.Skills.AnimalTaming.Value >= MinTameSkill) { if (BondingBegin == DateTime.MinValue) { @@ -4239,11 +4185,11 @@ namespace Server.Mobiles if (!CanTeach) return false; - if (skill == SkillName.Stealth && from.Skills[SkillName.Hiding].Base < Stealth.HidingRequirement) + if (skill == SkillName.Stealth && from.Skills.Hiding.Base < Stealth.HidingRequirement) return false; - if (skill == SkillName.RemoveTrap && (from.Skills[SkillName.Lockpicking].Base < 50.0 || - from.Skills[SkillName.DetectHidden].Base < 50.0)) + if (skill == SkillName.RemoveTrap && (from.Skills.Lockpicking.Base < 50.0 || + from.Skills.DetectHidden.Base < 50.0)) return false; if (!Core.AOS && (skill == SkillName.Focus || skill == SkillName.Chivalry || skill == SkillName.Necromancy)) @@ -5150,13 +5096,7 @@ namespace Server.Mobiles double seconds = (onSelf ? HealDelay : HealOwnerDelay) + (patient.Alive ? 0.0 : 5.0); - m_HealTimer = Timer.DelayCall(TimeSpan.FromSeconds(seconds), new TimerStateCallback(Heal_Callback), patient); - } - - private void Heal_Callback(object state) - { - if (state is Mobile mobile) - Heal(mobile); + m_HealTimer = Timer.DelayCall(TimeSpan.FromSeconds(seconds), Heal, patient); } public virtual void Heal(Mobile patient) @@ -5380,7 +5320,7 @@ namespace Server.Mobiles } // added lines to check if a wild creature in a house region has to be removed or not - if (!c.Controlled && !c.IsStabled && (c.Region.IsPartOf(typeof(HouseRegion)) && c.CanBeDamaged() || + if (!c.Controlled && !c.IsStabled && (c.Region.IsPartOf() && c.CanBeDamaged() || c.RemoveIfUntamed && c.Spawner == null)) { c.RemoveStep++; @@ -5415,4 +5355,4 @@ namespace Server.Mobiles c.Delete(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Familiars/HordeMinion.cs b/Scripts/Mobiles/Familiars/HordeMinion.cs index d450b9c26..a1d05a894 100644 --- a/Scripts/Mobiles/Familiars/HordeMinion.cs +++ b/Scripts/Mobiles/Familiars/HordeMinion.cs @@ -73,7 +73,7 @@ namespace Server.Mobiles if (pack == null) return; - ArrayList list = new ArrayList(); + List list = new List(); foreach (Item item in GetItemsInRange(2)) if (item.Movable && item.Stackable) @@ -83,17 +83,14 @@ namespace Server.Mobiles for (int i = 0; i < list.Count; ++i) { - Item item = (Item)list[i]; + Item item = list[i]; if (!pack.CheckHold(this, item, false, true)) return; - bool rejected; - LRReason reject; - NextActionTime = Core.TickCount; - Lift(item, item.Amount, out rejected, out reject); + Lift(item, item.Amount, out bool rejected, out LRReason _); if (rejected) continue; @@ -105,7 +102,7 @@ namespace Server.Mobiles } } - private void ConfirmRelease_Callback(Mobile from, bool okay, object state) + private void ConfirmRelease_Callback(Mobile from, bool okay) { if (okay) EndRelease(from); @@ -113,10 +110,8 @@ namespace Server.Mobiles public override void BeginRelease(Mobile from) { - Container pack = Backpack; - - if (pack != null && pack.Items.Count > 0) - from.SendGump(new WarningGump(1060635, 30720, 1061672, 32512, 420, 280, ConfirmRelease_Callback, null)); + if (Backpack?.Items.Count > 0) + from.SendGump(new WarningGump(1060635, 30720, 1061672, 32512, 420, 280, okay => ConfirmRelease_Callback(from, okay))); else EndRelease(from); } diff --git a/Scripts/Mobiles/Familiars/ShadowWisp.cs b/Scripts/Mobiles/Familiars/ShadowWisp.cs index 4c3dffe56..b24973421 100644 --- a/Scripts/Mobiles/Familiars/ShadowWisp.cs +++ b/Scripts/Mobiles/Familiars/ShadowWisp.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Mobiles { @@ -69,7 +70,7 @@ namespace Server.Mobiles if (caster == null) return; - ArrayList list = new ArrayList(); + List list = new List(); foreach (Mobile m in GetMobilesInRange(5)) if (m.Player && m.Alive && !m.IsDeadBondedPet && m.Karma <= 0 && m.AccessLevel < AccessLevel.Counselor) @@ -77,7 +78,7 @@ namespace Server.Mobiles for (int i = 0; i < list.Count; ++i) { - Mobile m = (Mobile)list[i]; + Mobile m = list[i]; bool friendly = true; for (int j = 0; friendly && j < caster.Aggressors.Count; ++j) diff --git a/Scripts/Mobiles/Guards/ArcherGuard.cs b/Scripts/Mobiles/Guards/ArcherGuard.cs index e6b48682a..7347a9585 100644 --- a/Scripts/Mobiles/Guards/ArcherGuard.cs +++ b/Scripts/Mobiles/Guards/ArcherGuard.cs @@ -21,7 +21,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { @@ -65,11 +65,11 @@ namespace Server.Mobiles AddItem(pack); - Skills[SkillName.Anatomy].Base = 120.0; - Skills[SkillName.Tactics].Base = 120.0; - Skills[SkillName.Archery].Base = 120.0; - Skills[SkillName.MagicResist].Base = 120.0; - Skills[SkillName.DetectHidden].Base = 100.0; + Skills.Anatomy.Base = 120.0; + Skills.Tactics.Base = 120.0; + Skills.Archery.Base = 120.0; + Skills.MagicResist.Base = 120.0; + Skills.DetectHidden.Base = 100.0; NextCombatTime = Core.TickCount + 500; Focus = target; diff --git a/Scripts/Mobiles/Guards/WarriorGuard.cs b/Scripts/Mobiles/Guards/WarriorGuard.cs index 830c53514..75cefad0d 100644 --- a/Scripts/Mobiles/Guards/WarriorGuard.cs +++ b/Scripts/Mobiles/Guards/WarriorGuard.cs @@ -21,7 +21,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { @@ -101,11 +101,11 @@ namespace Server.Mobiles AddItem(pack); - Skills[SkillName.Anatomy].Base = 120.0; - Skills[SkillName.Tactics].Base = 120.0; - Skills[SkillName.Swords].Base = 120.0; - Skills[SkillName.MagicResist].Base = 120.0; - Skills[SkillName.DetectHidden].Base = 100.0; + Skills.Anatomy.Base = 120.0; + Skills.Tactics.Base = 120.0; + Skills.Swords.Base = 120.0; + Skills.MagicResist.Base = 120.0; + Skills.DetectHidden.Base = 100.0; NextCombatTime = Core.TickCount + 500; Focus = target; diff --git a/Scripts/Mobiles/Healers/BaseHealer.cs b/Scripts/Mobiles/Healers/BaseHealer.cs index 5e0710d1f..af49235cf 100644 --- a/Scripts/Mobiles/Healers/BaseHealer.cs +++ b/Scripts/Mobiles/Healers/BaseHealer.cs @@ -94,7 +94,7 @@ namespace Server.Mobiles m.PlaySound(0x1F2); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, ResurrectMessage.Healer)); } diff --git a/Scripts/Mobiles/Healers/PricedHealer.cs b/Scripts/Mobiles/Healers/PricedHealer.cs index 567912940..1669827a7 100644 --- a/Scripts/Mobiles/Healers/PricedHealer.cs +++ b/Scripts/Mobiles/Healers/PricedHealer.cs @@ -40,7 +40,7 @@ namespace Server.Mobiles m.PlaySound(0x214); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, this, Price)); } diff --git a/Scripts/Mobiles/Monsters/AOS/DemonKnight.cs b/Scripts/Mobiles/Monsters/AOS/DemonKnight.cs index d70295724..1e9c1c916 100644 --- a/Scripts/Mobiles/Monsters/AOS/DemonKnight.cs +++ b/Scripts/Mobiles/Monsters/AOS/DemonKnight.cs @@ -235,15 +235,14 @@ namespace Server.Mobiles PlaySound(0x491); if (0.05 > Utility.RandomDouble()) - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(CreateBones_Callback), from); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), CreateBones_Callback, from); m_InHere = false; } } - public virtual void CreateBones_Callback(object state) + public virtual void CreateBones_Callback(Mobile from) { - Mobile from = (Mobile)state; Map map = from.Map; if (map == null) @@ -257,11 +256,11 @@ namespace Server.Mobiles int y = from.Y + Utility.RandomMinMax(-1, 1); int z = from.Z; - if (!map.CanFit(x, y, z, 16, false, true)) + if (!map.CanFit(x, y, z, 16)) { z = map.GetAverageZ(x, y); - if (z == from.Z || !map.CanFit(x, y, z, 16, false, true)) + if (z == from.Z || !map.CanFit(x, y, z, 16)) continue; } diff --git a/Scripts/Mobiles/Monsters/AOS/Revenant.cs b/Scripts/Mobiles/Monsters/AOS/Revenant.cs index a0d7174a8..e748ac6d0 100644 --- a/Scripts/Mobiles/Monsters/AOS/Revenant.cs +++ b/Scripts/Mobiles/Monsters/AOS/Revenant.cs @@ -16,7 +16,7 @@ namespace Server.Mobiles Hue = 1; // TODO: Sound values? - double scalar = caster.Skills[SkillName.SpiritSpeak].Value * 0.01; + double scalar = caster.Skills.SpiritSpeak.Value * 0.01; m_Target = target; m_ExpireTime = DateTime.UtcNow + duration; diff --git a/Scripts/Mobiles/Monsters/Humanoid/Magic/Betrayer.cs b/Scripts/Mobiles/Monsters/Humanoid/Magic/Betrayer.cs index f4f2b3240..5433f261d 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Magic/Betrayer.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Magic/Betrayer.cs @@ -128,20 +128,16 @@ namespace Server.Mobiles if (defender.Alive) { defender.Frozen = true; - Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(Recover_Callback), defender); + Timer.DelayCall(TimeSpan.FromSeconds(5.0), Recover_Callback, defender); } } } - private void Recover_Callback(object state) + private void Recover_Callback(Mobile defender) { - if (state is Mobile defender) - { - defender.Frozen = false; - defender.Combatant = null; - defender.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You recover your senses."); - } - + defender.Frozen = false; + defender.Combatant = null; + defender.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You recover your senses."); m_Stunning = false; } diff --git a/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs b/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs index 3ce772e06..26a2b71b3 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using Server.Items; using Server.Spells; @@ -118,11 +120,11 @@ namespace Server.Mobiles if (Map == null) return; - ArrayList list = new ArrayList(); + List list = new List(); foreach (Mobile m in GetMobilesInRange(8)) - if (m != this && m is SavageShaman) - list.Add(m); + if (m != this && m is SavageShaman ss) + list.Add(ss); Animate(111, 5, 1, true, false, 0); // Do a little dance... @@ -133,7 +135,7 @@ namespace Server.Mobiles { for (int i = 0; i < list.Count; ++i) { - SavageShaman dancer = (SavageShaman)list[i]; + SavageShaman dancer = list[i]; dancer.Animate(111, 5, 1, true, false, 0); // Get down tonight... @@ -150,120 +152,118 @@ namespace Server.Mobiles if (Deleted) return; - ArrayList list = new ArrayList(); - - foreach (Mobile m in GetMobilesInRange(8)) - list.Add(m); - - if (list.Count > 0) - switch (Utility.Random(3)) + IPooledEnumerable eable = GetMobilesInRange(8); + + switch (Utility.Random(3)) + { + case 0: /* greater heal */ { - case 0: /* greater heal */ + foreach (Mobile m in eable) { - foreach (Mobile m in list) - { - bool isFriendly = m is Savage || m is SavageRider || m is SavageShaman || m is SavageRidgeback; + bool isFriendly = m is Savage || m is SavageRider || m is SavageShaman || m is SavageRidgeback; - if (!isFriendly) - continue; + if (!isFriendly) + continue; - if (m.Poisoned || MortalStrike.IsWounded(m) || !CanBeBeneficial(m)) - continue; + if (m.Poisoned || MortalStrike.IsWounded(m) || !CanBeBeneficial(m)) + continue; - DoBeneficial(m); + DoBeneficial(m); - // Algorithm: (40% of magery) + (1-10) + // Algorithm: (40% of magery) + (1-10) - int toHeal = (int)(Skills[SkillName.Magery].Value * 0.4); - toHeal += Utility.Random(1, 10); + int toHeal = (int)(Skills.Magery.Value * 0.4); + toHeal += Utility.Random(1, 10); - m.Heal(toHeal, this); + m.Heal(toHeal, this); - m.FixedParticles(0x376A, 9, 32, 5030, EffectLayer.Waist); - m.PlaySound(0x202); - } - - break; + m.FixedParticles(0x376A, 9, 32, 5030, EffectLayer.Waist); + m.PlaySound(0x202); } - case 1: /* lightning */ - { - foreach (Mobile m in list) - { - bool isFriendly = m is Savage || m is SavageRider || m is SavageShaman || m is SavageRidgeback; - if (isFriendly) - continue; - - if (!CanBeHarmful(m)) - continue; - - DoHarmful(m); - - double damage; - - if (Core.AOS) - { - int baseDamage = 6 + (int)(Skills[SkillName.EvalInt].Value / 5.0); - - damage = Utility.RandomMinMax(baseDamage, baseDamage + 3); - } - else - { - damage = Utility.Random(12, 9); - } - - m.BoltEffect(0); - - SpellHelper.Damage(TimeSpan.FromSeconds(0.25), m, this, damage, 0, 0, 0, 0, 100); - } - - break; - } - case 2: /* poison */ - { - foreach (Mobile m in list) - { - bool isFriendly = m is Savage || m is SavageRider || m is SavageShaman || m is SavageRidgeback; - - if (isFriendly) - continue; - - if (!CanBeHarmful(m)) - continue; - - DoHarmful(m); - - m.Spell?.OnCasterHurt(); - - m.Paralyzed = false; - - double total = Skills[SkillName.Magery].Value + Skills[SkillName.Poisoning].Value; - - double dist = GetDistanceToSqrt(m); - - if (dist >= 3.0) - total -= (dist - 3.0) * 10.0; - - int level; - - if (total >= 200.0 && Utility.Random(1, 100) <= 10) - level = 3; - else if (total > 170.0) - level = 2; - else if (total > 130.0) - level = 1; - else - level = 0; - - m.ApplyPoison(this, Poison.GetPoison(level)); - - m.FixedParticles(0x374A, 10, 15, 5021, EffectLayer.Waist); - m.PlaySound(0x474); - } - - break; - } + break; } + case 1: /* lightning */ + { + foreach (Mobile m in eable) + { + bool isFriendly = m is Savage || m is SavageRider || m is SavageShaman || m is SavageRidgeback; + + if (isFriendly) + continue; + + if (!CanBeHarmful(m)) + continue; + + DoHarmful(m); + + double damage; + + if (Core.AOS) + { + int baseDamage = 6 + (int)(Skills.EvalInt.Value / 5.0); + + damage = Utility.RandomMinMax(baseDamage, baseDamage + 3); + } + else + { + damage = Utility.Random(12, 9); + } + + m.BoltEffect(0); + + SpellHelper.Damage(TimeSpan.FromSeconds(0.25), m, this, damage, 0, 0, 0, 0, 100); + } + + break; + } + case 2: /* poison */ + { + foreach (Mobile m in eable) + { + bool isFriendly = m is Savage || m is SavageRider || m is SavageShaman || m is SavageRidgeback; + + if (isFriendly) + continue; + + if (!CanBeHarmful(m)) + continue; + + DoHarmful(m); + + m.Spell?.OnCasterHurt(); + + m.Paralyzed = false; + + double total = Skills.Magery.Value + Skills.Poisoning.Value; + + double dist = GetDistanceToSqrt(m); + + if (dist >= 3.0) + total -= (dist - 3.0) * 10.0; + + int level; + + if (total >= 200.0 && Utility.Random(1, 100) <= 10) + level = 3; + else if (total > 170.0) + level = 2; + else if (total > 130.0) + level = 1; + else + level = 0; + + m.ApplyPoison(this, Poison.GetPoison(level)); + + m.FixedParticles(0x374A, 10, 15, 5021, EffectLayer.Waist); + m.PlaySound(0x474); + } + + break; + } + } + + eable.Free(); } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/Monsters/Humanoid/Magic/Succubus.cs b/Scripts/Mobiles/Monsters/Humanoid/Magic/Succubus.cs index 055a8c521..4ae0bc2ba 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Magic/Succubus.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Magic/Succubus.cs @@ -58,21 +58,15 @@ namespace Server.Mobiles public void DrainLife() { - ArrayList list = new ArrayList(); + IPooledEnumerable eable = GetMobilesInRange(2); - foreach (Mobile m in GetMobilesInRange(2)) + foreach (Mobile m in eable) { - if (m == this || !CanBeHarmful(m)) + if (m == this || !CanBeHarmful(m) || + !(m is BaseCreature creature && (creature.Controlled || creature.Summoned || creature.Team != Team) || + m.Player)) continue; - - if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || creature.Team != Team)) - list.Add(m); - else if (m.Player) - list.Add(m); - } - - foreach (Mobile m in list) - { + DoHarmful(m); m.FixedParticles(0x374A, 10, 15, 5013, 0x496, 0, EffectLayer.Waist); @@ -85,6 +79,8 @@ namespace Server.Mobiles Hits += toDrain; m.Damage(toDrain, this); } + + eable.Free(); } public override void OnGaveMeleeAttack(Mobile defender) diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/Brigand.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/Brigand.cs index ee73d5b03..4cec2825d 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/Brigand.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/Brigand.cs @@ -9,7 +9,7 @@ namespace Server.Mobiles { SpeechHue = Utility.RandomDyedHue(); Title = "the brigand"; - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/Executioner.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/Executioner.cs index d39c27a4d..3b5e2ff9b 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/Executioner.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/Executioner.cs @@ -9,7 +9,7 @@ namespace Server.Mobiles { SpeechHue = Utility.RandomDyedHue(); Title = "the executioner"; - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/Guardian.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/Guardian.cs index 9ec7f9379..43b0462d3 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/Guardian.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/Guardian.cs @@ -12,7 +12,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { @@ -58,11 +58,11 @@ namespace Server.Mobiles PackItem(new Arrow(250)); PackGold(250, 500); - Skills[SkillName.Anatomy].Base = 120.0; - Skills[SkillName.Tactics].Base = 120.0; - Skills[SkillName.Archery].Base = 120.0; - Skills[SkillName.MagicResist].Base = 120.0; - Skills[SkillName.DetectHidden].Base = 100.0; + Skills.Anatomy.Base = 120.0; + Skills.Tactics.Base = 120.0; + Skills.Archery.Base = 120.0; + Skills.MagicResist.Base = 120.0; + Skills.DetectHidden.Base = 100.0; } public Guardian(Serial serial) : base(serial) diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/HeadlessOne.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/HeadlessOne.cs index f5b4b9e4e..3051f3cc8 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/HeadlessOne.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/HeadlessOne.cs @@ -6,7 +6,7 @@ namespace Server.Mobiles public HeadlessOne() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) { Body = 31; - Hue = Utility.RandomSkinHue() & 0x7FFF; + Hue = Race.Human.RandomSkinHue() & 0x7FFF; BaseSoundID = 0x39D; SetStr(26, 50); diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/Juggernaut.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/Juggernaut.cs index c2b9d66bf..9c518a4cc 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/Juggernaut.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/Juggernaut.cs @@ -124,20 +124,16 @@ namespace Server.Mobiles if (defender.Alive) { defender.Frozen = true; - Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(Recover_Callback), defender); + Timer.DelayCall(TimeSpan.FromSeconds(5.0), Recover_Callback, defender); } } } - private void Recover_Callback(object state) + private void Recover_Callback(Mobile defender) { - if (state is Mobile defender) - { - defender.Frozen = false; - defender.Combatant = null; - defender.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You recover your senses."); - } - + defender.Frozen = false; + defender.Combatant = null; + defender.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You recover your senses."); m_Stunning = false; } diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/KhaldunRevenant.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/KhaldunRevenant.cs index b4a1bd55d..4f0e0c02d 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/KhaldunRevenant.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/KhaldunRevenant.cs @@ -1,12 +1,13 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; namespace Server.Mobiles { public class KhaldunRevenant : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static HashSet m_Set = new HashSet(); private DateTime m_ExpireTime; private Mobile m_Target; @@ -47,9 +48,7 @@ namespace Server.Mobiles VirtualArmor = 60; - Halberd weapon = new Halberd(); - weapon.Hue = 0x41CE; - weapon.Movable = false; + Halberd weapon = new Halberd { Hue = 0x41CE, Movable = false }; AddItem(weapon); } @@ -81,7 +80,7 @@ namespace Server.Mobiles if (lastKiller is BaseCreature) lastKiller = ((BaseCreature)lastKiller).GetMaster(); - if (IsInsideKhaldun(m) && IsInsideKhaldun(lastKiller) && lastKiller.Player && !m_Table.Contains(lastKiller)) + if (IsInsideKhaldun(m) && IsInsideKhaldun(lastKiller) && lastKiller.Player && !m_Set.Contains(lastKiller)) foreach (AggressorInfo ai in m.Aggressors) if (ai.Attacker == lastKiller && ai.CanReportMurder) { @@ -99,12 +98,12 @@ namespace Server.Mobiles revenant.FixedParticles(0, 0, 0, 0x13A7, EffectLayer.Waist); Effects.PlaySound(revenant.Location, revenant.Map, 0x29); - m_Table.Add(killer, null); + m_Set.Add(killer); } public static bool IsInsideKhaldun(Mobile from) { - return from?.Region != null && from.Region.IsPartOf("Khaldun"); + return from?.Region?.IsPartOf("Khaldun") == true; } public override void DisplayPaperdollTo(Mobile to) @@ -152,7 +151,7 @@ namespace Server.Mobiles public override void OnDelete() { if (m_Target != null) - m_Table.Remove(m_Target); + m_Set.Remove(m_Target); base.OnDelete(); } @@ -173,4 +172,4 @@ namespace Server.Mobiles Delete(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/OrcBrute.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/OrcBrute.cs index 7e39bc28d..9f48955c0 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/OrcBrute.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/OrcBrute.cs @@ -1,3 +1,4 @@ +using System.Linq; using Server.Items; namespace Server.Mobiles @@ -108,35 +109,15 @@ namespace Server.Mobiles if (map == null) return; - int orcs = 0; - - foreach (Mobile m in GetMobilesInRange(10)) - if (m is OrcishLord) - ++orcs; + IPooledEnumerable eable = GetMobilesInRange(10); + int orcs = eable.Count(); + eable.Free(); if (orcs < 10) { - BaseCreature orc = new SpawnedOrcishLord(); - - orc.Team = Team; - - Point3D loc = target.Location; - bool validLocation = false; - - for (int j = 0; !validLocation && j < 10; ++j) - { - int x = target.X + Utility.Random(3) - 1; - int y = target.Y + Utility.Random(3) - 1; - int z = map.GetAverageZ(x, y); - - if (validLocation = map.CanFit(x, y, Z, 16, false, false)) - loc = new Point3D(x, y, Z); - else if (validLocation = map.CanFit(x, y, z, 16, false, false)) - loc = new Point3D(x, y, z); - } - - orc.MoveToWorld(loc, map); + BaseCreature orc = new SpawnedOrcishLord{ Team = Team }; + orc.MoveToWorld(map.GetRandomNearbyLocation(target.Location), map); orc.Combatant = target; } } @@ -153,4 +134,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoon.cs b/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoon.cs index 2afaf18ec..169b2cc62 100644 --- a/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoon.cs +++ b/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoon.cs @@ -8,7 +8,7 @@ namespace Server.Mobiles public ChaosDragoon() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.15, 0.4) { Body = 0x190; - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); SetStr(176, 225); SetDex(81, 95); diff --git a/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoonElite.cs b/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoonElite.cs index 1325fd71a..3451d6d0e 100644 --- a/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoonElite.cs +++ b/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoonElite.cs @@ -9,7 +9,7 @@ namespace Server.Mobiles : base(AIType.AI_Mage, FightMode.Closest, 10, 1, 0.15, 0.4) { Body = 0x190; - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); SetStr(276, 350); SetDex(66, 90); diff --git a/Scripts/Mobiles/Monsters/LBR/Jukas/JukaMage.cs b/Scripts/Mobiles/Monsters/LBR/Jukas/JukaMage.cs index e68053647..159f54faf 100644 --- a/Scripts/Mobiles/Monsters/LBR/Jukas/JukaMage.cs +++ b/Scripts/Mobiles/Monsters/LBR/Jukas/JukaMage.cs @@ -113,7 +113,7 @@ namespace Server.Mobiles foreach (Mobile m in GetMobilesInRange(8)) if (m is JukaLord lord && IsFriend(lord) && lord.Combatant != null && CanBeBeneficial(lord) && - lord.CanBeginAction(typeof(JukaMage)) && InLOS(lord)) + lord.CanBeginAction() && InLOS(lord)) { toBuff = lord; break; @@ -121,7 +121,7 @@ namespace Server.Mobiles if (toBuff != null) { - if (CanBeBeneficial(toBuff) && toBuff.BeginAction(typeof(JukaMage))) + if (CanBeBeneficial(toBuff) && toBuff.BeginAction()) { m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds(Utility.RandomMinMax(30, 60)); @@ -130,8 +130,6 @@ namespace Server.Mobiles DoBeneficial(toBuff); - object[] state = { toBuff, toBuff.HitsMaxSeed, toBuff.RawStr, toBuff.RawDex }; - SpellHelper.Turn(this, toBuff); int toScale = toBuff.HitsMaxSeed; @@ -161,7 +159,7 @@ namespace Server.Mobiles toBuff.FixedParticles(0x375A, 10, 15, 5017, EffectLayer.Waist); toBuff.PlaySound(0x1EE); - Timer.DelayCall(TimeSpan.FromSeconds(20.0), new TimerStateCallback(Unbuff), state); + Timer.DelayCall(TimeSpan.FromSeconds(20.0), () => Unbuff(toBuff, toBuff.HitsMaxSeed, toBuff.RawStr, toBuff.RawDex)); } } else @@ -173,20 +171,16 @@ namespace Server.Mobiles base.OnThink(); } - private void Unbuff(object state) + private void Unbuff(JukaLord toDebuff, int hitsMaxSeed, int rawStr, int rawDex) { - object[] states = (object[])state; - - JukaLord toDebuff = (JukaLord)states[0]; - - toDebuff.EndAction(typeof(JukaMage)); + toDebuff.EndAction(); if (toDebuff.Deleted) return; - toDebuff.HitsMaxSeed = (int)states[1]; - toDebuff.RawStr = (int)states[2]; - toDebuff.RawDex = (int)states[3]; + toDebuff.HitsMaxSeed = hitsMaxSeed; + toDebuff.RawStr = rawStr; + toDebuff.RawDex = rawDex; toDebuff.Hits = toDebuff.Hits; toDebuff.Stam = toDebuff.Stam; diff --git a/Scripts/Mobiles/Monsters/LBR/Meers/MeerCaptain.cs b/Scripts/Mobiles/Monsters/LBR/Meers/MeerCaptain.cs index 352163668..c9b91e79e 100644 --- a/Scripts/Mobiles/Monsters/LBR/Meers/MeerCaptain.cs +++ b/Scripts/Mobiles/Monsters/LBR/Meers/MeerCaptain.cs @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using Server.Items; using Server.Spells; @@ -136,17 +138,14 @@ namespace Server.Mobiles { m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds(Utility.RandomMinMax(10, 15)); - ArrayList list = new ArrayList(); + IPooledEnumerable eable = GetMobilesInRange(8); - foreach (Mobile m in GetMobilesInRange(8)) - if (m is MeerWarrior && IsFriend(m) && CanBeBeneficial(m) && m.Hits < m.HitsMax && !m.Poisoned && - !MortalStrike.IsWounded(m)) - list.Add(m); - - for (int i = 0; i < list.Count; ++i) + foreach (Mobile m in eable) { - Mobile m = (Mobile)list[i]; - + if (!(m is MeerWarrior) || !IsFriend(m) || !CanBeBeneficial(m) || m.Hits >= m.HitsMax || m.Poisoned || + MortalStrike.IsWounded(m)) + continue; + DoBeneficial(m); int toHeal = Utility.RandomMinMax(20, 30); @@ -158,6 +157,8 @@ namespace Server.Mobiles m.FixedParticles(0x376A, 9, 32, 5030, EffectLayer.Waist); m.PlaySound(0x202); } + + eable.Free(); } base.OnThink(); diff --git a/Scripts/Mobiles/Monsters/LBR/Meers/MeerEternal.cs b/Scripts/Mobiles/Monsters/LBR/Meers/MeerEternal.cs index 0e7dc011b..135eae333 100644 --- a/Scripts/Mobiles/Monsters/LBR/Meers/MeerEternal.cs +++ b/Scripts/Mobiles/Monsters/LBR/Meers/MeerEternal.cs @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; namespace Server.Mobiles { @@ -92,11 +94,11 @@ namespace Server.Mobiles private void DoAreaLeech_Finish() { - ArrayList list = new ArrayList(); + IPooledEnumerable eable = GetMobilesInRange(6); - foreach (Mobile m in GetMobilesInRange(6)) - if (CanBeHarmful(m) && IsEnemy(m)) - list.Add(m); + List list = eable.Where(m => CanBeHarmful(m) && IsEnemy(m)).ToList(); + + eable.Free(); if (list.Count == 0) { @@ -115,20 +117,15 @@ namespace Server.Mobiles for (int i = 0; i < list.Count; ++i) { - Mobile m = (Mobile)list[i]; + Mobile m = list[i]; - int damage = (int)(m.Hits * scalar); - - damage += Utility.RandomMinMax(-5, 5); - - if (damage < 1) - damage = 1; + int damage = (int)(m.Hits * scalar) + Utility.RandomMinMax(-5, 5); m.MovingParticles(this, 0x36F4, 1, 0, false, false, 32, 0, 9535, 1, 0, (EffectLayer)255, 0x100); m.MovingParticles(this, 0x0001, 1, 0, false, true, 32, 0, 9535, 9536, 0, (EffectLayer)255, 0); DoHarmful(m); - Hits += AOS.Damage(m, this, damage, 100, 0, 0, 0, 0); + Hits += AOS.Damage(m, this, Math.Max(damage, 1), 100, 0, 0, 0, 0); } Say(true, "If I cannot cleanse thy soul, I will destroy it!"); @@ -139,27 +136,23 @@ namespace Server.Mobiles { Say(true, message); - Timer.DelayCall(TimeSpan.FromSeconds(0.5), new TimerStateCallback(DoFocusedLeech_Stage1), combatant); + Timer.DelayCall(TimeSpan.FromSeconds(0.5), DoFocusedLeech_Stage1, combatant); } - private void DoFocusedLeech_Stage1(object state) + private void DoFocusedLeech_Stage1(Mobile combatant) { - Mobile combatant = (Mobile)state; - if (CanBeHarmful(combatant)) { MovingParticles(combatant, 0x36FA, 1, 0, false, false, 1108, 0, 9533, 1, 0, (EffectLayer)255, 0x100); MovingParticles(combatant, 0x0001, 1, 0, false, true, 1108, 0, 9533, 9534, 0, (EffectLayer)255, 0); PlaySound(0x1FB); - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(DoFocusedLeech_Stage2), combatant); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), DoFocusedLeech_Stage2, combatant); } } - private void DoFocusedLeech_Stage2(object state) + private void DoFocusedLeech_Stage2(Mobile combatant) { - Mobile combatant = (Mobile)state; - if (CanBeHarmful(combatant)) { combatant.MovingParticles(this, 0x36F4, 1, 0, false, false, 32, 0, 9535, 1, 0, (EffectLayer)255, 0x100); @@ -218,4 +211,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs b/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs index 6ec494756..a3b42f4dc 100644 --- a/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs +++ b/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; using Server.Network; @@ -7,7 +8,7 @@ namespace Server.Mobiles { public class MeerMage : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); private DateTime m_NextAbilityTime; @@ -145,9 +146,11 @@ namespace Server.Mobiles } else if (combatant.Player) { + int count = 0; + Say(true, "I call a plague of insects to sting your flesh!"); m_Table[combatant] = Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(7.0), - new TimerStateCallback(DoEffect), new object[] { combatant, 0 }); + () => DoEffect(combatant, count++)); } } } @@ -157,29 +160,26 @@ namespace Server.Mobiles public static bool UnderEffect(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public static void StopEffect(Mobile m, bool message) { - if (m_Table[m] is Timer t) + Timer timer = m_Table[m]; + + if (timer != null) { if (message) m.PublicOverheadMessage(MessageType.Emote, m.SpeechHue, true, "* The open flame begins to scatter the swarm of insects *"); - t.Stop(); + timer.Stop(); m_Table.Remove(m); } } - public void DoEffect(object state) + public void DoEffect(Mobile m, int count) { - object[] states = (object[])state; - - Mobile m = (Mobile)states[0]; - int count = (int)states[1]; - if (!m.Alive) { StopEffect(m, false); @@ -206,8 +206,6 @@ namespace Server.Mobiles AOS.Damage(m, this, Utility.RandomMinMax(30, 40) - (Core.AOS ? 0 : 10), 100, 0, 0, 0, 0); - states[1] = count + 1; - if (!m.Alive) StopEffect(m, false); } @@ -226,4 +224,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/ML/Misc/Magic/GreaterDragon.cs b/Scripts/Mobiles/Monsters/ML/Misc/Magic/GreaterDragon.cs index 524c43e7d..c722410a4 100644 --- a/Scripts/Mobiles/Monsters/ML/Misc/Magic/GreaterDragon.cs +++ b/Scripts/Mobiles/Monsters/ML/Misc/Magic/GreaterDragon.cs @@ -96,8 +96,8 @@ namespace Server.Mobiles { AnimalTaming.ScaleStats(this, 0.50); AnimalTaming.ScaleSkills(this, 0.80, 0.90); // 90% * 80% = 72% of original skills trainable to 90% - Skills[SkillName.Magery].Base = - Skills[SkillName.Magery] + Skills.Magery.Base = + Skills.Magery .Cap; // Greater dragons have a 90% cap reduction and 90% skill reduction on magery } } diff --git a/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs b/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs index 67101ac2d..a64b26fd2 100644 --- a/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs +++ b/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs @@ -9,9 +9,7 @@ namespace Server.Mobiles { public class Ilhenir : BaseChampion { - private static Hashtable m_Table; - - private DateTime m_NextDrop = DateTime.UtcNow; + private static Dictionary m_Table = new Dictionary(); [Constructible] public Ilhenir() @@ -232,41 +230,25 @@ namespace Server.Mobiles public virtual void CacophonicAttack(Mobile to) { - if (m_Table == null) - m_Table = new Hashtable(); - - if (to.Alive && to.Player && m_Table[to] == null) + if (to.Alive && to.Player && !m_Table.ContainsKey(to)) { to.Send(SpeedControl.WalkSpeed); to.SendLocalizedMessage(1072069); // A cacophonic sound lambastes you, suppressing your ability to move. to.PlaySound(0x584); - m_Table[to] = Timer.DelayCall(TimeSpan.FromSeconds(30), new TimerStateCallback(EndCacophonic_Callback), to); + m_Table[to] = Timer.DelayCall(TimeSpan.FromSeconds(30), CacophonicEnd, to); } } - private void EndCacophonic_Callback(object state) - { - if (state is Mobile mobile) - CacophonicEnd(mobile); - } - public virtual void CacophonicEnd(Mobile from) { - if (m_Table == null) - m_Table = new Hashtable(); - - m_Table[from] = null; - + m_Table.Remove(from); from.Send(SpeedControl.Disable); } public static bool UnderCacophonicAttack(Mobile from) { - if (m_Table == null) - m_Table = new Hashtable(); - - return m_Table[from] != null; + return m_Table.ContainsKey(from); } public virtual void DropOoze() @@ -336,14 +318,7 @@ namespace Server.Mobiles private Timer m_Timer; [Constructible] - public StainedOoze() - : this(false) - { - } - - [Constructible] - public StainedOoze(bool corrosive) - : base(0x122A) + public StainedOoze(bool corrosive = false) : base(0x122A) { Movable = false; Hue = 0x95; @@ -447,4 +422,4 @@ namespace Server.Mobiles m_Ticks = ItemID == 0x122A ? 0 : 30; } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/ML/Special/Meraktus.cs b/Scripts/Mobiles/Monsters/ML/Special/Meraktus.cs index c4f6a4965..0af62c7b9 100644 --- a/Scripts/Mobiles/Monsters/ML/Special/Meraktus.cs +++ b/Scripts/Mobiles/Monsters/ML/Special/Meraktus.cs @@ -128,34 +128,35 @@ namespace Server.Mobiles { base.OnDeath(c); - if (Core.ML) + if (!Core.ML) + return; + + c.DropItem(new MalletAndChisel()); + + switch (Utility.Random(3)) { - c.DropItem(new MalletAndChisel()); - - switch (Utility.Random(3)) - { - case 0: - c.DropItem(new MinotaurHedge()); - break; - case 1: - c.DropItem(new BonePile()); - break; - case 2: - c.DropItem(new LightYarn()); - break; - } - - if (Utility.RandomBool()) - c.DropItem(new TormentedChains()); - - if (Utility.RandomDouble() < 0.025) - c.DropItem(new CrimsonCincture()); + case 0: + c.DropItem(new MinotaurHedge()); + break; + case 1: + c.DropItem(new BonePile()); + break; + case 2: + c.DropItem(new LightYarn()); + break; } + + if (Utility.RandomBool()) + c.DropItem(new TormentedChains()); + + if (Utility.RandomDouble() < 0.025) + c.DropItem(new CrimsonCincture()); } public override void GenerateLoot() { - if (Core.ML) AddLoot(LootPack.AosSuperBoss, 5); // Need to verify + if (Core.ML) + AddLoot(LootPack.AosSuperBoss, 5); // Need to verify } public override int GetAngerSound() @@ -186,43 +187,36 @@ namespace Server.Mobiles public override void OnGaveMeleeAttack(Mobile defender) { base.OnGaveMeleeAttack(defender); + if (0.2 >= Utility.RandomDouble()) Earthquake(); } public void Earthquake() { - Map map = Map; - if (map == null) - return; - ArrayList targets = new ArrayList(); - foreach (Mobile m in GetMobilesInRange(8)) - { - if (m == this || !CanBeHarmful(m)) - continue; - if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || creature.Team != Team)) - targets.Add(m); - else if (m.Player) - targets.Add(m); - } + IPooledEnumerable eable = GetMobilesInRange(8); - PlaySound(0x2F3); - for (int i = 0; i < targets.Count; ++i) + foreach (Mobile m in eable) { - Mobile m = (Mobile)targets[i]; - if (m != null && !m.Deleted && m is PlayerMobile pm) - if (pm.Mounted) + if (m == this || !CanBeHarmful(m) || m.Deleted || !m.Player && + !(m is BaseCreature creature && (creature.Controlled || creature.Summoned || creature.Team != Team))) + continue; + + if (m is PlayerMobile pm && pm.Mounted) pm.Mount.Rider = null; - double damage = m.Hits * 0.6; //was .6 - if (damage < 10.0) - damage = 10.0; - else if (damage > 75.0) - damage = 75.0; + + int damage = (int)(m.Hits * 0.6); + if (damage < 10) + damage = 10; + else if (damage > 75) + damage = 75; DoHarmful(m); - AOS.Damage(m, this, (int)damage, 100, 0, 0, 0, 0); + AOS.Damage(m, this, damage, 100, 0, 0, 0, 0); if (m.Alive && m.Body.IsHuman && !m.Mounted) m.Animate(20, 7, 1, true, false, 0); // take hit } + + eable.Free(); } public override void Serialize(GenericWriter writer) @@ -256,4 +250,4 @@ namespace Server.Mobiles #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/ML/Special/Twaulo.cs b/Scripts/Mobiles/Monsters/ML/Special/Twaulo.cs index fba4f7ca2..c88279530 100644 --- a/Scripts/Mobiles/Monsters/ML/Special/Twaulo.cs +++ b/Scripts/Mobiles/Monsters/ML/Special/Twaulo.cs @@ -92,27 +92,9 @@ namespace Server.Mobiles for (int i = 0; i < newPixies; ++i) { - Pixie pixie = new Pixie(); + Pixie pixie = new Pixie { Team = Team, FightMode = FightMode.Closest }; - pixie.Team = Team; - pixie.FightMode = FightMode.Closest; - - bool validLocation = false; - Point3D loc = Location; - - for (int j = 0; !validLocation && j < 10; ++j) - { - int x = X + Utility.Random(3) - 1; - int y = Y + Utility.Random(3) - 1; - int z = map.GetAverageZ(x, y); - - if (validLocation = map.CanFit(x, y, Z, 16, false, false)) - loc = new Point3D(x, y, Z); - else if (validLocation = map.CanFit(x, y, z, 16, false, false)) - loc = new Point3D(x, y, z); - } - - pixie.MoveToWorld(loc, map); + pixie.MoveToWorld(map.GetRandomNearbyLocation(Location), map); pixie.Combatant = target; } } @@ -153,4 +135,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/ML/Twisted Weald/Swoop.cs b/Scripts/Mobiles/Monsters/ML/Twisted Weald/Swoop.cs index 62c1653f5..54265b0b2 100644 --- a/Scripts/Mobiles/Monsters/ML/Twisted Weald/Swoop.cs +++ b/Scripts/Mobiles/Monsters/ML/Twisted Weald/Swoop.cs @@ -1,11 +1,12 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Mobiles { public class Swoop : Eagle { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public Swoop() @@ -102,7 +103,7 @@ namespace Server.Mobiles if (0.1 > Utility.RandomDouble()) { - ExpireTimer timer = (ExpireTimer)m_Table[defender]; + ExpireTimer timer = m_Table[defender]; if (timer != null) { @@ -169,4 +170,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/Misc/Magic/EtherealWarrior.cs b/Scripts/Mobiles/Monsters/Misc/Magic/EtherealWarrior.cs index 536ac9385..2364c7f31 100644 --- a/Scripts/Mobiles/Monsters/Misc/Magic/EtherealWarrior.cs +++ b/Scripts/Mobiles/Monsters/Misc/Magic/EtherealWarrior.cs @@ -77,7 +77,7 @@ namespace Server.Mobiles Direction = GetDirectionTo(from); from.PlaySound(0x1F2); from.FixedEffect(0x376A, 10, 16); - from.CloseGump(typeof(ResurrectGump)); + from.CloseGump(); from.SendGump(new ResurrectGump(from, ResurrectMessage.Healer)); } } diff --git a/Scripts/Mobiles/Monsters/Misc/Melee/AnimatedWeapon.cs b/Scripts/Mobiles/Monsters/Misc/Melee/AnimatedWeapon.cs index dae1e9c57..02acf0ba2 100644 --- a/Scripts/Mobiles/Monsters/Misc/Melee/AnimatedWeapon.cs +++ b/Scripts/Mobiles/Monsters/Misc/Melee/AnimatedWeapon.cs @@ -47,8 +47,8 @@ namespace Server.Mobiles SetSkill(SkillName.MagicResist, level); SetSkill(SkillName.Wrestling, level); - SetSkill(SkillName.Anatomy, caster.Skills[SkillName.Anatomy].Value / 2); - SetSkill(SkillName.Tactics, caster.Skills[SkillName.Tactics].Value / 2); + SetSkill(SkillName.Anatomy, caster.Skills.Anatomy.Value / 2); + SetSkill(SkillName.Tactics, caster.Skills.Tactics.Value / 2); Fame = 0; Karma = 0; diff --git a/Scripts/Mobiles/Monsters/Misc/Melee/BladeSpirits.cs b/Scripts/Mobiles/Monsters/Misc/Melee/BladeSpirits.cs index c1a373aa1..558207fed 100644 --- a/Scripts/Mobiles/Monsters/Misc/Melee/BladeSpirits.cs +++ b/Scripts/Mobiles/Monsters/Misc/Melee/BladeSpirits.cs @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; namespace Server.Mobiles { @@ -42,8 +44,7 @@ namespace Server.Mobiles ControlSlots = Core.SE ? 2 : 1; } - public BladeSpirits(Serial serial) - : base(serial) + public BladeSpirits(Serial serial) : base(serial) { } @@ -61,7 +62,7 @@ namespace Server.Mobiles public override double GetFightModeRanking(Mobile m, FightMode acqType, bool bPlayerOnly) { - return (m.Str + m.Skills[SkillName.Tactics].Value) / Math.Max(GetDistanceToSqrt(m), 1.0); + return (m.Str + m.Skills.Tactics.Value) / Math.Max(GetDistanceToSqrt(m), 1.0); } public override int GetAngerSound() @@ -83,18 +84,17 @@ namespace Server.Mobiles { if (Core.SE && Summoned) { - ArrayList spirtsOrVortexes = new ArrayList(); + IPooledEnumerable eable = GetMobilesInRange(5); + List spiritsOrVortexes = eable + .Where(m => (m is EnergyVortex || m is BladeSpirits) && ((BaseCreature)m).Summoned).ToList(); - foreach (Mobile m in GetMobilesInRange(5)) - if (m is EnergyVortex || m is BladeSpirits) - if (((BaseCreature)m).Summoned) - spirtsOrVortexes.Add(m); + eable.Free(); - while (spirtsOrVortexes.Count > 6) + while (spiritsOrVortexes.Count > 6) { - int index = Utility.Random(spirtsOrVortexes.Count); - Dispel((Mobile)spirtsOrVortexes[index]); - spirtsOrVortexes.RemoveAt(index); + int index = Utility.Random(spiritsOrVortexes.Count); + Dispel(spiritsOrVortexes[index]); + spiritsOrVortexes.RemoveAt(index); } } @@ -115,4 +115,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/Misc/Melee/EnergyVortex.cs b/Scripts/Mobiles/Monsters/Misc/Melee/EnergyVortex.cs index 0ecbc6e43..7b63f4863 100644 --- a/Scripts/Mobiles/Monsters/Misc/Melee/EnergyVortex.cs +++ b/Scripts/Mobiles/Monsters/Misc/Melee/EnergyVortex.cs @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; namespace Server.Mobiles { @@ -70,7 +72,7 @@ namespace Server.Mobiles public override double GetFightModeRanking(Mobile m, FightMode acqType, bool bPlayerOnly) { - return (m.Int + m.Skills[SkillName.Magery].Value) / Math.Max(GetDistanceToSqrt(m), 1.0); + return (m.Int + m.Skills.Magery.Value) / Math.Max(GetDistanceToSqrt(m), 1.0); } public override int GetAngerSound() @@ -87,19 +89,17 @@ namespace Server.Mobiles { if (Core.SE && Summoned) { - ArrayList spirtsOrVortexes = new ArrayList(); + IPooledEnumerable eable = GetMobilesInRange(5); + List spiritsOrVortexes = eable + .Where(m => (m is EnergyVortex || m is BladeSpirits) && ((BaseCreature)m).Summoned).ToList(); - foreach (Mobile m in GetMobilesInRange(5)) - if (m is EnergyVortex || m is BladeSpirits) - if (((BaseCreature)m).Summoned) - spirtsOrVortexes.Add(m); + eable.Free(); - while (spirtsOrVortexes.Count > 6) + while (spiritsOrVortexes.Count > 6) { - int index = Utility.Random(spirtsOrVortexes.Count); - //TODO: Confirm if it's the dispel with all the pretty effects or just a deletion of it. - Dispel((Mobile)spirtsOrVortexes[index]); - spirtsOrVortexes.RemoveAt(index); + int index = Utility.Random(spiritsOrVortexes.Count); + Dispel(spiritsOrVortexes[index]); + spiritsOrVortexes.RemoveAt(index); } } @@ -123,4 +123,4 @@ namespace Server.Mobiles BaseSoundID = 0; } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs b/Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs index fae0240b1..0d2d2b195 100644 --- a/Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs +++ b/Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs @@ -175,20 +175,16 @@ namespace Server.Mobiles if (defender.Alive) { defender.Frozen = true; - Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(Recover_Callback), defender); + Timer.DelayCall(TimeSpan.FromSeconds(5.0), Recover_Callback, defender); } } } - private void Recover_Callback(object state) + private void Recover_Callback(Mobile defender) { - if (state is Mobile defender) - { - defender.Frozen = false; - defender.Combatant = null; - defender.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You recover your senses."); - } - + defender.Frozen = false; + defender.Combatant = null; + defender.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You recover your senses."); m_Stunning = false; } diff --git a/Scripts/Mobiles/Monsters/Plant/Melee/BogThing.cs b/Scripts/Mobiles/Monsters/Plant/Melee/BogThing.cs index c25325544..717c133fc 100644 --- a/Scripts/Mobiles/Monsters/Plant/Melee/BogThing.cs +++ b/Scripts/Mobiles/Monsters/Plant/Melee/BogThing.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Items; @@ -82,47 +83,33 @@ namespace Server.Mobiles if (map == null) return; - Bogling spawned = new Bogling(); + Bogling spawned = new Bogling { Team = Team }; - spawned.Team = Team; - - bool validLocation = false; - Point3D loc = Location; - - for (int j = 0; !validLocation && j < 10; ++j) - { - int x = X + Utility.Random(3) - 1; - int y = Y + Utility.Random(3) - 1; - int z = map.GetAverageZ(x, y); - - if (validLocation = map.CanFit(x, y, Z, 16, false, false)) - loc = new Point3D(x, y, Z); - else if (validLocation = map.CanFit(x, y, z, 16, false, false)) - loc = new Point3D(x, y, z); - } - - spawned.MoveToWorld(loc, map); + spawned.MoveToWorld(map.GetRandomNearbyLocation(Location), map); spawned.Combatant = m; } public void EatBoglings() { - ArrayList toEat = new ArrayList(); + IPooledEnumerable eable = GetMobilesInRange(2); + bool sound = true; - foreach (Mobile m in GetMobilesInRange(2)) - if (m is Bogling) - toEat.Add(m); - - if (toEat.Count > 0) + foreach (Bogling bogling in eable) { - PlaySound(Utility.Random(0x3B, 2)); // Eat sound + if (Hits >= HitsMax) + break; - foreach (Mobile m in toEat) + if (sound) { - Hits += m.Hits / 2; - m.Delete(); + PlaySound(Utility.Random(0x3B, 2)); // Eat sound + sound = false; } + + Hits += bogling.Hits / 2; + bogling.Delete(); } + + eable.Free(); } public override void OnGotMeleeAttack(Mobile attacker) @@ -135,9 +122,7 @@ namespace Server.Mobiles SpawnBogling(attacker); } else if (0.25 >= Utility.RandomDouble()) - { EatBoglings(); - } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/Reptile/Magic/Leviathan.cs b/Scripts/Mobiles/Monsters/Reptile/Magic/Leviathan.cs index 7685e5a4d..9a208b62c 100644 --- a/Scripts/Mobiles/Monsters/Reptile/Magic/Leviathan.cs +++ b/Scripts/Mobiles/Monsters/Reptile/Magic/Leviathan.cs @@ -83,7 +83,6 @@ namespace Server.Mobiles public override double BreathMinDelay => 5.0; public override double BreathMaxDelay => 7.5; - public override double TreasureMapChance => 0.25; public override int TreasureMapLevel => 5; public static Type[] Artifacts{ get; } = diff --git a/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs b/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs index 6495f3ae9..6a0033969 100644 --- a/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs +++ b/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Items; @@ -7,7 +8,7 @@ namespace Server.Mobiles { public class BakeKitsune : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public BakeKitsune() : base(AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4) @@ -88,9 +89,10 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (0.1 > Utility.RandomDouble()) - { - /* Blood Bath + if (!(0.1 > Utility.RandomDouble())) + return; + + /* Blood Bath * Start cliloc 1070826 * Sound: 0x52B * 2-3 blood spots @@ -98,22 +100,21 @@ namespace Server.Mobiles * End cliloc: 1070824 */ - ExpireTimer timer = (ExpireTimer)m_Table[defender]; + ExpireTimer timer = m_Table[defender]; - if (timer != null) - { - timer.DoExpire(); - defender.SendLocalizedMessage(1070825); // The creature continues to rage! - } - else - { - defender.SendLocalizedMessage(1070826); // The creature goes into a rage, inflicting heavy damage! - } - - timer = new ExpireTimer(defender, this); - timer.Start(); - m_Table[defender] = timer; + if (timer != null) + { + timer.DoExpire(); + defender.SendLocalizedMessage(1070825); // The creature continues to rage! } + else + { + defender.SendLocalizedMessage(1070826); // The creature goes into a rage, inflicting heavy damage! + } + + timer = new ExpireTimer(defender, this); + timer.Start(); + m_Table[defender] = timer; } public override int GetAngerSound() @@ -286,4 +287,4 @@ namespace Server.Mobiles #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/SE/EliteNinja.cs b/Scripts/Mobiles/Monsters/SE/EliteNinja.cs index c9d6f2ed1..14408fc2f 100644 --- a/Scripts/Mobiles/Monsters/SE/EliteNinja.cs +++ b/Scripts/Mobiles/Monsters/SE/EliteNinja.cs @@ -8,7 +8,7 @@ namespace Server.Mobiles public EliteNinja() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) { SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = Utility.RandomBool(); Body = Female ? 0x191 : 0x190; diff --git a/Scripts/Mobiles/Monsters/SE/FanDancer.cs b/Scripts/Mobiles/Monsters/SE/FanDancer.cs index f588561ef..2be81d5c0 100644 --- a/Scripts/Mobiles/Monsters/SE/FanDancer.cs +++ b/Scripts/Mobiles/Monsters/SE/FanDancer.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Items; using Server.Network; @@ -8,7 +9,7 @@ namespace Server.Mobiles { public class FanDancer : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public FanDancer() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) @@ -148,7 +149,7 @@ namespace Server.Mobiles public bool IsFanned(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public override void Serialize(GenericWriter writer) @@ -186,4 +187,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/SE/Kappa.cs b/Scripts/Mobiles/Monsters/SE/Kappa.cs index 757bff0e5..6ea7a3e12 100644 --- a/Scripts/Mobiles/Monsters/SE/Kappa.cs +++ b/Scripts/Mobiles/Monsters/SE/Kappa.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Items; @@ -7,7 +8,7 @@ namespace Server.Mobiles { public class Kappa : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public Kappa() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) @@ -110,19 +111,17 @@ namespace Server.Mobiles public static bool IsBeingDrained(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public static void BeginLifeDrain(Mobile m, Mobile from) { - Timer t = (Timer)m_Table[m]; + InternalTimer timer = m_Table[m]; - t?.Stop(); + timer?.Stop(); + m_Table[m] = timer = new InternalTimer(from, m); - t = new InternalTimer(from, m); - m_Table[m] = t; - - t.Start(); + timer.Start(); } public static void DrainLife(Mobile m, Mobile from) @@ -140,9 +139,8 @@ namespace Server.Mobiles public static void EndLifeDrain(Mobile m) { - Timer t = (Timer)m_Table[m]; - - t?.Stop(); + Timer timer = m_Table[m]; + timer?.Stop(); m_Table.Remove(m); @@ -169,7 +167,6 @@ namespace Server.Mobiles from.SendLocalizedMessage(1070820); if (Mana > 14) Mana -= 15; - amt ^= amt; } } @@ -215,4 +212,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/SE/KazeKemono.cs b/Scripts/Mobiles/Monsters/SE/KazeKemono.cs index 40fc9b8e5..c28219523 100644 --- a/Scripts/Mobiles/Monsters/SE/KazeKemono.cs +++ b/Scripts/Mobiles/Monsters/SE/KazeKemono.cs @@ -1,12 +1,13 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Mobiles { public class KazeKemono : BaseCreature { - private static Hashtable m_FlurryOfTwigsTable = new Hashtable(); - private static Hashtable m_ChlorophylBlastTable = new Hashtable(); + private static Dictionary m_FlurryOfTwigsTable = new Dictionary(); + private static Dictionary m_ChlorophylBlastTable = new Dictionary(); [Constructible] public KazeKemono() @@ -73,7 +74,7 @@ namespace Server.Mobiles * Effect: Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(1048 779, 6)" ToLocation: "(1048 779, 6)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False" */ - ExpireTimer timer = (ExpireTimer)m_FlurryOfTwigsTable[defender]; + ExpireTimer timer = m_FlurryOfTwigsTable[defender]; if (timer != null) { @@ -106,7 +107,7 @@ namespace Server.Mobiles * Effect: Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(1048 779, 6)" ToLocation: "(1048 779, 6)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False" */ - ExpireTimer timer = (ExpireTimer)m_ChlorophylBlastTable[defender]; + ExpireTimer timer = m_ChlorophylBlastTable[defender]; if (timer != null) { @@ -148,9 +149,9 @@ namespace Server.Mobiles { private Mobile m_Mobile; private ResistanceMod m_Mod; - private Hashtable m_Table; + private Dictionary m_Table; - public ExpireTimer(Mobile m, ResistanceMod mod, Hashtable table, TimeSpan delay) + public ExpireTimer(Mobile m, ResistanceMod mod, Dictionary table, TimeSpan delay) : base(delay) { m_Mobile = m; @@ -177,4 +178,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/SE/LadyOfTheSnow.cs b/Scripts/Mobiles/Monsters/SE/LadyOfTheSnow.cs index b8f36e8e8..93d72a6cc 100644 --- a/Scripts/Mobiles/Monsters/SE/LadyOfTheSnow.cs +++ b/Scripts/Mobiles/Monsters/SE/LadyOfTheSnow.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Items; @@ -7,7 +8,7 @@ namespace Server.Mobiles { public class LadyOfTheSnow : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public LadyOfTheSnow() @@ -90,7 +91,7 @@ namespace Server.Mobiles * Reset cliloc: 1070831 */ - ExpireTimer timer = (ExpireTimer)m_Table[defender]; + ExpireTimer timer = m_Table[defender]; if (timer != null) { @@ -162,4 +163,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/SE/RaiJu.cs b/Scripts/Mobiles/Monsters/SE/RaiJu.cs index 0f9bbcce5..4f2941f70 100644 --- a/Scripts/Mobiles/Monsters/SE/RaiJu.cs +++ b/Scripts/Mobiles/Monsters/SE/RaiJu.cs @@ -1,11 +1,12 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Mobiles { public class RaiJu : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public RaiJu() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) @@ -86,7 +87,7 @@ namespace Server.Mobiles public bool IsStunned(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public override void Serialize(GenericWriter writer) @@ -127,4 +128,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/SE/Ronin.cs b/Scripts/Mobiles/Monsters/SE/Ronin.cs index bc3bbc105..88f78c9d5 100644 --- a/Scripts/Mobiles/Monsters/SE/Ronin.cs +++ b/Scripts/Mobiles/Monsters/SE/Ronin.cs @@ -8,7 +8,7 @@ namespace Server.Mobiles public Ronin() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) { SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Female = Utility.RandomBool(); Body = Female ? 0x191 : 0x190; diff --git a/Scripts/Mobiles/Monsters/SE/RuneBeetle.cs b/Scripts/Mobiles/Monsters/SE/RuneBeetle.cs index f3bd9f183..7acfd4c4d 100644 --- a/Scripts/Mobiles/Monsters/SE/RuneBeetle.cs +++ b/Scripts/Mobiles/Monsters/SE/RuneBeetle.cs @@ -8,7 +8,7 @@ namespace Server.Mobiles { public class RuneBeetle : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public RuneBeetle() : base(AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4) @@ -146,7 +146,7 @@ namespace Server.Mobiles * End ASCII: "The corruption of your armor has worn off" */ - ExpireTimer timer = (ExpireTimer)m_Table[defender]; + ExpireTimer timer = m_Table[defender]; if (timer != null) { @@ -259,4 +259,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/SE/TsukiWolf.cs b/Scripts/Mobiles/Monsters/SE/TsukiWolf.cs index 3d1726c85..3d17802f3 100644 --- a/Scripts/Mobiles/Monsters/SE/TsukiWolf.cs +++ b/Scripts/Mobiles/Monsters/SE/TsukiWolf.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Engines.Plants; using Server.Items; @@ -7,7 +8,7 @@ namespace Server.Mobiles { public class TsukiWolf : BaseCreature { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); [Constructible] public TsukiWolf() @@ -112,7 +113,7 @@ namespace Server.Mobiles * End cliloc: 1070824 */ - ExpireTimer timer = (ExpireTimer)m_Table[defender]; + ExpireTimer timer = m_Table[defender]; if (timer != null) { @@ -209,4 +210,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/SE/Yamandon.cs b/Scripts/Mobiles/Monsters/SE/Yamandon.cs index c98651a4f..a5e4db79c 100644 --- a/Scripts/Mobiles/Monsters/SE/Yamandon.cs +++ b/Scripts/Mobiles/Monsters/SE/Yamandon.cs @@ -117,22 +117,15 @@ namespace Server.Mobiles Animate(10, 4, 1, true, false, 0); - ArrayList targets = new ArrayList(); + IPooledEnumerable eable = target.GetMobilesInRange(8); - foreach (Mobile m in target.GetMobilesInRange(8)) + foreach (Mobile m in eable) { - if (m == this || !CanBeHarmful(m)) + if (m == this || !(CanBeHarmful(m) || m.Player && m.Alive)) continue; - if (m is BaseCreature bc && (bc.Controlled || bc.Summoned || bc.Team != Team)) - targets.Add(m); - else if (m.Player && m.Alive) - targets.Add(m); - } - - for (int i = 0; i < targets.Count; ++i) - { - Mobile m = (Mobile)targets[i]; + if (!(m is BaseCreature bc) || !(bc.Controlled || bc.Summoned || bc.Team != Team)) + continue; DoHarmful(m); @@ -141,6 +134,8 @@ namespace Server.Mobiles m.FixedParticles(0x36BD, 1, 10, 0x1F78, 0xA6, 0, (EffectLayer)255); m.ApplyPoison(this, Poison.Lethal); } + + eable.Free(); } } @@ -183,4 +178,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/PlayerMobile.cs b/Scripts/Mobiles/PlayerMobile.cs index ebc21f22e..80daf3b8f 100644 --- a/Scripts/Mobiles/PlayerMobile.cs +++ b/Scripts/Mobiles/PlayerMobile.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using Server.Accounting; using Server.ContextMenus; using Server.Engines.BulkOrders; @@ -103,7 +104,7 @@ namespace Server.Mobiles private List m_AllFollowers; - private Hashtable m_AntiMacroTable; + private Dictionary> m_AntiMacroTable; private TimeSpan m_GameTime; /* @@ -117,7 +118,6 @@ namespace Server.Mobiles private Mobile m_InsuranceAward; private int m_InsuranceBonus; - private int m_InsuranceCost; private int m_LastGlobalLight = -1, m_LastPersonalLight = -1; @@ -143,7 +143,7 @@ namespace Server.Mobiles VisibilityList = new List(); PermaFlags = new List(); - m_AntiMacroTable = new Hashtable(); + m_AntiMacroTable = new Dictionary>(); RecentlyReported = new List(); BOBFilter = new BOBFilter(); @@ -155,7 +155,7 @@ namespace Server.Mobiles JusticeProtectors = new List(); m_GuildRank = RankDefinition.Lowest; - m_ChampionTitles = new ChampionTitleInfo(); + ChampionTitles = new ChampionTitleInfo(); InvalidateMyRunUO(); } @@ -163,7 +163,7 @@ namespace Server.Mobiles public PlayerMobile(Serial s) : base(s) { VisibilityList = new List(); - m_AntiMacroTable = new Hashtable(); + m_AntiMacroTable = new Dictionary>(); InvalidateMyRunUO(); } @@ -657,7 +657,7 @@ namespace Server.Mobiles public override int GetMinResistance(ResistanceType type) { - int magicResist = (int)(Skills[SkillName.MagicResist].Value * 10); + int magicResist = (int)(Skills.MagicResist.Value * 10); int min = int.MinValue; if (magicResist >= 1000) @@ -702,7 +702,7 @@ namespace Server.Mobiles notice = "The server is currently under lockdown. You do not have sufficient access level to connect."; - Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(Disconnect), from); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => from.NetState?.Dispose()); } else if (from.AccessLevel >= AccessLevel.Administrator) { @@ -714,7 +714,7 @@ namespace Server.Mobiles notice = "The server is currently under lockdown. You have sufficient access level to connect."; } - from.SendGump(new NoticeGump(1060637, 30720, notice, 0xFFC000, 300, 140, null, null)); + from.SendGump(new NoticeGump(1060637, 30720, notice, 0xFFC000, 300, 140)); return; } @@ -959,12 +959,6 @@ namespace Server.Mobiles InvalidateMyRunUO(); } - private static void Disconnect(object state) - { - NetState ns = ((Mobile)state).NetState; - ns?.Dispose(); - } - private static void OnLogout(LogoutEventArgs e) { if (e.Mobile is PlayerMobile mobile) @@ -985,14 +979,7 @@ namespace Server.Mobiles DisguiseTimers.StartTimer(e.Mobile); - Timer.DelayCall(TimeSpan.Zero, new TimerStateCallback(ClearSpecialMovesCallback), e.Mobile); - } - - private static void ClearSpecialMovesCallback(object state) - { - Mobile from = (Mobile)state; - - SpecialMove.ClearAllMoves(from); + Timer.DelayCall(TimeSpan.Zero, SpecialMove.ClearAllMoves, e.Mobile); } private static void EventSink_Disconnected(DisconnectedEventArgs e) @@ -1156,11 +1143,11 @@ namespace Server.Mobiles NetState ns = NetState; if (ns != null) - if (HasGump(typeof(ResurrectGump))) + if (HasGump()) { if (Alive) { - CloseGump(typeof(ResurrectGump)); + CloseGump(); } else { @@ -1246,8 +1233,8 @@ namespace Server.Mobiles { m_NextProtectionCheck = 10; - GuardedRegion reg = (GuardedRegion)Region.GetRegion(typeof(GuardedRegion)); - bool isProtected = reg != null && !reg.IsDisabled(); + GuardedRegion reg = Region.GetRegion(); + bool isProtected = reg?.IsDisabled() == false; if (isProtected != m_LastProtectedMessage) { @@ -1323,7 +1310,7 @@ namespace Server.Mobiles if (Alive && house.InternalizedVendors.Count > 0 && house.IsOwner(this)) list.Add(new CallbackEntry(6204, GetVendor)); - if (house.IsAosRules && !Region.IsPartOf(typeof(SafeZone))) // Dueling + if (house.IsAosRules && !Region.IsPartOf()) // Dueling list.Add(new CallbackEntry(6207, LeaveHouse)); } @@ -1365,9 +1352,8 @@ namespace Server.Mobiles BaseHouse curhouse = BaseHouse.FindHouseAt(this); - if (curhouse != null) - if (Alive && Core.Expansion >= Expansion.AOS && curhouse.IsAosRules && curhouse.IsFriend(from)) - list.Add(new EjectPlayerEntry(from, this)); + if (curhouse != null && Alive && Core.Expansion >= Expansion.AOS && curhouse.IsAosRules && curhouse.IsFriend(from)) + list.Add(new EjectPlayerEntry(from, this)); } } @@ -1399,7 +1385,7 @@ namespace Server.Mobiles if (CheckAlive() && house != null && house.IsOwner(this) && house.InternalizedVendors.Count > 0) { - CloseGump(typeof(ReclaimVendorGump)); + CloseGump(); SendGump(new ReclaimVendorGump(house)); } } @@ -1414,7 +1400,8 @@ namespace Server.Mobiles public override void DisruptiveAction() { - if (Meditating) RemoveBuff(BuffIcon.ActiveMeditation); + if (Meditating) + RemoveBuff(BuffIcon.ActiveMeditation); base.DisruptiveAction(); } @@ -1654,7 +1641,7 @@ namespace Server.Mobiles #region Dueling - if (Region.IsPartOf(typeof(SafeZone)) && m is PlayerMobile pm) + if (Region.IsPartOf() && m is PlayerMobile pm) if (pm.DuelContext == null || pm.DuelPlayer == null || !pm.DuelContext.Started || pm.DuelContext.Finished || pm.DuelPlayer.Eliminated) return true; @@ -1760,10 +1747,8 @@ namespace Server.Mobiles private bool FindItems_Callback(Item item) { - if (!item.Deleted && (item.LootType == LootType.Blessed || item.Insured)) - if (Backpack != item.Parent) - return true; - return false; + return !item.Deleted && (item.LootType == LootType.Blessed || item.Insured) && + Backpack != item.Parent; } public override bool OnBeforeDeath() @@ -1782,7 +1767,6 @@ namespace Server.Mobiles EquipSnapshot = new List(Items); m_NonAutoreinsuredItems = 0; - m_InsuranceCost = 0; m_InsuranceAward = FindMostRecentDamager(false); if (m_InsuranceAward is BaseCreature creature) @@ -1829,7 +1813,6 @@ namespace Server.Mobiles if (Banker.Withdraw(this, cost)) { - m_InsuranceCost += cost; item.PaidInsurance = true; SendLocalizedMessage(1060398, cost.ToString()); // ~1_AMOUNT~ gold has been withdrawn from your bank box. @@ -1848,10 +1831,8 @@ namespace Server.Mobiles item.Insured = false; } - if (m_InsuranceAward != null) - if (Banker.Deposit(m_InsuranceAward, 300)) - if (m_InsuranceAward is PlayerMobile mobile) - mobile.m_InsuranceBonus += 300; + if (m_InsuranceAward != null && Banker.Deposit(m_InsuranceAward, 300) && m_InsuranceAward is PlayerMobile pm) + pm.m_InsuranceBonus += 300; return true; @@ -1909,8 +1890,8 @@ namespace Server.Mobiles IncognitoSpell.StopTimer(this); DisguiseTimers.RemoveTimer(this); - EndAction(typeof(PolymorphSpell)); - EndAction(typeof(IncognitoSpell)); + EndAction(); + EndAction(); MeerMage.StopEffect(this, false); @@ -2019,7 +2000,7 @@ namespace Server.Mobiles if (Alive) return false; - if (Core.ML && Skills[SkillName.SpiritSpeak].Value >= 100.0) + if (Core.ML && Skills.SpiritSpeak.Value >= 100.0) return false; if (Core.AOS) @@ -2027,7 +2008,7 @@ namespace Server.Mobiles { Mobile m = hears[i]; - if (m != this && m.Skills[SkillName.SpiritSpeak].Value >= 100.0) + if (m != this && m.Skills.SpiritSpeak.Value >= 100.0) return false; } @@ -2158,11 +2139,11 @@ namespace Server.Mobiles if (obj == null || m_AntiMacroTable == null || AccessLevel != AccessLevel.Player) return true; - Hashtable tbl = (Hashtable)m_AntiMacroTable[skill]; + Dictionary tbl = m_AntiMacroTable[skill]; if (tbl == null) - m_AntiMacroTable[skill] = tbl = new Hashtable(); + m_AntiMacroTable[skill] = tbl = new Dictionary(); - CountAndTimeStamp count = (CountAndTimeStamp)tbl[obj]; + CountAndTimeStamp count = tbl[obj]; if (count != null) { if (count.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow) @@ -2172,9 +2153,7 @@ namespace Server.Mobiles } ++count.Count; - if (count.Count <= SkillCheck.Allowance) - return true; - return false; + return count.Count <= SkillCheck.Allowance; } tbl[obj] = count = new CountAndTimeStamp(); @@ -2239,7 +2218,7 @@ namespace Server.Mobiles for (int i = 0; i < recipeCount; i++) { int r = reader.ReadInt(); - if (reader.ReadBool()) //Don't add in recipies which we haven't gotten or have been removed + if (reader.ReadBool()) //Don't add in recipes which we haven't gotten or have been removed m_AcquiredRecipes.Add(r, true); } } @@ -2253,7 +2232,7 @@ namespace Server.Mobiles } case 23: { - m_ChampionTitles = new ChampionTitleInfo(reader); + ChampionTitles = new ChampionTitleInfo(reader); goto case 22; } case 22: @@ -2457,8 +2436,8 @@ namespace Server.Mobiles if (LastOnline == DateTime.MinValue && Account != null) LastOnline = ((Account)Account).LastLogin; - if (m_ChampionTitles == null) - m_ChampionTitles = new ChampionTitleInfo(); + if (ChampionTitles == null) + ChampionTitles = new ChampionTitleInfo(); if (AccessLevel > AccessLevel.Player) m_IgnoreMobiles = true; @@ -2481,15 +2460,13 @@ namespace Server.Mobiles public override void Serialize(GenericWriter writer) { //cleanup our anti-macro table - foreach (Hashtable t in m_AntiMacroTable.Values) + foreach (Dictionary t in m_AntiMacroTable.Values) { - ArrayList remove = new ArrayList(); - foreach (CountAndTimeStamp time in t.Values) - if (time.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow) - remove.Add(time); + List toRemove = t.Where(kvp => kvp.Value.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow) + .Select(kvp => kvp.Key).ToList(); - for (int i = 0; i < remove.Count; ++i) - t.Remove(remove[i]); + foreach (object key in toRemove) + t.Remove(key); } CheckKillDecay(); @@ -2506,7 +2483,8 @@ namespace Server.Mobiles writer.Write(m_StuckMenuUses.Length); - for (int i = 0; i < m_StuckMenuUses.Length; ++i) writer.Write(m_StuckMenuUses[i]); + for (int i = 0; i < m_StuckMenuUses.Length; ++i) + writer.Write(m_StuckMenuUses[i]); } else { @@ -2534,7 +2512,7 @@ namespace Server.Mobiles writer.WriteDeltaTime(LastHonorLoss); - ChampionTitleInfo.Serialize(writer, m_ChampionTitles); + ChampionTitleInfo.Serialize(writer, ChampionTitles); writer.Write(LastValorLoss); writer.WriteEncodedInt(ToTItemsTurnedIn); @@ -2680,12 +2658,8 @@ namespace Server.Mobiles public virtual void CheckedAnimate(int action, int frameCount, int repeatCount, bool forward, bool repeat, int delay) { - if (!Mounted) base.Animate(action, frameCount, repeatCount, forward, repeat, delay); - } - - public override void Animate(int action, int frameCount, int repeatCount, bool forward, bool repeat, int delay) - { - base.Animate(action, frameCount, repeatCount, forward, repeat, delay); + if (!Mounted) + base.Animate(action, frameCount, repeatCount, forward, repeat, delay); } public override bool CanSee(Item item) @@ -2891,7 +2865,7 @@ namespace Server.Mobiles { BaseCreature pet = AutoStabled[i] as BaseCreature; - if (pet == null || pet.Deleted) + if (pet?.Deleted == true) { pet.IsStabled = false; pet.StabledBy = null; @@ -2963,7 +2937,8 @@ namespace Server.Mobiles private void RemoveBlock(Mobile mobile) { - (mobile as PlayerMobile).m_MountBlock = null; + if (mobile is PlayerMobile pm) + pm.m_MountBlock = null; } } @@ -3191,47 +3166,47 @@ namespace Server.Mobiles public void RecoverAmmo() { - if (Core.SE && Alive) - { - foreach (KeyValuePair kvp in RecoverableAmmo) - if (kvp.Value > 0) + if (!Core.SE || !Alive) + return; + + foreach (KeyValuePair kvp in RecoverableAmmo) + if (kvp.Value > 0) + { + Item ammo = null; + + try { - Item ammo = null; - - try - { - ammo = Activator.CreateInstance(kvp.Key) as Item; - } - catch - { - } - - if (ammo != null) - { - string name = ammo.Name; - ammo.Amount = kvp.Value; - - if (name == null) - { - if (ammo is Arrow) - name = "arrow"; - else if (ammo is Bolt) - name = "bolt"; - } - - if (name != null && ammo.Amount > 1) - name = $"{name}s"; - - if (name == null) - name = $"#{ammo.LabelNumber}"; - - PlaceInBackpack(ammo); - SendLocalizedMessage(1073504, $"{ammo.Amount}\t{name}"); // You recover ~1_NUM~ ~2_AMMO~. - } + ammo = Activator.CreateInstance(kvp.Key) as Item; + } + catch + { + // ignored } - RecoverableAmmo.Clear(); - } + if (ammo == null) + continue; + string name = ammo.Name; + ammo.Amount = kvp.Value; + + if (name == null) + { + if (ammo is Arrow) + name = "arrow"; + else if (ammo is Bolt) + name = "bolt"; + } + + if (name != null && ammo.Amount > 1) + name = $"{name}s"; + + if (name == null) + name = $"#{ammo.LabelNumber}"; + + PlaceInBackpack(ammo); + SendLocalizedMessage(1073504, $"{ammo.Amount}\t{name}"); // You recover ~1_NUM~ ~2_AMMO~. + } + + RecoverableAmmo.Clear(); } #endregion @@ -3456,7 +3431,7 @@ namespace Server.Mobiles if (Core.SE) { - if (!HasGump(typeof(CancelRenewInventoryInsuranceGump))) + if (!HasGump()) SendGump(new CancelRenewInventoryInsuranceGump(this, null)); } else @@ -3532,7 +3507,7 @@ namespace Server.Mobiles // TODO: Investigate item sorting - CloseGump(typeof(ItemInsuranceMenuGump)); + CloseGump(); if (items.Count == 0) SendLocalizedMessage(1114915, "", 0x35); // None of your current items meet the requirements for insurance. @@ -3664,7 +3639,7 @@ namespace Server.Mobiles { if (m_From.AutoRenewInsurance) { - if (!m_From.HasGump(typeof(CancelRenewInventoryInsuranceGump))) + if (!m_From.HasGump()) m_From.SendGump(new CancelRenewInventoryInsuranceGump(m_From, this)); } else @@ -3778,9 +3753,9 @@ namespace Server.Mobiles private void ToggleQuestItemTarget() { BaseQuestGump.CloseOtherGumps(this); - CloseGump(typeof(QuestLogDetailedGump)); - CloseGump(typeof(QuestLogGump)); - CloseGump(typeof(QuestOfferGump)); + CloseGump(); + CloseGump(); + CloseGump(); //CloseGump( typeof( UnknownGump802 ) ); //CloseGump( typeof( UnknownGump804 ) ); @@ -3897,7 +3872,7 @@ namespace Server.Mobiles get => m_DuelPlayer; set { - bool wasInTourny = DuelContext != null && !DuelContext.Finished && DuelContext.m_Tournament != null; + bool wasInTourney = DuelContext != null && !DuelContext.Finished && DuelContext.m_Tournament != null; m_DuelPlayer = value; @@ -3906,9 +3881,9 @@ namespace Server.Mobiles else DuelContext = m_DuelPlayer.Participant.Context; - bool isInTourny = DuelContext != null && !DuelContext.Finished && DuelContext.m_Tournament != null; + bool isInTourney = DuelContext != null && !DuelContext.Finished && DuelContext.m_Tournament != null; - if (wasInTourny != isInTourny) + if (wasInTourney != isInTourney) SendEverything(); } } @@ -4362,7 +4337,7 @@ namespace Server.Mobiles public bool YoungDeathTeleport() { - if (Region.IsPartOf(typeof(Jail)) + if (Region.IsPartOf() || Region.IsPartOf("Samurai start location") || Region.IsPartOf("Ninja start location") || Region.IsPartOf("Ninja cave")) @@ -4371,7 +4346,7 @@ namespace Server.Mobiles Point3D loc; Map map; - DungeonRegion dungeon = (DungeonRegion)Region.GetRegion(typeof(DungeonRegion)); + DungeonRegion dungeon = Region.GetRegion(); if (dungeon != null && dungeon.EntranceLocation != Point3D.Zero) { loc = dungeon.EntranceLocation; @@ -4451,14 +4426,8 @@ namespace Server.Mobiles set => SetFlag(PlayerFlag.DisplayChampionTitle, value); } - private ChampionTitleInfo m_ChampionTitles; - [CommandProperty(AccessLevel.GameMaster)] - public ChampionTitleInfo ChampionTitles - { - get => m_ChampionTitles; - set { } - } + public ChampionTitleInfo ChampionTitles{ get; private set; } private void ToggleChampionTitleDisplay() { @@ -4687,7 +4656,7 @@ namespace Server.Mobiles public static void CheckAtrophy(PlayerMobile pm) { - ChampionTitleInfo t = pm.m_ChampionTitles; + ChampionTitleInfo t = pm.ChampionTitles; if (t == null) return; @@ -4702,7 +4671,7 @@ namespace Server.Mobiles public static void AwardHarrowerTitle(PlayerMobile pm) //Called when killing a harrower. Will give a minimum of 1 point. { - ChampionTitleInfo t = pm.m_ChampionTitles; + ChampionTitleInfo t = pm.ChampionTitles; if (t == null) return; @@ -4871,4 +4840,4 @@ namespace Server.Mobiles #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Special/Barracoon.cs b/Scripts/Mobiles/Special/Barracoon.cs index 9927f0ce5..b86537ccb 100644 --- a/Scripts/Mobiles/Special/Barracoon.cs +++ b/Scripts/Mobiles/Special/Barracoon.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Server.Engines.CannedEvil; using Server.Items; using Server.Spells.Fifth; @@ -91,7 +92,7 @@ namespace Server.Mobiles public void Polymorph(Mobile m) { - if (!m.CanBeginAction(typeof(PolymorphSpell)) || !m.CanBeginAction(typeof(IncognitoSpell)) || m.IsBodyMod) + if (!m.CanBeginAction() || !m.CanBeginAction() || m.IsBodyMod) return; IMount mount = m.Mount; @@ -102,7 +103,7 @@ namespace Server.Mobiles if (m.Mounted) return; - if (m.BeginAction(typeof(PolymorphSpell))) + if (m.BeginAction()) { Item disarm = m.FindItemOnLayer(Layer.OneHanded); @@ -128,58 +129,38 @@ namespace Server.Mobiles if (map == null) return; - int rats = 0; + IPooledEnumerable eable = GetMobilesInRange(10); + int rats = eable.Aggregate(0, (c, m) => c + (m is Ratman || m is RatmanArcher || m is RatmanMage ? 1 : 0)); + eable.Free(); - foreach (Mobile m in GetMobilesInRange(10)) - if (m is Ratman || m is RatmanArcher || m is RatmanMage) - ++rats; + if (rats >= 16) + return; - if (rats < 16) + PlaySound(0x3D); + + rats = Utility.RandomMinMax(3, 6); + + for (int i = 0; i < rats; ++i) { - PlaySound(0x3D); + BaseCreature rat; - int newRats = Utility.RandomMinMax(3, 6); - - for (int i = 0; i < newRats; ++i) + switch (Utility.Random(5)) { - BaseCreature rat; - - switch (Utility.Random(5)) - { - default: - case 0: - case 1: - rat = new Ratman(); - break; - case 2: - case 3: - rat = new RatmanArcher(); - break; - case 4: - rat = new RatmanMage(); - break; - } - - rat.Team = Team; - - bool validLocation = false; - Point3D loc = Location; - - for (int j = 0; !validLocation && j < 10; ++j) - { - int x = X + Utility.Random(3) - 1; - int y = Y + Utility.Random(3) - 1; - int z = map.GetAverageZ(x, y); - - if (validLocation = map.CanFit(x, y, Z, 16, false, false)) - loc = new Point3D(x, y, Z); - else if (validLocation = map.CanFit(x, y, z, 16, false, false)) - loc = new Point3D(x, y, z); - } - - rat.MoveToWorld(loc, map); - rat.Combatant = target; + default: + rat = new Ratman(); + break; + case 2: + case 3: + rat = new RatmanArcher(); + break; + case 4: + rat = new RatmanMage(); + break; } + + rat.Team = Team; + rat.MoveToWorld(map.GetRandomNearbyLocation(Location), map); + rat.Combatant = target; } } @@ -187,6 +168,7 @@ namespace Server.Mobiles { if (target == null || target.Deleted) //sanity return; + if (0.6 >= Utility.RandomDouble()) // 60% chance to polymorph attacker into a ratman Polymorph(target); @@ -238,13 +220,13 @@ namespace Server.Mobiles protected override void OnTick() { - if (!m_Owner.CanBeginAction(typeof(PolymorphSpell))) + if (!m_Owner.CanBeginAction()) { m_Owner.BodyMod = 0; m_Owner.HueMod = -1; - m_Owner.EndAction(typeof(PolymorphSpell)); + m_Owner.EndAction(); } } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Special/BaseShieldGuard.cs b/Scripts/Mobiles/Special/BaseShieldGuard.cs index 1b5f7a07d..ad9d4a1b1 100644 --- a/Scripts/Mobiles/Special/BaseShieldGuard.cs +++ b/Scripts/Mobiles/Special/BaseShieldGuard.cs @@ -12,7 +12,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { @@ -80,11 +80,11 @@ namespace Server.Mobiles PackGold(250, 500); - Skills[SkillName.Anatomy].Base = 120.0; - Skills[SkillName.Tactics].Base = 120.0; - Skills[SkillName.Swords].Base = 120.0; - Skills[SkillName.MagicResist].Base = 120.0; - Skills[SkillName.DetectHidden].Base = 100.0; + Skills.Anatomy.Base = 120.0; + Skills.Tactics.Base = 120.0; + Skills.Swords.Base = 120.0; + Skills.MagicResist.Base = 120.0; + Skills.DetectHidden.Base = 100.0; } public BaseShieldGuard(Serial serial) : base(serial) diff --git a/Scripts/Mobiles/Special/Dummy.cs b/Scripts/Mobiles/Special/Dummy.cs index 2458b248d..a18848ea3 100644 --- a/Scripts/Mobiles/Special/Dummy.cs +++ b/Scripts/Mobiles/Special/Dummy.cs @@ -20,10 +20,10 @@ namespace Server.Mobiles double dPassiveSpeed) : base(iAI, iFightMode, iRangePerception, iRangeFight, dActiveSpeed, dPassiveSpeed) { Body = 400 + Utility.Random(2); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); - Skills[SkillName.DetectHidden].Base = 100; - Skills[SkillName.MagicResist].Base = 120; + Skills.DetectHidden.Base = 100; + Skills.MagicResist.Base = 120; Team = Utility.Random(3); diff --git a/Scripts/Mobiles/Special/DummySpecific.cs b/Scripts/Mobiles/Special/DummySpecific.cs index 2e9e2eaaf..3771a4c43 100644 --- a/Scripts/Mobiles/Special/DummySpecific.cs +++ b/Scripts/Mobiles/Special/DummySpecific.cs @@ -23,10 +23,10 @@ namespace Server.Mobiles // Skills and Stats InitStats(125, 125, 90); - Skills[SkillName.Macing].Base = 120; - Skills[SkillName.Anatomy].Base = 120; - Skills[SkillName.Healing].Base = 120; - Skills[SkillName.Tactics].Base = 120; + Skills.Macing.Base = 120; + Skills.Anatomy.Base = 120; + Skills.Healing.Base = 120; + Skills.Tactics.Base = 120; // Equip WarHammer war = new WarHammer(); @@ -96,10 +96,10 @@ namespace Server.Mobiles // Skills and Stats InitStats(125, 125, 90); - Skills[SkillName.Fencing].Base = 120; - Skills[SkillName.Anatomy].Base = 120; - Skills[SkillName.Healing].Base = 120; - Skills[SkillName.Tactics].Base = 120; + Skills.Fencing.Base = 120; + Skills.Anatomy.Base = 120; + Skills.Healing.Base = 120; + Skills.Tactics.Base = 120; // Equip Spear ssp = new Spear(); @@ -170,11 +170,11 @@ namespace Server.Mobiles // Skills and Stats InitStats(125, 125, 90); - Skills[SkillName.Swords].Base = 120; - Skills[SkillName.Anatomy].Base = 120; - Skills[SkillName.Healing].Base = 120; - Skills[SkillName.Tactics].Base = 120; - Skills[SkillName.Parry].Base = 120; + Skills.Swords.Base = 120; + Skills.Anatomy.Base = 120; + Skills.Healing.Base = 120; + Skills.Tactics.Base = 120; + Skills.Parry.Base = 120; // Equip Katana kat = new Katana(); @@ -244,12 +244,12 @@ namespace Server.Mobiles // Skills and Stats InitStats(90, 90, 125); - Skills[SkillName.Magery].Base = 120; - Skills[SkillName.EvalInt].Base = 120; - Skills[SkillName.Inscribe].Base = 100; - Skills[SkillName.Wrestling].Base = 120; - Skills[SkillName.Meditation].Base = 120; - Skills[SkillName.Poisoning].Base = 100; + Skills.Magery.Base = 120; + Skills.EvalInt.Base = 120; + Skills.Inscribe.Base = 100; + Skills.Wrestling.Base = 120; + Skills.Meditation.Base = 120; + Skills.Poisoning.Base = 100; // Equip Spellbook book = new Spellbook(); @@ -311,12 +311,12 @@ namespace Server.Mobiles // Skills and Stats InitStats(90, 90, 125); - Skills[SkillName.Magery].Base = 100; - Skills[SkillName.EvalInt].Base = 120; - Skills[SkillName.Anatomy].Base = 80; - Skills[SkillName.Wrestling].Base = 80; - Skills[SkillName.Meditation].Base = 100; - Skills[SkillName.Poisoning].Base = 100; + Skills.Magery.Base = 100; + Skills.EvalInt.Base = 120; + Skills.Anatomy.Base = 80; + Skills.Wrestling.Base = 80; + Skills.Meditation.Base = 100; + Skills.Poisoning.Base = 100; // Equip Spellbook book = new Spellbook(); @@ -401,13 +401,13 @@ namespace Server.Mobiles // Skills and Stats InitStats(125, 125, 125); - Skills[SkillName.Magery].Base = 120; - Skills[SkillName.EvalInt].Base = 120; - Skills[SkillName.Anatomy].Base = 120; - Skills[SkillName.Wrestling].Base = 120; - Skills[SkillName.Meditation].Base = 120; - Skills[SkillName.Poisoning].Base = 100; - Skills[SkillName.Inscribe].Base = 100; + Skills.Magery.Base = 120; + Skills.EvalInt.Base = 120; + Skills.Anatomy.Base = 120; + Skills.Wrestling.Base = 120; + Skills.Meditation.Base = 120; + Skills.Poisoning.Base = 100; + Skills.Inscribe.Base = 100; // Equip Spellbook book = new Spellbook(); @@ -497,12 +497,12 @@ namespace Server.Mobiles // Skills and Stats InitStats(125, 125, 125); - Skills[SkillName.Magery].Base = 120; - Skills[SkillName.EvalInt].Base = 120; - Skills[SkillName.Anatomy].Base = 120; - Skills[SkillName.Wrestling].Base = 120; - Skills[SkillName.Meditation].Base = 120; - Skills[SkillName.Healing].Base = 100; + Skills.Magery.Base = 120; + Skills.EvalInt.Base = 120; + Skills.Anatomy.Base = 120; + Skills.Wrestling.Base = 120; + Skills.Meditation.Base = 120; + Skills.Healing.Base = 100; // Equip Spellbook book = new Spellbook(); @@ -585,12 +585,12 @@ namespace Server.Mobiles // Skills and Stats InitStats(105, 105, 105); - Skills[SkillName.Magery].Base = 120; - Skills[SkillName.EvalInt].Base = 120; - Skills[SkillName.Swords].Base = 120; - Skills[SkillName.Tactics].Base = 120; - Skills[SkillName.Meditation].Base = 120; - Skills[SkillName.Poisoning].Base = 100; + Skills.Magery.Base = 120; + Skills.EvalInt.Base = 120; + Skills.Swords.Base = 120; + Skills.Tactics.Base = 120; + Skills.Meditation.Base = 120; + Skills.Poisoning.Base = 100; // Equip Spellbook book = new Spellbook(); @@ -702,12 +702,12 @@ namespace Server.Mobiles // Skills and Stats InitStats(105, 105, 105); - Skills[SkillName.Healing].Base = 120; - Skills[SkillName.Anatomy].Base = 120; - Skills[SkillName.Stealing].Base = 120; - Skills[SkillName.ArmsLore].Base = 100; - Skills[SkillName.Meditation].Base = 120; - Skills[SkillName.Wrestling].Base = 120; + Skills.Healing.Base = 120; + Skills.Anatomy.Base = 120; + Skills.Stealing.Base = 120; + Skills.ArmsLore.Base = 100; + Skills.Meditation.Base = 120; + Skills.Wrestling.Base = 120; // Equip Spellbook book = new Spellbook(); diff --git a/Scripts/Mobiles/Special/Harrower.cs b/Scripts/Mobiles/Special/Harrower.cs index a715ac21d..0d0e9d33c 100644 --- a/Scripts/Mobiles/Special/Harrower.cs +++ b/Scripts/Mobiles/Special/Harrower.cs @@ -93,7 +93,7 @@ namespace Server.Mobiles public Type[] SharedList => new[] { typeof(TheRobeOfBritanniaAri) }; public Type[] DecorativeList => new[] { typeof(EvilIdolSkull), typeof(SkullPole) }; - public static ArrayList Instances{ get; } = new ArrayList(); + public static List Instances{ get; } = new List(); public static bool CanSpawn => Instances.Count == 0; @@ -184,9 +184,7 @@ namespace Server.Mobiles if (!ok) continue; - HarrowerTentacles spawn = new HarrowerTentacles(this); - - spawn.Team = Team; + HarrowerTentacles spawn = new HarrowerTentacles(this) { Team = Team }; spawn.MoveToWorld(new Point3D(x, y, z), map); @@ -653,4 +651,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Special/HarrowerTentacles.cs b/Scripts/Mobiles/Special/HarrowerTentacles.cs index d7e03aaa6..46d800b89 100644 --- a/Scripts/Mobiles/Special/HarrowerTentacles.cs +++ b/Scripts/Mobiles/Special/HarrowerTentacles.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Mobiles { @@ -140,7 +141,6 @@ namespace Server.Mobiles public override void OnAfterDelete() { m_Timer?.Stop(); - m_Timer = null; base.OnAfterDelete(); @@ -148,7 +148,6 @@ namespace Server.Mobiles private class DrainTimer : Timer { - private static ArrayList m_ToDrain = new ArrayList(); private HarrowerTentacles m_Owner; public DrainTimer(HarrowerTentacles owner) : base(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(5.0)) @@ -165,24 +164,16 @@ namespace Server.Mobiles return; } - foreach (Mobile m in m_Owner.GetMobilesInRange(9)) + IPooledEnumerable eable = m_Owner.GetMobilesInRange(9); + + foreach (Mobile m in eable) { - if (m == m_Owner || m == m_Owner.Harrower || !m_Owner.CanBeHarmful(m)) + if (m == m_Owner || !(m_Owner.CanBeHarmful(m) || m.Player && m.Alive)) continue; - if (m is BaseCreature bc) - { - if (bc.Controlled || bc.Summoned) - m_ToDrain.Add(m); - } - else if (m.Player) - { - m_ToDrain.Add(m); - } - } + if (!(m is BaseCreature bc) || !(bc.Controlled || bc.Summoned || bc.Team != m_Owner.Team)) + continue; - foreach (Mobile m in m_ToDrain) - { m_Owner.DoHarmful(m); m.FixedParticles(0x374A, 10, 15, 5013, 0x455, 0, EffectLayer.Waist); @@ -198,8 +189,8 @@ namespace Server.Mobiles m.Damage(drain, m_Owner); } - m_ToDrain.Clear(); + eable.Free(); } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Special/LordOaks.cs b/Scripts/Mobiles/Special/LordOaks.cs index fc8f8cad4..39562f3f5 100644 --- a/Scripts/Mobiles/Special/LordOaks.cs +++ b/Scripts/Mobiles/Special/LordOaks.cs @@ -6,7 +6,7 @@ namespace Server.Mobiles { public class LordOaks : BaseChampion { - private Mobile m_Queen; + private BaseCreature m_Queen; private bool m_SpawnedQueen; [Constructible] @@ -102,27 +102,9 @@ namespace Server.Mobiles for (int i = 0; i < newPixies; ++i) { - Pixie pixie = new Pixie(); + Pixie pixie = new Pixie { Team = Team, FightMode = FightMode.Closest }; - pixie.Team = Team; - pixie.FightMode = FightMode.Closest; - - bool validLocation = false; - Point3D loc = Location; - - for (int j = 0; !validLocation && j < 10; ++j) - { - int x = X + Utility.Random(3) - 1; - int y = Y + Utility.Random(3) - 1; - int z = map.GetAverageZ(x, y); - - if (validLocation = map.CanFit(x, y, Z, 16, false, false)) - loc = new Point3D(x, y, Z); - else if (validLocation = map.CanFit(x, y, z, 16, false, false)) - loc = new Point3D(x, y, z); - } - - pixie.MoveToWorld(loc, map); + pixie.MoveToWorld(map.GetRandomNearbyLocation(Location), map); pixie.Combatant = target; } } @@ -161,18 +143,13 @@ namespace Server.Mobiles { Say(1042153); // Come forth my queen! - m_Queen = new Silvani(); - - ((BaseCreature)m_Queen).Team = Team; - + m_Queen = new Silvani { Team = Team }; m_Queen.MoveToWorld(Location, Map); m_SpawnedQueen = true; } - else if (m_Queen != null && m_Queen.Deleted) - { + else if (m_Queen?.Deleted != false) m_Queen = null; - } } public override void AlterDamageScalarFrom(Mobile caster, ref double scalar) @@ -231,7 +208,7 @@ namespace Server.Mobiles { case 0: { - m_Queen = reader.ReadMobile(); + m_Queen = reader.ReadMobile(); m_SpawnedQueen = reader.ReadBool(); break; @@ -239,4 +216,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Special/Neira.cs b/Scripts/Mobiles/Special/Neira.cs index 68751dfcc..b85f0c149 100644 --- a/Scripts/Mobiles/Special/Neira.cs +++ b/Scripts/Mobiles/Special/Neira.cs @@ -214,7 +214,7 @@ namespace Server.Mobiles m_Item = item; } - public Mobile Rider + Mobile IMount.Rider { get => m_Item.Rider; set { } diff --git a/Scripts/Mobiles/Special/Rikktor.cs b/Scripts/Mobiles/Special/Rikktor.cs index 6c56b769d..1e763eae4 100644 --- a/Scripts/Mobiles/Special/Rikktor.cs +++ b/Scripts/Mobiles/Special/Rikktor.cs @@ -95,25 +95,17 @@ namespace Server.Mobiles if (map == null) return; - ArrayList targets = new ArrayList(); - - foreach (Mobile m in GetMobilesInRange(8)) - { - if (m == this || !CanBeHarmful(m)) - continue; - - if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || - creature.Team != Team)) - targets.Add(m); - else if (m.Player) - targets.Add(m); - } - PlaySound(0x2F3); - for (int i = 0; i < targets.Count; ++i) + IPooledEnumerable eable = GetMobilesInRange(8); + + foreach (Mobile m in eable) { - Mobile m = (Mobile)targets[i]; + if (m == this || !(CanBeHarmful(m) || m.Player && m.Alive)) + continue; + + if (!(m is BaseCreature bc) || !(bc.Controlled || bc.Summoned || bc.Team != Team)) + continue; double damage = m.Hits * 0.6; @@ -129,6 +121,8 @@ namespace Server.Mobiles if (m.Alive && m.Body.IsHuman && !m.Mounted) m.Animate(20, 7, 1, true, false, 0); // take hit } + + eable.Free(); } public override int GetAngerSound() @@ -170,4 +164,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Special/Semidar.cs b/Scripts/Mobiles/Special/Semidar.cs index 81cd07a75..178b16f7e 100644 --- a/Scripts/Mobiles/Special/Semidar.cs +++ b/Scripts/Mobiles/Special/Semidar.cs @@ -87,22 +87,16 @@ namespace Server.Mobiles if (Map == null) return; - ArrayList list = new ArrayList(); + IPooledEnumerable eable = GetMobilesInRange(2); - foreach (Mobile m in GetMobilesInRange(2)) + foreach (Mobile m in eable) { - if (m == this || !CanBeHarmful(m)) + if (m == this || !(CanBeHarmful(m) || m.Player && m.Alive)) continue; - if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || - creature.Team != Team)) - list.Add(m); - else if (m.Player) - list.Add(m); - } + if (!(m is BaseCreature bc) || !(bc.Controlled || bc.Summoned || bc.Team != Team)) + continue; - foreach (Mobile m in list) - { DoHarmful(m); m.FixedParticles(0x374A, 10, 15, 5013, 0x496, 0, EffectLayer.Waist); @@ -115,6 +109,8 @@ namespace Server.Mobiles Hits += toDrain; m.Damage(toDrain, this); } + + eable.Free(); } public override void OnGaveMeleeAttack(Mobile defender) @@ -145,4 +141,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Special/Serado.cs b/Scripts/Mobiles/Special/Serado.cs index 2d3f755a8..42fbb5be5 100644 --- a/Scripts/Mobiles/Special/Serado.cs +++ b/Scripts/Mobiles/Special/Serado.cs @@ -128,42 +128,37 @@ namespace Server.Mobiles if (!(0.2 > Utility.RandomDouble())) return; - BaseCreature bc = attacker as BaseCreature; + Mobile target = null; + + if (attacker is BaseCreature bcAttacker) + { + if (bcAttacker.BardProvoked) + return; + + target = bcAttacker.GetMaster(); + } - if (bc?.BardProvoked == true) - return; - /* Counterattack with Hit Poison Area - * 20-25 damage, unresistable - * Lethal poison, 100% of the time - * Particle effect: Type: "2" From: "0x4061A107" To: "0x0" ItemId: "0x36BD" ItemIdName: "explosion" FromLocation: "(296 615, 17)" ToLocation: "(296 615, 17)" Speed: "1" Duration: "10" FixedDirection: "True" Explode: "False" Hue: "0xA6" RenderMode: "0x0" Effect: "0x1F78" ExplodeEffect: "0x1" ExplodeSound: "0x0" Serial: "0x4061A107" Layer: "255" Unknown: "0x0" - * Doesn't work on provoked monsters - */ + * 20-25 damage, unresistable + * Lethal poison, 100% of the time + * Particle effect: Type: "2" From: "0x4061A107" To: "0x0" ItemId: "0x36BD" ItemIdName: "explosion" FromLocation: "(296 615, 17)" ToLocation: "(296 615, 17)" Speed: "1" Duration: "10" FixedDirection: "True" Explode: "False" Hue: "0xA6" RenderMode: "0x0" Effect: "0x1F78" ExplodeEffect: "0x1" ExplodeSound: "0x0" Serial: "0x4061A107" Layer: "255" Unknown: "0x0" + * Doesn't work on provoked monsters + */ - Mobile target = bc?.GetMaster(); - - if (target == null || !target.InRange(this, 25)) + if (target?.InRange(this, 25) != true) target = attacker; Animate(10, 4, 1, true, false, 0); - ArrayList targets = new ArrayList(); + IPooledEnumerable eable = target.GetMobilesInRange(8); - foreach (Mobile m in target.GetMobilesInRange(8)) + foreach (Mobile m in eable) { - if (m == this || !CanBeHarmful(m)) + if (m == this || !(CanBeHarmful(m) || m.Player && m.Alive)) continue; - if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || - creature.Team != Team)) - targets.Add(m); - else if (m.Player) - targets.Add(m); - } - - for (int i = 0; i < targets.Count; ++i) - { - Mobile m = (Mobile)targets[i]; + if (!(m is BaseCreature bc) || !(bc.Controlled || bc.Summoned || bc.Team != Team)) + continue; DoHarmful(m); @@ -188,4 +183,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Special/Silvani.cs b/Scripts/Mobiles/Special/Silvani.cs index 5e3634923..b7312d9a2 100644 --- a/Scripts/Mobiles/Special/Silvani.cs +++ b/Scripts/Mobiles/Special/Silvani.cs @@ -67,27 +67,9 @@ namespace Server.Mobiles for (int i = 0; i < newPixies; ++i) { - Pixie pixie = new Pixie(); + Pixie pixie = new Pixie { Team = Team, FightMode = FightMode.Closest }; - pixie.Team = Team; - pixie.FightMode = FightMode.Closest; - - bool validLocation = false; - Point3D loc = Location; - - for (int j = 0; !validLocation && j < 10; ++j) - { - int x = X + Utility.Random(3) - 1; - int y = Y + Utility.Random(3) - 1; - int z = map.GetAverageZ(x, y); - - if (validLocation = map.CanFit(x, y, Z, 16, false, false)) - loc = new Point3D(x, y, Z); - else if (validLocation = map.CanFit(x, y, z, 16, false, false)) - loc = new Point3D(x, y, z); - } - - pixie.MoveToWorld(loc, map); + pixie.MoveToWorld(map.GetRandomNearbyLocation(Location), map); pixie.Combatant = target; } } @@ -129,4 +111,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Townfolk/Actor.cs b/Scripts/Mobiles/Townfolk/Actor.cs index 5c09e680a..06943f779 100644 --- a/Scripts/Mobiles/Townfolk/Actor.cs +++ b/Scripts/Mobiles/Townfolk/Actor.cs @@ -11,7 +11,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { diff --git a/Scripts/Mobiles/Townfolk/Artist.cs b/Scripts/Mobiles/Townfolk/Artist.cs index 4e038873a..15c6fc29d 100644 --- a/Scripts/Mobiles/Townfolk/Artist.cs +++ b/Scripts/Mobiles/Townfolk/Artist.cs @@ -15,7 +15,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); Title = "the artist"; - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) diff --git a/Scripts/Mobiles/Townfolk/BaseEscortable.cs b/Scripts/Mobiles/Townfolk/BaseEscortable.cs index 4dea0636e..e73cdccc6 100644 --- a/Scripts/Mobiles/Townfolk/BaseEscortable.cs +++ b/Scripts/Mobiles/Townfolk/BaseEscortable.cs @@ -127,7 +127,7 @@ namespace Server.Mobiles } } - public static Hashtable EscortTable{ get; } = new Hashtable(); + public static Dictionary EscortTable{ get; } = new Dictionary(); protected override List ConstructQuestList() { @@ -200,7 +200,7 @@ namespace Server.Mobiles SetDex(90, 100); SetInt(15, 25); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { @@ -263,9 +263,9 @@ namespace Server.Mobiles if (escorter != null || !m.Alive) return false; - BaseEscortable escortable = (BaseEscortable)EscortTable[m]; + BaseEscortable escortable = EscortTable[m]; - if (escortable != null && !escortable.Deleted && escortable.GetEscorter() == m) + if (escortable?.Deleted == false && escortable.GetEscorter() == m) { Say("I see you already have an escort."); return false; @@ -299,13 +299,7 @@ namespace Server.Mobiles public override bool HandlesOnSpeech(Mobile from) { - if (MLQuestSystem.Enabled) - return false; - - if (from.InRange(Location, 3)) - return true; - - return base.HandlesOnSpeech(from); + return !MLQuestSystem.Enabled && (from.InRange(Location, 3) || base.HandlesOnSpeech(from)); } public override void OnSpeech(SpeechEventArgs e) @@ -454,10 +448,7 @@ namespace Server.Mobiles m_Destination = null; m_DestinationString = null; - Container cont = escorter.Backpack; - - if (cont == null) - cont = escorter.BankBox; + Container cont = escorter.Backpack ?? escorter.BankBox; Gold gold = new Gold(500, 1000); @@ -589,7 +580,7 @@ namespace Server.Mobiles } if (escorter == from) - list.Add(new AbandonEscortEntry(this, from)); + list.Add(new AbandonEscortEntry(this)); } base.AddCustomContextEntries(from, list); @@ -597,9 +588,7 @@ namespace Server.Mobiles public virtual string[] GetPossibleDestinations() { - if (!Core.ML) - return m_TownNames; - return m_MLTownNames; + return Core.ML ? m_MLTownNames : m_TownNames; } public virtual string PickRandomDestination() @@ -660,24 +649,18 @@ namespace Server.Mobiles public class EscortDestinationInfo { - private static Hashtable m_Table; + private static Dictionary m_Table; public EscortDestinationInfo(string name, Region region) { Name = name; Region = region; } - //private Rectangle2D[] m_Bounds; public string Name{ get; } public Region Region{ get; } - /*public Rectangle2D[] Bounds - { - get{ return m_Bounds; } - }*/ - public bool Contains(Point3D p) { return Region.Contains(p); @@ -690,7 +673,7 @@ namespace Server.Mobiles if (list.Count == 0) return; - m_Table = new Hashtable(); + m_Table = new Dictionary(); foreach (Region r in list) { @@ -710,7 +693,7 @@ namespace Server.Mobiles if (name == null || m_Table == null) return null; - return (EscortDestinationInfo)m_Table[name]; + return m_Table[name]; } } @@ -752,14 +735,12 @@ namespace Server.Mobiles public class AbandonEscortEntry : ContextMenuEntry { - private Mobile m_From; private BaseEscortable m_Mobile; - public AbandonEscortEntry(BaseEscortable m, Mobile from) + public AbandonEscortEntry(BaseEscortable m) : base(6102, 3) { m_Mobile = m; - m_From = from; } public override void OnClick() @@ -767,4 +748,4 @@ namespace Server.Mobiles m_Mobile.Delete(); // OSI just seems to delete instantly } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Townfolk/Gypsy.cs b/Scripts/Mobiles/Townfolk/Gypsy.cs index 3f2f7f78a..f51a40281 100644 --- a/Scripts/Mobiles/Townfolk/Gypsy.cs +++ b/Scripts/Mobiles/Townfolk/Gypsy.cs @@ -16,7 +16,7 @@ namespace Server.Mobiles SetSkill(SkillName.Snooping, 65, 88); SetSkill(SkillName.Stealing, 65, 88); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { diff --git a/Scripts/Mobiles/Townfolk/HarborMaster.cs b/Scripts/Mobiles/Townfolk/HarborMaster.cs index c5591e02b..63c76d857 100644 --- a/Scripts/Mobiles/Townfolk/HarborMaster.cs +++ b/Scripts/Mobiles/Townfolk/HarborMaster.cs @@ -14,7 +14,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); Blessed = true; diff --git a/Scripts/Mobiles/Townfolk/Messenger.cs b/Scripts/Mobiles/Townfolk/Messenger.cs index 0892a542b..99b8b8108 100644 --- a/Scripts/Mobiles/Townfolk/Messenger.cs +++ b/Scripts/Mobiles/Townfolk/Messenger.cs @@ -48,29 +48,10 @@ namespace Server.Mobiles else AddItem(new Shoes(lowHue)); - //if ( !Female ) - //AddItem( new BodySash( lowHue ) ); + int randomHair = Utility.Random(4); + HairItemID = randomHair == 4 ? 0x203B : 0x2048 + randomHair; - //AddItem( new Cloak( GetRandomHue() ) ); - - //if ( !Female ) - //AddItem( new Longsword() ); - - switch (Utility.Random(4)) - { - case 0: - AddItem(new ShortHair(Utility.RandomHairHue())); - break; - case 1: - AddItem(new TwoPigTails(Utility.RandomHairHue())); - break; - case 2: - AddItem(new ReceedingHair(Utility.RandomHairHue())); - break; - case 3: - AddItem(new KrisnaHair(Utility.RandomHairHue())); - break; - } + HairHue = Race.RandomHairHue(); PackGold(200, 250); } diff --git a/Scripts/Mobiles/Townfolk/Ninja.cs b/Scripts/Mobiles/Townfolk/Ninja.cs index 38f9857c6..acec694c9 100644 --- a/Scripts/Mobiles/Townfolk/Ninja.cs +++ b/Scripts/Mobiles/Townfolk/Ninja.cs @@ -20,7 +20,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { diff --git a/Scripts/Mobiles/Townfolk/Samurai.cs b/Scripts/Mobiles/Townfolk/Samurai.cs index 4bed07153..751d459bb 100644 --- a/Scripts/Mobiles/Townfolk/Samurai.cs +++ b/Scripts/Mobiles/Townfolk/Samurai.cs @@ -18,7 +18,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { diff --git a/Scripts/Mobiles/Townfolk/Sculptor.cs b/Scripts/Mobiles/Townfolk/Sculptor.cs index 95743bf31..4bec4fcfa 100644 --- a/Scripts/Mobiles/Townfolk/Sculptor.cs +++ b/Scripts/Mobiles/Townfolk/Sculptor.cs @@ -12,7 +12,7 @@ namespace Server.Mobiles SpeechHue = Utility.RandomDyedHue(); Title = "the sculptor"; - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = Utility.RandomBool()) { diff --git a/Scripts/Mobiles/Townfolk/TownCrier.cs b/Scripts/Mobiles/Townfolk/TownCrier.cs index f5290d338..d0702845a 100644 --- a/Scripts/Mobiles/Townfolk/TownCrier.cs +++ b/Scripts/Mobiles/Townfolk/TownCrier.cs @@ -131,9 +131,7 @@ namespace Server.Mobiles public override void OnResponse(Mobile from, string text) { - TimeSpan ts; - - if (!TimeSpan.TryParse(text, out ts)) + if (!TimeSpan.TryParse(text, out TimeSpan ts)) { from.SendMessage("Value was not properly formatted. Use: "); from.SendGump(new TownCrierGump(from, m_Owner)); @@ -211,7 +209,7 @@ namespace Server.Mobiles m_From = from; m_Owner = owner; - from.CloseGump(typeof(TownCrierGump)); + from.CloseGump(); AddPage(0); @@ -319,7 +317,7 @@ namespace Server.Mobiles InitStats(100, 100, 25); Title = "the town crier"; - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (!Core.AOS) NameHue = 0x35; @@ -461,29 +459,24 @@ namespace Server.Mobiles } else if (m_NewsTimer == null) { + int index = 0; m_NewsTimer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(3.0), - new TimerStateCallback(ShoutNews_Callback), new object[] { tce, 0 }); + () => ShoutNews_Callback(tce, index)); PublicOverheadMessage(MessageType.Regular, 0x3B2, 502976); // Hear ye! Hear ye! } } - private void ShoutNews_Callback(object state) + private void ShoutNews_Callback(TownCrierEntry tce, int index) { - object[] states = (object[])state; - TownCrierEntry tce = (TownCrierEntry)states[0]; - int index = (int)states[1]; - if (index < 0 || index >= tce.Lines.Length) { m_NewsTimer?.Stop(); - m_NewsTimer = null; } else { PublicOverheadMessage(MessageType.Regular, 0x3B2, false, tce.Lines[index]); - states[1] = index + 1; } } @@ -514,8 +507,9 @@ namespace Server.Mobiles } else { + int index = 0; m_NewsTimer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(3.0), - new TimerStateCallback(ShoutNews_Callback), new object[] { tce, 0 }); + () => ShoutNews_Callback(tce, index)); PublicOverheadMessage(MessageType.Regular, 0x3B2, 502978); // Some of the latest news! } diff --git a/Scripts/Mobiles/Vendors/BaseVendor.cs b/Scripts/Mobiles/Vendors/BaseVendor.cs index 2a44cb85a..dbe765f30 100644 --- a/Scripts/Mobiles/Vendors/BaseVendor.cs +++ b/Scripts/Mobiles/Vendors/BaseVendor.cs @@ -27,8 +27,8 @@ namespace Server.Mobiles private static TimeSpan InventoryDecayTime = TimeSpan.FromHours(1.0); - private ArrayList m_ArmorBuyInfo = new ArrayList(); - private ArrayList m_ArmorSellInfo = new ArrayList(); + private List m_ArmorBuyInfo = new List(); + private List m_ArmorSellInfo = new List(); public BaseVendor(string title) : base(AIType.AI_Vendor, FightMode.None, 2, 1, 0.5, 2) @@ -39,18 +39,11 @@ namespace Server.Mobiles InitBody(); InitOutfit(); - Container pack; //these packs MUST exist, or the client will crash when the packets are sent - pack = new Backpack(); - pack.Layer = Layer.ShopBuy; - pack.Movable = false; - pack.Visible = false; + Container pack = new Backpack { Layer = Layer.ShopBuy, Movable = false, Visible = false }; AddItem(pack); - pack = new Backpack(); - pack.Layer = Layer.ShopResale; - pack.Movable = false; - pack.Visible = false; + pack = new Backpack { Layer = Layer.ShopResale, Movable = false, Visible = false }; AddItem(pack); LastRestock = DateTime.UtcNow; @@ -133,8 +126,7 @@ namespace Server.Mobiles IShopSellInfo[] info = GetSellInfo(); int totalCost = 0; List validBuy = new List(list.Count); - Container cont; - bool bought = false; + bool bought; bool fromBank = false; bool fullPurchase = true; int controlSlots = buyer.FollowersMax - buyer.Followers; @@ -199,7 +191,7 @@ namespace Server.Mobiles bought = buyer.AccessLevel >= AccessLevel.GameMaster; - cont = buyer.Backpack; + Container cont = buyer.Backpack; if (!bought && cont != null) { if (cont.ConsumeTotal(typeof(Gold), totalCost)) @@ -211,7 +203,7 @@ namespace Server.Mobiles if (!bought && totalCost >= 2000) { cont = buyer.FindBankNoCreate(); - if (cont != null && cont.ConsumeTotal(typeof(Gold), totalCost)) + if (cont?.ConsumeTotal(typeof(Gold), totalCost) == true) { bought = true; fromBank = true; @@ -268,10 +260,7 @@ namespace Server.Mobiles } else { - buyItem = LiftItemDupe(item, item.Amount - amount); - - if (buyItem == null) - buyItem = item; + buyItem = LiftItemDupe(item, item.Amount - amount) ?? item; } if (cont == null || !cont.TryDropItem(buyer, buyItem, false)) @@ -345,7 +334,6 @@ namespace Server.Mobiles IBuyItemInfo[] buyInfo = GetBuyInfo(); int GiveGold = 0; int Sold = 0; - Container cont; foreach (SellItemResponse resp in list) { @@ -398,7 +386,7 @@ namespace Server.Mobiles if (!found) { - cont = BuyPack; + Container cont = BuyPack; if (amount < resp.Item.Amount) { @@ -522,7 +510,7 @@ namespace Server.Mobiles InitStats(100, 100, 25); SpeechHue = Utility.RandomDyedHue(); - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); if (Female = GetGender()) { @@ -551,10 +539,7 @@ namespace Server.Mobiles public virtual int GetShoeHue() { - if (0.1 > Utility.RandomDouble()) - return 0; - - return Utility.RandomNeutralHue(); + return 0.1 > Utility.RandomDouble() ? 0 : Utility.RandomNeutralHue(); } public virtual void CheckMorph() @@ -573,12 +558,7 @@ namespace Server.Mobiles if (Map != Map.Tokuno) return false; - NameList n; - - if (Female) - n = NameList.GetNameList("tokuno female"); - else - n = NameList.GetNameList("tokuno male"); + NameList n = NameList.GetNameList(Female ? "tokuno female" : "tokuno male"); if (!n.ContainsName(Name)) TurnToTokuno(); @@ -588,10 +568,7 @@ namespace Server.Mobiles public virtual void TurnToTokuno() { - if (Female) - Name = NameList.RandomName("tokuno female"); - else - Name = NameList.RandomName("tokuno male"); + Name = NameList.RandomName(Female ? "tokuno female" : "tokuno male"); } public virtual bool CheckGargoyle() @@ -655,10 +632,7 @@ namespace Server.Mobiles for (int i = 0; i < Items.Count; ++i) { Item item = Items[i]; - - if (item is Hair || item is Beard) - item.Hue = 0; - else if (item is BaseClothing || item is BaseWeapon || item is BaseArmor || item is BaseTool) + if (item is BaseClothing || item is BaseWeapon || item is BaseArmor || item is BaseTool) item.Hue = GetRandomNecromancerHue(); } @@ -674,7 +648,7 @@ namespace Server.Mobiles { Item item = Items[i]; - if (item is BaseClothing || item is Hair || item is Beard) + if (item is BaseClothing) item.Delete(); } @@ -713,7 +687,7 @@ namespace Server.Mobiles public virtual int GetHairHue() { - return Utility.RandomHairHue(); + return Race.RandomHairHue(); } public virtual void InitOutfit() @@ -801,15 +775,13 @@ namespace Server.Mobiles UpdateBuyInfo(); - int count = 0; - List list; IBuyItemInfo[] buyInfo = GetBuyInfo(); IShopSellInfo[] sellInfo = GetSellInfo(); - list = new List(buyInfo.Length); + List list = new List(buyInfo.Length); Container cont = BuyPack; - List opls = null; + List opls = new List(); for (int idx = 0; idx < buyInfo.Length; idx++) { @@ -818,19 +790,18 @@ namespace Server.Mobiles if (buyItem.Amount <= 0 || list.Count >= 250) continue; - // NOTE: Only GBI supported; if you use another implementation of IBuyItemInfo, this will crash - GenericBuyInfo gbi = (GenericBuyInfo)buyItem; + if (!(buyItem is GenericBuyInfo gbi)) + return; + IEntity disp = gbi.GetDisplayEntity(); list.Add(new BuyItemState(buyItem.Name, cont.Serial, disp?.Serial ?? (Serial)0x7FC0FFEE, buyItem.Price, buyItem.Amount, buyItem.ItemID, buyItem.Hue)); - count++; - - if (opls == null) opls = new List(); if (disp is Item item) opls.Add(item.PropertyList); - else if (disp is Mobile mobile) opls.Add(mobile.PropertyList); + else if (disp is Mobile mobile) + opls.Add(mobile.PropertyList); } List playerItems = cont.Items; @@ -864,10 +835,6 @@ namespace Server.Mobiles if (name != null && list.Count < 250) { list.Add(new BuyItemState(name, cont.Serial, item.Serial, price, item.Amount, item.ItemID, item.Hue)); - count++; - - if (opls == null) opls = new List(); - opls.Add(item.PropertyList); } } @@ -876,37 +843,36 @@ namespace Server.Mobiles //if ( list.Count > 255 ) // Console.WriteLine( "Vendor Warning: Vendor {0} has more than 255 buy items, may cause client errors!", this ); - if (list.Count > 0) - { - list.Sort(new BuyItemStateComparer()); + if (list.Count <= 0) + return; - SendPacksTo(from); + list.Sort(new BuyItemStateComparer()); - NetState ns = from.NetState; + SendPacksTo(from); - if (ns == null) - return; + NetState ns = from.NetState; - if (ns.ContainerGridLines) - from.Send(new VendorBuyContent6017(list)); - else - from.Send(new VendorBuyContent(list)); + if (ns == null) + return; - from.Send(new VendorBuyList(this, list)); + if (ns.ContainerGridLines) + from.Send(new VendorBuyContent6017(list)); + else + from.Send(new VendorBuyContent(list)); - if (ns.HighSeas) - from.Send(new DisplayBuyListHS(this)); - else - from.Send(new DisplayBuyList(this)); + from.Send(new VendorBuyList(this, list)); - from.Send(new MobileStatusExtended(from)); //make sure their gold amount is sent + if (ns.HighSeas) + from.Send(new DisplayBuyListHS(this)); + else + from.Send(new DisplayBuyList(this)); - if (opls != null) - for (int i = 0; i < opls.Count; ++i) - from.Send(opls[i]); + from.Send(new MobileStatusExtended(from)); //make sure their gold amount is sent - SayTo(from, 500186); // Greetings. Have a look around. - } + for (int i = 0; i < opls.Count; ++i) + from.Send(opls[i]); + + SayTo(from, 500186); // Greetings. Have a look around. } public virtual void SendPacksTo(Mobile from) @@ -915,10 +881,7 @@ namespace Server.Mobiles if (pack == null) { - pack = new Backpack(); - pack.Layer = Layer.ShopBuy; - pack.Movable = false; - pack.Visible = false; + pack = new Backpack { Layer = Layer.ShopBuy, Movable = false, Visible = false }; AddItem(pack); } @@ -933,10 +896,7 @@ namespace Server.Mobiles if (pack == null) { - pack = new Backpack(); - pack.Layer = Layer.ShopResale; - pack.Movable = false; - pack.Visible = false; + pack = new Backpack { Layer = Layer.ShopResale, Movable = false, Visible = false }; AddItem(pack); } @@ -959,36 +919,36 @@ namespace Server.Mobiles Container pack = from.Backpack; - if (pack != null) + if (pack == null) + return; + + IShopSellInfo[] info = GetSellInfo(); + + Dictionary table = new Dictionary(); + + foreach (IShopSellInfo ssi in info) { - IShopSellInfo[] info = GetSellInfo(); + Item[] items = pack.FindItemsByType(ssi.Types); - Dictionary table = new Dictionary(); - - foreach (IShopSellInfo ssi in info) + foreach (Item item in items) { - Item[] items = pack.FindItemsByType(ssi.Types); + if (item is Container container && container.Items.Count != 0) + continue; - foreach (Item item in items) - { - if (item is Container container && container.Items.Count != 0) - continue; - - if (item.IsStandardLoot() && item.Movable && ssi.IsSellable(item)) - table[item] = new SellItemState(item, ssi.GetSellPriceFor(item), ssi.GetNameFor(item)); - } + if (item.IsStandardLoot() && item.Movable && ssi.IsSellable(item)) + table[item] = new SellItemState(item, ssi.GetSellPriceFor(item), ssi.GetNameFor(item)); } + } - if (table.Count > 0) - { - SendPacksTo(from); + if (table.Count > 0) + { + SendPacksTo(from); - from.Send(new VendorSellList(this, table.Values)); - } - else - { - Say(true, "You have nothing I would be interested in."); - } + from.Send(new VendorSellList(this, table.Values)); + } + else + { + Say(true, "You have nothing I would be interested in."); } } @@ -1059,9 +1019,7 @@ namespace Server.Mobiles for (int i = 0; i < buyInfo.Length; ++i) { - GenericBuyInfo gbi = (GenericBuyInfo)buyInfo[i]; - - if (gbi.GetDisplayEntity() == obj) + if (buyInfo[i] is GenericBuyInfo gbi && gbi.GetDisplayEntity() == obj) return gbi; } @@ -1125,14 +1083,12 @@ namespace Server.Mobiles for (int i = 1; i < amount; i++) { - item = bii.GetEntity() as Item; - - if (item != null) + if (bii.GetEntity() is Item newItem) { - item.Amount = 1; + newItem.Amount = 1; - if (cont == null || !cont.TryDropItem(buyer, item, false)) - item.MoveToWorld(buyer.Location, buyer.Map); + if (cont == null || !cont.TryDropItem(buyer, newItem, false)) + newItem.MoveToWorld(buyer.Location, buyer.Map); } } } @@ -1151,19 +1107,15 @@ namespace Server.Mobiles for (int i = 1; i < amount; ++i) { - m = bii.GetEntity() as Mobile; - - if (m != null) + if (bii.GetEntity() is Mobile newMobile) { - m.Direction = (Direction)Utility.Random(8); - m.MoveToWorld(buyer.Location, buyer.Map); + newMobile.Direction = (Direction)Utility.Random(8); + newMobile.MoveToWorld(buyer.Location, buyer.Map); - bc = m as BaseCreature; - - if (bc != null) + if (newMobile is BaseCreature newBc) { - bc.SetControlMaster(buyer); - bc.ControlOrder = OrderType.Stop; + newBc.SetControlMaster(buyer); + newBc.ControlOrder = OrderType.Stop; } } } @@ -1172,20 +1124,8 @@ namespace Server.Mobiles public virtual bool CheckVendorAccess(Mobile from) { - GuardedRegion reg = (GuardedRegion)Region.GetRegion(typeof(GuardedRegion)); - - if (reg != null && !reg.CheckVendorAccess(this, from)) - return false; - - if (Region != from.Region) - { - reg = (GuardedRegion)from.Region.GetRegion(typeof(GuardedRegion)); - - if (reg != null && !reg.CheckVendorAccess(this, from)) - return false; - } - - return true; + return Region.GetRegion()?.CheckVendorAccess(this, from) != false || + Region != from.Region && from.Region.GetRegion()?.CheckVendorAccess(this, from) != false; } public override void Serialize(GenericWriter writer) @@ -1335,12 +1275,12 @@ namespace Server.Mobiles public virtual IShopSellInfo[] GetSellInfo() { - return (IShopSellInfo[])m_ArmorSellInfo.ToArray(typeof(IShopSellInfo)); + return m_ArmorSellInfo.ToArray(); } public virtual IBuyItemInfo[] GetBuyInfo() { - return (IBuyItemInfo[])m_ArmorBuyInfo.ToArray(typeof(IBuyItemInfo)); + return m_ArmorBuyInfo.ToArray(); } private class BulkOrderInfoEntry : ContextMenuEntry @@ -1401,21 +1341,14 @@ namespace Server.Mobiles public virtual int GetPriceScalar() { - Town town = Town.FromRegion(Region); - - if (town != null) - return 100 + town.Tax; - - return 100; + return 100 + Town.FromRegion(Region)?.Tax ?? 0; } public void UpdateBuyInfo() { int priceScalar = GetPriceScalar(); - IBuyItemInfo[] buyinfo = (IBuyItemInfo[])m_ArmorBuyInfo.ToArray(typeof(IBuyItemInfo)); - - foreach (IBuyItemInfo info in buyinfo) + foreach (IBuyItemInfo info in m_ArmorBuyInfo.ToArray()) info.PriceScalar = priceScalar; } @@ -1516,4 +1449,4 @@ namespace Server //called when its time for the whole shop to restock void OnRestock(); } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Vendors/GenericBuy.cs b/Scripts/Mobiles/Vendors/GenericBuy.cs index 90623ddfa..f32c2ffe6 100644 --- a/Scripts/Mobiles/Vendors/GenericBuy.cs +++ b/Scripts/Mobiles/Vendors/GenericBuy.cs @@ -11,22 +11,12 @@ namespace Server.Mobiles private int m_Price; - public GenericBuyInfo(Type type, int price, int amount, int itemID, int hue) : this(null, type, price, amount, - itemID, hue, null) - { - } - - public GenericBuyInfo(string name, Type type, int price, int amount, int itemID, int hue) : this(name, type, price, - amount, itemID, hue, null) - { - } - - public GenericBuyInfo(Type type, int price, int amount, int itemID, int hue, object[] args) : this(null, type, price, + public GenericBuyInfo(Type type, int price, int amount, int itemID, int hue, object[] args = null) : this(null, type, price, amount, itemID, hue, args) { } - public GenericBuyInfo(string name, Type type, int price, int amount, int itemID, int hue, object[] args) + public GenericBuyInfo(string name, Type type, int price, int amount, int itemID, int hue, object[] args = null) { Type = type; m_Price = price; @@ -35,14 +25,10 @@ namespace Server.Mobiles Hue = hue; Args = args; - if (name == null) - Name = itemID < 0x4000 ? (1020000 + itemID).ToString() : (1078872 + itemID).ToString(); - else - Name = name; + Name = name ?? (itemID < 0x4000 ? (1020000 + itemID).ToString() : (1078872 + itemID).ToString()); } - public virtual bool CanCacheDisplay //return ( m_Args == null || m_Args.Length == 0 ); } - => false; + public virtual bool CanCacheDisplay => false; public Type Type{ get; set; } @@ -315,4 +301,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs b/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs index 1160368fa..76c898f0e 100644 --- a/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs +++ b/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs @@ -59,9 +59,9 @@ namespace Server.Mobiles public static int GetMaxStabled(Mobile from) { - double taming = from.Skills[SkillName.AnimalTaming].Value; - double anlore = from.Skills[SkillName.AnimalLore].Value; - double vetern = from.Skills[SkillName.Veterinary].Value; + double taming = from.Skills.AnimalTaming.Value; + double anlore = from.Skills.AnimalLore.Value; + double vetern = from.Skills.Veterinary.Value; double sklsum = taming + anlore + vetern; int max; @@ -89,7 +89,7 @@ namespace Server.Mobiles private void CloseClaimList(Mobile from) { - from.CloseGump(typeof(ClaimListGump)); + from.CloseGump(); } public void BeginClaimList(Mobile from) @@ -407,7 +407,7 @@ namespace Server.Mobiles m_From = from; m_List = list; - from.CloseGump(typeof(ClaimListGump)); + from.CloseGump(); AddPage(0); diff --git a/Scripts/Mobiles/Vendors/NPC/Blacksmith.cs b/Scripts/Mobiles/Vendors/NPC/Blacksmith.cs index 8e288f5b3..4f45107a7 100644 --- a/Scripts/Mobiles/Vendors/NPC/Blacksmith.cs +++ b/Scripts/Mobiles/Vendors/NPC/Blacksmith.cs @@ -99,7 +99,7 @@ namespace Server.Mobiles { if (from is PlayerMobile pm && pm.NextSmithBulkOrder == TimeSpan.Zero && (fromContextMenu || 0.2 > Utility.RandomDouble())) { - double theirSkill = pm.Skills[SkillName.Blacksmith].Base; + double theirSkill = pm.Skills.Blacksmith.Base; if (theirSkill >= 70.1) pm.NextSmithBulkOrder = TimeSpan.FromHours(6.0); @@ -124,7 +124,7 @@ namespace Server.Mobiles public override bool SupportsBulkOrders(Mobile from) { - return from is PlayerMobile && from.Skills[SkillName.Blacksmith].Base > 0; + return from is PlayerMobile && from.Skills.Blacksmith.Base > 0; } public override TimeSpan GetNextBulkOrder(Mobile from) diff --git a/Scripts/Mobiles/Vendors/NPC/CustomHairstylist.cs b/Scripts/Mobiles/Vendors/NPC/CustomHairstylist.cs index c9f6af408..bc0f6648e 100644 --- a/Scripts/Mobiles/Vendors/NPC/CustomHairstylist.cs +++ b/Scripts/Mobiles/Vendors/NPC/CustomHairstylist.cs @@ -136,9 +136,9 @@ namespace Server.Mobiles m_Vendor = vendor; m_SellList = sellList; - from.CloseGump(typeof(HairstylistBuyGump)); - from.CloseGump(typeof(ChangeHairHueGump)); - from.CloseGump(typeof(ChangeHairstyleGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); bool isFemale = from.Female || from.Body.IsFemale; @@ -282,9 +282,9 @@ namespace Server.Mobiles m_FacialHair = facialHair; m_Entries = entries; - from.CloseGump(typeof(HairstylistBuyGump)); - from.CloseGump(typeof(ChangeHairHueGump)); - from.CloseGump(typeof(ChangeHairstyleGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); AddPage(0); @@ -434,9 +434,9 @@ namespace Server.Mobiles m_FacialHair = facialHair; m_Entries = entries; - from.CloseGump(typeof(HairstylistBuyGump)); - from.CloseGump(typeof(ChangeHairHueGump)); - from.CloseGump(typeof(ChangeHairstyleGump)); + from.CloseGump(); + from.CloseGump(); + from.CloseGump(); int tableWidth = m_FacialHair ? 2 : 3; int tableHeight = (entries.Length + tableWidth - (m_FacialHair ? 1 : 2)) / tableWidth; diff --git a/Scripts/Mobiles/Vendors/NPC/Guildmasters/ThiefGuildmaster.cs b/Scripts/Mobiles/Vendors/NPC/Guildmasters/ThiefGuildmaster.cs index a59c73020..a43b3c6db 100644 --- a/Scripts/Mobiles/Vendors/NPC/Guildmasters/ThiefGuildmaster.cs +++ b/Scripts/Mobiles/Vendors/NPC/Guildmasters/ThiefGuildmaster.cs @@ -51,7 +51,7 @@ namespace Server.Mobiles return false; } - if (pm.Skills[SkillName.Stealing].Base < 60.0) + if (pm.Skills.Stealing.Base < 60.0) { SayTo(pm, 501051); // You must be at least a journeyman pickpocket to join this elite organization. return false; diff --git a/Scripts/Mobiles/Vendors/NPC/Tailor.cs b/Scripts/Mobiles/Vendors/NPC/Tailor.cs index cbc637832..31bf9db4b 100644 --- a/Scripts/Mobiles/Vendors/NPC/Tailor.cs +++ b/Scripts/Mobiles/Vendors/NPC/Tailor.cs @@ -49,7 +49,7 @@ namespace Server.Mobiles { if (from is PlayerMobile pm && pm.NextTailorBulkOrder == TimeSpan.Zero && (fromContextMenu || 0.2 > Utility.RandomDouble())) { - double theirSkill = pm.Skills[SkillName.Tailoring].Base; + double theirSkill = pm.Skills.Tailoring.Base; if (theirSkill >= 70.1) pm.NextTailorBulkOrder = TimeSpan.FromHours(6.0); @@ -74,7 +74,7 @@ namespace Server.Mobiles public override bool SupportsBulkOrders(Mobile from) { - return from is PlayerMobile && from.Skills[SkillName.Tailoring].Base > 0; + return from is PlayerMobile && from.Skills.Tailoring.Base > 0; } public override TimeSpan GetNextBulkOrder(Mobile from) diff --git a/Scripts/Mobiles/Vendors/NPC/Weaponsmith.cs b/Scripts/Mobiles/Vendors/NPC/Weaponsmith.cs index 47a0445b4..11dee008c 100644 --- a/Scripts/Mobiles/Vendors/NPC/Weaponsmith.cs +++ b/Scripts/Mobiles/Vendors/NPC/Weaponsmith.cs @@ -68,7 +68,7 @@ namespace Server.Mobiles { if (from is PlayerMobile pm && pm.NextSmithBulkOrder == TimeSpan.Zero && (fromContextMenu || 0.2 > Utility.RandomDouble())) { - double theirSkill = pm.Skills[SkillName.Blacksmith].Base; + double theirSkill = pm.Skills.Blacksmith.Base; if (theirSkill >= 70.1) pm.NextSmithBulkOrder = TimeSpan.FromHours(6.0); @@ -93,7 +93,7 @@ namespace Server.Mobiles public override bool SupportsBulkOrders(Mobile from) { - return from is PlayerMobile && Core.AOS && from.Skills[SkillName.Blacksmith].Base > 0; + return from is PlayerMobile && Core.AOS && from.Skills.Blacksmith.Base > 0; } public override TimeSpan GetNextBulkOrder(Mobile from) diff --git a/Scripts/Mobiles/Vendors/NPC/Weaver.cs b/Scripts/Mobiles/Vendors/NPC/Weaver.cs index ba5c8f2d9..4fb4f4a1e 100644 --- a/Scripts/Mobiles/Vendors/NPC/Weaver.cs +++ b/Scripts/Mobiles/Vendors/NPC/Weaver.cs @@ -49,7 +49,7 @@ namespace Server.Mobiles { if (from is PlayerMobile pm && pm.NextTailorBulkOrder == TimeSpan.Zero && (fromContextMenu || 0.2 > Utility.RandomDouble())) { - double theirSkill = pm.Skills[SkillName.Tailoring].Base; + double theirSkill = pm.Skills.Tailoring.Base; if (theirSkill >= 70.1) pm.NextTailorBulkOrder = TimeSpan.FromHours(6.0); @@ -74,7 +74,7 @@ namespace Server.Mobiles public override bool SupportsBulkOrders(Mobile from) { - return from is PlayerMobile && from.Skills[SkillName.Tailoring].Base > 0; + return from is PlayerMobile && from.Skills.Tailoring.Base > 0; } public override TimeSpan GetNextBulkOrder(Mobile from) diff --git a/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs b/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs index 7a7c6dc65..b4bd87800 100644 --- a/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs +++ b/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs @@ -217,28 +217,19 @@ namespace Server.Mobiles public override bool HandlesOnSpeech(Mobile from) { - if (InRange(from, 3)) - return true; - - return base.HandlesOnSpeech(from); + return InRange(from, 3) || base.HandlesOnSpeech(from); } - private void ShoutNews_Callback(object state) + private void ShoutNews_Callback(TownCrierEntry tce, int index) { - object[] states = (object[])state; - TownCrierEntry tce = (TownCrierEntry)states[0]; - int index = (int)states[1]; - if (index < 0 || index >= tce.Lines.Length) { m_NewsTimer?.Stop(); - m_NewsTimer = null; } else { PublicOverheadMessage(MessageType.Regular, 0x3B2, false, tce.Lines[index]); - states[1] = index + 1; } } @@ -278,8 +269,9 @@ namespace Server.Mobiles } else { + int index = 0; m_NewsTimer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(3.0), - new TimerStateCallback(ShoutNews_Callback), new object[] { tce, 0 }); + () => ShoutNews_Callback(tce, index)); PublicOverheadMessage(MessageType.Regular, 0x3B2, 502978); // Some of the latest news! } @@ -456,7 +448,7 @@ namespace Server.Mobiles public void BeginChangeAppearance(Mobile from) { - from.CloseGump(typeof(PlayerVendorCustomizeGump)); + from.CloseGump(); from.SendGump(new PlayerVendorCustomizeGump(this, from)); } @@ -623,8 +615,8 @@ namespace Server.Mobiles m_From = from; m_Barkeeper = barkeeper; - from.CloseGump(typeof(BarkeeperGump)); - from.CloseGump(typeof(BarkeeperTitleGump)); + from.CloseGump(); + from.CloseGump(); Entry[] entries = m_Entries; @@ -767,8 +759,8 @@ namespace Server.Mobiles m_From = from; m_Barkeeper = barkeeper; - from.CloseGump(typeof(BarkeeperGump)); - from.CloseGump(typeof(BarkeeperTitleGump)); + from.CloseGump(); + from.CloseGump(); RenderBackground(); RenderCategories(); diff --git a/Scripts/Mobiles/Vendors/PlayerVendor.cs b/Scripts/Mobiles/Vendors/PlayerVendor.cs index 3a3da61ce..cfbe0d313 100644 --- a/Scripts/Mobiles/Vendors/PlayerVendor.cs +++ b/Scripts/Mobiles/Vendors/PlayerVendor.cs @@ -460,7 +460,7 @@ namespace Server.Mobiles if (version < 1) { m_ShopName = "Shop Not Yet Named"; - Timer.DelayCall(TimeSpan.Zero, new TimerStateCallback(UpgradeFromVersion0), newVendorSystemActivated); + Timer.DelayCall(TimeSpan.Zero, UpgradeFromVersion0, newVendorSystemActivated); } else { @@ -490,7 +490,7 @@ namespace Server.Mobiles NameHue = -1; } - private void UpgradeFromVersion0(object newVendorSystem) + private void UpgradeFromVersion0(bool newVendorSystem) { List toRemove = new List(); @@ -505,7 +505,7 @@ namespace Server.Mobiles House = BaseHouse.FindHouseAt(this); - if ((bool)newVendorSystem) + if (newVendorSystem) ActivateNewVendorSystem(); } @@ -519,7 +519,7 @@ namespace Server.Mobiles public void InitBody() { - Hue = Utility.RandomSkinHue(); + Hue = Race.Human.RandomSkinHue(); SpeechHue = 0x3B2; if (!Core.AOS) @@ -859,8 +859,7 @@ namespace Server.Mobiles if (IsOwner(from)) { if (GetVendorItem(item) == null) - Timer.DelayCall(TimeSpan.Zero, new TimerStateCallback(NonLocalDropCallback), - new object[] { from, item }); + Timer.DelayCall(TimeSpan.Zero, () => OnItemGiven(from, item)); return true; } @@ -869,31 +868,21 @@ namespace Server.Mobiles return false; } - private void NonLocalDropCallback(object state) - { - object[] aState = (object[])state; - - Mobile from = (Mobile)aState[0]; - Item item = (Item)aState[1]; - - OnItemGiven(from, item); - } - private void OnItemGiven(Mobile from, Item item) { VendorItem vi = GetVendorItem(item); - if (vi != null) - { - string name; - if (!string.IsNullOrEmpty(item.Name)) - name = item.Name; - else - name = "#" + item.LabelNumber; + if (vi == null) + return; - from.SendLocalizedMessage(1043303, name); // Type in a price and description for ~1_ITEM~ (ESC=not for sale) - from.Prompt = new VendorPricePrompt(this, vi); - } + string name; + if (!string.IsNullOrEmpty(item.Name)) + name = item.Name; + else + name = "#" + item.LabelNumber; + + from.SendLocalizedMessage(1043303, name); // Type in a price and description for ~1_ITEM~ (ESC=not for sale) + from.Prompt = new VendorPricePrompt(this, vi); } public override bool AllowEquipFrom(Mobile from) @@ -955,15 +944,15 @@ namespace Server.Mobiles { if (BaseHouse.NewVendorSystem) { - to.CloseGump(typeof(NewPlayerVendorOwnerGump)); - to.CloseGump(typeof(NewPlayerVendorCustomizeGump)); + to.CloseGump(); + to.CloseGump(); to.SendGump(new NewPlayerVendorOwnerGump(this)); } else { - to.CloseGump(typeof(PlayerVendorOwnerGump)); - to.CloseGump(typeof(PlayerVendorCustomizeGump)); + to.CloseGump(); + to.CloseGump(); to.SendGump(new PlayerVendorOwnerGump(this)); } @@ -1006,7 +995,7 @@ namespace Server.Mobiles } else { - from.CloseGump(typeof(PlayerVendorBuyGump)); + from.CloseGump(); from.SendGump(new PlayerVendorBuyGump(vendor, vi)); } } @@ -1606,4 +1595,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Vendors/RentedVendor.cs b/Scripts/Mobiles/Vendors/RentedVendor.cs index cc2111247..8222f05b1 100644 --- a/Scripts/Mobiles/Vendors/RentedVendor.cs +++ b/Scripts/Mobiles/Vendors/RentedVendor.cs @@ -118,8 +118,7 @@ namespace Server.Mobiles public void SendRentalExpireMessage(Mobile to) { - int days, hours; - ComputeRentalExpireDelay(out days, out hours); + ComputeRentalExpireDelay(out int days, out int hours); to.SendLocalizedMessage(1062464, days + "\t" + @@ -230,14 +229,14 @@ namespace Server.Mobiles if (m_Vendor.IsOwner(from)) { - from.CloseGump(typeof(RenterVendorRentalGump)); + from.CloseGump(); from.SendGump(new RenterVendorRentalGump(m_Vendor)); m_Vendor.SendRentalExpireMessage(from); } else if (m_Vendor.IsLandlord(from)) { - from.CloseGump(typeof(LandlordVendorRentalGump)); + from.CloseGump(); from.SendGump(new LandlordVendorRentalGump(m_Vendor)); m_Vendor.SendRentalExpireMessage(from); @@ -314,9 +313,7 @@ namespace Server.Mobiles text = text.Trim(); - int amount; - - if (!int.TryParse(text, out amount)) + if (!int.TryParse(text, out int amount)) amount = -1; Mobile owner = m_Vendor.Owner; @@ -340,7 +337,7 @@ namespace Server.Mobiles { from.SendLocalizedMessage(1062504); // Please wait while the renter considers your offer. - owner.CloseGump(typeof(VendorRentalRefundGump)); + owner.CloseGump(); owner.SendGump(new VendorRentalRefundGump(m_Vendor, from, amount)); } } diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index 681405edf..6047a0dea 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using Server.Accounting; using Server.ContextMenus; using Server.Ethics; @@ -46,18 +47,18 @@ namespace Server.Multis BuiltOn = DateTime.UtcNow; LastTraded = DateTime.MinValue; - Doors = new ArrayList(); - LockDowns = new ArrayList(); - Secures = new ArrayList(); - Addons = new ArrayList(); + Doors = new List(); + LockDowns = new List(); + Secures = new List(); + Addons = new List(); - CoOwners = new ArrayList(); - Friends = new ArrayList(); - Bans = new ArrayList(); - Access = new ArrayList(); + CoOwners = new List(); + Friends = new List(); + Bans = new List(); + Access = new List(); - VendorRentalContracts = new ArrayList(); - InternalizedVendors = new ArrayList(); + VendorRentalContracts = new List(); + InternalizedVendors = new List(); m_Owner = owner; @@ -356,15 +357,15 @@ namespace Server.Multis public int MaxLockDowns{ get; set; } public Region Region => m_Region; - public ArrayList CoOwners{ get; set; } + public List CoOwners{ get; set; } - public ArrayList Friends{ get; set; } + public List Friends{ get; set; } - public ArrayList Access{ get; set; } + public List Access{ get; set; } - public ArrayList Bans{ get; set; } + public List Bans{ get; set; } - public ArrayList Doors{ get; set; } + public List Doors{ get; set; } public int LockDownCount { @@ -377,7 +378,7 @@ namespace Server.Multis if (Secures != null) for (int i = 0; i < Secures.Count; ++i) { - SecureInfo info = (SecureInfo)Secures[i]; + SecureInfo info = Secures[i]; if (info.Item.Deleted) continue; @@ -400,7 +401,7 @@ namespace Server.Multis if (Secures != null) for (int i = 0; i < Secures.Count; i++) { - SecureInfo info = (SecureInfo)Secures[i]; + SecureInfo info = Secures[i]; if (info.Item.Deleted) continue; @@ -412,27 +413,27 @@ namespace Server.Multis } } - public ArrayList Addons{ get; set; } + public List Addons{ get; set; } - public ArrayList LockDowns{ get; private set; } + public List LockDowns{ get; private set; } - public ArrayList Secures{ get; private set; } + public List Secures{ get; private set; } public HouseSign Sign{ get; set; } - public ArrayList PlayerVendors{ get; } = new ArrayList(); + public List PlayerVendors{ get; } = new List(); - public ArrayList PlayerBarkeepers{ get; } = new ArrayList(); + public List PlayerBarkeepers{ get; } = new List(); - public ArrayList VendorRentalContracts{ get; private set; } + public List VendorRentalContracts{ get; private set; } - public ArrayList VendorInventories{ get; } = new ArrayList(); + public List VendorInventories{ get; } = new List(); - public ArrayList RelocatedEntities{ get; } = new ArrayList(); + public List RelocatedEntities{ get; } = new List(); public MovingCrate MovingCrate{ get; set; } - public ArrayList InternalizedVendors{ get; private set; } + public List InternalizedVendors{ get; private set; } public DateTime BuiltOn{ get; set; } @@ -513,14 +514,10 @@ namespace Server.Multis public virtual void KillVendors() { - ArrayList list = new ArrayList(PlayerVendors); - - foreach (PlayerVendor vendor in list) + foreach (PlayerVendor vendor in PlayerVendors.ToList()) vendor.Destroy(true); - list = new ArrayList(PlayerBarkeepers); - - foreach (PlayerBarkeeper barkeeper in list) + foreach (PlayerBarkeeper barkeeper in PlayerBarkeepers.ToList()) barkeeper.Delete(); } @@ -569,13 +566,13 @@ namespace Server.Multis fromLockdowns = 0; fromMovingCrate = 0; - ArrayList list = Secures; + List list = Secures; if (list != null) { for (int i = 0; i < list.Count; ++i) { - SecureInfo si = (SecureInfo)list[i]; + SecureInfo si = list[i]; fromSecures += si.Item.TotalItems; } @@ -667,9 +664,9 @@ namespace Server.Multis eable.Free(); } - public ArrayList AvailableVendorsFor(Mobile m) + public List AvailableVendorsFor(Mobile m) { - ArrayList list = new ArrayList(); + List list = new List(); foreach (PlayerVendor vendor in PlayerVendors) if (vendor.CanInteractWith(m, false)) @@ -811,7 +808,7 @@ namespace Server.Multis InternalizedVendors.Add(mobile); } - foreach (Mobile mobile in PlayerBarkeepers) + foreach (PlayerBarkeeper mobile in PlayerBarkeepers) { mobile.Internalize(); InternalizedVendors.Add(mobile); @@ -990,10 +987,11 @@ namespace Server.Multis m_Trash = null; LockDowns.Remove(item); - VendorRentalContracts.Remove(item); + if (item is VendorRentalContract contract) + VendorRentalContracts.Remove(contract); Addons.Remove(item); for (int i = Secures.Count - 1; i >= 0; i--) - if (((SecureInfo)Secures[i]).Item == item) + if (Secures[i].Item == item) Secures.RemoveAt(i); } else if (entity is Mobile mobile && !mobile.Deleted) @@ -1059,9 +1057,7 @@ namespace Server.Multis public virtual bool CheckAosStorage(int need) { - int fromSecures, fromVendors, fromLockdowns, fromMovingCrate; - - return GetAosCurSecures(out fromSecures, out fromVendors, out fromLockdowns, out fromMovingCrate) + need <= + return GetAosCurSecures(out int fromSecures, out int fromVendors, out int fromLockdowns, out int fromMovingCrate) + need <= GetAosMaxSecures(); } @@ -1317,7 +1313,7 @@ namespace Server.Multis for (int i = 0; i < Secures.Count; ++i) { - SecureInfo info = (SecureInfo)Secures[i]; + SecureInfo info = Secures[i]; if (info.Item == item) return HasSecureAccess(m, info.Level) ? SecureAccessResult.Accessible : SecureAccessResult.Inaccessible; @@ -1594,15 +1590,15 @@ namespace Server.Multis i.Movable = false; else i.Movable = !locked; - + i.IsLockedDown = locked; if (locked) { - if (i is VendorRentalContract) + if (i is VendorRentalContract contract) { - if (!VendorRentalContracts.Contains(i)) - VendorRentalContracts.Add(i); + if (!VendorRentalContracts.Contains(contract)) + VendorRentalContracts.Add(contract); } else { @@ -1612,7 +1608,8 @@ namespace Server.Multis } else { - VendorRentalContracts.Remove(i); + if (i is VendorRentalContract contract) + VendorRentalContracts.Remove(contract); LockDowns.Remove(i); } @@ -1756,11 +1753,11 @@ namespace Server.Multis * contract vendor in the house. */ to.SendGump( - new WarningGump(1060635, 30720, 1062487, 32512, 420, 280, ConfirmTransfer_Callback, from)); + new WarningGump(1060635, 30720, 1062487, 32512, 420, 280, okay => ConfirmTransfer_Callback(to, okay, from))); } else { - to.CloseGump(typeof(HouseTransferGump)); + to.CloseGump(); to.SendGump(new HouseTransferGump(from, to, this)); } } @@ -1771,16 +1768,14 @@ namespace Server.Multis } } - private void ConfirmTransfer_Callback(Mobile to, bool ok, object state) + private void ConfirmTransfer_Callback(Mobile to, bool ok, Mobile from) { - Mobile from = (Mobile)state; - if (!ok || Deleted || !from.CheckAlive() || !IsOwner(from)) return; if (CheckTransferPosition(from, to)) { - to.CloseGump(typeof(HouseTransferGump)); + to.CloseGump(); to.SendGump(new HouseTransferGump(from, to, this)); } } @@ -1891,12 +1886,12 @@ namespace Server.Multis SecureInfo info = null; for (int i = 0; info == null && i < Secures.Count; ++i) - if (((SecureInfo)Secures[i]).Item == item) - info = (SecureInfo)Secures[i]; + if (Secures[i].Item == item) + info = Secures[i]; if (info != null) { - m.CloseGump(typeof(SetSecureLevelGump)); + m.CloseGump(); m.SendGump(new SetSecureLevelGump(m_Owner, info, this)); } else if (item.Parent != null) @@ -1932,7 +1927,7 @@ namespace Server.Multis LockDowns.Remove(item); item.Movable = false; - m.CloseGump(typeof(SetSecureLevelGump)); + m.CloseGump(); m.SendGump(new SetSecureLevelGump(m_Owner, info, this)); } } @@ -1985,7 +1980,7 @@ namespace Server.Multis for (int i = 0; i < Secures.Count; ++i) { - SecureInfo info = (SecureInfo)Secures[i]; + SecureInfo info = Secures[i]; if (info.Item == item && HasSecureAccess(m, info.Level)) { @@ -2363,7 +2358,7 @@ namespace Server.Multis writer.WriteEncodedInt(VendorInventories.Count); for (int i = 0; i < VendorInventories.Count; i++) { - VendorInventory inventory = (VendorInventory)VendorInventories[i]; + VendorInventory inventory = VendorInventories[i]; inventory.Serialize(writer); } @@ -2384,7 +2379,7 @@ namespace Server.Multis writer.Write(Secures.Count); for (int i = 0; i < Secures.Count; ++i) - ((SecureInfo)Secures[i]).Serialize(writer); + Secures[i].Serialize(writer); writer.Write(m_Public); @@ -2416,7 +2411,7 @@ namespace Server.Multis // Items in locked down containers that aren't locked down themselves must decay! for (int i = 0; i < LockDowns.Count; ++i) { - Item item = (Item)LockDowns[i]; + Item item = LockDowns[i]; if (item is Container cont && !(cont is BaseBoard || cont is Aquarium || cont is FishBowl)) { @@ -2465,14 +2460,14 @@ namespace Server.Multis case 13: // removed ban location serialization case 12: { - VendorRentalContracts = reader.ReadItemList(); - InternalizedVendors = reader.ReadMobileList(); + VendorRentalContracts = reader.ReadStrongItemList(); + InternalizedVendors = reader.ReadStrongMobileList(); int relocatedCount = reader.ReadEncodedInt(); for (int i = 0; i < relocatedCount; i++) { Point3D relLocation = reader.ReadPoint3D(); - IEntity entity = World.FindEntity(reader.ReadInt()); + IEntity entity = World.FindEntity(reader.ReadUInt()); if (entity != null) RelocatedEntities.Add(new RelocatedEntity(entity, relLocation)); @@ -2506,7 +2501,7 @@ namespace Server.Multis } case 7: { - Access = reader.ReadMobileList(); + Access = reader.ReadStrongMobileList(); goto case 6; } case 6: @@ -2518,13 +2513,13 @@ namespace Server.Multis case 5: // just removed fields case 4: { - Addons = reader.ReadItemList(); + Addons = reader.ReadStrongItemList(); goto case 3; } case 3: { count = reader.ReadInt(); - Secures = new ArrayList(count); + Secures = new List(count); for (int i = 0; i < count; ++i) { @@ -2557,15 +2552,15 @@ namespace Server.Multis if (version < 12) { - VendorRentalContracts = new ArrayList(); - InternalizedVendors = new ArrayList(); + VendorRentalContracts = new List(); + InternalizedVendors = new List(); } if (version < 4) - Addons = new ArrayList(); + Addons = new List(); if (version < 7) - Access = new ArrayList(); + Access = new List(); if (version < 8) Price = DefaultPrice; @@ -2582,26 +2577,26 @@ namespace Server.Multis UpdateRegion(); - CoOwners = reader.ReadMobileList(); - Friends = reader.ReadMobileList(); - Bans = reader.ReadMobileList(); + CoOwners = reader.ReadStrongMobileList(); + Friends = reader.ReadStrongMobileList(); + Bans = reader.ReadStrongMobileList(); Sign = reader.ReadItem() as HouseSign; m_Trash = reader.ReadItem() as TrashBarrel; - Doors = reader.ReadItemList(); - LockDowns = reader.ReadItemList(); + Doors = reader.ReadStrongItemList(); + LockDowns = reader.ReadStrongItemList(); for (int i = 0; i < LockDowns.Count; ++i) - ((Item)LockDowns[i]).IsLockedDown = true; + LockDowns[i].IsLockedDown = true; for (int i = 0; i < VendorRentalContracts.Count; ++i) - ((Item)VendorRentalContracts[i]).IsLockedDown = true; + VendorRentalContracts[i].IsLockedDown = true; if (version < 3) { - ArrayList items = reader.ReadItemList(); - Secures = new ArrayList(items.Count); + List items = reader.ReadStrongItemList(); + Secures = new List(items.Count); for (int i = 0; i < items.Count; ++i) { @@ -2663,18 +2658,13 @@ namespace Server.Multis private void FixLockdowns_Sandbox() { - ArrayList lockDowns = new ArrayList(); + List conts = LockDowns?.Where(item => item is Container).ToList(); - for (int i = 0; LockDowns != null && i < LockDowns.Count; ++i) - { - Item item = (Item)LockDowns[i]; + if (conts == null) + return; - if (item is Container) - lockDowns.Add(item); - } - - for (int i = 0; i < lockDowns.Count; ++i) - SetLockdown((Item)lockDowns[i], true, true); + foreach (Item cont in conts) + SetLockdown(cont, true, true); } public static void HandleDeletion(Mobile mob) @@ -2726,9 +2716,9 @@ namespace Server.Multis if (LockDowns != null) for (int i = 0; i < LockDowns.Count; ++i) { - if (LockDowns[i] is Item) + if (LockDowns[i] != null) { - Item item = (Item)LockDowns[i]; + Item item = LockDowns[i]; if (!(item is Container)) count += item.TotalItems; @@ -2777,7 +2767,7 @@ namespace Server.Multis { for (int i = 0; i < Doors.Count; ++i) { - Item item = (Item)Doors[i]; + Item item = Doors[i]; item?.Delete(); } @@ -2789,7 +2779,7 @@ namespace Server.Multis { for (int i = 0; i < LockDowns.Count; ++i) { - Item item = (Item)LockDowns[i]; + Item item = LockDowns[i]; if (item != null) { @@ -2807,7 +2797,7 @@ namespace Server.Multis { for (int i = 0; i < VendorRentalContracts.Count; ++i) { - Item item = (Item)VendorRentalContracts[i]; + Item item = VendorRentalContracts[i]; if (item != null) { @@ -2825,7 +2815,7 @@ namespace Server.Multis { for (int i = 0; i < Secures.Count; ++i) { - SecureInfo info = (SecureInfo)Secures[i]; + SecureInfo info = Secures[i]; if (info.Item is StrongBox) { @@ -2847,7 +2837,7 @@ namespace Server.Multis { for (int i = 0; i < Addons.Count; ++i) { - Item item = (Item)Addons[i]; + Item item = Addons[i]; if (item != null) { @@ -2886,9 +2876,7 @@ namespace Server.Multis Addons.Clear(); } - ArrayList inventories = new ArrayList(VendorInventories); - - foreach (VendorInventory inventory in inventories) + foreach (VendorInventory inventory in VendorInventories.ToList()) inventory.Delete(); MovingCrate?.Delete(); @@ -3024,7 +3012,7 @@ namespace Server.Multis for (int i = 0; i < Bans.Count; ++i) { - Mobile c = (Mobile)Bans[i]; + Mobile c = Bans[i]; if (c == m) return true; @@ -3069,13 +3057,8 @@ namespace Server.Multis public bool HasLockedDownItem(Item check) { - if (check == null) - return false; - - if (LockDowns == null) - return false; - - return LockDowns.Contains(check) || VendorRentalContracts.Contains(check); + return check != null && LockDowns != null && + (LockDowns.Contains(check) || check is VendorRentalContract contract && VendorRentalContracts.Contains(contract)); } public bool HasSecureItem(Item item) @@ -3089,7 +3072,7 @@ namespace Server.Multis bool contains = false; for (int i = 0; !contains && i < Secures.Count; ++i) - contains = ((SecureInfo)Secures[i]).Item == item; + contains = Secures[i].Item == item; return contains; } @@ -3678,7 +3661,7 @@ namespace Server.Multis if (item is ISecurable securable) { - bool isOwned = house.Doors.Contains(item); + bool isOwned = item is BaseDoor door && house.Doors.Contains(door); if (!isOwned) isOwned = house is HouseFoundation foundation && foundation.IsFixture(item); @@ -3691,11 +3674,11 @@ namespace Server.Multis } else { - ArrayList list = house.Secures; + List list = house.Secures; for (int i = 0; sec == null && list != null && i < list.Count; ++i) { - SecureInfo si = (SecureInfo)list[i]; + SecureInfo si = list[i]; if (si.Item == item) sec = si; @@ -3719,7 +3702,7 @@ namespace Server.Multis if (sec != null) { - Owner.From.CloseGump(typeof(SetSecureLevelGump)); + Owner.From.CloseGump(); Owner.From.SendGump(new SetSecureLevelGump(Owner.From, sec, BaseHouse.FindHouseAt(m_Item))); } } @@ -3744,4 +3727,4 @@ namespace Server.Multis return from == m_RegionOwner || AccountHandler.CheckAccount(from, m_RegionOwner); } } -} \ No newline at end of file +} diff --git a/Scripts/Multis/Boats/BaseBoat.cs b/Scripts/Multis/Boats/BaseBoat.cs index 0abdd4d92..3acbbab08 100644 --- a/Scripts/Multis/Boats/BaseBoat.cs +++ b/Scripts/Multis/Boats/BaseBoat.cs @@ -1376,11 +1376,9 @@ namespace Server.Multis { Point2D dest = MapItem.Pins[NextNavPoint]; - int x, y; - MapItem.ConvertToWorld(dest.X, dest.Y, out x, out y); + MapItem.ConvertToWorld(dest.X, dest.Y, out int x, out int y); - int maxSpeed; - dir = GetMovementFor(x, y, out maxSpeed); + dir = GetMovementFor(x, y, out int maxSpeed); if (maxSpeed == 0) { diff --git a/Scripts/Multis/Boats/BaseBoatDeed.cs b/Scripts/Multis/Boats/BaseBoatDeed.cs index 5509ccf9b..b0ff5946f 100644 --- a/Scripts/Multis/Boats/BaseBoatDeed.cs +++ b/Scripts/Multis/Boats/BaseBoatDeed.cs @@ -103,7 +103,7 @@ namespace Server.Multis return; } - if (from.Region.IsPartOf(typeof(HouseRegion)) || BaseBoat.FindBoatAt(from, from.Map) != null) + if (from.Region.IsPartOf() || BaseBoat.FindBoatAt(from, from.Map) != null) { from.SendLocalizedMessage(1010568, null, 0x25); // You may not place a ship while on another ship or inside a house. @@ -162,9 +162,9 @@ namespace Server.Multis Region region = Region.Find(p, from.Map); - if (region.IsPartOf(typeof(DungeonRegion))) + if (region.IsPartOf()) from.SendLocalizedMessage(502488); // You can not place a ship inside a dungeon. - else if (region.IsPartOf(typeof(HouseRegion)) || region.IsPartOf(typeof(ChampionSpawnRegion))) + else if (region.IsPartOf() || region.IsPartOf()) from.SendLocalizedMessage(1042549); // A boat may not be placed in this area. else m_Deed.OnPlacement(from, p); diff --git a/Scripts/Multis/Boats/BaseDockedBoat.cs b/Scripts/Multis/Boats/BaseDockedBoat.cs index 3209e2061..47203eb43 100644 --- a/Scripts/Multis/Boats/BaseDockedBoat.cs +++ b/Scripts/Multis/Boats/BaseDockedBoat.cs @@ -181,9 +181,9 @@ namespace Server.Multis Region region = Region.Find(p, from.Map); - if (region.IsPartOf(typeof(DungeonRegion))) + if (region.IsPartOf()) from.SendLocalizedMessage(502488); // You can not place a ship inside a dungeon. - else if (region.IsPartOf(typeof(HouseRegion)) || region.IsPartOf(typeof(ChampionSpawnRegion))) + else if (region.IsPartOf() || region.IsPartOf()) from.SendLocalizedMessage(1042549); // A boat may not be placed in this area. else m_Model.OnPlacement(from, p); diff --git a/Scripts/Multis/Boats/ConfirmDryDockGump.cs b/Scripts/Multis/Boats/ConfirmDryDockGump.cs index 31d2a7330..eb638a6aa 100644 --- a/Scripts/Multis/Boats/ConfirmDryDockGump.cs +++ b/Scripts/Multis/Boats/ConfirmDryDockGump.cs @@ -13,7 +13,7 @@ namespace Server.Multis m_From = from; m_Boat = boat; - m_From.CloseGump(typeof(ConfirmDryDockGump)); + m_From.CloseGump(); AddPage(0); diff --git a/Scripts/Multis/Boats/Plank.cs b/Scripts/Multis/Boats/Plank.cs index e6f93013f..786b3fbf1 100644 --- a/Scripts/Multis/Boats/Plank.cs +++ b/Scripts/Multis/Boats/Plank.cs @@ -191,7 +191,7 @@ namespace Server.Items z = from.Z + j; if (map.CanFit(x, y, z, 16, false, false) && !SpellHelper.CheckMulti(new Point3D(x, y, z), map) && - !Region.Find(new Point3D(x, y, z), map).IsPartOf(typeof(StrongholdRegion))) + !Region.Find(new Point3D(x, y, z), map).IsPartOf()) { if (i == 1 && j >= -2 && j <= 2) return true; @@ -204,7 +204,7 @@ namespace Server.Items z = map.GetAverageZ(x, y); if (map.CanFit(x, y, z, 16, false, false) && !SpellHelper.CheckMulti(new Point3D(x, y, z), map) && - !Region.Find(new Point3D(x, y, z), map).IsPartOf(typeof(StrongholdRegion))) + !Region.Find(new Point3D(x, y, z), map).IsPartOf()) { if (i == 1) return true; diff --git a/Scripts/Multis/Deeds.cs b/Scripts/Multis/Deeds.cs index f79408640..2b22716c6 100644 --- a/Scripts/Multis/Deeds.cs +++ b/Scripts/Multis/Deeds.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using Server.Regions; using Server.Targeting; @@ -26,13 +27,13 @@ namespace Server.Multis.Deeds if (from.AccessLevel >= AccessLevel.GameMaster || reg.AllowHousing(from, p)) m_Deed.OnPlacement(from, p); - else if (reg.IsPartOf(typeof(TempNoHousingRegion))) + else if (reg.IsPartOf()) from.SendLocalizedMessage( 501270); // Lord British has decreed a 'no build' period, thus you cannot build this house at this time. - else if (reg.IsPartOf(typeof(TreasureRegion)) || reg.IsPartOf(typeof(HouseRegion))) + else if (reg.IsPartOf() || reg.IsPartOf()) from.SendLocalizedMessage( 1043287); // The house could not be created here. Either something is blocking the house, or the house would not be on valid terrain. - else if (reg.IsPartOf(typeof(HouseRaffleRegion))) + else if (reg.IsPartOf()) from.SendLocalizedMessage(1150493); // You must have a deed for this plot of land in order to build here. else from.SendLocalizedMessage(501265); // Housing can not be created in this area. @@ -138,7 +139,7 @@ namespace Server.Multis.Deeds else { Point3D center = new Point3D(p.X - Offset.X, p.Y - Offset.Y, p.Z - Offset.Z); - HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out ArrayList toMove); + HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out List toMove); switch (res) { @@ -876,4 +877,4 @@ namespace Server.Multis.Deeds int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Multis/HouseFoundation.cs b/Scripts/Multis/HouseFoundation.cs index 05ba2511c..dd946dce9 100644 --- a/Scripts/Multis/HouseFoundation.cs +++ b/Scripts/Multis/HouseFoundation.cs @@ -268,7 +268,7 @@ namespace Server.Multis { Item item = Fixtures[i]; - if (Doors.Contains(item)) + if (item is BaseDoor door && Doors.Contains(door)) continue; item.MoveToWorld(new Point3D(item.X + x, item.Y + y, item.Z + z), Map); @@ -301,8 +301,11 @@ namespace Server.Multis for (int i = 0; i < Fixtures.Count; ++i) { - Fixtures[i].Delete(); - Doors.Remove(Fixtures[i]); + Item item = Fixtures[i]; + item.Delete(); + + if (item is BaseDoor door) + Doors.Remove(door); } Fixtures.Clear(); @@ -1698,7 +1701,7 @@ namespace Server.Multis Mobile from = state.Mobile; DesignContext context = DesignContext.Find(from); - if (World.FindItem(pvSrc.ReadInt32()) is HouseFoundation foundation && from.Map == foundation.Map && from.InRange(foundation.GetWorldLocation(), 24) && + if (World.FindItem(pvSrc.ReadUInt32()) is HouseFoundation foundation && from.Map == foundation.Map && from.InRange(foundation.GetWorldLocation(), 24) && from.CanSee(foundation)) { DesignState stateToSend; @@ -2274,7 +2277,7 @@ namespace Server.Multis m_Thread.Start(); } - public DesignStateDetailed(int serial, int revision, int xMin, int yMin, int xMax, int yMax, MultiTileEntry[] tiles) + public DesignStateDetailed(uint serial, int revision, int xMin, int yMin, int xMax, int yMax, MultiTileEntry[] tiles) : base(0xD8) { EnsureCapacity(17 + tiles.Length * 5); @@ -2408,7 +2411,7 @@ namespace Server.Multis int planeCount = 0; - byte[] m_DeflatedBuffer = null; + byte[] m_DeflatedBuffer; lock (m_DeflatedBufferPool) { m_DeflatedBuffer = m_DeflatedBufferPool.AcquireBuffer(); @@ -2520,6 +2523,16 @@ namespace Server.Multis m_Stream.UnderlyingStream.Write(m_PrimBuffer, 0, 4); } + + public void Write(uint value) + { + m_PrimBuffer[0] = (byte)(value >> 24); + m_PrimBuffer[1] = (byte)(value >> 16); + m_PrimBuffer[2] = (byte)(value >> 8); + m_PrimBuffer[3] = (byte)value; + + m_Stream.UnderlyingStream.Write(m_PrimBuffer, 0, 4); + } public void Write(short value) { @@ -2633,7 +2646,8 @@ namespace Server.Multis { public NetState m_NetState; public DesignState m_Root; - public int m_Serial, m_Revision; + public int m_Revision; + public uint m_Serial; public MultiTileEntry[] m_Tiles; public int m_xMin, m_yMin, m_xMax, m_yMax; diff --git a/Scripts/Multis/HousePlacement.cs b/Scripts/Multis/HousePlacement.cs index 44d01e959..57ea43167 100644 --- a/Scripts/Multis/HousePlacement.cs +++ b/Scripts/Multis/HousePlacement.cs @@ -37,10 +37,10 @@ namespace Server.Multis 0x0150, 0x015C // Furrows }; - public static HousePlacementResult Check(Mobile from, int multiID, Point3D center, out ArrayList toMove) + public static HousePlacementResult Check(Mobile from, int multiID, Point3D center, out List toMove) { // If this spot is considered valid, every item and mobile in this list will be moved under the house sign - toMove = new ArrayList(); + toMove = new List(); Map map = from.Map; @@ -56,9 +56,7 @@ namespace Server.Multis if (map == Map.Malas && (multiID == 0x007C || multiID == 0x007E)) return HousePlacementResult.InvalidCastleKeep; - NoHousingRegion noHousingRegion = (NoHousingRegion)Region.Find(center, map).GetRegion(typeof(NoHousingRegion)); - - if (noHousingRegion != null) + if (Region.Find(center, map).IsPartOf()) return HousePlacementResult.BadRegion; // This holds data describing the internal structure of the house @@ -78,7 +76,7 @@ namespace Server.Multis List yard = new List(), borders = new List(); /* RULES: - * + * * 1) All tiles which are around the -outside- of the foundation must not have anything impassable. * 2) No impassable object or land tile may come in direct contact with any part of the house. * 3) Five tiles from the front and back of the house must be completely clear of all house tiles. @@ -103,13 +101,13 @@ namespace Server.Multis if (!reg.AllowHousing(from, testPoint)) // Cannot place houses in dungeons, towns, treasure map areas etc { - if (reg.IsPartOf(typeof(TempNoHousingRegion))) + if (reg.IsPartOf()) return HousePlacementResult.BadRegionTemp; - if (reg.IsPartOf(typeof(TreasureRegion)) || reg.IsPartOf(typeof(HouseRegion))) + if (reg.IsPartOf() || reg.IsPartOf()) return HousePlacementResult.BadRegionHidden; - if (reg.IsPartOf(typeof(HouseRaffleRegion))) + if (reg.IsPartOf()) return HousePlacementResult.BadRegionRaffle; return HousePlacementResult.BadRegion; @@ -362,4 +360,4 @@ namespace Server.Multis return HousePlacementResult.Valid; } } -} \ No newline at end of file +} diff --git a/Scripts/Multis/HousePlacementTool.cs b/Scripts/Multis/HousePlacementTool.cs index 728d897e7..f447a75f6 100644 --- a/Scripts/Multis/HousePlacementTool.cs +++ b/Scripts/Multis/HousePlacementTool.cs @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using Server.Gumps; using Server.Mobiles; using Server.Multis; @@ -60,8 +62,8 @@ namespace Server.Items { m_From = from; - from.CloseGump(typeof(HousePlacementCategoryGump)); - from.CloseGump(typeof(HousePlacementListGump)); + from.CloseGump(); + from.CloseGump(); AddPage(0); @@ -123,8 +125,8 @@ namespace Server.Items m_From = from; m_Entries = entries; - from.CloseGump(typeof(HousePlacementCategoryGump)); - from.CloseGump(typeof(HousePlacementListGump)); + from.CloseGump(); + from.CloseGump(); AddPage(0); @@ -245,13 +247,13 @@ namespace Server.Items if (from.AccessLevel >= AccessLevel.GameMaster || reg.AllowHousing(from, p)) m_Placed = m_Entry.OnPlacement(from, p); - else if (reg.IsPartOf(typeof(TempNoHousingRegion))) + else if (reg.IsPartOf()) from.SendLocalizedMessage( 501270); // Lord British has decreed a 'no build' period, thus you cannot build this house at this time. - else if (reg.IsPartOf(typeof(TreasureRegion)) || reg.IsPartOf(typeof(HouseRegion))) + else if (reg.IsPartOf() || reg.IsPartOf()) from.SendLocalizedMessage( 1043287); // The house could not be created here. Either something is blocking the house, or the house would not be on valid terrain. - else if (reg.IsPartOf(typeof(HouseRaffleRegion))) + else if (reg.IsPartOf()) from.SendLocalizedMessage(1150493); // You must have a deed for this plot of land in order to build here. else from.SendLocalizedMessage(501265); // Housing can not be created in this area. @@ -270,7 +272,7 @@ namespace Server.Items public class HousePlacementEntry { - private static Hashtable m_Table; + private static Dictionary m_Table; private int m_Lockdowns; private int m_NewLockdowns; private int m_NewStorage; @@ -278,7 +280,7 @@ namespace Server.Items static HousePlacementEntry() { - m_Table = new Hashtable(); + m_Table = new Dictionary(); FillTable(ClassicHouses); FillTable(TwoStoryFoundations); @@ -561,28 +563,27 @@ namespace Server.Items object[] args; if (Type == typeof(HouseFoundation)) - args = new object[4] { from, MultiID, m_Storage, m_Lockdowns }; + args = new object[] { from, MultiID, m_Storage, m_Lockdowns }; else if (Type == typeof(SmallOldHouse) || Type == typeof(SmallShop) || Type == typeof(TwoStoryHouse)) - args = new object[2] { from, MultiID }; + args = new object[] { from, MultiID }; else - args = new object[1] { from }; + args = new object[] { from }; return Activator.CreateInstance(Type, args) as BaseHouse; } catch { + // ignored } return null; } - public void PlacementWarning_Callback(Mobile from, bool okay, object state) + public void PlacementWarning_Callback(Mobile from, bool okay, PreviewHouse prevHouse) { if (!from.CheckAlive() || from.Backpack?.FindItemByType() == null) return; - PreviewHouse prevHouse = (PreviewHouse)state; - if (!okay) { prevHouse.Delete(); @@ -594,19 +595,17 @@ namespace Server.Items /* Too much time has passed and the test house you created has been deleted. * Please try again! */ - from.SendGump(new NoticeGump(1060637, 30720, 1060647, 32512, 320, 180, null, null)); + from.SendGump(new NoticeGump(1060637, 30720, 1060647, 32512, 320, 180)); return; } Point3D center = prevHouse.Location; - Map map = prevHouse.Map; prevHouse.Delete(); - ArrayList toMove; //Point3D center = new Point3D( p.X - m_Offset.X, p.Y - m_Offset.Y, p.Z - m_Offset.Z ); - HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out toMove); + HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out List toMove); switch (res) { @@ -653,10 +652,10 @@ namespace Server.Items { object o = toMove[i]; - if (o is Mobile) - ((Mobile)o).Location = house.BanLocation; - else if (o is Item) - ((Item)o).Location = house.BanLocation; + if (o is Mobile mobile) + mobile.Location = house.BanLocation; + else if (o is Item item) + item.Location = house.BanLocation; } } @@ -702,7 +701,7 @@ namespace Server.Items return false; Point3D center = new Point3D(p.X - Offset.X, p.Y - Offset.Y, p.Z - Offset.Z); - HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out ArrayList toMove); + HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out List toMove); switch (res) { @@ -739,10 +738,10 @@ namespace Server.Items { object o = toMove[i]; - if (o is Mobile) - ((Mobile)o).Location = banLoc; - else if (o is Item) - ((Item)o).Location = banLoc; + if (o is Mobile mobile) + mobile.Location = banLoc; + else if (o is Item item) + item.Location = banLoc; } prev.MoveToWorld(center, from.Map); @@ -759,8 +758,7 @@ namespace Server.Items * If you are absolutely certain you wish to proceed, click the button next to OKAY below. * If you do not wish to trade for this house, click CANCEL. */ - from.SendGump(new WarningGump(1060635, 30720, 1049583, 32512, 420, 280, PlacementWarning_Callback, - prev)); + from.SendGump(new WarningGump(1060635, 30720, 1049583, 32512, 420, 280, okay => PlacementWarning_Callback(from, okay, prev))); return true; } @@ -807,29 +805,16 @@ namespace Server.Items { object obj = m_Table[house.GetType()]; - if (obj is HousePlacementEntry) return (HousePlacementEntry)obj; + if (obj is HousePlacementEntry entry) + return entry; - if (obj is ArrayList) + if (obj is List list) { - ArrayList list = (ArrayList)obj; - - for (int i = 0; i < list.Count; ++i) - { - HousePlacementEntry e = (HousePlacementEntry)list[i]; - - if (e.MultiID == house.ItemID) - return e; - } + return list.FirstOrDefault(e => e.MultiID == house.ItemID); } - else if (obj is Hashtable) - { - Hashtable table = (Hashtable)obj; - obj = table[house.ItemID]; - - if (obj is HousePlacementEntry) - return (HousePlacementEntry)obj; - } + if (obj is Dictionary table) + return table[house.ItemID]; return null; } @@ -846,40 +831,33 @@ namespace Server.Items { m_Table[e.Type] = e; } - else if (obj is HousePlacementEntry) + else if (obj is HousePlacementEntry entry) { - ArrayList list = new ArrayList(); - - list.Add(obj); - list.Add(e); + List list = new List { entry, e }; m_Table[e.Type] = list; } - else if (obj is ArrayList) + else if (obj is List list) { - ArrayList list = (ArrayList)obj; - if (list.Count == 8) { - Hashtable table = new Hashtable(); + Dictionary table = new Dictionary(); - for (int j = 0; j < list.Count; ++j) - table[((HousePlacementEntry)list[j]).MultiID] = list[j]; + foreach (HousePlacementEntry t in list) + table[t.MultiID] = t; table[e.MultiID] = e; m_Table[e.Type] = table; } else - { list.Add(e); - } } - else if (obj is Hashtable) + else if (obj is Dictionary table) { - ((Hashtable)obj)[e.MultiID] = e; + table[e.MultiID] = e; } } } } -} \ No newline at end of file +} diff --git a/Scripts/Multis/HouseSign.cs b/Scripts/Multis/HouseSign.cs index 084ac5c8e..2e2530869 100644 --- a/Scripts/Multis/HouseSign.cs +++ b/Scripts/Multis/HouseSign.cs @@ -148,11 +148,11 @@ namespace Server.Multis } } - public void ClaimGump_Callback(Mobile from, bool okay, object state) + public void ClaimGump_Callback(Mobile from, bool okay) { if (okay && Owner != null && Owner.Owner == null && Owner.DecayLevel != DecayLevel.DemolitionPending) { - bool canClaim = false; + bool canClaim; if (Owner.CoOwners == null || Owner.CoOwners.Count == 0) canClaim = Owner.IsFriend(from); @@ -185,7 +185,7 @@ namespace Server.Multis canClaim = Owner.IsCoOwner(m); if (canClaim && !BaseHouse.HasAccountHouse(m)) - m.SendGump(new WarningGump(501036, 32512, 1049719, 32512, 420, 280, ClaimGump_Callback, null)); + m.SendGump(new WarningGump(501036, 32512, 1049719, 32512, 420, 280, okay => ClaimGump_Callback(m, okay))); } ShowSign(m); @@ -285,7 +285,7 @@ namespace Server.Multis } else { - from.CloseGump(typeof(VendorInventoryGump)); + from.CloseGump(); from.SendGump(new VendorInventoryGump(m_Sign.Owner, from)); } } diff --git a/Scripts/Multis/Houses.cs b/Scripts/Multis/Houses.cs index ebd9bd708..1e5556a81 100644 --- a/Scripts/Multis/Houses.cs +++ b/Scripts/Multis/Houses.cs @@ -568,8 +568,8 @@ namespace Server.Multis door.Locked = true; door.KeyValue = keyValue; - if (door is BaseHouseDoor) - ((BaseHouseDoor)door).Facing = DoorFacing.EastCCW; + if (door is BaseHouseDoor houseDoor) + houseDoor.Facing = DoorFacing.EastCCW; AddDoor(door, -2, 0, id == 0xA2 ? 24 : 27); diff --git a/Scripts/Regions/BaseRegion.cs b/Scripts/Regions/BaseRegion.cs index ceff32a5e..202157f6b 100644 --- a/Scripts/Regions/BaseRegion.cs +++ b/Scripts/Regions/BaseRegion.cs @@ -70,9 +70,7 @@ namespace Server.Regions foreach (XmlNode node in spawning.ChildNodes) { - XmlElement el = node as XmlElement; - - if (el != null) + if (node is XmlElement el) { SpawnDefinition def = SpawnDefinition.GetSpawnDefinition(el); if (def == null) diff --git a/Scripts/Regions/GuardedRegion.cs b/Scripts/Regions/GuardedRegion.cs index e143da72c..8fe734488 100644 --- a/Scripts/Regions/GuardedRegion.cs +++ b/Scripts/Regions/GuardedRegion.cs @@ -77,7 +77,7 @@ namespace Server.Regions private static void CheckGuarded_OnCommand(CommandEventArgs e) { Mobile from = e.Mobile; - GuardedRegion reg = (GuardedRegion)from.Region.GetRegion(typeof(GuardedRegion)); + GuardedRegion reg = from.Region.GetRegion(); if (reg == null) from.SendMessage("You are not in a guardable region."); @@ -95,7 +95,7 @@ namespace Server.Regions if (e.Length == 1) { - GuardedRegion reg = (GuardedRegion)from.Region.GetRegion(typeof(GuardedRegion)); + GuardedRegion reg = from.Region.GetRegion(); if (reg == null) { @@ -122,7 +122,7 @@ namespace Server.Regions private static void ToggleGuarded_OnCommand(CommandEventArgs e) { Mobile from = e.Mobile; - GuardedRegion reg = (GuardedRegion)from.Region.GetRegion(typeof(GuardedRegion)); + GuardedRegion reg = from.Region.GetRegion(); if (reg == null) { @@ -342,7 +342,7 @@ namespace Server.Regions public bool IsGuardCandidate(Mobile m) { if (m is BaseGuard || !m.Alive || m.AccessLevel > AccessLevel.Player || m.Blessed || - m is BaseCreature && ((BaseCreature)m).IsInvulnerable || IsDisabled()) + m is BaseCreature creature && creature.IsInvulnerable || IsDisabled()) return false; return !AllowReds && m.Kills >= 5 || m.Criminal; diff --git a/Scripts/Regions/HouseRegion.cs b/Scripts/Regions/HouseRegion.cs index 0ef94749c..1203e1d46 100644 --- a/Scripts/Regions/HouseRegion.cs +++ b/Scripts/Regions/HouseRegion.cs @@ -86,10 +86,12 @@ namespace Server.Regions m_Recursion = true; - if (m is BaseCreature && ((BaseCreature)m).NoHouseRestrictions) + BaseCreature bc = m as BaseCreature; + + if (bc?.NoHouseRestrictions == true) { } - else if (m is BaseCreature && ((BaseCreature)m).IsHouseSummonable && + else if (bc.IsHouseSummonable == true && !(BaseCreature.Summoning || House.IsInside(oldLocation, 16))) { } @@ -122,8 +124,8 @@ namespace Server.Regions if (House.InternalizedVendors.Count > 0 && House.IsInside(m) && !House.IsInside(oldLocation, 16) && House.IsOwner(m) && m.Alive && - !m.HasGump(typeof(NoticeGump))) - m.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180, null, null)); + !m.HasGump()) + m.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180)); m_Recursion = false; } @@ -133,20 +135,21 @@ namespace Server.Regions if (!base.OnMoveInto(from, d, newLocation, oldLocation)) return false; - if (from is BaseCreature && ((BaseCreature)from).NoHouseRestrictions) + BaseCreature bc = from as BaseCreature; + + if (bc?.NoHouseRestrictions == true) { } - else if (from is BaseCreature && !((BaseCreature)from).Controlled - ) // Untamed creatures cannot enter public houses + else if (bc?.Controlled == false) // Untamed creatures cannot enter public houses { return false; } - else if (from is BaseCreature && ((BaseCreature)from).IsHouseSummonable && + else if (bc?.IsHouseSummonable == true && !(BaseCreature.Summoning || House.IsInside(oldLocation, 16))) { return false; } - else if (from is BaseCreature && !((BaseCreature)from).Controlled && House.IsAosRules && !House.Public) + else if (bc?.Controlled == false && House.IsAosRules && !House.Public) { return false; } @@ -181,8 +184,8 @@ namespace Server.Regions if (House.InternalizedVendors.Count > 0 && House.IsInside(from) && !House.IsInside(oldLocation, 16) && House.IsOwner(from) && from.Alive && - !from.HasGump(typeof(NoticeGump))) - from.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180, null, null)); + !from.HasGump()) + from.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180)); return true; } @@ -241,8 +244,8 @@ namespace Server.Regions } else if (isOwner) { - from.CloseGump(typeof(ConfirmHouseResize)); - from.CloseGump(typeof(HouseGumpAOS)); + from.CloseGump(); + from.CloseGump(); from.SendGump(new ConfirmHouseResize(from, House)); } else @@ -255,23 +258,12 @@ namespace Server.Regions return; if (e.HasKeyword(0x33)) // remove thyself { - if (isFriend) - { - from.SendLocalizedMessage(501326); // Target the individual to eject from this house. - from.Target = new HouseKickTarget(House); - } - else - { - from.SendLocalizedMessage(502094); // You must be in your house to do this. - } + from.SendLocalizedMessage(501326); // Target the individual to eject from this house. + from.Target = new HouseKickTarget(House); } else if (e.HasKeyword(0x34)) // I ban thee { - if (!isFriend) - { - from.SendLocalizedMessage(502094); // You must be in your house to do this. - } - else if (!House.Public && House.IsAosRules) + if (!House.Public && House.IsAosRules) { from.SendLocalizedMessage( 1062521); // You cannot ban someone from a private house. Revoke their access instead. @@ -289,13 +281,9 @@ namespace Server.Regions from.SendLocalizedMessage(502097); // Lock what down? from.Target = new LockdownTarget(false, House); } - else if (isFriend) - { - from.SendLocalizedMessage(1010587); // You are not a co-owner of this house. - } else { - from.SendLocalizedMessage(502094); // You must be in your house to do this. + from.SendLocalizedMessage(1010587); // You are not a co-owner of this house. } } else if (e.HasKeyword(0x24)) // I wish to release this @@ -305,13 +293,9 @@ namespace Server.Regions from.SendLocalizedMessage(502100); // Choose the item you wish to release from.Target = new LockdownTarget(true, House); } - else if (isFriend) - { - from.SendLocalizedMessage(1010587); // You are not a co-owner of this house. - } else { - from.SendLocalizedMessage(502094); // You must be in your house to do this. + from.SendLocalizedMessage(1010587); // You are not a co-owner of this house. } } else if (e.HasKeyword(0x25)) // I wish to secure this @@ -344,28 +328,22 @@ namespace Server.Regions from.SendLocalizedMessage(502109); // Owners do not get a strongbox of their own. else if (isCoOwner) House.AddStrongBox(from); - else if (isFriend) - from.SendLocalizedMessage(1010587); // You are not a co-owner of this house. else - from.SendLocalizedMessage(502094); // You must be in your house to do this. + from.SendLocalizedMessage(1010587); // You are not a co-owner of this house. } else if (e.HasKeyword(0x28)) // trash barrel { if (isCoOwner) House.AddTrashBarrel(from); - else if (isFriend) - from.SendLocalizedMessage(1010587); // You are not a co-owner of this house. else - from.SendLocalizedMessage(502094); // You must be in your house to do this. + from.SendLocalizedMessage(1010587); // You are not a co-owner of this house. } } public override bool OnDoubleClick(Mobile from, object o) { - if (o is Container) + if (o is Container c) { - Container c = (Container)o; - SecureAccessResult res = House.CheckSecureAccess(from, c); switch (res) @@ -383,10 +361,8 @@ namespace Server.Regions public override bool OnSingleClick(Mobile from, object o) { - if (o is Item) + if (o is Item item) { - Item item = (Item)o; - if (House.HasLockedDownItem(item)) item.LabelTo(from, 501643); // [locked down] else if (House.HasSecureItem(item)) diff --git a/Scripts/Regions/Spawning/SpawnDefinition.cs b/Scripts/Regions/Spawning/SpawnDefinition.cs index 49f67da8d..57373176e 100644 --- a/Scripts/Regions/Spawning/SpawnDefinition.cs +++ b/Scripts/Regions/Spawning/SpawnDefinition.cs @@ -36,7 +36,7 @@ namespace Server.Regions if (!Region.ReadString(xml, "name", ref group)) return null; - SpawnDefinition def = (SpawnDefinition)SpawnGroup.Table[group]; + SpawnDefinition def = SpawnGroup.Table[@group]; if (def == null) { @@ -121,12 +121,12 @@ namespace Server.Regions public class SpawnMobile : SpawnType { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); - protected bool m_Land; - protected bool m_Water; + private bool m_Land; + private bool m_Water; - protected SpawnMobile(Type type) : base(type) + public SpawnMobile(Type type) : base(type) { } @@ -152,13 +152,10 @@ namespace Server.Regions public static SpawnMobile Get(Type type) { - SpawnMobile sm = (SpawnMobile)m_Table[type]; + SpawnMobile sm = m_Table[type]; if (sm == null) - { - sm = new SpawnMobile(type); - m_Table[type] = sm; - } + m_Table[type] = sm = new SpawnMobile(type); return sm; } @@ -177,9 +174,7 @@ namespace Server.Regions { Mobile mobile = CreateMobile(); - BaseCreature creature = mobile as BaseCreature; - - if (creature != null) + if (mobile is BaseCreature creature) { creature.Home = entry.HomeLocation; creature.HomeMap = map; @@ -204,7 +199,7 @@ namespace Server.Regions public class SpawnItem : SpawnType { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); protected int m_Height; @@ -226,13 +221,10 @@ namespace Server.Regions public static SpawnItem Get(Type type) { - SpawnItem si = (SpawnItem)m_Table[type]; + SpawnItem si = m_Table[type]; if (si == null) - { - si = new SpawnItem(type); - m_Table[type] = si; - } + m_Table[type] = si = new SpawnItem(type); return si; } @@ -327,9 +319,7 @@ namespace Server.Regions List list = new List(); foreach (XmlNode node in xmlDef.ChildNodes) { - XmlElement el = node as XmlElement; - - if (el != null) + if (node is XmlElement el) { SpawnDefinition def = GetSpawnDefinition(el); if (def == null) @@ -364,7 +354,7 @@ namespace Server.Regions m_TotalWeight += elements[i].Weight; } - public static Hashtable Table{ get; } = new Hashtable(); + public static Dictionary Table{ get; } = new Dictionary(); public string Name{ get; } @@ -372,7 +362,7 @@ namespace Server.Regions public static void Register(SpawnGroup group) { - if (Table.Contains(group.Name)) + if (Table.ContainsKey(group.Name)) Console.WriteLine("Warning: Double SpawnGroup name '{0}'", group.Name); else Table[group.Name] = group; @@ -404,4 +394,4 @@ namespace Server.Regions return false; } } -} \ No newline at end of file +} diff --git a/Scripts/Regions/Spawning/SpawnEntry.cs b/Scripts/Regions/Spawning/SpawnEntry.cs index 524c196da..c81ca0f9f 100644 --- a/Scripts/Regions/Spawning/SpawnEntry.cs +++ b/Scripts/Regions/Spawning/SpawnEntry.cs @@ -34,13 +34,13 @@ namespace Server.Regions MaxSpawnTime = maxSpawnTime; Running = false; - if (Table.Contains(id)) + if (Table.ContainsKey(id)) Console.WriteLine("Warning: double SpawnEntry ID '{0}'", id); else Table[id] = this; } - public static Hashtable Table{ get; } = new Hashtable(); + public static Dictionary Table{ get; } = new Dictionary(); // When a creature's AI is deactivated (PlayerRangeSensitive optimization) does it return home? @@ -122,8 +122,8 @@ namespace Server.Regions spawn.Spawner = this; - if (spawn is BaseCreature) - ((BaseCreature)spawn).RemoveIfUntamed = RemoveIfUntamed; + if (spawn is BaseCreature creature) + creature.RemoveIfUntamed = RemoveIfUntamed; } private TimeSpan RandomTime() @@ -218,13 +218,7 @@ namespace Server.Regions writer.Write(SpawnedObjects.Count); for (int i = 0; i < SpawnedObjects.Count; i++) - { - ISpawnable spawn = SpawnedObjects[i]; - - int serial = spawn.Serial; - - writer.Write(serial); - } + writer.Write(SpawnedObjects[i].Serial); writer.Write(Running); @@ -245,10 +239,7 @@ namespace Server.Regions for (int i = 0; i < count; i++) { - int serial = reader.ReadInt(); - ISpawnable spawnableEntity = World.FindEntity(serial) as ISpawnable; - - if (spawnableEntity != null) + if (World.FindEntity(reader.ReadUInt()) is ISpawnable spawnableEntity) Add(spawnableEntity); } @@ -276,8 +267,7 @@ namespace Server.Regions for (int i = 0; i < count; i++) { - int serial = reader.ReadInt(); - IEntity entity = World.FindEntity(serial); + IEntity entity = World.FindEntity(reader.ReadUInt()); if (entity != null) { @@ -442,4 +432,4 @@ namespace Server.Regions args.Mobile.SendMessage("Spawners of region '{0}' have stopped.", region); } } -} \ No newline at end of file +} diff --git a/Scripts/Scripts.csproj b/Scripts/Scripts.csproj index 3e26ba823..e4e45e324 100644 --- a/Scripts/Scripts.csproj +++ b/Scripts/Scripts.csproj @@ -143,6 +143,7 @@ + @@ -181,30 +182,40 @@ - - - + + + + + + + + + + + + + - - - - - - + + + + + + @@ -547,7 +558,7 @@ - + diff --git a/Scripts/Skills/Anatomy.cs b/Scripts/Skills/Anatomy.cs index dfa1148ff..e4ab479a5 100644 --- a/Scripts/Skills/Anatomy.cs +++ b/Scripts/Skills/Anatomy.cs @@ -34,21 +34,19 @@ namespace Server.SkillHandlers from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 500324); // You know yourself quite well enough already. } - else if (targeted is TownCrier) + else if (targeted is TownCrier crier) { - ((TownCrier)targeted).PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500322, + crier.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500322, from.NetState); // This person looks fine to me, though he may have some news... } - else if (targeted is BaseVendor && ((BaseVendor)targeted).IsInvulnerable) + else if (targeted is BaseVendor vendor && vendor.IsInvulnerable) { - ((BaseVendor)targeted).PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500326, + vendor.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500326, from.NetState); // That can not be inspected. } - else if (targeted is Mobile) + else if (targeted is Mobile targ) { - Mobile targ = (Mobile)targeted; - - int marginOfError = Math.Max(0, 25 - (int)(from.Skills[SkillName.Anatomy].Value / 4)); + int marginOfError = Math.Max(0, 25 - (int)(from.Skills.Anatomy.Value / 4)); int str = targ.Str + Utility.RandomMinMax(-marginOfError, +marginOfError); int dex = targ.Dex + Utility.RandomMinMax(-marginOfError, +marginOfError); @@ -73,7 +71,7 @@ namespace Server.SkillHandlers targ.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1038045 + strMod * 11 + dexMod, from.NetState); // That looks [strong] and [dexterous]. - if (from.Skills[SkillName.Anatomy].Base >= 65.0) + if (from.Skills.Anatomy.Base >= 65.0) targ.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1038303 + stmMod, from.NetState); // That being is at [10,20,...] percent endurance. } diff --git a/Scripts/Skills/AnimalLore.cs b/Scripts/Skills/AnimalLore.cs index 6f00b78ff..3ff603655 100644 --- a/Scripts/Skills/AnimalLore.cs +++ b/Scripts/Skills/AnimalLore.cs @@ -34,20 +34,18 @@ namespace Server.SkillHandlers { from.SendLocalizedMessage(500331); // The spirits of the dead are not the province of animal lore. } - else if (targeted is BaseCreature) + else if (targeted is BaseCreature c) { - BaseCreature c = (BaseCreature)targeted; - if (!c.IsDeadPet) { if (c.Body.IsAnimal || c.Body.IsMonster || c.Body.IsSea) { - if (!c.Controlled && from.Skills[SkillName.AnimalLore].Value < 100.0) + if (!c.Controlled && from.Skills.AnimalLore.Value < 100.0) { from.SendLocalizedMessage( 1049674); // At your skill level, you can only lore tamed creatures. } - else if (!c.Controlled && !c.Tamable && from.Skills[SkillName.AnimalLore].Value < 110.0) + else if (!c.Controlled && !c.Tamable && from.Skills.AnimalLore.Value < 110.0) { from.SendLocalizedMessage( 1049675); // At your skill level, you can only lore tamed or tameable creatures. @@ -58,7 +56,7 @@ namespace Server.SkillHandlers } else { - from.CloseGump(typeof(AnimalLoreGump)); + from.CloseGump(); from.SendGump(new AnimalLoreGump(c)); } } diff --git a/Scripts/Skills/AnimalTaming.cs b/Scripts/Skills/AnimalTaming.cs index b07ca2ef5..6d5decde9 100644 --- a/Scripts/Skills/AnimalTaming.cs +++ b/Scripts/Skills/AnimalTaming.cs @@ -36,9 +36,7 @@ namespace Server.SkillHandlers public static bool CheckMastery(Mobile tamer, BaseCreature creature) { - BaseCreature familiar = (BaseCreature)SummonFamiliarSpell.Table[tamer]; - - if (familiar != null && !familiar.Deleted && familiar is DarkWolfFamiliar) + if (SummonFamiliarSpell.Table[tamer] is DarkWolfFamiliar familiar && !familiar.Deleted) if (creature is DireWolf || creature is GreyWolf || creature is TimberWolf || creature is WhiteWolf || creature is BakeKitsune) return true; @@ -107,133 +105,133 @@ namespace Server.SkillHandlers from.NextSkillTime = Core.TickCount; } - public virtual void ResetPacify(object obj) - { - if (obj is BaseCreature) ((BaseCreature)obj).BardPacified = true; - } - protected override void OnTarget(Mobile from, object targeted) { from.RevealingAction(); - if (targeted is Mobile) + if (!(targeted is Mobile mobile)) { - if (targeted is BaseCreature) + from.SendLocalizedMessage(502801); // You can't tame that! + return; + } + + if (!(mobile is BaseCreature creature)) + { + mobile.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502469, + from.NetState); // That being cannot be tamed. + return; + } + + if (!creature.Tamable) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1049655, + from.NetState); // That creature cannot be tamed. + return; + } + + if (creature.Controlled) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502804, + from.NetState); // That animal looks tame already. + return; + } + + if (from.Female && !creature.AllowFemaleTamer) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1049653, + from.NetState); // That creature can only be tamed by males. + return; + } + + if (!from.Female && !creature.AllowMaleTamer) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1049652, + from.NetState); // That creature can only be tamed by females. + return; + } + + if (creature is CuSidhe && from.Race != Race.Elf) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502801, + from.NetState); // You can't tame that! + return; + } + + if (from.Followers + creature.ControlSlots > from.FollowersMax) + { + from.SendLocalizedMessage(1049611); // You have too many followers to tame that creature. + return; + } + if (creature.Owners.Count >= BaseCreature.MaxOwners && !creature.Owners.Contains(from)) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1005615, + from.NetState); // This animal has had too many owners and is too upset for you to tame. + return; + } + if (MustBeSubdued(creature)) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1054025, + from.NetState); // You must subdue this creature before you can tame it! + return; + } + + if (!(CheckMastery(from, creature) || from.Skills.AnimalTaming.Value >= creature.MinTameSkill)) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502806, + from.NetState); // You have no chance of taming this creature. + return; + } + + if (creature is FactionWarHorse warHorse) + { + Faction faction = Faction.Find(from); + + if (faction == null || faction != warHorse.Faction) { - BaseCreature creature = (BaseCreature)targeted; - - if (!creature.Tamable) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1049655, - from.NetState); // That creature cannot be tamed. - } - else if (creature.Controlled) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502804, - from.NetState); // That animal looks tame already. - } - else if (from.Female && !creature.AllowFemaleTamer) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1049653, - from.NetState); // That creature can only be tamed by males. - } - else if (!from.Female && !creature.AllowMaleTamer) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1049652, - from.NetState); // That creature can only be tamed by females. - } - else if (creature is CuSidhe && from.Race != Race.Elf) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502801, - from.NetState); // You can't tame that! - } - else if (from.Followers + creature.ControlSlots > from.FollowersMax) - { - from.SendLocalizedMessage(1049611); // You have too many followers to tame that creature. - } - else if (creature.Owners.Count >= BaseCreature.MaxOwners && !creature.Owners.Contains(from)) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1005615, - from.NetState); // This animal has had too many owners and is too upset for you to tame. - } - else if (MustBeSubdued(creature)) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1054025, - from.NetState); // You must subdue this creature before you can tame it! - } - else if (CheckMastery(from, creature) || - from.Skills[SkillName.AnimalTaming].Value >= creature.MinTameSkill) - { - FactionWarHorse warHorse = creature as FactionWarHorse; - - if (warHorse != null) - { - Faction faction = Faction.Find(from); - - if (faction == null || faction != warHorse.Faction) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1042590, - from.NetState); // You cannot tame this creature. - return; - } - } - - if (m_BeingTamed.ContainsKey(creature)) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502802, - from.NetState); // Someone else is already taming this. - } - else if (creature.CanAngerOnTame && 0.95 >= Utility.RandomDouble()) - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502805, - from.NetState); // You seem to anger the beast! - creature.PlaySound(creature.GetAngerSound()); - creature.Direction = creature.GetDirectionTo(from); - - if (creature.BardPacified && Utility.RandomDouble() > .24) - Timer.DelayCall(TimeSpan.FromSeconds(2.0), new TimerStateCallback(ResetPacify), - creature); - else - creature.BardEndTime = DateTime.UtcNow; - - creature.BardPacified = false; - - creature.AIObject?.DoMove(creature.Direction); - - if (from is PlayerMobile && - !(((PlayerMobile)from).HonorActive || - TransformationSpellHelper.UnderTransformation(from, typeof(EtherealVoyageSpell)))) - creature.Combatant = from; - } - else - { - m_BeingTamed[creature] = from; - - from.LocalOverheadMessage(MessageType.Emote, 0x59, - 1010597); // You start to tame the creature. - from.NonlocalOverheadMessage(MessageType.Emote, 0x59, - 1010598); // *begins taming a creature.* - - new InternalTimer(from, creature, Utility.Random(3, 2)).Start(); - - m_SetSkillTime = false; - } - } - else - { - creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502806, - from.NetState); // You have no chance of taming this creature. - } + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1042590, + from.NetState); // You cannot tame this creature. + return; } + } + + if (m_BeingTamed.ContainsKey(creature)) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502802, + from.NetState); // Someone else is already taming this. + } + else if (creature.CanAngerOnTame && 0.95 >= Utility.RandomDouble()) + { + creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502805, + from.NetState); // You seem to anger the beast! + creature.PlaySound(creature.GetAngerSound()); + creature.Direction = creature.GetDirectionTo(from); + + if (creature.BardPacified && Utility.RandomDouble() > .24) + Timer.DelayCall(TimeSpan.FromSeconds(2.0), () => creature.BardPacified = true); else - { - ((Mobile)targeted).PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502469, - from.NetState); // That being cannot be tamed. - } + creature.BardEndTime = DateTime.UtcNow; + + creature.BardPacified = false; + + creature.AIObject?.DoMove(creature.Direction); + + if (from is PlayerMobile pm && + !(pm.HonorActive || + TransformationSpellHelper.UnderTransformation(pm, typeof(EtherealVoyageSpell)))) + creature.Combatant = pm; } else { - from.SendLocalizedMessage(502801); // You can't tame that! + m_BeingTamed[creature] = from; + + from.LocalOverheadMessage(MessageType.Emote, 0x59, + 1010597); // You start to tame the creature. + from.NonlocalOverheadMessage(MessageType.Emote, 0x59, + 1010598); // *begins taming a creature.* + + new InternalTimer(from, creature, Utility.Random(3, 2)).Start(); + + m_SetSkillTime = false; } } @@ -378,8 +376,8 @@ namespace Server.SkillHandlers if (m_Creature is GreaterDragon) { ScaleSkills(m_Creature, 0.72, 0.90); // 72% of original skills trainable to 90% - m_Creature.Skills[SkillName.Magery].Base = - m_Creature.Skills[SkillName.Magery] + m_Creature.Skills.Magery.Base = + m_Creature.Skills.Magery .Cap; // Greater dragons have a 90% cap reduction and 90% skill reduction on magery } else if (m_Paralyzed) @@ -434,4 +432,4 @@ namespace Server.SkillHandlers } } } -} \ No newline at end of file +} diff --git a/Scripts/Skills/ArmsLore.cs b/Scripts/Skills/ArmsLore.cs index 70cf25317..eb5401a9e 100644 --- a/Scripts/Skills/ArmsLore.cs +++ b/Scripts/Skills/ArmsLore.cs @@ -32,12 +32,10 @@ namespace Server.SkillHandlers protected override void OnTarget(Mobile from, object targeted) { - if (targeted is BaseWeapon) + if (targeted is BaseWeapon weap) { - if (from.CheckTargetSkill(SkillName.ArmsLore, targeted, 0, 100)) + if (from.CheckTargetSkill(SkillName.ArmsLore, weap, 0, 100)) { - BaseWeapon weap = (BaseWeapon)targeted; - if (weap.MaxHitPoints != 0) { int hp = (int)(weap.HitPoints / (double)weap.MaxHitPoints * 10); @@ -93,12 +91,10 @@ namespace Server.SkillHandlers from.SendLocalizedMessage(500353); // You are not certain... } } - else if (targeted is BaseArmor) + else if (targeted is BaseArmor arm) { - if (from.CheckTargetSkill(SkillName.ArmsLore, targeted, 0, 100)) + if (from.CheckTargetSkill(SkillName.ArmsLore, arm, 0, 100)) { - BaseArmor arm = (BaseArmor)targeted; - if (arm.MaxHitPoints != 0) { int hp = (int)(arm.HitPoints / (double)arm.MaxHitPoints * 10); @@ -137,11 +133,9 @@ namespace Server.SkillHandlers from.SendLocalizedMessage(500353); // You are not certain... } } - else if (targeted is SwampDragon && ((SwampDragon)targeted).HasBarding) + else if (targeted is SwampDragon pet && pet.HasBarding) { - SwampDragon pet = (SwampDragon)targeted; - - if (from.CheckTargetSkill(SkillName.ArmsLore, targeted, 0, 100)) + if (from.CheckTargetSkill(SkillName.ArmsLore, pet, 0, 100)) { int perc = 4 * pet.BardingHP / pet.BardingMaxHP; diff --git a/Scripts/Skills/Begging.cs b/Scripts/Skills/Begging.cs index f20b63c38..a0c75d075 100644 --- a/Scripts/Skills/Begging.cs +++ b/Scripts/Skills/Begging.cs @@ -45,10 +45,8 @@ namespace Server.SkillHandlers int number = -1; - if (targeted is Mobile) + if (targeted is Mobile targ) { - Mobile targ = (Mobile)targeted; - if (targ.Player) // We can't beg from players { number = 500398; // Perhaps just asking would work better. @@ -71,7 +69,7 @@ namespace Server.SkillHandlers } else { - // Face eachother + // Face each other from.Direction = from.GetDirectionTo(targ); targ.Direction = targ.GetDirectionTo(from); diff --git a/Scripts/Skills/DetectHidden.cs b/Scripts/Skills/DetectHidden.cs index 2c4386d1b..51e840bd8 100644 --- a/Scripts/Skills/DetectHidden.cs +++ b/Scripts/Skills/DetectHidden.cs @@ -32,16 +32,16 @@ namespace Server.SkillHandlers bool foundAnyone = false; Point3D p; - if (targ is Mobile) - p = ((Mobile)targ).Location; - else if (targ is Item) - p = ((Item)targ).Location; - else if (targ is IPoint3D) - p = new Point3D((IPoint3D)targ); + if (targ is Mobile mobile) + p = mobile.Location; + else if (targ is Item item) + p = item.Location; + else if (targ is IPoint3D d) + p = new Point3D(d); else p = src.Location; - double srcSkill = src.Skills[SkillName.DetectHidden].Value; + double srcSkill = src.Skills.DetectHidden.Value; int range = (int)(srcSkill / 10.0); if (!src.CheckSkill(SkillName.DetectHidden, 0.0, 100.0)) @@ -62,7 +62,7 @@ namespace Server.SkillHandlers if (trg.Hidden && src != trg) { double ss = srcSkill + Utility.Random(21) - 10; - double ts = trg.Skills[SkillName.Hiding].Value + Utility.Random(21) - 10; + double ts = trg.Skills.Hiding.Value + Utility.Random(21) - 10; if (src.AccessLevel >= trg.AccessLevel && (ss >= ts || inHouse && house.IsInside(trg))) { diff --git a/Scripts/Skills/Discordance.cs b/Scripts/Skills/Discordance.cs index 4bfdf53e5..d5bd4bd27 100644 --- a/Scripts/Skills/Discordance.cs +++ b/Scripts/Skills/Discordance.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; using Server.Mobiles; using Server.Targeting; @@ -8,7 +9,7 @@ namespace Server.SkillHandlers { public class Discordance { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public static void Initialize() { @@ -34,7 +35,7 @@ namespace Server.SkillHandlers public static bool GetEffect(Mobile targ, ref int effect) { - DiscordanceInfo info = m_Table[targ] as DiscordanceInfo; + DiscordanceInfo info = m_Table[targ]; if (info == null) return false; @@ -49,7 +50,7 @@ namespace Server.SkillHandlers Mobile targ = info.m_Creature; bool ends = false; - // According to uoherald bard must remain alive, visible, and + // According to uoherald bard must remain alive, visible, and // within range of the target or the effect ends in 15 seconds. if (!targ.Alive || targ.Deleted || !from.Alive || from.Hidden) { @@ -95,10 +96,10 @@ namespace Server.SkillHandlers public bool m_Ending; public DateTime m_EndTime; public Mobile m_From; - public ArrayList m_Mods; + public List m_Mods; public Timer m_Timer; - public DiscordanceInfo(Mobile from, Mobile creature, int effect, ArrayList mods) + public DiscordanceInfo(Mobile from, Mobile creature, int effect, List mods) { m_From = from; m_Creature = creature; @@ -116,12 +117,12 @@ namespace Server.SkillHandlers { object mod = m_Mods[i]; - if (mod is ResistanceMod) - m_Creature.AddResistanceMod((ResistanceMod)mod); - else if (mod is StatMod) - m_Creature.AddStatMod((StatMod)mod); - else if (mod is SkillMod) - m_Creature.AddSkillMod((SkillMod)mod); + if (mod is ResistanceMod resistanceMod) + m_Creature.AddResistanceMod(resistanceMod); + else if (mod is StatMod statMod) + m_Creature.AddStatMod(statMod); + else if (mod is SkillMod skillMod) + m_Creature.AddSkillMod(skillMod); } } @@ -131,12 +132,12 @@ namespace Server.SkillHandlers { object mod = m_Mods[i]; - if (mod is ResistanceMod) - m_Creature.RemoveResistanceMod((ResistanceMod)mod); - else if (mod is StatMod) - m_Creature.RemoveStatMod(((StatMod)mod).Name); - else if (mod is SkillMod) - m_Creature.RemoveSkillMod((SkillMod)mod); + if (mod is ResistanceMod resistanceMod) + m_Creature.RemoveResistanceMod(resistanceMod); + else if (mod is StatMod statMod) + m_Creature.RemoveStatMod(statMod.Name); + else if (mod is SkillMod skillMod) + m_Creature.RemoveSkillMod(skillMod); } } } @@ -161,24 +162,22 @@ namespace Server.SkillHandlers from.SendLocalizedMessage( 1062488); // The instrument you are trying to play is no longer in your backpack! } - else if (target is Mobile) + else if (target is Mobile targ) { - Mobile targ = (Mobile)target; - - if (targ == from || targ is BaseCreature && - (((BaseCreature)targ).BardImmune || !from.CanBeHarmful(targ, false)) && - ((BaseCreature)targ).ControlMaster != from) + if (targ == from || targ is BaseCreature bc && + (bc.BardImmune || !from.CanBeHarmful(bc, false)) && + bc.ControlMaster != from) { from.SendLocalizedMessage(1049535); // A song of discord would have no effect on that. } - else if (m_Table.Contains(targ)) //Already discorded + else if (m_Table.ContainsKey(targ)) //Already discorded { from.SendLocalizedMessage(1049537); // Your target is already in discord. } else if (!targ.Player) { double diff = m_Instrument.GetDifficultyFor(targ) - 10.0; - double music = from.Skills[SkillName.Musicianship].Value; + double music = from.Skills.Musicianship.Value; if (music > 100.0) diff -= (music - 100.0) * 0.5; @@ -189,19 +188,19 @@ namespace Server.SkillHandlers m_Instrument.PlayInstrumentBadly(from); m_Instrument.ConsumeUse(from); } - else if (from.CheckTargetSkill(SkillName.Discordance, target, diff - 25.0, diff + 25.0)) + else if (from.CheckTargetSkill(SkillName.Discordance, targ, diff - 25.0, diff + 25.0)) { from.SendLocalizedMessage(1049539); // You play the song surpressing your targets strength m_Instrument.PlayInstrumentWell(from); m_Instrument.ConsumeUse(from); - ArrayList mods = new ArrayList(); + List mods = new List(); int effect; double scalar; if (Core.AOS) { - double discord = from.Skills[SkillName.Discordance].Value; + double discord = from.Skills.Discordance.Value; if (discord > 100.0) effect = -20 + (int)((discord - 100.0) / -2.5); @@ -225,7 +224,7 @@ namespace Server.SkillHandlers } else { - effect = (int)(from.Skills[SkillName.Discordance].Value / -5.0); + effect = (int)(from.Skills.Discordance.Value / -5.0); scalar = effect * 0.01; mods.Add(new StatMod(StatType.Str, "DiscordanceStr", (int)(targ.RawStr * scalar), @@ -267,4 +266,4 @@ namespace Server.SkillHandlers } } } -} \ No newline at end of file +} diff --git a/Scripts/Skills/EvalInt.cs b/Scripts/Skills/EvalInt.cs index 391e75415..60524153f 100644 --- a/Scripts/Skills/EvalInt.cs +++ b/Scripts/Skills/EvalInt.cs @@ -33,21 +33,19 @@ namespace Server.SkillHandlers { from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 500910); // Hmm, that person looks really silly. } - else if (targeted is TownCrier) + else if (targeted is TownCrier crier) { - ((TownCrier)targeted).PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500907, + crier.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500907, from.NetState); // He looks smart enough to remember the news. Ask him about it. } - else if (targeted is BaseVendor && ((BaseVendor)targeted).IsInvulnerable) + else if (targeted is BaseVendor vendor && vendor.IsInvulnerable) { - ((BaseVendor)targeted).PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500909, + vendor.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500909, from.NetState); // That person could probably calculate the cost of what you buy from them. } - else if (targeted is Mobile) + else if (targeted is Mobile targ) { - Mobile targ = (Mobile)targeted; - - int marginOfError = Math.Max(0, 20 - (int)(from.Skills[SkillName.EvalInt].Value / 5)); + int marginOfError = Math.Max(0, 20 - (int)(from.Skills.EvalInt.Value / 5)); int intel = targ.Int + Utility.RandomMinMax(-marginOfError, +marginOfError); int mana = targ.Mana * 100 / Math.Max(targ.ManaMax, 1) + @@ -74,7 +72,7 @@ namespace Server.SkillHandlers targ.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1038169 + intMod + body, from.NetState); // He/She/It looks [slighly less intelligent than a rock.] [Of Average intellect] [etc...] - if (from.Skills[SkillName.EvalInt].Base >= 76.0) + if (from.Skills.EvalInt.Base >= 76.0) targ.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1038202 + mnMod, from.NetState); // That being is at [10,20,...] percent mental strength. } diff --git a/Scripts/Skills/ForensicEval.cs b/Scripts/Skills/ForensicEval.cs index 62344db5c..476ace831 100644 --- a/Scripts/Skills/ForensicEval.cs +++ b/Scripts/Skills/ForensicEval.cs @@ -35,7 +35,7 @@ namespace Server.SkillHandlers { if (from.CheckTargetSkill(SkillName.Forensics, target, 40.0, 100.0)) { - if (target is PlayerMobile && ((PlayerMobile)target).NpcGuild == NpcGuild.ThievesGuild) + if (target is PlayerMobile pm && pm.NpcGuild == NpcGuild.ThievesGuild) from.SendLocalizedMessage(501004); //That individual is a thief! else from.SendLocalizedMessage(501003); //You notice nothing unusual. @@ -45,12 +45,10 @@ namespace Server.SkillHandlers from.SendLocalizedMessage(501001); //You cannot determain anything useful. } } - else if (target is Corpse) + else if (target is Corpse c) { - if (from.CheckTargetSkill(SkillName.Forensics, target, 0.0, 100.0)) + if (from.CheckTargetSkill(SkillName.Forensics, c, 0.0, 100.0)) { - Corpse c = (Corpse)target; - if (c.m_Forensicist != null) from.SendLocalizedMessage(1042750, c.m_Forensicist); // The forensicist ~1_NAME~ has already discovered that: @@ -84,9 +82,8 @@ namespace Server.SkillHandlers from.SendLocalizedMessage(501001); //You cannot determain anything useful. } } - else if (target is ILockpickable) + else if (target is ILockpickable p) { - ILockpickable p = (ILockpickable)target; if (p.Picker != null) from.SendLocalizedMessage(1042749, p.Picker.Name); //This lock was opened by ~1_PICKER_NAME~ else diff --git a/Scripts/Skills/Hiding.cs b/Scripts/Skills/Hiding.cs index 4737fe218..65f4ffdbb 100644 --- a/Scripts/Skills/Hiding.cs +++ b/Scripts/Skills/Hiding.cs @@ -50,8 +50,8 @@ namespace Server.SkillHandlers bonus = 50.0; } - //int range = 18 - (int)(m.Skills[SkillName.Hiding].Value / 10); - int range = Math.Min((int)((100 - m.Skills[SkillName.Hiding].Value) / 2) + 8, + //int range = 18 - (int)(m.Skills.Hiding.Value / 10); + int range = Math.Min((int)((100 - m.Skills.Hiding.Value) / 2) + 8, 18); //Cap of 18 not OSI-exact, intentional difference bool badCombat = !CombatOverride && m.Combatant != null && m.InRange(m.Combatant.Location, range) && diff --git a/Scripts/Skills/ItemIdentification.cs b/Scripts/Skills/ItemIdentification.cs index 454b788b3..6fbda080b 100644 --- a/Scripts/Skills/ItemIdentification.cs +++ b/Scripts/Skills/ItemIdentification.cs @@ -29,26 +29,26 @@ namespace Server.Items protected override void OnTarget(Mobile from, object o) { - if (o is Item) + if (o is Item item) { - if (from.CheckTargetSkill(SkillName.ItemID, o, 0, 100)) + if (from.CheckTargetSkill(SkillName.ItemID, item, 0, 100)) { - if (o is BaseWeapon) - ((BaseWeapon)o).Identified = true; - else if (o is BaseArmor) - ((BaseArmor)o).Identified = true; + if (item is BaseWeapon weapon) + weapon.Identified = true; + else if (item is BaseArmor armor) + armor.Identified = true; if (!Core.AOS) - ((Item)o).OnSingleClick(from); + item.OnSingleClick(from); } else { from.SendLocalizedMessage(500353); // You are not certain... } } - else if (o is Mobile) + else if (o is Mobile mobile) { - ((Mobile)o).OnSingleClick(from); + mobile.OnSingleClick(from); } else { diff --git a/Scripts/Skills/Meditation.cs b/Scripts/Skills/Meditation.cs index e67eb45fb..212f046a1 100644 --- a/Scripts/Skills/Meditation.cs +++ b/Scripts/Skills/Meditation.cs @@ -19,10 +19,10 @@ namespace Server.SkillHandlers if (item is Spellbook || item is Runebook) return true; - if (Core.AOS && item is BaseWeapon && ((BaseWeapon)item).Attributes.SpellChanneling != 0) + if (Core.AOS && item is BaseWeapon weapon && weapon.Attributes.SpellChanneling != 0) return true; - if (Core.AOS && item is BaseArmor && ((BaseArmor)item).Attributes.SpellChanneling != 0) + if (Core.AOS && item is BaseArmor armor && armor.Attributes.SpellChanneling != 0) return true; return false; @@ -78,7 +78,7 @@ namespace Server.SkillHandlers return TimeSpan.FromSeconds(2.5); } - double skillVal = m.Skills[SkillName.Meditation].Value; + double skillVal = m.Skills.Meditation.Value; double chance = (50.0 + (skillVal - (m.ManaMax - m.Mana)) * 2) / 100; if (chance > Utility.RandomDouble()) diff --git a/Scripts/Skills/Peacemaking.cs b/Scripts/Skills/Peacemaking.cs index 14e54d8cb..43358fe3d 100644 --- a/Scripts/Skills/Peacemaking.cs +++ b/Scripts/Skills/Peacemaking.cs @@ -51,15 +51,15 @@ namespace Server.SkillHandlers { from.RevealingAction(); - if (!(targeted is Mobile)) + if (!(targeted is Mobile targ)) { from.SendLocalizedMessage(1049528); // You cannot calm that! } - else if (from.Region.IsPartOf(typeof(SafeZone))) + else if (from.Region.IsPartOf()) { from.SendMessage("You may not peacemake in this area."); } - else if (((Mobile)targeted).Region.IsPartOf(typeof(SafeZone))) + else if (targ.Region.IsPartOf()) { from.SendMessage("You may not peacemake there."); } @@ -105,8 +105,8 @@ namespace Server.SkillHandlers foreach (Mobile m in from.GetMobilesInRange(range)) { - if (m is BaseCreature && ((BaseCreature)m).Uncalmable || - m is BaseCreature && ((BaseCreature)m).AreaPeaceImmune || m == from || + BaseCreature bc = m as BaseCreature; + if (bc?.Uncalmable == true || bc?.AreaPeaceImmune == true || m == from || !from.CanBeHarmful(m, false)) continue; @@ -117,8 +117,8 @@ namespace Server.SkillHandlers m.Combatant = null; m.Warmode = false; - if (m is BaseCreature && !((BaseCreature)m).BardPacified) - ((BaseCreature)m).Pacify(from, DateTime.UtcNow + TimeSpan.FromSeconds(1.0)); + if (bc?.BardPacified == false) + bc.Pacify(from, DateTime.UtcNow + TimeSpan.FromSeconds(1.0)); } if (!calmed) @@ -132,20 +132,19 @@ namespace Server.SkillHandlers else { // Target mode : pacify a single target for a longer duration - - Mobile targ = (Mobile)targeted; + BaseCreature bc = targ as BaseCreature; if (!from.CanBeHarmful(targ, false)) { from.SendLocalizedMessage(1049528); m_SetSkillTime = true; } - else if (targ is BaseCreature && ((BaseCreature)targ).Uncalmable) + else if (bc?.Uncalmable == true) { from.SendLocalizedMessage(1049526); // You have no chance of calming that creature. m_SetSkillTime = true; } - else if (targ is BaseCreature && ((BaseCreature)targ).BardPacified) + else if (bc?.BardPacified == true) { from.SendLocalizedMessage(1049527); // That creature is already being calmed. m_SetSkillTime = true; @@ -160,7 +159,7 @@ namespace Server.SkillHandlers else { double diff = m_Instrument.GetDifficultyFor(targ) - 10.0; - double music = from.Skills[SkillName.Musicianship].Value; + double music = from.Skills.Musicianship.Value; if (music > 100.0) diff -= (music - 100.0) * 0.5; @@ -177,15 +176,13 @@ namespace Server.SkillHandlers m_Instrument.ConsumeUse(from); from.NextSkillTime = Core.TickCount + 5000; - if (targ is BaseCreature) + targ.Combatant = null; + targ.Warmode = false; + + if (bc != null) { - BaseCreature bc = (BaseCreature)targ; - from.SendLocalizedMessage(1049532); // You play hypnotic music, calming your target. - targ.Combatant = null; - targ.Warmode = false; - double seconds = 100 - diff / 1.5; if (seconds > 120) @@ -201,8 +198,6 @@ namespace Server.SkillHandlers targ.SendLocalizedMessage( 500616); // You hear lovely music, and forget to continue battling! - targ.Combatant = null; - targ.Warmode = false; } } } diff --git a/Scripts/Skills/Poisoning.cs b/Scripts/Skills/Poisoning.cs index fec159054..02776fcaa 100644 --- a/Scripts/Skills/Poisoning.cs +++ b/Scripts/Skills/Poisoning.cs @@ -30,10 +30,10 @@ namespace Server.SkillHandlers protected override void OnTarget(Mobile from, object targeted) { - if (targeted is BasePoisonPotion) + if (targeted is BasePoisonPotion potion) { from.SendLocalizedMessage(502142); // To what do you wish to apply the poison? - from.Target = new InternalTarget((BasePoisonPotion)targeted); + from.Target = new InternalTarget(potion); } else // Not a Poison Potion { @@ -61,10 +61,8 @@ namespace Server.SkillHandlers { startTimer = true; } - else if (targeted is BaseWeapon) + else if (targeted is BaseWeapon weapon) { - BaseWeapon weapon = (BaseWeapon)targeted; - if (Core.AOS) startTimer = weapon.PrimaryAbility == WeaponAbility.InfectiousStrike || weapon.SecondaryAbility == WeaponAbility.InfectiousStrike; @@ -116,26 +114,26 @@ namespace Server.SkillHandlers { if (m_From.CheckTargetSkill(SkillName.Poisoning, m_Target, m_MinSkill, m_MaxSkill)) { - if (m_Target is Food) + if (m_Target is Food food) { - ((Food)m_Target).Poison = m_Poison; + food.Poison = m_Poison; } - else if (m_Target is BaseWeapon) + else if (m_Target is BaseWeapon weapon) { - ((BaseWeapon)m_Target).Poison = m_Poison; - ((BaseWeapon)m_Target).PoisonCharges = 18 - m_Poison.Level * 2; + weapon.Poison = m_Poison; + weapon.PoisonCharges = 18 - m_Poison.Level * 2; } - else if (m_Target is FukiyaDarts) + else if (m_Target is FukiyaDarts darts) { - ((FukiyaDarts)m_Target).Poison = m_Poison; - ((FukiyaDarts)m_Target).PoisonCharges = Math.Min(18 - m_Poison.Level * 2, - ((FukiyaDarts)m_Target).UsesRemaining); + darts.Poison = m_Poison; + darts.PoisonCharges = Math.Min(18 - m_Poison.Level * 2, + darts.UsesRemaining); } - else if (m_Target is Shuriken) + else if (m_Target is Shuriken shuriken) { - ((Shuriken)m_Target).Poison = m_Poison; - ((Shuriken)m_Target).PoisonCharges = Math.Min(18 - m_Poison.Level * 2, - ((Shuriken)m_Target).UsesRemaining); + shuriken.Poison = m_Poison; + shuriken.PoisonCharges = Math.Min(18 - m_Poison.Level * 2, + shuriken.UsesRemaining); } m_From.SendLocalizedMessage(1010517); // You apply the poison @@ -145,17 +143,15 @@ namespace Server.SkillHandlers else // Failed { // 5% of chance of getting poisoned if failed - if (m_From.Skills[SkillName.Poisoning].Base < 80.0 && Utility.Random(20) == 0) + if (m_From.Skills.Poisoning.Base < 80.0 && Utility.Random(20) == 0) { m_From.SendLocalizedMessage(502148); // You make a grave mistake while applying the poison. m_From.ApplyPoison(m_From, m_Poison); } else { - if (m_Target is BaseWeapon) + if (m_Target is BaseWeapon weapon) { - BaseWeapon weapon = (BaseWeapon)m_Target; - if (weapon.Type == WeaponType.Slashing) m_From.SendLocalizedMessage( 1010516); // You fail to apply a sufficient dose of poison on the blade diff --git a/Scripts/Skills/Provocation.cs b/Scripts/Skills/Provocation.cs index baca501ff..a2aa3e567 100644 --- a/Scripts/Skills/Provocation.cs +++ b/Scripts/Skills/Provocation.cs @@ -116,7 +116,7 @@ namespace Server.SkillHandlers double diff = (m_Instrument.GetDifficultyFor(m_Creature) + m_Instrument.GetDifficultyFor(creature)) * 0.5 - 5.0; - double music = from.Skills[SkillName.Musicianship].Value; + double music = from.Skills.Musicianship.Value; if (music > 100.0) diff -= (music - 100.0) * 0.5; diff --git a/Scripts/Skills/RemoveTrap.cs b/Scripts/Skills/RemoveTrap.cs index a8913dc5e..32fe79a19 100644 --- a/Scripts/Skills/RemoveTrap.cs +++ b/Scripts/Skills/RemoveTrap.cs @@ -15,11 +15,11 @@ namespace Server.SkillHandlers public static TimeSpan OnUse(Mobile m) { - if (m.Skills[SkillName.Lockpicking].Value < 50) + if (m.Skills.Lockpicking.Value < 50) { m.SendLocalizedMessage(502366); // You do not know enough about locks. Become better at picking locks. } - else if (m.Skills[SkillName.DetectHidden].Value < 50) + else if (m.Skills.DetectHidden.Value < 50) { m.SendLocalizedMessage(502367); // You are not perceptive enough. Become better at detect hidden. } diff --git a/Scripts/Skills/Snooping.cs b/Scripts/Skills/Snooping.cs index ed86a04ad..dbd0cb721 100644 --- a/Scripts/Skills/Snooping.cs +++ b/Scripts/Skills/Snooping.cs @@ -23,7 +23,7 @@ namespace Server.SkillHandlers if (map != null && (map.Rules & MapRules.HarmfulRestrictions) == 0) return true; // felucca you can snoop anybody - GuardedRegion reg = (GuardedRegion)to.Region.GetRegion(typeof(GuardedRegion)); + GuardedRegion reg = to.Region.GetRegion(); if (reg == null || reg.IsDisabled()) return true; // not in town? we can snoop any npc @@ -56,7 +56,7 @@ namespace Server.SkillHandlers } if (root != null && from.AccessLevel == AccessLevel.Player && - from.Skills[SkillName.Snooping].Value < Utility.Random(100)) + from.Skills.Snooping.Value < Utility.Random(100)) { Map map = from.Map; @@ -88,7 +88,7 @@ namespace Server.SkillHandlers { from.SendLocalizedMessage(500210); // You failed to peek into the container. - if (from.Skills[SkillName.Hiding].Value / 2 < Utility.Random(100)) + if (from.Skills.Hiding.Value / 2 < Utility.Random(100)) from.RevealingAction(); } } diff --git a/Scripts/Skills/SpiritSpeak.cs b/Scripts/Skills/SpiritSpeak.cs index 4f2aaac63..abf7ef2ac 100644 --- a/Scripts/Skills/SpiritSpeak.cs +++ b/Scripts/Skills/SpiritSpeak.cs @@ -34,7 +34,7 @@ namespace Server.SkillHandlers if (!m.CanHearGhosts) { Timer t = new SpiritSpeakTimer(m); - double secs = m.Skills[SkillName.SpiritSpeak].Base / 50; + double secs = m.Skills.SpiritSpeak.Base / 50; secs *= 90; if (secs < 15) secs = 15; @@ -143,14 +143,14 @@ namespace Server.SkillHandlers if (toChannel != null) { - min = 1 + (int)(Caster.Skills[SkillName.SpiritSpeak].Value * 0.25); + min = 1 + (int)(Caster.Skills.SpiritSpeak.Value * 0.25); max = min + 4; mana = 0; number = 1061287; // You channel energy from a nearby corpse to heal your wounds. } else { - min = 1 + (int)(Caster.Skills[SkillName.SpiritSpeak].Value * 0.25); + min = 1 + (int)(Caster.Skills.SpiritSpeak.Value * 0.25); max = min + 4; mana = 10; number = 1061286; // You channel your own spiritual energy to heal your wounds. @@ -164,7 +164,7 @@ namespace Server.SkillHandlers { Caster.CheckSkill(SkillName.SpiritSpeak, 0.0, 120.0); - if (Utility.RandomDouble() > Caster.Skills[SkillName.SpiritSpeak].Value / 100.0) + if (Utility.RandomDouble() > Caster.Skills.SpiritSpeak.Value / 100.0) { Caster.SendLocalizedMessage(502443); // You fail your attempt at contacting the netherworld. } diff --git a/Scripts/Skills/Stealing.cs b/Scripts/Skills/Stealing.cs index 859e2b9c4..610e198ea 100644 --- a/Scripts/Skills/Stealing.cs +++ b/Scripts/Skills/Stealing.cs @@ -50,7 +50,7 @@ namespace Server.SkillHandlers { m.SendLocalizedMessage(1005584); // Both hands must be free to steal. } - else if (m.Region.IsPartOf(typeof(SafeZone))) + else if (m.Region.IsPartOf()) { m.SendMessage("You may not steal in this area."); } @@ -90,7 +90,7 @@ namespace Server.SkillHandlers { m_Thief.SendLocalizedMessage(1005584); // Both hands must be free to steal. } - else if (m_Thief.Region.IsPartOf(typeof(SafeZone))) + else if (m_Thief.Region.IsPartOf()) { m_Thief.SendMessage("You may not steal in this area."); } @@ -137,7 +137,7 @@ namespace Server.SkillHandlers } else if (faction != null) { - if (!m_Thief.CanBeginAction(typeof(IncognitoSpell))) + if (!m_Thief.CanBeginAction()) { m_Thief.SendLocalizedMessage(1010581); // You cannot steal the sigil when you are incognito } @@ -145,7 +145,7 @@ namespace Server.SkillHandlers { m_Thief.SendLocalizedMessage(1010583); // You cannot steal the sigil while disguised } - else if (!m_Thief.CanBeginAction(typeof(PolymorphSpell))) + else if (!m_Thief.CanBeginAction()) { m_Thief.SendLocalizedMessage(1010582); // You cannot steal the sigil while polymorphed } @@ -227,7 +227,7 @@ namespace Server.SkillHandlers { m_Thief.SendLocalizedMessage(502703); // You must be standing next to an item to steal it. } - else if (si != null && m_Thief.Skills[SkillName.Stealing].Value < 100.0) + else if (si != null && m_Thief.Skills.Stealing.Value < 100.0) { m_Thief.SendLocalizedMessage(1060025, "", 0x66D); // You're not skilled enough to attempt the theft of this item. @@ -263,7 +263,7 @@ namespace Server.SkillHandlers { if (toSteal.Stackable && toSteal.Amount > 1) { - int maxAmount = (int)(m_Thief.Skills[SkillName.Stealing].Value / 10.0 / toSteal.Weight); + int maxAmount = (int)(m_Thief.Skills.Stealing.Value / 10.0 / toSteal.Weight); if (maxAmount < 1) maxAmount = 1; @@ -320,7 +320,7 @@ namespace Server.SkillHandlers m_Thief.SendLocalizedMessage(502723); // You fail to steal the item. } - caught = m_Thief.Skills[SkillName.Stealing].Value < Utility.Random(150); + caught = m_Thief.Skills.Stealing.Value < Utility.Random(150); } } diff --git a/Scripts/Skills/Stealth.cs b/Scripts/Skills/Stealth.cs index e696af453..0fc551acc 100644 --- a/Scripts/Skills/Stealth.cs +++ b/Scripts/Skills/Stealth.cs @@ -60,12 +60,12 @@ namespace Server.SkillHandlers { m.SendLocalizedMessage(502725); // You must hide first } - else if (m.Skills[SkillName.Hiding].Base < HidingRequirement) + else if (m.Skills.Hiding.Base < HidingRequirement) { m.SendLocalizedMessage(502726); // You are not hidden well enough. Become better at hiding. m.RevealingAction(); } - else if (!m.CanBeginAction(typeof(Stealth))) + else if (!m.CanBeginAction()) { m.SendLocalizedMessage(1063086); // You cannot use this skill right now. m.RevealingAction(); @@ -82,7 +82,7 @@ namespace Server.SkillHandlers else if (m.CheckSkill(SkillName.Stealth, -20.0 + armorRating * 2, (Core.AOS ? 60.0 : 80.0) + armorRating * 2)) { - int steps = (int)(m.Skills[SkillName.Stealth].Value / (Core.AOS ? 5.0 : 10.0)); + int steps = (int)(m.Skills.Stealth.Value / (Core.AOS ? 5.0 : 10.0)); if (steps < 1) steps = 1; diff --git a/Scripts/Skills/Tracking.cs b/Scripts/Skills/Tracking.cs index 42793d8d6..1324d2e6b 100644 --- a/Scripts/Skills/Tracking.cs +++ b/Scripts/Skills/Tracking.cs @@ -20,8 +20,8 @@ namespace Server.SkillHandlers { m.SendLocalizedMessage(1011350); // What do you wish to track? - m.CloseGump(typeof(TrackWhatGump)); - m.CloseGump(typeof(TrackWhoGump)); + m.CloseGump(); + m.CloseGump(); m.SendGump(new TrackWhatGump(m)); return TimeSpan.FromSeconds(10.0); // 10 second delay before beign able to re-use a skill @@ -192,7 +192,7 @@ namespace Server.SkillHandlers from.CheckSkill(SkillName.Tracking, 21.1, 100.0); // Passive gain - int range = 10 + (int)(from.Skills[SkillName.Tracking].Value / 10); + int range = 10 + (int)(from.Skills.Tracking.Value / 10); List list = new List(); @@ -228,14 +228,14 @@ namespace Server.SkillHandlers return true; - int tracking = from.Skills[SkillName.Tracking].Fixed; - int detectHidden = from.Skills[SkillName.DetectHidden].Fixed; + int tracking = from.Skills.Tracking.Fixed; + int detectHidden = from.Skills.DetectHidden.Fixed; if (Core.ML && m.Race == Race.Elf) tracking /= 2; //The 'Guide' says that it requires twice as Much tracking SKILL to track an elf. Not the total difficulty to track. - int hiding = m.Skills[SkillName.Hiding].Fixed; - int stealth = m.Skills[SkillName.Stealth].Fixed; + int hiding = m.Skills.Hiding.Fixed; + int stealth = m.Skills.Stealth.Fixed; int divisor = hiding + stealth; // Necromancy forms affect tracking difficulty diff --git a/Scripts/SpecialSystems/Engines/GiftGiving.cs b/Scripts/SpecialSystems/Engines/GiftGiving.cs index 728e2d0c5..cdd529296 100644 --- a/Scripts/SpecialSystems/Engines/GiftGiving.cs +++ b/Scripts/SpecialSystems/Engines/GiftGiving.cs @@ -61,12 +61,7 @@ namespace Server.Misc public virtual void DelayGiveGift(TimeSpan delay, Mobile mob) { - Timer.DelayCall(delay, new TimerStateCallback(DelayGiveGift_Callback), mob); - } - - protected virtual void DelayGiveGift_Callback(object state) - { - GiveGift((Mobile)state); + Timer.DelayCall(delay, GiveGift, mob); } public virtual GiftResult GiveGift(Mobile mob, Item item) diff --git a/Scripts/SpecialSystems/Engines/TestCenter.cs b/Scripts/SpecialSystems/Engines/TestCenter.cs index 504054fa7..be7018bed 100644 --- a/Scripts/SpecialSystems/Engines/TestCenter.cs +++ b/Scripts/SpecialSystems/Engines/TestCenter.cs @@ -121,9 +121,7 @@ namespace Server.Misc private static void ChangeSkill(Mobile from, string name, double value) { - SkillName index; - - if (!Enum.TryParse(name, true, out index) || !Core.SE && (int)index > 51 || !Core.AOS && (int)index > 48) + if (!Enum.TryParse(name, true, out SkillName index) || !Core.SE && (int)index > 51 || !Core.AOS && (int)index > 48) { from.SendLocalizedMessage(1005631); // You have specified an invalid skill to set. return; diff --git a/Scripts/SpecialSystems/Items/Resurrection/ResGate.cs b/Scripts/SpecialSystems/Items/Resurrection/ResGate.cs index c4d2ebab2..d999b0ac1 100644 --- a/Scripts/SpecialSystems/Items/Resurrection/ResGate.cs +++ b/Scripts/SpecialSystems/Items/Resurrection/ResGate.cs @@ -25,7 +25,7 @@ namespace Server.Items m.PlaySound(0x214); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m)); } else diff --git a/Scripts/Spells/Base/MagerySpell.cs b/Scripts/Spells/Base/MagerySpell.cs index 4f7aa9af0..af1bc26fc 100644 --- a/Scripts/Spells/Base/MagerySpell.cs +++ b/Scripts/Spells/Base/MagerySpell.cs @@ -55,10 +55,10 @@ namespace Server.Spells int maxSkill = (1 + (int)Circle) * 10; maxSkill += (1 + (int)Circle / 6) * 25; - if (m.Skills[SkillName.MagicResist].Value < maxSkill) - m.CheckSkill(SkillName.MagicResist, 0.0, m.Skills[SkillName.MagicResist].Cap); + if (m.Skills.MagicResist.Value < maxSkill) + m.CheckSkill(SkillName.MagicResist, 0.0, m.Skills.MagicResist.Cap); - return m.Skills[SkillName.MagicResist].Value; + return m.Skills.MagicResist.Value; } public virtual bool CheckResisted(Mobile target) @@ -76,16 +76,16 @@ namespace Server.Spells int maxSkill = (1 + (int)Circle) * 10; maxSkill += (1 + (int)Circle / 6) * 25; - if (target.Skills[SkillName.MagicResist].Value < maxSkill) - target.CheckSkill(SkillName.MagicResist, 0.0, target.Skills[SkillName.MagicResist].Cap); + if (target.Skills.MagicResist.Value < maxSkill) + target.CheckSkill(SkillName.MagicResist, 0.0, target.Skills.MagicResist.Cap); return n >= Utility.RandomDouble(); } public virtual double GetResistPercentForCircle(Mobile target, SpellCircle circle) { - double firstPercent = target.Skills[SkillName.MagicResist].Value / 5.0; - double secondPercent = target.Skills[SkillName.MagicResist].Value - + double firstPercent = target.Skills.MagicResist.Value / 5.0; + double secondPercent = target.Skills.MagicResist.Value - ((Caster.Skills[CastSkill].Value - 20.0) / 5.0 + (1 + (int)circle) * 5.0); return (firstPercent > secondPercent ? firstPercent : secondPercent) / diff --git a/Scripts/Spells/Base/Spell.cs b/Scripts/Spells/Base/Spell.cs index 5159d0fd3..5e413fb3e 100644 --- a/Scripts/Spells/Base/Spell.cs +++ b/Scripts/Spells/Base/Spell.cs @@ -89,9 +89,9 @@ namespace Server.Spells if (IsCasting) { - object o = ProtectionSpell.Registry[Caster]; + double d = ProtectionSpell.Registry[Caster]; - if (!(o is double d) || d <= Utility.RandomDouble() * 100.0) + if (d <= Utility.RandomDouble() * 100.0) Disturb(DisturbType.Hurt, false, true); } } @@ -242,7 +242,7 @@ namespace Server.Spells // There is no chance to gain // m.CheckSkill( SkillName.Inscribe, 0.0, 120.0 ); - return m.Skills[SkillName.Inscribe].Value; + return m.Skills.Inscribe.Value; } public virtual int GetInscribeFixed(Mobile m) @@ -250,7 +250,7 @@ namespace Server.Spells // There is no chance to gain // m.CheckSkill( SkillName.Inscribe, 0.0, 120.0 ); - return m.Skills[SkillName.Inscribe].Fixed; + return m.Skills.Inscribe.Fixed; } public virtual int GetDamageFixed(Mobile m) @@ -269,7 +269,7 @@ namespace Server.Spells public virtual double GetResistSkill(Mobile m) { - return m.Skills[SkillName.MagicResist].Value; + return m.Skills.MagicResist.Value; } public virtual double GetDamageScalar(Mobile target) @@ -279,7 +279,7 @@ namespace Server.Spells if (!Core.AOS) //EvalInt stuff for AoS is handled elsewhere { double casterEI = Caster.Skills[DamageSkill].Value; - double targetRS = target.Skills[SkillName.MagicResist].Value; + double targetRS = target.Skills.MagicResist.Value; /* if ( Core.AOS ) @@ -645,7 +645,7 @@ namespace Server.Spells int fcMax = 4; if (CastSkill == SkillName.Magery || CastSkill == SkillName.Necromancy || - CastSkill == SkillName.Chivalry && Caster.Skills[SkillName.Magery].Value >= 70.0) + CastSkill == SkillName.Chivalry && Caster.Skills.Magery.Value >= 70.0) fcMax = 2; int fc = AosAttributes.GetValue(Caster, AosAttribute.CastSpeed); @@ -653,7 +653,7 @@ namespace Server.Spells if (fc > fcMax) fc = fcMax; - if (ProtectionSpell.Registry.Contains(Caster)) + if (ProtectionSpell.Registry.ContainsKey(Caster)) fc -= 2; if (EssenceOfWindSpell.IsDebuffed(Caster)) @@ -911,4 +911,4 @@ namespace Server.Spells } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Base/SpellHelper.cs b/Scripts/Spells/Base/SpellHelper.cs index 07dd3e4d1..b62e79342 100644 --- a/Scripts/Spells/Base/SpellHelper.cs +++ b/Scripts/Spells/Base/SpellHelper.cs @@ -22,7 +22,7 @@ namespace Server { public static void Nullify(Mobile from) { - if (!from.CanBeginAction(typeof(DefensiveSpell))) + if (!from.CanBeginAction()) new InternalTimer(from).Start(); } @@ -40,7 +40,7 @@ namespace Server protected override void OnTick() { - m_Mobile.EndAction(typeof(DefensiveSpell)); + m_Mobile.EndAction(); } } } @@ -333,7 +333,7 @@ namespace Server.Spells if (Core.AOS) return TimeSpan.FromSeconds(6 * caster.Skills.EvalInt.Fixed / 50 + 1); - return TimeSpan.FromSeconds(caster.Skills[SkillName.Magery].Value * 1.2); + return TimeSpan.FromSeconds(caster.Skills.Magery.Value * 1.2); } public static double GetOffsetScalar(Mobile caster, Mobile target, bool curse) @@ -378,7 +378,7 @@ namespace Server.Spells } } - return 1 + (int)(caster.Skills[SkillName.Magery].Value * 0.1); + return 1 + (int)(caster.Skills.Magery.Value * 0.1); } public static Guild GetGuildFor(Mobile m) @@ -484,7 +484,7 @@ namespace Server.Spells if (map == null) return; - double scale = 1.0 + (caster.Skills[SkillName.Magery].Value - 100.0) / 200.0; + double scale = 1.0 + (caster.Skills.Magery.Value - 100.0) / 200.0; if (scaleDuration) duration = TimeSpan.FromSeconds(duration.TotalSeconds * scale); @@ -617,7 +617,7 @@ namespace Server.Spells return false; } - if (caster != null && caster.AccessLevel == AccessLevel.Player && caster.Region.IsPartOf(typeof(Jail))) + if (caster != null && caster.AccessLevel == AccessLevel.Player && caster.Region.IsPartOf()) { caster.SendLocalizedMessage(1114345); // You'll need a better jailbreak plan than that! return false; @@ -698,7 +698,7 @@ namespace Server.Spells public static bool IsFeluccaDungeon(Map map, Point3D loc) { Region region = Region.Find(loc, map); - return region.IsPartOf(typeof(DungeonRegion)) && region.Map == Map.Felucca; + return region.IsPartOf() && region.Map == Map.Felucca; } public static bool IsKhaldun(Map map, Point3D loc) @@ -723,13 +723,11 @@ namespace Server.Spells { #region Duels - if (Region.Find(loc, map).IsPartOf(typeof(SafeZone))) + if (Region.Find(loc, map).IsPartOf()) { if (m_TravelType == TravelCheckType.TeleportTo || m_TravelType == TravelCheckType.TeleportFrom) { - PlayerMobile pm = m_TravelCaster as PlayerMobile; - - if (pm?.DuelPlayer != null && !pm.DuelPlayer.Eliminated) + if (m_TravelCaster is PlayerMobile pm && pm.DuelPlayer != null && !pm.DuelPlayer.Eliminated) return true; } @@ -750,12 +748,12 @@ namespace Server.Spells return false; }*/ - return Region.Find(loc, map).IsPartOf(typeof(StrongholdRegion)); + return Region.Find(loc, map).IsPartOf(); } public static bool IsChampionSpawn(Map map, Point3D loc) { - return Region.Find(loc, map).IsPartOf(typeof(ChampionSpawnRegion)); + return Region.Find(loc, map).IsPartOf(); } public static bool IsDoomFerry(Map map, Point3D loc) @@ -858,11 +856,11 @@ namespace Server.Spells #region Dueling - SafeZone sz = (SafeZone)Region.Find(loc, map).GetRegion(typeof(SafeZone)); + SafeZone sz = Region.Find(loc, map).GetRegion(); if (sz != null) { - PlayerMobile pm = (PlayerMobile)caster; + PlayerMobile pm = caster as PlayerMobile; if (pm?.DuelContext == null || !pm.DuelContext.Started || pm.DuelPlayer == null || pm.DuelPlayer.Eliminated) return true; @@ -870,7 +868,7 @@ namespace Server.Spells #endregion - GuardedRegion reg = (GuardedRegion)Region.Find(loc, map).GetRegion(typeof(GuardedRegion)); + GuardedRegion reg = Region.Find(loc, map).GetRegion(); return reg != null && !reg.IsDisabled(); } @@ -1176,7 +1174,7 @@ namespace Server.Spells return false; } - if (!caster.CanBeginAction(typeof(PolymorphSpell))) + if (!caster.CanBeginAction()) { caster.SendLocalizedMessage(1061628); // You can't do that while polymorphed. return false; @@ -1200,7 +1198,7 @@ namespace Server.Spells { caster.SendLocalizedMessage(1061632); // You can't do that while carrying the sigil. } - else if (!caster.CanBeginAction(typeof(PolymorphSpell))) + else if (!caster.CanBeginAction()) { caster.SendLocalizedMessage(1061628); // You can't do that while polymorphed. } @@ -1213,7 +1211,7 @@ namespace Server.Spells { caster.SendLocalizedMessage(1061091); // You cannot cast that spell in this form. } - else if (!caster.CanBeginAction(typeof(IncognitoSpell)) || caster.IsBodyMod && GetContext(caster) == null) + else if (!caster.CanBeginAction() || caster.IsBodyMod && GetContext(caster) == null) { spell.DoFizzle(); } diff --git a/Scripts/Spells/Bushido/Confidence.cs b/Scripts/Spells/Bushido/Confidence.cs index 602440da7..4520dfb88 100644 --- a/Scripts/Spells/Bushido/Confidence.cs +++ b/Scripts/Spells/Bushido/Confidence.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Spells.Bushido { @@ -11,9 +12,8 @@ namespace Server.Spells.Bushido 9002 ); - private static Hashtable m_Table = new Hashtable(); - - private static Hashtable m_RegenTable = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); + private static Dictionary m_RegenTable = new Dictionary(); public Confidence(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -51,27 +51,22 @@ namespace Server.Spells.Bushido public static bool IsConfident(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public static void BeginConfidence(Mobile m) { - Timer t = (Timer)m_Table[m]; + Timer timer = m_Table[m]; + timer?.Stop(); + m_Table[m] = timer = new InternalTimer(m); - t?.Stop(); - - t = new InternalTimer(m); - - m_Table[m] = t; - - t.Start(); + timer.Start(); } public static void EndConfidence(Mobile m) { - Timer t = (Timer)m_Table[m]; - - t?.Stop(); + Timer timer = m_Table[m]; + timer?.Stop(); m_Table.Remove(m); @@ -80,27 +75,23 @@ namespace Server.Spells.Bushido public static bool IsRegenerating(Mobile m) { - return m_RegenTable.Contains(m); + return m_RegenTable.ContainsKey(m); } public static void BeginRegenerating(Mobile m) { - Timer t = (Timer)m_RegenTable[m]; + Timer timer = m_RegenTable[m]; + timer?.Stop(); - t?.Stop(); + m_RegenTable[m] = timer = new RegenTimer(m); - t = new RegenTimer(m); - - m_RegenTable[m] = t; - - t.Start(); + timer.Start(); } public static void StopRegenerating(Mobile m) { - Timer t = (Timer)m_RegenTable[m]; - - t?.Stop(); + Timer timer = m_RegenTable[m]; + timer?.Stop(); m_RegenTable.Remove(m); } @@ -149,4 +140,4 @@ namespace Server.Spells.Bushido } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Bushido/CounterAttack.cs b/Scripts/Spells/Bushido/CounterAttack.cs index 849fb2eca..281e0685b 100644 --- a/Scripts/Spells/Bushido/CounterAttack.cs +++ b/Scripts/Spells/Bushido/CounterAttack.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; namespace Server.Spells.Bushido @@ -12,7 +13,7 @@ namespace Server.Spells.Bushido 9002 ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public CounterAttack(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -28,13 +29,13 @@ namespace Server.Spells.Bushido if (!base.CheckCast()) return false; - if (Caster.FindItemOnLayer(Layer.TwoHanded) as BaseShield != null) + if (Caster.FindItemOnLayer(Layer.TwoHanded) is BaseShield) return true; - if (Caster.FindItemOnLayer(Layer.OneHanded) as BaseWeapon != null) + if (Caster.FindItemOnLayer(Layer.OneHanded) is BaseWeapon) return true; - if (Caster.FindItemOnLayer(Layer.TwoHanded) as BaseWeapon != null) + if (Caster.FindItemOnLayer(Layer.TwoHanded) is BaseWeapon) return true; Caster.SendLocalizedMessage(1062944); // You must have a weapon or a shield equipped to use this ability! @@ -64,27 +65,23 @@ namespace Server.Spells.Bushido public static bool IsCountering(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public static void StartCountering(Mobile m) { - Timer t = (Timer)m_Table[m]; + Timer timer = m_Table[m]; + timer?.Stop(); - t?.Stop(); + m_Table[m] = timer = new InternalTimer(m); - t = new InternalTimer(m); - - m_Table[m] = t; - - t.Start(); + timer.Start(); } public static void StopCountering(Mobile m) { - Timer t = (Timer)m_Table[m]; - - t?.Stop(); + Timer timer = m_Table[m]; + timer?.Stop(); m_Table.Remove(m); @@ -108,4 +105,4 @@ namespace Server.Spells.Bushido } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Bushido/Evasion.cs b/Scripts/Spells/Bushido/Evasion.cs index 6213eca09..a8952a7e6 100644 --- a/Scripts/Spells/Bushido/Evasion.cs +++ b/Scripts/Spells/Bushido/Evasion.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; namespace Server.Spells.Bushido @@ -12,7 +13,7 @@ namespace Server.Spells.Bushido 9002 ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public Evasion(Mobile caster, Item scroll) : base(caster, scroll, m_Info) @@ -57,7 +58,7 @@ namespace Server.Spells.Bushido return false; } - if (!Caster.CanBeginAction(typeof(Evasion))) + if (!Caster.CanBeginAction()) { if (messages) Caster.SendLocalizedMessage(501789); // You must wait before trying again. return false; @@ -114,8 +115,8 @@ namespace Server.Spells.Bushido BeginEvasion(Caster); - Caster.BeginAction(typeof(Evasion)); - Timer.DelayCall(TimeSpan.FromSeconds(20.0), delegate { Caster.EndAction(typeof(Evasion)); }); + Caster.BeginAction(); + Timer.DelayCall(TimeSpan.FromSeconds(20.0), delegate { Caster.EndAction(); }); } FinishSequence(); @@ -123,7 +124,7 @@ namespace Server.Spells.Bushido public static bool IsEvading(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public static TimeSpan GetEvadeDuration(Mobile m) @@ -179,22 +180,17 @@ namespace Server.Spells.Bushido public static void BeginEvasion(Mobile m) { - Timer t = (Timer)m_Table[m]; + Timer timer = m_Table[m]; + timer?.Stop(); - t?.Stop(); - - t = new InternalTimer(m, GetEvadeDuration(m)); - - m_Table[m] = t; - - t.Start(); + m_Table[m] = timer = new InternalTimer(m, GetEvadeDuration(m)); + timer.Start(); } public static void EndEvasion(Mobile m) { - Timer t = (Timer)m_Table[m]; - - t?.Stop(); + Timer timer = m_Table[m]; + timer?.Stop(); m_Table.Remove(m); @@ -219,4 +215,4 @@ namespace Server.Spells.Bushido } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Bushido/HonorableExecution.cs b/Scripts/Spells/Bushido/HonorableExecution.cs index 62c89abe4..5861f1de9 100644 --- a/Scripts/Spells/Bushido/HonorableExecution.cs +++ b/Scripts/Spells/Bushido/HonorableExecution.cs @@ -1,11 +1,12 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Spells.Bushido { public class HonorableExecution : SamuraiMove { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 0; public override double RequiredSkill => 25.0; @@ -15,7 +16,7 @@ namespace Server.Spells.Bushido public override double GetDamageScalar(Mobile attacker, Mobile defender) { - double bushido = attacker.Skills[SkillName.Bushido].Value; + double bushido = attacker.Skills.Bushido.Value; // TODO: 20 -> Perfection return 1.0 + bushido * 20 / 10000; @@ -28,10 +29,11 @@ namespace Server.Spells.Bushido ClearCurrentMove(attacker); - if (m_Table[attacker] is HonorableExecutionInfo info) + HonorableExecutionInfo info = m_Table[attacker]; + + if (info != null) { info.Clear(); - info.m_Timer?.Stop(); } @@ -39,20 +41,20 @@ namespace Server.Spells.Bushido { attacker.FixedParticles(0x373A, 1, 17, 0x7E2, EffectLayer.Waist); - double bushido = attacker.Skills[SkillName.Bushido].Value; + double bushido = attacker.Skills.Bushido.Value; attacker.Hits += 20 + (int)(bushido * bushido / 480.0); int swingBonus = Math.Max(1, (int)(bushido * bushido / 720.0)); info = new HonorableExecutionInfo(attacker, swingBonus); - info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(20.0), new TimerStateCallback(EndEffect), info); + info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(20.0), RemovePenalty, info.m_Mobile); m_Table[attacker] = info; } else { - ArrayList mods = new ArrayList + List mods = new List { new ResistanceMod(ResistanceType.Physical, -40), new ResistanceMod(ResistanceType.Fire, -40), @@ -60,14 +62,14 @@ namespace Server.Spells.Bushido new ResistanceMod(ResistanceType.Poison, -40), new ResistanceMod(ResistanceType.Energy, -40) }; - - double resSpells = attacker.Skills[SkillName.MagicResist].Value; + + double resSpells = attacker.Skills.MagicResist.Value; if (resSpells > 0.0) mods.Add(new DefaultSkillMod(SkillName.MagicResist, true, -resSpells)); info = new HonorableExecutionInfo(attacker, mods); - info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(7.0), new TimerStateCallback(EndEffect), info); + info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(7.0), RemovePenalty, info.m_Mobile); m_Table[attacker] = info; } @@ -103,24 +105,19 @@ namespace Server.Spells.Bushido m_Table.Remove(target); } - public void EndEffect(object state) - { - RemovePenalty(((HonorableExecutionInfo)state).m_Mobile); - } - private class HonorableExecutionInfo { public Mobile m_Mobile; - public ArrayList m_Mods; + public List m_Mods; public bool m_Penalty; public int m_SwingBonus; public Timer m_Timer; - public HonorableExecutionInfo(Mobile from, ArrayList mods) : this(from, 0, mods, true) + public HonorableExecutionInfo(Mobile from, List mods) : this(from, 0, mods, true) { } - public HonorableExecutionInfo(Mobile from, int swingBonus, ArrayList mods = null, bool penalty = false) + public HonorableExecutionInfo(Mobile from, int swingBonus, List mods = null, bool penalty = false) { m_Mobile = from; m_SwingBonus = swingBonus; @@ -163,4 +160,4 @@ namespace Server.Spells.Bushido } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Bushido/LightningStrike.cs b/Scripts/Spells/Bushido/LightningStrike.cs index af3b105d4..8ee5ed951 100644 --- a/Scripts/Spells/Bushido/LightningStrike.cs +++ b/Scripts/Spells/Bushido/LightningStrike.cs @@ -32,7 +32,7 @@ namespace Server.Spells.Bushido public override bool IgnoreArmor(Mobile attacker) { - double bushido = attacker.Skills[SkillName.Bushido].Value; + double bushido = attacker.Skills.Bushido.Value; double criticalChance = bushido * bushido / 72000.0; return criticalChance >= Utility.RandomDouble(); } diff --git a/Scripts/Spells/Bushido/MomentumStrike.cs b/Scripts/Spells/Bushido/MomentumStrike.cs index 5b53c3bf6..1d96a48eb 100644 --- a/Scripts/Spells/Bushido/MomentumStrike.cs +++ b/Scripts/Spells/Bushido/MomentumStrike.cs @@ -40,7 +40,7 @@ namespace Server.Spells.Bushido Mobile target = targets[Utility.Random(targets.Count)]; - double damageBonus = attacker.Skills[SkillName.Bushido].Value / 100.0; + double damageBonus = attacker.Skills.Bushido.Value / 100.0; if (!defender.Alive) damageBonus *= 1.5; diff --git a/Scripts/Spells/Chivalry/CleanseByFire.cs b/Scripts/Spells/Chivalry/CleanseByFire.cs index a12717909..3c7550d5e 100644 --- a/Scripts/Spells/Chivalry/CleanseByFire.cs +++ b/Scripts/Spells/Chivalry/CleanseByFire.cs @@ -58,7 +58,7 @@ namespace Server.Spells.Chivalry if (p != null) { // Cleanse by fire is now difficulty based - int chanceToCure = 10000 + (int)(Caster.Skills[SkillName.Chivalry].Value * 75) - (p.Level + 1) * 2000; + int chanceToCure = 10000 + (int)(Caster.Skills.Chivalry.Value * 75) - (p.Level + 1) * 2000; chanceToCure /= 100; if (chanceToCure > Utility.Random(100)) diff --git a/Scripts/Spells/Chivalry/ConsecrateWeapon.cs b/Scripts/Spells/Chivalry/ConsecrateWeapon.cs index dc5d2f8fb..a97ea0fbb 100644 --- a/Scripts/Spells/Chivalry/ConsecrateWeapon.cs +++ b/Scripts/Spells/Chivalry/ConsecrateWeapon.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; namespace Server.Spells.Chivalry @@ -12,7 +13,7 @@ namespace Server.Spells.Chivalry 9002 ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public ConsecrateWeaponSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -77,15 +78,14 @@ namespace Server.Spells.Chivalry TimeSpan duration = TimeSpan.FromSeconds(seconds); - Timer t = (Timer)m_Table[weapon]; - - t?.Stop(); + ExpireTimer timer = m_Table[weapon]; + timer?.Stop(); weapon.Consecrated = true; - m_Table[weapon] = t = new ExpireTimer(weapon, duration); + m_Table[weapon] = timer = new ExpireTimer(weapon, duration); - t.Start(); + timer.Start(); } FinishSequence(); @@ -105,8 +105,8 @@ namespace Server.Spells.Chivalry { m_Weapon.Consecrated = false; Effects.PlaySound(m_Weapon.GetWorldLocation(), m_Weapon.Map, 0x1F8); - m_Table.Remove(this); + m_Table.Remove(m_Weapon); } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Chivalry/DivineFury.cs b/Scripts/Spells/Chivalry/DivineFury.cs index bea8dcfcb..bd95f62aa 100644 --- a/Scripts/Spells/Chivalry/DivineFury.cs +++ b/Scripts/Spells/Chivalry/DivineFury.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Spells.Chivalry { @@ -11,7 +12,7 @@ namespace Server.Spells.Chivalry 9002 ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public DivineFurySpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -36,9 +37,8 @@ namespace Server.Spells.Chivalry Caster.Stam = Caster.StamMax; - Timer t = (Timer)m_Table[Caster]; - - t?.Stop(); + Timer timer = m_Table[Caster]; + timer?.Stop(); int delay = ComputePowerValue(10); @@ -48,8 +48,7 @@ namespace Server.Spells.Chivalry else if (delay > 24) delay = 24; - m_Table[Caster] = t = Timer.DelayCall(TimeSpan.FromSeconds(delay), new TimerStateCallback(Expire_Callback), - Caster); + m_Table[Caster] = Timer.DelayCall(TimeSpan.FromSeconds(delay), Expire_Callback, Caster); Caster.Delta(MobileDelta.WeaponDamage); BuffInfo.AddBuff(Caster, @@ -61,17 +60,15 @@ namespace Server.Spells.Chivalry public static bool UnderEffect(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } - private static void Expire_Callback(object state) + private static void Expire_Callback(Mobile m) { - Mobile m = (Mobile)state; - m_Table.Remove(m); m.Delta(MobileDelta.WeaponDamage); m.PlaySound(0xF8); } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Chivalry/EnemyOfOne.cs b/Scripts/Spells/Chivalry/EnemyOfOne.cs index 8382d357c..ee429ae36 100644 --- a/Scripts/Spells/Chivalry/EnemyOfOne.cs +++ b/Scripts/Spells/Chivalry/EnemyOfOne.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Mobiles; namespace Server.Spells.Chivalry @@ -12,7 +13,7 @@ namespace Server.Spells.Chivalry 9002 ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public EnemyOfOneSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -35,9 +36,8 @@ namespace Server.Spells.Chivalry Caster.FixedParticles(0x375A, 1, 30, 9966, 33, 2, EffectLayer.Head); Caster.FixedParticles(0x37B9, 1, 30, 9502, 43, 3, EffectLayer.Head); - Timer t = (Timer)m_Table[Caster]; - - t?.Stop(); + Timer timer = m_Table[Caster]; + timer?.Stop(); double delay = (double)ComputePowerValue(1) / 60; @@ -47,8 +47,7 @@ namespace Server.Spells.Chivalry else if (delay > 3.5) delay = 3.5; - m_Table[Caster] = Timer.DelayCall(TimeSpan.FromMinutes(delay), new TimerStateCallback(Expire_Callback), - Caster); + m_Table[Caster] = Timer.DelayCall(TimeSpan.FromMinutes(delay), Expire_Callback, Caster); if (Caster is PlayerMobile mobile) { @@ -63,10 +62,8 @@ namespace Server.Spells.Chivalry FinishSequence(); } - private static void Expire_Callback(object state) + private static void Expire_Callback(Mobile m) { - Mobile m = (Mobile)state; - m_Table.Remove(m); m.PlaySound(0x1F8); @@ -78,4 +75,4 @@ namespace Server.Spells.Chivalry } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Chivalry/NobleSacrifice.cs b/Scripts/Spells/Chivalry/NobleSacrifice.cs index 3591af33e..97a8b806b 100644 --- a/Scripts/Spells/Chivalry/NobleSacrifice.cs +++ b/Scripts/Spells/Chivalry/NobleSacrifice.cs @@ -62,7 +62,7 @@ namespace Server.Spells.Chivalry if (!m.Alive) { - if (m.Region != null && m.Region.IsPartOf("Khaldun")) + if (m.Region?.IsPartOf("Khaldun") == true) { Caster.SendLocalizedMessage( 1010395); // The veil of death in this area is too strong and resists thy efforts to restore life. @@ -70,7 +70,7 @@ namespace Server.Spells.Chivalry else if (resChance > Utility.RandomDouble()) { m.FixedParticles(0x375A, 1, 15, 5005, 5, 3, EffectLayer.Head); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, Caster)); sacrifice = true; } diff --git a/Scripts/Spells/Eighth/Earthquake.cs b/Scripts/Spells/Eighth/Earthquake.cs index 115b3e9d7..4be387c45 100644 --- a/Scripts/Spells/Eighth/Earthquake.cs +++ b/Scripts/Spells/Eighth/Earthquake.cs @@ -33,7 +33,7 @@ namespace Server.Spells.Eighth Map map = Caster.Map; if (map != null) - foreach (Mobile m in Caster.GetMobilesInRange(1 + (int)(Caster.Skills[SkillName.Magery].Value / 15.0))) + foreach (Mobile m in Caster.GetMobilesInRange(1 + (int)(Caster.Skills.Magery.Value / 15.0))) if (Caster != m && SpellHelper.ValidIndirectTarget(Caster, m) && Caster.CanBeHarmful(m, false) && (!Core.AOS || Caster.InLOS(m))) targets.Add(m); diff --git a/Scripts/Spells/Eighth/Resurrection.cs b/Scripts/Spells/Eighth/Resurrection.cs index 34b350685..7c41b1e49 100644 --- a/Scripts/Spells/Eighth/Resurrection.cs +++ b/Scripts/Spells/Eighth/Resurrection.cs @@ -68,7 +68,7 @@ namespace Server.Spells.Eighth Caster.SendLocalizedMessage(501042); // Target can not be resurrected at that location. m.SendLocalizedMessage(502391); // Thou can not be resurrected there! } - else if (m.Region != null && m.Region.IsPartOf("Khaldun")) + else if (m.Region?.IsPartOf("Khaldun") == true) { Caster.SendLocalizedMessage( 1010395); // The veil of death in this area is too strong and resists thy efforts to restore life. @@ -80,7 +80,7 @@ namespace Server.Spells.Eighth m.PlaySound(0x214); m.FixedEffect(0x376A, 10, 16); - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, Caster)); } diff --git a/Scripts/Spells/Fifth/Incognito.cs b/Scripts/Spells/Fifth/Incognito.cs index 90237e643..d6203c7d3 100644 --- a/Scripts/Spells/Fifth/Incognito.cs +++ b/Scripts/Spells/Fifth/Incognito.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Factions; using Server.Items; using Server.Mobiles; @@ -18,22 +19,7 @@ namespace Server.Spells.Fifth Reagent.Nightshade ); - private static Hashtable m_Timers = new Hashtable(); - - private static int[] m_HairIDs = - { - 0x2044, 0x2045, 0x2046, - 0x203C, 0x203B, 0x203D, - 0x2047, 0x2048, 0x2049, - 0x204A, 0x0000 - }; - - private static int[] m_BeardIDs = - { - 0x203E, 0x203F, 0x2040, - 0x2041, 0x204B, 0x204C, - 0x204D, 0x0000 - }; + private static Dictionary m_Timers = new Dictionary(); public IncognitoSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -49,7 +35,7 @@ namespace Server.Spells.Fifth return false; } - if (!Caster.CanBeginAction(typeof(IncognitoSpell))) + if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1005559); // This spell is already in effect. return false; @@ -70,7 +56,7 @@ namespace Server.Spells.Fifth { Caster.SendLocalizedMessage(1010445); // You cannot incognito if you have a sigil } - else if (!Caster.CanBeginAction(typeof(IncognitoSpell))) + else if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1005559); // This spell is already in effect. } @@ -82,13 +68,13 @@ namespace Server.Spells.Fifth { Caster.SendLocalizedMessage(1061631); // You can't do that while disguised. } - else if (!Caster.CanBeginAction(typeof(PolymorphSpell)) || Caster.IsBodyMod) + else if (!Caster.CanBeginAction() || Caster.IsBodyMod) { DoFizzle(); } else if (CheckSequence()) { - if (Caster.BeginAction(typeof(IncognitoSpell))) + if (Caster.BeginAction()) { DisguiseTimers.StopTimer(Caster); @@ -121,8 +107,7 @@ namespace Server.Spells.Fifth TimeSpan length = TimeSpan.FromSeconds(timeVal); - Timer t = new InternalTimer(Caster, length); - + InternalTimer t = new InternalTimer(Caster, length); m_Timers[Caster] = t; t.Start(); @@ -138,18 +123,16 @@ namespace Server.Spells.Fifth FinishSequence(); } - public static bool StopTimer(Mobile m) + public static void StopTimer(Mobile m) { - Timer t = (Timer)m_Timers[m]; + Timer t = m_Timers[m]; - if (t != null) - { - t.Stop(); - m_Timers.Remove(m); - BuffInfo.RemoveBuff(m, BuffIcon.Incognito); - } + if (t == null) + return; - return t != null; + t.Stop(); + m_Timers.Remove(m); + BuffInfo.RemoveBuff(m, BuffIcon.Incognito); } private class InternalTimer : Timer @@ -173,14 +156,14 @@ namespace Server.Spells.Fifth protected override void OnTick() { - if (!m_Owner.CanBeginAction(typeof(IncognitoSpell))) + if (!m_Owner.CanBeginAction()) { (m_Owner as PlayerMobile)?.SetHairMods(-1, -1); m_Owner.BodyMod = 0; m_Owner.HueMod = -1; m_Owner.NameMod = null; - m_Owner.EndAction(typeof(IncognitoSpell)); + m_Owner.EndAction(); BaseArmor.ValidateMobile(m_Owner); BaseClothing.ValidateMobile(m_Owner); @@ -188,4 +171,4 @@ namespace Server.Spells.Fifth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Fifth/MagicReflect.cs b/Scripts/Spells/Fifth/MagicReflect.cs index c2b794b5f..99f95768b 100644 --- a/Scripts/Spells/Fifth/MagicReflect.cs +++ b/Scripts/Spells/Fifth/MagicReflect.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; namespace Server.Spells.Fifth { @@ -13,7 +14,7 @@ namespace Server.Spells.Fifth Reagent.SpidersSilk ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public MagicReflectSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -32,7 +33,7 @@ namespace Server.Spells.Fifth return false; } - if (!Caster.CanBeginAction(typeof(DefensiveSpell))) + if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1005385); // The spell will not adhere to you at this time. return false; @@ -56,17 +57,17 @@ namespace Server.Spells.Fifth { Mobile targ = Caster; - ResistanceMod[] mods = (ResistanceMod[])m_Table[targ]; + ResistanceMod[] mods = m_Table[targ]; if (mods == null) { targ.PlaySound(0x1E9); targ.FixedParticles(0x375A, 10, 15, 5037, EffectLayer.Waist); - int physiMod = -25 + (int)(targ.Skills[SkillName.Inscribe].Value / 20); + int physiMod = -25 + (int)(targ.Skills.Inscribe.Value / 20); int otherMod = 10; - mods = new ResistanceMod[5] + mods = new[] { new ResistanceMod(ResistanceType.Physical, physiMod), new ResistanceMod(ResistanceType.Fire, otherMod), @@ -106,15 +107,15 @@ namespace Server.Spells.Fifth { Caster.SendLocalizedMessage(1005559); // This spell is already in effect. } - else if (!Caster.CanBeginAction(typeof(DefensiveSpell))) + else if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1005385); // The spell will not adhere to you at this time. } else if (CheckSequence()) { - if (Caster.BeginAction(typeof(DefensiveSpell))) + if (Caster.BeginAction()) { - int value = (int)(Caster.Skills[SkillName.Magery].Value + Caster.Skills[SkillName.Inscribe].Value); + int value = (int)(Caster.Skills.Magery.Value + Caster.Skills.Inscribe.Value); value = (int)(8 + value / 200 * 7.0); //absorb from 8 to 15 "circles" Caster.MagicDamageAbsorb = value; @@ -134,17 +135,16 @@ namespace Server.Spells.Fifth public static void EndReflect(Mobile m) { - if (m_Table.Contains(m)) - { - ResistanceMod[] mods = (ResistanceMod[])m_Table[m]; + ResistanceMod[] mods = m_Table[m]; - if (mods != null) - for (int i = 0; i < mods.Length; ++i) - m.RemoveResistanceMod(mods[i]); + if (mods != null) + { + for (int i = 0; i < mods.Length; ++i) + m.RemoveResistanceMod(mods[i]); m_Table.Remove(m); BuffInfo.RemoveBuff(m, BuffIcon.MagicReflection); } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Fifth/MindBlast.cs b/Scripts/Spells/Fifth/MindBlast.cs index 559fe882e..a0cd18622 100644 --- a/Scripts/Spells/Fifth/MindBlast.cs +++ b/Scripts/Spells/Fifth/MindBlast.cs @@ -30,14 +30,8 @@ namespace Server.Spells.Fifth Caster.Target = new InternalTarget(this); } - private void AosDelay_Callback(object state) + private void AosDelay_Callback(Mobile caster, Mobile target, Mobile defender, int damage) { - object[] states = (object[])state; - Mobile caster = (Mobile)states[0]; - Mobile target = (Mobile)states[1]; - Mobile defender = (Mobile)states[2]; - int damage = (int)states[3]; - if (caster.HarmfulCheck(defender)) { SpellHelper.Damage(this, target, Utility.RandomMinMax(damage, damage + 4), 0, 0, 100, 0, 0); @@ -63,14 +57,13 @@ namespace Server.Spells.Fifth SpellHelper.CheckReflect((int)Circle, ref from, ref target); - int damage = (int)((Caster.Skills[SkillName.Magery].Value + Caster.Int) / 5); + int damage = (int)((Caster.Skills.Magery.Value + Caster.Int) / 5); if (damage > 60) damage = 60; Timer.DelayCall(TimeSpan.FromSeconds(1.0), - new TimerStateCallback(AosDelay_Callback), - new object[] { Caster, target, m, damage }); + () => AosDelay_Callback(Caster, target, m, damage)); } } else if (CheckHSequence(m)) diff --git a/Scripts/Spells/Fifth/Paralyze.cs b/Scripts/Spells/Fifth/Paralyze.cs index 56cf9727f..b5f0892e1 100644 --- a/Scripts/Spells/Fifth/Paralyze.cs +++ b/Scripts/Spells/Fifth/Paralyze.cs @@ -65,7 +65,7 @@ namespace Server.Spells.Fifth { // Algorithm: ((20% of magery) + 7) seconds [- 50% if resisted] - duration = 7.0 + Caster.Skills[SkillName.Magery].Value * 0.2; + duration = 7.0 + Caster.Skills.Magery.Value * 0.2; if (CheckResisted(m)) duration *= 0.75; diff --git a/Scripts/Spells/Fifth/SummonCreature.cs b/Scripts/Spells/Fifth/SummonCreature.cs index 69b31e9b7..4e848f32c 100644 --- a/Scripts/Spells/Fifth/SummonCreature.cs +++ b/Scripts/Spells/Fifth/SummonCreature.cs @@ -72,7 +72,7 @@ namespace Server.Spells.Fifth if (Core.AOS) duration = TimeSpan.FromSeconds(2 * Caster.Skills.Magery.Fixed / 5); else - duration = TimeSpan.FromSeconds(4.0 * Caster.Skills[SkillName.Magery].Value); + duration = TimeSpan.FromSeconds(4.0 * Caster.Skills.Magery.Value); SpellHelper.Summon(creature, Caster, 0x215, duration, false, false); } diff --git a/Scripts/Spells/First/Heal.cs b/Scripts/Spells/First/Heal.cs index 57dd26eff..77118315d 100644 --- a/Scripts/Spells/First/Heal.cs +++ b/Scripts/Spells/First/Heal.cs @@ -77,7 +77,7 @@ namespace Server.Spells.First } else { - toHeal = (int)(Caster.Skills[SkillName.Magery].Value * 0.1); + toHeal = (int)(Caster.Skills.Magery.Value * 0.1); toHeal += Utility.Random(1, 5); } diff --git a/Scripts/Spells/First/NightSight.cs b/Scripts/Spells/First/NightSight.cs index 79ba72b43..c43ab9a44 100644 --- a/Scripts/Spells/First/NightSight.cs +++ b/Scripts/Spells/First/NightSight.cs @@ -38,13 +38,13 @@ namespace Server.Spells.First { SpellHelper.Turn(m_Spell.Caster, targ); - if (targ.BeginAction(typeof(LightCycle))) + if (targ.BeginAction()) { new LightCycle.NightSightTimer(targ).Start(); int level = (int)(LightCycle.DungeonLevel * ((Core.AOS - ? targ.Skills[SkillName.Magery].Value - : from.Skills[SkillName.Magery].Value) / 100)); + ? targ.Skills.Magery.Value + : from.Skills.Magery.Value) / 100)); if (level < 0) level = 0; diff --git a/Scripts/Spells/First/ReactiveArmor.cs b/Scripts/Spells/First/ReactiveArmor.cs index 4b611fb57..85ea4a7a0 100644 --- a/Scripts/Spells/First/ReactiveArmor.cs +++ b/Scripts/Spells/First/ReactiveArmor.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; namespace Server.Spells.First { @@ -13,7 +14,7 @@ namespace Server.Spells.First Reagent.SulfurousAsh ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public ReactiveArmorSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -32,7 +33,7 @@ namespace Server.Spells.First return false; } - if (!Caster.CanBeginAction(typeof(DefensiveSpell))) + if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1005385); // The spell will not adhere to you at this time. return false; @@ -57,17 +58,17 @@ namespace Server.Spells.First { Mobile targ = Caster; - ResistanceMod[] mods = (ResistanceMod[])m_Table[targ]; + ResistanceMod[] mods = m_Table[targ]; if (mods == null) { targ.PlaySound(0x1E9); targ.FixedParticles(0x376A, 9, 32, 5008, EffectLayer.Waist); - mods = new ResistanceMod[5] + mods = new [] { new ResistanceMod(ResistanceType.Physical, - 15 + (int)(targ.Skills[SkillName.Inscribe].Value / 20)), + 15 + (int)(targ.Skills.Inscribe.Value / 20)), new ResistanceMod(ResistanceType.Fire, -5), new ResistanceMod(ResistanceType.Cold, -5), new ResistanceMod(ResistanceType.Poison, -5), @@ -79,7 +80,7 @@ namespace Server.Spells.First for (int i = 0; i < mods.Length; ++i) targ.AddResistanceMod(mods[i]); - int physresist = 15 + (int)(targ.Skills[SkillName.Inscribe].Value / 20); + int physresist = 15 + (int)(targ.Skills.Inscribe.Value / 20); string args = $"{physresist}\t{5}\t{5}\t{5}\t{5}"; BuffInfo.AddBuff(Caster, new BuffInfo(BuffIcon.ReactiveArmor, 1075812, 1075813, args)); @@ -106,16 +107,16 @@ namespace Server.Spells.First { Caster.SendLocalizedMessage(1005559); // This spell is already in effect. } - else if (!Caster.CanBeginAction(typeof(DefensiveSpell))) + else if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1005385); // The spell will not adhere to you at this time. } else if (CheckSequence()) { - if (Caster.BeginAction(typeof(DefensiveSpell))) + if (Caster.BeginAction()) { - int value = (int)(Caster.Skills[SkillName.Magery].Value + Caster.Skills[SkillName.Meditation].Value + - Caster.Skills[SkillName.Inscribe].Value); + int value = (int)(Caster.Skills.Magery.Value + Caster.Skills.Meditation.Value + + Caster.Skills.Inscribe.Value); value /= 3; if (value < 0) @@ -140,17 +141,16 @@ namespace Server.Spells.First public static void EndArmor(Mobile m) { - if (m_Table.Contains(m)) - { - ResistanceMod[] mods = (ResistanceMod[])m_Table[m]; + ResistanceMod[] mods = m_Table[m]; - if (mods != null) - for (int i = 0; i < mods.Length; ++i) - m.RemoveResistanceMod(mods[i]); + if (mods != null) + { + for (int i = 0; i < mods.Length; ++i) + m.RemoveResistanceMod(mods[i]); m_Table.Remove(m); BuffInfo.RemoveBuff(m, BuffIcon.ReactiveArmor); } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Fourth/ArchCure.cs b/Scripts/Spells/Fourth/ArchCure.cs index 26faa81c2..6b8cfbf4f 100644 --- a/Scripts/Spells/Fourth/ArchCure.cs +++ b/Scripts/Spells/Fourth/ArchCure.cs @@ -85,7 +85,7 @@ namespace Server.Spells.Fourth if (poison != null) { - int chanceToCure = 10000 + (int)(Caster.Skills[SkillName.Magery].Value * 75) - + int chanceToCure = 10000 + (int)(Caster.Skills.Magery.Value * 75) - (poison.Level + 1) * 1750; chanceToCure /= 100; chanceToCure -= 1; diff --git a/Scripts/Spells/Fourth/ArchProtection.cs b/Scripts/Spells/Fourth/ArchProtection.cs index 56ad0133c..90b3f28d1 100644 --- a/Scripts/Spells/Fourth/ArchProtection.cs +++ b/Scripts/Spells/Fourth/ArchProtection.cs @@ -77,14 +77,14 @@ namespace Server.Spells.Fourth { Effects.PlaySound(p, Caster.Map, 0x299); - int val = (int)(Caster.Skills[SkillName.Magery].Value / 10.0 + 1); + int val = (int)(Caster.Skills.Magery.Value / 10.0 + 1); if (targets.Count > 0) for (int i = 0; i < targets.Count; ++i) { Mobile m = targets[i]; - if (m.BeginAction(typeof(ArchProtectionSpell))) + if (m.BeginAction()) { Caster.DoBeneficial(m); m.VirtualArmorMod += val; @@ -113,7 +113,7 @@ namespace Server.Spells.Fourth { int v = _Table[m]; _Table.Remove(m); - m.EndAction(typeof(ArchProtectionSpell)); + m.EndAction(); m.VirtualArmorMod -= v; if (m.VirtualArmorMod < 0) m.VirtualArmorMod = 0; @@ -126,7 +126,7 @@ namespace Server.Spells.Fourth public InternalTimer(Mobile target, Mobile caster) : base(TimeSpan.FromSeconds(0)) { - double time = caster.Skills[SkillName.Magery].Value * 1.2; + double time = caster.Skills.Magery.Value * 1.2; if (time > 144) time = 144; Delay = TimeSpan.FromSeconds(time); diff --git a/Scripts/Spells/Fourth/Curse.cs b/Scripts/Spells/Fourth/Curse.cs index 12cb41452..301dc05a0 100644 --- a/Scripts/Spells/Fourth/Curse.cs +++ b/Scripts/Spells/Fourth/Curse.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Targeting; namespace Server.Spells.Fourth @@ -15,7 +16,7 @@ namespace Server.Spells.Fourth Reagent.SulfurousAsh ); - private static Hashtable m_UnderEffect = new Hashtable(); + private static Dictionary m_UnderEffect = new Dictionary(); public CurseSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -28,10 +29,8 @@ namespace Server.Spells.Fourth Caster.Target = new InternalTarget(this); } - public static void RemoveEffect(object state) + public static void RemoveEffect(Mobile m) { - Mobile m = (Mobile)state; - m_UnderEffect.Remove(m); m.UpdateResistances(); @@ -39,7 +38,7 @@ namespace Server.Spells.Fourth public static bool UnderEffect(Mobile m) { - return m_UnderEffect.Contains(m); + return m_UnderEffect.ContainsKey(m); } public void Target(Mobile m) @@ -60,13 +59,13 @@ namespace Server.Spells.Fourth SpellHelper.AddStatCurse(Caster, m, StatType.Int); SpellHelper.DisableSkillCheck = false; - Timer t = (Timer)m_UnderEffect[m]; + Timer t = m_UnderEffect[m]; if (Caster.Player && m.Player /*&& Caster != m */ && t == null ) //On OSI you CAN curse yourself and get this effect. { TimeSpan duration = SpellHelper.GetDuration(Caster, m); - m_UnderEffect[m] = Timer.DelayCall(duration, new TimerStateCallback(RemoveEffect), m); + m_UnderEffect[m] = Timer.DelayCall(duration, RemoveEffect, m); m.UpdateResistances(); } @@ -111,4 +110,4 @@ namespace Server.Spells.Fourth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Fourth/FireField.cs b/Scripts/Spells/Fourth/FireField.cs index 7f4278d78..a5388cbb2 100644 --- a/Scripts/Spells/Fourth/FireField.cs +++ b/Scripts/Spells/Fourth/FireField.cs @@ -67,7 +67,7 @@ namespace Server.Spells.Fourth if (Core.AOS) duration = TimeSpan.FromSeconds((15 + Caster.Skills.Magery.Fixed / 5) / 4); else - duration = TimeSpan.FromSeconds(4.0 + Caster.Skills[SkillName.Magery].Value * 0.5); + duration = TimeSpan.FromSeconds(4.0 + Caster.Skills.Magery.Value * 0.5); for (int i = -2; i <= 2; ++i) { diff --git a/Scripts/Spells/Fourth/GreaterHeal.cs b/Scripts/Spells/Fourth/GreaterHeal.cs index f76cfeaa0..39aee8a86 100644 --- a/Scripts/Spells/Fourth/GreaterHeal.cs +++ b/Scripts/Spells/Fourth/GreaterHeal.cs @@ -68,7 +68,7 @@ namespace Server.Spells.Fourth // Algorithm: (40% of magery) + (1-10) - int toHeal = (int)(Caster.Skills[SkillName.Magery].Value * 0.4); + int toHeal = (int)(Caster.Skills.Magery.Value * 0.4); toHeal += Utility.Random(1, 10); //m.Heal( toHeal, Caster ); diff --git a/Scripts/Spells/Fourth/ManaDrain.cs b/Scripts/Spells/Fourth/ManaDrain.cs index 355d617e0..71ea6f192 100644 --- a/Scripts/Spells/Fourth/ManaDrain.cs +++ b/Scripts/Spells/Fourth/ManaDrain.cs @@ -28,13 +28,8 @@ namespace Server.Spells.Fourth Caster.Target = new InternalTarget(this); } - private void AosDelay_Callback(object state) + private void AosDelay_Callback(Mobile m, int mana) { - object[] states = (object[])state; - - Mobile m = (Mobile)states[0]; - int mana = (int)states[1]; - if (m.Alive && !m.IsDeadBondedPet) { m.Mana += mana; @@ -81,8 +76,7 @@ namespace Server.Spells.Fourth { m.Mana -= toDrain; - m_Table[m] = Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(AosDelay_Callback), - new object[] { m, toDrain }); + m_Table[m] = Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => AosDelay_Callback(m, toDrain)); } } else diff --git a/Scripts/Spells/Gargoyle/SpellDefinitions/FlySpell.cs b/Scripts/Spells/Gargoyle/SpellDefinitions/FlySpell.cs index 5abc03b8a..1fc81594a 100644 --- a/Scripts/Spells/Gargoyle/SpellDefinitions/FlySpell.cs +++ b/Scripts/Spells/Gargoyle/SpellDefinitions/FlySpell.cs @@ -43,7 +43,7 @@ namespace Server.Spells public void Stop() { m_Stop = true; - Disturb(DisturbType.Hurt, false, false); + Disturb(DisturbType.Hurt, false); } public override bool CheckDisturb(DisturbType type, bool checkFirst, bool resistable) diff --git a/Scripts/Spells/Mysticism/MysticSpell.cs b/Scripts/Spells/Mysticism/MysticSpell.cs index 99d084e98..5cfb41eec 100644 --- a/Scripts/Spells/Mysticism/MysticSpell.cs +++ b/Scripts/Spells/Mysticism/MysticSpell.cs @@ -22,12 +22,12 @@ namespace Server.Spells.Mysticism */ public override double GetDamageSkill(Mobile m) { - return Math.Max(m.Skills[SkillName.Imbuing].Value, m.Skills[SkillName.Focus].Value); + return Math.Max(m.Skills.Imbuing.Value, m.Skills.Focus.Value); } public override int GetDamageFixed(Mobile m) { - return Math.Max(m.Skills[SkillName.Imbuing].Fixed, m.Skills[SkillName.Focus].Fixed); + return Math.Max(m.Skills.Imbuing.Fixed, m.Skills.Focus.Fixed); } public override void GetCastSkills(out double min, out double max) @@ -82,12 +82,12 @@ namespace Server.Spells.Mysticism public static double GetBaseSkill(Mobile m) { - return m.Skills[SkillName.Mysticism].Value; + return m.Skills.Mysticism.Value; } public static double GetBoostSkill(Mobile m) { - return Math.Max(m.Skills[SkillName.Imbuing].Value, m.Skills[SkillName.Focus].Value); + return Math.Max(m.Skills.Imbuing.Value, m.Skills.Focus.Value); } } } \ No newline at end of file diff --git a/Scripts/Spells/Mysticism/NetherCycloneSpell.cs b/Scripts/Spells/Mysticism/NetherCycloneSpell.cs index 675b2ac98..15982d9dd 100644 --- a/Scripts/Spells/Mysticism/NetherCycloneSpell.cs +++ b/Scripts/Spells/Mysticism/NetherCycloneSpell.cs @@ -85,7 +85,7 @@ namespace Server.Spells.Mysticism Caster.DoHarmful(m); SpellHelper.Damage(this, m, damage, 0, 0, 0, 0, 0, 100); - double resistedReduction = reduction - m.Skills[SkillName.MagicResist].Value / 800.0; + double resistedReduction = reduction - m.Skills.MagicResist.Value / 800.0; m.Stam -= (int)(m.StamMax * resistedReduction); m.Mana -= (int)(m.ManaMax * resistedReduction); diff --git a/Scripts/Spells/Mysticism/SpellPlagueSpell.cs b/Scripts/Spells/Mysticism/SpellPlagueSpell.cs index e6e3fc4a9..b6c32540d 100644 --- a/Scripts/Spells/Mysticism/SpellPlagueSpell.cs +++ b/Scripts/Spells/Mysticism/SpellPlagueSpell.cs @@ -158,7 +158,7 @@ namespace Server.Spells.Mysticism { int exploChance = 90 - m_Explosions * 30; - double resist = m_Target.Skills[SkillName.MagicResist].Value; + double resist = m_Target.Skills.MagicResist.Value; if (resist >= 70) exploChance -= (int)((resist - 70.0) * 3.0 / 10.0); diff --git a/Scripts/Spells/Mysticism/StoneFormSpell.cs b/Scripts/Spells/Mysticism/StoneFormSpell.cs index 4b68f11d8..7e54faf3a 100644 --- a/Scripts/Spells/Mysticism/StoneFormSpell.cs +++ b/Scripts/Spells/Mysticism/StoneFormSpell.cs @@ -20,7 +20,7 @@ namespace Server.Spells.Mysticism Reagent.Garlic ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public StoneFormSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) @@ -39,7 +39,7 @@ namespace Server.Spells.Mysticism public static bool UnderEffect(Mobile m) { - return m_Table.Contains(m); + return m_Table.ContainsKey(m); } public override bool CheckCast() @@ -50,7 +50,7 @@ namespace Server.Spells.Mysticism return false; } - if (!Caster.CanBeginAction(typeof(PolymorphSpell))) + if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1061628); // You can't do that while polymorphed. return false; @@ -77,11 +77,11 @@ namespace Server.Spells.Mysticism { Caster.SendLocalizedMessage(1061632); // You can't do that while carrying the sigil. } - else if (!Caster.CanBeginAction(typeof(PolymorphSpell))) + else if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1061628); // You can't do that while polymorphed. } - else if (!Caster.CanBeginAction(typeof(IncognitoSpell)) || Caster.IsBodyMod && !UnderEffect(Caster)) + else if (!Caster.CanBeginAction() || Caster.IsBodyMod && !UnderEffect(Caster)) { Caster.SendLocalizedMessage(1063218); // You cannot use that ability in this form. } @@ -106,8 +106,7 @@ namespace Server.Spells.Mysticism int offset = (int)((GetBaseSkill(Caster) + GetBoostSkill(Caster)) / 24.0); - List mods = new List - { + ResistanceMod[] mods = { new ResistanceMod(ResistanceType.Physical, offset), new ResistanceMod(ResistanceType.Fire, offset), new ResistanceMod(ResistanceType.Cold, offset), @@ -115,8 +114,8 @@ namespace Server.Spells.Mysticism new ResistanceMod(ResistanceType.Energy, offset) }; - foreach (ResistanceMod mod in mods) - Caster.AddResistanceMod(mod); + for (int i = 0; i < mods.Length; ++i) + Caster.AddResistanceMod(mods[i]); m_Table[Caster] = mods; @@ -143,10 +142,10 @@ namespace Server.Spells.Mysticism public static void RemoveEffects(Mobile m) { - List mods = (List)m_Table[m]; + ResistanceMod[] mods = m_Table[m]; - foreach (ResistanceMod mod in mods) - m.RemoveResistanceMod(mod); + for (int i = 0; i < mods.Length; ++i) + m.RemoveResistanceMod(mods[i]); m.BodyMod = 0; m.HueMod = -1; @@ -164,4 +163,4 @@ namespace Server.Spells.Mysticism RemoveEffects(m); } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/AnimateDeadSpell.cs b/Scripts/Spells/Necromancy/AnimateDeadSpell.cs index fdedad3e1..3def622e8 100644 --- a/Scripts/Spells/Necromancy/AnimateDeadSpell.cs +++ b/Scripts/Spells/Necromancy/AnimateDeadSpell.cs @@ -140,7 +140,7 @@ namespace Server.Spells.Necromancy if (qs is DarkTidesQuest) { - QuestObjective objective = qs.FindObjective(typeof(AnimateMaabusCorpseObjective)); + QuestObjective objective = qs.FindObjective(); if (objective != null && !objective.Completed) { @@ -189,8 +189,8 @@ namespace Server.Spells.Necromancy Effects.SendLocationParticles(EffectItem.Create(p, map, EffectItem.DefaultDuration), 0x3789, 1, 40, 0x3F, 3, 9907, 0); - Timer.DelayCall(TimeSpan.FromSeconds(2.0), new TimerStateCallback(SummonDelay_Callback), - new object[] { Caster, c, p, map, group }); + Timer.DelayCall(TimeSpan.FromSeconds(2.0), + () => SummonDelay_Callback(Caster, c, p, map, group)); } } } @@ -242,30 +242,19 @@ namespace Server.Spells.Necromancy if (list.Count > 3) Timer.DelayCall(TimeSpan.Zero, list[0].Kill); - Timer.DelayCall(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.0), new TimerStateCallback(Summoned_Damage), - summoned); + Timer.DelayCall(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.0), Summoned_Damage, summoned); } - private static void Summoned_Damage(object state) + private static void Summoned_Damage(Mobile mob) { - Mobile mob = (Mobile)state; - if (mob.Hits > 0) --mob.Hits; else mob.Kill(); } - private static void SummonDelay_Callback(object state) + private static void SummonDelay_Callback(Mobile caster, Corpse corpse, Point3D loc, Map map, CreatureGroup group) { - object[] states = (object[])state; - - Mobile caster = (Mobile)states[0]; - Corpse corpse = (Corpse)states[1]; - Point3D loc = (Point3D)states[2]; - Map map = (Map)states[3]; - CreatureGroup group = (CreatureGroup)states[4]; - if (corpse.Animated) return; @@ -274,8 +263,8 @@ namespace Server.Spells.Necromancy if (owner == null) return; - double necromancy = caster.Skills[SkillName.Necromancy].Value; - double spiritSpeak = caster.Skills[SkillName.SpiritSpeak].Value; + double necromancy = caster.Skills.Necromancy.Value; + double spiritSpeak = caster.Skills.SpiritSpeak.Value; int casterAbility = 0; diff --git a/Scripts/Spells/Necromancy/BloodOathSpell.cs b/Scripts/Spells/Necromancy/BloodOathSpell.cs index 0deee24ff..082b85355 100644 --- a/Scripts/Spells/Necromancy/BloodOathSpell.cs +++ b/Scripts/Spells/Necromancy/BloodOathSpell.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Mobiles; using Server.Targeting; @@ -14,8 +15,8 @@ namespace Server.Spells.Necromancy Reagent.DaemonBlood ); - private static Hashtable m_OathTable = new Hashtable(); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_OathTable = new Dictionary(); + private static Dictionary m_Table = new Dictionary(); public BloodOathSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -38,11 +39,11 @@ namespace Server.Spells.Necromancy { Caster.SendLocalizedMessage(1060508); // You can't curse that. } - else if (m_OathTable.Contains(Caster)) + else if (m_OathTable.ContainsKey(Caster)) { Caster.SendLocalizedMessage(1061607); // You are already bonded in a Blood Oath. } - else if (m_OathTable.Contains(m)) + else if (m_OathTable.ContainsKey(m)) { if (m.Player) Caster.SendLocalizedMessage(1061608); // That player is already bonded in a Blood Oath. @@ -61,7 +62,7 @@ namespace Server.Spells.Necromancy * ((ss-rm)/8)+8 */ - ExpireTimer timer = (ExpireTimer)m_Table[m]; + ExpireTimer timer = m_Table[m]; timer?.DoExpire(); m_OathTable[Caster] = Caster; @@ -93,15 +94,10 @@ namespace Server.Spells.Necromancy FinishSequence(); } - public static bool RemoveCurse(Mobile m) + public static void RemoveCurse(Mobile m) { - ExpireTimer t = (ExpireTimer)m_Table[m]; - - if (t == null) - return false; - - t.DoExpire(); - return true; + ExpireTimer t = m_Table[m]; + t?.DoExpire(); } public static Mobile GetBloodOath(Mobile m) @@ -109,12 +105,8 @@ namespace Server.Spells.Necromancy if (m == null) return null; - Mobile oath = (Mobile)m_OathTable[m]; - - if (oath == m) - oath = null; - - return oath; + Mobile oath = m_OathTable[m]; + return oath == m ? null : oath; } private class ExpireTimer : Timer @@ -141,13 +133,13 @@ namespace Server.Spells.Necromancy public void DoExpire() { - if (m_OathTable.Contains(m_Caster)) + if (m_OathTable.ContainsKey(m_Caster)) { m_Caster.SendLocalizedMessage(1061620); // Your Blood Oath has been broken. m_OathTable.Remove(m_Caster); } - if (m_OathTable.Contains(m_Target)) + if (m_OathTable.ContainsKey(m_Target)) { m_Target.SendLocalizedMessage(1061620); // Your Blood Oath has been broken. m_OathTable.Remove(m_Target); @@ -185,4 +177,4 @@ namespace Server.Spells.Necromancy } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/CorpseSkin.cs b/Scripts/Spells/Necromancy/CorpseSkin.cs index ff39fb6a0..ae80e572d 100644 --- a/Scripts/Spells/Necromancy/CorpseSkin.cs +++ b/Scripts/Spells/Necromancy/CorpseSkin.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Targeting; namespace Server.Spells.Necromancy @@ -14,7 +15,7 @@ namespace Server.Spells.Necromancy Reagent.GraveDust ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public CorpseSkinSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -48,7 +49,7 @@ namespace Server.Spells.Necromancy * NOTE: Resistance is not checked if targeting yourself */ - ExpireTimer timer = (ExpireTimer)m_Table[m]; + ExpireTimer timer = m_Table[m]; if (timer != null) timer.DoExpire(); @@ -66,8 +67,7 @@ namespace Server.Spells.Necromancy TimeSpan duration = TimeSpan.FromSeconds((ss - mr) / 2.5 + 40.0); - ResistanceMod[] mods = new ResistanceMod[4] - { + ResistanceMod[] mods = { new ResistanceMod(ResistanceType.Fire, -15), new ResistanceMod(ResistanceType.Poison, -15), new ResistanceMod(ResistanceType.Cold, +10), @@ -92,7 +92,7 @@ namespace Server.Spells.Necromancy public static bool RemoveCurse(Mobile m) { - ExpireTimer t = (ExpireTimer)m_Table[m]; + ExpireTimer t = m_Table[m]; if (t == null) return false; @@ -151,4 +151,4 @@ namespace Server.Spells.Necromancy } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/CurseWeapon.cs b/Scripts/Spells/Necromancy/CurseWeapon.cs index 9d550b85c..34199f36a 100644 --- a/Scripts/Spells/Necromancy/CurseWeapon.cs +++ b/Scripts/Spells/Necromancy/CurseWeapon.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; namespace Server.Spells.Necromancy @@ -13,7 +14,7 @@ namespace Server.Spells.Necromancy Reagent.PigIron ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public CurseWeaponSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -47,18 +48,17 @@ namespace Server.Spells.Necromancy Caster.FixedParticles(0x37B9, 1, 14, 9502, 32, 5, (EffectLayer)255); new SoundEffectTimer(Caster).Start(); - TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills[SkillName.SpiritSpeak].Value / 3.4 + 1.0); + TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills.SpiritSpeak.Value / 3.4 + 1.0); - Timer t = (Timer)m_Table[weapon]; - - t?.Stop(); + ExpireTimer timer = m_Table[weapon]; + timer?.Stop(); weapon.Cursed = true; - m_Table[weapon] = t = new ExpireTimer(weapon, duration); + m_Table[weapon] = timer = new ExpireTimer(weapon, duration); - t.Start(); + timer.Start(); } FinishSequence(); @@ -78,7 +78,7 @@ namespace Server.Spells.Necromancy { m_Weapon.Cursed = false; Effects.PlaySound(m_Weapon.GetWorldLocation(), m_Weapon.Map, 0xFA); - m_Table.Remove(this); + m_Table.Remove(m_Weapon); } } @@ -98,4 +98,4 @@ namespace Server.Spells.Necromancy } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/EvilOmen.cs b/Scripts/Spells/Necromancy/EvilOmen.cs index 6caad743f..8105cf7ff 100644 --- a/Scripts/Spells/Necromancy/EvilOmen.cs +++ b/Scripts/Spells/Necromancy/EvilOmen.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Mobiles; using Server.Targeting; @@ -15,7 +16,7 @@ namespace Server.Spells.Necromancy Reagent.NoxCrystal ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public EvilOmenSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) @@ -56,19 +57,19 @@ namespace Server.Spells.Necromancy m.FixedParticles(0x3728, 1, 13, 9912, 1150, 7, EffectLayer.Head); m.FixedParticles(0x3779, 1, 15, 9502, 67, 7, EffectLayer.Head); - if (!m_Table.Contains(m)) + if (!m_Table.ContainsKey(m)) { - SkillMod mod = new DefaultSkillMod(SkillName.MagicResist, false, 50.0); + DefaultSkillMod mod = new DefaultSkillMod(SkillName.MagicResist, false, 50.0); - if (m.Skills[SkillName.MagicResist].Base > 50.0) + if (m.Skills.MagicResist.Base > 50.0) m.AddSkillMod(mod); m_Table[m] = mod; } - TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills[SkillName.SpiritSpeak].Value / 12 + 1.0); + TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills.SpiritSpeak.Value / 12 + 1.0); - Timer.DelayCall(duration, new TimerStateCallback(EffectExpire_Callback), m); + Timer.DelayCall(duration, () => TryEndEffect(m)); HarmfulSpell(m); @@ -78,14 +79,9 @@ namespace Server.Spells.Necromancy FinishSequence(); } - private static void EffectExpire_Callback(object state) - { - TryEndEffect((Mobile)state); - } - /* * The naming here was confusing. Its a 1-off effect spell. - * So, we dont actually "checkeffect"; we endeffect with bool + * So, we don't actually "checkeffect"; we endeffect with bool * return to determine external behaviors. * * -refactored. @@ -93,7 +89,7 @@ namespace Server.Spells.Necromancy public static bool TryEndEffect(Mobile m) { - SkillMod mod = (SkillMod)m_Table[m]; + DefaultSkillMod mod = m_Table[m]; if (mod == null) return false; @@ -128,4 +124,4 @@ namespace Server.Spells.Necromancy } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/Exorcism.cs b/Scripts/Spells/Necromancy/Exorcism.cs index 365dcd0b6..755ceb8eb 100644 --- a/Scripts/Spells/Necromancy/Exorcism.cs +++ b/Scripts/Spells/Necromancy/Exorcism.cs @@ -87,7 +87,8 @@ namespace Server.Spells.Necromancy public override void OnCast() { - if (!(Caster.Region.GetRegion(typeof(ChampionSpawnRegion)) is ChampionSpawnRegion r) || !Caster.InRange(r.ChampionSpawn, Range)) + ChampionSpawnRegion r = Caster.Region.GetRegion(); + if (r == null || !Caster.InRange(r.ChampionSpawn, Range)) { Caster.SendLocalizedMessage(1072111); // You are not in a valid exorcism region. } @@ -130,7 +131,7 @@ namespace Server.Spells.Necromancy if (SpellHelper.IsAnyT2A(map, c.Location) && SpellHelper.IsAnyT2A(map, m.Location)) return false; //Same Map, both in T2A, ie, same 'sub server'. - if (m.Region.IsPartOf(typeof(DungeonRegion)) == Region.Find(c.Location, map).IsPartOf(typeof(DungeonRegion))) + if (m.Region.IsPartOf() == Region.Find(c.Location, map).IsPartOf()) return false; //Same Map, both in Dungeon region OR They're both NOT in a dungeon region. //Just an approximation cause RunUO doens't divide up the world the same way OSI does ;p diff --git a/Scripts/Spells/Necromancy/MindRot.cs b/Scripts/Spells/Necromancy/MindRot.cs index b56963e93..fe17ac7bd 100644 --- a/Scripts/Spells/Necromancy/MindRot.cs +++ b/Scripts/Spells/Necromancy/MindRot.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Targeting; namespace Server.Spells.Necromancy @@ -15,7 +16,7 @@ namespace Server.Spells.Necromancy Reagent.DaemonBlood ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public MindRotSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -70,13 +71,13 @@ namespace Server.Spells.Necromancy public static void ClearMindRotScalar(Mobile m) { - if (!m_Table.ContainsKey(m)) + MRBucket tmpB = m_Table[m]; + + if (tmpB == null) return; BuffInfo.RemoveBuff(m, BuffIcon.Mindrot); - MRBucket tmpB = (MRBucket)m_Table[m]; - MRExpireTimer tmpT = tmpB.m_MRExpireTimer; - tmpT.Stop(); + tmpB.m_MRExpireTimer.Stop(); m_Table.Remove(m); m.SendLocalizedMessage(1060872); // Your mind feels normal again. } @@ -88,10 +89,11 @@ namespace Server.Spells.Necromancy public static bool GetMindRotScalar(Mobile m, ref double scalar) { - if (!m_Table.ContainsKey(m)) + MRBucket tmpB = m_Table[m]; + + if (tmpB == null) return false; - MRBucket tmpB = (MRBucket)m_Table[m]; scalar = tmpB.m_Scalar; return true; } @@ -100,11 +102,10 @@ namespace Server.Spells.Necromancy { if (!m_Table.ContainsKey(target)) { - m_Table.Add(target, new MRBucket(scalar, new MRExpireTimer(caster, target, duration))); + MRBucket tmpB = new MRBucket(scalar, new MRExpireTimer(caster, target, duration)); + m_Table.Add(target, tmpB); BuffInfo.AddBuff(target, new BuffInfo(BuffIcon.Mindrot, 1075665, duration, target)); - MRBucket tmpB = (MRBucket)m_Table[target]; - MRExpireTimer tmpT = tmpB.m_MRExpireTimer; - tmpT.Start(); + tmpB.m_MRExpireTimer.Start(); target.SendLocalizedMessage(1074384); } } @@ -146,16 +147,6 @@ namespace Server.Spells.Necromancy Priority = TimerPriority.TwoFiftyMS; } - public void RenewDelay(TimeSpan delay) - { - m_End = DateTime.UtcNow + delay; - } - - public void Halt() - { - Stop(); - } - protected override void OnTick() { if (m_Target.Deleted || !m_Target.Alive || DateTime.UtcNow >= m_End) @@ -178,4 +169,4 @@ namespace Server.Spells.Necromancy m_MRExpireTimer = theTimer; } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/PainSpike.cs b/Scripts/Spells/Necromancy/PainSpike.cs index adeaefb0a..c0dd877d1 100644 --- a/Scripts/Spells/Necromancy/PainSpike.cs +++ b/Scripts/Spells/Necromancy/PainSpike.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Misc; using Server.Targeting; @@ -15,7 +16,7 @@ namespace Server.Spells.Necromancy Reagent.PigIron ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public PainSpikeSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -58,20 +59,18 @@ namespace Server.Spells.Necromancy TimeSpan buffTime = TimeSpan.FromSeconds(10.0); - if (m_Table.Contains(m)) + InternalTimer timer = m_Table[m]; + + if (timer == null) { - damage = Utility.RandomMinMax(3, 7); - - if (m_Table[m] is Timer t) - { - t.Delay += TimeSpan.FromSeconds(2.0); - - buffTime = t.Next - DateTime.UtcNow; - } + m_Table[m] = timer = new InternalTimer(m, damage); + timer.Start(); } else { - new InternalTimer(m, damage).Start(); + damage = Utility.RandomMinMax(3, 7); + timer.Delay += TimeSpan.FromSeconds(2.0); + buffTime = timer.Next - DateTime.UtcNow; } BuffInfo.AddBuff(m, new BuffInfo(BuffIcon.PainSpike, 1075667, buffTime, m, Convert.ToString((int)damage))); @@ -100,8 +99,6 @@ namespace Server.Spells.Necromancy m_Mobile = m; m_ToRestore = (int)toRestore; - - m_Table[m] = this; } protected override void OnTick() @@ -136,4 +133,4 @@ namespace Server.Spells.Necromancy } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/Strangle.cs b/Scripts/Spells/Necromancy/Strangle.cs index 5cdf68e0c..e4b1edd36 100644 --- a/Scripts/Spells/Necromancy/Strangle.cs +++ b/Scripts/Spells/Necromancy/Strangle.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Targeting; namespace Server.Spells.Necromancy @@ -14,7 +15,7 @@ namespace Server.Spells.Necromancy Reagent.NoxCrystal ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public StrangleSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -58,19 +59,19 @@ namespace Server.Spells.Necromancy m.FixedParticles(0x36CB, 1, 9, 9911, 67, 5, EffectLayer.Head); m.FixedParticles(0x374A, 1, 17, 9502, 1108, 4, (EffectLayer)255); - if (!m_Table.Contains(m)) - { - Timer t = new InternalTimer(m, Caster); - t.Start(); + InternalTimer timer = m_Table[m]; - m_Table[m] = t; + if (timer == null) + { + m_Table[m] = timer = new InternalTimer(m, Caster); + timer.Start(); } HarmfulSpell(m); } //Calculations for the buff bar - double spiritlevel = Caster.Skills[SkillName.SpiritSpeak].Value / 10; + double spiritlevel = Caster.Skills.SpiritSpeak.Value / 10; if (spiritlevel < 4) spiritlevel = 4; int d_MinDamage = 4; @@ -95,10 +96,7 @@ namespace Server.Spells.Necromancy { int delay = (int)Math.Ceiling((1.0 + 5 * i_Count) / i_MaxCount); - if (delay <= 5) - i_HitDelay = delay; - else - i_HitDelay = 5; + i_HitDelay = delay <= 5 ? delay : 5; } } @@ -113,12 +111,12 @@ namespace Server.Spells.Necromancy public static bool RemoveCurse(Mobile m) { - Timer t = (Timer)m_Table[m]; + Timer timer = m_Table[m]; - if (t == null) + if (timer == null) return false; - t.Stop(); + timer.Stop(); m.SendLocalizedMessage(1061687); // You can breath normally again. m_Table.Remove(m); @@ -141,7 +139,7 @@ namespace Server.Spells.Necromancy m_Target = target; m_From = from; - double spiritLevel = from.Skills[SkillName.SpiritSpeak].Value / 10; + double spiritLevel = from.Skills.SpiritSpeak.Value / 10; m_MinBaseDamage = spiritLevel - 2; m_MaxBaseDamage = spiritLevel + 1; @@ -237,4 +235,4 @@ namespace Server.Spells.Necromancy } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/SummonFamiliar.cs b/Scripts/Spells/Necromancy/SummonFamiliar.cs index 16a51287d..b118592a8 100644 --- a/Scripts/Spells/Necromancy/SummonFamiliar.cs +++ b/Scripts/Spells/Necromancy/SummonFamiliar.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Mobiles; using Server.Network; @@ -26,7 +27,7 @@ namespace Server.Spells.Necromancy public override double RequiredSkill => 30.0; public override int RequiredMana => 17; - public static Hashtable Table{ get; } = new Hashtable(); + public static Dictionary Table{ get; } = new Dictionary(); public static SummonFamiliarEntry[] Entries{ get; } = { @@ -39,9 +40,9 @@ namespace Server.Spells.Necromancy public override bool CheckCast() { - BaseCreature check = (BaseCreature)Table[Caster]; + BaseCreature check = Table[Caster]; - if (check != null && !check.Deleted) + if (check?.Deleted == false) { Caster.SendLocalizedMessage(1061605); // You already have a familiar. return false; @@ -54,7 +55,7 @@ namespace Server.Spells.Necromancy { if (CheckSequence()) { - Caster.CloseGump(typeof(SummonFamiliarGump)); + Caster.CloseGump(); Caster.SendGump(new SummonFamiliarGump(Caster, Entries, this)); } @@ -89,7 +90,6 @@ namespace Server.Spells.Necromancy private const int EnabledColor32 = 0x18CD00; private const int DisabledColor32 = 0x4A8B52; - private static Hashtable m_Table = new Hashtable(); private SummonFamiliarEntry[] m_Entries; private Mobile m_From; @@ -117,8 +117,8 @@ namespace Server.Spells.Necromancy AddHtmlLocalized(30, 26, 200, 20, 1060147, EnabledColor16, false, false); // Chose thy familiar... - double necro = from.Skills[SkillName.Necromancy].Value; - double spirit = from.Skills[SkillName.SpiritSpeak].Value; + double necro = from.Skills.Necromancy.Value; + double spirit = from.Skills.SpiritSpeak.Value; for (int i = 0; i < entries.Length; ++i) { @@ -146,10 +146,10 @@ namespace Server.Spells.Necromancy { SummonFamiliarEntry entry = m_Entries[index]; - double necro = m_From.Skills[SkillName.Necromancy].Value; - double spirit = m_From.Skills[SkillName.SpiritSpeak].Value; + double necro = m_From.Skills.Necromancy.Value; + double spirit = m_From.Skills.SpiritSpeak.Value; - BaseCreature check = (BaseCreature)SummonFamiliarSpell.Table[m_From]; + BaseCreature check = SummonFamiliarSpell.Table[m_From]; #region Dueling @@ -160,7 +160,7 @@ namespace Server.Spells.Necromancy #endregion - else if (check != null && !check.Deleted) + else if (check?.Deleted == false) { m_From.SendLocalizedMessage(1061605); // You already have a familiar. } @@ -169,14 +169,14 @@ namespace Server.Spells.Necromancy // That familiar requires ~1_NECROMANCY~ Necromancy and ~2_SPIRIT~ Spirit Speak. m_From.SendLocalizedMessage(1061606, $"{entry.ReqNecromancy:F1}\t{entry.ReqSpiritSpeak:F1}"); - m_From.CloseGump(typeof(SummonFamiliarGump)); + m_From.CloseGump(); m_From.SendGump(new SummonFamiliarGump(m_From, SummonFamiliarSpell.Entries, m_Spell)); } else if (entry.Type == null) { m_From.SendMessage("That familiar has not yet been defined."); - m_From.CloseGump(typeof(SummonFamiliarGump)); + m_From.CloseGump(); m_From.SendGump(new SummonFamiliarGump(m_From, SummonFamiliarSpell.Entries, m_Spell)); } else @@ -185,7 +185,8 @@ namespace Server.Spells.Necromancy { BaseCreature bc = (BaseCreature)Activator.CreateInstance(entry.Type); - bc.Skills.MagicResist = m_From.Skills.MagicResist; + // TODO: Is this right? + bc.Skills.MagicResist.Base = m_From.Skills.MagicResist.Base; if (BaseCreature.Summon(bc, m_From, m_From.Location, -1, TimeSpan.FromDays(1.0))) { @@ -196,6 +197,7 @@ namespace Server.Spells.Necromancy } catch { + // ignored } } } @@ -205,4 +207,4 @@ namespace Server.Spells.Necromancy } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Ninjitsu/AnimalForm.cs b/Scripts/Spells/Ninjitsu/AnimalForm.cs index 7db41dfba..67d593c08 100644 --- a/Scripts/Spells/Ninjitsu/AnimalForm.cs +++ b/Scripts/Spells/Ninjitsu/AnimalForm.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Gumps; using Server.Items; using Server.Mobiles; @@ -24,9 +25,8 @@ namespace Server.Spells.Ninjitsu 9002 ); - private static Hashtable m_LastAnimalForms = new Hashtable(); - - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_LastAnimalForms = new Dictionary(); + private static Dictionary m_Table = new Dictionary(); private bool m_WasMoving; @@ -82,7 +82,7 @@ namespace Server.Spells.Ninjitsu public override bool CheckCast() { - if (!Caster.CanBeginAction(typeof(PolymorphSpell))) + if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1061628); // You can't do that while polymorphed. return false; @@ -129,7 +129,7 @@ namespace Server.Spells.Ninjitsu public override void OnCast() { - if (!Caster.CanBeginAction(typeof(PolymorphSpell))) + if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1061628); // You can't do that while polymorphed. } @@ -137,7 +137,7 @@ namespace Server.Spells.Ninjitsu { Caster.SendLocalizedMessage(1063219); // You cannot mimic an animal while in that form. } - else if (!Caster.CanBeginAction(typeof(IncognitoSpell)) || Caster.IsBodyMod && GetContext(Caster) == null) + else if (!Caster.CanBeginAction() || Caster.IsBodyMod && GetContext(Caster) == null) { DoFizzle(); } @@ -162,7 +162,7 @@ namespace Server.Spells.Ninjitsu if (GetLastAnimalForm(Caster) == -1 || !skipGump) { - Caster.CloseGump(typeof(AnimalFormGump)); + Caster.CloseGump(); Caster.SendGump(new AnimalFormGump(Caster, Entries, this)); } else @@ -197,8 +197,8 @@ namespace Server.Spells.Ninjitsu public int GetLastAnimalForm(Mobile m) { - if (m_LastAnimalForms.Contains(m)) - return (int)m_LastAnimalForms[m]; + if (m_LastAnimalForms.ContainsKey(m)) + return m_LastAnimalForms[m]; return -1; } @@ -214,7 +214,7 @@ namespace Server.Spells.Ninjitsu if (m.Skills.Ninjitsu.Value < entry.ReqSkill) { - string args = $"{entry.ReqSkill.ToString("F1")}\t{SkillName.Ninjitsu}\t "; + string args = $"{entry.ReqSkill:F1}\t{SkillName.Ninjitsu}\t "; m.SendLocalizedMessage(1063013, args); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability. return MorphResult.NoSkill; @@ -257,8 +257,7 @@ namespace Server.Spells.Ninjitsu if (entry.StealthBonus) { - mod = new DefaultSkillMod(SkillName.Stealth, true, 20.0); - mod.ObeyCap = true; + mod = new DefaultSkillMod(SkillName.Stealth, true, 20.0) { ObeyCap = true }; m.AddSkillMod(mod); } @@ -266,8 +265,7 @@ namespace Server.Spells.Ninjitsu if (entry.StealingBonus) { - stealingMod = new DefaultSkillMod(SkillName.Stealing, true, 10.0); - stealingMod.ObeyCap = true; + stealingMod = new DefaultSkillMod(SkillName.Stealing, true, 10.0) { ObeyCap = true }; m.AddSkillMod(stealingMod); } @@ -325,19 +323,17 @@ namespace Server.Spells.Ninjitsu public static AnimalFormContext GetContext(Mobile m) { - return m_Table[m] as AnimalFormContext; + return m_Table[m]; } public static bool UnderTransformation(Mobile m) { - return GetContext(m) != null; + return m_Table.ContainsKey(m); } public static bool UnderTransformation(Mobile m, Type type) { - AnimalFormContext context = GetContext(m); - - return context != null && context.Type == type; + return GetContext(m)?.Type == type; } /* @@ -400,14 +396,12 @@ namespace Server.Spells.Ninjitsu //TODO: Convert this for ML to the BaseImageTileButtonsgump private Mobile m_Caster; private AnimalForm m_Spell; - private Item m_Talisman; public AnimalFormGump(Mobile caster, AnimalFormEntry[] entries, AnimalForm spell) : base(50, 50) { m_Caster = caster; m_Spell = spell; - m_Talisman = caster.Talisman; AddPage(0); @@ -615,7 +609,7 @@ namespace Server.Spells.Ninjitsu { m_Mobile.RevealingAction(); m_Mobile.PlaySound(0x227); - Effects.SendMovingEffect(m_Mobile, target, 0x36D4, 5, 0, false, false, 0, 0); + Effects.SendMovingEffect(m_Mobile, target, 0x36D4, 5, 0, false, false); DelayCall(TimeSpan.FromSeconds(1), BreathDamage_Callback, target); } @@ -631,4 +625,4 @@ namespace Server.Spells.Ninjitsu } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Ninjitsu/Backstab.cs b/Scripts/Spells/Ninjitsu/Backstab.cs index 8071f2b5b..5e19f08cb 100644 --- a/Scripts/Spells/Ninjitsu/Backstab.cs +++ b/Scripts/Spells/Ninjitsu/Backstab.cs @@ -15,7 +15,7 @@ namespace Server.Spells.Ninjitsu public override double GetDamageScalar(Mobile attacker, Mobile defender) { - double ninjitsu = attacker.Skills[SkillName.Ninjitsu].Value; + double ninjitsu = attacker.Skills.Ninjitsu.Value; return 1.0 + ninjitsu / 360 + Tracking.GetStalkingBonus(attacker, defender) / 100; } @@ -37,8 +37,8 @@ namespace Server.Spells.Ninjitsu if (valid) { - attacker.BeginAction(typeof(Stealth)); - Timer.DelayCall(TimeSpan.FromSeconds(5.0), delegate { attacker.EndAction(typeof(Stealth)); }); + attacker.BeginAction(); + Timer.DelayCall(TimeSpan.FromSeconds(5.0), delegate { attacker.EndAction(); }); } return valid; diff --git a/Scripts/Spells/Ninjitsu/DeathStrike.cs b/Scripts/Spells/Ninjitsu/DeathStrike.cs index 43e702c5f..26873512d 100644 --- a/Scripts/Spells/Ninjitsu/DeathStrike.cs +++ b/Scripts/Spells/Ninjitsu/DeathStrike.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; using Server.SkillHandlers; @@ -7,7 +8,7 @@ namespace Server.Spells.Ninjitsu { public class DeathStrike : NinjaMove { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 30; public override double RequiredSkill => 85.0; @@ -27,7 +28,7 @@ namespace Server.Spells.Ninjitsu ClearCurrentMove(attacker); - double ninjitsu = attacker.Skills[SkillName.Ninjitsu].Value; + double ninjitsu = attacker.Skills.Ninjitsu.Value; double chance; bool @@ -48,18 +49,16 @@ namespace Server.Spells.Ninjitsu } - DeathStrikeInfo info; + DeathStrikeInfo info = m_Table[defender]; int damageBonus = 0; - if (m_Table.Contains(defender)) + if (info != null) { defender.SendLocalizedMessage(1063092); // Your opponent lands another Death Strike! - info = (DeathStrikeInfo)m_Table[defender]; - if (info.m_Steps > 0) - damageBonus = attacker.Skills[SkillName.Ninjitsu].Fixed / 150; + damageBonus = attacker.Skills.Ninjitsu.Fixed / 150; info.m_Timer?.Stop(); @@ -75,8 +74,10 @@ namespace Server.Spells.Ninjitsu defender.FixedParticles(0x374A, 1, 17, 0x26BC, EffectLayer.Waist); attacker.PlaySound(attacker.Female ? 0x50D : 0x50E); - info = new DeathStrikeInfo(defender, attacker, damageBonus, isRanged); - info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(ProcessDeathStrike), defender); + info = new DeathStrikeInfo(defender, attacker, damageBonus, isRanged) + { + m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), ProcessDeathStrike, defender) + }; m_Table[defender] = info; @@ -85,29 +86,29 @@ namespace Server.Spells.Ninjitsu public static void AddStep(Mobile m) { - if (!(m_Table[m] is DeathStrikeInfo info)) + DeathStrikeInfo info = m_Table[m]; + if (info == null) return; if (++info.m_Steps >= 5) ProcessDeathStrike(m); } - private static void ProcessDeathStrike(object state) + private static void ProcessDeathStrike(Mobile defender) { - Mobile defender = (Mobile)state; - - if (!(m_Table[defender] is DeathStrikeInfo info)) //sanity + DeathStrikeInfo info = m_Table[defender]; + if (info == null) return; int damage; - double ninjitsu = info.m_Attacker.Skills[SkillName.Ninjitsu].Value; + double ninjitsu = info.m_Attacker.Skills.Ninjitsu.Value; double stalkingBonus = Tracking.GetStalkingBonus(info.m_Attacker, info.m_Target); if (Core.ML) { - double scalar = (info.m_Attacker.Skills[SkillName.Hiding].Value + - info.m_Attacker.Skills[SkillName.Stealth].Value) / 220; + double scalar = (info.m_Attacker.Skills.Hiding.Value + + info.m_Attacker.Skills.Stealth.Value) / 220; if (scalar > 1) scalar = 1; @@ -159,4 +160,4 @@ namespace Server.Spells.Ninjitsu } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Ninjitsu/FocusAttack.cs b/Scripts/Spells/Ninjitsu/FocusAttack.cs index edf17468c..c4451c3e4 100644 --- a/Scripts/Spells/Ninjitsu/FocusAttack.cs +++ b/Scripts/Spells/Ninjitsu/FocusAttack.cs @@ -34,14 +34,14 @@ namespace Server.Spells.Ninjitsu public override double GetDamageScalar(Mobile attacker, Mobile defender) { - double ninjitsu = attacker.Skills[SkillName.Ninjitsu].Value; + double ninjitsu = attacker.Skills.Ninjitsu.Value; return 1.0 + ninjitsu * ninjitsu / 43636; } public override double GetPropertyBonus(Mobile attacker) { - double ninjitsu = attacker.Skills[SkillName.Ninjitsu].Value; + double ninjitsu = attacker.Skills.Ninjitsu.Value; double bonus = ninjitsu * ninjitsu / 43636; diff --git a/Scripts/Spells/Ninjitsu/KiAttack.cs b/Scripts/Spells/Ninjitsu/KiAttack.cs index 7a8b02cde..15b7de078 100644 --- a/Scripts/Spells/Ninjitsu/KiAttack.cs +++ b/Scripts/Spells/Ninjitsu/KiAttack.cs @@ -1,12 +1,13 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Items; namespace Server.Spells.Ninjitsu { public class KiAttack : NinjaMove { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 25; public override double RequiredSkill => 80.0; @@ -20,7 +21,7 @@ namespace Server.Spells.Ninjitsu return; KiAttackInfo info = new KiAttackInfo(from); - info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(2.0), new TimerStateCallback(EndKiAttack), info); + info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(2.0), EndKiAttack, info); m_Table[from] = info; } @@ -33,12 +34,12 @@ namespace Server.Spells.Ninjitsu return false; } - if (Core.ML && @from.Weapon is BaseRanged) + if (Core.ML && from.Weapon is BaseRanged) { from.SendLocalizedMessage(1075858); // You can only use this with melee attacks. return false; } - + return base.Validate(from); } @@ -80,18 +81,21 @@ namespace Server.Spells.Ninjitsu public override void OnClearMove(Mobile from) { - if (m_Table[@from] is KiAttackInfo info) - { - info.m_Timer?.Stop(); + KiAttackInfo info = m_Table[from]; - m_Table.Remove(info.m_Mobile); - } + if (info == null) + return; + + info.m_Timer?.Stop(); + m_Table.Remove(info.m_Mobile); } public static double GetBonus(Mobile from) { - if (!(m_Table[@from] is KiAttackInfo info)) - return 0.0; + KiAttackInfo info = m_Table[from]; + + if (info == null) + return 0; int xDelta = info.m_Location.X - from.X; int yDelta = info.m_Location.Y - from.Y; @@ -104,10 +108,8 @@ namespace Server.Spells.Ninjitsu return bonus; } - private static void EndKiAttack(object state) + private static void EndKiAttack(KiAttackInfo info) { - KiAttackInfo info = (KiAttackInfo)state; - info.m_Timer?.Stop(); ClearCurrentMove(info.m_Mobile); @@ -129,4 +131,4 @@ namespace Server.Spells.Ninjitsu } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Ninjitsu/ShadowJump.cs b/Scripts/Spells/Ninjitsu/ShadowJump.cs index 123c49f40..6b00f0ff6 100644 --- a/Scripts/Spells/Ninjitsu/ShadowJump.cs +++ b/Scripts/Spells/Ninjitsu/ShadowJump.cs @@ -87,7 +87,7 @@ namespace Server.Spells.Ninjitsu { Caster.SendLocalizedMessage(502831); // Cannot teleport to that spot. } - else if (Region.Find(to, map).GetRegion(typeof(HouseRegion)) != null) + else if (Region.Find(to, map).IsPartOf()) { Caster.SendLocalizedMessage(502829); // Cannot teleport to that spot. } diff --git a/Scripts/Spells/Ninjitsu/SurpriseAttack.cs b/Scripts/Spells/Ninjitsu/SurpriseAttack.cs index 3228aee88..a60922971 100644 --- a/Scripts/Spells/Ninjitsu/SurpriseAttack.cs +++ b/Scripts/Spells/Ninjitsu/SurpriseAttack.cs @@ -1,12 +1,13 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.SkillHandlers; namespace Server.Spells.Ninjitsu { public class SurpriseAttack : NinjaMove { - private static Hashtable m_Table = new Hashtable(); + private static Dictionary m_Table = new Dictionary(); public override int BaseMana => 20; public override double RequiredSkill => Core.ML ? 60.0 : 30.0; @@ -32,8 +33,8 @@ namespace Server.Spells.Ninjitsu if (valid) { - attacker.BeginAction(typeof(Stealth)); - Timer.DelayCall(TimeSpan.FromSeconds(5.0), delegate { attacker.EndAction(typeof(Stealth)); }); + attacker.BeginAction(); + Timer.DelayCall(TimeSpan.FromSeconds(5.0), delegate { attacker.EndAction(); }); } return valid; @@ -52,23 +53,21 @@ namespace Server.Spells.Ninjitsu attacker.RevealingAction(); - SurpriseAttackInfo info; + SurpriseAttackInfo info = m_Table[defender]; - if (m_Table.Contains(defender)) + if (info != null) { - info = (SurpriseAttackInfo)m_Table[defender]; - info.m_Timer?.Stop(); m_Table.Remove(defender); } - int ninjitsu = attacker.Skills[SkillName.Ninjitsu].Fixed; + int ninjitsu = attacker.Skills.Ninjitsu.Fixed; int malus = ninjitsu / 60 + (int)Tracking.GetStalkingBonus(attacker, defender); info = new SurpriseAttackInfo(defender, malus); - info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(8.0), new TimerStateCallback(EndSurprise), info); + info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(8.0), EndSurprise, info); m_Table[defender] = info; @@ -86,19 +85,18 @@ namespace Server.Spells.Ninjitsu public static bool GetMalus(Mobile target, ref int malus) { - if (!(m_Table[target] is SurpriseAttackInfo info)) + SurpriseAttackInfo info = m_Table[target]; + + if (info == null) return false; malus = info.m_Malus; return true; } - private static void EndSurprise(object state) + private static void EndSurprise(SurpriseAttackInfo info) { - SurpriseAttackInfo info = (SurpriseAttackInfo)state; - info.m_Timer?.Stop(); - info.m_Target.SendLocalizedMessage(1063131); // Your defenses have returned to normal. m_Table.Remove(info.m_Target); @@ -117,4 +115,4 @@ namespace Server.Spells.Ninjitsu } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Second/Cure.cs b/Scripts/Spells/Second/Cure.cs index ac336ed72..3d78f4048 100644 --- a/Scripts/Spells/Second/Cure.cs +++ b/Scripts/Spells/Second/Cure.cs @@ -49,7 +49,7 @@ namespace Server.Spells.Second if (p != null) { - int chanceToCure = 10000 + (int)(Caster.Skills[SkillName.Magery].Value * 75) - + int chanceToCure = 10000 + (int)(Caster.Skills.Magery.Value * 75) - (p.Level + 1) * (Core.AOS ? p.Level < 4 ? 3300 : 3100 : 1750); chanceToCure /= 100; diff --git a/Scripts/Spells/Second/Protection.cs b/Scripts/Spells/Second/Protection.cs index 62017a187..4a49f4c27 100644 --- a/Scripts/Spells/Second/Protection.cs +++ b/Scripts/Spells/Second/Protection.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Server.Spells.Second { @@ -14,13 +15,13 @@ namespace Server.Spells.Second Reagent.SulfurousAsh ); - private static Hashtable m_Table = new Hashtable(); + private static Dictionary> m_Table = new Dictionary>(); public ProtectionSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { } - public static Hashtable Registry{ get; } = new Hashtable(); + public static Dictionary Registry{ get; } = new Dictionary(); public override SpellCircle Circle => SpellCircle.Second; @@ -35,7 +36,7 @@ namespace Server.Spells.Second return false; } - if (!Caster.CanBeginAction(typeof(DefensiveSpell))) + if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1005385); // The spell will not adhere to you at this time. return false; @@ -55,29 +56,28 @@ namespace Server.Spells.Second * even after dying�until you �turn them off� by casting them again. */ - object[] mods = (object[])m_Table[target]; + Tuple mods = m_Table[target]; if (mods == null) { target.PlaySound(0x1E9); target.FixedParticles(0x375A, 9, 20, 5016, EffectLayer.Waist); - mods = new object[2] - { + mods = new Tuple( new ResistanceMod(ResistanceType.Physical, - -15 + Math.Min((int)(caster.Skills[SkillName.Inscribe].Value / 20), 15)), + -15 + Math.Min((int)(caster.Skills.Inscribe.Value / 20), 15)), new DefaultSkillMod(SkillName.MagicResist, true, - -35 + Math.Min((int)(caster.Skills[SkillName.Inscribe].Value / 20), 35)) - }; + -35 + Math.Min((int)(caster.Skills.Inscribe.Value / 20), 35)) + ); m_Table[target] = mods; Registry[target] = 100.0; - target.AddResistanceMod((ResistanceMod)mods[0]); - target.AddSkillMod((SkillMod)mods[1]); + target.AddResistanceMod(mods.Item1); + target.AddSkillMod(mods.Item2); - int physloss = -15 + (int)(caster.Skills[SkillName.Inscribe].Value / 20); - int resistloss = -35 + (int)(caster.Skills[SkillName.Inscribe].Value / 20); + int physloss = -15 + (int)(caster.Skills.Inscribe.Value / 20); + int resistloss = -35 + (int)(caster.Skills.Inscribe.Value / 20); string args = $"{physloss}\t{resistloss}"; BuffInfo.AddBuff(target, new BuffInfo(BuffIcon.Protection, 1075814, 1075815, args)); } @@ -89,8 +89,8 @@ namespace Server.Spells.Second m_Table.Remove(target); Registry.Remove(target); - target.RemoveResistanceMod((ResistanceMod)mods[0]); - target.RemoveSkillMod((SkillMod)mods[1]); + target.RemoveResistanceMod(mods.Item1); + target.RemoveSkillMod(mods.Item2); BuffInfo.RemoveBuff(target, BuffIcon.Protection); } @@ -98,18 +98,18 @@ namespace Server.Spells.Second public static void EndProtection(Mobile m) { - if (m_Table.Contains(m)) - { - object[] mods = (object[])m_Table[m]; + Tuple mods = m_Table[m]; - m_Table.Remove(m); - Registry.Remove(m); + if (mods == null) + return; - m.RemoveResistanceMod((ResistanceMod)mods[0]); - m.RemoveSkillMod((SkillMod)mods[1]); + m_Table.Remove(m); + Registry.Remove(m); - BuffInfo.RemoveBuff(m, BuffIcon.Protection); - } + m.RemoveResistanceMod(mods.Item1); + m.RemoveSkillMod(mods.Item2); + + BuffInfo.RemoveBuff(m, BuffIcon.Protection); } public override void OnCast() @@ -127,17 +127,17 @@ namespace Server.Spells.Second { Caster.SendLocalizedMessage(1005559); // This spell is already in effect. } - else if (!Caster.CanBeginAction(typeof(DefensiveSpell))) + else if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1005385); // The spell will not adhere to you at this time. } else if (CheckSequence()) { - if (Caster.BeginAction(typeof(DefensiveSpell))) + if (Caster.BeginAction()) { - double value = (int)(Caster.Skills[SkillName.EvalInt].Value + - Caster.Skills[SkillName.Meditation].Value + - Caster.Skills[SkillName.Inscribe].Value); + double value = (int)(Caster.Skills.EvalInt.Value + + Caster.Skills.Meditation.Value + + Caster.Skills.Inscribe.Value); value /= 4; if (value < 0) @@ -167,7 +167,7 @@ namespace Server.Spells.Second public InternalTimer(Mobile caster) : base(TimeSpan.FromSeconds(0)) { - double val = caster.Skills[SkillName.Magery].Value * 2.0; + double val = caster.Skills.Magery.Value * 2.0; if (val < 15) val = 15; else if (val > 240) @@ -185,4 +185,4 @@ namespace Server.Spells.Second } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Seventh/EnergyField.cs b/Scripts/Spells/Seventh/EnergyField.cs index 0358c223d..e43f81905 100644 --- a/Scripts/Spells/Seventh/EnergyField.cs +++ b/Scripts/Spells/Seventh/EnergyField.cs @@ -65,7 +65,7 @@ namespace Server.Spells.Seventh if (Core.AOS) duration = TimeSpan.FromSeconds((15 + Caster.Skills.Magery.Fixed / 5) / 7); else - duration = TimeSpan.FromSeconds(Caster.Skills[SkillName.Magery].Value * 0.28 + + duration = TimeSpan.FromSeconds(Caster.Skills.Magery.Value * 0.28 + 2.0); // (28% of magery) + 2.0 seconds int itemID = eastToWest ? 0x3946 : 0x3956; diff --git a/Scripts/Spells/Seventh/Polymorph.cs b/Scripts/Spells/Seventh/Polymorph.cs index b8254e745..f6a06d5b6 100644 --- a/Scripts/Spells/Seventh/Polymorph.cs +++ b/Scripts/Spells/Seventh/Polymorph.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server.Factions; using Server.Gumps; using Server.Items; @@ -19,19 +20,15 @@ namespace Server.Spells.Seventh Reagent.MandrakeRoot ); - private static Hashtable m_Timers = new Hashtable(); + private static Dictionary m_Timers = new Dictionary(); private int m_NewBody; - public PolymorphSpell(Mobile caster, Item scroll, int body) : base(caster, scroll, m_Info) + public PolymorphSpell(Mobile caster, Item scroll, int body = 0) : base(caster, scroll, m_Info) { m_NewBody = body; } - public PolymorphSpell(Mobile caster, Item scroll) : this(caster, scroll, 0) - { - } - public override SpellCircle Circle => SpellCircle.Seventh; public override bool CheckCast() @@ -66,7 +63,7 @@ namespace Server.Spells.Seventh return false; } - if (!Caster.CanBeginAction(typeof(PolymorphSpell))) + if (!Caster.CanBeginAction()) { if (Core.ML) EndPolymorph(Caster); @@ -77,11 +74,7 @@ namespace Server.Spells.Seventh if (m_NewBody == 0) { - Gump gump; - if (Core.SE) - gump = new NewPolymorphGump(Caster, Scroll); - else - gump = new PolymorphGump(Caster, Scroll); + Gump gump = Core.SE ? (Gump)new NewPolymorphGump(Caster, Scroll) : new PolymorphGump(Caster, Scroll); Caster.SendGump(gump); return false; @@ -101,7 +94,7 @@ namespace Server.Spells.Seventh { Caster.SendLocalizedMessage(1010521); // You cannot polymorph while you have a Town Sigil } - else if (!Caster.CanBeginAction(typeof(PolymorphSpell))) + else if (!Caster.CanBeginAction()) { if (Core.ML) EndPolymorph(Caster); @@ -120,13 +113,13 @@ namespace Server.Spells.Seventh { Caster.SendLocalizedMessage(1042512); // You cannot polymorph while wearing body paint } - else if (!Caster.CanBeginAction(typeof(IncognitoSpell)) || Caster.IsBodyMod) + else if (!Caster.CanBeginAction() || Caster.IsBodyMod) { DoFizzle(); } else if (CheckSequence()) { - if (Caster.BeginAction(typeof(PolymorphSpell))) + if (Caster.BeginAction()) { if (m_NewBody != 0) { @@ -141,7 +134,7 @@ namespace Server.Spells.Seventh Caster.BodyMod = m_NewBody; if (m_NewBody == 400 || m_NewBody == 401) - Caster.HueMod = Utility.RandomSkinHue(); + Caster.HueMod = Caster.Race.RandomSkinHue(); else Caster.HueMod = 0; @@ -152,11 +145,11 @@ namespace Server.Spells.Seventh { StopTimer(Caster); - Timer t = new InternalTimer(Caster); + InternalTimer timer = new InternalTimer(Caster); - m_Timers[Caster] = t; + m_Timers[Caster] = timer; - t.Start(); + timer.Start(); } } } @@ -169,26 +162,23 @@ namespace Server.Spells.Seventh FinishSequence(); } - public static bool StopTimer(Mobile m) + public static void StopTimer(Mobile m) { - Timer t = (Timer)m_Timers[m]; + InternalTimer timer = m_Timers[m]; + if (timer == null) + return; - if (t != null) - { - t.Stop(); - m_Timers.Remove(m); - } - - return t != null; + timer.Stop(); + m_Timers.Remove(m); } private static void EndPolymorph(Mobile m) { - if (!m.CanBeginAction(typeof(PolymorphSpell))) + if (!m.CanBeginAction()) { m.BodyMod = 0; m.HueMod = -1; - m.EndAction(typeof(PolymorphSpell)); + m.EndAction(); BaseArmor.ValidateMobile(m); BaseClothing.ValidateMobile(m); @@ -203,7 +193,7 @@ namespace Server.Spells.Seventh { m_Owner = owner; - int val = (int)owner.Skills[SkillName.Magery].Value; + int val = (int)owner.Skills.Magery.Value; if (val > 120) val = 120; @@ -218,4 +208,4 @@ namespace Server.Spells.Seventh } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Sixth/ParalyzeField.cs b/Scripts/Spells/Sixth/ParalyzeField.cs index b40608937..8466520d7 100644 --- a/Scripts/Spells/Sixth/ParalyzeField.cs +++ b/Scripts/Spells/Sixth/ParalyzeField.cs @@ -61,7 +61,7 @@ namespace Server.Spells.Sixth int itemID = eastToWest ? 0x3967 : 0x3979; - TimeSpan duration = TimeSpan.FromSeconds(3.0 + Caster.Skills[SkillName.Magery].Value / 3.0); + TimeSpan duration = TimeSpan.FromSeconds(3.0 + Caster.Skills.Magery.Value / 3.0); for (int i = -2; i <= 2; ++i) { @@ -171,8 +171,8 @@ namespace Server.Spells.Sixth if (Core.AOS) { - duration = 2.0 + ((int)(m_Caster.Skills[SkillName.EvalInt].Value / 10) - - (int)(m.Skills[SkillName.MagicResist].Value / 10)); + duration = 2.0 + ((int)(m_Caster.Skills.EvalInt.Value / 10) - + (int)(m.Skills.MagicResist.Value / 10)); if (!m.Player) duration *= 3.0; @@ -182,7 +182,7 @@ namespace Server.Spells.Sixth } else { - duration = 7.0 + m_Caster.Skills[SkillName.Magery].Value * 0.2; + duration = 7.0 + m_Caster.Skills.Magery.Value * 0.2; } m.Paralyze(TimeSpan.FromSeconds(duration)); diff --git a/Scripts/Spells/Sixth/Reveal.cs b/Scripts/Spells/Sixth/Reveal.cs index 18b05db09..3b7473e24 100644 --- a/Scripts/Spells/Sixth/Reveal.cs +++ b/Scripts/Spells/Sixth/Reveal.cs @@ -44,7 +44,7 @@ namespace Server.Spells.Sixth if (map != null) { IPooledEnumerable eable = map.GetMobilesInRange(new Point3D(p), - 1 + (int)(Caster.Skills[SkillName.Magery].Value / 20.0)); + 1 + (int)(Caster.Skills.Magery.Value / 20.0)); foreach (Mobile m in eable) { @@ -80,11 +80,11 @@ namespace Server.Spells.Sixth if (!Core.AOS || InvisibilitySpell.HasTimer(m)) return true; - int magery = from.Skills[SkillName.Magery].Fixed; - int detectHidden = from.Skills[SkillName.DetectHidden].Fixed; + int magery = from.Skills.Magery.Fixed; + int detectHidden = from.Skills.DetectHidden.Fixed; - int hiding = m.Skills[SkillName.Hiding].Fixed; - int stealth = m.Skills[SkillName.Stealth].Fixed; + int hiding = m.Skills.Hiding.Fixed; + int stealth = m.Skills.Stealth.Fixed; int divisor = hiding + stealth; int chance; diff --git a/Scripts/Spells/Spellweaving/AttuneWeapon.cs b/Scripts/Spells/Spellweaving/AttuneWeapon.cs index 293ead1a4..f9ffce3cb 100644 --- a/Scripts/Spells/Spellweaving/AttuneWeapon.cs +++ b/Scripts/Spells/Spellweaving/AttuneWeapon.cs @@ -30,7 +30,7 @@ namespace Server.Spells.Spellweaving return false; } - if (!Caster.CanBeginAction(typeof(AttuneWeaponSpell))) + if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(1075124); // You must wait before casting that spell again. return false; @@ -47,7 +47,7 @@ namespace Server.Spells.Spellweaving Caster.FixedParticles(0x3728, 1, 13, 0x26B8, 0x455, 7, EffectLayer.Waist); Caster.FixedParticles(0x3779, 1, 15, 0x251E, 0x3F, 7, EffectLayer.Waist); - double skill = Caster.Skills[SkillName.Spellweaving].Value; + double skill = Caster.Skills.Spellweaving.Value; int damageAbsorb = (int)(18 + (skill - 10) / 10 * 3 + FocusLevel * 6); Caster.MeleeDamageAbsorb = damageAbsorb; @@ -59,7 +59,7 @@ namespace Server.Spells.Spellweaving m_Table[Caster] = t; - Caster.BeginAction(typeof(AttuneWeaponSpell)); + Caster.BeginAction(); BuffInfo.AddBuff(Caster, new BuffInfo(BuffIcon.AttuneWeapon, 1075798, duration, Caster, damageAbsorb.ToString())); @@ -124,7 +124,7 @@ namespace Server.Spells.Spellweaving m_Table.Remove(m_Mobile); - DelayCall(TimeSpan.FromSeconds(120), delegate { m_Mobile.EndAction(typeof(AttuneWeaponSpell)); }); + DelayCall(TimeSpan.FromSeconds(120), delegate { m_Mobile.EndAction(); }); BuffInfo.RemoveBuff(m_Mobile, BuffIcon.AttuneWeapon); } } diff --git a/Scripts/Spells/Spellweaving/EssenceOfWind.cs b/Scripts/Spells/Spellweaving/EssenceOfWind.cs index 8dc8dd454..6e0a2bc7d 100644 --- a/Scripts/Spells/Spellweaving/EssenceOfWind.cs +++ b/Scripts/Spells/Spellweaving/EssenceOfWind.cs @@ -27,7 +27,7 @@ namespace Server.Spells.Spellweaving int range = 5 + FocusLevel; int damage = 25 + FocusLevel; - double skill = Caster.Skills[SkillName.Spellweaving].Value; + double skill = Caster.Skills.Spellweaving.Value; TimeSpan duration = TimeSpan.FromSeconds((int)(skill / 24) + FocusLevel); diff --git a/Scripts/Spells/Spellweaving/EtherealVoyage.cs b/Scripts/Spells/Spellweaving/EtherealVoyage.cs index feee3769e..61512015c 100644 --- a/Scripts/Spells/Spellweaving/EtherealVoyage.cs +++ b/Scripts/Spells/Spellweaving/EtherealVoyage.cs @@ -35,7 +35,7 @@ namespace Server.Spells.Spellweaving { if (TransformationSpellHelper.UnderTransformation(Caster, typeof(EtherealVoyageSpell))) Caster.SendLocalizedMessage(501775); // This spell is already in effect. - else if (!Caster.CanBeginAction(typeof(EtherealVoyageSpell))) + else if (!Caster.CanBeginAction()) Caster.SendLocalizedMessage(1075124); // You must wait before casting that spell again. else if (Caster.Combatant != null) Caster.SendLocalizedMessage(1072586); // You cannot cast Ethereal Voyage while you are in combat. @@ -68,7 +68,7 @@ namespace Server.Spells.Spellweaving TransformationSpellHelper.RemoveContext(m, true); - Timer.DelayCall(TimeSpan.FromMinutes(5), delegate { m.EndAction(typeof(EtherealVoyageSpell)); }); + Timer.DelayCall(TimeSpan.FromMinutes(5), delegate { m.EndAction(); }); BuffInfo.RemoveBuff(m, BuffIcon.EtherealVoyage); } diff --git a/Scripts/Spells/Spellweaving/GiftOfLife.cs b/Scripts/Spells/Spellweaving/GiftOfLife.cs index c16b6a7b5..bc48b61b9 100644 --- a/Scripts/Spells/Spellweaving/GiftOfLife.cs +++ b/Scripts/Spells/Spellweaving/GiftOfLife.cs @@ -72,7 +72,7 @@ namespace Server.Spells.Spellweaving m.FixedParticles(0x3709, 1, 30, 0x26ED, 5, 2, EffectLayer.Waist); m.FixedParticles(0x376A, 1, 30, 0x251E, 5, 3, EffectLayer.Waist); - double skill = Caster.Skills[SkillName.Spellweaving].Value; + double skill = Caster.Skills.Spellweaving.Value; TimeSpan duration = TimeSpan.FromMinutes((int)(skill / 24) * 2 + FocusLevel); @@ -105,7 +105,7 @@ namespace Server.Spells.Spellweaving if (master?.NetState != null && Utility.InUpdateRange(pet, master)) { - master.CloseGump(typeof(PetResurrectGump)); + master.CloseGump(); master.SendGump(new PetResurrectGump(master, pet, hitsScalar)); } else @@ -118,7 +118,7 @@ namespace Server.Spells.Spellweaving if (friend.NetState != null && Utility.InUpdateRange(pet, friend)) { - friend.CloseGump(typeof(PetResurrectGump)); + friend.CloseGump(); friend.SendGump(new PetResurrectGump(friend, pet)); break; } @@ -127,7 +127,7 @@ namespace Server.Spells.Spellweaving } else { - m.CloseGump(typeof(ResurrectGump)); + m.CloseGump(); m.SendGump(new ResurrectGump(m, hitsScalar)); } diff --git a/Scripts/Spells/Spellweaving/GiftOfRenewal.cs b/Scripts/Spells/Spellweaving/GiftOfRenewal.cs index da03bc616..4ecbb9d39 100644 --- a/Scripts/Spells/Spellweaving/GiftOfRenewal.cs +++ b/Scripts/Spells/Spellweaving/GiftOfRenewal.cs @@ -35,7 +35,7 @@ namespace Server.Spells.Spellweaving { Caster.SendLocalizedMessage(501775); // This spell is already in effect. } - else if (!Caster.CanBeginAction(typeof(GiftOfRenewalSpell))) + else if (!Caster.CanBeginAction()) { Caster.SendLocalizedMessage(501789); // You must wait before trying again. } @@ -52,7 +52,7 @@ namespace Server.Spells.Spellweaving } else { - double skill = Caster.Skills[SkillName.Spellweaving].Value; + double skill = Caster.Skills.Spellweaving.Value; int hitsPerRound = 5 + (int)(skill / 24) + FocusLevel; TimeSpan duration = TimeSpan.FromSeconds(30 + FocusLevel * 10); @@ -72,7 +72,7 @@ namespace Server.Spells.Spellweaving m_Table[m] = info; - Caster.BeginAction(typeof(GiftOfRenewalSpell)); + Caster.BeginAction(); BuffInfo.AddBuff(m, new BuffInfo(BuffIcon.GiftOfRenewal, 1031602, 1075797, duration, m, hitsPerRound.ToString())); @@ -91,7 +91,7 @@ namespace Server.Spells.Spellweaving info.m_Timer.Stop(); BuffInfo.RemoveBuff(m, BuffIcon.GiftOfRenewal); - Timer.DelayCall(TimeSpan.FromSeconds(60), delegate { info.m_Caster.EndAction(typeof(GiftOfRenewalSpell)); }); + Timer.DelayCall(TimeSpan.FromSeconds(60), delegate { info.m_Caster.EndAction(); }); return true; } diff --git a/Scripts/Spells/Spellweaving/NatureFury.cs b/Scripts/Spells/Spellweaving/NatureFury.cs index 6a226789f..d6d503f38 100644 --- a/Scripts/Spells/Spellweaving/NatureFury.cs +++ b/Scripts/Spells/Spellweaving/NatureFury.cs @@ -50,7 +50,7 @@ namespace Server.Spells.Spellweaving if (map == null) return; - HouseRegion r = Region.Find(p, map).GetRegion(typeof(HouseRegion)) as HouseRegion; + HouseRegion r = Region.Find(p, map).GetRegion(); if (r?.House != null && !r.House.IsFriend(Caster)) return; diff --git a/Scripts/Spells/Spellweaving/Thunderstorm.cs b/Scripts/Spells/Spellweaving/Thunderstorm.cs index f8ed838e6..f2ec18d01 100644 --- a/Scripts/Spells/Spellweaving/Thunderstorm.cs +++ b/Scripts/Spells/Spellweaving/Thunderstorm.cs @@ -28,7 +28,7 @@ namespace Server.Spells.Spellweaving { Caster.PlaySound(0x5CE); - double skill = Caster.Skills[SkillName.Spellweaving].Value; + double skill = Caster.Skills.Spellweaving.Value; int damage = Math.Max(11, 10 + (int)(skill / 24)) + FocusLevel; diff --git a/Scripts/Spells/Third/Poison.cs b/Scripts/Spells/Third/Poison.cs index 49455bbe4..1c88c109f 100644 --- a/Scripts/Spells/Third/Poison.cs +++ b/Scripts/Spells/Third/Poison.cs @@ -69,11 +69,11 @@ namespace Server.Spells.Third } else { - //double total = Caster.Skills[SkillName.Magery].Value + Caster.Skills[SkillName.Poisoning].Value; + //double total = Caster.Skills.Magery.Value + Caster.Skills.Poisoning.Value; #region Dueling - double total = Caster.Skills[SkillName.Magery].Value; + double total = Caster.Skills.Magery.Value; if (Caster is PlayerMobile pm) { @@ -83,12 +83,12 @@ namespace Server.Spells.Third } else { - total += pm.Skills[SkillName.Poisoning].Value; + total += pm.Skills.Poisoning.Value; } } else { - total += Caster.Skills[SkillName.Poisoning].Value; + total += Caster.Skills.Poisoning.Value; } #endregion diff --git a/Scripts/Spells/Third/Teleport.cs b/Scripts/Spells/Third/Teleport.cs index f4f9af940..dfa7f300a 100644 --- a/Scripts/Spells/Third/Teleport.cs +++ b/Scripts/Spells/Third/Teleport.cs @@ -79,7 +79,7 @@ namespace Server.Spells.Third { Caster.SendLocalizedMessage(502831); // Cannot teleport to that spot. } - else if (Region.Find(to, map).GetRegion(typeof(HouseRegion)) != null) + else if (Region.Find(to, map).IsPartOf()) { Caster.SendLocalizedMessage(502829); // Cannot teleport to that spot. } diff --git a/Scripts/Spells/Third/Unlock.cs b/Scripts/Spells/Third/Unlock.cs index 7a4fcc441..51f8c8609 100644 --- a/Scripts/Spells/Third/Unlock.cs +++ b/Scripts/Spells/Third/Unlock.cs @@ -76,7 +76,7 @@ namespace Server.Spells.Third } else { - int level = (int)(from.Skills[SkillName.Magery].Value * 0.8) - 4; + int level = (int)(from.Skills.Magery.Value * 0.8) - 4; if (level >= cont.RequiredSkill && !(cont is TreasureMapChest chest && chest.Level > 2)) diff --git a/Scripts/Targets/BladedItemTarget.cs b/Scripts/Targets/BladedItemTarget.cs index 4fe2b115f..8ba51032a 100644 --- a/Scripts/Targets/BladedItemTarget.cs +++ b/Scripts/Targets/BladedItemTarget.cs @@ -54,7 +54,8 @@ namespace Server.Targets if (qs is WitchApprenticeQuest) { - if (qs.FindObjective(typeof(FindIngredientObjective)) is FindIngredientObjective obj && !obj.Completed && obj.Ingredient == Ingredient.RedMushrooms) + FindIngredientObjective obj = qs.FindObjective(); + if (obj?.Completed == false && obj.Ingredient == Ingredient.RedMushrooms) { player.SendLocalizedMessage(1055036); // You slice a red cap mushroom from its stem. obj.Complete(); diff --git a/Scripts/Targets/MoveTarget.cs b/Scripts/Targets/MoveTarget.cs index 1057ec516..1f6746e0f 100644 --- a/Scripts/Targets/MoveTarget.cs +++ b/Scripts/Targets/MoveTarget.cs @@ -19,7 +19,7 @@ namespace Server.Targets { if (!BaseCommand.IsAccessible(from, m_Object)) { - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. return; } diff --git a/Scripts/Targets/PickMoveTarget.cs b/Scripts/Targets/PickMoveTarget.cs index 8adf5fb4d..5546c1155 100644 --- a/Scripts/Targets/PickMoveTarget.cs +++ b/Scripts/Targets/PickMoveTarget.cs @@ -13,7 +13,7 @@ namespace Server.Targets { if (!BaseCommand.IsAccessible(from, o)) { - from.SendMessage("That is not accessible."); + from.SendLocalizedMessage(500447); // That is not accessible. return; } diff --git a/Server/Body.cs b/Server/Body.cs index eed6a14e4..a41e0c6b0 100644 --- a/Server/Body.cs +++ b/Server/Body.cs @@ -54,10 +54,7 @@ namespace Server string[] split = line.Split('\t'); - BodyType type; - int bodyID; - - if (int.TryParse(split[0], out bodyID) && Enum.TryParse(split[1], true, out type) && bodyID >= 0 && + if (int.TryParse(split[0], out int bodyID) && Enum.TryParse(split[1], true, out BodyType type) && bodyID >= 0 && bodyID < m_Types.Length) { m_Types[bodyID] = type; diff --git a/Server/Commands.cs b/Server/Commands.cs index e46b3fec6..0b8668820 100644 --- a/Server/Commands.cs +++ b/Server/Commands.cs @@ -61,6 +61,14 @@ namespace Server.Commands return Utility.ToInt32(Arguments[index]); } + + public uint GetUInt32(int index) + { + if (index < 0 || index >= Arguments.Length) + return 0; + + return Utility.ToUInt32(Arguments[index]); + } public bool GetBoolean(int index) { diff --git a/Server/Diagnostics/GumpProfile.cs b/Server/Diagnostics/GumpProfile.cs index 71be281d5..5c8b918b2 100644 --- a/Server/Diagnostics/GumpProfile.cs +++ b/Server/Diagnostics/GumpProfile.cs @@ -38,9 +38,7 @@ namespace Server.Diagnostics { if (!Core.Profiling) return null; - GumpProfile prof; - - if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new GumpProfile(type)); + if (!_profiles.TryGetValue(type, out GumpProfile prof)) _profiles.Add(type, prof = new GumpProfile(type)); return prof; } diff --git a/Server/Diagnostics/PacketProfile.cs b/Server/Diagnostics/PacketProfile.cs index 22899de93..8c4828705 100644 --- a/Server/Diagnostics/PacketProfile.cs +++ b/Server/Diagnostics/PacketProfile.cs @@ -68,9 +68,7 @@ namespace Server.Diagnostics [MethodImpl(MethodImplOptions.Synchronized)] public static PacketSendProfile Acquire(Type type) { - PacketSendProfile prof; - - if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new PacketSendProfile(type)); + if (!_profiles.TryGetValue(type, out PacketSendProfile prof)) _profiles.Add(type, prof = new PacketSendProfile(type)); return prof; } @@ -102,9 +100,7 @@ namespace Server.Diagnostics [MethodImpl(MethodImplOptions.Synchronized)] public static PacketReceiveProfile Acquire(int packetId) { - PacketReceiveProfile prof; - - if (!_profiles.TryGetValue(packetId, out prof)) + if (!_profiles.TryGetValue(packetId, out PacketReceiveProfile prof)) _profiles.Add(packetId, prof = new PacketReceiveProfile(packetId)); return prof; diff --git a/Server/Diagnostics/TargetProfile.cs b/Server/Diagnostics/TargetProfile.cs index 480725c4b..10312c79f 100644 --- a/Server/Diagnostics/TargetProfile.cs +++ b/Server/Diagnostics/TargetProfile.cs @@ -38,9 +38,7 @@ namespace Server.Diagnostics { if (!Core.Profiling) return null; - TargetProfile prof; - - if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new TargetProfile(type)); + if (!_profiles.TryGetValue(type, out TargetProfile prof)) _profiles.Add(type, prof = new TargetProfile(type)); return prof; } diff --git a/Server/Diagnostics/TimerProfile.cs b/Server/Diagnostics/TimerProfile.cs index e0b633772..792cde9ea 100644 --- a/Server/Diagnostics/TimerProfile.cs +++ b/Server/Diagnostics/TimerProfile.cs @@ -44,9 +44,7 @@ namespace Server.Diagnostics { if (!Core.Profiling) return null; - TimerProfile prof; - - if (!_profiles.TryGetValue(name, out prof)) _profiles.Add(name, prof = new TimerProfile(name)); + if (!_profiles.TryGetValue(name, out TimerProfile prof)) _profiles.Add(name, prof = new TimerProfile(name)); return prof; } diff --git a/Server/Effects.cs b/Server/Effects.cs index 56372489c..70260ed45 100644 --- a/Server/Effects.cs +++ b/Server/Effects.cs @@ -284,13 +284,7 @@ namespace Server } public static void SendMovingEffect(IEntity from, IEntity to, int itemID, int speed, int duration, - bool fixedDirection, bool explodes) - { - SendMovingEffect(from, to, itemID, speed, duration, fixedDirection, explodes, 0, 0); - } - - public static void SendMovingEffect(IEntity from, IEntity to, int itemID, int speed, int duration, - bool fixedDirection, bool explodes, int hue, int renderMode) + bool fixedDirection, bool explodes, int hue = 0, int renderMode = 0) { if (from is Mobile mobile) mobile.ProcessDelta(); @@ -328,11 +322,11 @@ namespace Server bool fixedDirection, bool explodes, int hue, int renderMode, int effect, int explodeEffect, int explodeSound, EffectLayer layer, int unknown) { - if (from is Mobile mobile) - mobile.ProcessDelta(); + if (from is Mobile fromMob) + fromMob.ProcessDelta(); - if (to is Mobile mobile1) - mobile1.ProcessDelta(); + if (to is Mobile toMob) + toMob.ProcessDelta(); Map map = from.Map; @@ -376,42 +370,42 @@ namespace Server public static void SendPacket(Point3D origin, Map map, Packet p) { - if (map != null) + if (map == null) + return; + + IPooledEnumerable eable = map.GetClientsInRange(origin); + + p.Acquire(); + + foreach (NetState state in eable) { - IPooledEnumerable eable = map.GetClientsInRange(origin); - - p.Acquire(); - - foreach (NetState state in eable) - { - state.Mobile.ProcessDelta(); - state.Send(p); - } - - p.Release(); - - eable.Free(); + state.Mobile.ProcessDelta(); + state.Send(p); } + + p.Release(); + + eable.Free(); } public static void SendPacket(IPoint3D origin, Map map, Packet p) { - if (map != null) + if (map == null) + return; + + IPooledEnumerable eable = map.GetClientsInRange(new Point3D(origin)); + + p.Acquire(); + + foreach (NetState state in eable) { - IPooledEnumerable eable = map.GetClientsInRange(new Point3D(origin)); - - p.Acquire(); - - foreach (NetState state in eable) - { - state.Mobile.ProcessDelta(); - state.Send(p); - } - - p.Release(); - - eable.Free(); + state.Mobile.ProcessDelta(); + state.Send(p); } + + p.Release(); + + eable.Free(); } } } \ No newline at end of file diff --git a/Server/EventSink.cs b/Server/EventSink.cs index 81fbbba74..ba31ba159 100644 --- a/Server/EventSink.cs +++ b/Server/EventSink.cs @@ -128,12 +128,12 @@ namespace Server public class CreateGuildEventArgs : EventArgs { - public CreateGuildEventArgs(int id) + public CreateGuildEventArgs(uint id) { Id = id; } - public int Id{ get; set; } + public uint Id{ get; set; } public BaseGuild Guild{ get; set; } } diff --git a/Server/Guild.cs b/Server/Guild.cs index a13336d34..ad939f883 100644 --- a/Server/Guild.cs +++ b/Server/Guild.cs @@ -31,9 +31,9 @@ namespace Server.Guilds public abstract class BaseGuild : ISerializable { - private static int m_NextID = 1; + private static uint m_NextID = 1; - protected BaseGuild(int Id) //serialization ctor + protected BaseGuild(uint Id) //serialization ctor { this.Id = Id; List.Add(this.Id, this); @@ -48,28 +48,26 @@ namespace Server.Guilds } [CommandProperty(AccessLevel.Counselor)] - public int Id{ get; } + public uint Id{ get; } public abstract string Abbreviation{ get; set; } public abstract string Name{ get; set; } public abstract GuildType Type{ get; set; } public abstract bool Disbanded{ get; } - public static Dictionary List{ get; } = new Dictionary(); + public static Dictionary List{ get; } = new Dictionary(); int ISerializable.TypeReference => 0; - int ISerializable.SerialIdentity => Id; + uint ISerializable.SerialIdentity => Id; public abstract void Serialize(GenericWriter writer); public abstract void Deserialize(GenericReader reader); public abstract void OnDelete(Mobile mob); - public static BaseGuild Find(int id) + public static BaseGuild Find(uint id) { - BaseGuild g; - - List.TryGetValue(id, out g); + List.TryGetValue(id, out BaseGuild g); return g; } diff --git a/Server/Gumps/Gump.cs b/Server/Gumps/Gump.cs index 0cfa9b4f5..57d044282 100644 --- a/Server/Gumps/Gump.cs +++ b/Server/Gumps/Gump.cs @@ -27,7 +27,7 @@ namespace Server.Gumps { public class Gump { - private static int m_NextSerial = 1; + private static uint m_NextSerial = 1; private static byte[] m_BeginLayout = StringToBuffer("{ "); private static byte[] m_EndLayout = StringToBuffer(" }"); @@ -39,10 +39,10 @@ namespace Server.Gumps private bool m_Closable = true; private bool m_Disposable = true; - private bool m_Dragable = true; + private bool m_Draggable = true; private bool m_Resizable = true; - private int m_Serial; + private uint m_Serial; private List m_Strings; internal int m_TextEntries, m_Switches; @@ -68,7 +68,7 @@ namespace Server.Gumps public List Entries{ get; } - public int Serial + public uint Serial { get => m_Serial; set @@ -133,14 +133,14 @@ namespace Server.Gumps } } - public bool Dragable + public bool Draggable { - get => m_Dragable; + get => m_Draggable; set { - if (m_Dragable != value) + if (m_Draggable != value) { - m_Dragable = value; + m_Draggable = value; Invalidate(); } } @@ -161,7 +161,7 @@ namespace Server.Gumps public static int GetTypeID(Type type) { - return type.FullName.GetHashCode(); + return type?.FullName?.GetHashCode() ?? -1; } public void Invalidate() @@ -290,7 +290,7 @@ namespace Server.Gumps Add(new GumpTextEntryLimited(x, y, width, height, hue, entryID, initialText, size)); } - public void AddItemProperty(int serial) + public void AddItemProperty(uint serial) { Add(new GumpItemProperty(serial)); } @@ -349,7 +349,7 @@ namespace Server.Gumps else disp = new DisplayGumpFast(this); - if (!m_Dragable) + if (!m_Draggable) disp.AppendLayout(m_NoMove); if (!m_Closable) @@ -379,7 +379,7 @@ namespace Server.Gumps m_TextEntries = disp.TextEntries; m_Switches = disp.Switches; - return disp as Packet; + return (Packet)disp; } public virtual void OnResponse(NetState sender, RelayInfo info) diff --git a/Server/Gumps/GumpEntry.cs b/Server/Gumps/GumpEntry.cs index e202ad02f..6ae7604c3 100644 --- a/Server/Gumps/GumpEntry.cs +++ b/Server/Gumps/GumpEntry.cs @@ -41,6 +41,11 @@ namespace Server.Gumps } } } + + protected void Delta(ref uint var, uint val) + { + if (var != val) var = val; + } protected void Delta(ref int var, int val) { diff --git a/Server/Gumps/GumpItemProperty.cs b/Server/Gumps/GumpItemProperty.cs index 30338a196..c06e6f78f 100644 --- a/Server/Gumps/GumpItemProperty.cs +++ b/Server/Gumps/GumpItemProperty.cs @@ -25,14 +25,14 @@ namespace Server.Gumps public class GumpItemProperty : GumpEntry { private static byte[] m_LayoutName = Gump.StringToBuffer("itemproperty"); - private int m_Serial; + private uint m_Serial; - public GumpItemProperty(int serial) + public GumpItemProperty(uint serial) { m_Serial = serial; } - public int Serial + public uint Serial { get => m_Serial; set => Delta(ref m_Serial, value); diff --git a/Server/Item.cs b/Server/Item.cs index 7e46ac2f9..6e4b02a86 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -596,7 +596,7 @@ namespace Server IEntity parent; - Serial serial = reader.ReadInt(); + Serial serial = reader.ReadUInt(); if (serial.IsItem) parent = World.FindItem(serial); @@ -658,7 +658,7 @@ namespace Server Spawner = 0x100 } - public class Item : IEntity, IHued, IComparable, ISerializable, ISpawnable + public class Item : IHued, IComparable, ISerializable, ISpawnable { public const int QuestItemHue = 0x4EA; // Hmmmm... "for EA"? public static readonly List EmptyItems = new List(); @@ -730,15 +730,7 @@ namespace Server public int TempFlags { - get - { - CompactInfo info = LookupCompactInfo(); - - if (info != null) - return info.m_TempFlags; - - return 0; - } + get => LookupCompactInfo()?.m_TempFlags ?? 0; set { CompactInfo info = AcquireCompactInfo(); @@ -752,15 +744,7 @@ namespace Server public int SavedFlags { - get - { - CompactInfo info = LookupCompactInfo(); - - if (info != null) - return info.m_SavedFlags; - - return 0; - } + get => LookupCompactInfo()?.m_SavedFlags ?? 0; set { CompactInfo info = AcquireCompactInfo(); @@ -777,12 +761,7 @@ namespace Server /// public Mobile HeldBy { - get - { - CompactInfo info = LookupCompactInfo(); - - return info?.m_HeldBy; - } + get => LookupCompactInfo()?.m_HeldBy; set { CompactInfo info = AcquireCompactInfo(); @@ -797,19 +776,7 @@ namespace Server /// /// Overridable. Determines whether the item will show . /// - public virtual bool DisplayWeight - { - get - { - if (!Core.ML) - return false; - - if (!Movable && !(IsLockedDown || IsSecure) && ItemData.Weight == 255) - return false; - - return true; - } - } + public virtual bool DisplayWeight => Core.ML && (Movable || IsLockedDown || IsSecure || ItemData.Weight != 255); [CommandProperty(AccessLevel.GameMaster)] public LootType LootType @@ -1097,10 +1064,7 @@ namespace Server { CompactInfo info = LookupCompactInfo(); - if (info != null && info.m_Weight != -1) - return info.m_Weight; - - return DefaultWeight; + return info != null && info.m_Weight != -1 ? info.m_Weight : DefaultWeight; } set { @@ -1161,18 +1125,7 @@ namespace Server } } - public List Items - { - get - { - List items = LookupItems(); - - if (items == null) - items = EmptyItems; - - return items; - } - } + public List Items => LookupItems() ?? EmptyItems; [CommandProperty(AccessLevel.GameMaster)] public IEntity RootParent @@ -1230,15 +1183,7 @@ namespace Server [CommandProperty(AccessLevel.GameMaster)] public string Name { - get - { - CompactInfo info = LookupCompactInfo(); - - if (info?.m_Name != null) - return info.m_Name; - - return DefaultName; - } + get => LookupCompactInfo()?.m_Name ?? DefaultName; set { if (value == null || value != DefaultName) @@ -1390,12 +1335,7 @@ namespace Server public Mobile BlessedFor { - get - { - CompactInfo info = LookupCompactInfo(); - - return info?.m_BlessedFor; - } + get => LookupCompactInfo()?.m_BlessedFor; set { CompactInfo info = AcquireCompactInfo(); @@ -1464,7 +1404,8 @@ namespace Server { Mobile m = state.Mobile; - if (m.InRange(oldLocation, GetUpdateRange(m))) state.Send(RemovePacket); + if (m.InRange(oldLocation, GetUpdateRange(m))) + state.Send(RemovePacket); } eable.Free(); @@ -1863,7 +1804,7 @@ namespace Server int ISerializable.TypeReference => m_TypeRef; - int ISerializable.SerialIdentity => Serial; + uint ISerializable.SerialIdentity => Serial; public virtual void Serialize(GenericWriter writer) { @@ -2070,12 +2011,7 @@ namespace Server public ISpawner Spawner { - get - { - CompactInfo info = LookupCompactInfo(); - - return info?.m_Spawner; - } + get => LookupCompactInfo()?.m_Spawner; set { CompactInfo info = AcquireCompactInfo(); @@ -2141,10 +2077,7 @@ namespace Server private CompactInfo AcquireCompactInfo() { - if (m_CompactInfo == null) - m_CompactInfo = new CompactInfo(); - - return m_CompactInfo; + return m_CompactInfo ?? (m_CompactInfo = new CompactInfo()); } private void ReleaseCompactInfo() @@ -2178,27 +2111,16 @@ namespace Server if (this is Container container) return container.m_Items; - CompactInfo info = LookupCompactInfo(); - - return info?.m_Items; + return LookupCompactInfo()?.m_Items; } public List AcquireItems() { if (this is Container cont) - { - if (cont.m_Items == null) - cont.m_Items = new List(); - - return cont.m_Items; - } + return cont.m_Items ?? (cont.m_Items = new List()); CompactInfo info = AcquireCompactInfo(); - - if (info.m_Items == null) - info.m_Items = new List(); - - return info.m_Items; + return info.m_Items ?? (info.m_Items = new List()); } private void SetFlag(ImplFlag flag, bool value) @@ -2216,16 +2138,12 @@ namespace Server public BounceInfo GetBounce() { - CompactInfo info = LookupCompactInfo(); - - return info?.m_Bounce; + return LookupCompactInfo()?.m_Bounce; } public void RecordBounce() { - CompactInfo info = AcquireCompactInfo(); - - info.m_Bounce = new BounceInfo(this); + AcquireCompactInfo().m_Bounce = new BounceInfo(this); } public void ClearBounce() @@ -2234,23 +2152,23 @@ namespace Server BounceInfo bounce = info?.m_Bounce; - if (bounce != null) + if (bounce == null) + return; + + info.m_Bounce = null; + + if (bounce.m_Parent is Item parentItem) { - info.m_Bounce = null; - - if (bounce.m_Parent is Item parentItem) - { - if (!parentItem.Deleted) - parentItem.OnItemBounceCleared(this); - } - else if (bounce.m_Parent is Mobile parentMobile) - { - if (!parentMobile.Deleted) - parentMobile.OnItemBounceCleared(this); - } - - VerifyCompactInfo(); + if (!parentItem.Deleted) + parentItem.OnItemBounceCleared(this); } + else if (bounce.m_Parent is Mobile parentMobile) + { + if (!parentMobile.Deleted) + parentMobile.OnItemBounceCleared(this); + } + + VerifyCompactInfo(); } /// @@ -2560,7 +2478,7 @@ namespace Server /// { /// if ( from.Int >= 100 ) /// return true; - /// + /// /// return base.AllowEquippedCast( from ); /// } /// When placed in an Item script, the item may be cast when equipped if the has 100 or more @@ -2940,12 +2858,7 @@ namespace Server public bool GetTempFlag(int flag) { - CompactInfo info = LookupCompactInfo(); - - if (info == null) - return false; - - return (info.m_TempFlags & flag) != 0; + return ((LookupCompactInfo()?.m_TempFlags ?? 0) & flag) != 0; } public void SetTempFlag(int flag, bool value) @@ -2963,12 +2876,7 @@ namespace Server public bool GetSavedFlag(int flag) { - CompactInfo info = LookupCompactInfo(); - - if (info == null) - return false; - - return (info.m_SavedFlags & flag) != 0; + return ((LookupCompactInfo()?.m_SavedFlags ?? 0) & flag) != 0; } public void SetSavedFlag(int flag, bool value) @@ -3077,7 +2985,7 @@ namespace Server if (GetSaveFlag(flags, SaveFlag.Parent)) { - Serial parent = reader.ReadInt(); + Serial parent = reader.ReadUInt(); if (parent.IsMobile) m_Parent = World.FindMobile(parent); @@ -3197,7 +3105,7 @@ namespace Server if (GetSaveFlag(flags, SaveFlag.Parent)) { - Serial parent = reader.ReadInt(); + Serial parent = reader.ReadUInt(); if (parent.IsMobile) m_Parent = World.FindMobile(parent); @@ -3290,7 +3198,7 @@ namespace Server if (name != DefaultName) AcquireCompactInfo().m_Name = name; - Serial parent = reader.ReadInt(); + Serial parent = reader.ReadUInt(); if (parent.IsMobile) m_Parent = World.FindMobile(parent); @@ -3554,6 +3462,7 @@ namespace Server } catch { + // ignored } else m_DeltaQueue.Remove(this); @@ -3599,37 +3508,37 @@ namespace Server public void PublicOverheadMessage(MessageType type, int hue, bool ascii, string text) { - if (m_Map != null) + if (m_Map == null) + return; + + Packet p = null; + Point3D worldLoc = GetWorldLocation(); + + IPooledEnumerable eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()); + + foreach (NetState state in eable) { - Packet p = null; - Point3D worldLoc = GetWorldLocation(); + Mobile m = state.Mobile; - IPooledEnumerable eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()); - - foreach (NetState state in eable) + if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m))) { - Mobile m = state.Mobile; - - if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m))) + if (p == null) { - if (p == null) - { - if (ascii) - p = new AsciiMessage(Serial, m_ItemID, type, hue, 3, Name, text); - else - p = new UnicodeMessage(Serial, m_ItemID, type, hue, 3, "ENU", Name, text); + if (ascii) + p = new AsciiMessage(Serial, m_ItemID, type, hue, 3, Name, text); + else + p = new UnicodeMessage(Serial, m_ItemID, type, hue, 3, "ENU", Name, text); - p.Acquire(); - } - - state.Send(p); + p.Acquire(); } + + state.Send(p); } - - Packet.Release(p); - - eable.Free(); } + + Packet.Release(p); + + eable.Free(); } public void PublicOverheadMessage(MessageType type, int hue, int number) @@ -3639,30 +3548,30 @@ namespace Server public void PublicOverheadMessage(MessageType type, int hue, int number, string args) { - if (m_Map != null) + if (m_Map == null) + return; + + Packet p = null; + Point3D worldLoc = GetWorldLocation(); + + IPooledEnumerable eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()); + + foreach (NetState state in eable) { - Packet p = null; - Point3D worldLoc = GetWorldLocation(); + Mobile m = state.Mobile; - IPooledEnumerable eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()); - - foreach (NetState state in eable) + if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m))) { - Mobile m = state.Mobile; + if (p == null) + p = Packet.Acquire(new MessageLocalized(Serial, m_ItemID, type, hue, 3, number, Name, args)); - if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m))) - { - if (p == null) - p = Packet.Acquire(new MessageLocalized(Serial, m_ItemID, type, hue, 3, number, Name, args)); - - state.Send(p); - } + state.Send(p); } - - Packet.Release(p); - - eable.Free(); } + + Packet.Release(p); + + eable.Free(); } public virtual void OnAfterDelete() @@ -3673,7 +3582,7 @@ namespace Server { List items = LookupItems(); - if (items != null && items.Contains(item)) + if (items?.Contains(item) == true) { item.SendRemovePacket(); @@ -3728,26 +3637,16 @@ namespace Server public virtual bool DropToMobile(Mobile from, Mobile target, Point3D p) { - if (Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null || - target.Map == null) - return false; - if (from.AccessLevel < AccessLevel.GameMaster && !from.InRange(target.Location, 2)) - return false; - if (!from.CanSee(target) || !from.InLOS(target)) - return false; - if (!from.OnDroppedItemToMobile(this, target)) - return false; - if (!OnDroppedToMobile(from, target)) - return false; - if (!target.OnDragDrop(from, this)) - return false; - - return true; + return !(Deleted || from.Deleted || target.Deleted) && from.Map == target.Map && from.Map != null && + target.Map != null && (from.AccessLevel >= AccessLevel.GameMaster || from.InRange(target.Location, 2)) && + from.CanSee(target) && from.InLOS(target) && from.OnDroppedItemToMobile(this, target) && + OnDroppedToMobile(from, target) && target.OnDragDrop(from, this); } public virtual bool OnDroppedInto(Mobile from, Container target, Point3D p) { - if (!from.OnDroppedItemInto(this, target, p)) return false; + if (!from.OnDroppedItemInto(this, target, p)) + return false; if (Nontransferable && from.Player && target != from.Backpack) { @@ -4044,21 +3943,20 @@ namespace Server public void SendRemovePacket() { - if (!Deleted && m_Map != null) + if (Deleted || m_Map == null) + return; + Point3D worldLoc = GetWorldLocation(); + + IPooledEnumerable eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()); + + foreach (NetState state in eable) { - Point3D worldLoc = GetWorldLocation(); + Mobile m = state.Mobile; - IPooledEnumerable eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()); - - foreach (NetState state in eable) - { - Mobile m = state.Mobile; - - if (m.InRange(worldLoc, GetUpdateRange(m))) state.Send(RemovePacket); - } - - eable.Free(); + if (m.InRange(worldLoc, GetUpdateRange(m))) state.Send(RemovePacket); } + + eable.Free(); } public virtual int GetDropSound() @@ -4090,12 +3988,7 @@ namespace Server public Point3D GetWorldTop() { - IEntity root = RootParent; - - if (root == null) - return new Point3D(m_Location.m_X, m_Location.m_Y, m_Location.m_Z + ItemData.CalcHeight); - - return root.Location; + return RootParent?.Location ?? new Point3D(m_Location.m_X, m_Location.m_Y, m_Location.m_Z + ItemData.CalcHeight); } public void SendLocalizedMessageTo(Mobile to, int number) @@ -4550,65 +4443,56 @@ namespace Server { Point3D oldLocation = m_Location; - if (oldLocation != value) + if (oldLocation == value) + return; + if (m_Map != null) { - if (m_Map != null) + if (m_Parent == null) { - if (m_Parent == null) + IPooledEnumerable eable; + + if (m_Location.m_X != 0) { - IPooledEnumerable eable; - - if (m_Location.m_X != 0) - { - eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange()); - - foreach (NetState state in eable) - { - Mobile m = state.Mobile; - - if (!m.InRange(value, GetUpdateRange(m))) state.Send(RemovePacket); - } - - eable.Free(); - } - - Point3D oldLoc = m_Location; - m_Location = value; - ReleaseWorldPackets(); - - SetLastMoved(); - - eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange()); + eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange()); foreach (NetState state in eable) { Mobile m = state.Mobile; - if (m.CanSee(this) && m.InRange(m_Location, GetUpdateRange(m)) && - (!state.HighSeas || !NoMoveHS || (m_DeltaFlags & ItemDelta.Update) != 0 || - !m.InRange(oldLoc, GetUpdateRange(m)))) - SendInfoTo(state); + if (!m.InRange(value, GetUpdateRange(m))) state.Send(RemovePacket); } eable.Free(); - - RemDelta(ItemDelta.Update); } - else if (m_Parent is Item) + + Point3D oldLoc = m_Location; + m_Location = value; + ReleaseWorldPackets(); + + SetLastMoved(); + + eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange()); + + foreach (NetState state in eable) { - m_Location = value; - ReleaseWorldPackets(); + Mobile m = state.Mobile; - Delta(ItemDelta.Update); - } - else - { - m_Location = value; - ReleaseWorldPackets(); + if (m.CanSee(this) && m.InRange(m_Location, GetUpdateRange(m)) && + (!state.HighSeas || !NoMoveHS || (m_DeltaFlags & ItemDelta.Update) != 0 || + !m.InRange(oldLoc, GetUpdateRange(m)))) + SendInfoTo(state); } - if (m_Parent == null) - m_Map.OnMove(oldLocation, this); + eable.Free(); + + RemDelta(ItemDelta.Update); + } + else if (m_Parent is Item) + { + m_Location = value; + ReleaseWorldPackets(); + + Delta(ItemDelta.Update); } else { @@ -4616,8 +4500,16 @@ namespace Server ReleaseWorldPackets(); } - OnLocationChange(oldLocation); + if (m_Parent == null) + m_Map.OnMove(oldLocation, this); } + else + { + m_Location = value; + ReleaseWorldPackets(); + } + + OnLocationChange(oldLocation); } } @@ -4675,4 +4567,4 @@ namespace Server #endregion } -} \ No newline at end of file +} diff --git a/Server/Items/Container.cs b/Server/Items/Container.cs index 8662fe4a1..b3bf416c7 100644 --- a/Server/Items/Container.cs +++ b/Server/Items/Container.cs @@ -845,7 +845,6 @@ namespace Server.Items for (int i = 0; i < groups.Count; ++i) { items[i] = groups[i].ToArray(); - //items[i] = (Item[])(((ArrayList)groups[i]).ToArray( typeof( Item ) )); for (int j = 0; j < items[i].Length; ++j) totals[i] += items[i][j].Amount; @@ -939,7 +938,6 @@ namespace Server.Items for (int j = 0; j < groups.Count; ++j) { items[i][j] = groups[j].ToArray(); - //items[i][j] = (Item[])(((ArrayList)groups[j]).ToArray( typeof( Item ) )); for (int k = 0; k < items[i][j].Length; ++k) totals[i][j] += items[i][j][k].Amount; @@ -1341,7 +1339,6 @@ namespace Server.Items { Item[] items = groups[i].ToArray(); - //Item[] items = (Item[])(((ArrayList)groups[i]).ToArray( typeof( Item ) )); int total = 0; for (int j = 0; j < items.Length; ++j) @@ -1392,7 +1389,6 @@ namespace Server.Items for (int j = 0; j < groups.Count; ++j) { Item[] items = groups[j].ToArray(); - //Item[] items = (Item[])(((ArrayList)groups[j]).ToArray( typeof( Item ) )); int total = 0; for (int k = 0; k < items.Length; ++k) @@ -1445,7 +1441,6 @@ namespace Server.Items for (int j = 0; j < groups.Count; ++j) { Item[] items = groups[j].ToArray(); - //Item[] items = (Item[])(((ArrayList)groups[j]).ToArray( typeof( Item ) )); int total = 0; for (int k = 0; k < items.Length; ++k) @@ -1501,7 +1496,7 @@ namespace Server.Items { if (current == null || current.Items.Count == 0) return; - + List items = current.Items; for (int i = 0; i < items.Count; ++i) @@ -1530,7 +1525,7 @@ namespace Server.Items { if (current == null || current.Items.Count == 0) return; - + List items = current.Items; for (int i = 0; i < items.Count; ++i) @@ -1554,7 +1549,7 @@ namespace Server.Items { if (current == null || current.Items.Count == 0) return null; - + List list = current.Items; for (int i = 0; i < list.Count; ++i) @@ -1585,7 +1580,7 @@ namespace Server.Items { if (current == null || current.Items.Count <= 0) return null; - + List list = current.Items; for (int i = 0; i < list.Count; ++i) @@ -1619,7 +1614,7 @@ namespace Server.Items { List list = new List(); RecurseFindItemsByType(this, recurse, list, predicate); - + return list; } @@ -1628,7 +1623,7 @@ namespace Server.Items { if (current == null || current.Items.Count == 0) return; - + List items = current.Items; for (int i = 0; i < items.Count; ++i) @@ -1655,7 +1650,7 @@ namespace Server.Items { if (current == null || current.Items.Count == 0) return null; - + List list = current.Items; for (int i = 0; i < list.Count; ++i) @@ -1777,12 +1772,8 @@ namespace Server.Items public static ContainerData GetData(int itemID) { - ContainerData data = null; - m_Table.TryGetValue(itemID, out data); - - if (data != null) - return data; - return Default; + m_Table.TryGetValue(itemID, out ContainerData data); + return data ?? Default; } } -} \ No newline at end of file +} diff --git a/Server/Items/VirtualCheck.cs b/Server/Items/VirtualCheck.cs index 32f546d6a..51db01159 100644 --- a/Server/Items/VirtualCheck.cs +++ b/Server/Items/VirtualCheck.cs @@ -181,10 +181,10 @@ namespace Server Closable = true; Disposable = true; - Dragable = true; + Draggable = true; Resizable = false; - User.CloseGump(GetType()); + User.CloseGump(); CompileLayout(); } @@ -201,7 +201,7 @@ namespace Server public void Close() { - User.CloseGump(GetType()); + User.CloseGump(); if (Check != null && !Check.Deleted) Check.UpdateTrade(User); diff --git a/Server/Items/VirtualHair.cs b/Server/Items/VirtualHair.cs index 10fbf3547..315f607bb 100644 --- a/Server/Items/VirtualHair.cs +++ b/Server/Items/VirtualHair.cs @@ -24,12 +24,7 @@ namespace Server { public abstract class BaseHairInfo { - protected BaseHairInfo(int itemid) - : this(itemid, 0) - { - } - - protected BaseHairInfo(int itemid, int hue) + protected BaseHairInfo(int itemid, int hue = 0) { ItemID = itemid; Hue = hue; @@ -67,7 +62,7 @@ namespace Server public class HairInfo : BaseHairInfo { public HairInfo(int itemid) - : base(itemid, 0) + : base(itemid) { } @@ -81,7 +76,8 @@ namespace Server { } - public static int FakeSerial(Mobile parent) + // TOOD: Can we make this higher for newer clients? + public static uint FakeSerial(Mobile parent) { return 0x7FFFFFFF - 0x400 - parent.Serial * 4; } @@ -90,7 +86,7 @@ namespace Server public class FacialHairInfo : BaseHairInfo { public FacialHairInfo(int itemid) - : base(itemid, 0) + : base(itemid) { } @@ -104,7 +100,8 @@ namespace Server { } - public static int FakeSerial(Mobile parent) + // TOOD: Can we make this higher for newer clients? + public static uint FakeSerial(Mobile parent) { return 0x7FFFFFFF - 0x400 - 1 - parent.Serial * 4; } @@ -120,9 +117,7 @@ namespace Server if (parent.SolidHueOverride >= 0) hue = parent.SolidHueOverride; - int hairSerial = HairInfo.FakeSerial(parent); - - m_Stream.Write(hairSerial); + m_Stream.Write(HairInfo.FakeSerial(parent)); m_Stream.Write((short)parent.HairItemID); m_Stream.Write((byte)0); m_Stream.Write((byte)Layer.Hair); @@ -141,9 +136,7 @@ namespace Server if (parent.SolidHueOverride >= 0) hue = parent.SolidHueOverride; - int hairSerial = FacialHairInfo.FakeSerial(parent); - - m_Stream.Write(hairSerial); + m_Stream.Write(FacialHairInfo.FakeSerial(parent)); m_Stream.Write((short)parent.FacialHairItemID); m_Stream.Write((byte)0); m_Stream.Write((byte)Layer.FacialHair); diff --git a/Server/Map.cs b/Server/Map.cs index fe03184f8..815cf9bad 100644 --- a/Server/Map.cs +++ b/Server/Map.cs @@ -95,7 +95,7 @@ namespace Server { return s.Mobiles.OfType().Where(o => !o.Deleted && bounds.Contains(o)); } - + public static IEnumerable SelectItems(Sector s, Rectangle2D bounds) where T : Item { return s.Items.OfType() @@ -1572,5 +1572,47 @@ namespace Server } #endregion + + public Point3D GetRandomNearbyLocation(Point3D loc, int maxRange = 2, int minRange = 0, int retryCount = 10, int height = 16, bool checkBlocksFit = false, + bool checkMobiles = false) + { + int j = 0; + int range = maxRange - minRange; + bool[,] locs = range <= 10 ? new bool[range + 1, range + 1] : null; + + do + { + int xRand = Utility.Random(range); + int yRand = Utility.Random(range); + + if (locs?[xRand, yRand] != true) + { + int x = loc.X + xRand + minRange; + int y = loc.Y + yRand + minRange; + + if (CanFit(x, y, loc.Z, height, checkBlocksFit, checkMobiles)) + { + loc = new Point3D(x, y, loc.Z); + break; + } + + int z = GetAverageZ(x, y); + + if (CanFit(x, y, z, height, checkBlocksFit, checkMobiles)) + { + loc = new Point3D(x, y, z); + break; + } + + if (locs != null) + locs[xRand, yRand] = true; + } + + j++; + } + while (j < retryCount); + + return loc; + } } -} \ No newline at end of file +} diff --git a/Server/Mobile.cs b/Server/Mobile.cs index 2049857e1..8ffad92a9 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -43,15 +43,11 @@ namespace Server public delegate void TargetCallback(Mobile from, object targeted); - public delegate void TargetStateCallback(Mobile from, object targeted, object state); - - public delegate void TargetStateCallback(Mobile from, object targeted, T state); + public delegate void TargetStateCallback(Mobile from, object targeted, T state); public delegate void PromptCallback(Mobile from, string text); - public delegate void PromptStateCallback(Mobile from, string text, object state); - - public delegate void PromptStateCallback(Mobile from, string text, T state); + public delegate void PromptStateCallback(Mobile from, string text, T state); #endregion @@ -461,7 +457,7 @@ namespace Server /// /// Base class representing players, npcs, and creatures. /// - public class Mobile : IEntity, IHued, IComparable, ISerializable, ISpawnable + public class Mobile : IHued, IComparable, ISerializable, ISpawnable { private const int WarmodeCatchCount = 4; // Allow four warmode changes in 0.5 seconds, any more will be delay for two seconds @@ -677,11 +673,7 @@ namespace Server public List Stabled{ get; private set; } [CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)] - public VirtueInfo Virtues - { - get => m_Virtues; - set { } - } + public VirtueInfo Virtues{ get; private set; } public object Party{ get; set; } @@ -709,16 +701,16 @@ namespace Server public int MagicDamageAbsorb{ get; set; } [CommandProperty(AccessLevel.GameMaster)] - public int SkillsTotal => m_Skills?.Total ?? 0; + public int SkillsTotal => Skills?.Total ?? 0; [CommandProperty(AccessLevel.GameMaster)] public int SkillsCap { - get => m_Skills?.Cap ?? 0; + get => Skills?.Cap ?? 0; set { - if (m_Skills != null) - m_Skills.Cap = value; + if (Skills != null) + Skills.Cap = value; } } @@ -1250,11 +1242,7 @@ namespace Server public static IWeapon DefaultWeapon{ get; set; } [CommandProperty(AccessLevel.Counselor)] - public Skills Skills - { - get => m_Skills; - set { } - } + public Skills Skills{ get; private set; } [CommandProperty(AccessLevel.Counselor, AccessLevel.Administrator)] public AccessLevel AccessLevel @@ -2786,7 +2774,7 @@ namespace Server int ISerializable.TypeReference => m_TypeRef; - int ISerializable.SerialIdentity => Serial; + uint ISerializable.SerialIdentity => Serial; public virtual void Serialize(GenericWriter writer) { @@ -2822,7 +2810,7 @@ namespace Server writer.Write(CantWalk); - VirtueInfo.Serialize(writer, m_Virtues); + VirtueInfo.Serialize(writer, Virtues); writer.Write(Thirst); writer.Write(BAC); @@ -2892,7 +2880,7 @@ namespace Server writer.Write(m_Fame); writer.Write(m_Karma); writer.Write((byte)m_AccessLevel); - m_Skills.Serialize(writer); + Skills.Serialize(writer); writer.Write(Items); @@ -3004,7 +2992,7 @@ namespace Server public virtual void ComputeResistances() { if (Resistances == null) - Resistances = new int[5] { int.MinValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue }; + Resistances = new int[] { int.MinValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue }; for (int i = 0; i < Resistances.Length; ++i) Resistances[i] = 0; @@ -3060,10 +3048,7 @@ namespace Server public virtual int GetMaxResistance(ResistanceType type) { - if (m_Player) - return MaxPlayerResistance; - - return int.MaxValue; + return m_Player ? MaxPlayerResistance : int.MaxValue; } public int GetAOSStatus(int index) @@ -3253,7 +3238,7 @@ namespace Server for (int i = 0; i < SkillMods.Count; ++i) { SkillMod mod = SkillMods[i]; - Skill sk = m_Skills[mod.Skill]; + Skill sk = Skills[mod.Skill]; sk?.Update(); } } @@ -3283,7 +3268,7 @@ namespace Server SkillMods.Add(mod); mod.Owner = this; - Skill sk = m_Skills[mod.Skill]; + Skill sk = Skills[mod.Skill]; sk?.Update(); } } @@ -3305,7 +3290,7 @@ namespace Server SkillMods.Remove(mod); mod.Owner = null; - Skill sk = m_Skills[mod.Skill]; + Skill sk = Skills[mod.Skill]; sk?.Update(); } } @@ -3383,32 +3368,43 @@ namespace Server return m_Map.LineOfSight(this, target); } + public bool BeginAction() + { + return BeginAction(typeof(T)); + } + public bool BeginAction(object toLock) { if (_actions == null) { - _actions = new List(); - - _actions.Add(toLock); - + _actions = new List { toLock }; return true; } if (!_actions.Contains(toLock)) { _actions.Add(toLock); - return true; } return false; } + public bool CanBeginAction() + { + return CanBeginAction(typeof(T)); + } + public bool CanBeginAction(object toLock) { return _actions == null || !_actions.Contains(toLock); } + public void EndAction() + { + EndAction(typeof(T)); + } + public void EndAction(object toLock) { if (_actions != null) @@ -3794,30 +3790,13 @@ namespace Server public Target BeginTarget(int range, bool allowGround, TargetFlags flags, TargetCallback callback) { - Target t = new SimpleTarget(range, flags, allowGround, callback); - - Target = t; - - return t; - } - - public Target BeginTarget(int range, bool allowGround, TargetFlags flags, TargetStateCallback callback, object state) - { - Target t = new SimpleStateTarget(range, flags, allowGround, callback, state); - - Target = t; - - return t; + return Target = new SimpleTarget(range, flags, allowGround, callback); } public Target BeginTarget(int range, bool allowGround, TargetFlags flags, TargetStateCallback callback, T state) { - Target t = new SimpleStateTarget(range, flags, allowGround, callback, state); - - Target = t; - - return t; + return Target = new SimpleStateTarget(range, flags, allowGround, callback, state); } /// @@ -4660,10 +4639,7 @@ namespace Server //Body = this.Female ? 0x193 : 0x192; Body = Race.GhostBody(this); - Item deathShroud = new Item(0x204E); - - deathShroud.Movable = false; - deathShroud.Layer = Layer.OuterTorso; + Item deathShroud = new Item(0x204E) { Movable = false, Layer = Layer.OuterTorso }; AddItem(deathShroud); @@ -4730,11 +4706,9 @@ namespace Server } else if (!AllowItemUse(item)) { - okay = false; } else if (!item.CheckItemUse(this, item)) { - okay = false; } else if (root is Mobile mobile && mobile.IsSnoop(this)) { @@ -5355,7 +5329,7 @@ namespace Server public static Mobile GetDamagerFrom(DamageEntry de) { - return de == null ? null : de.Damager; + return de?.Damager; } public Mobile FindMostRecentDamager(bool allowSelf) @@ -5484,10 +5458,7 @@ namespace Server public virtual DamageEntry RegisterDamage(int amount, Mobile from) { - DamageEntry de = FindDamageEntryFor(from); - - if (de == null) - de = new DamageEntry(from); + DamageEntry de = FindDamageEntryFor(from) ?? new DamageEntry(from); de.DamageGiven += amount; de.LastDamage = DateTime.UtcNow; @@ -5645,10 +5616,8 @@ namespace Server if (ourState != null) { - if (ourState.DamagePacket) - p = Packet.Acquire(new DamagePacket(this, amount)); - else - p = Packet.Acquire(new DamagePacketOld(this, amount)); + p = ourState.DamagePacket ? Packet.Acquire(new DamagePacket(this, amount)) : + Packet.Acquire(new DamagePacketOld(this, amount)); ourState.Send(p); } @@ -5717,7 +5686,7 @@ namespace Server public void SendVisibleDamageSelective(Mobile from, int amount) { - NetState ourState = m_NetState, theirState = from == null ? null : from.m_NetState; + NetState ourState = m_NetState, theirState = from?.m_NetState; Mobile damager = from; Mobile damaged = this; @@ -5878,7 +5847,7 @@ namespace Server case 19: // Just removed variables case 18: { - m_Virtues = new VirtueInfo(reader); + Virtues = new VirtueInfo(reader); goto case 17; } @@ -6001,7 +5970,7 @@ namespace Server Stabled = new List(); if (version < 18) - m_Virtues = new VirtueInfo(); + Virtues = new VirtueInfo(); if (version < 11) m_DisplayGuildTitle = true; @@ -6043,7 +6012,7 @@ namespace Server m_Karma = reader.ReadInt(); m_AccessLevel = (AccessLevel)reader.ReadByte(); - m_Skills = new Skills(this, reader); + Skills = new Skills(this, reader); Items = reader.ReadStrongItemList(); @@ -6355,73 +6324,72 @@ namespace Server { Map map = m_Map; - if (map != null) - { - ProcessDelta(); + if (map == null) + return; + ProcessDelta(); - Packet p = null; - //Packet pNew = null; + Packet p = null; + //Packet pNew = null; - IPooledEnumerable eable = map.GetClientsInRange(m_Location); + IPooledEnumerable eable = map.GetClientsInRange(m_Location); - foreach (NetState state in eable) - if (state.Mobile.CanSee(this)) + foreach (NetState state in eable) + if (state.Mobile.CanSee(this)) + { + state.Mobile.ProcessDelta(); + + //if ( state.StygianAbyss ) { + //if ( pNew == null ) + //pNew = Packet.Acquire( new NewMobileAnimation( this, action, frameCount, delay ) ); + + //state.Send( pNew ); + //} else { + if (p == null) { - state.Mobile.ProcessDelta(); + #region SA - //if ( state.StygianAbyss ) { - //if ( pNew == null ) - //pNew = Packet.Acquire( new NewMobileAnimation( this, action, frameCount, delay ) ); - - //state.Send( pNew ); - //} else { - if (p == null) + if (Body.IsGargoyle) { - #region SA + frameCount = 10; - if (Body.IsGargoyle) + if (Flying) { - frameCount = 10; - - if (Flying) - { - if (action >= 9 && action <= 11) - action = 71; - else if (action >= 12 && action <= 14) - action = 72; - else if (action == 20) - action = 77; - else if (action == 31) - action = 71; - else if (action == 34) - action = 78; - else if (action >= 200 && action <= 259) - action = 75; - else if (action >= 260 && action <= 270) action = 75; - } - else - { - if (action >= 200 && action <= 259) - action = 17; - else if (action >= 260 && action <= 270) action = 16; - } + if (action >= 9 && action <= 11) + action = 71; + else if (action >= 12 && action <= 14) + action = 72; + else if (action == 20) + action = 77; + else if (action == 31) + action = 71; + else if (action == 34) + action = 78; + else if (action >= 200 && action <= 259) + action = 75; + else if (action >= 260 && action <= 270) action = 75; + } + else + { + if (action >= 200 && action <= 259) + action = 17; + else if (action >= 260 && action <= 270) action = 16; } - - #endregion - - p = Packet.Acquire(new MobileAnimation(this, action, frameCount, repeatCount, forward, repeat, - delay)); } - state.Send(p); - //} + #endregion + + p = Packet.Acquire(new MobileAnimation(this, action, frameCount, repeatCount, forward, repeat, + delay)); } - Packet.Release(p); - //Packet.Release( pNew ); + state.Send(p); + //} + } - eable.Free(); - } + Packet.Release(p); + //Packet.Release( pNew ); + + eable.Free(); } public void SendSound(int soundID) @@ -6438,23 +6406,20 @@ namespace Server public void PlaySound(int soundID) { - if (soundID == -1) + if (soundID == -1 || m_Map == null) return; - if (m_Map != null) - { - Packet p = Packet.Acquire(new PlaySound(soundID, this)); + Packet p = Packet.Acquire(new PlaySound(soundID, this)); - IPooledEnumerable eable = m_Map.GetClientsInRange(m_Location); + IPooledEnumerable eable = m_Map.GetClientsInRange(m_Location); - foreach (NetState state in eable) - if (state.Mobile.CanSee(this)) - state.Send(p); + foreach (NetState state in eable) + if (state.Mobile.CanSee(this)) + state.Send(p); - Packet.Release(p); + Packet.Release(p); - eable.Free(); - } + eable.Free(); } public virtual void OnAccessLevelChanged(AccessLevel oldLevel) @@ -6485,40 +6450,38 @@ namespace Server public void SendRemovePacket(bool everyone) { - if (m_Map != null) - { - IPooledEnumerable eable = m_Map.GetClientsInRange(m_Location); + if (m_Map == null) + return; - foreach (NetState state in eable) - if (state != m_NetState && (everyone || !state.Mobile.CanSee(this))) - state.Send(RemovePacket); + IPooledEnumerable eable = m_Map.GetClientsInRange(m_Location); - eable.Free(); - } + foreach (NetState state in eable) + if (state != m_NetState && (everyone || !state.Mobile.CanSee(this))) + state.Send(RemovePacket); + + eable.Free(); } public void ClearScreen() { - NetState ns = m_NetState; + if (m_Map == null || m_NetState == null) + return; - if (m_Map != null && ns != null) - { - IPooledEnumerable eable = m_Map.GetObjectsInRange(m_Location, Core.GlobalMaxUpdateRange); + IPooledEnumerable eable = m_Map.GetObjectsInRange(m_Location, Core.GlobalMaxUpdateRange); - foreach (IEntity o in eable) - if (o is Mobile m) - { - if (m != this && Utility.InUpdateRange(m_Location, m.m_Location)) - ns.Send(m.RemovePacket); - } - else if (o is Item item) - { - if (InRange(item.Location, item.GetUpdateRange(this))) - ns.Send(item.RemovePacket); - } + foreach (IEntity o in eable) + if (o is Mobile m) + { + if (m != this && Utility.InUpdateRange(m_Location, m.m_Location)) + m_NetState.Send(m.RemovePacket); + } + else if (o is Item item) + { + if (InRange(item.Location, item.GetUpdateRange(this))) + m_NetState.Send(item.RemovePacket); + } - eable.Free(); - } + eable.Free(); } public bool Send(Packet p) @@ -6534,7 +6497,8 @@ namespace Server return true; } - if (throwOnOffline) throw new MobileNotConnectedException(this, "Packet could not be sent."); + if (throwOnOffline) + throw new MobileNotConnectedException(this, "Packet could not be sent."); return false; } @@ -6644,10 +6608,7 @@ namespace Server public virtual int GetSeason() { - if (m_Map != null) - return m_Map.Season; - - return 1; + return m_Map?.Season ?? 1; } public virtual int GetPacketFlags() @@ -6720,27 +6681,27 @@ namespace Server { AllowedStealthSteps = 0; - if (m_Map != null) - { - IPooledEnumerable eable = m_Map.GetClientsInRange(m_Location); + if (m_Map == null) + return; - foreach (NetState state in eable) - if (!state.Mobile.CanSee(this)) - { - state.Send(RemovePacket); - } - else - { - state.Send(MobileIncoming.Create(state, state.Mobile, this)); + IPooledEnumerable eable = m_Map.GetClientsInRange(m_Location); - if (IsDeadBondedPet) - state.Send(new BondedStatus(0, Serial, 1)); + foreach (NetState state in eable) + if (!state.Mobile.CanSee(this)) + { + state.Send(RemovePacket); + } + else + { + state.Send(MobileIncoming.Create(state, state.Mobile, this)); - if (ObjectPropertyList.Enabled) state.Send(OPLPacket); - } + if (IsDeadBondedPet) + state.Send(new BondedStatus(0, Serial, 1)); - eable.Free(); - } + if (ObjectPropertyList.Enabled) state.Send(OPLPacket); + } + + eable.Free(); } public virtual void OnConnected() @@ -6757,9 +6718,11 @@ namespace Server public virtual bool CanSee(object o) { - if (o is Item item) return CanSee(item); + if (o is Item item) + return CanSee(item); - if (o is Mobile mobile) return CanSee(mobile); + if (o is Mobile mobile) + return CanSee(mobile); return true; } @@ -6835,10 +6798,7 @@ namespace Server for (int i = 0; delta < 0 && i < m_InvalidBodies.Length; ++i) delta = m_InvalidBodies[i] - body; - if (delta != 0) - return body; - - return 0; + return delta != 0 ? body : 0; } public void FreeCache() @@ -7242,7 +7202,7 @@ namespace Server /// SendMessage( "That is too heavy for you to lift." ); /// return false; /// } - /// + /// /// return base.OnDragLift( item ); /// } /// @@ -7372,7 +7332,7 @@ namespace Server { m_StatCap = 225; m_FollowersMax = 5; - m_Skills = new Skills(this); + Skills = new Skills(this); Items = new List(); StatMods = new List(); SkillMods = new List(); @@ -7380,7 +7340,7 @@ namespace Server AutoPageNotify = true; Aggressors = new List(); Aggressed = new List(); - m_Virtues = new VirtueInfo(); + Virtues = new VirtueInfo(); Stabled = new List(); DamageEntries = new List(); @@ -7519,7 +7479,7 @@ namespace Server public virtual void OnSkillsQuery(Mobile from) { if (from == this) - Send(new SkillUpdate(m_Skills)); + Send(new SkillUpdate(Skills)); } /// @@ -7735,25 +7695,6 @@ namespace Server } } - private class SimpleStateTarget : Target - { - private TargetStateCallback m_Callback; - private object m_State; - - public SimpleStateTarget(int range, TargetFlags flags, bool allowGround, TargetStateCallback callback, - object state) - : base(range, allowGround, flags) - { - m_Callback = callback; - m_State = state; - } - - protected override void OnTarget(Mobile from, object targeted) - { - m_Callback?.Invoke(from, targeted, m_State); - } - } - private class SimpleStateTarget : Target { private TargetStateCallback m_Callback; @@ -7930,7 +7871,6 @@ namespace Server private int m_Hits, m_Stam, m_Mana; private int m_Fame, m_Karma; private AccessLevel m_AccessLevel; - private Skills m_Skills; private bool m_Player; private string m_Title; private int m_LightLevel; @@ -7957,13 +7897,12 @@ namespace Server private Region m_Region; private int m_VirtualArmor; private int m_Followers, m_FollowersMax; - private List _actions; // prefer List over ArrayList for more specific profiling information + private List _actions; private Queue m_MoveRecords; private int m_WarmodeChanges; private DateTime m_NextWarmodeChange; private WarmodeTimer m_WarmodeTimer; private int m_VirtualArmorMod; - private VirtueInfo m_Virtues; private Body m_BodyMod; private Race m_Race; @@ -8231,95 +8170,17 @@ namespace Server public Prompt BeginPrompt(PromptCallback callback, PromptCallback cancelCallback) { - Prompt p = new SimplePrompt(callback, cancelCallback); - - Prompt = p; - return p; + return Prompt = new SimplePrompt(callback, cancelCallback); } - public Prompt BeginPrompt(PromptCallback callback, bool callbackHandlesCancel) + public Prompt BeginPrompt(PromptCallback callback, bool callbackHandlesCancel = false) { - Prompt p = new SimplePrompt(callback, callbackHandlesCancel); - - Prompt = p; - return p; - } - - public Prompt BeginPrompt(PromptCallback callback) - { - return BeginPrompt(callback, false); - } - - private class SimpleStatePrompt : Prompt - { - private PromptStateCallback m_Callback; - - private bool m_CallbackHandlesCancel; - private PromptStateCallback m_CancelCallback; - - private object m_State; - - public SimpleStatePrompt(PromptStateCallback callback, PromptStateCallback cancelCallback, object state) - { - m_Callback = callback; - m_CancelCallback = cancelCallback; - m_State = state; - } - - public SimpleStatePrompt(PromptStateCallback callback, bool callbackHandlesCancel, object state) - { - m_Callback = callback; - m_State = state; - m_CallbackHandlesCancel = callbackHandlesCancel; - } - - public SimpleStatePrompt(PromptStateCallback callback, object state) - : this(callback, false, state) - { - } - - public override void OnResponse(Mobile from, string text) - { - m_Callback?.Invoke(from, text, m_State); - } - - public override void OnCancel(Mobile from) - { - if (m_CallbackHandlesCancel && m_Callback != null) - m_Callback(from, "", m_State); - else - { - m_CancelCallback?.Invoke(from, "", m_State); - } - } - } - - public Prompt BeginPrompt(PromptStateCallback callback, PromptStateCallback cancelCallback, object state) - { - Prompt p = new SimpleStatePrompt(callback, cancelCallback, state); - - Prompt = p; - return p; - } - - public Prompt BeginPrompt(PromptStateCallback callback, bool callbackHandlesCancel, object state) - { - Prompt p = new SimpleStatePrompt(callback, callbackHandlesCancel, state); - - Prompt = p; - return p; - } - - public Prompt BeginPrompt(PromptStateCallback callback, object state) - { - return BeginPrompt(callback, false, state); + return Prompt = new SimplePrompt(callback, callbackHandlesCancel); } private class SimpleStatePrompt : Prompt { private PromptStateCallback m_Callback; - - private bool m_CallbackHandlesCancel; private PromptStateCallback m_CancelCallback; private T m_State; @@ -8335,11 +8196,10 @@ namespace Server { m_Callback = callback; m_State = state; - m_CallbackHandlesCancel = callbackHandlesCancel; + m_CancelCallback = callbackHandlesCancel ? callback : null; } - public SimpleStatePrompt(PromptStateCallback callback, T state) - : this(callback, false, state) + public SimpleStatePrompt(PromptStateCallback callback, T state) : this(callback, false, state) { } @@ -8350,29 +8210,18 @@ namespace Server public override void OnCancel(Mobile from) { - if (m_CallbackHandlesCancel && m_Callback != null) - m_Callback(from, "", m_State); - else - { - m_CancelCallback?.Invoke(from, "", m_State); - } + m_CancelCallback?.Invoke(from, "", m_State); } } public Prompt BeginPrompt(PromptStateCallback callback, PromptStateCallback cancelCallback, T state) { - Prompt p = new SimpleStatePrompt(callback, cancelCallback, state); - - Prompt = p; - return p; + return Prompt = new SimpleStatePrompt(callback, cancelCallback, state); } public Prompt BeginPrompt(PromptStateCallback callback, bool callbackHandlesCancel, T state) { - Prompt p = new SimpleStatePrompt(callback, callbackHandlesCancel, state); - - Prompt = p; - return p; + return Prompt = new SimpleStatePrompt(callback, callbackHandlesCancel, state); } public Prompt BeginPrompt(PromptStateCallback callback, T state) @@ -8647,123 +8496,71 @@ namespace Server return false; } - public Gump FindGump(Type type) + public Gump FindGump() where T : Gump { - NetState ns = m_NetState; - - if (ns != null) - foreach (Gump gump in ns.Gumps) - if (type.IsInstanceOfType(gump)) - return gump; - - return null; + return m_NetState?.Gumps.Find(g => g is T); } - public bool CloseGump(Type type) + public bool CloseGump() where T : Gump { - if (m_NetState != null) + if (m_NetState == null) + return false; + + Gump gump = FindGump(); + + if (gump != null) { - Gump gump = FindGump(type); - - if (gump != null) - { - m_NetState.Send(new CloseGump(gump.TypeID, 0)); - - m_NetState.RemoveGump(gump); - - gump.OnServerClose(m_NetState); - } - - return true; + // TODO: Recycle CloseGump + m_NetState.Send(new CloseGump(gump.TypeID, 0)); + m_NetState.RemoveGump(gump); + gump.OnServerClose(m_NetState); } - return false; - } - - [Obsolete("Use CloseGump( Type ) instead.")] - public bool CloseGump(Type type, int buttonID) - { - return CloseGump(type); - } - - [Obsolete("Use CloseGump( Type ) instead.")] - public bool CloseGump(Type type, int buttonID, bool throwOnOffline) - { - return CloseGump(type); + return true; } public bool CloseAllGumps() { NetState ns = m_NetState; - if (ns != null) + if (ns == null) + return false; + + List gumps = new List(ns.Gumps); + + ns.ClearGumps(); + + foreach (Gump gump in gumps) { - List gumps = new List(ns.Gumps); + ns.Send(new CloseGump(gump.TypeID, 0)); - ns.ClearGumps(); - - foreach (Gump gump in gumps) - { - ns.Send(new CloseGump(gump.TypeID, 0)); - - gump.OnServerClose(ns); - } - - return true; + gump.OnServerClose(ns); } - return false; + return true; } - [Obsolete("Use CloseAllGumps() instead.", false)] - public bool CloseAllGumps(bool throwOnOffline) + public bool HasGump() where T : Gump { - return CloseAllGumps(); - } - - public bool HasGump(Type type) - { - return FindGump(type) != null; - } - - [Obsolete("Use HasGump( Type ) instead.", false)] - public bool HasGump(Type type, bool throwOnOffline) - { - return HasGump(type); + return FindGump() != null; } public bool SendGump(Gump g) { - return SendGump(g, false); - } + if (m_NetState == null) + return false; - public bool SendGump(Gump g, bool throwOnOffline) - { - if (m_NetState != null) - { - g.SendTo(m_NetState); - return true; - } - - if (throwOnOffline) throw new MobileNotConnectedException(this, "Gump could not be sent."); - return false; + g.SendTo(m_NetState); + return true; } public bool SendMenu(IMenu m) { - return SendMenu(m, false); - } + if (m_NetState == null) + return false; - public bool SendMenu(IMenu m, bool throwOnOffline) - { - if (m_NetState != null) - { - m.SendTo(m_NetState); - return true; - } - - if (throwOnOffline) throw new MobileNotConnectedException(this, "Menu could not be sent."); - return false; + m.SendTo(m_NetState); + return true; } #endregion @@ -9830,7 +9627,7 @@ namespace Server public void MovingEffect(IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes) { - Effects.SendMovingEffect(this, to, itemID, speed, duration, fixedDirection, explodes, 0, 0); + Effects.SendMovingEffect(this, to, itemID, speed, duration, fixedDirection, explodes); } public void MovingParticles(IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, @@ -10353,4 +10150,4 @@ namespace Server #endregion } -} \ No newline at end of file +} diff --git a/Server/Network/NetState.cs b/Server/Network/NetState.cs index 201eea87c..d483d97b4 100644 --- a/Server/Network/NetState.cs +++ b/Server/Network/NetState.cs @@ -449,8 +449,7 @@ namespace Server.Network return; } - int length; - byte[] buffer = p.Compile(CompressionEnabled, out length); + byte[] buffer = p.Compile(CompressionEnabled, out int length); if (buffer != null) { diff --git a/Server/Network/PacketHandlers.cs b/Server/Network/PacketHandlers.cs index ae0fe9bf9..5dd6144d7 100644 --- a/Server/Network/PacketHandlers.cs +++ b/Server/Network/PacketHandlers.cs @@ -329,7 +329,7 @@ namespace Server.Network public static void EncodedCommand(NetState state, PacketReader pvSrc) { - IEntity e = World.FindEntity(pvSrc.ReadInt32()); + IEntity e = World.FindEntity(pvSrc.ReadUInt32()); int packetID = pvSrc.ReadUInt16(); EncodedPacketHandler ph = GetEncodedHandler(packetID); @@ -361,7 +361,7 @@ namespace Server.Network public static void RenameRequest(NetState state, PacketReader pvSrc) { Mobile from = state.Mobile; - Mobile targ = World.FindMobile(pvSrc.ReadInt32()); + Mobile targ = World.FindMobile(pvSrc.ReadUInt32()); if (targ != null) EventSink.InvokeRenameRequest(new RenameRequestEventArgs(from, targ, pvSrc.ReadStringSafe())); @@ -378,7 +378,7 @@ namespace Server.Network { case 1: // Cancel { - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); if (World.FindItem(serial) is SecureTradeContainer cont && cont.Trade != null && (cont.Trade.From.Mobile == state.Mobile || cont.Trade.To.Mobile == state.Mobile)) @@ -388,7 +388,7 @@ namespace Server.Network } case 2: // Check { - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); if (World.FindItem(serial) is SecureTradeContainer cont) { @@ -412,7 +412,7 @@ namespace Server.Network } case 3: // Update Gold { - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); if (World.FindItem(serial) is SecureTradeContainer cont) { @@ -447,7 +447,7 @@ namespace Server.Network pvSrc.Seek(1, SeekOrigin.Begin); int msgSize = pvSrc.ReadUInt16(); - Mobile vendor = World.FindMobile(pvSrc.ReadInt32()); + Mobile vendor = World.FindMobile(pvSrc.ReadUInt32()); byte flag = pvSrc.ReadByte(); if (vendor == null) return; @@ -469,7 +469,7 @@ namespace Server.Network while (msgSize > 0) { byte layer = pvSrc.ReadByte(); - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); int amount = pvSrc.ReadInt16(); buyList.Add(new BuyItemResponse(serial, amount)); @@ -487,7 +487,7 @@ namespace Server.Network public static void VendorSellReply(NetState state, PacketReader pvSrc) { - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); Mobile vendor = World.FindMobile(serial); if (vendor == null) return; @@ -505,7 +505,7 @@ namespace Server.Network for (int i = 0; i < count; i++) { - Item item = World.FindItem(pvSrc.ReadInt32()); + Item item = World.FindItem(pvSrc.ReadUInt32()); int Amount = pvSrc.ReadInt16(); if (item != null && Amount > 0) @@ -567,7 +567,7 @@ namespace Server.Network { Mobile from = state.Mobile; - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); int unk = pvSrc.ReadByte(); string lang = pvSrc.ReadString(3); @@ -590,7 +590,7 @@ namespace Server.Network public static void MobileNameRequest(NetState state, PacketReader pvSrc) { - Mobile m = World.FindMobile(pvSrc.ReadInt32()); + Mobile m = World.FindMobile(pvSrc.ReadUInt32()); if (m != null && Utility.InUpdateRange(state.Mobile, m) && state.Mobile.CanSee(m)) state.Send(new MobileName(m)); @@ -605,7 +605,7 @@ namespace Server.Network public static void AttackReq(NetState state, PacketReader pvSrc) { Mobile from = state.Mobile; - Mobile m = World.FindMobile(pvSrc.ReadInt32()); + Mobile m = World.FindMobile(pvSrc.ReadUInt32()); if (m != null) from.Attack(m); @@ -613,7 +613,7 @@ namespace Server.Network public static void HuePickerResponse(NetState state, PacketReader pvSrc) { - int serial = pvSrc.ReadInt32(); + uint serial = pvSrc.ReadUInt32(); int value = pvSrc.ReadInt16(); int hue = pvSrc.ReadInt16() & 0x3FFF; @@ -836,7 +836,7 @@ namespace Server.Network if (split.Length > 0) { int spellID = Utility.ToInt32(split[0]) - 1; - int serial = split.Length > 1 ? Utility.ToInt32(split[1]) : -1; + uint serial = split.Length > 1 ? Utility.ToUInt32(split[1]) : (uint)Serial.MinusOne; EventSink.InvokeCastSpellRequest(new CastSpellRequestEventArgs(m, spellID, World.FindItem(serial))); } @@ -892,7 +892,7 @@ namespace Server.Network public static void AsciiPromptResponse(NetState state, PacketReader pvSrc) { - int serial = pvSrc.ReadInt32(); + uint serial = pvSrc.ReadUInt32(); int prompt = pvSrc.ReadInt32(); int type = pvSrc.ReadInt32(); string text = pvSrc.ReadStringSafe(); @@ -916,7 +916,7 @@ namespace Server.Network public static void UnicodePromptResponse(NetState state, PacketReader pvSrc) { - int serial = pvSrc.ReadInt32(); + uint serial = pvSrc.ReadUInt32(); int prompt = pvSrc.ReadInt32(); int type = pvSrc.ReadInt32(); string lang = pvSrc.ReadString(4); @@ -941,7 +941,7 @@ namespace Server.Network public static void MenuResponse(NetState state, PacketReader pvSrc) { - int serial = pvSrc.ReadInt32(); + uint serial = pvSrc.ReadUInt32(); int menuID = pvSrc.ReadInt16(); // unused in our implementation int index = pvSrc.ReadInt16(); int itemID = pvSrc.ReadInt16(); @@ -966,7 +966,7 @@ namespace Server.Network public static void ProfileReq(NetState state, PacketReader pvSrc) { int type = pvSrc.ReadByte(); - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); Mobile beholder = state.Mobile; Mobile beheld = World.FindMobile(serial); @@ -1006,14 +1006,11 @@ namespace Server.Network public static void LiftReq(NetState state, PacketReader pvSrc) { - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); int amount = pvSrc.ReadUInt16(); Item item = World.FindItem(serial); - bool rejected; - LRReason reject; - - state.Mobile.Lift(item, amount, out rejected, out reject); + state.Mobile.Lift(item, amount, out bool rejected, out LRReason reject); } public static void EquipReq(NetState state, PacketReader pvSrc) @@ -1028,7 +1025,7 @@ namespace Server.Network if (!valid) return; pvSrc.Seek(5, SeekOrigin.Current); - Mobile to = World.FindMobile(pvSrc.ReadInt32()); + Mobile to = World.FindMobile(pvSrc.ReadUInt32()); if (to == null) to = from; @@ -1045,7 +1042,7 @@ namespace Server.Network int x = pvSrc.ReadInt16(); int y = pvSrc.ReadInt16(); int z = pvSrc.ReadSByte(); - Serial dest = pvSrc.ReadInt32(); + Serial dest = pvSrc.ReadUInt32(); Point3D loc = new Point3D(x, y, z); @@ -1083,7 +1080,7 @@ namespace Server.Network int y = pvSrc.ReadInt16(); int z = pvSrc.ReadSByte(); pvSrc.ReadByte(); // Grid Location? - Serial dest = pvSrc.ReadInt32(); + Serial dest = pvSrc.ReadUInt32(); Point3D loc = new Point3D(x, y, z); @@ -1140,7 +1137,7 @@ namespace Server.Network int type = pvSrc.ReadByte(); int targetID = pvSrc.ReadInt32(); int flags = pvSrc.ReadByte(); - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16(); int graphic = pvSrc.ReadUInt16(); @@ -1164,7 +1161,7 @@ namespace Server.Network // User pressed escape t.Cancel(from, TargetCancelType.Canceled); } - else if (Target.TargetIDValidation && t.TargetID != targetID) + else if (t.TargetID != targetID) { // Sanity, prevent fake target } @@ -1240,92 +1237,93 @@ namespace Server.Network public static void DisplayGumpResponse(NetState state, PacketReader pvSrc) { - int serial = pvSrc.ReadInt32(); + uint serial = pvSrc.ReadUInt32(); int typeID = pvSrc.ReadInt32(); int buttonID = pvSrc.ReadInt32(); foreach (Gump gump in state.Gumps) - if (gump.Serial == serial && gump.TypeID == typeID) + { + if (gump.Serial != serial || gump.TypeID != typeID) + continue; + bool buttonExists = buttonID == 0; // 0 is always 'close' + + if (!buttonExists) + foreach (GumpEntry e in gump.Entries) + { + if (e is GumpButton button && button.ButtonID == buttonID) + { + buttonExists = true; + break; + } + + if (e is GumpImageTileButton tileButton && tileButton.ButtonID == buttonID) + { + buttonExists = true; + break; + } + } + + if (!buttonExists) { - bool buttonExists = buttonID == 0; // 0 is always 'close' - - if (!buttonExists) - foreach (GumpEntry e in gump.Entries) - { - if (e is GumpButton button && button.ButtonID == buttonID) - { - buttonExists = true; - break; - } - - if (e is GumpImageTileButton tileButton && tileButton.ButtonID == buttonID) - { - buttonExists = true; - break; - } - } - - if (!buttonExists) - { - state.WriteConsole("Invalid gump response, disconnecting..."); - state.Dispose(); - return; - } - - int switchCount = pvSrc.ReadInt32(); - - if (switchCount < 0 || switchCount > gump.m_Switches) - { - state.WriteConsole("Invalid gump response, disconnecting..."); - state.Dispose(); - return; - } - - int[] switches = new int[switchCount]; - - for (int j = 0; j < switches.Length; ++j) - switches[j] = pvSrc.ReadInt32(); - - int textCount = pvSrc.ReadInt32(); - - if (textCount < 0 || textCount > gump.m_TextEntries) - { - state.WriteConsole("Invalid gump response, disconnecting..."); - state.Dispose(); - return; - } - - TextRelay[] textEntries = new TextRelay[textCount]; - - for (int j = 0; j < textEntries.Length; ++j) - { - int entryID = pvSrc.ReadUInt16(); - int textLength = pvSrc.ReadUInt16(); - - if (textLength > 239) - { - state.WriteConsole("Invalid gump response, disconnecting..."); - state.Dispose(); - return; - } - - string text = pvSrc.ReadUnicodeStringSafe(textLength); - textEntries[j] = new TextRelay(entryID, text); - } - - state.RemoveGump(gump); - - GumpProfile prof = GumpProfile.Acquire(gump.GetType()); - - prof?.Start(); - - gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries)); - - prof?.Finish(); - + state.WriteConsole("Invalid gump response, disconnecting..."); + state.Dispose(); return; } + int switchCount = pvSrc.ReadInt32(); + + if (switchCount < 0 || switchCount > gump.m_Switches) + { + state.WriteConsole("Invalid gump response, disconnecting..."); + state.Dispose(); + return; + } + + int[] switches = new int[switchCount]; + + for (int j = 0; j < switches.Length; ++j) + switches[j] = pvSrc.ReadInt32(); + + int textCount = pvSrc.ReadInt32(); + + if (textCount < 0 || textCount > gump.m_TextEntries) + { + state.WriteConsole("Invalid gump response, disconnecting..."); + state.Dispose(); + return; + } + + TextRelay[] textEntries = new TextRelay[textCount]; + + for (int j = 0; j < textEntries.Length; ++j) + { + int entryID = pvSrc.ReadUInt16(); + int textLength = pvSrc.ReadUInt16(); + + if (textLength > 239) + { + state.WriteConsole("Invalid gump response, disconnecting..."); + state.Dispose(); + return; + } + + string text = pvSrc.ReadUnicodeStringSafe(textLength); + textEntries[j] = new TextRelay(entryID, text); + } + + state.RemoveGump(gump); + + GumpProfile prof = GumpProfile.Acquire(gump.GetType()); + + prof?.Start(); + + gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries)); + + prof?.Finish(); + + return; + } + if (typeID == 461) { // Virtue gump @@ -1333,7 +1331,7 @@ namespace Server.Network if (buttonID == 1 && switchCount > 0) { - Mobile beheld = World.FindMobile(pvSrc.ReadInt32()); + Mobile beheld = World.FindMobile(pvSrc.ReadUInt32()); if (beheld != null) EventSink.InvokeVirtueGumpRequest(new VirtueGumpRequestEventArgs(state.Mobile, beheld)); @@ -1466,7 +1464,7 @@ namespace Server.Network if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0) { - int value = pvSrc.ReadInt32(); + uint value = pvSrc.ReadUInt32(); if ((value & ~0x7FFFFFFF) != 0) { @@ -1504,7 +1502,7 @@ namespace Server.Network { Mobile from = state.Mobile; - Serial s = pvSrc.ReadInt32(); + Serial s = pvSrc.ReadUInt32(); if (s.IsMobile) { @@ -1609,28 +1607,22 @@ namespace Server.Network PacketHandler ph = GetExtendedHandler(packetID); - if (ph != null) + if (ph == null) { - if (ph.Ingame && state.Mobile == null) - { + pvSrc.Trace(state); + return; + } + + if (ph.Ingame && state.Mobile?.Deleted != false) + { + if (state.Mobile == null) Console.WriteLine( "Client: {0}: Sent ingame packet (0xBFx{1:X2}) before having been attached to a mobile", state, packetID); - state.Dispose(); - } - else if (ph.Ingame && state.Mobile.Deleted) - { - state.Dispose(); - } - else - { - ph.OnReceive(state, pvSrc); - } + state.Dispose(); } else - { - pvSrc.Trace(state); - } + ph.OnReceive(state, pvSrc); } public static void CastSpell(NetState state, PacketReader pvSrc) @@ -1643,7 +1635,7 @@ namespace Server.Network Item spellbook = null; if (pvSrc.ReadInt16() == 1) - spellbook = World.FindItem(pvSrc.ReadInt32()); + spellbook = World.FindItem(pvSrc.ReadUInt32()); int spellID = pvSrc.ReadInt16() - 1; @@ -1659,12 +1651,12 @@ namespace Server.Network if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0) { - Item bandage = World.FindItem(pvSrc.ReadInt32()); + Item bandage = World.FindItem(pvSrc.ReadUInt32()); if (bandage == null) return; - Mobile target = World.FindMobile(pvSrc.ReadInt32()); + Mobile target = World.FindMobile(pvSrc.ReadUInt32()); if (target == null) return; @@ -1700,7 +1692,7 @@ namespace Server.Network for (int i = 0; i < count; ++i) { - Serial s = pvSrc.ReadInt32(); + Serial s = pvSrc.ReadUInt32(); if (s.IsMobile) { @@ -1727,7 +1719,7 @@ namespace Server.Network Mobile from = state.Mobile; - Serial s = pvSrc.ReadInt32(); + Serial s = pvSrc.ReadUInt32(); if (s.IsMobile) { @@ -1789,13 +1781,13 @@ namespace Server.Network public static void PartyMessage_RemoveMember(NetState state, PacketReader pvSrc) { if (PartyCommands.Handler != null) - PartyCommands.Handler.OnRemove(state.Mobile, World.FindMobile(pvSrc.ReadInt32())); + PartyCommands.Handler.OnRemove(state.Mobile, World.FindMobile(pvSrc.ReadUInt32())); } public static void PartyMessage_PrivateMessage(NetState state, PacketReader pvSrc) { if (PartyCommands.Handler != null) - PartyCommands.Handler.OnPrivateMessage(state.Mobile, World.FindMobile(pvSrc.ReadInt32()), + PartyCommands.Handler.OnPrivateMessage(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()), pvSrc.ReadUnicodeStringSafe()); } @@ -1814,13 +1806,13 @@ namespace Server.Network public static void PartyMessage_Accept(NetState state, PacketReader pvSrc) { if (PartyCommands.Handler != null) - PartyCommands.Handler.OnAccept(state.Mobile, World.FindMobile(pvSrc.ReadInt32())); + PartyCommands.Handler.OnAccept(state.Mobile, World.FindMobile(pvSrc.ReadUInt32())); } public static void PartyMessage_Decline(NetState state, PacketReader pvSrc) { if (PartyCommands.Handler != null) - PartyCommands.Handler.OnDecline(state.Mobile, World.FindMobile(pvSrc.ReadInt32())); + PartyCommands.Handler.OnDecline(state.Mobile, World.FindMobile(pvSrc.ReadUInt32())); } public static void StunRequest(NetState state, PacketReader pvSrc) @@ -1875,7 +1867,7 @@ namespace Server.Network if (menu != null && from == menu.From) { - IEntity entity = World.FindEntity(pvSrc.ReadInt32()); + IEntity entity = World.FindEntity(pvSrc.ReadUInt32()); if (entity != null && entity == menu.Target && from.CanSee(entity)) { @@ -1910,7 +1902,7 @@ namespace Server.Network public static void ContextMenuRequest(NetState state, PacketReader pvSrc) { Mobile from = state.Mobile; - IEntity target = World.FindEntity(pvSrc.ReadInt32()); + IEntity target = World.FindEntity(pvSrc.ReadUInt32()); if (from != null && target != null && from.Map == target.Map && from.CanSee(target)) { @@ -1941,7 +1933,7 @@ namespace Server.Network public static void CloseStatus(NetState state, PacketReader pvSrc) { - Serial serial = pvSrc.ReadInt32(); + Serial serial = pvSrc.ReadUInt32(); } public static void Language(NetState state, PacketReader pvSrc) @@ -1981,7 +1973,7 @@ namespace Server.Network pvSrc.ReadInt32(); // 0xEDEDEDED int type = pvSrc.ReadByte(); - Mobile m = World.FindMobile(pvSrc.ReadInt32()); + Mobile m = World.FindMobile(pvSrc.ReadUInt32()); if (m != null) switch (type) diff --git a/Server/Network/PacketReader.cs b/Server/Network/PacketReader.cs index cda8dbc86..c120903b5 100644 --- a/Server/Network/PacketReader.cs +++ b/Server/Network/PacketReader.cs @@ -60,6 +60,7 @@ namespace Server.Network } catch { + // ignored } } diff --git a/Server/Network/Packets.cs b/Server/Network/Packets.cs index b60627c7d..42fbf30f6 100644 --- a/Server/Network/Packets.cs +++ b/Server/Network/Packets.cs @@ -298,7 +298,7 @@ namespace Server.Network m_Stream.Write((short)list.Count); //The client sorts these by their X/Y value. - //OSI sends these in wierd order. X/Y highest to lowest and serial loest to highest + //OSI sends these in weird order. X/Y highest to lowest and serial lowest to highest //These are already sorted by serial (done by the vendor class) but we have to send them by x/y //(the x74 packet is sent in 'correct' order.) for (int i = list.Count - 1; i >= 0; --i) @@ -326,7 +326,7 @@ namespace Server.Network m_Stream.Write((short)list.Count); //The client sorts these by their X/Y value. - //OSI sends these in wierd order. X/Y highest to lowest and serial loest to highest + //OSI sends these in weird order. X/Y highest to lowest and serial loewst to highest //These are already sorted by serial (done by the vendor class) but we have to send them by x/y //(the x74 packet is sent in 'correct' order.) for (int i = list.Count - 1; i >= 0; --i) @@ -1142,11 +1142,11 @@ namespace Server.Network m_Stream.Write((byte)0); /*} else if ( ) { m_Stream.Write( (byte) 0x01 ); - + m_Stream.Write( (int) item.Serial ); - + m_Stream.Write( (short) itemID ); - + m_Stream.Write( (byte) item.Direction );*/ } else @@ -1200,11 +1200,11 @@ namespace Server.Network m_Stream.Write((byte)0); /*} else if ( ) { m_Stream.Write( (byte) 0x01 ); - + m_Stream.Write( (int) item.Serial ); - + m_Stream.Write( (ushort) itemID ); - + m_Stream.Write( (byte) item.Direction );*/ } else @@ -2346,6 +2346,7 @@ namespace Server.Network void AppendLayout(bool val); void AppendLayout(int val); + void AppendLayout(uint val); void AppendLayoutNS(int val); void AppendLayout(string text); void AppendLayout(byte[] buffer); @@ -2404,6 +2405,14 @@ namespace Server.Network m_Layout.Write(m_Buffer, 0, bytes); } + public void AppendLayout(uint val) + { + string toString = val.ToString(); + int bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1) + 1; + + m_Layout.Write(m_Buffer, 0, bytes); + } + public void AppendLayoutNS(int val) { string toString = val.ToString(); @@ -2548,6 +2557,15 @@ namespace Server.Network m_LayoutLength += bytes; } + public void AppendLayout(uint val) + { + string toString = val.ToString(); + int bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1) + 1; + + m_Stream.Write(m_Buffer, 0, bytes); + m_LayoutLength += bytes; + } + public void AppendLayoutNS(int val) { string toString = val.ToString(); @@ -3094,12 +3112,17 @@ namespace Server.Network IWeapon weapon = m.Weapon; - int min = 0, max = 0; - - weapon?.GetStatusDamage(m, out min, out max); - - m_Stream.Write((short)min); // Damage min - m_Stream.Write((short)max); // Damage max + if (weapon != null) + { + weapon.GetStatusDamage(m, out int min, out int max); + m_Stream.Write((short)min); // Damage min + m_Stream.Write((short)max); // Damage max + } + else + { + m_Stream.Write((short)0); // Damage min + m_Stream.Write((short)0); // Damage max + } m_Stream.Write(m.TithingPoints); } @@ -3193,12 +3216,17 @@ namespace Server.Network IWeapon weapon = beheld.Weapon; - int min = 0, max = 0; - - weapon?.GetStatusDamage(beheld, out min, out max); - - m_Stream.Write((short)min); // Damage min - m_Stream.Write((short)max); // Damage max + if (weapon != null) + { + weapon.GetStatusDamage(beheld, out int min, out int max); + m_Stream.Write((short)min); // Damage min + m_Stream.Write((short)max); // Damage max + } + else + { + m_Stream.Write((short)0); // Damage min + m_Stream.Write((short)0); // Damage max + } m_Stream.Write(beheld.TithingPoints); } @@ -3748,17 +3776,7 @@ namespace Server.Network public sealed class MovementAck : Packet { - private static MovementAck[][] m_Cache = new MovementAck[8][] - { - new MovementAck[256], - new MovementAck[256], - new MovementAck[256], - new MovementAck[256], - new MovementAck[256], - new MovementAck[256], - new MovementAck[256], - new MovementAck[256] - }; + private static MovementAck[] m_Cache = new MovementAck[8 * 256]; private MovementAck(int seq, int noto) : base(0x22, 3) { @@ -3770,11 +3788,11 @@ namespace Server.Network { int noto = Notoriety.Compute(m, m); - MovementAck p = m_Cache[noto][seq]; + MovementAck p = m_Cache[noto * seq]; if (p == null) { - m_Cache[noto][seq] = p = new MovementAck(seq, noto); + m_Cache[noto * seq] = p = new MovementAck(seq, noto); p.SetStatic(); } @@ -4183,6 +4201,7 @@ namespace Server.Network } } + [Flags] public enum AffixType : byte { Append = 0x00, @@ -4606,4 +4625,4 @@ namespace Server.Network Warned = 0x10 } } -} \ No newline at end of file +} diff --git a/Server/Persistence/BinaryMemoryWriter.cs b/Server/Persistence/BinaryMemoryWriter.cs index 83dc64214..27a82ab92 100644 --- a/Server/Persistence/BinaryMemoryWriter.cs +++ b/Server/Persistence/BinaryMemoryWriter.cs @@ -35,7 +35,7 @@ namespace Server protected override int BufferSize => 512; - public int CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile, int typeCode, int serial) + public int CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile, int typeCode, uint serial) { Flush(); diff --git a/Server/Persistence/ParallelSaveStrategy.cs b/Server/Persistence/ParallelSaveStrategy.cs index c5737f67c..02132c602 100644 --- a/Server/Persistence/ParallelSaveStrategy.cs +++ b/Server/Persistence/ParallelSaveStrategy.cs @@ -81,7 +81,7 @@ namespace Server WaitHandle.WaitAll( Array.ConvertAll( consumers, - delegate(Consumer input) { return input.completionEvent; } + input => input.completionEvent ) ); diff --git a/Server/Persistence/QueuedMemoryWriter.cs b/Server/Persistence/QueuedMemoryWriter.cs index f4ad4981a..ede3556a2 100644 --- a/Server/Persistence/QueuedMemoryWriter.cs +++ b/Server/Persistence/QueuedMemoryWriter.cs @@ -73,11 +73,6 @@ namespace Server { IndexInfo info = _orderedIndexInfo[i]; - int typeCode = info.typeCode; - int serial = info.serial; - int length = info.size; - - indexBuffer[0] = (byte)info.typeCode; indexBuffer[1] = (byte)(info.typeCode >> 8); indexBuffer[2] = (byte)(info.typeCode >> 16); @@ -115,7 +110,7 @@ namespace Server { public int size; public int typeCode; - public int serial; + public uint serial; } } } \ No newline at end of file diff --git a/Server/Poison.cs b/Server/Poison.cs index 75188097f..558be8eac 100644 --- a/Server/Poison.cs +++ b/Server/Poison.cs @@ -65,17 +65,7 @@ namespace Server public static Poison Parse(string value) { - Poison p = null; - - int plevel; - - if (int.TryParse(value, out plevel)) - p = GetPoison(plevel); - - if (p == null) - p = GetPoison(value); - - return p; + return (int.TryParse(value, out int plevel) ? GetPoison(plevel) : null) ?? GetPoison(value); } public static Poison GetPoison(int level) diff --git a/Server/Region.cs b/Server/Region.cs index 750ae967e..3b7e9458c 100644 --- a/Server/Region.cs +++ b/Server/Region.cs @@ -398,6 +398,7 @@ namespace Server return false; } + // TODO: Memoize this public bool IsChildOf(Region region) { if (region == null) @@ -415,6 +416,22 @@ namespace Server return false; } + + // TODO: Memoize this + public T GetRegion() where T : Region + { + Region r = this; + + do + { + if (r is T tr) + return tr; + + r = r.Parent; + } while (r != null); + + return null; + } public Region GetRegion(Type regionType) { @@ -451,18 +468,15 @@ namespace Server return null; } + + public bool IsPartOf() where T : Region + { + return GetRegion() != null; + } public bool IsPartOf(Region region) { - if (this == region) - return true; - - return IsChildOf(region); - } - - public bool IsPartOf(Type regionType) - { - return GetRegion(regionType) != null; + return this == region || IsChildOf(region); } public bool IsPartOf(string regionName) @@ -472,16 +486,7 @@ namespace Server public virtual bool AcceptsSpawnsFrom(Region region) { - if (!AllowSpawn()) - return false; - - if (region == this) - return true; - - if (Parent != null) - return Parent.AcceptsSpawnsFrom(region); - - return false; + return AllowSpawn() && (region == this || Parent?.AcceptsSpawnsFrom(region) == true); } public List GetPlayers() @@ -554,9 +559,7 @@ namespace Server public override string ToString() { - if (m_Name != null) - return m_Name; - return GetType().Name; + return m_Name ?? GetType().Name; } @@ -596,18 +599,12 @@ namespace Server public virtual Type GetResource(Type type) { - if (Parent != null) - return Parent.GetResource(type); - - return type; + return Parent != null ? Parent.GetResource(type) : type; } public virtual bool CanUseStuckMenu(Mobile m) { - if (Parent != null) - return Parent.CanUseStuckMenu(m); - - return true; + return Parent == null || Parent.CanUseStuckMenu(m); } public virtual void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal) @@ -632,61 +629,39 @@ namespace Server public virtual bool OnTarget(Mobile m, Target t, object o) { - if (Parent != null) - return Parent.OnTarget(m, t, o); - - return true; + return Parent == null || Parent.OnTarget(m, t, o); } public virtual bool OnCombatantChange(Mobile m, Mobile Old, Mobile New) { - if (Parent != null) - return Parent.OnCombatantChange(m, Old, New); - - return true; + return Parent == null || Parent.OnCombatantChange(m, Old, New); } public virtual bool AllowHousing(Mobile from, Point3D p) { - if (Parent != null) - return Parent.AllowHousing(from, p); - - return true; + return Parent == null || Parent.AllowHousing(from, p); } public virtual bool SendInaccessibleMessage(Item item, Mobile from) { - if (Parent != null) - return Parent.SendInaccessibleMessage(item, from); - - return false; + return Parent != null && Parent.SendInaccessibleMessage(item, from); } public virtual bool CheckAccessibility(Item item, Mobile from) { - if (Parent != null) - return Parent.CheckAccessibility(item, from); - - return true; + return Parent == null || Parent.CheckAccessibility(item, from); } public virtual bool OnDecay(Item item) { - if (Parent != null) - return Parent.OnDecay(item); - - return true; + return Parent == null || Parent.OnDecay(item); } public virtual bool AllowHarmful(Mobile from, Mobile target) { - if (Parent != null) - return Parent.AllowHarmful(from, target); - - if (Mobile.AllowHarmfulHandler != null) - return Mobile.AllowHarmfulHandler(from, target); - - return true; + return Parent?.AllowHarmful(from, target) == true || + Mobile.AllowHarmfulHandler == null || + Mobile.AllowHarmfulHandler(from, target); } public virtual void OnCriminalAction(Mobile m, bool message) @@ -699,13 +674,9 @@ namespace Server public virtual bool AllowBeneficial(Mobile from, Mobile target) { - if (Parent != null) - return Parent.AllowBeneficial(from, target); - - if (Mobile.AllowBeneficialHandler != null) - return Mobile.AllowBeneficialHandler(from, target); - - return true; + return Parent?.AllowBeneficial(from, target) == true || + Mobile.AllowBeneficialHandler == null || + Mobile.AllowBeneficialHandler(from, target); } public virtual void OnBeneficialAction(Mobile helper, Mobile target) @@ -730,18 +701,12 @@ namespace Server public virtual bool OnSkillUse(Mobile m, int Skill) { - if (Parent != null) - return Parent.OnSkillUse(m, Skill); - - return true; + return Parent == null || Parent.OnSkillUse(m, Skill); } public virtual bool OnBeginSpellCast(Mobile m, ISpell s) { - if (Parent != null) - return Parent.OnBeginSpellCast(m, s); - - return true; + return Parent == null || Parent.OnBeginSpellCast(m, s); } public virtual void OnSpellCast(Mobile m, ISpell s) @@ -751,18 +716,12 @@ namespace Server public virtual bool OnResurrect(Mobile m) { - if (Parent != null) - return Parent.OnResurrect(m); - - return true; + return Parent == null || Parent.OnResurrect(m); } public virtual bool OnBeforeDeath(Mobile m) { - if (Parent != null) - return Parent.OnBeforeDeath(m); - - return true; + return Parent == null || Parent.OnBeforeDeath(m); } public virtual void OnDeath(Mobile m) @@ -772,42 +731,27 @@ namespace Server public virtual bool OnDamage(Mobile m, ref int Damage) { - if (Parent != null) - return Parent.OnDamage(m, ref Damage); - - return true; + return Parent == null || Parent.OnDamage(m, ref Damage); } public virtual bool OnHeal(Mobile m, ref int Heal) { - if (Parent != null) - return Parent.OnHeal(m, ref Heal); - - return true; + return Parent == null || Parent.OnHeal(m, ref Heal); } public virtual bool OnDoubleClick(Mobile m, object o) { - if (Parent != null) - return Parent.OnDoubleClick(m, o); - - return true; + return Parent == null || Parent.OnDoubleClick(m, o); } public virtual bool OnSingleClick(Mobile m, object o) { - if (Parent != null) - return Parent.OnSingleClick(m, o); - - return true; + return Parent == null || Parent.OnSingleClick(m, o); } public virtual bool AllowSpawn() { - if (Parent != null) - return Parent.AllowSpawn(); - - return true; + return Parent == null || Parent.AllowSpawn(); } public virtual void AlterLightLevel(Mobile m, ref int global, ref int personal) @@ -863,14 +807,14 @@ namespace Server if (oldRChild >= newRChild) { - oldR.OnExit(m); - oldR = oldR.Parent; + oldR?.OnExit(m); + oldR = oldR?.Parent; } if (newRChild >= oldRChild) { - newR.OnEnter(m); - newR = newR.Parent; + newR?.OnEnter(m); + newR = newR?.Parent; } } } @@ -892,19 +836,22 @@ namespace Server XmlElement root = doc["ServerRegions"]; if (root == null) + { Console.WriteLine("Could not find root element 'ServerRegions' in Regions.xml"); - else - foreach (XmlElement facet in root.SelectNodes("Facet")) + return; + } + + foreach (XmlElement facet in root.SelectNodes("Facet")) + { + Map map = null; + if (ReadMap(facet, "name", ref map)) { - Map map = null; - if (ReadMap(facet, "name", ref map)) - { - if (map == Map.Internal) - Console.WriteLine("Invalid internal map in a facet element"); - else - LoadRegions(facet, map, null); - } + if (map == Map.Internal) + Console.WriteLine("Invalid internal map in a facet element"); + else + LoadRegions(facet, map, null); } + } Console.WriteLine("done"); } @@ -1088,9 +1035,7 @@ namespace Server Type type = typeof(T); - T tempVal; - - if (type.IsEnum && Enum.TryParse(s, true, out tempVal)) + if (type.IsEnum && Enum.TryParse(s, true, out T tempVal)) { value = tempVal; return true; diff --git a/Server/ScriptCompiler.cs b/Server/ScriptCompiler.cs index d03f08b1c..f78c62d38 100644 --- a/Server/ScriptCompiler.cs +++ b/Server/ScriptCompiler.cs @@ -127,17 +127,7 @@ namespace Server } } - public static bool CompileCSScripts(out Assembly assembly) - { - return CompileCSScripts(false, true, out assembly); - } - - public static bool CompileCSScripts(bool debug, out Assembly assembly) - { - return CompileCSScripts(debug, true, out assembly); - } - - public static bool CompileCSScripts(bool debug, bool cache, out Assembly assembly) + public static bool CompileCSScripts(out Assembly assembly, bool cache = true, bool debug = false) { Console.Write("Scripts: Compiling C# scripts..."); string[] files = GetScripts("*.cs"); @@ -190,6 +180,7 @@ namespace Server } catch { + // ignored } DeleteFiles("Scripts.CS*.dll"); @@ -252,6 +243,7 @@ namespace Server } catch { + // ignored } assembly = results.CompiledAssembly; @@ -259,17 +251,7 @@ namespace Server } } - public static bool CompileVBScripts(out Assembly assembly) - { - return CompileVBScripts(false, out assembly); - } - - public static bool CompileVBScripts(bool debug, out Assembly assembly) - { - return CompileVBScripts(debug, true, out assembly); - } - - public static bool CompileVBScripts(bool debug, bool cache, out Assembly assembly) + public static bool CompileVBScripts(out Assembly assembly, bool cache = true, bool debug = false) { Console.Write("Scripts: Compiling VB.NET scripts..."); string[] files = GetScripts("*.vb"); @@ -323,6 +305,7 @@ namespace Server } catch { + // ignored } } @@ -540,11 +523,10 @@ namespace Server List assemblies = new List(); - Assembly assembly; - - if (CompileCSScripts(debug, cache, out assembly)) + if (CompileCSScripts(out Assembly assembly, cache, debug)) { - if (assembly != null) assemblies.Add(assembly); + if (assembly != null) + assemblies.Add(assembly); } else { @@ -553,9 +535,10 @@ namespace Server if (Core.VBdotNet) { - if (CompileVBScripts(debug, cache, out assembly)) + if (CompileVBScripts(out Assembly vbAssembly, cache, debug)) { - if (assembly != null) assemblies.Add(assembly); + if (vbAssembly != null) + assemblies.Add(vbAssembly); } else { @@ -567,7 +550,8 @@ namespace Server Console.WriteLine("Scripts: Skipping VB.NET Scripts...done (use -vb to enable)"); } - if (assemblies.Count == 0) return false; + if (assemblies.Count == 0) + return false; Assemblies = assemblies.ToArray(); @@ -618,8 +602,7 @@ namespace Server return m_NullCache; } - TypeCache c = null; - m_TypeCaches.TryGetValue(asm, out c); + m_TypeCaches.TryGetValue(asm, out TypeCache c); if (c == null) m_TypeCaches[asm] = c = new TypeCache(asm); @@ -758,7 +741,7 @@ namespace Server public Type Get(string key, bool ignoreCase) { - Type t = null; + Type t; if (ignoreCase) m_Insensitive.TryGetValue(key, out t); diff --git a/Server/Serial.cs b/Server/Serial.cs index f0a0f9e75..3ea527f6a 100644 --- a/Server/Serial.cs +++ b/Server/Serial.cs @@ -22,9 +22,9 @@ using System; namespace Server { - public struct Serial : IComparable, IComparable + public struct Serial : IComparable, IComparable, IComparable { - public static readonly Serial MinusOne = new Serial(-1); + public static readonly Serial MinusOne = new Serial(0xFFFFFFFF); public static readonly Serial Zero = new Serial(0); public static Serial LastMobile{ get; private set; } = Zero; @@ -55,46 +55,52 @@ namespace Server } } - private Serial(int serial) + private Serial(uint serial) { Value = serial; } - public int Value{ get; } + public uint Value{ get; } public bool IsMobile => Value > 0 && Value < 0x40000000; - public bool IsItem => Value >= 0x40000000 && Value <= 0x7FFFFFFF; + public bool IsItem => Value >= 0x40000000 && Value < 0x80000000; public bool IsValid => Value > 0; public override int GetHashCode() { - return Value; + return Value.GetHashCode(); } - + public int CompareTo(Serial other) { return Value.CompareTo(other.Value); } - public int CompareTo(object other) + public int CompareTo(object obj) { - if (other is Serial serial) - return CompareTo(serial); - - if (other == null) - return -1; - - throw new ArgumentException(); + return Value.CompareTo(obj); } - public override bool Equals(object o) + public int CompareTo(uint other) { - if (!(o is Serial serial)) - return false; + return Value.CompareTo(other); + } - return serial.Value == Value; + public override bool Equals(object obj) + { + if (obj is Serial serial) + { + return this == serial; + } + + if (obj is uint u) + { + return Value == u; + } + + return false; } public static bool operator ==(Serial l, Serial r) @@ -127,22 +133,17 @@ namespace Server return l.Value <= r.Value; } - /*public static Serial operator ++ ( Serial l ) - { - return new Serial( l + 1 ); - }*/ - public override string ToString() { return $"0x{Value:X8}"; } - public static implicit operator int(Serial a) + public static implicit operator uint(Serial a) { return a.Value; } - public static implicit operator Serial(int a) + public static implicit operator Serial(uint a) { return new Serial(a); } diff --git a/Server/Serialization.cs b/Server/Serialization.cs index 69542bfde..f053688cb 100644 --- a/Server/Serialization.cs +++ b/Server/Serialization.cs @@ -67,10 +67,6 @@ namespace Server public abstract T ReadMobile() where T : Mobile; public abstract T ReadGuild() where T : BaseGuild; - public abstract ArrayList ReadItemList(); - public abstract ArrayList ReadMobileList(); - public abstract ArrayList ReadGuildList(); - public abstract List ReadStrongItemList(); public abstract List ReadStrongItemList() where T : Item; @@ -139,15 +135,6 @@ namespace Server public abstract void Write(Race value); - public abstract void WriteItemList(ArrayList list); - public abstract void WriteItemList(ArrayList list, bool tidy); - - public abstract void WriteMobileList(ArrayList list); - public abstract void WriteMobileList(ArrayList list, bool tidy); - - public abstract void WriteGuildList(ArrayList list); - public abstract void WriteGuildList(ArrayList list, bool tidy); - public abstract void Write(List list); public abstract void Write(List list, bool tidy); @@ -370,8 +357,7 @@ namespace Server } catch { - if (ticks < now) d = TimeSpan.MaxValue; - else d = TimeSpan.MaxValue; + d = TimeSpan.MaxValue; } Write(d); @@ -476,18 +462,12 @@ namespace Server if (m_Index + 8 > m_Buffer.Length) Flush(); -#if MONO - byte[] bytes = BitConverter.GetBytes(value); - for(int i = 0; i < bytes.Length; i++) - m_Buffer[m_Index++] = bytes[i]; -#else fixed (byte* pBuffer = m_Buffer) { *(double*)(pBuffer + m_Index) = value; } m_Index += 8; -#endif } public override unsafe void Write(float value) @@ -495,18 +475,12 @@ namespace Server if (m_Index + 4 > m_Buffer.Length) Flush(); -#if MONO - byte[] bytes = BitConverter.GetBytes(value); - for(int i = 0; i < bytes.Length; i++) - m_Buffer[m_Index++] = bytes[i]; -#else fixed (byte* pBuffer = m_Buffer) { *(float*)(pBuffer + m_Index) = value; } m_Index += 4; -#endif } public override void Write(char value) @@ -632,66 +606,6 @@ namespace Server Write(value); } - public override void WriteMobileList(ArrayList list) - { - WriteMobileList(list, false); - } - - public override void WriteMobileList(ArrayList list, bool tidy) - { - if (tidy) - for (int i = 0; i < list.Count;) - if (((Mobile)list[i]).Deleted) - list.RemoveAt(i); - else - ++i; - - Write(list.Count); - - for (int i = 0; i < list.Count; ++i) - Write((Mobile)list[i]); - } - - public override void WriteItemList(ArrayList list) - { - WriteItemList(list, false); - } - - public override void WriteItemList(ArrayList list, bool tidy) - { - if (tidy) - for (int i = 0; i < list.Count;) - if (((Item)list[i]).Deleted) - list.RemoveAt(i); - else - ++i; - - Write(list.Count); - - for (int i = 0; i < list.Count; ++i) - Write((Item)list[i]); - } - - public override void WriteGuildList(ArrayList list) - { - WriteGuildList(list, false); - } - - public override void WriteGuildList(ArrayList list, bool tidy) - { - if (tidy) - for (int i = 0; i < list.Count;) - if (((BaseGuild)list[i]).Disbanded) - list.RemoveAt(i); - else - ++i; - - Write(list.Count); - - for (int i = 0; i < list.Count; ++i) - Write((BaseGuild)list[i]); - } - public override void Write(List list) { Write(list, false); @@ -757,7 +671,7 @@ namespace Server Write(set.Count); - foreach (Item item in set) Write(item); + foreach (T item in set) Write(item); } public override void Write(List list) @@ -825,7 +739,7 @@ namespace Server Write(set.Count); - foreach (Mobile mob in set) Write(mob); + foreach (T mob in set) Write(mob); } public override void Write(List list) @@ -893,7 +807,7 @@ namespace Server Write(set.Count); - foreach (BaseGuild guild in set) Write(guild); + foreach (T guild in set) Write(guild); } } @@ -920,9 +834,7 @@ namespace Server public override string ReadString() { - if (ReadByte() != 0) - return m_File.ReadString(); - return null; + return ReadByte() != 0 ? m_File.ReadString() : null; } public override DateTime ReadDeltaTime() @@ -1076,7 +988,7 @@ namespace Server public override IEntity ReadEntity() { - Serial serial = ReadInt(); + Serial serial = ReadUInt(); IEntity entity = World.FindEntity(serial); if (entity == null) return new Entity(serial, new Point3D(0, 0, 0), Map.Internal); @@ -1085,17 +997,17 @@ namespace Server public override Item ReadItem() { - return World.FindItem(ReadInt()); + return World.FindItem(ReadUInt()); } public override Mobile ReadMobile() { - return World.FindMobile(ReadInt()); + return World.FindMobile(ReadUInt()); } public override BaseGuild ReadGuild() { - return BaseGuild.Find(ReadInt()); + return BaseGuild.Find(ReadUInt()); } public override T ReadItem() @@ -1113,69 +1025,6 @@ namespace Server return ReadGuild() as T; } - public override ArrayList ReadItemList() - { - int count = ReadInt(); - - if (count > 0) - { - ArrayList list = new ArrayList(count); - - for (int i = 0; i < count; ++i) - { - Item item = ReadItem(); - - if (item != null) list.Add(item); - } - - return list; - } - - return new ArrayList(); - } - - public override ArrayList ReadMobileList() - { - int count = ReadInt(); - - if (count > 0) - { - ArrayList list = new ArrayList(count); - - for (int i = 0; i < count; ++i) - { - Mobile m = ReadMobile(); - - if (m != null) list.Add(m); - } - - return list; - } - - return new ArrayList(); - } - - public override ArrayList ReadGuildList() - { - int count = ReadInt(); - - if (count > 0) - { - ArrayList list = new ArrayList(count); - - for (int i = 0; i < count; ++i) - { - BaseGuild g = ReadGuild(); - - if (g != null) list.Add(g); - } - - return list; - } - - return new ArrayList(); - } - public override List ReadStrongItemList() { return ReadStrongItemList(); @@ -1384,10 +1233,9 @@ namespace Server m_WriteQueue.Enqueue(mem); } - if (m_WorkerThread == null || !m_WorkerThread.IsAlive) + if (m_WorkerThread.IsAlive != true) { - m_WorkerThread = new Thread(new WorkerThread(this).Worker); - m_WorkerThread.Priority = ThreadPriority.BelowNormal; + m_WorkerThread = new Thread(new WorkerThread(this).Worker) { Priority = ThreadPriority.BelowNormal }; m_WorkerThread.Start(); } } @@ -1453,8 +1301,7 @@ namespace Server } catch { - if (ticks < now) d = TimeSpan.MaxValue; - else d = TimeSpan.MaxValue; + d = TimeSpan.MaxValue; } Write(d); @@ -1659,66 +1506,6 @@ namespace Server Write(value); } - public override void WriteMobileList(ArrayList list) - { - WriteMobileList(list, false); - } - - public override void WriteMobileList(ArrayList list, bool tidy) - { - if (tidy) - for (int i = 0; i < list.Count;) - if (((Mobile)list[i]).Deleted) - list.RemoveAt(i); - else - ++i; - - Write(list.Count); - - for (int i = 0; i < list.Count; ++i) - Write((Mobile)list[i]); - } - - public override void WriteItemList(ArrayList list) - { - WriteItemList(list, false); - } - - public override void WriteItemList(ArrayList list, bool tidy) - { - if (tidy) - for (int i = 0; i < list.Count;) - if (((Item)list[i]).Deleted) - list.RemoveAt(i); - else - ++i; - - Write(list.Count); - - for (int i = 0; i < list.Count; ++i) - Write((Item)list[i]); - } - - public override void WriteGuildList(ArrayList list) - { - WriteGuildList(list, false); - } - - public override void WriteGuildList(ArrayList list, bool tidy) - { - if (tidy) - for (int i = 0; i < list.Count;) - if (((BaseGuild)list[i]).Disbanded) - list.RemoveAt(i); - else - ++i; - - Write(list.Count); - - for (int i = 0; i < list.Count; ++i) - Write((BaseGuild)list[i]); - } - public override void Write(List list) { Write(list, false); @@ -1784,7 +1571,7 @@ namespace Server Write(set.Count); - foreach (Item item in set) Write(item); + foreach (T item in set) Write(item); } public override void Write(List list) @@ -1852,7 +1639,7 @@ namespace Server Write(set.Count); - foreach (Mobile mob in set) Write(mob); + foreach (T mob in set) Write(mob); } public override void Write(List list) @@ -1920,7 +1707,7 @@ namespace Server Write(set.Count); - foreach (BaseGuild guild in set) Write(guild); + foreach (T guild in set) Write(guild); } private class WorkerThread @@ -1936,7 +1723,7 @@ namespace Server { ThreadCount++; - int lastCount = 0; + int lastCount; do { @@ -1966,7 +1753,7 @@ namespace Server public interface ISerializable { int TypeReference{ get; } - int SerialIdentity{ get; } + uint SerialIdentity{ get; } void Serialize(GenericWriter writer); } -} \ No newline at end of file +} diff --git a/Server/Skills.cs b/Server/Skills.cs index 3f1f7cd5e..56a8a4f29 100644 --- a/Server/Skills.cs +++ b/Server/Skills.cs @@ -424,8 +424,7 @@ namespace Server public double GainFactor{ get; set; } - public static SkillInfo[] Table{ get; set; } = new SkillInfo[58] - { + public static SkillInfo[] Table{ get; set; } = { new SkillInfo(0, "Alchemy", 0.0, 5.0, 5.0, "Alchemist", null, 0.0, 0.5, 0.5, 1.0), new SkillInfo(1, "Anatomy", 0.0, 0.0, 0.0, "Biologist", null, 0.15, 0.15, 0.7, 1.0), new SkillInfo(2, "Animal Lore", 0.0, 0.0, 0.0, "Naturalist", null, 0.0, 0.0, 1.0, 1.0), @@ -548,6 +547,7 @@ namespace Server } else { + // Will be discarded new Skill(this, null, reader); } @@ -710,419 +710,184 @@ namespace Server m_Highest = skill; Owner.OnSkillInvalidated(skill); - - NetState ns = Owner.NetState; - - ns?.Send(new SkillChange(skill)); + Owner.NetState?.Send(new SkillChange(skill)); } #region Skill Getters & Setters [CommandProperty(AccessLevel.Counselor)] - public Skill Alchemy - { - get => this[SkillName.Alchemy]; - set { } - } + public Skill Alchemy => this[SkillName.Alchemy]; [CommandProperty(AccessLevel.Counselor)] - public Skill Anatomy - { - get => this[SkillName.Anatomy]; - set { } - } + public Skill Anatomy => this[SkillName.Anatomy]; [CommandProperty(AccessLevel.Counselor)] - public Skill AnimalLore - { - get => this[SkillName.AnimalLore]; - set { } - } + public Skill AnimalLore => this[SkillName.AnimalLore]; [CommandProperty(AccessLevel.Counselor)] - public Skill ItemID - { - get => this[SkillName.ItemID]; - set { } - } + public Skill ItemID => this[SkillName.ItemID]; [CommandProperty(AccessLevel.Counselor)] - public Skill ArmsLore - { - get => this[SkillName.ArmsLore]; - set { } - } + public Skill ArmsLore => this[SkillName.ArmsLore]; [CommandProperty(AccessLevel.Counselor)] - public Skill Parry - { - get => this[SkillName.Parry]; - set { } - } + public Skill Parry => this[SkillName.Parry]; [CommandProperty(AccessLevel.Counselor)] - public Skill Begging - { - get => this[SkillName.Begging]; - set { } - } + public Skill Begging => this[SkillName.Begging]; [CommandProperty(AccessLevel.Counselor)] - public Skill Blacksmith - { - get => this[SkillName.Blacksmith]; - set { } - } + public Skill Blacksmith => this[SkillName.Blacksmith]; [CommandProperty(AccessLevel.Counselor)] - public Skill Fletching - { - get => this[SkillName.Fletching]; - set { } - } + public Skill Fletching => this[SkillName.Fletching]; [CommandProperty(AccessLevel.Counselor)] - public Skill Peacemaking - { - get => this[SkillName.Peacemaking]; - set { } - } + public Skill Peacemaking => this[SkillName.Peacemaking]; [CommandProperty(AccessLevel.Counselor)] - public Skill Camping - { - get => this[SkillName.Camping]; - set { } - } + public Skill Camping => this[SkillName.Camping]; [CommandProperty(AccessLevel.Counselor)] - public Skill Carpentry - { - get => this[SkillName.Carpentry]; - set { } - } + public Skill Carpentry => this[SkillName.Carpentry]; [CommandProperty(AccessLevel.Counselor)] - public Skill Cartography - { - get => this[SkillName.Cartography]; - set { } - } + public Skill Cartography => this[SkillName.Cartography]; [CommandProperty(AccessLevel.Counselor)] - public Skill Cooking - { - get => this[SkillName.Cooking]; - set { } - } + public Skill Cooking => this[SkillName.Cooking]; [CommandProperty(AccessLevel.Counselor)] - public Skill DetectHidden - { - get => this[SkillName.DetectHidden]; - set { } - } + public Skill DetectHidden => this[SkillName.DetectHidden]; [CommandProperty(AccessLevel.Counselor)] - public Skill Discordance - { - get => this[SkillName.Discordance]; - set { } - } + public Skill Discordance => this[SkillName.Discordance]; [CommandProperty(AccessLevel.Counselor)] - public Skill EvalInt - { - get => this[SkillName.EvalInt]; - set { } - } + public Skill EvalInt => this[SkillName.EvalInt]; [CommandProperty(AccessLevel.Counselor)] - public Skill Healing - { - get => this[SkillName.Healing]; - set { } - } + public Skill Healing => this[SkillName.Healing]; [CommandProperty(AccessLevel.Counselor)] - public Skill Fishing - { - get => this[SkillName.Fishing]; - set { } - } + public Skill Fishing => this[SkillName.Fishing]; [CommandProperty(AccessLevel.Counselor)] - public Skill Forensics - { - get => this[SkillName.Forensics]; - set { } - } + public Skill Forensics => this[SkillName.Forensics]; [CommandProperty(AccessLevel.Counselor)] - public Skill Herding - { - get => this[SkillName.Herding]; - set { } - } + public Skill Herding => this[SkillName.Herding]; [CommandProperty(AccessLevel.Counselor)] - public Skill Hiding - { - get => this[SkillName.Hiding]; - set { } - } + public Skill Hiding => this[SkillName.Hiding]; [CommandProperty(AccessLevel.Counselor)] - public Skill Provocation - { - get => this[SkillName.Provocation]; - set { } - } + public Skill Provocation => this[SkillName.Provocation]; [CommandProperty(AccessLevel.Counselor)] - public Skill Inscribe - { - get => this[SkillName.Inscribe]; - set { } - } + public Skill Inscribe => this[SkillName.Inscribe]; [CommandProperty(AccessLevel.Counselor)] - public Skill Lockpicking - { - get => this[SkillName.Lockpicking]; - set { } - } + public Skill Lockpicking => this[SkillName.Lockpicking]; [CommandProperty(AccessLevel.Counselor)] - public Skill Magery - { - get => this[SkillName.Magery]; - set { } - } + public Skill Magery => this[SkillName.Magery]; [CommandProperty(AccessLevel.Counselor)] - public Skill MagicResist - { - get => this[SkillName.MagicResist]; - set { } - } + public Skill MagicResist => this[SkillName.MagicResist]; [CommandProperty(AccessLevel.Counselor)] - public Skill Tactics - { - get => this[SkillName.Tactics]; - set { } - } + public Skill Tactics => this[SkillName.Tactics]; [CommandProperty(AccessLevel.Counselor)] - public Skill Snooping - { - get => this[SkillName.Snooping]; - set { } - } + public Skill Snooping => this[SkillName.Snooping]; [CommandProperty(AccessLevel.Counselor)] - public Skill Musicianship - { - get => this[SkillName.Musicianship]; - set { } - } + public Skill Musicianship => this[SkillName.Musicianship]; [CommandProperty(AccessLevel.Counselor)] - public Skill Poisoning - { - get => this[SkillName.Poisoning]; - set { } - } + public Skill Poisoning => this[SkillName.Poisoning]; [CommandProperty(AccessLevel.Counselor)] - public Skill Archery - { - get => this[SkillName.Archery]; - set { } - } + public Skill Archery => this[SkillName.Archery]; [CommandProperty(AccessLevel.Counselor)] - public Skill SpiritSpeak - { - get => this[SkillName.SpiritSpeak]; - set { } - } + public Skill SpiritSpeak => this[SkillName.SpiritSpeak]; [CommandProperty(AccessLevel.Counselor)] - public Skill Stealing - { - get => this[SkillName.Stealing]; - set { } - } + public Skill Stealing => this[SkillName.Stealing]; [CommandProperty(AccessLevel.Counselor)] - public Skill Tailoring - { - get => this[SkillName.Tailoring]; - set { } - } + public Skill Tailoring => this[SkillName.Tailoring]; [CommandProperty(AccessLevel.Counselor)] - public Skill AnimalTaming - { - get => this[SkillName.AnimalTaming]; - set { } - } + public Skill AnimalTaming => this[SkillName.AnimalTaming]; [CommandProperty(AccessLevel.Counselor)] - public Skill TasteID - { - get => this[SkillName.TasteID]; - set { } - } + public Skill TasteID => this[SkillName.TasteID]; [CommandProperty(AccessLevel.Counselor)] - public Skill Tinkering - { - get => this[SkillName.Tinkering]; - set { } - } + public Skill Tinkering => this[SkillName.Tinkering]; [CommandProperty(AccessLevel.Counselor)] - public Skill Tracking - { - get => this[SkillName.Tracking]; - set { } - } + public Skill Tracking => this[SkillName.Tracking]; [CommandProperty(AccessLevel.Counselor)] - public Skill Veterinary - { - get => this[SkillName.Veterinary]; - set { } - } + public Skill Veterinary => this[SkillName.Veterinary]; [CommandProperty(AccessLevel.Counselor)] - public Skill Swords - { - get => this[SkillName.Swords]; - set { } - } + public Skill Swords => this[SkillName.Swords]; [CommandProperty(AccessLevel.Counselor)] - public Skill Macing - { - get => this[SkillName.Macing]; - set { } - } + public Skill Macing => this[SkillName.Macing]; [CommandProperty(AccessLevel.Counselor)] - public Skill Fencing - { - get => this[SkillName.Fencing]; - set { } - } + public Skill Fencing => this[SkillName.Fencing]; [CommandProperty(AccessLevel.Counselor)] - public Skill Wrestling - { - get => this[SkillName.Wrestling]; - set { } - } + public Skill Wrestling => this[SkillName.Wrestling]; [CommandProperty(AccessLevel.Counselor)] - public Skill Lumberjacking - { - get => this[SkillName.Lumberjacking]; - set { } - } + public Skill Lumberjacking => this[SkillName.Lumberjacking]; [CommandProperty(AccessLevel.Counselor)] - public Skill Mining - { - get => this[SkillName.Mining]; - set { } - } + public Skill Mining => this[SkillName.Mining]; [CommandProperty(AccessLevel.Counselor)] - public Skill Meditation - { - get => this[SkillName.Meditation]; - set { } - } + public Skill Meditation => this[SkillName.Meditation]; [CommandProperty(AccessLevel.Counselor)] - public Skill Stealth - { - get => this[SkillName.Stealth]; - set { } - } + public Skill Stealth => this[SkillName.Stealth]; [CommandProperty(AccessLevel.Counselor)] - public Skill RemoveTrap - { - get => this[SkillName.RemoveTrap]; - set { } - } + public Skill RemoveTrap => this[SkillName.RemoveTrap]; [CommandProperty(AccessLevel.Counselor)] - public Skill Necromancy - { - get => this[SkillName.Necromancy]; - set { } - } + public Skill Necromancy => this[SkillName.Necromancy]; [CommandProperty(AccessLevel.Counselor)] - public Skill Focus - { - get => this[SkillName.Focus]; - set { } - } + public Skill Focus => this[SkillName.Focus]; [CommandProperty(AccessLevel.Counselor)] - public Skill Chivalry - { - get => this[SkillName.Chivalry]; - set { } - } + public Skill Chivalry => this[SkillName.Chivalry]; [CommandProperty(AccessLevel.Counselor)] - public Skill Bushido - { - get => this[SkillName.Bushido]; - set { } - } + public Skill Bushido => this[SkillName.Bushido]; [CommandProperty(AccessLevel.Counselor)] - public Skill Ninjitsu - { - get => this[SkillName.Ninjitsu]; - set { } - } + public Skill Ninjitsu => this[SkillName.Ninjitsu]; [CommandProperty(AccessLevel.Counselor)] - public Skill Spellweaving - { - get => this[SkillName.Spellweaving]; - set { } - } + public Skill Spellweaving => this[SkillName.Spellweaving]; [CommandProperty(AccessLevel.Counselor)] - public Skill Mysticism - { - get => this[SkillName.Mysticism]; - set { } - } + public Skill Mysticism => this[SkillName.Mysticism]; [CommandProperty(AccessLevel.Counselor)] - public Skill Imbuing - { - get => this[SkillName.Imbuing]; - set { } - } + public Skill Imbuing => this[SkillName.Imbuing]; [CommandProperty(AccessLevel.Counselor)] - public Skill Throwing - { - get => this[SkillName.Throwing]; - set { } - } + public Skill Throwing => this[SkillName.Throwing]; #endregion } diff --git a/Server/Targeting/Target.cs b/Server/Targeting/Target.cs index 4e00064d0..9df06fba1 100644 --- a/Server/Targeting/Target.cs +++ b/Server/Targeting/Target.cs @@ -39,8 +39,6 @@ namespace Server.Targeting CheckLOS = true; } - public static bool TargetIDValidation{ get; set; } = true; - public DateTime TimeoutTime{ get; private set; } public bool CheckLOS{ get; set; } @@ -59,13 +57,8 @@ namespace Server.Targeting public static void Cancel(Mobile m) { - NetState ns = m.NetState; - - ns?.Send(CancelTarget.Instance); - - Target targ = m.Target; - - targ?.OnTargetCancel(m, TargetCancelType.Canceled); + m.NetState?.Send(CancelTarget.Instance); + m.Target?.OnTargetCancel(m, TargetCancelType.Canceled); } public void BeginTimeout(Mobile from, TimeSpan delay) @@ -81,7 +74,6 @@ namespace Server.Targeting public void CancelTimeout() { m_TimeoutTimer?.Stop(); - m_TimeoutTimer = null; } @@ -204,11 +196,11 @@ namespace Server.Targeting OnTargetOutOfLOS(from, targeted); else if (item?.InSecureTrade == true) OnTargetInSecureTrade(from, targeted); - else if (item?.IsAccessibleTo(from) == true) + else if (item?.IsAccessibleTo(from) == false) OnTargetNotAccessible(from, targeted); - else if (item?.CheckTarget(from, this, targeted) == true) + else if (item?.CheckTarget(from, this, targeted) == false) OnTargetUntargetable(from, targeted); - else if (mobile?.CheckTarget(from, this, mobile) != true) + else if (mobile?.CheckTarget(from, this, mobile) == false) OnTargetUntargetable(from, mobile); else if (from.Region.OnTarget(from, this, targeted)) OnTarget(from, targeted); diff --git a/Server/Targeting/TargetFlags.cs b/Server/Targeting/TargetFlags.cs index c665b17d5..fade1b5b4 100644 --- a/Server/Targeting/TargetFlags.cs +++ b/Server/Targeting/TargetFlags.cs @@ -18,8 +18,11 @@ * ***************************************************************************/ +using System; + namespace Server.Targeting { + [Flags] public enum TargetFlags : byte { None = 0x00, diff --git a/Server/TileMatrix.cs b/Server/TileMatrix.cs index f96ff514a..03aa5e192 100644 --- a/Server/TileMatrix.cs +++ b/Server/TileMatrix.cs @@ -713,6 +713,12 @@ namespace Server public int Compare(UOPEntry x, UOPEntry y) { + if (x == null) + return y == null ? 0 : 1; + + if (y == null) + return -1; + return x.m_Offset.CompareTo(y.m_Offset); } } diff --git a/Server/Timer.cs b/Server/Timer.cs index 6ce81605e..35f3f53e5 100644 --- a/Server/Timer.cs +++ b/Server/Timer.cs @@ -40,9 +40,7 @@ namespace Server public delegate void TimerCallback(); - public delegate void TimerStateCallback(object state); - - public delegate void TimerStateCallback(T state); + public delegate void TimerStateCallback(T state); public class Timer { @@ -293,8 +291,7 @@ namespace Server string key = t.ToString(); - List list; - hash.TryGetValue(key, out list); + hash.TryGetValue(key, out List list); if (list == null) hash[key] = list = new List(); @@ -517,36 +514,6 @@ namespace Server return t; } - public static Timer DelayCall(TimerStateCallback callback, object state) - { - return DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, state); - } - - public static Timer DelayCall(TimeSpan delay, TimerStateCallback callback, object state) - { - return DelayCall(delay, TimeSpan.Zero, 1, callback, state); - } - - public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerStateCallback callback, object state) - { - return DelayCall(delay, interval, 0, callback, state); - } - - public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback, - object state) - { - Timer t = new DelayStateCallTimer(delay, interval, count, callback, state); - - if (count == 1) - t.Priority = ComputePriority(delay); - else - t.Priority = ComputePriority(interval); - - t.Start(); - - return t; - } - #endregion #region DelayCall(..) @@ -571,10 +538,7 @@ namespace Server { Timer t = new DelayStateCallTimer(delay, interval, count, callback, state); - if (count == 1) - t.Priority = ComputePriority(delay); - else - t.Priority = ComputePriority(interval); + t.Priority = ComputePriority(count == 1 ? delay : interval); t.Start(); @@ -609,34 +573,6 @@ namespace Server } } - private class DelayStateCallTimer : Timer - { - private object m_State; - - public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback, - object state) : base(delay, interval, count) - { - Callback = callback; - m_State = state; - - RegCreation(); - } - - public TimerStateCallback Callback{ get; } - - public override bool DefRegCreation => false; - - protected override void OnTick() - { - Callback?.Invoke(m_State); - } - - public override string ToString() - { - return $"DelayStateCall[{FormatDelegate(Callback)}]"; - } - } - private class DelayStateCallTimer : Timer { private T m_State; diff --git a/Server/Utility.cs b/Server/Utility.cs index 2f5545db3..f7fcfe25b 100644 --- a/Server/Utility.cs +++ b/Server/Utility.cs @@ -166,11 +166,10 @@ namespace Server public static IPAddress Intern(IPAddress ipAddress) { - if (_ipAddressTable == null) _ipAddressTable = new Dictionary(); + if (_ipAddressTable == null) + _ipAddressTable = new Dictionary(); - IPAddress interned; - - if (!_ipAddressTable.TryGetValue(ipAddress, out interned)) + if (!_ipAddressTable.TryGetValue(ipAddress, out IPAddress interned)) { interned = ipAddress; _ipAddressTable[ipAddress] = interned; @@ -186,18 +185,14 @@ namespace Server public static bool IsValidIP(string text) { - bool valid = true; - - IPMatch(text, IPAddress.None, ref valid); + IPMatch(text, IPAddress.None, out bool valid); return valid; } public static bool IPMatch(string val, IPAddress ip) { - bool valid = true; - - return IPMatch(val, ip, ref valid); + return IPMatch(val, ip, out _); } public static string FixHtml(string str) @@ -428,7 +423,7 @@ namespace Server return false; } - public static bool IPMatch(string val, IPAddress ip, ref bool valid) + public static bool IPMatch(string val, IPAddress ip, out bool valid) { valid = true; @@ -698,17 +693,6 @@ namespace Server } } - public static ArrayList BuildArrayList(IEnumerable enumerable) - { - IEnumerator e = enumerable.GetEnumerator(); - - ArrayList list = new ArrayList(); - - while (e.MoveNext()) list.Add(e.Current); - - return list; - } - public static bool RangeCheck(IPoint2D p1, IPoint2D p2, int range) { return p1.X >= p2.X - range @@ -800,6 +784,7 @@ namespace Server } catch { + // ignored } } @@ -811,6 +796,7 @@ namespace Server } catch { + // ignored } } @@ -864,9 +850,14 @@ namespace Server m.FacialHairHue = m.Race.RandomHairHue(); } - public static List CastConvertList(List list) where TOutput : TInput + public static List CastListContravariant(List list) where TInput : TOutput { - return list.ConvertAll(delegate(TInput value) { return (TOutput)value; }); + return list.ConvertAll(value => (TOutput)value); + } + + public static List CastListCovariant(List list) where TOutput : TInput + { + return list.ConvertAll(value => (TOutput)value); } public static List SafeConvertList(List list) where TOutput : class @@ -888,24 +879,21 @@ namespace Server public static bool ToBoolean(string value) { - bool b; - bool.TryParse(value, out b); + bool.TryParse(value, out bool b); return b; } public static double ToDouble(string value) { - double d; - double.TryParse(value, out d); + double.TryParse(value, out double d); return d; } public static TimeSpan ToTimeSpan(string value) { - TimeSpan t; - TimeSpan.TryParse(value, out t); + TimeSpan.TryParse(value, out TimeSpan t); return t; } @@ -922,6 +910,18 @@ namespace Server return i; } + public static uint ToUInt32(string value) + { + uint i; + + if (value.StartsWith("0x")) + uint.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i); + else + uint.TryParse(value, out i); + + return i; + } + #endregion #region Get[Something] @@ -934,10 +934,7 @@ namespace Server } catch { - if (double.TryParse(doubleString, out double val)) - return val; - - return defaultValue; + return double.TryParse(doubleString, out double val) ? val : defaultValue; } } @@ -949,10 +946,19 @@ namespace Server } catch { - if (int.TryParse(intString, out int val)) - return val; + return int.TryParse(intString, out int val) ? val : defaultValue; + } + } - return defaultValue; + public static uint GetXMLUInt32(string uintString, uint defaultValue) + { + try + { + return XmlConvert.ToUInt32(uintString); + } + catch + { + return uint.TryParse(uintString, out uint val) ? val : defaultValue; } } @@ -964,10 +970,7 @@ namespace Server } catch { - if (DateTime.TryParse(dateTimeString, out DateTime d)) - return d; - - return defaultValue; + return DateTime.TryParse(dateTimeString, out DateTime d) ? d : defaultValue; } } @@ -979,10 +982,7 @@ namespace Server } catch { - if (DateTimeOffset.TryParse(dateTimeOffsetString, out DateTimeOffset d)) - return d; - - return defaultValue; + return DateTimeOffset.TryParse(dateTimeOffsetString, out DateTimeOffset d) ? d : defaultValue; } } @@ -998,30 +998,19 @@ namespace Server } } - public static string GetAttribute(XmlElement node, string attributeName) - { - return GetAttribute(node, attributeName, null); - } - - public static string GetAttribute(XmlElement node, string attributeName, string defaultValue) + public static string GetAttribute(XmlElement node, string attributeName, string defaultValue = null) { if (node == null) return defaultValue; XmlAttribute attr = node.Attributes[attributeName]; - if (attr == null) - return defaultValue; - - return attr.Value; + return attr == null ? defaultValue : attr.Value; } public static string GetText(XmlElement node, string defaultValue) { - if (node == null) - return defaultValue; - - return node.InnerText; + return node == null ? defaultValue : node.InnerText; } public static int GetAddressValue(IPAddress address) @@ -1090,15 +1079,23 @@ namespace Server return total; } - public static int RandomList(params int[] list) + public static void Shuffle(IList list) { - return list[RandomImpl.Next(list.Length)]; + int count = list.Count; + for (int i = count - 1; i > 0; i--) + { + int r = RandomImpl.Next(count); + T swap = list[r]; + list[r] = list[i]; + list[i] = swap; + } } - public static bool RandomBool() - { - return RandomImpl.NextBool(); - } + public static int RandomList(params int[] list) => RandomList(list); + + public static T RandomList(IList list) => list[RandomImpl.Next(list.Count)]; + + public static bool RandomBool() => RandomImpl.NextBool(); public static int RandomMinMax(int min, int max) { @@ -1285,38 +1282,6 @@ namespace Server return RandomList(0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59); } - //[Obsolete( "Depreciated, use the methods for the Mobile's race", false )] - public static int ClipSkinHue(int hue) - { - if (hue < 1002) - return 1002; - if (hue > 1058) - return 1058; - return hue; - } - - //[Obsolete( "Depreciated, use the methods for the Mobile's race", false )] - public static int RandomSkinHue() - { - return Random(1002, 57) | 0x8000; - } - - //[Obsolete( "Depreciated, use the methods for the Mobile's race", false )] - public static int ClipHairHue(int hue) - { - if (hue < 1102) - return 1102; - if (hue > 1149) - return 1149; - return hue; - } - - //[Obsolete( "Depreciated, use the methods for the Mobile's race", false )] - public static int RandomHairHue() - { - return Random(1102, 48); - } - #endregion } -} \ No newline at end of file +} diff --git a/Server/World.cs b/Server/World.cs index f0a309621..81daa0fd4 100644 --- a/Server/World.cs +++ b/Server/World.cs @@ -46,7 +46,7 @@ namespace Server public static readonly string GuildIndexPath = Path.Combine("Saves/Guilds/", "Guilds.idx"); public static readonly string GuildDataPath = Path.Combine("Saves/Guilds/", "Guilds.bin"); - private static readonly Type[] m_SerialTypeArray = new Type[1] { typeof(Serial) }; + private static readonly Type[] m_SerialTypeArray = new Type[] { typeof(Serial) }; internal static int m_Saves; @@ -181,7 +181,7 @@ namespace Server _addQueue = new Queue(); _deleteQueue = new Queue(); - int mobileCount = 0, itemCount = 0, guildCount = 0; + int mobileCount, itemCount, guildCount; object[] ctorArgs = new object[1]; @@ -207,7 +207,7 @@ namespace Server for (int i = 0; i < mobileCount; ++i) { int typeID = idxReader.ReadInt32(); - int serial = idxReader.ReadInt32(); + uint serial = idxReader.ReadUInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); @@ -227,6 +227,7 @@ namespace Server } catch { + // ignored } if (m != null) @@ -262,7 +263,7 @@ namespace Server for (int i = 0; i < itemCount; ++i) { int typeID = idxReader.ReadInt32(); - int serial = idxReader.ReadInt32(); + uint serial = idxReader.ReadUInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); @@ -282,6 +283,7 @@ namespace Server } catch { + // ignored } if (item != null) @@ -306,11 +308,11 @@ namespace Server guildCount = idxReader.ReadInt32(); - CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1); + CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(0xFFFFFFFF); for (int i = 0; i < guildCount; ++i) { idxReader.ReadInt32(); //no typeid for guilds - int id = idxReader.ReadInt32(); + uint id = idxReader.ReadUInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); @@ -440,7 +442,7 @@ namespace Server failed = e; failedGuilds = true; failedType = typeof(BaseGuild); - failedTypeID = g.Id; + failedTypeID = (int)g.Id; failedSerial = g.Id; break; @@ -576,6 +578,7 @@ namespace Server } catch { + // ignored } } @@ -694,9 +697,7 @@ namespace Server public static Mobile FindMobile(Serial serial) { - Mobile mob; - - Mobiles.TryGetValue(serial, out mob); + Mobiles.TryGetValue(serial, out Mobile mob); return mob; } @@ -716,9 +717,7 @@ namespace Server public static Item FindItem(Serial serial) { - Item item; - - Items.TryGetValue(serial, out item); + Items.TryGetValue(serial, out Item item); return item; }