diff --git a/Scripts/Accounting/AccountHandler.cs b/Scripts/Accounting/AccountHandler.cs index a81976dd8..d26612fb0 100644 --- a/Scripts/Accounting/AccountHandler.cs +++ b/Scripts/Accounting/AccountHandler.cs @@ -79,11 +79,7 @@ namespace Server.Misc if (a.LoginIPs.Length > 0) { IPAddress ip = a.LoginIPs[0]; - - if (m_IPTable.ContainsKey(ip)) - m_IPTable[ip]++; - else - m_IPTable[ip] = 1; + m_IPTable[ip] = (m_IPTable.TryGetValue(ip, out int value) ? value : 0) + 1; } } @@ -424,4 +420,4 @@ namespace Server.Misc return false; } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/Batch.cs b/Scripts/Commands/Batch.cs index 155587495..0238ca21b 100644 --- a/Scripts/Commands/Batch.cs +++ b/Scripts/Commands/Batch.cs @@ -91,12 +91,9 @@ namespace Server.Commands continue; Type type = obj.GetType(); - - PropertyInfo[] chain = propertyChains[type]; - string failReason = ""; - if (chain == null) + if (!propertyChains.TryGetValue(type, out PropertyInfo[] chain)) propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object, PropertyAccess.Read, ref failReason); diff --git a/Scripts/Commands/Docs.cs b/Scripts/Commands/Docs.cs index e86e6f779..464e0687f 100644 --- a/Scripts/Commands/Docs.cs +++ b/Scripts/Commands/Docs.cs @@ -69,9 +69,7 @@ namespace Server.Commands TypeInfo info = new TypeInfo(type); m_Types[type] = info; - m_Namespaces.TryGetValue(nspace, out List nspaces); - - if (nspaces == null) + if (!m_Namespaces.TryGetValue(nspace, out List nspaces)) m_Namespaces[nspace] = nspaces = new List(); nspaces.Add(info); @@ -682,9 +680,8 @@ namespace Server.Commands m_Types = new Dictionary(); m_Namespaces = new Dictionary>(); - List assemblies = new List(); + List assemblies = new List { Core.Assembly }; - assemblies.Add(Core.Assembly); foreach (Assembly asm in ScriptCompiler.Assemblies) assemblies.Add(asm); @@ -1882,9 +1879,7 @@ namespace Server.Commands lastIndex = index; - table.TryGetValue(index, out SpeechEntry entry); - - if (entry == null) + if (!table.TryGetValue(index, out SpeechEntry entry)) table[index] = entry = new SpeechEntry(index); entry.Strings.Add(text); @@ -1925,12 +1920,12 @@ namespace Server.Commands public int Compare(DocCommandEntry a, DocCommandEntry b) { if (a == null && b == null) return 0; - + int v = b?.AccessLevel.CompareTo(a?.AccessLevel) ?? 1; if (v != 0) return v; - + return a?.Name.CompareTo(b?.Name) ?? 1; } } @@ -2290,9 +2285,7 @@ namespace Server.Commands { html.Write(" {1}", GetTooltipFor(parms[j]), parms[j].Name); @@ -2732,10 +2725,10 @@ namespace Server.Commands if (v != 0) return v; - + return a?.Name.CompareTo(b?.Name) ?? 1; } } #endregion -} \ No newline at end of file +} diff --git a/Scripts/Commands/Generic/Implementors/BaseCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/BaseCommandImplementor.cs index 13998b8cd..6ea26d0b9 100644 --- a/Scripts/Commands/Generic/Implementors/BaseCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/BaseCommandImplementor.cs @@ -251,9 +251,7 @@ namespace Server.Commands.Generic { if (e.Length >= 1) { - Commands.TryGetValue(e.GetString(0), out BaseCommand command); - - if (command == null) + if (!Commands.TryGetValue(e.GetString(0), out BaseCommand command)) { e.Mobile.SendMessage( "That is either an invalid command name or one that does not support this modifier."); @@ -294,4 +292,4 @@ namespace Server.Commands.Generic impl.Register(); } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/Profiling.cs b/Scripts/Commands/Profiling.cs index afb656428..9bfc975c6 100644 --- a/Scripts/Commands/Profiling.cs +++ b/Scripts/Commands/Profiling.cs @@ -99,10 +99,7 @@ namespace Server.Commands { Type type = item.GetType(); - if (table.ContainsKey(type)) - table[type] = 1 + table[type]; - else - table[type] = 1; + table[type] = (table.TryGetValue(type, out int value) ? value : 0) + 1; } List> items = table.ToList(); @@ -112,10 +109,7 @@ namespace Server.Commands { Type type = m.GetType(); - if (table.ContainsKey(type)) - table[type] = 1 + table[type]; - else - table[type] = 1; + table[type] = (table.TryGetValue(type, out int value) ? value : 0) + 1; } List> mobiles = table.ToList(); @@ -161,10 +155,8 @@ namespace Server.Commands do { - typeTable.TryGetValue(itemType, out int[] countTable); - - if (countTable == null) - countTable = new int[9]; + if (!typeTable.TryGetValue(itemType, out int[] countTable)) + typeTable[itemType] = countTable = new int[9]; if ((flags & ExpandFlag.Name) != 0) ++countTable[0]; @@ -253,13 +245,13 @@ namespace Server.Commands ++totalCount; Type type = item.GetType(); - int[] parms = table[type]; - if (parms == null) - table[type] = parms = new[] { 0, 0 }; - - parms[0]++; - parms[1] += item.Amount; + if (table.TryGetValue(type, out int[] parms)) + { + parms[0]++; + parms[1] += item.Amount; + } else + table[type] = new[] { 1, item.Amount }; } using (StreamWriter op = new StreamWriter("internal.log")) @@ -319,13 +311,9 @@ namespace Server.Commands int length = bin.ReadInt32(); Type objType = types[typeID]; - while (objType != typeof(object)) + while (objType != null && objType != typeof(object)) { - if (table.ContainsKey(objType)) - table[objType] = length + table[objType]; - else - table[objType] = length; - + table[objType] = length + (table.TryGetValue(objType, out int value) ? value : 0); objType = objType.BaseType; total += length; } @@ -362,10 +350,7 @@ namespace Server.Commands int v = -aCount.CompareTo(bCount); - if (v != 0) - return v; - - return x.Key.FullName.CompareTo(y.Key.FullName); + return v != 0 ? v : x.Key.FullName.CompareTo(y.Key.FullName); } } @@ -378,10 +363,7 @@ namespace Server.Commands int v = -aCount.CompareTo(bCount); - if (v != 0) - return v; - - return x.Key.FullName.CompareTo(y.Key.FullName); + return v != 0 ? v : x.Key.FullName.CompareTo(y.Key.FullName); } } } diff --git a/Scripts/Commands/Statics.cs b/Scripts/Commands/Statics.cs index ee873143e..ab557ea39 100644 --- a/Scripts/Commands/Statics.cs +++ b/Scripts/Commands/Statics.cs @@ -125,16 +125,12 @@ namespace Server if (itemMap == null || itemMap == Map.Internal) continue; - Dictionary table = mapTable[itemMap]; - - if (table == null) + if (!mapTable.TryGetValue(itemMap, out Dictionary table)) mapTable[itemMap] = table = new Dictionary(); Point2D p = new Point2D(item.X >> 3, item.Y >> 3); - DeltaState state = table[p]; - - if (state == null) + if (!table.TryGetValue(p, out DeltaState state)) table[p] = state = new DeltaState(p); state.m_List.Add(item); @@ -159,16 +155,12 @@ namespace Server if (itemMap == null || itemMap == Map.Internal) continue; - Dictionary table = mapTable[itemMap]; - - if (table == null) + if (!mapTable.TryGetValue(itemMap, out Dictionary table)) mapTable[itemMap] = table = new Dictionary(); Point2D p = new Point2D(item.X >> 3, item.Y >> 3); - DeltaState state = table[p]; - - if (state == null) + if (!table.TryGetValue(p, out DeltaState state)) table[p] = state = new DeltaState(p); state.m_List.Add(item); diff --git a/Scripts/Engines/CannedEvil/ChampionSpawn.cs b/Scripts/Engines/CannedEvil/ChampionSpawn.cs index b272337b9..384daaa0b 100644 --- a/Scripts/Engines/CannedEvil/ChampionSpawn.cs +++ b/Scripts/Engines/CannedEvil/ChampionSpawn.cs @@ -953,10 +953,7 @@ namespace Server.Engines.CannedEvil if (from == null || !from.Player) return; - if (m_DamageEntries.ContainsKey(from)) - m_DamageEntries[from] += amount; - else - m_DamageEntries.Add(from, amount); + m_DamageEntries[from] = amount + (m_DamageEntries.TryGetValue(from, out int value) ? value : 0); } public void AwardArtifact(Item artifact) @@ -1073,12 +1070,10 @@ namespace Server.Engines.CannedEvil case 5: { int entries = reader.ReadInt(); - Mobile m; - int damage; for (int i = 0; i < entries; ++i) { - m = reader.ReadMobile(); - damage = reader.ReadInt(); + Mobile m = reader.ReadMobile(); + int damage = reader.ReadInt(); if (m == null) continue; @@ -1243,4 +1238,4 @@ namespace Server.Engines.CannedEvil } } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/ConPVP/AcceptDuelGump.cs b/Scripts/Engines/ConPVP/AcceptDuelGump.cs index 9086e72bc..ac853fd84 100644 --- a/Scripts/Engines/ConPVP/AcceptDuelGump.cs +++ b/Scripts/Engines/ConPVP/AcceptDuelGump.cs @@ -117,9 +117,7 @@ namespace Server.Engines.ConPVP public static void BeginIgnore(Mobile source, Mobile toIgnore) { - List list = m_IgnoreLists[source]; - - if (list == null) + if (!m_IgnoreLists.TryGetValue(source, out List list)) m_IgnoreLists[source] = list = new List(); for (int i = 0; i < list.Count; ++i) @@ -141,9 +139,7 @@ namespace Server.Engines.ConPVP public static bool IsIgnored(Mobile source, Mobile check) { - List list = m_IgnoreLists[source]; - - if (list == null) + if (!m_IgnoreLists.TryGetValue(source, out List list)) return false; for (int i = 0; i < list.Count; ++i) @@ -280,4 +276,4 @@ namespace Server.Engines.ConPVP } } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/ConPVP/Games/BombingRun.cs b/Scripts/Engines/ConPVP/Games/BombingRun.cs index 11bd63e1b..7adbe3b5d 100644 --- a/Scripts/Engines/ConPVP/Games/BombingRun.cs +++ b/Scripts/Engines/ConPVP/Games/BombingRun.cs @@ -1247,7 +1247,7 @@ namespace Server.Engines.ConPVP if (mob == null) return null; - if (!(Players[mob] is BRPlayerInfo val)) + if (!Players.TryGetValue(mob, out BRPlayerInfo val)) Players[mob] = val = new BRPlayerInfo(this, mob); return val; diff --git a/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs b/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs index 567b55846..231d693bb 100644 --- a/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs +++ b/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs @@ -604,7 +604,7 @@ namespace Server.Engines.ConPVP if (mob == null) return null; - if (!(Players[mob] is KHPlayerInfo val)) + if (!Players.TryGetValue(mob, out KHPlayerInfo val)) Players[mob] = val = new KHPlayerInfo(this, mob); return val; diff --git a/Scripts/Engines/ConPVP/Ladder.cs b/Scripts/Engines/ConPVP/Ladder.cs index cc8a4406d..01be31f5d 100644 --- a/Scripts/Engines/ConPVP/Ladder.cs +++ b/Scripts/Engines/ConPVP/Ladder.cs @@ -269,9 +269,7 @@ namespace Server.Engines.ConPVP public LadderEntry Find(Mobile mob) { - LadderEntry entry = m_Table[mob]; - - if (entry == null) + if (m_Table.TryGetValue(mob, out LadderEntry entry)) { m_Table[mob] = entry = new LadderEntry(mob, this); entry.Index = Entries.Count; @@ -283,7 +281,8 @@ namespace Server.Engines.ConPVP public LadderEntry FindNoCreate(Mobile mob) { - return m_Table[mob]; + m_Table.TryGetValue(mob, out LadderEntry entry); + return entry; } public void Serialize(GenericWriter writer) @@ -364,4 +363,4 @@ namespace Server.Engines.ConPVP writer.WriteEncodedInt(Losses); } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/ConPVP/Preferences.cs b/Scripts/Engines/ConPVP/Preferences.cs index f919854dc..1b81442c2 100644 --- a/Scripts/Engines/ConPVP/Preferences.cs +++ b/Scripts/Engines/ConPVP/Preferences.cs @@ -107,9 +107,7 @@ namespace Server.Engines.ConPVP public PreferencesEntry Find(Mobile mob) { - PreferencesEntry entry = m_Table[mob]; - - if (entry == null) + if (m_Table.TryGetValue(mob, out PreferencesEntry entry)) { m_Table[mob] = entry = new PreferencesEntry(mob); Entries.Add(entry); @@ -276,4 +274,4 @@ namespace Server.Engines.ConPVP m_ColumnX += width; } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Craft/Core/CraftItem.cs b/Scripts/Engines/Craft/Core/CraftItem.cs index db10e6355..16c0e27c1 100644 --- a/Scripts/Engines/Craft/Core/CraftItem.cs +++ b/Scripts/Engines/Craft/Core/CraftItem.cs @@ -110,50 +110,50 @@ namespace Server.Engines.Craft public static int ItemIDOf(Type type) { - if (!_itemIds.TryGetValue(type, out int itemId)) + if (_itemIds.TryGetValue(type, out int itemId)) + return itemId; + + if (type == typeof(FactionExplosionTrap)) + itemId = 14034; + else if (type == typeof(FactionGasTrap)) + itemId = 4523; + else if (type == typeof(FactionSawTrap)) + itemId = 4359; + else if (type == typeof(FactionSpikeTrap)) itemId = 4517; + + if (itemId == 0) { - if (type == typeof(FactionExplosionTrap)) - itemId = 14034; - else if (type == typeof(FactionGasTrap)) - itemId = 4523; - else if (type == typeof(FactionSawTrap)) - itemId = 4359; - else if (type == typeof(FactionSpikeTrap)) itemId = 4517; + object[] attrs = type.GetCustomAttributes(typeof(CraftItemIDAttribute), false); - if (itemId == 0) + if (attrs.Length > 0) { - object[] attrs = type.GetCustomAttributes(typeof(CraftItemIDAttribute), false); - - if (attrs.Length > 0) - { - CraftItemIDAttribute craftItemID = (CraftItemIDAttribute)attrs[0]; - itemId = craftItemID.ItemID; - } + CraftItemIDAttribute craftItemID = (CraftItemIDAttribute)attrs[0]; + itemId = craftItemID.ItemID; } - - if (itemId == 0) - { - Item item = null; - - try - { - item = Activator.CreateInstance(type) as Item; - } - catch - { - // ignored - } - - if (item != null) - { - itemId = item.ItemID; - item.Delete(); - } - } - - _itemIds[type] = itemId; } + if (itemId == 0) + { + Item item = null; + + try + { + item = Activator.CreateInstance(type) as Item; + } + catch + { + // ignored + } + + if (item != null) + { + itemId = item.ItemID; + item.Delete(); + } + } + + _itemIds[type] = itemId; + return itemId; } @@ -1248,4 +1248,4 @@ namespace Server.Engines.Craft #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Craft/Core/CraftSystem.cs b/Scripts/Engines/Craft/Core/CraftSystem.cs index 74aa79d29..6490fb5e6 100644 --- a/Scripts/Engines/Craft/Core/CraftSystem.cs +++ b/Scripts/Engines/Craft/Core/CraftSystem.cs @@ -81,9 +81,7 @@ namespace Server.Engines.Craft return null; } - m_ContextTable.TryGetValue(m, out CraftContext c); - - if (c == null) + if (!m_ContextTable.TryGetValue(m, out CraftContext c)) m_ContextTable[m] = c = new CraftContext(); return c; @@ -91,9 +89,7 @@ namespace Server.Engines.Craft public void OnMade(Mobile m, CraftItem item) { - CraftContext c = GetContext(m); - - c?.OnMade(item); + GetContext(m)?.OnMade(item); } public virtual bool ConsumeOnFailure(Mobile from, Type resourceType, CraftItem craftItem) @@ -104,8 +100,8 @@ namespace Server.Engines.Craft public void CreateItem(Mobile from, Type type, Type typeRes, BaseTool tool, CraftItem realCraftItem) { // Verify if the type is in the list of the craftable item - CraftItem craftItem = CraftItems.SearchFor(type); - if (craftItem != null) realCraftItem.Craft(from, this, typeRes, tool); + if (CraftItems.SearchFor(type) != null) + realCraftItem.Craft(from, this, typeRes, tool); } public int RandomRecipe() @@ -359,4 +355,4 @@ namespace Server.Engines.Craft public abstract int CanCraft(Mobile from, BaseTool tool, Type itemType); } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Harvest/Core/HarvestDefinition.cs b/Scripts/Engines/Harvest/Core/HarvestDefinition.cs index a83826ebb..135c05fec 100644 --- a/Scripts/Engines/Harvest/Core/HarvestDefinition.cs +++ b/Scripts/Engines/Harvest/Core/HarvestDefinition.cs @@ -5,11 +5,6 @@ namespace Server.Engines.Harvest { public class HarvestDefinition { - public HarvestDefinition() - { - Banks = new Dictionary>(); - } - public int BankWidth{ get; set; } public int BankHeight{ get; set; } @@ -70,7 +65,8 @@ namespace Server.Engines.Harvest public bool RandomizeVeins{ get; set; } - public Dictionary> Banks{ get; set; } + public Dictionary> Banks{ get; } + = new Dictionary>(); public void SendMessageTo(Mobile from, object message) { @@ -88,15 +84,12 @@ namespace Server.Engines.Harvest x /= BankWidth; y /= BankHeight; - Banks.TryGetValue(map, out Dictionary banks); - - if (banks == null) + if (!Banks.TryGetValue(map, out Dictionary banks)) Banks[map] = banks = new Dictionary(); Point2D key = new Point2D(x, y); - banks.TryGetValue(key, out HarvestBank bank); - if (bank == null) + if (!banks.TryGetValue(key, out HarvestBank bank)) banks[key] = bank = new HarvestBank(this, GetVeinAt(map, x, y)); return bank; @@ -178,4 +171,4 @@ namespace Server.Engines.Harvest return dist == 0; } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Help/PageQueue.cs b/Scripts/Engines/Help/PageQueue.cs index e387bbe04..3e6029d04 100644 --- a/Scripts/Engines/Help/PageQueue.cs +++ b/Scripts/Engines/Help/PageQueue.cs @@ -199,9 +199,7 @@ namespace Server.Engines.Help [Description("Opens the page queue menu.")] private static void Pages_OnCommand(CommandEventArgs e) { - PageEntry entry = (PageEntry)m_KeyedByHandler[e.Mobile]; - - if (entry != null) + if (m_KeyedByHandler.TryGetValue(e.Mobile, out PageEntry entry)) e.Mobile.SendGump(new PageEntryGump(e.Mobile, entry)); else if (List.Count > 0) e.Mobile.SendGump(new PageQueueGump()); @@ -224,11 +222,6 @@ namespace Server.Engines.Help return List.IndexOf(e); } - public static void Cancel(Mobile sender) - { - Remove((PageEntry)m_KeyedBySender[sender]); - } - public static void Remove(PageEntry e) { if (e == null) @@ -245,7 +238,8 @@ namespace Server.Engines.Help public static PageEntry GetEntry(Mobile sender) { - return (PageEntry)m_KeyedBySender[sender]; + m_KeyedBySender.TryGetValue(sender, out PageEntry entry); + return entry; } public static void Remove(Mobile sender) @@ -285,9 +279,10 @@ namespace Server.Engines.Help Mobile sender = entry.Sender; DateTime time = DateTime.UtcNow; - MailMessage mail = new MailMessage(Email.FromAddress, Email.SpeechLogPageAddresses); - - mail.Subject = "RunUO Speech Log Page Forwarding"; + MailMessage mail = new MailMessage(Email.FromAddress, Email.SpeechLogPageAddresses) + { + Subject = "RunUO Speech Log Page Forwarding" + }; using (StringWriter writer = new StringWriter()) { diff --git a/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs b/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs index a4eba1aa6..1d919bde9 100644 --- a/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs +++ b/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs @@ -108,7 +108,7 @@ namespace Server.Engines.MLQuests.Gumps private static void Timeout(NetState ns) { - if (m_Pending.ContainsKey(ns)) + if (IsPending(ns)) { m_Pending.Remove(ns); ns.Send(CloseRaceChanger.Instance); @@ -339,4 +339,4 @@ namespace Server.Engines.MLQuests.Gumps } #endregion -} \ No newline at end of file +} diff --git a/Scripts/Engines/MLQuests/QuesterNameAttribute.cs b/Scripts/Engines/MLQuests/QuesterNameAttribute.cs index 4d9fbe38f..3c8191f7f 100644 --- a/Scripts/Engines/MLQuests/QuesterNameAttribute.cs +++ b/Scripts/Engines/MLQuests/QuesterNameAttribute.cs @@ -26,12 +26,7 @@ namespace Server.Engines.MLQuests object[] attributes = t.GetCustomAttributes(m_Type, false); - if (attributes.Length != 0) - result = ((QuesterNameAttribute)attributes[0]).QuesterName; - else - result = t.Name; - - return m_Cache[t] = result; + return m_Cache[t] = attributes.Length != 0 ? ((QuesterNameAttribute)attributes[0]).QuesterName : t.Name; } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Party/DeclineTimer.cs b/Scripts/Engines/Party/DeclineTimer.cs index 198696ea6..85613ea4c 100644 --- a/Scripts/Engines/Party/DeclineTimer.cs +++ b/Scripts/Engines/Party/DeclineTimer.cs @@ -17,8 +17,7 @@ namespace Server.Engines.PartySystem public static void Start(Mobile m, Mobile leader) { - DeclineTimer t = m_Table[m]; - + m_Table.TryGetValue(m, out DeclineTimer t); t?.Stop(); m_Table[m] = t = new DeclineTimer(m, leader); diff --git a/Scripts/Engines/Plants/MiscItems/OrangePetals.cs b/Scripts/Engines/Plants/MiscItems/OrangePetals.cs index 8f89e3569..580f98aea 100644 --- a/Scripts/Engines/Plants/MiscItems/OrangePetals.cs +++ b/Scripts/Engines/Plants/MiscItems/OrangePetals.cs @@ -87,12 +87,13 @@ namespace Server.Items private static OrangePetalsContext GetContext(Mobile m) { - return m_Table[m] as OrangePetalsContext; + m_Table.TryGetValue(m, out OrangePetalsContext context); + return context; } public static bool UnderEffect(Mobile m) { - return GetContext(m) != null; + return m_Table.ContainsKey(m); } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Engines/Plants/PlantHue.cs b/Scripts/Engines/Plants/PlantHue.cs index 4141e1eec..631a81387 100644 --- a/Scripts/Engines/Plants/PlantHue.cs +++ b/Scripts/Engines/Plants/PlantHue.cs @@ -43,27 +43,29 @@ namespace Server.Engines.Plants static PlantHueInfo() { - m_Table = new Dictionary(); + m_Table = new Dictionary + { + [PlantHue.Plain] = new PlantHueInfo(0, 1060813, PlantHue.Plain, 0x835), + [PlantHue.Red] = new PlantHueInfo(0x66D, 1060814, PlantHue.Red, 0x24), + [PlantHue.Blue] = new PlantHueInfo(0x53D, 1060815, PlantHue.Blue, 0x6), + [PlantHue.Yellow] = new PlantHueInfo(0x8A5, 1060818, PlantHue.Yellow, 0x38), + [PlantHue.BrightRed] = new PlantHueInfo(0x21, 1060814, PlantHue.BrightRed, 0x21), + [PlantHue.BrightBlue] = new PlantHueInfo(0x5, 1060815, PlantHue.BrightBlue, 0x6), + [PlantHue.BrightYellow] = new PlantHueInfo(0x38, 1060818, PlantHue.BrightYellow, 0x35), + [PlantHue.Purple] = new PlantHueInfo(0xD, 1060816, PlantHue.Purple, 0x10), + [PlantHue.Green] = new PlantHueInfo(0x59B, 1060819, PlantHue.Green, 0x42), + [PlantHue.Orange] = new PlantHueInfo(0x46F, 1060817, PlantHue.Orange, 0x2E), + [PlantHue.BrightPurple] = new PlantHueInfo(0x10, 1060816, PlantHue.BrightPurple, 0xD), + [PlantHue.BrightGreen] = new PlantHueInfo(0x42, 1060819, PlantHue.BrightGreen, 0x3F), + [PlantHue.BrightOrange] = new PlantHueInfo(0x2B, 1060817, PlantHue.BrightOrange, 0x2B), + [PlantHue.Black] = new PlantHueInfo(0x455, 1060820, PlantHue.Black, 0), + [PlantHue.White] = new PlantHueInfo(0x481, 1060821, PlantHue.White, 0x481), + [PlantHue.Pink] = new PlantHueInfo(0x48E, 1061854, PlantHue.Pink), + [PlantHue.Magenta] = new PlantHueInfo(0x486, 1061852, PlantHue.Magenta), + [PlantHue.Aqua] = new PlantHueInfo(0x495, 1061853, PlantHue.Aqua), + [PlantHue.FireRed] = new PlantHueInfo(0x489, 1061855, PlantHue.FireRed) + }; - m_Table[PlantHue.Plain] = new PlantHueInfo(0, 1060813, PlantHue.Plain, 0x835); - m_Table[PlantHue.Red] = new PlantHueInfo(0x66D, 1060814, PlantHue.Red, 0x24); - m_Table[PlantHue.Blue] = new PlantHueInfo(0x53D, 1060815, PlantHue.Blue, 0x6); - m_Table[PlantHue.Yellow] = new PlantHueInfo(0x8A5, 1060818, PlantHue.Yellow, 0x38); - m_Table[PlantHue.BrightRed] = new PlantHueInfo(0x21, 1060814, PlantHue.BrightRed, 0x21); - m_Table[PlantHue.BrightBlue] = new PlantHueInfo(0x5, 1060815, PlantHue.BrightBlue, 0x6); - m_Table[PlantHue.BrightYellow] = new PlantHueInfo(0x38, 1060818, PlantHue.BrightYellow, 0x35); - m_Table[PlantHue.Purple] = new PlantHueInfo(0xD, 1060816, PlantHue.Purple, 0x10); - m_Table[PlantHue.Green] = new PlantHueInfo(0x59B, 1060819, PlantHue.Green, 0x42); - m_Table[PlantHue.Orange] = new PlantHueInfo(0x46F, 1060817, PlantHue.Orange, 0x2E); - m_Table[PlantHue.BrightPurple] = new PlantHueInfo(0x10, 1060816, PlantHue.BrightPurple, 0xD); - m_Table[PlantHue.BrightGreen] = new PlantHueInfo(0x42, 1060819, PlantHue.BrightGreen, 0x3F); - m_Table[PlantHue.BrightOrange] = new PlantHueInfo(0x2B, 1060817, PlantHue.BrightOrange, 0x2B); - m_Table[PlantHue.Black] = new PlantHueInfo(0x455, 1060820, PlantHue.Black, 0); - m_Table[PlantHue.White] = new PlantHueInfo(0x481, 1060821, PlantHue.White, 0x481); - m_Table[PlantHue.Pink] = new PlantHueInfo(0x48E, 1061854, PlantHue.Pink); - m_Table[PlantHue.Magenta] = new PlantHueInfo(0x486, 1061852, PlantHue.Magenta); - m_Table[PlantHue.Aqua] = new PlantHueInfo(0x495, 1061853, PlantHue.Aqua); - m_Table[PlantHue.FireRed] = new PlantHueInfo(0x489, 1061855, PlantHue.FireRed); } private PlantHueInfo(int hue, int name, PlantHue plantHue) : this(hue, name, plantHue, hue) @@ -88,9 +90,7 @@ namespace Server.Engines.Plants public static PlantHueInfo GetInfo(PlantHue plantHue) { - if (m_Table.TryGetValue(plantHue, out PlantHueInfo info)) - return info; - return m_Table[PlantHue.Plain]; + return m_Table.TryGetValue(plantHue, out PlantHueInfo info) ? info : m_Table[PlantHue.Plain]; } public static PlantHue RandomFirstGeneration() @@ -181,4 +181,4 @@ namespace Server.Engines.Plants return IsPrimary(PlantHue); } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Quests/Dark Tides/Objectives.cs b/Scripts/Engines/Quests/Dark Tides/Objectives.cs index dfdc2b81f..ebd492a12 100644 --- a/Scripts/Engines/Quests/Dark Tides/Objectives.cs +++ b/Scripts/Engines/Quests/Dark Tides/Objectives.cs @@ -118,14 +118,14 @@ namespace Server.Engines.Quests.Necro public override void CheckProgress() { - if (System.From.Map == Map.Malas && System.From.InRange(new Point3D(1076, 450, -84), 5)) - if (SummonFamiliarSpell.Table[System.From] is HordeMinionFamiliar hmf && hmf.InRange(System.From, 5) && - hmf.TargetLocation == null) - { - System.From.SendLocalizedMessage( - 1060113); // You instinctively will your familiar to fetch the scroll for you. - hmf.TargetLocation = new Point2D(1076, 450); - } + if (System.From.Map != Map.Malas || !System.From.InRange(new Point3D(1076, 450, -84), 5) || + !SummonFamiliarSpell.Table.TryGetValue(System.From, out BaseCreature bc) || !(bc is HordeMinionFamiliar hmf) || + !hmf.InRange(System.From, 5) || hmf.TargetLocation != null) + return; + + System.From.SendLocalizedMessage( + 1060113); // You instinctively will your familiar to fetch the scroll for you. + hmf.TargetLocation = new Point2D(1076, 450); } public override void OnComplete() @@ -376,4 +376,4 @@ namespace Server.Engines.Quests.Necro System.AddConversation(new BankerConversation()); } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Reports/Objects/Staffing/StaffHistory.cs b/Scripts/Engines/Reports/Objects/Staffing/StaffHistory.cs index b614bd78f..38bd54370 100644 --- a/Scripts/Engines/Reports/Objects/Staffing/StaffHistory.cs +++ b/Scripts/Engines/Reports/Objects/Staffing/StaffHistory.cs @@ -45,7 +45,7 @@ namespace Server.Engines.Reports if (string.IsNullOrEmpty(account)) return null; - if (!(StaffInfo[account] is StaffInfo info)) + if (!StaffInfo.TryGetValue(account, out StaffInfo info)) StaffInfo[account] = info = new StaffInfo(account); return info; @@ -57,7 +57,7 @@ namespace Server.Engines.Reports if (string.IsNullOrEmpty(account)) return null; - if (!(UserInfo[account] is UserInfo info)) + if (!UserInfo.TryGetValue(account, out UserInfo info)) UserInfo[account] = info = new UserInfo(account); return info; diff --git a/Scripts/Engines/Reports/Persistance/PersistableType.cs b/Scripts/Engines/Reports/Persistance/PersistableType.cs index b65af48bb..352112dac 100644 --- a/Scripts/Engines/Reports/Persistance/PersistableType.cs +++ b/Scripts/Engines/Reports/Persistance/PersistableType.cs @@ -32,7 +32,8 @@ namespace Server.Engines.Reports public static PersistableType Find(string name) { - return m_Table[name]; + m_Table.TryGetValue(name, out PersistableType value); + return value; } public static void Register(PersistableType type) diff --git a/Scripts/Engines/Spawner/Spawner.cs b/Scripts/Engines/Spawner/Spawner.cs index 09cdf19a2..122b9f79e 100644 --- a/Scripts/Engines/Spawner/Spawner.cs +++ b/Scripts/Engines/Spawner/Spawner.cs @@ -209,12 +209,7 @@ namespace Server.Mobiles false); } - public SpawnerEntry AddEntry(string creaturename, int probability, int amount) - { - return AddEntry(creaturename, probability, amount, true); - } - - public SpawnerEntry AddEntry(string creaturename, int probability, int amount, bool dotimer) + public SpawnerEntry AddEntry(string creaturename, int probability, int amount, bool dotimer = true) { SpawnerEntry entry = new SpawnerEntry(creaturename, probability, amount); Entries.Add(entry); @@ -356,7 +351,7 @@ namespace Server.Mobiles if (Entries.Count <= 0 || IsFull) return; - + int probsum = 0; for (int i = 0; i < Entries.Count; i++) @@ -365,7 +360,7 @@ namespace Server.Mobiles if (probsum <= 0) return; - + int rand = Utility.RandomMinMax(1, probsum); for (int i = 0; i < Entries.Count; i++) @@ -639,7 +634,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 mapZ = map.GetAverageZ(x, y); if (waterMob) @@ -1221,4 +1216,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Virtues/VirtueGump.cs b/Scripts/Engines/Virtues/VirtueGump.cs index ebc2f2556..a9cbb50e0 100644 --- a/Scripts/Engines/Virtues/VirtueGump.cs +++ b/Scripts/Engines/Virtues/VirtueGump.cs @@ -77,9 +77,7 @@ namespace Server return; } - m_Callbacks.TryGetValue(e.GumpID, out OnVirtueUsed callback); - - if (callback != null) + if (m_Callbacks.TryGetValue(e.GumpID, out OnVirtueUsed callback)) callback(e.Beholder); else e.Beholder.SendLocalizedMessage(1052066); // That virtue is not active yet. @@ -180,4 +178,4 @@ namespace Server } } } -} \ No newline at end of file +} diff --git a/Scripts/Gumps/Go/GoGump.cs b/Scripts/Gumps/Go/GoGump.cs index 437fdcac9..dfebaf843 100644 --- a/Scripts/Gumps/Go/GoGump.cs +++ b/Scripts/Gumps/Go/GoGump.cs @@ -181,9 +181,7 @@ namespace Server.Gumps else tree = Tokuno; - tree.LastBranch.TryGetValue(from, out ParentNode branch); - - if (branch == null) + if (!tree.LastBranch.TryGetValue(from, out ParentNode branch)) branch = tree.Root; if (branch != null) @@ -236,4 +234,4 @@ namespace Server.Gumps } } } -} \ No newline at end of file +} diff --git a/Scripts/Gumps/Go/LocationTree.cs b/Scripts/Gumps/Go/LocationTree.cs index 618d51033..c2b73e576 100644 --- a/Scripts/Gumps/Go/LocationTree.cs +++ b/Scripts/Gumps/Go/LocationTree.cs @@ -15,9 +15,7 @@ namespace Server.Gumps if (File.Exists(path)) { - XmlTextReader xml = new XmlTextReader(new StreamReader(path)); - - xml.WhitespaceHandling = WhitespaceHandling.None; + XmlTextReader xml = new XmlTextReader(new StreamReader(path)) { WhitespaceHandling = WhitespaceHandling.None }; Root = Parse(xml); @@ -40,4 +38,4 @@ namespace Server.Gumps return new ParentNode(xml, null); } } -} \ No newline at end of file +} diff --git a/Scripts/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs b/Scripts/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs index fd1d2d676..a3ab83934 100644 --- a/Scripts/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs +++ b/Scripts/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs @@ -250,10 +250,8 @@ namespace Server.Engines.Events { if ( m_DeadPlayer != null && !m_DeadPlayer.Deleted ) { - if ( HalloweenHauntings.ReAnimated.Count > 0 && HalloweenHauntings.ReAnimated.ContainsKey( m_DeadPlayer ) ) - { + if ( HalloweenHauntings.ReAnimated.ContainsKey( m_DeadPlayer ) ) HalloweenHauntings.ReAnimated.Remove( m_DeadPlayer ); - } } } } @@ -261,7 +259,7 @@ namespace Server.Engines.Events public override void Serialize( GenericWriter writer ) { base.Serialize( writer ); - writer.Write( ( int )0 ); + writer.Write( 0 ); writer.WriteMobile( m_DeadPlayer ); } @@ -271,7 +269,7 @@ namespace Server.Engines.Events base.Deserialize( reader ); int version = reader.ReadInt(); - m_DeadPlayer = ( PlayerMobile )reader.ReadMobile(); + m_DeadPlayer = reader.ReadMobile(); } } } diff --git a/Scripts/Items/Addons/ArcheryButteAddon.cs b/Scripts/Items/Addons/ArcheryButteAddon.cs index b65bda7be..129f13b8c 100644 --- a/Scripts/Items/Addons/ArcheryButteAddon.cs +++ b/Scripts/Items/Addons/ArcheryButteAddon.cs @@ -95,9 +95,7 @@ namespace Server.Items if ( m_Entries == null ) m_Entries = new Dictionary(); - ScoreEntry e = m_Entries[from]; - - if ( e == null ) + if (!m_Entries.TryGetValue(from, out ScoreEntry e)) m_Entries[from] = e = new ScoreEntry(); return e; diff --git a/Scripts/Items/Containers/FillableContainers.cs b/Scripts/Items/Containers/FillableContainers.cs index 599f79ca8..cbf604d32 100644 --- a/Scripts/Items/Containers/FillableContainers.cs +++ b/Scripts/Items/Containers/FillableContainers.cs @@ -1529,7 +1529,7 @@ namespace Server.Items !(nearest is Cobbler && mob is Provisioner)) continue; - if (m_AcquireTable[mob.GetType()] is FillableContent check) + if (m_AcquireTable.TryGetValue(mob.GetType(), out FillableContent check)) { nearest = mob; content = check; diff --git a/Scripts/Items/Containers/FurnitureContainer.cs b/Scripts/Items/Containers/FurnitureContainer.cs index f0babd11c..254c825c1 100644 --- a/Scripts/Items/Containers/FurnitureContainer.cs +++ b/Scripts/Items/Containers/FurnitureContainer.cs @@ -390,9 +390,7 @@ namespace Server.Items public static void Close(Container c) { - m_Table.TryGetValue(c, out Timer t); - - if (t != null) + if (m_Table.TryGetValue(c, out Timer t)) { t.Stop(); m_Table.Remove(c); @@ -436,4 +434,4 @@ namespace Server.Items DynamicFurniture.Close(m_Container); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs b/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs index f114f68c3..334fa6e4b 100644 --- a/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs +++ b/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs @@ -219,7 +219,11 @@ namespace Server.Items public static StealableInstance GetStealableInstance(Item item) { - return (StealableInstance)Instance?.m_Table[item]; + if (Instance == null) + return null; + + Instance.m_Table.TryGetValue(item, out StealableInstance value); + return value; } public override void OnDelete() diff --git a/Scripts/Items/Food/Beverage.cs b/Scripts/Items/Food/Beverage.cs index 3e3c4f386..af564855b 100644 --- a/Scripts/Items/Food/Beverage.cs +++ b/Scripts/Items/Food/Beverage.cs @@ -1106,30 +1106,23 @@ namespace Server.Items { if (from.BAC > 0 && from.Map != Map.Internal && !from.Deleted) { - Timer t = m_Table[from]; + if (m_Table.ContainsKey(from)) + return; - if (t == null) - { - if (from.BAC > 60) - from.BAC = 60; + if (from.BAC > 60) + from.BAC = 60; - t = new HeaveTimer(from); - t.Start(); + Timer t = new HeaveTimer(from); + t.Start(); - m_Table[from] = t; - } + m_Table[from] = t; } - else + else if (m_Table.TryGetValue(from, out Timer t)) { - Timer t = m_Table[from]; + t.Stop(); + m_Table.Remove(from); - if (t != null) - { - t.Stop(); - m_Table.Remove(from); - - from.SendLocalizedMessage(500850); // You feel sober. - } + from.SendLocalizedMessage(500850); // You feel sober. } } diff --git a/Scripts/Items/Misc/Corpses/Corpse.cs b/Scripts/Items/Misc/Corpses/Corpse.cs index f47ad21c0..9adfc9fe3 100644 --- a/Scripts/Items/Misc/Corpses/Corpse.cs +++ b/Scripts/Items/Misc/Corpses/Corpse.cs @@ -342,9 +342,9 @@ namespace Server.Items if (!m.Player || m.AccessLevel > AccessLevel.Player) //Staff and creatures not subject to instancing. return true; - if (m_InstancedItems != null) - if (m_InstancedItems.TryGetValue(child, out InstancedItemInfo info) && (InstancedCorpse || info.Perpetual)) - return info.IsOwner(m); //IsOwner checks Party stuff. + if (m_InstancedItems != null && m_InstancedItems.TryGetValue(child, out InstancedItemInfo info) + && (InstancedCorpse || info.Perpetual)) + return info.IsOwner(m); //IsOwner checks Party stuff. return true; } @@ -495,7 +495,7 @@ namespace Server.Items c = new Corpse(owner, hair, facialhair, equipItems); owner.Corpse = c; - + for (int i = 0; i < initialContent.Count; ++i) { Item item = initialContent[i]; @@ -830,7 +830,7 @@ namespace Server.Items if (!Looters.Contains(from)) Looters.Add(from); - if (m_InstancedItems != null && m_InstancedItems.ContainsKey(item)) + if (m_InstancedItems?.ContainsKey(item) == true) m_InstancedItems.Remove(item); } @@ -847,7 +847,7 @@ namespace Server.Items if (!Looters.Contains(from)) Looters.Add(from); - if (m_InstancedItems != null && m_InstancedItems.ContainsKey(item)) + if (m_InstancedItems?.ContainsKey(item) == true) m_InstancedItems.Remove(item); } @@ -891,12 +891,7 @@ namespace Server.Items if (!IsCriminalAction(from)) return true; - Map map = Map; - - if (map == null || (map.Rules & MapRules.HarmfulRestrictions) != 0) - return false; - - return true; + return Map != null && (Map.Rules & MapRules.HarmfulRestrictions) == 0; } public bool CheckLoot(Mobile from, Item item) @@ -1194,4 +1189,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Misc/PowerGenerator.cs b/Scripts/Items/Misc/PowerGenerator.cs index 1a8bc34ef..254044364 100644 --- a/Scripts/Items/Misc/PowerGenerator.cs +++ b/Scripts/Items/Misc/PowerGenerator.cs @@ -58,7 +58,7 @@ namespace Server.Items { private static readonly TimeSpan m_UseTimeout = TimeSpan.FromMinutes(2.0); - private Dictionary m_DamageTable = new Dictionary(); + private HashSet m_DamageTable = new HashSet(); private DateTime m_LastUse; private int m_SideLength; @@ -217,12 +217,12 @@ namespace Server.Items if (!to.Alive) return; - if (m_DamageTable[to] == null) + if (!m_DamageTable.Contains(to)) { to.Frozen = true; DamageTimer timer = new DamageTimer(this, to); - m_DamageTable[to] = timer; + m_DamageTable.Add(to); timer.Start(); } diff --git a/Scripts/Items/Misc/Teleporter.cs b/Scripts/Items/Misc/Teleporter.cs index 5bd858038..561f62108 100644 --- a/Scripts/Items/Misc/Teleporter.cs +++ b/Scripts/Items/Misc/Teleporter.cs @@ -690,7 +690,7 @@ namespace Server.Items m.SendLocalizedMessage(ProgressNumber); if (ShowTimeRemaining) - m.SendMessage("Time remaining: {0}", FormatTime(m_Table[m].Timer.Next - DateTime.UtcNow)); + m.SendMessage("Time remaining: {0}", FormatTime(info.Timer.Next - DateTime.UtcNow)); Timer.DelayCall(TimeSpan.FromSeconds(5), EndLock, m); } @@ -764,19 +764,12 @@ namespace Server.Items private Dictionary m_Teleporting; [Constructible] - public TimeoutTeleporter() - : this(new Point3D(0, 0, 0), null, false) + public TimeoutTeleporter() : this(new Point3D(0, 0, 0)) { } [Constructible] - public TimeoutTeleporter(Point3D pointDest, Map mapDest) - : this(pointDest, mapDest, false) - { - } - - [Constructible] - public TimeoutTeleporter(Point3D pointDest, Map mapDest, bool creatures) + public TimeoutTeleporter(Point3D pointDest, Map mapDest = null, bool creatures = false) : base(pointDest, mapDest, creatures) { m_Teleporting = new Dictionary(); @@ -1195,4 +1188,4 @@ namespace Server.Items DeadOnly = 0x100 } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Camping/Bedroll.cs b/Scripts/Items/Skill Items/Camping/Bedroll.cs index 01d225ef7..7cc4f33e7 100644 --- a/Scripts/Items/Skill Items/Camping/Bedroll.cs +++ b/Scripts/Items/Skill Items/Camping/Bedroll.cs @@ -46,7 +46,7 @@ namespace Server.Items { CampfireEntry entry = Campfire.GetEntry(from); - if (entry != null && entry.Safe) + if (entry?.Safe == true) from.SendGump(new LogoutGump(entry, this)); } } @@ -127,4 +127,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Camping/Campfire.cs b/Scripts/Items/Skill Items/Camping/Campfire.cs index 81035850d..cf03a99f5 100644 --- a/Scripts/Items/Skill Items/Camping/Campfire.cs +++ b/Scripts/Items/Skill Items/Camping/Campfire.cs @@ -86,7 +86,8 @@ namespace Server.Items public static CampfireEntry GetEntry(Mobile player) { - return m_Table[player]; + m_Table.TryGetValue(player, out CampfireEntry value); + return value; } public static void RemoveEntry(CampfireEntry entry) @@ -195,4 +196,4 @@ namespace Server.Items set => m_Safe = value; } } -} \ No newline at end of file +} 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 a8bafc707..b4b1cb2ff 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs @@ -288,14 +288,14 @@ namespace Server.Items public static void AddDelay(Mobile m) { - m_Delay[m]?.Stop(); + m_Delay.TryGetValue(m, out Timer timer); + timer?.Stop(); m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), EndDelay, m); } public static int GetDelay(Mobile m) { - Timer timer = m_Delay[m]; - if (timer?.Next > DateTime.UtcNow) + if (m_Delay.TryGetValue(m, out Timer timer) && timer.Next > DateTime.UtcNow) return (int)(timer.Next - DateTime.UtcNow).TotalSeconds; return 0; @@ -303,9 +303,7 @@ namespace Server.Items public static void EndDelay(Mobile m) { - Timer timer = m_Delay[m]; - - if (timer != null) + if (m_Delay.TryGetValue(m, out Timer timer)) { timer.Stop(); m_Delay.Remove(m); 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 f227e36ab..6d151acff 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 @@ -153,14 +153,14 @@ namespace Server.Items public static void AddDelay(Mobile m) { - m_Delay[m]?.Stop(); + m_Delay.TryGetValue(m, out Timer timer); + timer?.Stop(); m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(60), EndDelay, m); } public static int GetDelay(Mobile m) { - Timer timer = m_Delay[m]; - if (timer?.Next > DateTime.UtcNow) + if (m_Delay.TryGetValue(m, out Timer timer) && timer.Next > DateTime.UtcNow) return (int)(timer.Next - DateTime.UtcNow).TotalSeconds; return 0; @@ -168,8 +168,7 @@ namespace Server.Items public static void EndDelay(Mobile m) { - Timer timer = m_Delay[m]; - if (timer != null) + if (m_Delay.TryGetValue(m, out Timer timer)) { timer.Stop(); m_Delay.Remove(m); diff --git a/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs index 66ae1b945..673ab77bf 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs @@ -63,26 +63,20 @@ namespace Server.Items public static bool HasTimer(Mobile m) { - return m_Table[m] != null; + return m_Table.ContainsKey(m); } - public static void RemoveTimer(Mobile m) + public static void RemoveTimer(Mobile m, bool interrupted = false) { - Timer timer = m_Table[m]; - - if (timer != null) + if (m_Table.TryGetValue(m, out Timer timer)) { + if (interrupted) + m.SendLocalizedMessage(1073187); // The invisibility effect is interrupted. timer.Stop(); m_Table.Remove(m); } } - public static void Iterrupt(Mobile m) - { - m.SendLocalizedMessage(1073187); // The invisibility effect is interrupted. - RemoveTimer(m); - } - public override void Serialize(GenericWriter writer) { base.Serialize(writer); diff --git a/Scripts/Items/Skill Items/Magical/Spellbook.cs b/Scripts/Items/Skill Items/Magical/Spellbook.cs index 4ca10e5df..f4416b20c 100644 --- a/Scripts/Items/Skill Items/Magical/Spellbook.cs +++ b/Scripts/Items/Skill Items/Magical/Spellbook.cs @@ -435,11 +435,9 @@ namespace Server.Items return null; } - m_Table.TryGetValue(from, out List list); - bool searchAgain = false; - if (list == null) + if (!m_Table.TryGetValue(from, out List list)) m_Table[from] = list = FindAllSpellbooks(from); else searchAgain = true; @@ -911,4 +909,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Misc/RecipeScroll.cs b/Scripts/Items/Skill Items/Misc/RecipeScroll.cs index 74144799f..d811eaa90 100644 --- a/Scripts/Items/Skill Items/Misc/RecipeScroll.cs +++ b/Scripts/Items/Skill Items/Misc/RecipeScroll.cs @@ -42,10 +42,8 @@ namespace Server.Items { get { - if (Recipe.Recipes.ContainsKey(m_RecipeID)) - return Recipe.Recipes[m_RecipeID]; - - return null; + Recipe.Recipes.TryGetValue(m_RecipeID, out Recipe recipe); + return recipe; } } @@ -121,4 +119,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs index 1efe7492b..93dd08df2 100644 --- a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs +++ b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs @@ -203,12 +203,8 @@ namespace Server.Items public static BaseInstrument GetInstrument(Mobile from) { - BaseInstrument item = m_Instruments[from]; - if (item == null) - return null; - - if (item.IsChildOf(from.Backpack)) - return item; + if (m_Instruments.TryGetValue(from, out BaseInstrument instrument) && instrument.IsChildOf(from.Backpack)) + return instrument; m_Instruments.Remove(from); return null; @@ -222,7 +218,6 @@ namespace Server.Items public static void PickInstrument(Mobile from, InstrumentPickedCallback callback) { BaseInstrument instrument = GetInstrument(from); - if (instrument != null) { callback?.Invoke(from, instrument); @@ -531,7 +526,7 @@ namespace Server.Items { SetInstrument(from, this); - // Delay of 7 second before beign able to play another instrument again + // Delay of 7 second before being able to play another instrument again new InternalTimer(from).Start(); if (CheckMusicianship(from)) diff --git a/Scripts/Items/Skill Items/Ninjitsu/NinjaWeapons.cs b/Scripts/Items/Skill Items/Ninjitsu/NinjaWeapons.cs index d4c1c3a34..8a759a0b9 100644 --- a/Scripts/Items/Skill Items/Ninjitsu/NinjaWeapons.cs +++ b/Scripts/Items/Skill Items/Ninjitsu/NinjaWeapons.cs @@ -65,7 +65,7 @@ namespace Server.Items ConsumeUse(weapon); if (CombatCheck(from, target)) - Timer.DelayCall(TimeSpan.FromSeconds(1.0), OnHit, new object[] { from, target, weapon }); + Timer.DelayCall(TimeSpan.FromSeconds(1.0), () => OnHit(from, target, weapon)); Timer.DelayCall(TimeSpan.FromSeconds(2.5), ResetUsing, from); } @@ -187,15 +187,15 @@ namespace Server.Items BaseWeapon defWeapon = defender.Weapon as BaseWeapon; Skill atkSkill = defender.Skills.Ninjitsu; - Skill defSkill = defender.Skills[defWeapon.Skill]; + // Skill defSkill = defender.Skills[defWeapon.Skill]; double atSkillValue = attacker.Skills.Ninjitsu.Value; - double defSkillValue = defWeapon.GetDefendSkillValue(attacker, defender); - - double attackValue = AosAttributes.GetValue(attacker, AosAttribute.AttackChance); + double defSkillValue = defWeapon?.GetDefendSkillValue(attacker, defender) ?? 0.0; if (defSkillValue <= -20.0) defSkillValue = -19.9; + double attackValue = AosAttributes.GetValue(attacker, AosAttribute.AttackChance); + if (DivineFurySpell.UnderEffect(attacker)) attackValue += 10; if (AnimalForm.UnderTransformation(attacker, typeof(GreyWolf)) || @@ -230,29 +230,24 @@ namespace Server.Items return attacker.CheckSkill(atkSkill.SkillName, chance); } - private static void OnHit(object[] states) + private static void OnHit(Mobile from, Mobile target, INinjaWeapon weapon) { - Mobile from = states[0] as Mobile; - Mobile target = states[1] as Mobile; - INinjaWeapon weapon = states[2] as INinjaWeapon; + if (!from.CanBeHarmful(target)) + return; + from.DoHarmful(target); - if (from.CanBeHarmful(target)) + AOS.Damage(target, from, weapon.WeaponDamage, 100, 0, 0, 0, 0); + + if (weapon.Poison != null && weapon.PoisonCharges > 0) { - from.DoHarmful(target); + if (EvilOmenSpell.TryEndEffect(target)) + target.ApplyPoison(from, Poison.GetPoison(weapon.Poison.Level + 1)); + else + target.ApplyPoison(from, weapon.Poison); - AOS.Damage(target, from, weapon.WeaponDamage, 100, 0, 0, 0, 0); + weapon.PoisonCharges--; - if (weapon.Poison != null && weapon.PoisonCharges > 0) - { - if (EvilOmenSpell.TryEndEffect(target)) - target.ApplyPoison(from, Poison.GetPoison(weapon.Poison.Level + 1)); - else - target.ApplyPoison(from, weapon.Poison); - - weapon.PoisonCharges--; - - if (weapon.PoisonCharges < 1) weapon.Poison = null; - } + if (weapon.PoisonCharges < 1) weapon.Poison = null; } } @@ -314,4 +309,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Thief/DisguiseKit.cs b/Scripts/Items/Skill Items/Thief/DisguiseKit.cs index 39ec80f1e..7b34f086b 100644 --- a/Scripts/Items/Skill Items/Thief/DisguiseKit.cs +++ b/Scripts/Items/Skill Items/Thief/DisguiseKit.cs @@ -259,15 +259,13 @@ namespace Server.Items public static void CreateTimer(Mobile m, TimeSpan delay) { - if (m != null) - if (!Timers.ContainsKey(m)) - Timers[m] = new InternalTimer(m, delay); + if (m != null && !IsDisguised(m)) + Timers[m] = new InternalTimer(m, delay); } public static void StartTimer(Mobile m) { Timers.TryGetValue(m, out Timer t); - t?.Start(); } @@ -276,43 +274,31 @@ namespace Server.Items return Timers.ContainsKey(m); } - public static bool StopTimer(Mobile m) + public static void StopTimer(Mobile m) { - Timers.TryGetValue(m, out Timer t); + if (!Timers.TryGetValue(m, out Timer t)) + return; - if (t != null) - { - TimeSpan ts = t.Next - DateTime.UtcNow; - if (ts < TimeSpan.Zero) - ts = TimeSpan.Zero; + TimeSpan ts = t.Next - DateTime.UtcNow; + if (ts < TimeSpan.Zero) + ts = TimeSpan.Zero; - t.Delay = ts; - t.Stop(); - } - - return t != null; + t.Delay = ts; + t.Stop(); } - public static bool RemoveTimer(Mobile m) + public static void RemoveTimer(Mobile m) { - Timers.TryGetValue(m, out Timer t); - - if (t != null) + if (Timers.TryGetValue(m, out Timer t)) { t.Stop(); Timers.Remove(m); } - - return t != null; } public static TimeSpan TimeRemaining(Mobile m) { - Timers.TryGetValue(m, out Timer t); - - if (t != null) return t.Next - DateTime.UtcNow; - - return TimeSpan.Zero; + return Timers.TryGetValue(m, out Timer t) ? t.Next - DateTime.UtcNow : TimeSpan.Zero; } private class InternalTimer : Timer @@ -336,4 +322,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} 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 6d174e2da..67cb8ddeb 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 @@ -20,7 +20,7 @@ namespace Server.Items [Flippable(0x2AF9, 0x2AFD)] public class DawnsMusicBox : Item, ISecurable { - private static Dictionary m_Info = new Dictionary(); + private static Dictionary m_Info; public static MusicName[] m_CommonTracks = { @@ -231,76 +231,78 @@ namespace Server.Items public static void Initialize() { - m_Info.Add(MusicName.Samlethe, new DawnsMusicInfo(1075152, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Sailing, new DawnsMusicInfo(1075163, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Britain2, new DawnsMusicInfo(1075145, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Britain1, new DawnsMusicInfo(1075144, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Bucsden, new DawnsMusicInfo(1075146, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Forest_a, new DawnsMusicInfo(1075161, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Cove, new DawnsMusicInfo(1075176, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Death, new DawnsMusicInfo(1075171, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Dungeon9, new DawnsMusicInfo(1075160, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Dungeon2, new DawnsMusicInfo(1075175, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Cave01, new DawnsMusicInfo(1075159, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Combat3, new DawnsMusicInfo(1075170, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Combat1, new DawnsMusicInfo(1075168, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Combat2, new DawnsMusicInfo(1075169, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Jhelom, new DawnsMusicInfo(1075147, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Linelle, new DawnsMusicInfo(1075185, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.LBCastle, new DawnsMusicInfo(1075148, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Minoc, new DawnsMusicInfo(1075150, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Moonglow, new DawnsMusicInfo(1075177, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Magincia, new DawnsMusicInfo(1075149, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Nujelm, new DawnsMusicInfo(1075174, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.BTCastle, new DawnsMusicInfo(1075173, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Tavern04, new DawnsMusicInfo(1075167, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Skarabra, new DawnsMusicInfo(1075154, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Stones2, new DawnsMusicInfo(1075143, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Serpents, new DawnsMusicInfo(1075153, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Taiko, new DawnsMusicInfo(1075180, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Tavern01, new DawnsMusicInfo(1075164, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Tavern02, new DawnsMusicInfo(1075165, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Tavern03, new DawnsMusicInfo(1075166, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.TokunoDungeon, new DawnsMusicInfo(1075179, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Trinsic, new DawnsMusicInfo(1075155, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.OldUlt01, new DawnsMusicInfo(1075142, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Ocllo, new DawnsMusicInfo(1075151, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Vesper, new DawnsMusicInfo(1075156, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Victory, new DawnsMusicInfo(1075172, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Mountn_a, new DawnsMusicInfo(1075162, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Wind, new DawnsMusicInfo(1075157, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Yew, new DawnsMusicInfo(1075158, DawnsMusicRarity.Common)); - m_Info.Add(MusicName.Zento, new DawnsMusicInfo(1075178, DawnsMusicRarity.Common)); - - m_Info.Add(MusicName.GwennoConversation, new DawnsMusicInfo(1075131, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.DreadHornArea, new DawnsMusicInfo(1075181, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.ElfCity, new DawnsMusicInfo(1075182, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.GoodEndGame, new DawnsMusicInfo(1075132, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.GoodVsEvil, new DawnsMusicInfo(1075133, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.GreatEarthSerpents, new DawnsMusicInfo(1075134, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.GrizzleDungeon, new DawnsMusicInfo(1075186, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.Humanoids_U9, new DawnsMusicInfo(1075135, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.MelisandesLair, new DawnsMusicInfo(1075183, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.MinocNegative, new DawnsMusicInfo(1075136, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.ParoxysmusLair, new DawnsMusicInfo(1075184, DawnsMusicRarity.Uncommon)); - m_Info.Add(MusicName.Paws, new DawnsMusicInfo(1075137, DawnsMusicRarity.Uncommon)); - - m_Info.Add(MusicName.SelimsBar, new DawnsMusicInfo(1075138, DawnsMusicRarity.Rare)); - m_Info.Add(MusicName.SerpentIsleCombat_U7, new DawnsMusicInfo(1075139, DawnsMusicRarity.Rare)); - m_Info.Add(MusicName.ValoriaShips, new DawnsMusicInfo(1075140, DawnsMusicRarity.Rare)); + m_Info = new Dictionary + { + { MusicName.Samlethe, new DawnsMusicInfo(1075152, DawnsMusicRarity.Common) }, + { MusicName.Sailing, new DawnsMusicInfo(1075163, DawnsMusicRarity.Common) }, + { MusicName.Britain2, new DawnsMusicInfo(1075145, DawnsMusicRarity.Common) }, + { MusicName.Britain1, new DawnsMusicInfo(1075144, DawnsMusicRarity.Common) }, + { MusicName.Bucsden, new DawnsMusicInfo(1075146, DawnsMusicRarity.Common) }, + { MusicName.Forest_a, new DawnsMusicInfo(1075161, DawnsMusicRarity.Common) }, + { MusicName.Cove, new DawnsMusicInfo(1075176, DawnsMusicRarity.Common) }, + { MusicName.Death, new DawnsMusicInfo(1075171, DawnsMusicRarity.Common) }, + { MusicName.Dungeon9, new DawnsMusicInfo(1075160, DawnsMusicRarity.Common) }, + { MusicName.Dungeon2, new DawnsMusicInfo(1075175, DawnsMusicRarity.Common) }, + { MusicName.Cave01, new DawnsMusicInfo(1075159, DawnsMusicRarity.Common) }, + { MusicName.Combat3, new DawnsMusicInfo(1075170, DawnsMusicRarity.Common) }, + { MusicName.Combat1, new DawnsMusicInfo(1075168, DawnsMusicRarity.Common) }, + { MusicName.Combat2, new DawnsMusicInfo(1075169, DawnsMusicRarity.Common) }, + { MusicName.Jhelom, new DawnsMusicInfo(1075147, DawnsMusicRarity.Common) }, + { MusicName.Linelle, new DawnsMusicInfo(1075185, DawnsMusicRarity.Common) }, + { MusicName.LBCastle, new DawnsMusicInfo(1075148, DawnsMusicRarity.Common) }, + { MusicName.Minoc, new DawnsMusicInfo(1075150, DawnsMusicRarity.Common) }, + { MusicName.Moonglow, new DawnsMusicInfo(1075177, DawnsMusicRarity.Common) }, + { MusicName.Magincia, new DawnsMusicInfo(1075149, DawnsMusicRarity.Common) }, + { MusicName.Nujelm, new DawnsMusicInfo(1075174, DawnsMusicRarity.Common) }, + { MusicName.BTCastle, new DawnsMusicInfo(1075173, DawnsMusicRarity.Common) }, + { MusicName.Tavern04, new DawnsMusicInfo(1075167, DawnsMusicRarity.Common) }, + { MusicName.Skarabra, new DawnsMusicInfo(1075154, DawnsMusicRarity.Common) }, + { MusicName.Stones2, new DawnsMusicInfo(1075143, DawnsMusicRarity.Common) }, + { MusicName.Serpents, new DawnsMusicInfo(1075153, DawnsMusicRarity.Common) }, + { MusicName.Taiko, new DawnsMusicInfo(1075180, DawnsMusicRarity.Common) }, + { MusicName.Tavern01, new DawnsMusicInfo(1075164, DawnsMusicRarity.Common) }, + { MusicName.Tavern02, new DawnsMusicInfo(1075165, DawnsMusicRarity.Common) }, + { MusicName.Tavern03, new DawnsMusicInfo(1075166, DawnsMusicRarity.Common) }, + { MusicName.TokunoDungeon, new DawnsMusicInfo(1075179, DawnsMusicRarity.Common) }, + { MusicName.Trinsic, new DawnsMusicInfo(1075155, DawnsMusicRarity.Common) }, + { MusicName.OldUlt01, new DawnsMusicInfo(1075142, DawnsMusicRarity.Common) }, + { MusicName.Ocllo, new DawnsMusicInfo(1075151, DawnsMusicRarity.Common) }, + { MusicName.Vesper, new DawnsMusicInfo(1075156, DawnsMusicRarity.Common) }, + { MusicName.Victory, new DawnsMusicInfo(1075172, DawnsMusicRarity.Common) }, + { MusicName.Mountn_a, new DawnsMusicInfo(1075162, DawnsMusicRarity.Common) }, + { MusicName.Wind, new DawnsMusicInfo(1075157, DawnsMusicRarity.Common) }, + { MusicName.Yew, new DawnsMusicInfo(1075158, DawnsMusicRarity.Common) }, + { MusicName.Zento, new DawnsMusicInfo(1075178, DawnsMusicRarity.Common) }, + { MusicName.GwennoConversation, new DawnsMusicInfo(1075131, DawnsMusicRarity.Uncommon) }, + { MusicName.DreadHornArea, new DawnsMusicInfo(1075181, DawnsMusicRarity.Uncommon) }, + { MusicName.ElfCity, new DawnsMusicInfo(1075182, DawnsMusicRarity.Uncommon) }, + { MusicName.GoodEndGame, new DawnsMusicInfo(1075132, DawnsMusicRarity.Uncommon) }, + { MusicName.GoodVsEvil, new DawnsMusicInfo(1075133, DawnsMusicRarity.Uncommon) }, + { MusicName.GreatEarthSerpents, new DawnsMusicInfo(1075134, DawnsMusicRarity.Uncommon) }, + { MusicName.GrizzleDungeon, new DawnsMusicInfo(1075186, DawnsMusicRarity.Uncommon) }, + { MusicName.Humanoids_U9, new DawnsMusicInfo(1075135, DawnsMusicRarity.Uncommon) }, + { MusicName.MelisandesLair, new DawnsMusicInfo(1075183, DawnsMusicRarity.Uncommon) }, + { MusicName.MinocNegative, new DawnsMusicInfo(1075136, DawnsMusicRarity.Uncommon) }, + { MusicName.ParoxysmusLair, new DawnsMusicInfo(1075184, DawnsMusicRarity.Uncommon) }, + { MusicName.Paws, new DawnsMusicInfo(1075137, DawnsMusicRarity.Uncommon) }, + { MusicName.SelimsBar, new DawnsMusicInfo(1075138, DawnsMusicRarity.Rare) }, + { MusicName.SerpentIsleCombat_U7, new DawnsMusicInfo(1075139, DawnsMusicRarity.Rare) }, + { MusicName.ValoriaShips, new DawnsMusicInfo(1075140, DawnsMusicRarity.Rare) } + }; } public static DawnsMusicInfo GetInfo(MusicName name) { - if (m_Info.ContainsKey(name)) - return m_Info[name]; + if (m_Info == null) // sanity + return null; - return null; + m_Info.TryGetValue(name, out DawnsMusicInfo info); + return info; } public static MusicName RandomTrack(DawnsMusicRarity rarity) { - MusicName[] list = null; + MusicName[] list; switch (rarity) { @@ -319,4 +321,4 @@ namespace Server.Items return list[Utility.Random(list.Length)]; } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Special/Holiday/HolidayFoods.cs b/Scripts/Items/Special/Holiday/HolidayFoods.cs index db6377497..baa3005ad 100644 --- a/Scripts/Items/Special/Holiday/HolidayFoods.cs +++ b/Scripts/Items/Special/Holiday/HolidayFoods.cs @@ -23,27 +23,19 @@ namespace Server.Items { } - public static Dictionary ToothAches{ get; set; } - - public static void Initialize() - { - ToothAches = new Dictionary(); - } + private static Dictionary m_ToothAches = new Dictionary(); private static CandyCaneTimer EnsureTimer(Mobile from) { - if (!ToothAches.TryGetValue(from, out CandyCaneTimer timer)) - ToothAches[from] = timer = new CandyCaneTimer(from); + if (!m_ToothAches.TryGetValue(from, out CandyCaneTimer timer)) + m_ToothAches[from] = timer = new CandyCaneTimer(from); return timer; } public static int GetToothAche(Mobile from) { - if (ToothAches.TryGetValue(from, out CandyCaneTimer timer)) - return timer.Eaten; - - return 0; + return m_ToothAches.TryGetValue(from, out CandyCaneTimer timer) ? timer.Eaten : 0; } public static void SetToothAche(Mobile from, int value) @@ -92,7 +84,7 @@ namespace Server.Items if (Eater == null || Eater.Deleted || Eaten <= 0) { Stop(); - ToothAches.Remove(Eater); + m_ToothAches.Remove(Eater); } else if (Eater.Map != Map.Internal && Eater.Alive) { @@ -171,4 +163,4 @@ namespace Server.Items int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Talismans/TalismanSlayer.cs b/Scripts/Items/Talismans/TalismanSlayer.cs index c9684080d..15b84549a 100644 --- a/Scripts/Items/Talismans/TalismanSlayer.cs +++ b/Scripts/Items/Talismans/TalismanSlayer.cs @@ -20,84 +20,70 @@ namespace Server.Items public static class TalismanSlayer { - private static Dictionary m_Table = new Dictionary(); + private static Dictionary m_Table; public static void Initialize() { - m_Table[TalismanSlayerName.Bear] = new[] + m_Table = new Dictionary { - typeof(GrizzlyBear), typeof(BlackBear), typeof(BrownBear), typeof(PolarBear) //, typeof( Grobu ) - }; + [TalismanSlayerName.Bear] = new[] + { + typeof(GrizzlyBear), typeof(BlackBear), typeof(BrownBear), typeof(PolarBear) //, typeof( Grobu ) + }, + [TalismanSlayerName.Vermin] = new[] + { + typeof(RatmanMage), typeof(RatmanMage), typeof(RatmanArcher), typeof(Barracoon), typeof(Ratman), typeof(SewerRat), + typeof(Rat), typeof(GiantRat) //, typeof( Chiikkaha ) + }, + [TalismanSlayerName.Bat] = new[] { typeof(Mongbat), typeof(StrongMongbat), typeof(VampireBat) }, + [TalismanSlayerName.Mage] = + new[] + { + typeof(EvilMage), typeof(EvilMageLord), typeof(AncientLich), typeof(Lich), typeof(LichLord), + typeof(SkeletalMage), typeof(BoneMagi), typeof(OrcishMage), typeof(KhaldunZealot), typeof(JukaMage) + }, + [TalismanSlayerName.Beetle] = + new[] + { + typeof(Beetle), typeof(RuneBeetle), typeof(FireBeetle), typeof(DeathwatchBeetle), + typeof(DeathwatchBeetleHatchling) + }, + [TalismanSlayerName.Bird] = new[] + { + typeof(Bird), typeof(TropicalBird), typeof(Chicken), typeof(Crane), typeof(DesertOstard), typeof(Eagle), + typeof(ForestOstard), typeof(FrenziedOstard), + typeof(Phoenix), /*typeof( Pyre ), typeof( Swoop ), typeof( Saliva ),*/ typeof(Harpy), typeof(StoneHarpy) // ????? + }, + [TalismanSlayerName.Ice] = new[] + { + typeof(ArcticOgreLord), typeof(IceElemental), typeof(SnowElemental), typeof(FrostOoze), + typeof(IceFiend), /*typeof( UnfrozenMummy ),*/ typeof(FrostSpider), typeof(LadyOfTheSnow), typeof(FrostTroll), - m_Table[TalismanSlayerName.Vermin] = new[] - { - typeof(RatmanMage), typeof(RatmanMage), typeof(RatmanArcher), typeof(Barracoon), - typeof(Ratman), typeof(SewerRat), typeof(Rat), typeof(GiantRat) //, typeof( Chiikkaha ) - }; + // TODO WinterReaper, check + typeof(IceSnake), typeof(SnowLeopard), typeof(PolarBear), typeof(IceSerpent), typeof(GiantIceWorm) + }, + [TalismanSlayerName.Flame] = new[] + { + typeof(FireBeetle), typeof(HellHound), typeof(LavaSerpent), typeof(FireElemental), typeof(PredatorHellCat), + typeof(Phoenix), typeof(FireGargoyle), typeof(HellCat), + /*typeof( Pyre ),*/ typeof(FireSteed), typeof(LavaLizard), - m_Table[TalismanSlayerName.Bat] = new[] - { - typeof(Mongbat), typeof(StrongMongbat), typeof(VampireBat) - }; - - m_Table[TalismanSlayerName.Mage] = new[] - { - typeof(EvilMage), typeof(EvilMageLord), typeof(AncientLich), typeof(Lich), typeof(LichLord), - typeof(SkeletalMage), typeof(BoneMagi), typeof(OrcishMage), typeof(KhaldunZealot), typeof(JukaMage) - }; - - m_Table[TalismanSlayerName.Beetle] = new[] - { - typeof(Beetle), typeof(RuneBeetle), typeof(FireBeetle), typeof(DeathwatchBeetle), - typeof(DeathwatchBeetleHatchling) - }; - - m_Table[TalismanSlayerName.Bird] = new[] - { - typeof(Bird), typeof(TropicalBird), typeof(Chicken), typeof(Crane), - typeof(DesertOstard), typeof(Eagle), typeof(ForestOstard), typeof(FrenziedOstard), - typeof(Phoenix), /*typeof( Pyre ), typeof( Swoop ), typeof( Saliva ),*/ typeof(Harpy), - typeof(StoneHarpy) // ????? - }; - - m_Table[TalismanSlayerName.Ice] = new[] - { - typeof(ArcticOgreLord), typeof(IceElemental), typeof(SnowElemental), typeof(FrostOoze), - typeof(IceFiend), /*typeof( UnfrozenMummy ),*/ typeof(FrostSpider), typeof(LadyOfTheSnow), - typeof(FrostTroll), - - // TODO WinterReaper, check - typeof(IceSnake), typeof(SnowLeopard), typeof(PolarBear), typeof(IceSerpent), typeof(GiantIceWorm) - }; - - m_Table[TalismanSlayerName.Flame] = new[] - { - typeof(FireBeetle), typeof(HellHound), typeof(LavaSerpent), typeof(FireElemental), - typeof(PredatorHellCat), typeof(Phoenix), typeof(FireGargoyle), typeof(HellCat), - /*typeof( Pyre ),*/ typeof(FireSteed), typeof(LavaLizard), - - // TODO check - typeof(LavaSnake) - }; - - m_Table[TalismanSlayerName.Bovine] = new[] - { - typeof(Cow), typeof(Bull), typeof(Gaman) /*, typeof( MinotaurCaptain ), - typeof( MinotaurScout ), typeof( Minotaur )*/ - - // TODO TormentedMinotaur + // TODO check + typeof(LavaSnake) + }, + [TalismanSlayerName.Bovine] = new[] + { + typeof(Cow), typeof(Bull), typeof(Gaman) /*, typeof( MinotaurCaptain ), + typeof( MinotaurScout ), typeof( Minotaur )*/ + // TODO TormentedMinotaur + } }; } public static bool Slays(TalismanSlayerName name, Mobile m) { - if (!m_Table.ContainsKey(name)) - return false; - - Type[] types = m_Table[name]; - - if (types == null || m == null) - return false; + if (m == null || !m_Table.TryGetValue(name, out Type[] types) || types == null) + return false;; Type type = m.GetType(); @@ -108,4 +94,4 @@ namespace Server.Items return false; } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Abilities/BleedAttack.cs b/Scripts/Items/Weapons/Abilities/BleedAttack.cs index 3d4396de3..ce134afce 100644 --- a/Scripts/Items/Weapons/Abilities/BleedAttack.cs +++ b/Scripts/Items/Weapons/Abilities/BleedAttack.cs @@ -59,11 +59,10 @@ namespace Server.Items public static void BeginBleed(Mobile m, Mobile from) { - Timer t = m_Table[m]; + m_Table.TryGetValue(m, out Timer t); t?.Stop(); m_Table[m] = t = new InternalTimer(from, m); - t.Start(); } @@ -90,9 +89,7 @@ namespace Server.Items public static void EndBleed(Mobile m, bool message) { - Timer t = m_Table[m]; - - if (t == null) + if (!m_Table.TryGetValue(m, out Timer t)) return; t.Stop(); diff --git a/Scripts/Items/Weapons/Abilities/Block.cs b/Scripts/Items/Weapons/Abilities/Block.cs index 74880f21c..59c3efebc 100644 --- a/Scripts/Items/Weapons/Abilities/Block.cs +++ b/Scripts/Items/Weapons/Abilities/Block.cs @@ -45,8 +45,7 @@ namespace Server.Items public static bool GetBonus(Mobile targ, ref int bonus) { - BlockInfo info = m_Table[targ]; - if (info == null) + if (!m_Table.TryGetValue(targ, out BlockInfo info)) return false; bonus = info.m_Bonus; @@ -61,9 +60,7 @@ namespace Server.Items public static void EndBlock(Mobile m) { - BlockInfo info = m_Table[m]; - - if (info == null) + if (!m_Table.TryGetValue(m, out BlockInfo info)) return; info.m_Timer?.Stop(); diff --git a/Scripts/Items/Weapons/Abilities/DefenseMastery.cs b/Scripts/Items/Weapons/Abilities/DefenseMastery.cs index eca17aafc..adb6c70b4 100644 --- a/Scripts/Items/Weapons/Abilities/DefenseMastery.cs +++ b/Scripts/Items/Weapons/Abilities/DefenseMastery.cs @@ -41,9 +41,7 @@ namespace Server.Items ((Math.Max(attacker.Skills.Bushido.Value, attacker.Skills.Ninjitsu.Value) - 50.0) / 70.0)); - DefenseMasteryInfo info = m_Table[attacker]; - - if (info != null) + if (m_Table.TryGetValue(attacker, out DefenseMasteryInfo info)) EndDefense(info); ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, 50 + modifier); @@ -59,9 +57,7 @@ namespace Server.Items public static bool GetMalus(Mobile targ, ref int damageMalus) { - DefenseMasteryInfo info = m_Table[targ]; - - if (info == null) + if (!m_Table.TryGetValue(targ, out DefenseMasteryInfo info)) return false; damageMalus = info.m_DamageMalus; diff --git a/Scripts/Items/Weapons/Abilities/DualWield.cs b/Scripts/Items/Weapons/Abilities/DualWield.cs index 6375bbe11..f9cb9b074 100644 --- a/Scripts/Items/Weapons/Abilities/DualWield.cs +++ b/Scripts/Items/Weapons/Abilities/DualWield.cs @@ -30,8 +30,7 @@ namespace Server.Items if (!Validate(attacker) || !CheckMana(attacker, true)) return; - DualWieldTimer timer = Registry[attacker]; - if (timer != null) + if (Registry.TryGetValue(attacker, out DualWieldTimer timer)) { timer.Stop(); Registry.Remove(attacker); diff --git a/Scripts/Items/Weapons/Abilities/Feint.cs b/Scripts/Items/Weapons/Abilities/Feint.cs index 3c9878b4e..0559a9758 100644 --- a/Scripts/Items/Weapons/Abilities/Feint.cs +++ b/Scripts/Items/Weapons/Abilities/Feint.cs @@ -30,8 +30,7 @@ namespace Server.Items if (!Validate(attacker) || !CheckMana(attacker, true)) return; - FeintTimer timer = Registry[defender]; - if (timer != null) + if (Registry.TryGetValue(defender, out FeintTimer timer)) { timer.Stop(); Registry.Remove(defender); diff --git a/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs b/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs index 3ec95780b..5401190c8 100644 --- a/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs +++ b/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs @@ -78,9 +78,7 @@ namespace Server.Items Mobile m = targets[i]; attacker.DoHarmful(m, true); - FrenziedWirlwindTimer timer = Registry[m]; - - if (timer != null) + if (Registry.TryGetValue(m, out FrenziedWirlwindTimer timer)) { timer.Stop(); Registry.Remove(m); diff --git a/Scripts/Items/Weapons/Abilities/MortalStrike.cs b/Scripts/Items/Weapons/Abilities/MortalStrike.cs index 39a5bd362..8e7a4bae2 100644 --- a/Scripts/Items/Weapons/Abilities/MortalStrike.cs +++ b/Scripts/Items/Weapons/Abilities/MortalStrike.cs @@ -41,8 +41,8 @@ namespace Server.Items public static void BeginWound(Mobile m, TimeSpan duration) { - InternalTimer timer = m_Table[m]; - timer?.Stop(); + if (m_Table.TryGetValue(m, out InternalTimer timer)) + timer?.Stop(); m_Table[m] = timer = new InternalTimer(m, duration); timer.Start(); @@ -52,9 +52,7 @@ namespace Server.Items public static void EndWound(Mobile m) { - Timer timer = m_Table[m]; - - if (timer != null) + if (m_Table.TryGetValue(m, out InternalTimer timer)) { timer.Stop(); m_Table.Remove(m); diff --git a/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs b/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs index 479c0f1a1..4bfa6b8e4 100644 --- a/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs +++ b/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs @@ -88,18 +88,20 @@ namespace Server.Items public static void BeginImmunity(Mobile m, TimeSpan duration) { - InternalTimer timer = m_Table[m]; + if (m_Table.TryGetValue(m, out InternalTimer timer)) + timer?.Stop(); - timer?.Stop(); m_Table[m] = timer = new InternalTimer(m, duration); timer.Start(); } public static void EndImmunity(Mobile m) { - InternalTimer timer = m_Table[m]; - timer?.Stop(); - m_Table.Remove(m); + if (m_Table.TryGetValue(m, out InternalTimer timer)) + { + timer?.Stop(); + m_Table.Remove(m); + } } private class InternalTimer : Timer diff --git a/Scripts/Items/Weapons/Abilities/TalonStrike.cs b/Scripts/Items/Weapons/Abilities/TalonStrike.cs index 7d2fbfd21..3d77db0be 100644 --- a/Scripts/Items/Weapons/Abilities/TalonStrike.cs +++ b/Scripts/Items/Weapons/Abilities/TalonStrike.cs @@ -8,7 +8,7 @@ namespace Server.Items /// public class TalonStrike : WeaponAbility { - private static Dictionary m_Table = new Dictionary(); + private static HashSet m_Table = new HashSet(); 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 (m_Table.ContainsKey(defender) || !Validate(attacker) || !CheckMana(attacker, true)) + if (m_Table.Contains(defender) || !Validate(attacker) || !CheckMana(attacker, true)) return; ClearCurrentAbility(attacker); @@ -42,7 +42,7 @@ namespace Server.Items timer.Start(); - m_Table.Add(defender, timer); + m_Table.Add(defender); } private class InternalTimer : Timer diff --git a/Scripts/Items/Weapons/Abilities/WeaponAbility.cs b/Scripts/Items/Weapons/Abilities/WeaponAbility.cs index 2a1cc8026..1b1259c90 100644 --- a/Scripts/Items/Weapons/Abilities/WeaponAbility.cs +++ b/Scripts/Items/Weapons/Abilities/WeaponAbility.cs @@ -350,7 +350,7 @@ namespace Server.Items return null; } - WeaponAbility a = Table[m]; + Table.TryGetValue(m, out WeaponAbility a); if (!IsWeaponAbility(m, a)) { @@ -446,7 +446,8 @@ namespace Server.Items private static WeaponAbilityContext GetContext(Mobile m) { - return m_PlayersTable[m]; + m_PlayersTable.TryGetValue(m, out WeaponAbilityContext context); + return context; } private class WeaponAbilityTimer : Timer diff --git a/Scripts/Items/Weapons/HitLower.cs b/Scripts/Items/Weapons/HitLower.cs index aab3a262f..723b3ff09 100644 --- a/Scripts/Items/Weapons/HitLower.cs +++ b/Scripts/Items/Weapons/HitLower.cs @@ -9,12 +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 Dictionary m_AttackTable = new Dictionary(); - private static Dictionary m_DefenseTable = new Dictionary(); + private static HashSet m_AttackTable = new HashSet(); + private static HashSet m_DefenseTable = new HashSet(); public static bool IsUnderAttackEffect(Mobile m) { - return m_AttackTable.ContainsKey(m); + return m_AttackTable.Contains(m); } public static bool ApplyAttack(Mobile m) @@ -22,7 +22,9 @@ namespace Server.Items if (IsUnderAttackEffect(m)) return false; - m_AttackTable[m] = new AttackTimer(m); + m_AttackTable.Add(m); + AttackTimer timer = new AttackTimer(m); + timer.Start(); m.SendLocalizedMessage(1062319); // Your attack chance has been reduced! return true; } @@ -35,7 +37,7 @@ namespace Server.Items public static bool IsUnderDefenseEffect(Mobile m) { - return m_DefenseTable.ContainsKey(m); + return m_DefenseTable.Contains(m); } public static bool ApplyDefense(Mobile m) @@ -43,7 +45,9 @@ namespace Server.Items if (IsUnderDefenseEffect(m)) return false; - m_DefenseTable[m] = new DefenseTimer(m); + m_DefenseTable.Add(m); + DefenseTimer timer = new DefenseTimer(m); + timer.Start(); m.SendLocalizedMessage(1062318); // Your defense chance has been reduced! return true; } @@ -61,10 +65,7 @@ namespace Server.Items public AttackTimer(Mobile player) : base(AttackEffectDuration) { m_Player = player; - Priority = TimerPriority.TwoFiftyMS; - - Start(); } protected override void OnTick() @@ -80,10 +81,7 @@ namespace Server.Items public DefenseTimer(Mobile player) : base(DefenseEffectDuration) { m_Player = player; - Priority = TimerPriority.TwoFiftyMS; - - Start(); } protected override void OnTick() diff --git a/Scripts/Misc/Assistants.cs b/Scripts/Misc/Assistants.cs index 561b791b2..a6172e18d 100644 --- a/Scripts/Misc/Assistants.cs +++ b/Scripts/Misc/Assistants.cs @@ -107,7 +107,7 @@ namespace Server.Misc m.Send(new BeginHandshake()); if (m_Dictionary.TryGetValue(m, out Timer t)) - t?.Stop(); + t.Stop(); m_Dictionary[m] = t = Timer.DelayCall(Settings.HandshakeTimeout, OnHandshakeTimeout, m); t.Start(); @@ -124,7 +124,7 @@ namespace Server.Misc Mobile m = state.Mobile; if (m_Dictionary.TryGetValue(m, out Timer t)) { - t?.Stop(); + t.Stop(); m_Dictionary.Remove(m); } @@ -159,7 +159,7 @@ namespace Server.Misc { if (m == null) return; - + if (m.NetState != null && m.NetState.Running) m.NetState.Dispose(); @@ -179,4 +179,4 @@ namespace Server.Misc } } } -} \ No newline at end of file +} diff --git a/Scripts/Misc/Emitter.cs b/Scripts/Misc/Emitter.cs index a01e1383c..5c7f1518f 100644 --- a/Scripts/Misc/Emitter.cs +++ b/Scripts/Misc/Emitter.cs @@ -114,14 +114,14 @@ namespace Server if (!m_Temps.TryGetValue( localType, out Queue list )) m_Temps[localType] = list = new Queue(); - if ( list.Count > 0 ) - return list.Dequeue(); - - return CreateLocal( localType ); + return list.Count > 0 ? list.Dequeue() : CreateLocal( localType ); } public void ReleaseTemp( LocalBuilder local ) { + if (local.LocalType == null) + return; + if (!m_Temps.TryGetValue( local.LocalType, out Queue list )) m_Temps[local.LocalType] = list = new Queue(); diff --git a/Scripts/Misc/Guild.cs b/Scripts/Misc/Guild.cs index 336fe334b..24b759523 100644 --- a/Scripts/Misc/Guild.cs +++ b/Scripts/Misc/Guild.cs @@ -242,18 +242,11 @@ namespace Server.Guilds for (int i = 0; i < m_Members.Count; i++) m_Members[i].Alliance = null; - Alliances.TryGetValue(Name.ToLower(), out AllianceInfo aInfo); - - if (aInfo == this) + if (Alliances.TryGetValue(Name.ToLower(), out AllianceInfo aInfo) && aInfo == this) Alliances.Remove(Name.ToLower()); } - public void InvalidateMemberProperties() - { - InvalidateMemberProperties(false); - } - - public void InvalidateMemberProperties(bool onlyOPL) + public void InvalidateMemberProperties(bool onlyOPL = false) { for (int i = 0; i < m_Members.Count; i++) { @@ -1449,11 +1442,7 @@ namespace Server.Guilds if (m == null) continue; - if (!votes.TryGetValue(m, out int v)) - votes[m] = 1; - else - votes[m] = v + 1; - + votes[m] = 1 + (votes.TryGetValue(m, out int v) ? v : 0); votingMembers++; } diff --git a/Scripts/Misc/InhumanSpeech.cs b/Scripts/Misc/InhumanSpeech.cs index 802b2be4b..fbb1b038d 100644 --- a/Scripts/Misc/InhumanSpeech.cs +++ b/Scripts/Misc/InhumanSpeech.cs @@ -405,9 +405,7 @@ namespace Server.Misc for ( int i = 0; i < split.Length; ++i ) { - m_KeywordHash.TryGetValue( split[i], out string keyword ); - - if ( keyword != null ) + if (m_KeywordHash.TryGetValue( split[i], out string keyword )) keywordsFound.Add( keyword ); } diff --git a/Scripts/Misc/LanguageStatistics.cs b/Scripts/Misc/LanguageStatistics.cs index b01c00c24..43c528e66 100644 --- a/Scripts/Misc/LanguageStatistics.cs +++ b/Scripts/Misc/LanguageStatistics.cs @@ -8,15 +8,15 @@ namespace Server.Misc /** * This file requires to be saved in a Unicode * compatible format. - * + * * Warning: if you change String.Format methods, * please note that the following character * is suggested before any left-to-right text * in order to prevent undesired formatting * resulting from mixing LR and RL text: ‎ - * + * * Use this one if you need to force RL: ‏ - * + * * If you do not see the above chars, please * enable showing of unicode control chars **/ @@ -199,17 +199,17 @@ namespace Server.Misc string lang = mob?.Language; - if (lang != null) - { - lang = lang.ToUpper(); + if (lang == null) + continue; - if (!ht.ContainsKey(lang)) - ht[lang] = new InternationalCodeCounter(lang); - else - ht[lang].Increase(); + lang = lang.ToUpper(); - break; - } + if (ht.TryGetValue(lang, out InternationalCodeCounter codes)) + codes.Increase(); + else + ht[lang] = new InternationalCodeCounter(lang); + + break; } else foreach (Mobile mob in World.Mobiles.Values) @@ -217,15 +217,15 @@ namespace Server.Misc { string lang = mob.Language; - if (lang != null) - { - lang = lang.ToUpper(); + if (lang == null) + continue; - if (!ht.ContainsKey(lang)) - ht[lang] = new InternationalCodeCounter(lang); - else - ht[lang].Increase(); - } + lang = lang.ToUpper(); + + if (ht.TryGetValue(lang, out InternationalCodeCounter codes)) + codes.Increase(); + else + ht[lang] = new InternationalCodeCounter(lang); } writer.WriteLine( @@ -350,4 +350,4 @@ namespace Server.Misc } } } -} \ No newline at end of file +} diff --git a/Scripts/Misc/NameList.cs b/Scripts/Misc/NameList.cs index c0eb26ab2..140b690d5 100644 --- a/Scripts/Misc/NameList.cs +++ b/Scripts/Misc/NameList.cs @@ -45,12 +45,7 @@ namespace Server public static string RandomName( string type ) { - NameList list = GetNameList( type ); - - if ( list != null ) - return list.GetRandomName(); - - return ""; + return GetNameList( type )?.GetRandomName() ?? ""; } private static Dictionary m_Table; diff --git a/Scripts/Misc/ResourceInfo.cs b/Scripts/Misc/ResourceInfo.cs index d967516d6..b7290d500 100644 --- a/Scripts/Misc/ResourceInfo.cs +++ b/Scripts/Misc/ResourceInfo.cs @@ -488,10 +488,7 @@ namespace Server.Items if ( m_TypeTable == null ) return CraftResource.None; - if (!m_TypeTable.TryGetValue(resourceType, out CraftResource res)) - return CraftResource.None; - - return res; + return m_TypeTable.TryGetValue(resourceType, out CraftResource res) ? res : CraftResource.None; } /// diff --git a/Scripts/Misc/VendorGenerator.cs b/Scripts/Misc/VendorGenerator.cs index 8bd7af4af..a8a38f218 100644 --- a/Scripts/Misc/VendorGenerator.cs +++ b/Scripts/Misc/VendorGenerator.cs @@ -392,9 +392,10 @@ namespace Server if (flags != ShopFlags.None) { Point2D p = new Point2D(x, y); - ShopInfo si = m_ShopTable[p]; - if (si == null) + if (m_ShopTable.TryGetValue(p, out ShopInfo si)) + si.m_Flags |= flags; + else { List floor = new List(); @@ -409,10 +410,6 @@ namespace Server for (int i = 0; i < floor.Count; ++i) m_ShopTable[floor[i]] = si; } - else - { - si.m_Flags |= flags; - } } } diff --git a/Scripts/Misc/Weather.cs b/Scripts/Misc/Weather.cs index ccc2e0abe..c1f34a70b 100644 --- a/Scripts/Misc/Weather.cs +++ b/Scripts/Misc/Weather.cs @@ -45,9 +45,7 @@ namespace Server.Misc if ( facet == null ) return null; - m_WeatherByFacet.TryGetValue( facet, out List list ); - - if ( list == null ) + if (!m_WeatherByFacet.TryGetValue( facet, out List list )) m_WeatherByFacet[facet] = list = new List(); return list; @@ -74,10 +72,8 @@ namespace Server.Misc if ( !isValid ) continue; - Weather w = new Weather( m_Facets[i], new[]{ area }, temperature, chanceOfPercipitation, chanceOfExtremeTemperature, TimeSpan.FromSeconds( 30.0 ) ); - - w.Bounds = bounds; - w.MoveSpeed = moveSpeed; + new Weather(m_Facets[i], new[] { area }, temperature, chanceOfPercipitation, chanceOfExtremeTemperature, + TimeSpan.FromSeconds(30.0)) { Bounds = bounds, MoveSpeed = moveSpeed }; } } @@ -127,36 +123,13 @@ namespace Server.Misc public static bool CheckIntersection( Rectangle2D r1, Rectangle2D r2 ) { - if ( r1.X >= (r2.X + r2.Width) ) - return false; - - if ( r2.X >= (r1.X + r1.Width) ) - return false; - - if ( r1.Y >= (r2.Y + r2.Height) ) - return false; - - if ( r2.Y >= (r1.Y + r1.Height) ) - return false; - - return true; + return r1.X < r2.X + r2.Width && r2.X < r1.X + r1.Width && r1.Y < r2.Y + r2.Height && r2.Y < r1.Y + r1.Height; } public static bool CheckContains( Rectangle2D big, Rectangle2D small ) { - if ( small.X < big.X ) - return false; - - if ( small.Y < big.Y ) - return false; - - if ( (small.X + small.Width) > (big.X + big.Width) ) - return false; - - if ( (small.Y + small.Height) > (big.Y + big.Height) ) - return false; - - return true; + return small.X >= big.X && small.Y >= big.Y && small.X + small.Width <= big.X + big.Width + && small.Y + small.Height <= big.Y + big.Height; } public virtual bool IntersectsWith( Rectangle2D area ) @@ -182,7 +155,7 @@ namespace Server.Misc list?.Add( this ); - Timer.DelayCall( TimeSpan.FromSeconds( (0.2+(Utility.RandomDouble()*0.8)) * interval.TotalSeconds ), interval, OnTick ); + Timer.DelayCall( TimeSpan.FromSeconds( (0.2+Utility.RandomDouble()*0.8) * interval.TotalSeconds ), interval, OnTick ); } public virtual void Reposition() @@ -231,8 +204,8 @@ namespace Server.Misc for ( int i = 0; i < 5; ++i ) // try 5 times to find a valid spot { - int xOffset = (MoveSpeed * MoveAngleX) / 100; - int yOffset = (MoveSpeed * MoveAngleY) / 100; + int xOffset = MoveSpeed * MoveAngleX / 100; + int yOffset = MoveSpeed * MoveAngleY / 100; Rectangle2D oldArea = Area[0]; Rectangle2D newArea = new Rectangle2D( oldArea.X + xOffset, oldArea.Y + yOffset, oldArea.Width, oldArea.Height ); @@ -255,8 +228,8 @@ namespace Server.Misc { if ( m_Stage == 0 ) { - m_Active = ( ChanceOfPercipitation > Utility.Random( 100 ) ); - m_ExtremeTemperature = ( ChanceOfExtremeTemperature > Utility.Random( 100 ) ); + m_Active = ChanceOfPercipitation > Utility.Random( 100 ); + m_ExtremeTemperature = ChanceOfExtremeTemperature > Utility.Random( 100 ); if ( MoveSpeed > 0 ) { @@ -270,9 +243,8 @@ namespace Server.Misc if ( m_Stage > 0 && MoveSpeed > 0 ) MoveForward(); - int type, density, temperature; - - temperature = Temperature; + int type, density; + int temperature = Temperature; if ( m_ExtremeTemperature ) temperature *= -1; @@ -283,7 +255,7 @@ namespace Server.Misc } else { - density = 150 - (m_Stage * 5); + density = 150 - m_Stage * 5; if ( density < 10 ) density = 10; @@ -310,7 +282,7 @@ namespace Server.Misc if ( mob == null || mob.Map != Facet ) continue; - bool contains = ( Area.Length == 0 ); + bool contains = Area.Length == 0; for ( int j = 0; !contains && j < Area.Length; ++j ) contains = Area[j].Contains( mob.Location ); @@ -358,7 +330,7 @@ namespace Server.Misc Weather w = list[i]; for ( int j = 0; j < w.Area.Length; ++j ) - AddWorldPin( w.Area[j].X + (w.Area[j].Width/2), w.Area[j].Y + (w.Area[j].Height/2) ); + AddWorldPin( w.Area[j].X + w.Area[j].Width/2, w.Area[j].Y + w.Area[j].Height/2 ); } base.OnDoubleClick( from ); diff --git a/Scripts/Mobiles/AI/SpeedInfo.cs b/Scripts/Mobiles/AI/SpeedInfo.cs index 29be32361..2ce741e70 100644 --- a/Scripts/Mobiles/AI/SpeedInfo.cs +++ b/Scripts/Mobiles/AI/SpeedInfo.cs @@ -169,9 +169,9 @@ namespace Server if (m_Table == null) LoadTable(); - m_Table.TryGetValue(obj.GetType(), out SpeedInfo sp); + ; - return sp != null; + return m_Table.ContainsKey(obj.GetType()); } public static bool GetSpeeds(object obj, ref double activeSpeed, ref double passiveSpeed) @@ -182,9 +182,7 @@ namespace Server if (m_Table == null) LoadTable(); - m_Table.TryGetValue(obj.GetType(), out SpeedInfo sp); - - if (sp == null) + if (!m_Table.TryGetValue(obj.GetType(), out SpeedInfo sp)) return false; activeSpeed = sp.ActiveSpeed; @@ -207,4 +205,4 @@ namespace Server } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Animals/Mounts/Hiryu.cs b/Scripts/Mobiles/Animals/Mounts/Hiryu.cs index fd705bc4e..aef3335e4 100644 --- a/Scripts/Mobiles/Animals/Mounts/Hiryu.cs +++ b/Scripts/Mobiles/Animals/Mounts/Hiryu.cs @@ -167,39 +167,37 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (0.1 > Utility.RandomDouble()) - { - /* Grasping Claw + if (0.1 <= Utility.RandomDouble()) + return; + + /* Grasping Claw * Start cliloc: 1070836 * Effect: Physical resistance -15% for 5 seconds * End cliloc: 1070838 * 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 = m_Table[defender]; - - if (timer != null) - { - timer.DoExpire(); - defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state. - } - else - { - defender.SendLocalizedMessage( - 1070836); // The blow from the creature's claws has made you more susceptible to physical attacks. - } - - int effect = -(defender.PhysicalResistance * 15 / 100); - - ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect); - - defender.FixedEffect(0x37B9, 10, 5); - defender.AddResistanceMod(mod); - - timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0)); - timer.Start(); - m_Table[defender] = timer; + if (m_Table.TryGetValue(defender, out ExpireTimer timer)) + { + timer.DoExpire(); + defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state. } + else + { + defender.SendLocalizedMessage( + 1070836); // The blow from the creature's claws has made you more susceptible to physical attacks. + } + + int effect = -(defender.PhysicalResistance * 15 / 100); + + ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect); + + defender.FixedEffect(0x37B9, 10, 5); + defender.AddResistanceMod(mod); + + timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0)); + timer.Start(); + m_Table[defender] = timer; } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs b/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs index 2e3e0de8b..fb8e36110 100644 --- a/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs +++ b/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs @@ -161,39 +161,37 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (0.1 > Utility.RandomDouble()) - { - /* Grasping Claw + if (0.1 <= Utility.RandomDouble()) + return; + + /* Grasping Claw * Start cliloc: 1070836 * Effect: Physical resistance -15% for 5 seconds * End cliloc: 1070838 * 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 = m_Table[defender]; - - if (timer != null) - { - timer.DoExpire(); - defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state. - } - else - { - defender.SendLocalizedMessage( - 1070836); // The blow from the creature's claws has made you more susceptible to physical attacks. - } - - int effect = -(defender.PhysicalResistance * 15 / 100); - - ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect); - - defender.FixedEffect(0x37B9, 10, 5); - defender.AddResistanceMod(mod); - - timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0)); - timer.Start(); - m_Table[defender] = timer; + if (m_Table.TryGetValue(defender, out ExpireTimer timer)) + { + timer.DoExpire(); + defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state. } + else + { + defender.SendLocalizedMessage( + 1070836); // The blow from the creature's claws has made you more susceptible to physical attacks. + } + + int effect = -(defender.PhysicalResistance * 15 / 100); + + ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect); + + defender.FixedEffect(0x37B9, 10, 5); + defender.AddResistanceMod(mod); + + timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0)); + timer.Start(); + m_Table[defender] = timer; } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/BaseCreature.cs b/Scripts/Mobiles/BaseCreature.cs index 1a0d4675e..ef0f2394d 100644 --- a/Scripts/Mobiles/BaseCreature.cs +++ b/Scripts/Mobiles/BaseCreature.cs @@ -415,7 +415,10 @@ namespace Server.Mobiles } } - public virtual bool IsNecroFamiliar => Summoned && m_ControlMaster != null && SummonFamiliarSpell.Table[m_ControlMaster] == this; + public virtual bool IsNecroFamiliar => Summoned && m_ControlMaster != null && + SummonFamiliarSpell.Table.TryGetValue(m_ControlMaster, out BaseCreature bc) && + bc == this; + public virtual bool DeleteCorpseOnDeath => !Core.AOS && m_bSummoned; [CommandProperty(AccessLevel.GameMaster)] @@ -2317,7 +2320,7 @@ namespace Server.Mobiles } if (DeathAdderCharmable && from.CanBeHarmful(this, false)) - if (SummonFamiliarSpell.Table[from] is DeathAdder da && !da.Deleted) + if (SummonFamiliarSpell.Table.TryGetValue(from, out BaseCreature bc) && (bc as DeathAdder)?.Deleted == false) { from.SendAsciiMessage("You charm the snake. Select a target to attack."); from.Target = new DeathAdderCharmTarget(this); @@ -2345,7 +2348,7 @@ namespace Server.Mobiles list.Add(1080078); // guarding } - if (Summoned && !IsAnimatedDead && !IsNecroFamiliar && !(this is Clone)) + if (Summoned && !(IsAnimatedDead || IsNecroFamiliar || this is Clone)) { list.Add(1049646); // (summoned) } @@ -3296,7 +3299,7 @@ namespace Server.Mobiles if (!m_Charmed.DeathAdderCharmable || m_Charmed.Combatant != null || !from.CanBeHarmful(m_Charmed, false)) return; - if (!(SummonFamiliarSpell.Table[from] is DeathAdder da) || da.Deleted) + if (!(SummonFamiliarSpell.Table.TryGetValue(from, out BaseCreature bc) && (bc as DeathAdder)?.Deleted == false)) return; if (!(targeted is Mobile targ && from.CanBeHarmful(targ, false))) diff --git a/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs b/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs index a3b42f4dc..c81f316b1 100644 --- a/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs +++ b/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs @@ -165,9 +165,7 @@ namespace Server.Mobiles public static void StopEffect(Mobile m, bool message) { - Timer timer = m_Table[m]; - - if (timer != null) + if (m_Table.TryGetValue(m, out Timer timer)) { if (message) m.PublicOverheadMessage(MessageType.Emote, m.SpeechHue, true, @@ -181,15 +179,11 @@ namespace Server.Mobiles public void DoEffect(Mobile m, int count) { if (!m.Alive) - { StopEffect(m, false); - } else { if (m.FindItemOnLayer(Layer.TwoHanded) is Torch torch && torch.Burning) - { StopEffect(m, true); - } else { if (count % 4 == 0) diff --git a/Scripts/Mobiles/Monsters/ML/Bedlam/LadyJennifyr.cs b/Scripts/Mobiles/Monsters/ML/Bedlam/LadyJennifyr.cs index 8b2d2b4c1..f30c2d296 100644 --- a/Scripts/Mobiles/Monsters/ML/Bedlam/LadyJennifyr.cs +++ b/Scripts/Mobiles/Monsters/ML/Bedlam/LadyJennifyr.cs @@ -73,22 +73,22 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (Utility.RandomDouble() < 0.1) - { - if (m_Table.TryGetValue(defender, out ExpireTimer timer)) - timer.DoExpire(); + if (Utility.RandomDouble() >= 0.1) + return; - defender.FixedParticles(0x3709, 10, 30, 5052, EffectLayer.LeftFoot); - defender.PlaySound(0x208); - defender.SendLocalizedMessage( - 1070833); // The creature fans you with fire, reducing your resistance to fire attacks. + if (m_Table.TryGetValue(defender, out ExpireTimer timer)) + timer.DoExpire(); - ResistanceMod mod = new ResistanceMod(ResistanceType.Fire, -10); - defender.AddResistanceMod(mod); + defender.FixedParticles(0x3709, 10, 30, 5052, EffectLayer.LeftFoot); + defender.PlaySound(0x208); + defender.SendLocalizedMessage( + 1070833); // The creature fans you with fire, reducing your resistance to fire attacks. - m_Table[defender] = timer = new ExpireTimer(defender, mod); - timer.Start(); - } + ResistanceMod mod = new ResistanceMod(ResistanceType.Fire, -10); + defender.AddResistanceMod(mod); + + m_Table[defender] = timer = new ExpireTimer(defender, mod); + timer.Start(); } public override void Serialize(GenericWriter writer) @@ -133,4 +133,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/ML/Humanoid/Magic/Satyr.cs b/Scripts/Mobiles/Monsters/ML/Humanoid/Magic/Satyr.cs index d939f7b04..441ff720c 100644 --- a/Scripts/Mobiles/Monsters/ML/Humanoid/Magic/Satyr.cs +++ b/Scripts/Mobiles/Monsters/ML/Humanoid/Magic/Satyr.cs @@ -140,7 +140,10 @@ namespace Server.Mobiles public static void SuppressRemove(Mobile target) { - if (target != null && m_Suppressed[target] is Timer t) + if (target == null) + return; + + if (m_Suppressed.TryGetValue(target, out Timer t)) { if (t.Running) t.Stop(); @@ -199,7 +202,7 @@ namespace Server.Mobiles { Item item = m.FindItemOnLayer(layer); - if (item != null && item.Movable) + if (item?.Movable == true) m.PlaceInBackpack(item); } @@ -235,4 +238,4 @@ namespace Server.Mobiles #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs b/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs index a64b26fd2..be3243175 100644 --- a/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs +++ b/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs @@ -9,7 +9,7 @@ namespace Server.Mobiles { public class Ilhenir : BaseChampion { - private static Dictionary m_Table = new Dictionary(); + private static HashSet m_Table = new HashSet(); [Constructible] public Ilhenir() @@ -230,13 +230,14 @@ namespace Server.Mobiles public virtual void CacophonicAttack(Mobile to) { - if (to.Alive && to.Player && !m_Table.ContainsKey(to)) + if (to.Alive && to.Player && !UnderCacophonicAttack(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), CacophonicEnd, to); + m_Table.Add(to); + Timer.DelayCall(TimeSpan.FromSeconds(30), CacophonicEnd, to); } } @@ -248,7 +249,7 @@ namespace Server.Mobiles public static bool UnderCacophonicAttack(Mobile from) { - return m_Table.ContainsKey(from); + return m_Table.Contains(from); } public virtual void DropOoze() diff --git a/Scripts/Mobiles/Monsters/ML/Twisted Weald/Swoop.cs b/Scripts/Mobiles/Monsters/ML/Twisted Weald/Swoop.cs index 54265b0b2..299921cd4 100644 --- a/Scripts/Mobiles/Monsters/ML/Twisted Weald/Swoop.cs +++ b/Scripts/Mobiles/Monsters/ML/Twisted Weald/Swoop.cs @@ -101,32 +101,30 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (0.1 > Utility.RandomDouble()) + if (0.1 <= Utility.RandomDouble()) + return; + + if (m_Table.TryGetValue(defender, out ExpireTimer timer)) { - ExpireTimer timer = m_Table[defender]; - - if (timer != null) - { - timer.DoExpire(); - defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state. - } - else - { - defender.SendLocalizedMessage( - 1070836); // The blow from the creature's claws has made you more susceptible to physical attacks. - } - - int effect = -(defender.PhysicalResistance * 15 / 100); - - ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect); - - defender.FixedEffect(0x37B9, 10, 5); - defender.AddResistanceMod(mod); - - timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0)); - timer.Start(); - m_Table[defender] = timer; + timer.DoExpire(); + defender.SendLocalizedMessage(1070837); // The creature lands another blow in your weakened state. } + else + { + defender.SendLocalizedMessage( + 1070836); // The blow from the creature's claws has made you more susceptible to physical attacks. + } + + int effect = -(defender.PhysicalResistance * 15 / 100); + + ResistanceMod mod = new ResistanceMod(ResistanceType.Physical, effect); + + defender.FixedEffect(0x37B9, 10, 5); + defender.AddResistanceMod(mod); + + timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(5.0)); + timer.Start(); + m_Table[defender] = timer; } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs b/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs index 6a0033969..d737001e5 100644 --- a/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs +++ b/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs @@ -89,7 +89,7 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (!(0.1 > Utility.RandomDouble())) + if (0.1 <= Utility.RandomDouble()) return; /* Blood Bath @@ -100,9 +100,7 @@ namespace Server.Mobiles * End cliloc: 1070824 */ - ExpireTimer timer = m_Table[defender]; - - if (timer != null) + if (m_Table.TryGetValue(defender, out ExpireTimer timer)) { timer.DoExpire(); defender.SendLocalizedMessage(1070825); // The creature continues to rage! @@ -254,7 +252,6 @@ namespace Server.Mobiles AddItem(new Robe(Utility.RandomNondyedHue())); - m_DisguiseTimer = null; m_DisguiseTimer = Timer.DelayCall(TimeSpan.FromSeconds(75), RemoveDisguise); } @@ -280,9 +277,7 @@ namespace Server.Mobiles public void DeleteItemOnLayer(Layer layer) { - Item item = FindItemOnLayer(layer); - - item?.Delete(); + FindItemOnLayer(layer)?.Delete(); } #endregion diff --git a/Scripts/Mobiles/Monsters/SE/FanDancer.cs b/Scripts/Mobiles/Monsters/SE/FanDancer.cs index 2be81d5c0..39fee4b9a 100644 --- a/Scripts/Mobiles/Monsters/SE/FanDancer.cs +++ b/Scripts/Mobiles/Monsters/SE/FanDancer.cs @@ -9,7 +9,7 @@ namespace Server.Mobiles { public class FanDancer : BaseCreature { - private static Dictionary m_Table = new Dictionary(); + private static HashSet m_Table = new HashSet(); [Constructible] public FanDancer() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) @@ -143,13 +143,13 @@ namespace Server.Mobiles ExpireTimer timer = new ExpireTimer(defender, mod, TimeSpan.FromSeconds(10.0)); timer.Start(); - m_Table[defender] = timer; + m_Table.Add(defender); } } public bool IsFanned(Mobile m) { - return m_Table.ContainsKey(m); + return m_Table.Contains(m); } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/Monsters/SE/Kappa.cs b/Scripts/Mobiles/Monsters/SE/Kappa.cs index 6ea7a3e12..190b98f53 100644 --- a/Scripts/Mobiles/Monsters/SE/Kappa.cs +++ b/Scripts/Mobiles/Monsters/SE/Kappa.cs @@ -116,8 +116,7 @@ namespace Server.Mobiles public static void BeginLifeDrain(Mobile m, Mobile from) { - InternalTimer timer = m_Table[m]; - + m_Table.TryGetValue(m, out InternalTimer timer); timer?.Stop(); m_Table[m] = timer = new InternalTimer(from, m); @@ -139,12 +138,12 @@ namespace Server.Mobiles public static void EndLifeDrain(Mobile m) { - Timer timer = m_Table[m]; - timer?.Stop(); - - m_Table.Remove(m); - - m.SendLocalizedMessage(1070849); // The drain on your life force is gone. + if (m_Table.TryGetValue(m, out InternalTimer timer)) + { + timer?.Stop(); + m_Table.Remove(m); + m.SendLocalizedMessage(1070849); // The drain on your life force is gone. + } } public override void OnDamage(int amount, Mobile from, bool willKill) diff --git a/Scripts/Mobiles/Monsters/SE/KazeKemono.cs b/Scripts/Mobiles/Monsters/SE/KazeKemono.cs index c28219523..2f7985960 100644 --- a/Scripts/Mobiles/Monsters/SE/KazeKemono.cs +++ b/Scripts/Mobiles/Monsters/SE/KazeKemono.cs @@ -74,9 +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 = m_FlurryOfTwigsTable[defender]; - - if (timer != null) + if (m_FlurryOfTwigsTable.TryGetValue(defender, out ExpireTimer timer)) { timer.DoExpire(); defender.SendLocalizedMessage(1070851); // The creature lands another blow in your weakened state. @@ -97,8 +95,10 @@ namespace Server.Mobiles timer = new ExpireTimer(defender, mod, m_FlurryOfTwigsTable, TimeSpan.FromSeconds(5.0)); timer.Start(); m_FlurryOfTwigsTable[defender] = timer; + return; } - else if (0.05 > Utility.RandomDouble()) + + if (0.05 > Utility.RandomDouble()) { /* Chlorophyl Blast * Start cliloc: 1070827 @@ -107,9 +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 = m_ChlorophylBlastTable[defender]; - - if (timer != null) + if (m_ChlorophylBlastTable.TryGetValue(defender, out ExpireTimer timer)) { timer.DoExpire(); defender.SendLocalizedMessage(1070828); // The creature continues to hinder your energy resistance! diff --git a/Scripts/Mobiles/Monsters/SE/LadyOfTheSnow.cs b/Scripts/Mobiles/Monsters/SE/LadyOfTheSnow.cs index 93d72a6cc..6d72626b1 100644 --- a/Scripts/Mobiles/Monsters/SE/LadyOfTheSnow.cs +++ b/Scripts/Mobiles/Monsters/SE/LadyOfTheSnow.cs @@ -81,32 +81,30 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (0.1 > Utility.RandomDouble()) + if (0.1 <= Utility.RandomDouble()) + return; + + /* Cold Wind + * Graphics: Message - Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(928 164, 34)" ToLocation: "(928 164, 34)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False" + * Start cliloc: 1070832 + * Damage: 1hp per second for 5 seconds + * End cliloc: 1070830 + * Reset cliloc: 1070831 + */ + + if (m_Table.TryGetValue(defender, out ExpireTimer timer)) { - /* Cold Wind - * Graphics: Message - Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(928 164, 34)" ToLocation: "(928 164, 34)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False" - * Start cliloc: 1070832 - * Damage: 1hp per second for 5 seconds - * End cliloc: 1070830 - * Reset cliloc: 1070831 - */ - - ExpireTimer timer = m_Table[defender]; - - if (timer != null) - { - timer.DoExpire(); - defender.SendLocalizedMessage(1070831); // The freezing wind continues to blow! - } - else - { - defender.SendLocalizedMessage(1070832); // An icy wind surrounds you, freezing your lungs as you breathe! - } - - timer = new ExpireTimer(defender, this); - timer.Start(); - m_Table[defender] = timer; + timer.DoExpire(); + defender.SendLocalizedMessage(1070831); // The freezing wind continues to blow! } + else + { + defender.SendLocalizedMessage(1070832); // An icy wind surrounds you, freezing your lungs as you breathe! + } + + timer = new ExpireTimer(defender, this); + timer.Start(); + m_Table[defender] = timer; } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/Monsters/SE/RaiJu.cs b/Scripts/Mobiles/Monsters/SE/RaiJu.cs index 4f2941f70..62be99714 100644 --- a/Scripts/Mobiles/Monsters/SE/RaiJu.cs +++ b/Scripts/Mobiles/Monsters/SE/RaiJu.cs @@ -6,7 +6,7 @@ namespace Server.Mobiles { public class RaiJu : BaseCreature { - private static Dictionary m_Table = new Dictionary(); + private static HashSet m_Table = new HashSet(); [Constructible] public RaiJu() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4) @@ -61,33 +61,28 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (0.1 > Utility.RandomDouble() && !IsStunned(defender)) - { - /* Lightning Fist - * Cliloc: 1070839 - * Effect: Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(884 715, 10)" ToLocation: "(884 715, 10)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False" - * Damage: 35-65, 100% energy, resistable - * Freezes for 4 seconds - * Effect cannot stack - */ + if (0.1 <= Utility.RandomDouble() || m_Table.Contains(defender)) + return; - defender.FixedEffect(0x37B9, 10, 5); - defender.SendLocalizedMessage(1070839); // The creature attacks with stunning force! + /* Lightning Fist + * Cliloc: 1070839 + * Effect: Type: "3" From: "0x57D4F5B" To: "0x0" ItemId: "0x37B9" ItemIdName: "glow" FromLocation: "(884 715, 10)" ToLocation: "(884 715, 10)" Speed: "10" Duration: "5" FixedDirection: "True" Explode: "False" + * Damage: 35-65, 100% energy, resistable + * Freezes for 4 seconds + * Effect cannot stack + */ - // This should be done in place of the normal attack damage. - //AOS.Damage( defender, this, Utility.RandomMinMax( 35, 65 ), 0, 0, 0, 0, 100 ); + defender.FixedEffect(0x37B9, 10, 5); + defender.SendLocalizedMessage(1070839); // The creature attacks with stunning force! - defender.Frozen = true; + // This should be done in place of the normal attack damage. + //AOS.Damage( defender, this, Utility.RandomMinMax( 35, 65 ), 0, 0, 0, 0, 100 ); - ExpireTimer timer = new ExpireTimer(defender, TimeSpan.FromSeconds(4.0)); - timer.Start(); - m_Table[defender] = timer; - } - } + defender.Frozen = true; - public bool IsStunned(Mobile m) - { - return m_Table.ContainsKey(m); + ExpireTimer timer = new ExpireTimer(defender, TimeSpan.FromSeconds(4.0)); + timer.Start(); + m_Table.Add(defender); } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/Monsters/SE/RuneBeetle.cs b/Scripts/Mobiles/Monsters/SE/RuneBeetle.cs index 7acfd4c4d..9466d4074 100644 --- a/Scripts/Mobiles/Monsters/SE/RuneBeetle.cs +++ b/Scripts/Mobiles/Monsters/SE/RuneBeetle.cs @@ -138,77 +138,75 @@ namespace Server.Mobiles { base.OnGaveMeleeAttack(defender); - if (0.05 > Utility.RandomDouble()) + if (0.05 <= Utility.RandomDouble()) + return; + + /* Rune Corruption + * Start cliloc: 1070846 "The creature magically corrupts your armor!" + * Effect: All resistances -70 (lowest 0) for 5 seconds + * End ASCII: "The corruption of your armor has worn off" + */ + + if (m_Table.TryGetValue(defender, out ExpireTimer timer)) { - /* Rune Corruption - * Start cliloc: 1070846 "The creature magically corrupts your armor!" - * Effect: All resistances -70 (lowest 0) for 5 seconds - * End ASCII: "The corruption of your armor has worn off" - */ - - ExpireTimer timer = m_Table[defender]; - - if (timer != null) - { - timer.DoExpire(); - defender.SendLocalizedMessage(1070845); // The creature continues to corrupt your armor! - } - else - { - defender.SendLocalizedMessage(1070846); // The creature magically corrupts your armor! - } - - List mods = new List(); - - if (Core.ML) - { - if (defender.PhysicalResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Physical, -(defender.PhysicalResistance / 2))); - - if (defender.FireResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Fire, -(defender.FireResistance / 2))); - - if (defender.ColdResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Cold, -(defender.ColdResistance / 2))); - - if (defender.PoisonResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Poison, -(defender.PoisonResistance / 2))); - - if (defender.EnergyResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Energy, -(defender.EnergyResistance / 2))); - } - else - { - if (defender.PhysicalResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Physical, - defender.PhysicalResistance > 70 ? -70 : -defender.PhysicalResistance)); - - if (defender.FireResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Fire, - defender.FireResistance > 70 ? -70 : -defender.FireResistance)); - - if (defender.ColdResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Cold, - defender.ColdResistance > 70 ? -70 : -defender.ColdResistance)); - - if (defender.PoisonResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Poison, - defender.PoisonResistance > 70 ? -70 : -defender.PoisonResistance)); - - if (defender.EnergyResistance > 0) - mods.Add(new ResistanceMod(ResistanceType.Energy, - defender.EnergyResistance > 70 ? -70 : -defender.EnergyResistance)); - } - - for (int i = 0; i < mods.Count; ++i) - defender.AddResistanceMod(mods[i]); - - defender.FixedEffect(0x37B9, 10, 5); - - timer = new ExpireTimer(defender, mods, TimeSpan.FromSeconds(5.0)); - timer.Start(); - m_Table[defender] = timer; + timer.DoExpire(); + defender.SendLocalizedMessage(1070845); // The creature continues to corrupt your armor! } + else + { + defender.SendLocalizedMessage(1070846); // The creature magically corrupts your armor! + } + + List mods = new List(); + + if (Core.ML) + { + if (defender.PhysicalResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Physical, -(defender.PhysicalResistance / 2))); + + if (defender.FireResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Fire, -(defender.FireResistance / 2))); + + if (defender.ColdResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Cold, -(defender.ColdResistance / 2))); + + if (defender.PoisonResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Poison, -(defender.PoisonResistance / 2))); + + if (defender.EnergyResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Energy, -(defender.EnergyResistance / 2))); + } + else + { + if (defender.PhysicalResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Physical, + defender.PhysicalResistance > 70 ? -70 : -defender.PhysicalResistance)); + + if (defender.FireResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Fire, + defender.FireResistance > 70 ? -70 : -defender.FireResistance)); + + if (defender.ColdResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Cold, + defender.ColdResistance > 70 ? -70 : -defender.ColdResistance)); + + if (defender.PoisonResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Poison, + defender.PoisonResistance > 70 ? -70 : -defender.PoisonResistance)); + + if (defender.EnergyResistance > 0) + mods.Add(new ResistanceMod(ResistanceType.Energy, + defender.EnergyResistance > 70 ? -70 : -defender.EnergyResistance)); + } + + for (int i = 0; i < mods.Count; ++i) + defender.AddResistanceMod(mods[i]); + + defender.FixedEffect(0x37B9, 10, 5); + + timer = new ExpireTimer(defender, mods, TimeSpan.FromSeconds(5.0)); + timer.Start(); + m_Table[defender] = timer; } public override void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/Monsters/SE/TsukiWolf.cs b/Scripts/Mobiles/Monsters/SE/TsukiWolf.cs index 3d17802f3..f8eb7706f 100644 --- a/Scripts/Mobiles/Monsters/SE/TsukiWolf.cs +++ b/Scripts/Mobiles/Monsters/SE/TsukiWolf.cs @@ -103,9 +103,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 @@ -113,22 +114,19 @@ namespace Server.Mobiles * End cliloc: 1070824 */ - 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 (m_Table.TryGetValue(defender, out ExpireTimer timer)) + { + 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 void Serialize(GenericWriter writer) diff --git a/Scripts/Mobiles/PlayerMobile.cs b/Scripts/Mobiles/PlayerMobile.cs index 80daf3b8f..f1ecc1494 100644 --- a/Scripts/Mobiles/PlayerMobile.cs +++ b/Scripts/Mobiles/PlayerMobile.cs @@ -2139,12 +2139,10 @@ namespace Server.Mobiles if (obj == null || m_AntiMacroTable == null || AccessLevel != AccessLevel.Player) return true; - Dictionary tbl = m_AntiMacroTable[skill]; - if (tbl == null) + if (!m_AntiMacroTable.TryGetValue(skill, out Dictionary tbl)) m_AntiMacroTable[skill] = tbl = new Dictionary(); - CountAndTimeStamp count = tbl[obj]; - if (count != null) + if (tbl.TryGetValue(obj, out CountAndTimeStamp count)) { if (count.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow) { @@ -4738,10 +4736,8 @@ namespace Server.Mobiles public virtual bool HasRecipe(int recipeID) { - if (m_AcquiredRecipes != null && m_AcquiredRecipes.ContainsKey(recipeID)) - return m_AcquiredRecipes[recipeID]; - - return false; + m_AcquiredRecipes?.TryGetValue(recipeID, out bool value); + return value; } public virtual void AcquireRecipe(Recipe r) @@ -4764,16 +4760,7 @@ namespace Server.Mobiles } [CommandProperty(AccessLevel.GameMaster)] - public int KnownRecipes - { - get - { - if (m_AcquiredRecipes == null) - return 0; - - return m_AcquiredRecipes.Count; - } - } + public int KnownRecipes => m_AcquiredRecipes?.Count ?? 0; #endregion @@ -4784,11 +4771,9 @@ namespace Server.Mobiles if (!BuffInfo.Enabled || m_BuffTable == null) return; - NetState state = NetState; - - if (state != null && state.BuffIcon) + if (NetState?.BuffIcon == true) foreach (BuffInfo info in m_BuffTable.Values) - state.Send(new AddBuffPacket(this, info)); + NetState.Send(new AddBuffPacket(this, info)); } private Dictionary m_BuffTable; @@ -4805,9 +4790,8 @@ namespace Server.Mobiles m_BuffTable.Add(b.ID, b); - NetState state = NetState; - - if (state != null && state.BuffIcon) state.Send(new AddBuffPacket(this, b)); + if (NetState?.BuffIcon == true) + NetState.Send(new AddBuffPacket(this, b)); } public void RemoveBuff(BuffInfo b) @@ -4830,9 +4814,8 @@ namespace Server.Mobiles m_BuffTable.Remove(b); - NetState state = NetState; - - if (state != null && state.BuffIcon) state.Send(new RemoveBuffPacket(this, b)); + if (NetState?.BuffIcon == true) + NetState.Send(new RemoveBuffPacket(this, b)); if (m_BuffTable.Count <= 0) m_BuffTable = null; diff --git a/Scripts/Mobiles/Special/Harrower.cs b/Scripts/Mobiles/Special/Harrower.cs index 0d0e9d33c..57add926e 100644 --- a/Scripts/Mobiles/Special/Harrower.cs +++ b/Scripts/Mobiles/Special/Harrower.cs @@ -391,10 +391,7 @@ namespace Server.Mobiles if (from == null || !from.Player) return; - if (m_DamageEntries.ContainsKey(from)) - m_DamageEntries[from] += amount; - else - m_DamageEntries.Add(from, amount); + m_DamageEntries[from] = amount + (m_DamageEntries.TryGetValue(from, out int value) ? value : 0); from.SendMessage($"Total Damage: {m_DamageEntries[from]}"); } diff --git a/Scripts/Mobiles/Townfolk/BaseEscortable.cs b/Scripts/Mobiles/Townfolk/BaseEscortable.cs index e73cdccc6..5a86f1420 100644 --- a/Scripts/Mobiles/Townfolk/BaseEscortable.cs +++ b/Scripts/Mobiles/Townfolk/BaseEscortable.cs @@ -258,14 +258,10 @@ namespace Server.Mobiles if (dest == null) return false; - Mobile escorter = GetEscorter(); - - if (escorter != null || !m.Alive) + if (GetEscorter() != null || !m.Alive) return false; - BaseEscortable escortable = EscortTable[m]; - - if (escortable?.Deleted == false && escortable.GetEscorter() == m) + if (EscortTable.TryGetValue(m, out BaseEscortable escortable) && escortable?.Deleted == false && escortable.GetEscorter() == m) { Say("I see you already have an escort."); return false; @@ -693,7 +689,8 @@ namespace Server.Mobiles if (name == null || m_Table == null) return null; - return m_Table[name]; + m_Table.TryGetValue(name, out EscortDestinationInfo info); + return info; } } diff --git a/Scripts/Mobiles/Vendors/BaseVendor.cs b/Scripts/Mobiles/Vendors/BaseVendor.cs index dbe765f30..c9b61d3f1 100644 --- a/Scripts/Mobiles/Vendors/BaseVendor.cs +++ b/Scripts/Mobiles/Vendors/BaseVendor.cs @@ -924,27 +924,25 @@ namespace Server.Mobiles IShopSellInfo[] info = GetSellInfo(); - Dictionary table = new Dictionary(); + List list = new List(); foreach (IShopSellInfo ssi in info) { - Item[] items = pack.FindItemsByType(ssi.Types); - - foreach (Item item in items) + foreach (Item item in pack.FindItemsByType(ssi.Types)) { 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)); + list.Add(new SellItemState(item, ssi.GetSellPriceFor(item), ssi.GetNameFor(item))); } } - if (table.Count > 0) + if (list.Count > 0) { SendPacksTo(from); - from.Send(new VendorSellList(this, table.Values)); + from.Send(new VendorSellList(this, list)); } else { diff --git a/Scripts/Mobiles/Vendors/GenericSell.cs b/Scripts/Mobiles/Vendors/GenericSell.cs index 29550e23d..be9c6b504 100644 --- a/Scripts/Mobiles/Vendors/GenericSell.cs +++ b/Scripts/Mobiles/Vendors/GenericSell.cs @@ -9,10 +9,6 @@ namespace Server.Mobiles private Dictionary m_Table = new Dictionary(); private Type[] m_Types; - public GenericSellInfo() - { - } - public void Add( Type type, int price ) { m_Table[type] = price; diff --git a/Scripts/Mobiles/Vendors/PlayerVendor.cs b/Scripts/Mobiles/Vendors/PlayerVendor.cs index cfbe0d313..272df6a94 100644 --- a/Scripts/Mobiles/Vendors/PlayerVendor.cs +++ b/Scripts/Mobiles/Vendors/PlayerVendor.cs @@ -351,7 +351,8 @@ namespace Server.Mobiles if (BaseHouse.NewVendorSystem) return ChargePerRealWorldDay / 12; long total = 0; - foreach (VendorItem vi in m_SellItems.Values) total += vi.Price; + foreach (VendorItem vi in m_SellItems.Values) + total += vi.Price; total -= 500; @@ -369,7 +370,8 @@ namespace Server.Mobiles if (BaseHouse.NewVendorSystem) { long total = 0; - foreach (VendorItem vi in m_SellItems.Values) total += vi.Price; + foreach (VendorItem vi in m_SellItems.Values) + total += vi.Price; return (int)(60 + total / 500 * 3); } diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index 6047a0dea..cb09944da 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -71,9 +71,7 @@ namespace Server.Multis if (owner != null) { - m_Table.TryGetValue(owner, out List list); - - if (list == null) + if (!m_Table.TryGetValue(owner, out List list)) m_Table[owner] = list = new List(); list.Add(this); @@ -276,9 +274,7 @@ namespace Server.Multis { if (m_Owner != null) { - m_Table.TryGetValue(m_Owner, out List list); - - if (list == null) + if (!m_Table.TryGetValue(m_Owner, out List list)) m_Table[m_Owner] = list = new List(); list.Remove(this); @@ -289,9 +285,7 @@ namespace Server.Multis if (m_Owner != null) { - m_Table.TryGetValue(m_Owner, out List list); - - if (list == null) + if (!m_Table.TryGetValue(m_Owner, out List list)) m_Table[m_Owner] = list = new List(); list.Add(this); @@ -1111,9 +1105,7 @@ namespace Server.Multis if (m != null) { - m_Table.TryGetValue(m, out List exists); - - if (exists != null) + if (m_Table.TryGetValue(m, out List exists)) for (int i = 0; i < exists.Count; ++i) { BaseHouse house = exists[i]; @@ -2616,9 +2608,7 @@ namespace Server.Multis if (m_Owner != null) { - m_Table.TryGetValue(m_Owner, out List list); - - if (list == null) + if (!m_Table.TryGetValue(m_Owner, out List list)) m_Table[m_Owner] = list = new List(); list.Add(this); @@ -2745,9 +2735,7 @@ namespace Server.Multis if (m_Owner != null) { - m_Table.TryGetValue(m_Owner, out List list); - - if (list == null) + if (!m_Table.TryGetValue(m_Owner, out List list)) m_Table[m_Owner] = list = new List(); list.Remove(this); @@ -2888,12 +2876,7 @@ namespace Server.Multis public static bool HasHouse(Mobile m) { - if (m == null) - return false; - - m_Table.TryGetValue(m, out List list); - - if (list == null) + if (m == null || !m_Table.TryGetValue(m, out List list)) return false; for (int i = 0; i < list.Count; ++i) diff --git a/Scripts/Multis/DynamicDecay.cs b/Scripts/Multis/DynamicDecay.cs index 072c4c99d..031a774d7 100644 --- a/Scripts/Multis/DynamicDecay.cs +++ b/Scripts/Multis/DynamicDecay.cs @@ -23,12 +23,7 @@ namespace Server.Multis public static void Register(DecayLevel level, TimeSpan min, TimeSpan max) { - DecayStageInfo info = new DecayStageInfo(min, max); - - if (m_Stages.ContainsKey(level)) - m_Stages[level] = info; - else - m_Stages.Add(level, info); + m_Stages[level] = new DecayStageInfo(min, max); } public static bool Decays(DecayLevel level) @@ -38,10 +33,9 @@ namespace Server.Multis public static TimeSpan GetRandomDuration(DecayLevel level) { - if (!m_Stages.ContainsKey(level)) + if (!m_Stages.TryGetValue(level, out DecayStageInfo info)) return TimeSpan.Zero; - DecayStageInfo info = m_Stages[level]; long min = info.MinDuration.Ticks; long max = info.MaxDuration.Ticks; @@ -61,4 +55,4 @@ namespace Server.Multis public TimeSpan MaxDuration{ get; } } -} \ No newline at end of file +} diff --git a/Scripts/Multis/HousePlacementTool.cs b/Scripts/Multis/HousePlacementTool.cs index f447a75f6..03546c7de 100644 --- a/Scripts/Multis/HousePlacementTool.cs +++ b/Scripts/Multis/HousePlacementTool.cs @@ -803,7 +803,7 @@ namespace Server.Items public static HousePlacementEntry Find(BaseHouse house) { - object obj = m_Table[house.GetType()]; + m_Table.TryGetValue(house.GetType(), out object obj); if (obj is HousePlacementEntry entry) return entry; @@ -825,9 +825,7 @@ namespace Server.Items { HousePlacementEntry e = entries[i]; - object obj = m_Table[e.Type]; - - if (obj == null) + if (!m_Table.TryGetValue(e.Type, out object obj)) { m_Table[e.Type] = e; } diff --git a/Scripts/Regions/GuardedRegion.cs b/Scripts/Regions/GuardedRegion.cs index 8fe734488..7334a55b3 100644 --- a/Scripts/Regions/GuardedRegion.cs +++ b/Scripts/Regions/GuardedRegion.cs @@ -258,58 +258,53 @@ namespace Server.Regions public void CheckGuardCandidate(Mobile m) { - if (IsDisabled()) + if (IsDisabled() || !IsGuardCandidate(m)) return; - if (IsGuardCandidate(m)) + if (!m_GuardCandidates.TryGetValue(m, out GuardTimer timer)) { - m_GuardCandidates.TryGetValue(m, out GuardTimer timer); + timer = new GuardTimer(m, m_GuardCandidates); + timer.Start(); - if (timer == null) - { - timer = new GuardTimer(m, m_GuardCandidates); - timer.Start(); + m_GuardCandidates[m] = timer; + m.SendLocalizedMessage(502275); // Guards can now be called on you! - m_GuardCandidates[m] = timer; - m.SendLocalizedMessage(502275); // Guards can now be called on you! + Map map = m.Map; - Map map = m.Map; + if (map == null) + return; - if (map != null) + Mobile fakeCall = null; + double prio = 0.0; + + foreach (Mobile v in m.GetMobilesInRange(8)) + if (!v.Player && v != m && !IsGuardCandidate(v) && + ((v as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this))) { - Mobile fakeCall = null; - double prio = 0.0; + double dist = m.GetDistanceToSqrt(v); - foreach (Mobile v in m.GetMobilesInRange(8)) - if (!v.Player && v != m && !IsGuardCandidate(v) && - ((v as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this))) - { - double dist = m.GetDistanceToSqrt(v); - - if (fakeCall == null || dist < prio) - { - fakeCall = v; - prio = dist; - } - } - - if (fakeCall != null) + if (fakeCall == null || dist < prio) { - fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042, - 1013043, 1013052)); - MakeGuard(m); - timer.Stop(); - m_GuardCandidates.Remove(m); - m.SendLocalizedMessage(502276); // Guards can no longer be called on you. + fakeCall = v; + prio = dist; } } - } - else + + if (fakeCall != null) { + fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042, + 1013043, 1013052)); + MakeGuard(m); timer.Stop(); - timer.Start(); + m_GuardCandidates.Remove(m); + m.SendLocalizedMessage(502276); // Guards can no longer be called on you. } } + else + { + timer.Stop(); + timer.Start(); + } } public void CallGuards(Point3D p) @@ -323,9 +318,7 @@ namespace Server.Regions if (IsGuardCandidate(m) && (!AllowReds && m.Kills >= 5 && m.Region.IsPartOf(this) || m_GuardCandidates.ContainsKey(m))) { - m_GuardCandidates.TryGetValue(m, out GuardTimer timer); - - if (timer != null) + if (m_GuardCandidates.TryGetValue(m, out GuardTimer timer)) { timer.Stop(); m_GuardCandidates.Remove(m); @@ -371,4 +364,4 @@ namespace Server.Regions } } } -} \ No newline at end of file +} diff --git a/Scripts/Regions/Spawning/SpawnDefinition.cs b/Scripts/Regions/Spawning/SpawnDefinition.cs index 57373176e..972e1e3f2 100644 --- a/Scripts/Regions/Spawning/SpawnDefinition.cs +++ b/Scripts/Regions/Spawning/SpawnDefinition.cs @@ -36,9 +36,7 @@ namespace Server.Regions if (!Region.ReadString(xml, "name", ref group)) return null; - SpawnDefinition def = SpawnGroup.Table[@group]; - - if (def == null) + if (!SpawnGroup.Table.TryGetValue(group, out SpawnGroup def)) { Console.WriteLine("Could not find group '{0}' in a SpawnDefinition", group); return null; @@ -152,9 +150,7 @@ namespace Server.Regions public static SpawnMobile Get(Type type) { - SpawnMobile sm = m_Table[type]; - - if (sm == null) + if (!m_Table.TryGetValue(type, out SpawnMobile sm)) m_Table[type] = sm = new SpawnMobile(type); return sm; @@ -221,9 +217,7 @@ namespace Server.Regions public static SpawnItem Get(Type type) { - SpawnItem si = m_Table[type]; - - if (si == null) + if (!m_Table.TryGetValue(type, out SpawnItem si)) m_Table[type] = si = new SpawnItem(type); return si; diff --git a/Scripts/Regions/Spawning/SpawnEntry.cs b/Scripts/Regions/Spawning/SpawnEntry.cs index c81ca0f9f..ca82a9329 100644 --- a/Scripts/Regions/Spawning/SpawnEntry.cs +++ b/Scripts/Regions/Spawning/SpawnEntry.cs @@ -209,7 +209,7 @@ namespace Server.Regions m_SpawnTimer = null; } - if (Table[ID] == this) + if (Table.TryGetValue(ID, out SpawnEntry entry) && entry == this) Table.Remove(ID); } @@ -310,6 +310,7 @@ namespace Server.Regions Mobile from = args.Mobile; Region reg; + if (args.Length == 0) { reg = from.Region; @@ -317,29 +318,26 @@ namespace Server.Regions else { string name = args.GetString(0); - //reg = if (!from.Map.Regions.TryGetValue( name, out (Region) from.Map.Regions[name] )) + if (!from.Map.Regions.TryGetValue(name, out reg)) { from.SendMessage("Could not find region '{0}'.", name); return null; } } - BaseRegion br = reg as BaseRegion; + if (reg is BaseRegion br && br.Spawns != null) + return br; - if (br?.Spawns == null) - { - from.SendMessage("There are no spawners in region '{0}'.", reg); - return null; - } - - return br; + from.SendMessage("There are no spawners in region '{0}'.", reg); + return null; } [Usage("RespawnAllRegions")] [Description("Respawns all regions and sets the spawners as running.")] private static void RespawnAllRegions_OnCommand(CommandEventArgs args) { - foreach (SpawnEntry entry in Table.Values) entry.Respawn(); + foreach (SpawnEntry entry in Table.Values) + entry.Respawn(); args.Mobile.SendMessage("All regions have respawned."); } @@ -363,7 +361,8 @@ namespace Server.Regions [Description("Deletes all spawned objects of every regions and sets the spawners as not running.")] private static void DelAllRegionSpawns_OnCommand(CommandEventArgs args) { - foreach (SpawnEntry entry in Table.Values) entry.DeleteSpawnedObjects(); + foreach (SpawnEntry entry in Table.Values) + entry.DeleteSpawnedObjects(); args.Mobile.SendMessage("All region spawned objects have been deleted."); } @@ -388,7 +387,8 @@ namespace Server.Regions [Description("Sets the region spawners of all regions as running.")] private static void StartAllRegionSpawns_OnCommand(CommandEventArgs args) { - foreach (SpawnEntry entry in Table.Values) entry.Start(); + foreach (SpawnEntry entry in Table.Values) + entry.Start(); args.Mobile.SendMessage("All region spawners have started."); } @@ -412,7 +412,8 @@ namespace Server.Regions [Description("Sets the region spawners of all regions as not running.")] private static void StopAllRegionSpawns_OnCommand(CommandEventArgs args) { - foreach (SpawnEntry entry in Table.Values) entry.Stop(); + foreach (SpawnEntry entry in Table.Values) + entry.Stop(); args.Mobile.SendMessage("All region spawners have stopped."); } diff --git a/Scripts/Scripts.csproj b/Scripts/Scripts.csproj index e4e45e324..123a83fc2 100644 --- a/Scripts/Scripts.csproj +++ b/Scripts/Scripts.csproj @@ -208,7 +208,6 @@ - diff --git a/Scripts/Skills/AnimalTaming.cs b/Scripts/Skills/AnimalTaming.cs index 6d5decde9..a6a9782f7 100644 --- a/Scripts/Skills/AnimalTaming.cs +++ b/Scripts/Skills/AnimalTaming.cs @@ -12,7 +12,7 @@ namespace Server.SkillHandlers { public class AnimalTaming { - private static Dictionary m_BeingTamed = new Dictionary(); + private static HashSet m_BeingTamed = new HashSet(); public static bool DisableMessage{ get; set; } @@ -36,12 +36,10 @@ namespace Server.SkillHandlers public static bool CheckMastery(Mobile tamer, BaseCreature creature) { - 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; - - return false; + return SummonFamiliarSpell.Table.TryGetValue(tamer, out BaseCreature bc) && bc is DarkWolfFamiliar familiar && + !familiar.Deleted && (creature is DireWolf || creature is GreyWolf || creature is TimberWolf || + creature is WhiteWolf || + creature is BakeKitsune); } public static bool MustBeSubdued(BaseCreature bc) @@ -194,7 +192,7 @@ namespace Server.SkillHandlers } } - if (m_BeingTamed.ContainsKey(creature)) + if (m_BeingTamed.Contains(creature)) { creature.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 502802, from.NetState); // Someone else is already taming this. @@ -222,7 +220,7 @@ namespace Server.SkillHandlers } else { - m_BeingTamed[creature] = from; + m_BeingTamed.Add(creature); from.LocalOverheadMessage(MessageType.Emote, 0x59, 1010597); // You start to tame the creature. diff --git a/Scripts/Skills/Discordance.cs b/Scripts/Skills/Discordance.cs index d5bd4bd27..b92eb30e9 100644 --- a/Scripts/Skills/Discordance.cs +++ b/Scripts/Skills/Discordance.cs @@ -35,9 +35,7 @@ namespace Server.SkillHandlers public static bool GetEffect(Mobile targ, ref int effect) { - DiscordanceInfo info = m_Table[targ]; - - if (info == null) + if (!m_Table.TryGetValue(targ, out DiscordanceInfo info)) return false; effect = info.m_Effect; diff --git a/Scripts/Skills/Inscribe.cs b/Scripts/Skills/Inscribe.cs index 14f6956e0..61d7aaf87 100644 --- a/Scripts/Skills/Inscribe.cs +++ b/Scripts/Skills/Inscribe.cs @@ -43,9 +43,9 @@ namespace Server.SkillHandlers public static bool IsEmpty(BaseBook book) { foreach (BookPageInfo page in book.Pages) - foreach (string line in page.Lines) - if (line.Trim().Length != 0) - return false; + foreach (string line in page.Lines) + if (line.Trim().Length != 0) + return false; return true; } @@ -170,4 +170,4 @@ namespace Server.SkillHandlers } } } -} \ No newline at end of file +} diff --git a/Scripts/Skills/Tracking.cs b/Scripts/Skills/Tracking.cs index 1324d2e6b..22e2d60ef 100644 --- a/Scripts/Skills/Tracking.cs +++ b/Scripts/Skills/Tracking.cs @@ -35,9 +35,9 @@ namespace Server.SkillHandlers public static double GetStalkingBonus(Mobile tracker, Mobile target) { - m_Table.TryGetValue(tracker, out TrackingInfo info); + ; - if (info == null || info.m_Target != target || info.m_Map != target.Map) + if (!m_Table.TryGetValue(tracker, out TrackingInfo info) || info.m_Target != target || info.m_Map != target.Map) return 0.0; int xDelta = info.m_Location.X - target.X; @@ -47,10 +47,7 @@ namespace Server.SkillHandlers m_Table.Remove(tracker); //Reset as of Pub 40, counting it as bug for Core.SE. - if (Core.ML) - return Math.Min(bonus, 10 + tracker.Skills.Tracking.Value / 10); - - return bonus; + return Core.ML ? Math.Min(bonus, 10 + tracker.Skills.Tracking.Value / 10) : bonus; } @@ -399,4 +396,4 @@ namespace Server.SkillHandlers } } } -} \ No newline at end of file +} diff --git a/Scripts/SpecialSystems/Engines/PreventInaccess.cs b/Scripts/SpecialSystems/Engines/PreventInaccess.cs index 231ef909a..377b05d32 100644 --- a/Scripts/SpecialSystems/Engines/PreventInaccess.cs +++ b/Scripts/SpecialSystems/Engines/PreventInaccess.cs @@ -54,9 +54,8 @@ namespace Server.Misc from.Location = dest.Location; from.Map = dest.Map; } - else if (m_MoveHistory.ContainsKey(from)) + else if (m_MoveHistory.TryGetValue(from, out LocationInfo orig)) { - LocationInfo orig = m_MoveHistory[from]; from.SendMessage("Your character was moved from {0} ({1}) due to a detected client crash.", orig.Location, orig.Map); @@ -87,4 +86,4 @@ namespace Server.Misc public Map Map{ get; } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Base/SpecialMove.cs b/Scripts/Spells/Base/SpecialMove.cs index 3c6beb11f..594b02ec3 100644 --- a/Scripts/Spells/Base/SpecialMove.cs +++ b/Scripts/Spells/Base/SpecialMove.cs @@ -219,9 +219,7 @@ namespace Server.Spells return null; } - Table.TryGetValue(m, out SpecialMove move); - - if (move != null && move.ValidatesDuringHit && !move.Validate(m)) + if (Table.TryGetValue(m, out SpecialMove move) && move.ValidatesDuringHit && !move.Validate(m)) { ClearCurrentMove(m); return null; @@ -272,9 +270,9 @@ namespace Server.Spells public static void ClearCurrentMove(Mobile m) { - Table.TryGetValue(m, out SpecialMove move); + ; - if (move != null) + if (Table.TryGetValue(m, out SpecialMove move)) { move.OnClearMove(m); @@ -306,17 +304,7 @@ namespace Server.Spells private static SpecialMoveContext GetContext(Mobile m) { - return m_PlayersTable.ContainsKey(m) ? m_PlayersTable[m] : null; - } - - public static bool GetContext(Mobile m, Type type) - { - m_PlayersTable.TryGetValue(m, out SpecialMoveContext context); - - if (context == null) - return false; - - return context.Type == type; + return m_PlayersTable.TryGetValue(m, out SpecialMoveContext context) ? context : null; } private class SpecialMoveTimer : Timer @@ -349,4 +337,4 @@ namespace Server.Spells public Type Type{ get; } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Base/Spell.cs b/Scripts/Spells/Base/Spell.cs index 5e413fb3e..eec45b17a 100644 --- a/Scripts/Spells/Base/Spell.cs +++ b/Scripts/Spells/Base/Spell.cs @@ -84,16 +84,9 @@ namespace Server.Spells public virtual void OnCasterHurt() { //Confirm: Monsters and pets cannot be disturbed. - if (!Caster.Player) - return; - - if (IsCasting) - { - double d = ProtectionSpell.Registry[Caster]; - - if (d <= Utility.RandomDouble() * 100.0) - Disturb(DisturbType.Hurt, false, true); - } + if (Caster.Player && IsCasting && ProtectionSpell.Registry.TryGetValue(Caster, out double d) && + d <= Utility.RandomDouble() * 100.0) + Disturb(DisturbType.Hurt, false, true); } public virtual void OnCasterKilled() @@ -144,20 +137,15 @@ namespace Server.Spells return; //Sanity if (!m_ContextTable.TryGetValue(GetType(), out DelayedDamageContextWrapper contexts)) - { - contexts = new DelayedDamageContextWrapper(); - m_ContextTable.Add(GetType(), contexts); - } + m_ContextTable[GetType()] = contexts = new DelayedDamageContextWrapper(); contexts.Add(m, t); } public void RemoveDelayedDamageContext(Mobile m) { - if (!m_ContextTable.TryGetValue(GetType(), out DelayedDamageContextWrapper contexts)) - return; - - contexts.Remove(m); + if (m_ContextTable.TryGetValue(GetType(), out DelayedDamageContextWrapper contexts)) + contexts.Remove(m); } public void HarmfulSpell(Mobile m) diff --git a/Scripts/Spells/Base/SpellHelper.cs b/Scripts/Spells/Base/SpellHelper.cs index b62e79342..3f3f7242a 100644 --- a/Scripts/Spells/Base/SpellHelper.cs +++ b/Scripts/Spells/Base/SpellHelper.cs @@ -1041,7 +1041,7 @@ namespace Server.Spells if (context == null) /* cleanup */ return; - + if (context.Type == typeof(WraithFormSpell)) { int wraithLeech = @@ -1137,7 +1137,7 @@ namespace Server.Spells { BaseCreature bcFrom = m_From as BaseCreature; BaseCreature bcTarg = m_Target as BaseCreature; - + if (bcFrom != null && m_Target != null) bcFrom.AlterSpellDamageTo(m_Target, ref m_Damage); @@ -1299,24 +1299,24 @@ namespace Server.Spells public static void RemoveContext(Mobile m, TransformContext context, bool resetGraphics) { - if (m_Table.ContainsKey(m)) + if (!m_Table.ContainsKey(m)) + return; + + m_Table.Remove(m); + + List mods = context.Mods; + + for (int i = 0; i < mods.Count; ++i) + m.RemoveResistanceMod(mods[i]); + + if (resetGraphics) { - m_Table.Remove(m); - - List mods = context.Mods; - - for (int i = 0; i < mods.Count; ++i) - m.RemoveResistanceMod(mods[i]); - - if (resetGraphics) - { - m.HueMod = -1; - m.BodyMod = 0; - } - - context.Timer.Stop(); - context.Spell.RemoveEffect(m); + m.HueMod = -1; + m.BodyMod = 0; } + + context.Timer.Stop(); + context.Spell.RemoveEffect(m); } public static TransformContext GetContext(Mobile m) @@ -1406,4 +1406,4 @@ namespace Server.Spells } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Base/SpellRegistry.cs b/Scripts/Spells/Base/SpellRegistry.cs index 42d968b2e..ab2ad4630 100644 --- a/Scripts/Spells/Base/SpellRegistry.cs +++ b/Scripts/Spells/Base/SpellRegistry.cs @@ -70,10 +70,7 @@ namespace Server.Spells public static int GetRegistryNumber(Type type) { - if (m_IDsFromTypes.ContainsKey(type)) - return m_IDsFromTypes[type]; - - return -1; + return m_IDsFromTypes.TryGetValue(type, out int value) ? value : -1; } public static void Register(int spellID, Type type) @@ -99,6 +96,7 @@ namespace Server.Spells } catch { + // ignored } if (spm != null) @@ -113,10 +111,11 @@ namespace Server.Spells Type t = m_Types[spellID]; - if (t == null || !t.IsSubclassOf(typeof(SpecialMove)) || !SpecialMoves.ContainsKey(spellID)) + if (t == null || !t.IsSubclassOf(typeof(SpecialMove))) return null; - return SpecialMoves[spellID]; + SpecialMoves.TryGetValue(spellID, out SpecialMove move); + return move; } public static Spell NewSpell(int spellID, Mobile caster, Item scroll) @@ -167,4 +166,4 @@ namespace Server.Spells return null; } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Bushido/Confidence.cs b/Scripts/Spells/Bushido/Confidence.cs index 4520dfb88..138285613 100644 --- a/Scripts/Spells/Bushido/Confidence.cs +++ b/Scripts/Spells/Bushido/Confidence.cs @@ -56,7 +56,7 @@ namespace Server.Spells.Bushido public static void BeginConfidence(Mobile m) { - Timer timer = m_Table[m]; + m_Table.TryGetValue(m, out Timer timer); timer?.Stop(); m_Table[m] = timer = new InternalTimer(m); @@ -65,10 +65,11 @@ namespace Server.Spells.Bushido public static void EndConfidence(Mobile m) { - Timer timer = m_Table[m]; - timer?.Stop(); - - m_Table.Remove(m); + if (m_Table.TryGetValue(m, out Timer timer)) + { + timer.Stop(); + m_Table.Remove(m); + } OnEffectEnd(m, typeof(Confidence)); } @@ -80,7 +81,7 @@ namespace Server.Spells.Bushido public static void BeginRegenerating(Mobile m) { - Timer timer = m_RegenTable[m]; + m_RegenTable.TryGetValue(m, out Timer timer); timer?.Stop(); m_RegenTable[m] = timer = new RegenTimer(m); @@ -90,10 +91,11 @@ namespace Server.Spells.Bushido public static void StopRegenerating(Mobile m) { - Timer timer = m_RegenTable[m]; - timer?.Stop(); - - m_RegenTable.Remove(m); + if (m_RegenTable.TryGetValue(m, out Timer timer)) + { + timer.Stop(); + m_RegenTable.Remove(m); + } } private class InternalTimer : Timer diff --git a/Scripts/Spells/Bushido/CounterAttack.cs b/Scripts/Spells/Bushido/CounterAttack.cs index 281e0685b..9544647ad 100644 --- a/Scripts/Spells/Bushido/CounterAttack.cs +++ b/Scripts/Spells/Bushido/CounterAttack.cs @@ -70,7 +70,7 @@ namespace Server.Spells.Bushido public static void StartCountering(Mobile m) { - Timer timer = m_Table[m]; + m_Table.TryGetValue(m, out Timer timer); timer?.Stop(); m_Table[m] = timer = new InternalTimer(m); @@ -80,10 +80,11 @@ namespace Server.Spells.Bushido public static void StopCountering(Mobile m) { - Timer timer = m_Table[m]; - timer?.Stop(); - - m_Table.Remove(m); + if (m_Table.TryGetValue(m, out Timer timer)) + { + timer.Stop(); + m_Table.Remove(m); + } OnEffectEnd(m, typeof(CounterAttack)); } diff --git a/Scripts/Spells/Bushido/Evasion.cs b/Scripts/Spells/Bushido/Evasion.cs index a8952a7e6..50c8338d2 100644 --- a/Scripts/Spells/Bushido/Evasion.cs +++ b/Scripts/Spells/Bushido/Evasion.cs @@ -27,10 +27,7 @@ namespace Server.Spells.Bushido public override bool CheckCast() { - if (VerifyCast(Caster, true)) - return base.CheckCast(); - - return false; + return VerifyCast(Caster, true) && base.CheckCast(); } public static bool VerifyCast(Mobile Caster, bool messages) @@ -180,7 +177,7 @@ namespace Server.Spells.Bushido public static void BeginEvasion(Mobile m) { - Timer timer = m_Table[m]; + m_Table.TryGetValue(m, out Timer timer); timer?.Stop(); m_Table[m] = timer = new InternalTimer(m, GetEvadeDuration(m)); @@ -189,10 +186,11 @@ namespace Server.Spells.Bushido public static void EndEvasion(Mobile m) { - Timer timer = m_Table[m]; - timer?.Stop(); - - m_Table.Remove(m); + if (m_Table.TryGetValue(m, out Timer timer)) + { + timer.Stop(); + m_Table.Remove(m); + } OnEffectEnd(m, typeof(Evasion)); } diff --git a/Scripts/Spells/Bushido/HonorableExecution.cs b/Scripts/Spells/Bushido/HonorableExecution.cs index 5861f1de9..cb2efa475 100644 --- a/Scripts/Spells/Bushido/HonorableExecution.cs +++ b/Scripts/Spells/Bushido/HonorableExecution.cs @@ -29,9 +29,7 @@ namespace Server.Spells.Bushido ClearCurrentMove(attacker); - HonorableExecutionInfo info = m_Table[attacker]; - - if (info != null) + if (m_Table.TryGetValue(attacker, out HonorableExecutionInfo info)) { info.Clear(); info.m_Timer?.Stop(); @@ -79,29 +77,21 @@ namespace Server.Spells.Bushido public static int GetSwingBonus(Mobile target) { - if (!(m_Table[target] is HonorableExecutionInfo info)) - return 0; - - return info.m_SwingBonus; + return m_Table.TryGetValue(target, out HonorableExecutionInfo info) ? info.m_SwingBonus : 0; } public static bool IsUnderPenalty(Mobile target) { - if (!(m_Table[target] is HonorableExecutionInfo info)) - return false; - - return info.m_Penalty; + return m_Table.TryGetValue(target, out HonorableExecutionInfo info) && info.m_Penalty; } public static void RemovePenalty(Mobile target) { - if (!(m_Table[target] is HonorableExecutionInfo info) || !info.m_Penalty) + if (!m_Table.TryGetValue(target, out HonorableExecutionInfo info) || !info.m_Penalty) return; info.Clear(); - info.m_Timer?.Stop(); - m_Table.Remove(target); } diff --git a/Scripts/Spells/Chivalry/ConsecrateWeapon.cs b/Scripts/Spells/Chivalry/ConsecrateWeapon.cs index a97ea0fbb..fde82c008 100644 --- a/Scripts/Spells/Chivalry/ConsecrateWeapon.cs +++ b/Scripts/Spells/Chivalry/ConsecrateWeapon.cs @@ -78,7 +78,7 @@ namespace Server.Spells.Chivalry TimeSpan duration = TimeSpan.FromSeconds(seconds); - ExpireTimer timer = m_Table[weapon]; + m_Table.TryGetValue(weapon, out ExpireTimer timer); timer?.Stop(); weapon.Consecrated = true; diff --git a/Scripts/Spells/Chivalry/DivineFury.cs b/Scripts/Spells/Chivalry/DivineFury.cs index bd95f62aa..d732c0b79 100644 --- a/Scripts/Spells/Chivalry/DivineFury.cs +++ b/Scripts/Spells/Chivalry/DivineFury.cs @@ -37,7 +37,7 @@ namespace Server.Spells.Chivalry Caster.Stam = Caster.StamMax; - Timer timer = m_Table[Caster]; + m_Table.TryGetValue(Caster, out Timer timer); timer?.Stop(); int delay = ComputePowerValue(10); diff --git a/Scripts/Spells/Chivalry/EnemyOfOne.cs b/Scripts/Spells/Chivalry/EnemyOfOne.cs index ee429ae36..e1954a822 100644 --- a/Scripts/Spells/Chivalry/EnemyOfOne.cs +++ b/Scripts/Spells/Chivalry/EnemyOfOne.cs @@ -36,7 +36,7 @@ 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 timer = m_Table[Caster]; + m_Table.TryGetValue(Caster, out Timer timer); timer?.Stop(); double delay = (double)ComputePowerValue(1) / 60; diff --git a/Scripts/Spells/Fifth/Incognito.cs b/Scripts/Spells/Fifth/Incognito.cs index d6203c7d3..e03b8dd38 100644 --- a/Scripts/Spells/Fifth/Incognito.cs +++ b/Scripts/Spells/Fifth/Incognito.cs @@ -125,9 +125,7 @@ namespace Server.Spells.Fifth public static void StopTimer(Mobile m) { - Timer t = m_Timers[m]; - - if (t == null) + if (!m_Timers.TryGetValue(m, out InternalTimer t)) return; t.Stop(); @@ -156,18 +154,18 @@ namespace Server.Spells.Fifth protected override void OnTick() { - if (!m_Owner.CanBeginAction()) - { - (m_Owner as PlayerMobile)?.SetHairMods(-1, -1); + if (m_Owner.CanBeginAction()) + return; - m_Owner.BodyMod = 0; - m_Owner.HueMod = -1; - m_Owner.NameMod = null; - m_Owner.EndAction(); + (m_Owner as PlayerMobile)?.SetHairMods(-1, -1); - BaseArmor.ValidateMobile(m_Owner); - BaseClothing.ValidateMobile(m_Owner); - } + m_Owner.BodyMod = 0; + m_Owner.HueMod = -1; + m_Owner.NameMod = null; + m_Owner.EndAction(); + + BaseArmor.ValidateMobile(m_Owner); + BaseClothing.ValidateMobile(m_Owner); } } } diff --git a/Scripts/Spells/Fifth/MagicReflect.cs b/Scripts/Spells/Fifth/MagicReflect.cs index 99f95768b..3897b4ac5 100644 --- a/Scripts/Spells/Fifth/MagicReflect.cs +++ b/Scripts/Spells/Fifth/MagicReflect.cs @@ -57,9 +57,7 @@ namespace Server.Spells.Fifth { Mobile targ = Caster; - ResistanceMod[] mods = m_Table[targ]; - - if (mods == null) + if (!m_Table.TryGetValue(targ, out ResistanceMod[] mods)) { targ.PlaySound(0x1E9); targ.FixedParticles(0x375A, 10, 15, 5037, EffectLayer.Waist); @@ -116,7 +114,7 @@ namespace Server.Spells.Fifth if (Caster.BeginAction()) { int value = (int)(Caster.Skills.Magery.Value + Caster.Skills.Inscribe.Value); - value = (int)(8 + value / 200 * 7.0); //absorb from 8 to 15 "circles" + value = (int)(8 + value / 200.0 * 7.0); //absorb from 8 to 15 "circles" Caster.MagicDamageAbsorb = value; diff --git a/Scripts/Spells/First/ReactiveArmor.cs b/Scripts/Spells/First/ReactiveArmor.cs index 85ea4a7a0..eac621c05 100644 --- a/Scripts/Spells/First/ReactiveArmor.cs +++ b/Scripts/Spells/First/ReactiveArmor.cs @@ -58,9 +58,7 @@ namespace Server.Spells.First { Mobile targ = Caster; - ResistanceMod[] mods = m_Table[targ]; - - if (mods == null) + if (!m_Table.TryGetValue(targ, out ResistanceMod[] mods)) { targ.PlaySound(0x1E9); targ.FixedParticles(0x376A, 9, 32, 5008, EffectLayer.Waist); diff --git a/Scripts/Spells/Fourth/ArchProtection.cs b/Scripts/Spells/Fourth/ArchProtection.cs index 90b3f28d1..d8f9e6547 100644 --- a/Scripts/Spells/Fourth/ArchProtection.cs +++ b/Scripts/Spells/Fourth/ArchProtection.cs @@ -109,9 +109,8 @@ namespace Server.Spells.Fourth public static void RemoveEntry(Mobile m) { - if (_Table.ContainsKey(m)) + if (_Table.TryGetValue(m, out int v)) { - int v = _Table[m]; _Table.Remove(m); m.EndAction(); m.VirtualArmorMod -= v; @@ -162,4 +161,4 @@ namespace Server.Spells.Fourth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Fourth/Curse.cs b/Scripts/Spells/Fourth/Curse.cs index 301dc05a0..0aec525e6 100644 --- a/Scripts/Spells/Fourth/Curse.cs +++ b/Scripts/Spells/Fourth/Curse.cs @@ -16,7 +16,7 @@ namespace Server.Spells.Fourth Reagent.SulfurousAsh ); - private static Dictionary m_UnderEffect = new Dictionary(); + private static HashSet m_UnderEffect = new HashSet(); public CurseSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -38,7 +38,7 @@ namespace Server.Spells.Fourth public static bool UnderEffect(Mobile m) { - return m_UnderEffect.ContainsKey(m); + return m_UnderEffect.Contains(m); } public void Target(Mobile m) @@ -59,13 +59,12 @@ namespace Server.Spells.Fourth SpellHelper.AddStatCurse(Caster, m, StatType.Int); SpellHelper.DisableSkillCheck = false; - Timer t = m_UnderEffect[m]; - - if (Caster.Player && m.Player /*&& Caster != m */ && t == null + if (Caster.Player && m.Player /*&& Caster != m */ && !UnderEffect(m) ) //On OSI you CAN curse yourself and get this effect. { TimeSpan duration = SpellHelper.GetDuration(Caster, m); - m_UnderEffect[m] = Timer.DelayCall(duration, RemoveEffect, m); + m_UnderEffect.Add(m); + Timer.DelayCall(duration, RemoveEffect, m); m.UpdateResistances(); } diff --git a/Scripts/Spells/Fourth/ManaDrain.cs b/Scripts/Spells/Fourth/ManaDrain.cs index 71ea6f192..f8a1a7572 100644 --- a/Scripts/Spells/Fourth/ManaDrain.cs +++ b/Scripts/Spells/Fourth/ManaDrain.cs @@ -15,7 +15,7 @@ namespace Server.Spells.Fourth Reagent.SpidersSilk ); - private static Dictionary m_Table = new Dictionary(); + private static HashSet m_Table = new HashSet(); public ManaDrainSpell(Mobile caster, Item scroll) : base(caster, scroll, m_Info) { @@ -66,7 +66,7 @@ namespace Server.Spells.Fourth else if (toDrain > m.Mana) toDrain = m.Mana; - if (m_Table.ContainsKey(m)) + if (m_Table.Contains(m)) toDrain = 0; m.FixedParticles(0x3789, 10, 25, 5032, EffectLayer.Head); @@ -76,7 +76,8 @@ namespace Server.Spells.Fourth { m.Mana -= toDrain; - m_Table[m] = Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => AosDelay_Callback(m, toDrain)); + m_Table.Add(m); + Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => AosDelay_Callback(m, toDrain)); } } else @@ -124,4 +125,4 @@ namespace Server.Spells.Fourth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Mysticism/SpellPlagueSpell.cs b/Scripts/Spells/Mysticism/SpellPlagueSpell.cs index b6c32540d..04e259b96 100644 --- a/Scripts/Spells/Mysticism/SpellPlagueSpell.cs +++ b/Scripts/Spells/Mysticism/SpellPlagueSpell.cs @@ -67,11 +67,8 @@ namespace Server.Spells.Mysticism SpellPlagueContext context = new SpellPlagueContext(this, targeted); - if (m_Table.ContainsKey(targeted)) - { - SpellPlagueContext oldContext = m_Table[targeted]; + if (m_Table.TryGetValue(targeted, out SpellPlagueContext oldContext)) oldContext.SetNext(context); - } else { m_Table[targeted] = context; @@ -89,22 +86,14 @@ namespace Server.Spells.Mysticism public static void RemoveEffect(Mobile m) { - if (!m_Table.ContainsKey(m)) - return; - - SpellPlagueContext context = m_Table[m]; - - context.EndPlague(false); + if (m_Table.TryGetValue(m, out SpellPlagueContext context)) + context.EndPlague(false); } public static void CheckPlague(Mobile m) { - if (!m_Table.ContainsKey(m)) - return; - - SpellPlagueContext context = m_Table[m]; - - context.OnDamage(); + if (m_Table.TryGetValue(m, out SpellPlagueContext context)) + context.OnDamage(); } private static void OnPlayerDeath(PlayerDeathEventArgs e) @@ -225,4 +214,4 @@ namespace Server.Spells.Mysticism } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Mysticism/StoneFormSpell.cs b/Scripts/Spells/Mysticism/StoneFormSpell.cs index 7e54faf3a..618ce8748 100644 --- a/Scripts/Spells/Mysticism/StoneFormSpell.cs +++ b/Scripts/Spells/Mysticism/StoneFormSpell.cs @@ -142,7 +142,8 @@ namespace Server.Spells.Mysticism public static void RemoveEffects(Mobile m) { - ResistanceMod[] mods = m_Table[m]; + if (!m_Table.TryGetValue(m, out ResistanceMod[] mods)) + return; for (int i = 0; i < mods.Length; ++i) m.RemoveResistanceMod(mods[i]); @@ -157,10 +158,7 @@ namespace Server.Spells.Mysticism private static void OnPlayerDeath(PlayerDeathEventArgs e) { - Mobile m = e.Mobile; - - if (UnderEffect(m)) - RemoveEffects(m); + RemoveEffects(e.Mobile); } } } diff --git a/Scripts/Spells/Necromancy/AnimateDeadSpell.cs b/Scripts/Spells/Necromancy/AnimateDeadSpell.cs index 3def622e8..702162bb0 100644 --- a/Scripts/Spells/Necromancy/AnimateDeadSpell.cs +++ b/Scripts/Spells/Necromancy/AnimateDeadSpell.cs @@ -205,9 +205,7 @@ namespace Server.Spells.Necromancy if (master == null) return; - m_Table.TryGetValue(master, out List list); - - if (list == null) + if (!m_Table.TryGetValue(master, out List list)) return; list.Remove(summoned); @@ -221,9 +219,7 @@ namespace Server.Spells.Necromancy if (master == null) return; - m_Table.TryGetValue(master, out List list); - - if (list == null) + if (!m_Table.TryGetValue(master, out List list)) m_Table[master] = list = new List(); for (int i = list.Count - 1; i >= 0; --i) @@ -306,6 +302,7 @@ namespace Server.Spells.Necromancy } catch { + // ignored } if (summoned == null) @@ -394,4 +391,4 @@ namespace Server.Spells.Necromancy } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Necromancy/BloodOathSpell.cs b/Scripts/Spells/Necromancy/BloodOathSpell.cs index 082b85355..49ae4b292 100644 --- a/Scripts/Spells/Necromancy/BloodOathSpell.cs +++ b/Scripts/Spells/Necromancy/BloodOathSpell.cs @@ -62,7 +62,7 @@ namespace Server.Spells.Necromancy * ((ss-rm)/8)+8 */ - ExpireTimer timer = m_Table[m]; + m_Table.TryGetValue(m, out ExpireTimer timer); timer?.DoExpire(); m_OathTable[Caster] = Caster; @@ -96,17 +96,13 @@ namespace Server.Spells.Necromancy public static void RemoveCurse(Mobile m) { - ExpireTimer t = m_Table[m]; + m_Table.TryGetValue(m, out ExpireTimer t); t?.DoExpire(); } public static Mobile GetBloodOath(Mobile m) { - if (m == null) - return null; - - Mobile oath = m_OathTable[m]; - return oath == m ? null : oath; + return m == null || m_OathTable.TryGetValue(m, out Mobile oath) && oath == m ? null : oath; } private class ExpireTimer : Timer diff --git a/Scripts/Spells/Necromancy/CorpseSkin.cs b/Scripts/Spells/Necromancy/CorpseSkin.cs index ae80e572d..b1f5defa0 100644 --- a/Scripts/Spells/Necromancy/CorpseSkin.cs +++ b/Scripts/Spells/Necromancy/CorpseSkin.cs @@ -49,9 +49,7 @@ namespace Server.Spells.Necromancy * NOTE: Resistance is not checked if targeting yourself */ - ExpireTimer timer = m_Table[m]; - - if (timer != null) + if (m_Table.TryGetValue(m, out ExpireTimer timer)) timer.DoExpire(); else m.SendLocalizedMessage(1061689); // Your skin turns dry and corpselike. diff --git a/Scripts/Spells/Necromancy/CurseWeapon.cs b/Scripts/Spells/Necromancy/CurseWeapon.cs index 34199f36a..50a0c647b 100644 --- a/Scripts/Spells/Necromancy/CurseWeapon.cs +++ b/Scripts/Spells/Necromancy/CurseWeapon.cs @@ -50,12 +50,10 @@ namespace Server.Spells.Necromancy TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills.SpiritSpeak.Value / 3.4 + 1.0); - - ExpireTimer timer = m_Table[weapon]; + m_Table.TryGetValue(weapon, out ExpireTimer timer); timer?.Stop(); weapon.Cursed = true; - m_Table[weapon] = timer = new ExpireTimer(weapon, duration); timer.Start(); diff --git a/Scripts/Spells/Necromancy/EvilOmen.cs b/Scripts/Spells/Necromancy/EvilOmen.cs index 8105cf7ff..171fd7432 100644 --- a/Scripts/Spells/Necromancy/EvilOmen.cs +++ b/Scripts/Spells/Necromancy/EvilOmen.cs @@ -69,7 +69,7 @@ namespace Server.Spells.Necromancy TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills.SpiritSpeak.Value / 12 + 1.0); - Timer.DelayCall(duration, () => TryEndEffect(m)); + Timer.DelayCall(duration, TryEndEffect_Callback, m); HarmfulSpell(m); @@ -86,6 +86,10 @@ namespace Server.Spells.Necromancy * * -refactored. */ + private static void TryEndEffect_Callback(Mobile m) + { + TryEndEffect(m); + } public static bool TryEndEffect(Mobile m) { diff --git a/Scripts/Spells/Necromancy/MindRot.cs b/Scripts/Spells/Necromancy/MindRot.cs index fe17ac7bd..634424e2f 100644 --- a/Scripts/Spells/Necromancy/MindRot.cs +++ b/Scripts/Spells/Necromancy/MindRot.cs @@ -58,10 +58,7 @@ namespace Server.Spells.Necromancy ((GetDamageSkill(Caster) - GetResistSkill(m)) / 5.0 + 20.0) * (m.Player ? 1.0 : 2.0)); m.CheckSkill(SkillName.MagicResist, 0.0, 120.0); //Skill check for gain - if (m.Player) - SetMindRotScalar(Caster, m, 1.25, duration); - else - SetMindRotScalar(Caster, m, 2.00, duration); + SetMindRotScalar(Caster, m, m.Player ? 1.25 : 2.00, duration); HarmfulSpell(m); } @@ -71,9 +68,7 @@ namespace Server.Spells.Necromancy public static void ClearMindRotScalar(Mobile m) { - MRBucket tmpB = m_Table[m]; - - if (tmpB == null) + if (!m_Table.TryGetValue(m, out MRBucket tmpB)) return; BuffInfo.RemoveBuff(m, BuffIcon.Mindrot); @@ -89,13 +84,13 @@ namespace Server.Spells.Necromancy public static bool GetMindRotScalar(Mobile m, ref double scalar) { - MRBucket tmpB = m_Table[m]; + if (m_Table.TryGetValue(m, out MRBucket tmpB)) + { + scalar = tmpB.m_Scalar; + return true; + } - if (tmpB == null) - return false; - - scalar = tmpB.m_Scalar; - return true; + return false; } public static void SetMindRotScalar(Mobile caster, Mobile target, double scalar, TimeSpan duration) diff --git a/Scripts/Spells/Necromancy/PainSpike.cs b/Scripts/Spells/Necromancy/PainSpike.cs index c0dd877d1..1e5c213b5 100644 --- a/Scripts/Spells/Necromancy/PainSpike.cs +++ b/Scripts/Spells/Necromancy/PainSpike.cs @@ -59,9 +59,7 @@ namespace Server.Spells.Necromancy TimeSpan buffTime = TimeSpan.FromSeconds(10.0); - InternalTimer timer = m_Table[m]; - - if (timer == null) + if (!m_Table.TryGetValue(m, out InternalTimer timer)) { m_Table[m] = timer = new InternalTimer(m, damage); timer.Start(); diff --git a/Scripts/Spells/Necromancy/Strangle.cs b/Scripts/Spells/Necromancy/Strangle.cs index e4b1edd36..4af1c477f 100644 --- a/Scripts/Spells/Necromancy/Strangle.cs +++ b/Scripts/Spells/Necromancy/Strangle.cs @@ -59,9 +59,7 @@ namespace Server.Spells.Necromancy m.FixedParticles(0x36CB, 1, 9, 9911, 67, 5, EffectLayer.Head); m.FixedParticles(0x374A, 1, 17, 9502, 1108, 4, (EffectLayer)255); - InternalTimer timer = m_Table[m]; - - if (timer == null) + if (!m_Table.TryGetValue(m, out InternalTimer timer)) { m_Table[m] = timer = new InternalTimer(m, Caster); timer.Start(); @@ -111,9 +109,7 @@ namespace Server.Spells.Necromancy public static bool RemoveCurse(Mobile m) { - Timer timer = m_Table[m]; - - if (timer == null) + if (!m_Table.TryGetValue(m, out InternalTimer timer)) return false; timer.Stop(); diff --git a/Scripts/Spells/Necromancy/SummonFamiliar.cs b/Scripts/Spells/Necromancy/SummonFamiliar.cs index b118592a8..5e023b7e2 100644 --- a/Scripts/Spells/Necromancy/SummonFamiliar.cs +++ b/Scripts/Spells/Necromancy/SummonFamiliar.cs @@ -40,15 +40,11 @@ namespace Server.Spells.Necromancy public override bool CheckCast() { - BaseCreature check = Table[Caster]; + if (!(Table.TryGetValue(Caster, out BaseCreature check) && check?.Deleted == false)) + return base.CheckCast(); - if (check?.Deleted == false) - { - Caster.SendLocalizedMessage(1061605); // You already have a familiar. - return false; - } - - return base.CheckCast(); + Caster.SendLocalizedMessage(1061605); // You already have a familiar. + return false; } public override void OnCast() @@ -149,18 +145,12 @@ namespace Server.Spells.Necromancy double necro = m_From.Skills.Necromancy.Value; double spirit = m_From.Skills.SpiritSpeak.Value; - BaseCreature check = SummonFamiliarSpell.Table[m_From]; - #region Dueling - - if ((m_From as PlayerMobile)?.DuelContext != null && - !((PlayerMobile)m_From).DuelContext.AllowSpellCast(m_From, m_Spell)) + if ((m_From as PlayerMobile)?.DuelContext?.AllowSpellCast(m_From, m_Spell) == false) { } - #endregion - - else if (check?.Deleted == false) + else if (SummonFamiliarSpell.Table.TryGetValue(m_From, out BaseCreature check) && check?.Deleted == false) { m_From.SendLocalizedMessage(1061605); // You already have a familiar. } diff --git a/Scripts/Spells/Ninjitsu/AnimalForm.cs b/Scripts/Spells/Ninjitsu/AnimalForm.cs index 67d593c08..766b4f570 100644 --- a/Scripts/Spells/Ninjitsu/AnimalForm.cs +++ b/Scripts/Spells/Ninjitsu/AnimalForm.cs @@ -197,10 +197,7 @@ namespace Server.Spells.Ninjitsu public int GetLastAnimalForm(Mobile m) { - if (m_LastAnimalForms.ContainsKey(m)) - return m_LastAnimalForms[m]; - - return -1; + return m_LastAnimalForms.TryGetValue(m, out int value) ? value : -1; } public static MorphResult Morph(Mobile m, int entryID) @@ -323,7 +320,7 @@ namespace Server.Spells.Ninjitsu public static AnimalFormContext GetContext(Mobile m) { - return m_Table[m]; + return m_Table.TryGetValue(m, out AnimalFormContext context) ? context : null; } public static bool UnderTransformation(Mobile m) @@ -445,19 +442,19 @@ namespace Server.Spells.Ninjitsu } } - if (enabled) - { - int x = pos % 2 == 0 ? 14 : 264; - int y = pos / 2 * 64 + 44; + if (!enabled) + continue; - Rectangle2D b = ItemBounds.Table[entries[i].ItemID]; + int x = pos % 2 == 0 ? 14 : 264; + int y = pos / 2 * 64 + 44; - AddImageTiledButton(x, y, 0x918, 0x919, i + 1, GumpButtonType.Reply, 0, entries[i].ItemID, - entries[i].Hue, 40 - b.Width / 2 - b.X, 30 - b.Height / 2 - b.Y, entries[i].Tooltip); - AddHtmlLocalized(x + 84, y, 250, 60, entries[i].Name, 0x7FFF, false, false); + Rectangle2D b = ItemBounds.Table[entries[i].ItemID]; - current++; - } + AddImageTiledButton(x, y, 0x918, 0x919, i + 1, GumpButtonType.Reply, 0, entries[i].ItemID, + entries[i].Hue, 40 - b.Width / 2 - b.X, 30 - b.Height / 2 - b.Y, entries[i].Tooltip); + AddHtmlLocalized(x + 84, y, 250, 60, entries[i].Name, 0x7FFF, false, false); + + current++; } } @@ -484,8 +481,7 @@ namespace Server.Spells.Ninjitsu { #region Dueling - if ((m_Caster as PlayerMobile)?.DuelContext != null && - !((PlayerMobile)m_Caster).DuelContext.AllowSpellCast(m_Caster, m_Spell)) + if ((m_Caster as PlayerMobile)?.DuelContext?.AllowSpellCast(m_Caster, m_Spell) == false) { } diff --git a/Scripts/Spells/Ninjitsu/DeathStrike.cs b/Scripts/Spells/Ninjitsu/DeathStrike.cs index 26873512d..203bdd0e7 100644 --- a/Scripts/Spells/Ninjitsu/DeathStrike.cs +++ b/Scripts/Spells/Ninjitsu/DeathStrike.cs @@ -48,12 +48,9 @@ namespace Server.Spells.Ninjitsu return; } - - DeathStrikeInfo info = m_Table[defender]; - int damageBonus = 0; - if (info != null) + if (m_Table.TryGetValue(defender, out DeathStrikeInfo info)) { defender.SendLocalizedMessage(1063092); // Your opponent lands another Death Strike! @@ -86,18 +83,13 @@ namespace Server.Spells.Ninjitsu public static void AddStep(Mobile m) { - DeathStrikeInfo info = m_Table[m]; - if (info == null) - return; - - if (++info.m_Steps >= 5) + if (m_Table.TryGetValue(m, out DeathStrikeInfo info) && ++info.m_Steps >= 5) ProcessDeathStrike(m); } private static void ProcessDeathStrike(Mobile defender) { - DeathStrikeInfo info = m_Table[defender]; - if (info == null) + if (!m_Table.TryGetValue(defender, out DeathStrikeInfo info)) return; int damage; diff --git a/Scripts/Spells/Ninjitsu/KiAttack.cs b/Scripts/Spells/Ninjitsu/KiAttack.cs index 15b7de078..e74ea7fbd 100644 --- a/Scripts/Spells/Ninjitsu/KiAttack.cs +++ b/Scripts/Spells/Ninjitsu/KiAttack.cs @@ -81,20 +81,16 @@ namespace Server.Spells.Ninjitsu public override void OnClearMove(Mobile from) { - KiAttackInfo info = m_Table[from]; - - if (info == null) + if (!m_Table.TryGetValue(from, out KiAttackInfo info)) return; - info.m_Timer?.Stop(); + info.m_Timer.Stop(); m_Table.Remove(info.m_Mobile); } public static double GetBonus(Mobile from) { - KiAttackInfo info = m_Table[from]; - - if (info == null) + if (!m_Table.TryGetValue(from, out KiAttackInfo info)) return 0; int xDelta = info.m_Location.X - from.X; diff --git a/Scripts/Spells/Ninjitsu/MirrorImage.cs b/Scripts/Spells/Ninjitsu/MirrorImage.cs index f78043a76..06dd52bf9 100644 --- a/Scripts/Spells/Ninjitsu/MirrorImage.cs +++ b/Scripts/Spells/Ninjitsu/MirrorImage.cs @@ -39,24 +39,18 @@ namespace Server.Spells.Ninjitsu if (m == null) return; - if (m_CloneCount.ContainsKey(m)) - m_CloneCount[m]++; - else - m_CloneCount[m] = 1; + m_CloneCount[m] = 1 + (m_CloneCount.TryGetValue(m, out int count) ? count : 0); } public static void RemoveClone(Mobile m) { - if (m == null) + if (m == null || !m_CloneCount.TryGetValue(m, out int count)) return; - if (m_CloneCount.ContainsKey(m)) - { + if (count <= 1) + m_CloneCount.Remove(m); + else m_CloneCount[m]--; - - if (m_CloneCount[m] == 0) - m_CloneCount.Remove(m); - } } public override bool CheckCast() @@ -272,4 +266,4 @@ namespace Server.Mobiles return true; } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Ninjitsu/SurpriseAttack.cs b/Scripts/Spells/Ninjitsu/SurpriseAttack.cs index a60922971..626278a3a 100644 --- a/Scripts/Spells/Ninjitsu/SurpriseAttack.cs +++ b/Scripts/Spells/Ninjitsu/SurpriseAttack.cs @@ -53,9 +53,7 @@ namespace Server.Spells.Ninjitsu attacker.RevealingAction(); - SurpriseAttackInfo info = m_Table[defender]; - - if (info != null) + if (m_Table.TryGetValue(defender, out SurpriseAttackInfo info)) { info.m_Timer?.Stop(); @@ -85,9 +83,7 @@ namespace Server.Spells.Ninjitsu public static bool GetMalus(Mobile target, ref int malus) { - SurpriseAttackInfo info = m_Table[target]; - - if (info == null) + if (!m_Table.TryGetValue(target, out SurpriseAttackInfo info)) return false; malus = info.m_Malus; diff --git a/Scripts/Spells/Second/Protection.cs b/Scripts/Spells/Second/Protection.cs index 4a49f4c27..c3f4b1f88 100644 --- a/Scripts/Spells/Second/Protection.cs +++ b/Scripts/Spells/Second/Protection.cs @@ -36,13 +36,12 @@ namespace Server.Spells.Second return false; } - if (!Caster.CanBeginAction()) - { - Caster.SendLocalizedMessage(1005385); // The spell will not adhere to you at this time. - return false; - } + if (Caster.CanBeginAction()) + return true; + + Caster.SendLocalizedMessage(1005385); // The spell will not adhere to you at this time. + return false; - return true; } public static void Toggle(Mobile caster, Mobile target) @@ -56,9 +55,7 @@ namespace Server.Spells.Second * even after dying�until you �turn them off� by casting them again. */ - Tuple mods = m_Table[target]; - - if (mods == null) + if (m_Table.TryGetValue(target, out Tuple mods)) { target.PlaySound(0x1E9); target.FixedParticles(0x375A, 9, 20, 5016, EffectLayer.Waist); @@ -98,9 +95,7 @@ namespace Server.Spells.Second public static void EndProtection(Mobile m) { - Tuple mods = m_Table[m]; - - if (mods == null) + if (!m_Table.TryGetValue(m, out Tuple mods)) return; m_Table.Remove(m); diff --git a/Scripts/Spells/Seventh/Polymorph.cs b/Scripts/Spells/Seventh/Polymorph.cs index f6a06d5b6..c8958d5ce 100644 --- a/Scripts/Spells/Seventh/Polymorph.cs +++ b/Scripts/Spells/Seventh/Polymorph.cs @@ -164,8 +164,7 @@ namespace Server.Spells.Seventh public static void StopTimer(Mobile m) { - InternalTimer timer = m_Timers[m]; - if (timer == null) + if (!m_Timers.TryGetValue(m, out InternalTimer timer)) return; timer.Stop(); @@ -174,15 +173,15 @@ namespace Server.Spells.Seventh private static void EndPolymorph(Mobile m) { - if (!m.CanBeginAction()) - { - m.BodyMod = 0; - m.HueMod = -1; - m.EndAction(); + if (m.CanBeginAction()) + return; - BaseArmor.ValidateMobile(m); - BaseClothing.ValidateMobile(m); - } + m.BodyMod = 0; + m.HueMod = -1; + m.EndAction(); + + BaseArmor.ValidateMobile(m); + BaseClothing.ValidateMobile(m); } private class InternalTimer : Timer diff --git a/Scripts/Spells/Sixth/Invisibility.cs b/Scripts/Spells/Sixth/Invisibility.cs index f5f5faf32..c1e1d4742 100644 --- a/Scripts/Spells/Sixth/Invisibility.cs +++ b/Scripts/Spells/Sixth/Invisibility.cs @@ -88,13 +88,11 @@ namespace Server.Spells.Sixth public static void RemoveTimer(Mobile m) { - m_Table.TryGetValue(m, out Timer t); + if (!m_Table.TryGetValue(m, out Timer t)) + return; - if (t != null) - { - t.Stop(); - m_Table.Remove(m); - } + t.Stop(); + m_Table.Remove(m); } private class InternalTimer : Timer @@ -135,4 +133,4 @@ namespace Server.Spells.Sixth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Spellweaving/AttuneWeapon.cs b/Scripts/Spells/Spellweaving/AttuneWeapon.cs index f9ffce3cb..1e1b7ae66 100644 --- a/Scripts/Spells/Spellweaving/AttuneWeapon.cs +++ b/Scripts/Spells/Spellweaving/AttuneWeapon.cs @@ -30,13 +30,12 @@ namespace Server.Spells.Spellweaving return false; } - if (!Caster.CanBeginAction()) - { - Caster.SendLocalizedMessage(1075124); // You must wait before casting that spell again. - return false; - } + if (Caster.CanBeginAction()) + return base.CheckCast(); + + Caster.SendLocalizedMessage(1075124); // You must wait before casting that spell again. + return false; - return base.CheckCast(); } public override void OnCast() @@ -92,7 +91,8 @@ namespace Server.Spells.Spellweaving public static void StopAbsorbing(Mobile m, bool message) { - if (m_Table.TryGetValue(m, out ExpireTimer t)) t.DoExpire(message); + if (m_Table.TryGetValue(m, out ExpireTimer t)) + t.DoExpire(message); } private class ExpireTimer : Timer @@ -129,4 +129,4 @@ namespace Server.Spells.Spellweaving } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Spellweaving/EssenceOfWind.cs b/Scripts/Spells/Spellweaving/EssenceOfWind.cs index 6e0a2bc7d..ad4a3a632 100644 --- a/Scripts/Spells/Spellweaving/EssenceOfWind.cs +++ b/Scripts/Spells/Spellweaving/EssenceOfWind.cs @@ -64,18 +64,12 @@ namespace Server.Spells.Spellweaving public static int GetFCMalus(Mobile m) { - if (m_Table.TryGetValue(m, out EssenceOfWindInfo info)) - return info.FCMalus; - - return 0; + return m_Table.TryGetValue(m, out EssenceOfWindInfo info) ? info.FCMalus : 0; } public static int GetSSIMalus(Mobile m) { - if (m_Table.TryGetValue(m, out EssenceOfWindInfo info)) - return info.SSIMalus; - - return 0; + return m_Table.TryGetValue(m, out EssenceOfWindInfo info) ? info.SSIMalus : 0; } public static bool IsDebuffed(Mobile m) @@ -127,15 +121,10 @@ namespace Server.Spells.Spellweaving public void DoExpire(bool message) { Stop(); - /* - if ( message ) - { - } - */ m_Table.Remove(m_Mobile); BuffInfo.RemoveBuff(m_Mobile, BuffIcon.EssenceOfWind); } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Spellweaving/GiftOfLife.cs b/Scripts/Spells/Spellweaving/GiftOfLife.cs index bc48b61b9..2af71865d 100644 --- a/Scripts/Spells/Spellweaving/GiftOfLife.cs +++ b/Scripts/Spells/Spellweaving/GiftOfLife.cs @@ -95,45 +95,45 @@ namespace Server.Spells.Spellweaving private static void HandleDeath_OnCallback(Mobile m) { - if (m_Table.TryGetValue(m, out ExpireTimer timer)) + if (!m_Table.TryGetValue(m, out ExpireTimer timer)) + return; + + double hitsScalar = timer.Spell.HitsScalar; + + if (m is BaseCreature pet && pet.IsDeadBondedPet) { - double hitsScalar = timer.Spell.HitsScalar; + Mobile master = pet.GetMaster(); - if (m is BaseCreature pet && pet.IsDeadBondedPet) + if (master?.NetState != null && Utility.InUpdateRange(pet, master)) { - Mobile master = pet.GetMaster(); - - if (master?.NetState != null && Utility.InUpdateRange(pet, master)) - { - master.CloseGump(); - master.SendGump(new PetResurrectGump(master, pet, hitsScalar)); - } - else - { - List friends = pet.Friends; - - for (int i = 0; friends != null && i < friends.Count; i++) - { - Mobile friend = friends[i]; - - if (friend.NetState != null && Utility.InUpdateRange(pet, friend)) - { - friend.CloseGump(); - friend.SendGump(new PetResurrectGump(friend, pet)); - break; - } - } - } + master.CloseGump(); + master.SendGump(new PetResurrectGump(master, pet, hitsScalar)); } else { - m.CloseGump(); - m.SendGump(new ResurrectGump(m, hitsScalar)); - } + List friends = pet.Friends; - //Per OSI, buff is removed when gump sent, irregardless of online status or acceptence - timer.DoExpire(); + for (int i = 0; friends != null && i < friends.Count; i++) + { + Mobile friend = friends[i]; + + if (friend.NetState != null && Utility.InUpdateRange(pet, friend)) + { + friend.CloseGump(); + friend.SendGump(new PetResurrectGump(friend, pet)); + break; + } + } + } } + else + { + m.CloseGump(); + m.SendGump(new ResurrectGump(m, hitsScalar)); + } + + //Per OSI, buff is removed when gump sent, irregardless of online status or acceptence + timer.DoExpire(); } public static void OnLogin(LoginEventArgs e) @@ -199,4 +199,4 @@ namespace Server.Spells.Spellweaving } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Spellweaving/GiftOfRenewal.cs b/Scripts/Spells/Spellweaving/GiftOfRenewal.cs index 4ecbb9d39..cdfd41510 100644 --- a/Scripts/Spells/Spellweaving/GiftOfRenewal.cs +++ b/Scripts/Spells/Spellweaving/GiftOfRenewal.cs @@ -84,19 +84,17 @@ namespace Server.Spells.Spellweaving public static bool StopEffect(Mobile m) { - if (m_Table.TryGetValue(m, out GiftOfRenewalInfo info)) - { - m_Table.Remove(m); + if (!m_Table.TryGetValue(m, out GiftOfRenewalInfo info)) + return false; - info.m_Timer.Stop(); - BuffInfo.RemoveBuff(m, BuffIcon.GiftOfRenewal); + m_Table.Remove(m); - Timer.DelayCall(TimeSpan.FromSeconds(60), delegate { info.m_Caster.EndAction(); }); + info.m_Timer.Stop(); + BuffInfo.RemoveBuff(m, BuffIcon.GiftOfRenewal); - return true; - } + Timer.DelayCall(TimeSpan.FromSeconds(60), delegate { info.m_Caster.EndAction(); }); - return false; + return true; } private class GiftOfRenewalInfo @@ -119,17 +117,17 @@ namespace Server.Spells.Spellweaving private class InternalTimer : Timer { - public GiftOfRenewalInfo m_Info; + private GiftOfRenewalInfo m_GiftInfo; public InternalTimer(GiftOfRenewalInfo info) : base(TimeSpan.FromSeconds(2.0), TimeSpan.FromSeconds(2.0)) { - m_Info = info; + m_GiftInfo = info; } protected override void OnTick() { - Mobile m = m_Info.m_Mobile; + Mobile m = m_GiftInfo.m_Mobile; if (!m_Table.ContainsKey(m)) { @@ -147,14 +145,14 @@ namespace Server.Spells.Spellweaving if (m.Hits >= m.HitsMax) return; - int toHeal = m_Info.m_HitsPerRound; + int toHeal = m_GiftInfo.m_HitsPerRound; - SpellHelper.Heal(toHeal, m, m_Info.m_Caster); + SpellHelper.Heal(toHeal, m, m_GiftInfo.m_Caster); m.FixedParticles(0x376A, 9, 32, 5005, EffectLayer.Waist); } } - public class InternalTarget : Target + private class InternalTarget : Target { private GiftOfRenewalSpell m_Owner; @@ -176,4 +174,4 @@ namespace Server.Spells.Spellweaving } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs b/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs index d797c9a6d..ac8a7d2e2 100644 --- a/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs +++ b/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs @@ -70,10 +70,7 @@ namespace Server.Spells.Spellweaving public static int GetImmolatingDamage(BaseWeapon weapon) { - if (m_WeaponDamageTable.TryGetValue(weapon, out ImmolatingWeaponEntry entry)) - return entry.m_Damage; - - return 0; + return m_WeaponDamageTable.TryGetValue(weapon, out ImmolatingWeaponEntry entry) ? entry.m_Damage : 0; } public static void DoEffect(BaseWeapon weapon, Mobile target) @@ -89,16 +86,14 @@ namespace Server.Spells.Spellweaving public static void StopImmolating(BaseWeapon weapon) { - if (m_WeaponDamageTable.TryGetValue(weapon, out ImmolatingWeaponEntry entry)) - { - entry.m_Caster?.PlaySound(0x27); + if (!m_WeaponDamageTable.TryGetValue(weapon, out ImmolatingWeaponEntry entry)) + return; - entry.m_Timer.Stop(); + entry.m_Caster?.PlaySound(0x27); + entry.m_Timer.Stop(); + m_WeaponDamageTable.Remove(weapon); - m_WeaponDamageTable.Remove(weapon); - - weapon.InvalidateProperties(); - } + weapon.InvalidateProperties(); } private class ImmolatingWeaponEntry @@ -127,4 +122,4 @@ namespace Server.Spells.Spellweaving } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Spellweaving/Thunderstorm.cs b/Scripts/Spells/Spellweaving/Thunderstorm.cs index f2ec18d01..c6cbf24dd 100644 --- a/Scripts/Spells/Spellweaving/Thunderstorm.cs +++ b/Scripts/Spells/Spellweaving/Thunderstorm.cs @@ -63,14 +63,13 @@ namespace Server.Spells.Spellweaving SpellHelper.Damage(this, m, m.Player && Caster.Player ? pvpDamage : pvmDamage, 0, 0, 0, 0, 100); - if (oldSpell != null && oldSpell != m.Spell) - if (!CheckResisted(m)) - { - m_Table[m] = Timer.DelayCall(duration, DoExpire, m); + if (oldSpell != null && oldSpell != m.Spell && !CheckResisted(m)) + { + m_Table[m] = Timer.DelayCall(duration, DoExpire, m); - BuffInfo.AddBuff(m, - new BuffInfo(BuffIcon.Thunderstorm, 1075800, duration, m, GetCastRecoveryMalus(m))); - } + BuffInfo.AddBuff(m, + new BuffInfo(BuffIcon.Thunderstorm, 1075800, duration, m, GetCastRecoveryMalus(m))); + } } } @@ -84,13 +83,13 @@ namespace Server.Spells.Spellweaving public static void DoExpire(Mobile m) { - if (m_Table.TryGetValue(m, out Timer t)) - { - t.Stop(); - m_Table.Remove(m); + if (!m_Table.TryGetValue(m, out Timer t)) + return; - BuffInfo.RemoveBuff(m, BuffIcon.Thunderstorm); - } + t.Stop(); + m_Table.Remove(m); + + BuffInfo.RemoveBuff(m, BuffIcon.Thunderstorm); } } -} \ No newline at end of file +} diff --git a/Server/Commands.cs b/Server/Commands.cs index 0b8668820..e20cee97c 100644 --- a/Server/Commands.cs +++ b/Server/Commands.cs @@ -61,7 +61,7 @@ namespace Server.Commands return Utility.ToInt32(Arguments[index]); } - + public uint GetUInt32(int index) { if (index < 0 || index >= Arguments.Length) @@ -126,14 +126,10 @@ namespace Server.Commands public static class CommandSystem { - static CommandSystem() - { - Entries = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - public static string Prefix{ get; set; } = "["; - public static Dictionary Entries{ get; } + public static Dictionary Entries{ get; } = + new Dictionary(StringComparer.OrdinalIgnoreCase); public static AccessLevel BadCommandIgnoreLevel{ get; set; } = AccessLevel.Player; @@ -191,71 +187,64 @@ namespace Server.Commands Entries[command] = new CommandEntry(command, handler, access); } - public static bool Handle(Mobile from, string text) + public static bool Handle(Mobile from, string text, MessageType type = MessageType.Regular) { - return Handle(from, text, MessageType.Regular); - } + if (!text.StartsWith(Prefix) && type != MessageType.Command) + return false; - public static bool Handle(Mobile from, string text, MessageType type) - { - if (text.StartsWith(Prefix) || type == MessageType.Command) + if (type != MessageType.Command) + text = text.Substring(Prefix.Length); + + int indexOf = text.IndexOf(' '); + + string command; + string[] args; + string argString; + + if (indexOf >= 0) { - if (type != MessageType.Command) - text = text.Substring(Prefix.Length); + argString = text.Substring(indexOf + 1); - int indexOf = text.IndexOf(' '); - - string command; - string[] args; - string argString; - - if (indexOf >= 0) - { - argString = text.Substring(indexOf + 1); - - command = text.Substring(0, indexOf); - args = Split(argString); - } - else - { - argString = ""; - command = text.ToLower(); - args = new string[0]; - } - - Entries.TryGetValue(command, out CommandEntry entry); - - if (entry != null) - { - if (from.AccessLevel >= entry.AccessLevel) - { - if (entry.Handler != null) - { - CommandEventArgs e = new CommandEventArgs(from, command, argString, args); - entry.Handler(e); - EventSink.InvokeCommand(e); - } - } - else - { - if (from.AccessLevel <= BadCommandIgnoreLevel) - return false; - - from.SendMessage("You do not have access to that command."); - } - } - else - { - if (from.AccessLevel <= BadCommandIgnoreLevel) - return false; - - from.SendMessage("That is not a valid command."); - } - - return true; + command = text.Substring(0, indexOf); + args = Split(argString); + } + else + { + argString = ""; + command = text.ToLower(); + args = new string[0]; } - return false; + Entries.TryGetValue(command, out CommandEntry entry); + + if (entry != null) + { + if (@from.AccessLevel >= entry.AccessLevel) + { + if (entry.Handler != null) + { + CommandEventArgs e = new CommandEventArgs(@from, command, argString, args); + entry.Handler(e); + EventSink.InvokeCommand(e); + } + } + else + { + if (@from.AccessLevel <= BadCommandIgnoreLevel) + return false; + + @from.SendMessage("You do not have access to that command."); + } + } + else + { + if (@from.AccessLevel <= BadCommandIgnoreLevel) + return false; + + @from.SendMessage("That is not a valid command."); + } + + return true; } } -} \ No newline at end of file +} diff --git a/Server/Diagnostics/GumpProfile.cs b/Server/Diagnostics/GumpProfile.cs index 5c8b918b2..b8ac1c7cb 100644 --- a/Server/Diagnostics/GumpProfile.cs +++ b/Server/Diagnostics/GumpProfile.cs @@ -27,8 +27,7 @@ namespace Server.Diagnostics { private static Dictionary _profiles = new Dictionary(); - public GumpProfile(Type type) - : base(type.FullName) + public GumpProfile(Type type) : base(type.FullName) { } @@ -36,11 +35,13 @@ namespace Server.Diagnostics public static GumpProfile Acquire(Type type) { - if (!Core.Profiling) return null; + if (!Core.Profiling) + return null; - if (!_profiles.TryGetValue(type, out GumpProfile prof)) _profiles.Add(type, prof = new GumpProfile(type)); + if (!_profiles.TryGetValue(type, out GumpProfile prof)) + _profiles.Add(type, prof = new GumpProfile(type)); return prof; } } -} \ No newline at end of file +} diff --git a/Server/Diagnostics/PacketProfile.cs b/Server/Diagnostics/PacketProfile.cs index 8c4828705..e85c7d89d 100644 --- a/Server/Diagnostics/PacketProfile.cs +++ b/Server/Diagnostics/PacketProfile.cs @@ -58,8 +58,7 @@ namespace Server.Diagnostics private long _created; - public PacketSendProfile(Type type) - : base(type.FullName) + public PacketSendProfile(Type type) : base(type.FullName) { } @@ -68,7 +67,8 @@ namespace Server.Diagnostics [MethodImpl(MethodImplOptions.Synchronized)] public static PacketSendProfile Acquire(Type type) { - if (!_profiles.TryGetValue(type, out PacketSendProfile prof)) _profiles.Add(type, prof = new PacketSendProfile(type)); + if (!_profiles.TryGetValue(type, out PacketSendProfile prof)) + _profiles.Add(type, prof = new PacketSendProfile(type)); return prof; } @@ -106,4 +106,4 @@ namespace Server.Diagnostics return prof; } } -} \ No newline at end of file +} diff --git a/Server/Diagnostics/TargetProfile.cs b/Server/Diagnostics/TargetProfile.cs index 10312c79f..581961a0d 100644 --- a/Server/Diagnostics/TargetProfile.cs +++ b/Server/Diagnostics/TargetProfile.cs @@ -36,11 +36,13 @@ namespace Server.Diagnostics public static TargetProfile Acquire(Type type) { - if (!Core.Profiling) return null; + if (!Core.Profiling) + return null; - if (!_profiles.TryGetValue(type, out TargetProfile prof)) _profiles.Add(type, prof = new TargetProfile(type)); + if (!_profiles.TryGetValue(type, out TargetProfile prof)) + _profiles.Add(type, prof = new TargetProfile(type)); return prof; } } -} \ No newline at end of file +} diff --git a/Server/Diagnostics/TimerProfile.cs b/Server/Diagnostics/TimerProfile.cs index 792cde9ea..2f6f8826c 100644 --- a/Server/Diagnostics/TimerProfile.cs +++ b/Server/Diagnostics/TimerProfile.cs @@ -42,9 +42,11 @@ namespace Server.Diagnostics public static TimerProfile Acquire(string name) { - if (!Core.Profiling) return null; + if (!Core.Profiling) + return null; - if (!_profiles.TryGetValue(name, out TimerProfile prof)) _profiles.Add(name, prof = new TimerProfile(name)); + if (!_profiles.TryGetValue(name, out TimerProfile prof)) + _profiles.Add(name, prof = new TimerProfile(name)); return prof; } @@ -56,4 +58,4 @@ namespace Server.Diagnostics op.Write("\t{0,12:N0} {1,12:N0} {2,-12:N0}", Created, Started, Stopped); } } -} \ No newline at end of file +} diff --git a/Server/Items/Container.cs b/Server/Items/Container.cs index b3bf416c7..cb6a6c8e3 100644 --- a/Server/Items/Container.cs +++ b/Server/Items/Container.cs @@ -1747,6 +1747,7 @@ namespace Server.Items } catch { + // ignored } } } diff --git a/Server/Map.cs b/Server/Map.cs index 815cf9bad..beab84716 100644 --- a/Server/Map.cs +++ b/Server/Map.cs @@ -907,13 +907,13 @@ namespace Server { string regName = reg.Name; - if (regName != null) - { - if (Regions.ContainsKey(regName)) - Console.WriteLine("Warning: Duplicate region name '{0}' for map '{1}'", regName, Name); - else - Regions[regName] = reg; - } + if (regName == null) + return; + + if (Regions.ContainsKey(regName)) + Console.WriteLine("Warning: Duplicate region name '{0}' for map '{1}'", regName, Name); + else + Regions[regName] = reg; } public void UnregisterRegion(Region reg) diff --git a/Server/Network/PacketHandlers.cs b/Server/Network/PacketHandlers.cs index 5dd6144d7..0fdd794aa 100644 --- a/Server/Network/PacketHandlers.cs +++ b/Server/Network/PacketHandlers.cs @@ -1612,7 +1612,7 @@ namespace Server.Network pvSrc.Trace(state); return; } - + if (ph.Ingame && state.Mobile?.Deleted != false) { if (state.Mobile == null) @@ -2491,9 +2491,8 @@ namespace Server.Network int authID = pvSrc.ReadInt32(); - if (m_AuthIDWindow.ContainsKey(authID)) + if (m_AuthIDWindow.TryGetValue(authID, out AuthIDPersistence ap)) { - AuthIDPersistence ap = m_AuthIDWindow[authID]; m_AuthIDWindow.Remove(authID); state.Version = ap.Version; @@ -2685,6 +2684,7 @@ namespace Server.Network { if (m_State == null) Stop(); + if (m_State.Version != null) { m_State.BlockAllPackets = false; @@ -2706,4 +2706,4 @@ namespace Server.Network } } } -} \ No newline at end of file +} diff --git a/Server/ScriptCompiler.cs b/Server/ScriptCompiler.cs index f78c62d38..f6a41c46c 100644 --- a/Server/ScriptCompiler.cs +++ b/Server/ScriptCompiler.cs @@ -397,19 +397,14 @@ namespace Server Dictionary> table = e.IsWarning ? warnings : errors; - List list = null; - table.TryGetValue(file, out list); - - if (list == null) + if (!table.TryGetValue(file, out List list)) table[file] = list = new List(); list.Add(e); } - if (errors.Count > 0) - Console.WriteLine("failed ({0} errors, {1} warnings)", errors.Count, warnings.Count); - else - Console.WriteLine("done ({0} errors, {1} warnings)", errors.Count, warnings.Count); + Console.WriteLine(errors.Count > 0 ? "failed ({0} errors, {1} warnings)" : "done ({0} errors, {1} warnings)", + errors.Count, warnings.Count); string scriptRoot = Path.GetFullPath(Path.Combine(Core.BaseDirectory, "Scripts" + Path.DirectorySeparatorChar)); @@ -496,24 +491,16 @@ namespace Server } catch { + // ignored } } catch { + // ignored } } - public static bool Compile() - { - return Compile(false); - } - - public static bool Compile(bool debug) - { - return Compile(debug, true); - } - - public static bool Compile(bool debug, bool cache) + public static bool Compile(bool debug, bool cache = true) { EnsureDirectory("Scripts/"); EnsureDirectory("Scripts/Output/"); @@ -596,15 +583,9 @@ namespace Server { if (asm == null) { - if (m_NullCache == null) - m_NullCache = new TypeCache(null); - - return m_NullCache; + return m_NullCache ?? (m_NullCache = new TypeCache(null)); } - - m_TypeCaches.TryGetValue(asm, out TypeCache c); - - if (c == null) + if (!m_TypeCaches.TryGetValue(asm, out TypeCache c)) m_TypeCaches[asm] = c = new TypeCache(asm); return c; @@ -622,10 +603,7 @@ namespace Server for (int i = 0; type == null && i < Assemblies.Length; ++i) type = GetTypeCache(Assemblies[i]).GetTypeByFullName(fullName, ignoreCase); - if (type == null) - type = GetTypeCache(Core.Assembly).GetTypeByFullName(fullName, ignoreCase); - - return type; + return type ?? GetTypeCache(Core.Assembly).GetTypeByFullName(fullName, ignoreCase); } public static Type FindTypeByName(string name) @@ -640,10 +618,7 @@ namespace Server for (int i = 0; type == null && i < Assemblies.Length; ++i) type = GetTypeCache(Assemblies[i]).GetTypeByName(name, ignoreCase); - if (type == null) - type = GetTypeCache(Core.Assembly).GetTypeByName(name, ignoreCase); - - return type; + return type ?? GetTypeCache(Core.Assembly).GetTypeByName(name, ignoreCase); } public static void EnsureDirectory(string dir) @@ -678,10 +653,7 @@ namespace Server { public TypeCache(Assembly asm) { - if (asm == null) - Types = Type.EmptyTypes; - else - Types = asm.GetTypes(); + Types = asm == null ? Type.EmptyTypes : asm.GetTypes(); Names = new TypeTable(Types.Length); FullNames = new TypeTable(Types.Length); @@ -751,4 +723,4 @@ namespace Server return t; } } -} \ No newline at end of file +} diff --git a/Server/Server.csproj b/Server/Server.csproj index ed5babfbd..5f1395219 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -1,6 +1,6 @@  - + Debug x86 @@ -88,8 +88,8 @@ false - - ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll @@ -258,6 +258,6 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/Server/Timer.cs b/Server/Timer.cs index 35f3f53e5..9028e3cf2 100644 --- a/Server/Timer.cs +++ b/Server/Timer.cs @@ -250,8 +250,7 @@ namespace Server private static long[] m_NextPriorities = new long[8]; - private static long[] m_PriorityDelays = new long[8] - { + private static long[] m_PriorityDelays = { 0, 10, 25, @@ -291,9 +290,7 @@ namespace Server string key = t.ToString(); - hash.TryGetValue(key, out List list); - - if (list == null) + if (!hash.TryGetValue(key, out List list)) hash[key] = list = new List(); list.Add(t); @@ -603,4 +600,4 @@ namespace Server #endregion } -} \ No newline at end of file +} diff --git a/Server/Utility.cs b/Server/Utility.cs index f7fcfe25b..297a0673f 100644 --- a/Server/Utility.cs +++ b/Server/Utility.cs @@ -119,27 +119,8 @@ namespace Server private static Stack m_ConsoleColors = new Stack(); - public static Encoding UTF8 - { - get - { - if (m_UTF8 == null) - m_UTF8 = new UTF8Encoding(false, false); - - return m_UTF8; - } - } - - public static Encoding UTF8WithEncoding - { - get - { - if (m_UTF8WithEncoding == null) - m_UTF8WithEncoding = new UTF8Encoding(true, false); - - return m_UTF8WithEncoding; - } - } + public static Encoding UTF8 => m_UTF8 ?? (m_UTF8 = new UTF8Encoding(false, false)); + public static Encoding UTF8WithEncoding => m_UTF8WithEncoding ?? (m_UTF8WithEncoding = new UTF8Encoding(true, false)); public static void Separate(StringBuilder sb, string value, string separator) { @@ -153,10 +134,8 @@ namespace Server { if (str == null) return null; - if (str.Length == 0) - return string.Empty; - return string.Intern(str); + return str.Length == 0 ? string.Empty : string.Intern(str); } public static void Intern(ref string str) diff --git a/Server/app.config b/Server/app.config index d7600510c..33a3bf96b 100644 --- a/Server/app.config +++ b/Server/app.config @@ -1,24 +1,24 @@ - + - + + + + type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" + warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/> + type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" + warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/> - - diff --git a/Server/packages.config b/Server/packages.config index db32a4f66..c697f90c1 100644 --- a/Server/packages.config +++ b/Server/packages.config @@ -1,4 +1,13 @@  + + + + + + + + + - + \ No newline at end of file