diff --git a/Projects/Server/AssemblyHandler.cs b/Projects/Server/AssemblyHandler.cs index 47888693a..f21d05f60 100644 --- a/Projects/Server/AssemblyHandler.cs +++ b/Projects/Server/AssemblyHandler.cs @@ -14,6 +14,7 @@ *************************************************************************/ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -89,40 +90,41 @@ namespace Server return m_TypeCaches[asm] = new TypeCache(asm); } - public static Type FindFirstTypeForName(string name, bool ignoreCase = false, Func predicate = null) + private static bool IgnoreCaseTypeComparer(string name, Type type) => + type.FullName.InsensitiveEquals(name) || type.Name.InsensitiveEquals(name); + + private static bool CaseTypeComparer(string name, Type type) => + type.FullName.EqualsOrdinal(name) || type.Name.EqualsOrdinal(name); + + public static Type FindFirstTypeForName(string name, bool ignoreCase = false, Func predicate = null) { if (string.IsNullOrWhiteSpace(name)) { return null; } - var types = FindTypesByName(name, ignoreCase).ToList(); + var types = FindTypesByName(name, ignoreCase); + if (types.Count == 0) { return null; } - if (predicate != null) - { - return types.FirstOrDefault(predicate); - } - - if (types.Count == 1) - { - return types[0]; - } - // Try to find the closest match if there is no predicate. // Check for exact match of the FullName or Name // Then check for case-insensitive match of FullName or Name // Otherwise just return the first entry - var stringComparer = ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal; + predicate ??= ignoreCase ? IgnoreCaseTypeComparer : CaseTypeComparer; - return types.FirstOrDefault( - x => - stringComparer.Equals(x.FullName, name) || stringComparer.Equals(x.Name, name) - ) ?? - types[0]; + foreach (var type in types) + { + if (predicate(name, type)) + { + return type; + } + } + + return null; } public static List FindTypesByName(string name, bool ignoreCase = false) @@ -136,12 +138,18 @@ namespace Server for (var i = 0; i < Assemblies.Length; i++) { - types.AddRange(GetTypeCache(Assemblies[i])[name]); + foreach (var type in GetTypeCache(Assemblies[i])[name]) + { + types.Add(type); + } } if (types.Count == 0) { - types.AddRange(GetTypeCache(Core.Assembly)[name]); + foreach(var type in GetTypeCache(Core.Assembly)[name]) + { + types.Add(type); + } } return types; @@ -159,11 +167,10 @@ namespace Server public class TypeCache { private readonly Dictionary m_NameMap = new(); - private readonly Type[] m_Types; public TypeCache(Assembly asm) { - m_Types = asm?.GetTypes() ?? Type.EmptyTypes; + Types = asm?.GetTypes() ?? Type.EmptyTypes; var nameMap = new Dictionary>(); HashSet refs; @@ -181,9 +188,9 @@ namespace Server }; var aliasType = typeof(TypeAliasAttribute); - for (var i = 0; i < m_Types.Length; i++) + for (var i = 0; i < Types.Length; i++) { - var current = m_Types[i]; + var current = Types[i]; addToRefs(i, current.Name); addToRefs(i, current.Name.ToLower()); addToRefs(i, current.FullName); @@ -204,10 +211,70 @@ namespace Server } } - public IEnumerable Types => m_Types; - public IEnumerable Names => m_NameMap.Keys; + public Enumerator this[string name] => new(name, this); - public IEnumerable this[string name] => - m_NameMap.TryGetValue(name, out var value) ? value.Select(x => m_Types[x]) : Array.Empty(); + public Type[] Types { get; } + + public struct Enumerator : IEnumerable, IEnumerator + { + private readonly TypeCache _cache; + private readonly int[] _values; + private int _index; + private Type _current; + + internal Enumerator(string name, TypeCache cache) + { + _cache = cache; + _values = !cache.m_NameMap.TryGetValue(name, out var values) ? Array.Empty() : values; + _index = 0; + _current = default; + } + + public void Dispose() + { + } + + public bool MoveNext() + { + int[] localList = _values; + + while ((uint)_index < (uint)localList.Length) + { + _current = _cache.Types[_values[_index++]]; + + if (_current != null) + { + return true; + } + } + + return false; + } + + public Type Current => _current!; + + object IEnumerator.Current + { + get + { + if (_index == 0 || _index == _values.Length + 1) + { + throw new InvalidOperationException(nameof(_index)); + } + + return Current; + } + } + + void IEnumerator.Reset() + { + _index = 0; + _current = default; + } + + public IEnumerator GetEnumerator() => this; + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } } } diff --git a/Projects/Server/ContextMenus/ContextMenu.cs b/Projects/Server/ContextMenus/ContextMenu.cs index 65f771282..a58a4d0a5 100644 --- a/Projects/Server/ContextMenus/ContextMenu.cs +++ b/Projects/Server/ContextMenus/ContextMenu.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; namespace Server.ContextMenus { @@ -64,7 +63,21 @@ namespace Server.ContextMenus /// /// Returns true if this ContextMenu requires packet version 2. /// - public bool RequiresNewPacket => - Entries.Any(t => t.Number < 3000000 || t.Number > 3032767); + public bool RequiresNewPacket + { + get + { + for (var i = 0; i < Entries.Length; ++i) + { + var number = Entries[i].Number; + if (number < 3000000 || number > 3032767) + { + return true; + } + } + + return false; + } + } } } diff --git a/Projects/Server/Guild.cs b/Projects/Server/Guild.cs index 4678e7bbf..a93d0b745 100644 --- a/Projects/Server/Guild.cs +++ b/Projects/Server/Guild.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; namespace Server.Guilds { @@ -43,11 +42,31 @@ namespace Server.Guilds public abstract void Deserialize(IGenericReader reader); public abstract void OnDelete(Mobile mob); - public static BaseGuild FindByName(string name) => - World.Guilds.Values.FirstOrDefault(g => g.Name == name); + public static BaseGuild FindByName(string name) + { + foreach (var g in World.Guilds.Values) + { + if (g.Name == name) + { + return g; + } + } - public static BaseGuild FindByAbbrev(string abbr) => - World.Guilds.Values.FirstOrDefault(g => g.Abbreviation == abbr); + return null; + } + + public static BaseGuild FindByAbbrev(string abbr) + { + foreach (var g in World.Guilds.Values) + { + if (g.Abbreviation == abbr) + { + return g; + } + } + + return null; + } public static HashSet Search(string find) { diff --git a/Projects/Server/Items/Container.cs b/Projects/Server/Items/Container.cs index c1861d1e8..d22bc32a2 100644 --- a/Projects/Server/Items/Container.cs +++ b/Projects/Server/Items/Container.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using Server.Network; using Server.Utilities; using QueuePool = Server.Utilities.RefPool>; @@ -1457,7 +1456,11 @@ namespace Server.Items for (var j = 0; j < groups.Count; ++j) { var items = groups[j].ToArray(); - var total = items.Sum(t => t.Amount); + var total = 0; + foreach (var item in items) + { + total += item.Amount; + } if (total >= best) { @@ -1531,9 +1534,27 @@ namespace Server.Items return best; } - public int GetAmount(Type type, bool recurse = true) => FindItemsByType(type, recurse).Sum(t => t.Amount); + public int GetAmount(Type type, bool recurse = true) + { + var total = 0; + foreach (var item in FindItemsByType(type, recurse)) + { + total += item.Amount; + } - public int GetAmount(Type[] types, bool recurse = true) => FindItemsByType(types, recurse).Sum(t => t.Amount); + return total; + } + + public int GetAmount(Type[] types, bool recurse = true) + { + var total = 0; + foreach (var item in FindItemsByType(types, recurse)) + { + total += item.Amount; + } + + return total; + } public Item[] FindItemsByType(Type type, bool recurse = true) { diff --git a/Projects/Server/Items/Item.cs b/Projects/Server/Items/Item.cs index 6abafb23d..96022c548 100644 --- a/Projects/Server/Items/Item.cs +++ b/Projects/Server/Items/Item.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Runtime.CompilerServices; using Server.ContextMenus; using Server.Items; @@ -3619,28 +3618,27 @@ namespace Server var eable = map.GetItemsInRange(p, 0); - var items = eable.Where( - item => + var items = new List(); + foreach (var item in eable) + { + if (item is BaseMulti || item.ItemID > TileData.MaxItemValue) { - if (item is BaseMulti || item.ItemID > TileData.MaxItemValue) - { - return false; - } - - var id = item.ItemData; - - if (id.Surface) - { - var top = item.Z + id.CalcHeight; - if (top <= maxZ && top >= z) - { - z = top; - } - } - - return true; + continue; } - ).ToList(); + + var id = item.ItemData; + + if (id.Surface) + { + var top = item.Z + id.CalcHeight; + if (top <= maxZ && top >= z) + { + z = top; + } + } + + items.Add(item); + } eable.Free(); diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs index a5ede1400..bae492e7a 100644 --- a/Projects/Server/Main.cs +++ b/Projects/Server/Main.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Reflection; using System.Runtime; using System.Runtime.InteropServices; @@ -38,7 +37,9 @@ namespace Server private static bool m_Profiling; private static DateTime m_ProfileStart; private static TimeSpan m_ProfileTime; - private static bool? m_IsRunningFromXUnit; +#nullable enable + private static bool? _isRunningFromXUnit; +#nullable disable private static long m_CycleIndex; private static readonly float[] m_CyclesPerSecond = new float[127]; // Divisible by long.MaxValue @@ -58,11 +59,31 @@ namespace Server private const string assembliesConfiguration = "Data/assemblies.json"; - public static bool IsRunningFromXUnit => - m_IsRunningFromXUnit ??= AppDomain.CurrentDomain.GetAssemblies() - .Any( - a => a.FullName.InsensitiveStartsWith("XUNIT") - ); +#nullable enable + // TODO: Find a way to get rid of this + public static bool IsRunningFromXUnit + { + get + { + if (_isRunningFromXUnit != null) + { + return _isRunningFromXUnit.Value; + } + + foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) + { + if (a.FullName.InsensitiveStartsWith("xunit")) + { + _isRunningFromXUnit = true; + return true; + } + } + + _isRunningFromXUnit = false; + return false; + } + } +#nullable disable public static bool Profiling { @@ -440,9 +461,11 @@ namespace Server var assemblyPath = Path.Join(BaseDirectory, assembliesConfiguration); // Load UOContent.dll - var assemblyFiles = JsonConfig.Deserialize>(assemblyPath) - .Select(t => Path.Join(BaseDirectory, "Assemblies", t)) - .ToArray(); + var assemblyFiles = JsonConfig.Deserialize>(assemblyPath).ToArray(); + for (var i = 0; i < assemblyFiles.Length; i++) + { + assemblyFiles[i] = Path.Join(BaseDirectory, "Assemblies", assemblyFiles[i]); + } AssemblyHandler.LoadScripts(assemblyFiles); diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index 3bf10a618..cb4217516 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using Microsoft.Toolkit.HighPerformance.Extensions; @@ -6012,7 +6011,15 @@ namespace Server de.Responsible = list = new List(); } - var resp = list.FirstOrDefault(check => check.Damager == master); + DamageEntry resp = null; + foreach (var check in list) + { + if (check.Damager == master) + { + resp = check; + break; + } + } if (resp == null) { diff --git a/Projects/Server/Skills.cs b/Projects/Server/Skills.cs index d49a196f2..650146859 100644 --- a/Projects/Server/Skills.cs +++ b/Projects/Server/Skills.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using Server.Network; namespace Server @@ -806,15 +805,9 @@ namespace Server [CommandProperty(AccessLevel.Counselor)] public Skill Throwing => this[SkillName.Throwing]; - public IEnumerator GetEnumerator() - { - return m_Skills.Where(s => s != null).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return m_Skills.Where(s => s != null).GetEnumerator(); - } + public Enumerator GetEnumerator() => new(this); + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this); + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this); public override string ToString() => "..."; @@ -902,5 +895,60 @@ namespace Server Owner.OnSkillInvalidated(skill); Owner.NetState.SendSkillChange(skill); } + + public struct Enumerator : IEnumerator + { + private readonly Skills _skills; + private int _index; + private Skill _current; + + internal Enumerator(Skills skills) + { + _skills = skills; + _index = 0; + _current = default; + } + + public void Dispose() + { + } + + public bool MoveNext() + { + Skills localList = _skills; + + while ((uint)_index < (uint)localList.Length) + { + _current = localList.m_Skills[_index++]; + if (_current != null) + { + return true; + } + } + + return false; + } + + public Skill Current => _current!; + + object IEnumerator.Current + { + get + { + if (_index == 0 || _index == _skills.Length + 1) + { + throw new InvalidOperationException(nameof(_index)); + } + + return Current; + } + } + + void IEnumerator.Reset() + { + _index = 0; + _current = default; + } + } } } diff --git a/Projects/Server/TileMatrix.cs b/Projects/Server/TileMatrix.cs index b31002f8a..6363a9f7a 100644 --- a/Projects/Server/TileMatrix.cs +++ b/Projects/Server/TileMatrix.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -224,16 +223,11 @@ namespace Server var any = false; - m_TilesList.AddRange( - eable.SelectMany( - t => - { - any = true; - return t; - } - ) - .ToArray() - ); + foreach (StaticTile[] multiTiles in eable) + { + any = true; + m_TilesList.AddRange(multiTiles); + } eable.Free(); diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs index 03cb5ac57..90901775e 100644 --- a/Projects/Server/Utilities/Utility.cs +++ b/Projects/Server/Utilities/Utility.cs @@ -3,7 +3,6 @@ using System.Buffers.Binary; using System.Collections.Generic; using System.Globalization; using System.IO; -using System.Linq; using System.Net; using System.Net.Sockets; using System.Runtime.CompilerServices; @@ -742,7 +741,12 @@ namespace Server var byteIndex = 0; - var length = mems.Sum(mem => mem.Length); + var length = 0; + for (var i = 0; i < mems.Length; i++) + { + length += mems[i].Length; + } + var position = 0; var memIndex = 0; var span = mems[memIndex].Span; @@ -1386,5 +1390,7 @@ namespace Server i = (i & 0x3333333333333333UL) + ((i >> 2) & 0x3333333333333333UL); return (int)(unchecked(((i + (i >> 4)) & 0xF0F0F0F0F0F0F0FUL) * 0x101010101010101UL) >> 56); } + + } } diff --git a/Projects/UOContent/Accounting/IPLimiter.cs b/Projects/UOContent/Accounting/IPLimiter.cs index 2f9389f7e..dd2739107 100644 --- a/Projects/UOContent/Accounting/IPLimiter.cs +++ b/Projects/UOContent/Accounting/IPLimiter.cs @@ -1,4 +1,3 @@ -using System.Linq; using System.Net; using Server.Network; @@ -22,7 +21,16 @@ namespace Server.Misc MaxAddresses = ServerConfiguration.GetOrUpdateSetting("ipLimiter.maxConnectionsPerIP", 10); } - public static bool IsExempt(IPAddress ip) => Exemptions.Contains(ip); + public static bool IsExempt(IPAddress ip) + { + for (int i = 0; i < Exemptions.Length; i++) + { + if (ip.Equals(Exemptions[i])) + return true; + } + + return false; + } public static bool Verify(IPAddress ourAddress) { diff --git a/Projects/UOContent/Commands/Object Creation/Add.cs b/Projects/UOContent/Commands/Object Creation/Add.cs index 092924edb..5c2eddb9b 100644 --- a/Projects/UOContent/Commands/Object Creation/Add.cs +++ b/Projects/UOContent/Commands/Object Creation/Add.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.Text; using Server.Items; @@ -230,7 +229,14 @@ namespace Server.Commands // Handle optional constructors var paramList = ctor.GetParameters(); - var totalParams = paramList.Count(t => !t.HasDefaultValue); + var totalParams = 0; + for (var j = 0; j < paramList.Length; j++) + { + if (!paramList[j].HasDefaultValue) + { + totalParams++; + } + } if (args.Length >= totalParams && args.Length <= paramList.Length) { diff --git a/Projects/UOContent/Commands/Object Creation/AddGump.cs b/Projects/UOContent/Commands/Object Creation/AddGump.cs index e4bb04815..6ba1d00c9 100644 --- a/Projects/UOContent/Commands/Object Creation/AddGump.cs +++ b/Projects/UOContent/Commands/Object Creation/AddGump.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Network; using Server.Targeting; @@ -160,11 +159,11 @@ namespace Server.Gumps for (var i = 0; i < asms.Length; ++i) { - types = AssemblyHandler.GetTypeCache(asms[i]).Types.ToArray(); + types = AssemblyHandler.GetTypeCache(asms[i]).Types; Match(match, types, results); } - types = AssemblyHandler.GetTypeCache(Core.Assembly).Types.ToArray(); + types = AssemblyHandler.GetTypeCache(Core.Assembly).Types; Match(match, types, results); results.Sort(new TypeNameComparer()); diff --git a/Projects/UOContent/Commands/Object Creation/Categorization.cs b/Projects/UOContent/Commands/Object Creation/Categorization.cs index 189398da2..6481b5557 100644 --- a/Projects/UOContent/Commands/Object Creation/Categorization.cs +++ b/Projects/UOContent/Commands/Object Creation/Categorization.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Reflection; using Server.Items; using Server.Json; @@ -79,67 +78,69 @@ namespace Server.Commands if (ce.Matched.Count > 0) { + var objects = new CAGObject[ce.Matched.Count]; + + for (var i = 0; i < ce.Matched.Count; i++) + { + var cte = ce.Matched[i]; + if (cte.Object is Item item) + { + var itemID = item.ItemID; + + if (item is BaseAddon addon && addon.Components.Count == 1) + { + itemID = addon.Components[0].ItemID; + } + + if (itemID > TileData.MaxItemValue) + { + itemID = 1; + } + + int? hue = item.Hue & 0x7FFF; + + if ((hue & 0x4000) != 0) + { + hue = 0; + } + + objects[i] = new CAGObject + { + Type = cte.Type, + ItemID = itemID, + Hue = hue == 0 ? null : hue + }; + } + + if (cte.Object is Mobile m) + { + var itemID = ShrinkTable.Lookup(m, 1); + + int? hue = m.Hue & 0x7FFF; + + if ((hue & 0x4000) != 0) + { + hue = 0; + } + + objects[i] = new CAGObject + { + Type = cte.Type, + ItemID = itemID, + Hue = hue == 0 ? null : hue + }; + } + + throw new InvalidCastException( + $"Categorization Type Entry: {cte.Type.Name} is not a valid type." + ); + } + list.Add( new CAGJson { Category = category, - Objects = ce.Matched.Select( - cte => - { - if (cte.Object is Item item) - { - var itemID = item.ItemID; - - if (item is BaseAddon addon && addon.Components.Count == 1) - { - itemID = addon.Components[0].ItemID; - } - - if (itemID > TileData.MaxItemValue) - { - itemID = 1; - } - - int? hue = item.Hue & 0x7FFF; - - if ((hue & 0x4000) != 0) - { - hue = 0; - } - - return new CAGObject - { - Type = cte.Type, - ItemID = itemID, - Hue = hue == 0 ? null : hue - }; - } - - if (cte.Object is Mobile m) - { - var itemID = ShrinkTable.Lookup(m, 1); - - int? hue = m.Hue & 0x7FFF; - - if ((hue & 0x4000) != 0) - { - hue = 0; - } - - return new CAGObject - { - Type = cte.Type, - ItemID = itemID, - Hue = hue == 0 ? null : hue - }; - } - - throw new InvalidCastException( - $"Categorization Type Entry: {cte.Type.Name} is not a valid type." - ); - } - ) - .ToArray() + Objects = objects } ); } diff --git a/Projects/UOContent/Commands/Object Creation/Decorate.cs b/Projects/UOContent/Commands/Object Creation/Decorate.cs index e02f19a3a..58ccc5d7c 100644 --- a/Projects/UOContent/Commands/Object Creation/Decorate.cs +++ b/Projects/UOContent/Commands/Object Creation/Decorate.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using Server.Engines.Quests.Haven; using Server.Engines.Quests.Necro; using Server.Engines.Spawners; @@ -1130,10 +1129,13 @@ namespace Server.Commands { eable = map.GetItemsInRange(new Point3D(x, y, z), 0); - if (eable.Any(item => item.Z == z && item.ItemID == itemID)) + foreach (var item in eable) { - eable.Free(); - return true; + if (item.Z == z && item.ItemID == itemID) + { + eable.Free(); + return true; + } } } diff --git a/Projects/UOContent/Commands/Object Creation/DecorateMag.cs b/Projects/UOContent/Commands/Object Creation/DecorateMag.cs index 5e01b3d1a..2c25319b4 100644 --- a/Projects/UOContent/Commands/Object Creation/DecorateMag.cs +++ b/Projects/UOContent/Commands/Object Creation/DecorateMag.cs @@ -2,7 +2,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; -using System.Linq; using Server.Engines.Quests.Haven; using Server.Engines.Quests.Necro; using Server.Engines.Spawners; @@ -1127,10 +1126,13 @@ namespace Server.Commands { eable = map.GetItemsInRange(new Point3D(x, y, z), 0); - if (eable.Any(item => item.Z == z && item.ItemID == itemID)) + foreach (var item in eable) { - eable.Free(); - return true; + if (item.Z == z && item.ItemID == itemID) + { + eable.Free(); + return true; + } } } diff --git a/Projects/UOContent/Engines/ConPVP/DuelContext.cs b/Projects/UOContent/Engines/ConPVP/DuelContext.cs index 640ba2a19..e8dab53ab 100644 --- a/Projects/UOContent/Engines/ConPVP/DuelContext.cs +++ b/Projects/UOContent/Engines/ConPVP/DuelContext.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using Server.Engines.PartySystem; using Server.Factions; using Server.Gumps; @@ -1295,9 +1294,26 @@ namespace Server.Engines.ConPVP } } - public static bool CheckCombat(Mobile m) => - m.Aggressed.Any(info => info.Defender.Player && DateTime.UtcNow - info.LastCombatTime < CombatDelay) || - m.Aggressors.Any(info => info.Attacker.Player && DateTime.UtcNow - info.LastCombatTime < CombatDelay); + public static bool CheckCombat(Mobile m) + { + foreach (var info in m.Aggressed) + { + if (info.Defender.Player && DateTime.UtcNow - info.LastCombatTime < CombatDelay) + { + return true; + } + } + + foreach (var info in m.Aggressors) + { + if (info.Attacker.Player && DateTime.UtcNow - info.LastCombatTime < CombatDelay) + { + return true; + } + } + + return false; + } private static void EventSink_Login(Mobile m) { diff --git a/Projects/UOContent/Engines/Craft/Core/CraftItem.cs b/Projects/UOContent/Engines/Craft/Core/CraftItem.cs index 27505a8c5..b5c2ecda8 100644 --- a/Projects/UOContent/Engines/Craft/Core/CraftItem.cs +++ b/Projects/UOContent/Engines/Craft/Core/CraftItem.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Commands; using Server.Factions; using Server.Items; @@ -404,12 +403,13 @@ namespace Server.Engines.Craft } var eable = map.GetItemsInRange(from.Location, 2); - var found = eable.Any(item => item.Z + 16 > item.Z && item.Z + 16 > item.Z && Find(item.ItemID, itemIDs)); - eable.Free(); - - if (found) + foreach (var item in eable) { - return true; + if (item.Z + 16 > item.Z && item.Z + 16 > item.Z && Find(item.ItemID, itemIDs)) + { + eable.Free(); + return true; + } } for (var x = -2; x <= 2; ++x) @@ -449,8 +449,23 @@ namespace Server.Engines.Craft return contains; } - public bool IsQuantityType(Type[][] types) => - types.Any(check => check.Any(t => typeof(IHasQuantity).IsAssignableFrom(t))); + public bool IsQuantityType(Type[][] types) + { + for (int i = 0; i < types.Length; ++i) + { + Type[] check = types[i]; + + for (int j = 0; j < check.Length; ++j) + { + if (typeof(IHasQuantity).IsAssignableFrom(check[j])) + { + return true; + } + } + } + + return false; + } public int ConsumeQuantity(Container cont, Type[][] types, int[] amounts) { @@ -861,8 +876,7 @@ namespace Server.Engines.Craft } public bool CheckSkills( - Mobile from, Type typeRes, CraftSystem craftSystem, ref int quality, - ref bool allRequiredSkills + Mobile from, Type typeRes, CraftSystem craftSystem, ref int quality, ref bool allRequiredSkills ) => CheckSkills(from, typeRes, craftSystem, ref quality, out allRequiredSkills, true); diff --git a/Projects/UOContent/Engines/Craft/DefAlchemy.cs b/Projects/UOContent/Engines/Craft/DefAlchemy.cs index 91a9851ca..0d1b66311 100644 --- a/Projects/UOContent/Engines/Craft/DefAlchemy.cs +++ b/Projects/UOContent/Engines/Craft/DefAlchemy.cs @@ -17,7 +17,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044001; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefAlchemy()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefAlchemy(); public override double GetChanceAtMin(CraftItem item) => 0.0; diff --git a/Projects/UOContent/Engines/Craft/DefBlacksmithy.cs b/Projects/UOContent/Engines/Craft/DefBlacksmithy.cs index a2e09b687..4552d8557 100644 --- a/Projects/UOContent/Engines/Craft/DefBlacksmithy.cs +++ b/Projects/UOContent/Engines/Craft/DefBlacksmithy.cs @@ -30,7 +30,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044002; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefBlacksmithy()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefBlacksmithy(); public override CraftECA ECA => CraftECA.ChanceMinusSixtyToFourtyFive; diff --git a/Projects/UOContent/Engines/Craft/DefBowFletching.cs b/Projects/UOContent/Engines/Craft/DefBowFletching.cs index 8c55830d5..ac042499c 100644 --- a/Projects/UOContent/Engines/Craft/DefBowFletching.cs +++ b/Projects/UOContent/Engines/Craft/DefBowFletching.cs @@ -15,7 +15,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044006; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefBowFletching()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefBowFletching(); public override CraftECA ECA => CraftECA.FiftyPercentChanceMinusTenPercent; diff --git a/Projects/UOContent/Engines/Craft/DefCarpentry.cs b/Projects/UOContent/Engines/Craft/DefCarpentry.cs index c440eda2c..69445dfb4 100644 --- a/Projects/UOContent/Engines/Craft/DefCarpentry.cs +++ b/Projects/UOContent/Engines/Craft/DefCarpentry.cs @@ -15,7 +15,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044004; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefCarpentry()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefCarpentry(); public override double GetChanceAtMin(CraftItem item) => 0.5; diff --git a/Projects/UOContent/Engines/Craft/DefCartography.cs b/Projects/UOContent/Engines/Craft/DefCartography.cs index 2673457e0..0c93b0fa6 100644 --- a/Projects/UOContent/Engines/Craft/DefCartography.cs +++ b/Projects/UOContent/Engines/Craft/DefCartography.cs @@ -15,7 +15,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044008; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefCartography()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefCartography(); public override double GetChanceAtMin(CraftItem item) => 0.0; diff --git a/Projects/UOContent/Engines/Craft/DefCooking.cs b/Projects/UOContent/Engines/Craft/DefCooking.cs index 9425ff4b3..199c287cc 100644 --- a/Projects/UOContent/Engines/Craft/DefCooking.cs +++ b/Projects/UOContent/Engines/Craft/DefCooking.cs @@ -15,7 +15,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044003; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefCooking()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefCooking(); public override CraftECA ECA => CraftECA.ChanceMinusSixtyToFourtyFive; diff --git a/Projects/UOContent/Engines/Craft/DefGlassblowing.cs b/Projects/UOContent/Engines/Craft/DefGlassblowing.cs index 6dbdb7dcf..bf4793f13 100644 --- a/Projects/UOContent/Engines/Craft/DefGlassblowing.cs +++ b/Projects/UOContent/Engines/Craft/DefGlassblowing.cs @@ -16,7 +16,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044622; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefGlassblowing()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefGlassblowing(); public override double GetChanceAtMin(CraftItem item) => item.ItemType == typeof(HollowPrism) ? 0.5 : 0.0; diff --git a/Projects/UOContent/Engines/Craft/DefMasonry.cs b/Projects/UOContent/Engines/Craft/DefMasonry.cs index 52c8a8d9c..cd2d6cdea 100644 --- a/Projects/UOContent/Engines/Craft/DefMasonry.cs +++ b/Projects/UOContent/Engines/Craft/DefMasonry.cs @@ -16,7 +16,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044500; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefMasonry()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefMasonry(); public override double GetChanceAtMin(CraftItem item) => 0.0; diff --git a/Projects/UOContent/Engines/Craft/DefTailoring.cs b/Projects/UOContent/Engines/Craft/DefTailoring.cs index 8af99b50a..7d6c5ce19 100644 --- a/Projects/UOContent/Engines/Craft/DefTailoring.cs +++ b/Projects/UOContent/Engines/Craft/DefTailoring.cs @@ -23,7 +23,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044005; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefTailoring()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefTailoring(); public override CraftECA ECA => CraftECA.ChanceMinusSixtyToFourtyFive; diff --git a/Projects/UOContent/Engines/Craft/DefTinkering.cs b/Projects/UOContent/Engines/Craft/DefTinkering.cs index 6cd978e83..19324ef38 100644 --- a/Projects/UOContent/Engines/Craft/DefTinkering.cs +++ b/Projects/UOContent/Engines/Craft/DefTinkering.cs @@ -31,7 +31,7 @@ namespace Server.Engines.Craft public override int GumpTitleNumber => 1044007; - public static CraftSystem CraftSystem => m_CraftSystem ?? (m_CraftSystem = new DefTinkering()); + public static CraftSystem CraftSystem => m_CraftSystem ??= new DefTinkering(); public override double GetChanceAtMin(CraftItem item) { diff --git a/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs b/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs index 7141d68bc..2ad788ed4 100644 --- a/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs +++ b/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Mobiles; using Server.Network; using Server.Spells; @@ -192,12 +191,20 @@ namespace Server.Engines.Doom [Usage("GenLeverPuzzle"), Description("Generates lamp room and lever puzzle in doom.")] public static void GenLampPuzzle_OnCommand(CommandEventArgs e) { - if (Map.Malas.GetItemsInRange(lp_Center, 0).OfType().Any()) + var eable = Map.Malas.GetItemsInRange(lp_Center, 0); + + foreach (var item in eable) { - e.Mobile.SendMessage("Lamp room puzzle already exists: please delete the existing controller first ..."); - return; + if (item is LeverPuzzleController) + { + eable.Free(); + e.Mobile.SendMessage("Lamp room puzzle already exists: please delete the existing controller first ..."); + return; + } } + eable.Free(); + e.Mobile.SendMessage("Generating Lamp Room puzzle..."); new LeverPuzzleController().MoveToWorld(lp_Center, Map.Malas); @@ -634,7 +641,10 @@ namespace Server.Engines.Doom { IEntity m_IEntity = new Entity(Serial.Zero, RandomPointIn(m_Player.Location, 10), m_Player.Map); - var mobiles = m_IEntity.Map.GetMobilesInRange(m_IEntity.Location, 2).ToList(); + var eable = m_IEntity.Map.GetMobilesInRange(m_IEntity.Location, 2); + var mobiles = new List(); + mobiles.AddRange(eable); + eable.Free(); for (var k = 0; k < mobiles.Count; k++) { diff --git a/Projects/UOContent/Engines/Ethics/Core/Ethic.cs b/Projects/UOContent/Engines/Ethics/Core/Ethic.cs index c6859ac15..01f2cd8fb 100644 --- a/Projects/UOContent/Engines/Ethics/Core/Ethic.cs +++ b/Projects/UOContent/Engines/Ethics/Core/Ethic.cs @@ -1,4 +1,3 @@ -using System.Linq; using Server.Ethics.Evil; using Server.Ethics.Hero; using Server.Items; @@ -156,7 +155,21 @@ namespace Server.Ethics continue; } - if (!e.Mobile.GetItemsInRange(2).Any(item => item is AnkhNorth || item is AnkhWest)) + var eable = e.Mobile.GetItemsInRange(2); + var found = false; + + foreach (var item in eable) + { + if (item is AnkhNorth || item is AnkhWest) + { + found = true; + break; + } + } + + eable.Free(); + + if (!found) { continue; } diff --git a/Projects/UOContent/Engines/Factions/Core/Faction.cs b/Projects/UOContent/Engines/Factions/Core/Faction.cs index bec06efc5..e8f8f3dcd 100644 --- a/Projects/UOContent/Engines/Factions/Core/Faction.cs +++ b/Projects/UOContent/Engines/Factions/Core/Faction.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Accounting; using Server.Commands.Generic; using Server.Engines.ConPVP; @@ -275,18 +274,37 @@ namespace Server.Factions } var eable = mob.Map.GetObjectsInRange(mob.Location, range, items, mobs); - var isInstance = eable.Any(type.IsInstanceOfType); + foreach (var obj in eable) + { + if (type.IsInstanceOfType(obj)) + { + eable.Free(); + return true; + } + } + eable.Free(); - return isInstance; + return false; } public static bool IsNearType(Mobile mob, Type[] types, int range) { var eable = mob.GetObjectsInRange(range); - var found = eable.Any(obj => types.Any(t => t.IsInstanceOfType(obj))); + foreach (var obj in eable) + { + for (int i = 0; i < types.Length; i++) + { + if (types[i].IsInstanceOfType(obj)) + { + eable.Free(); + return true; + } + } + } + eable.Free(); - return found; + return false; } public void RemovePlayerState(PlayerState pl) diff --git a/Projects/UOContent/Engines/Factions/Core/Generator.cs b/Projects/UOContent/Engines/Factions/Core/Generator.cs index dc1b63ca6..13e255343 100644 --- a/Projects/UOContent/Engines/Factions/Core/Generator.cs +++ b/Projects/UOContent/Engines/Factions/Core/Generator.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; namespace Server.Factions { @@ -77,7 +76,20 @@ namespace Server.Factions } } - private static bool CheckExistence(Point3D loc, Map facet, Type type) => - facet.GetItemsInRange(loc, 0).Any(type.IsInstanceOfType); + private static bool CheckExistence(Point3D loc, Map facet, Type type) + { + var eable = facet.GetItemsInRange(loc, 0); + foreach (var item in eable) + { + if (type.IsInstanceOfType(item)) + { + eable.Free(); + return true; + } + } + + eable.Free(); + return false; + } } } diff --git a/Projects/UOContent/Engines/Factions/Core/Reflector.cs b/Projects/UOContent/Engines/Factions/Core/Reflector.cs index d802b57d0..a4da897af 100644 --- a/Projects/UOContent/Engines/Factions/Core/Reflector.cs +++ b/Projects/UOContent/Engines/Factions/Core/Reflector.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Utilities; namespace Server.Factions @@ -60,7 +59,7 @@ namespace Server.Factions { var asm = asms[i]; var tc = AssemblyHandler.GetTypeCache(asm); - var types = tc.Types.ToArray(); + var types = tc.Types; for (var j = 0; j < types.Length; ++j) { diff --git a/Projects/UOContent/Engines/Factions/Items/Power Faction Items/StormsEye.cs b/Projects/UOContent/Engines/Factions/Items/Power Faction Items/StormsEye.cs index 71c96b54d..93c0e6f20 100644 --- a/Projects/UOContent/Engines/Factions/Items/Power Faction Items/StormsEye.cs +++ b/Projects/UOContent/Engines/Factions/Items/Power Faction Items/StormsEye.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using System.Collections.Generic; using Server.Factions; using Server.Spells; using Server.Targeting; @@ -90,13 +90,19 @@ namespace Server private static void OnHit(Mobile from, Point3D origin, Map facet) { - var targets = facet.GetMobilesInRange(origin, 12) - .Where( - mob => - from.CanBeHarmful(mob, false) && mob.InLOS(new Point3D(origin, origin.Z + 1)) && - Faction.Find(mob) != null - ) - .ToList(); + var eable = facet.GetMobilesInRange(origin, 12); + var targets = new List(); + foreach (var m in eable) + { + if (from.CanBeHarmful(m, false) && + m.InLOS(new Point3D(origin, origin.Z + 1)) && + Faction.Find(m) != null) + { + targets.Add(from); + } + } + + eable.Free(); foreach (var mob in targets) { diff --git a/Projects/UOContent/Engines/Harvest/Core/HarvestDefinition.cs b/Projects/UOContent/Engines/Harvest/Core/HarvestDefinition.cs index fb1902503..5cc7412da 100644 --- a/Projects/UOContent/Engines/Harvest/Core/HarvestDefinition.cs +++ b/Projects/UOContent/Engines/Harvest/Core/HarvestDefinition.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Random; namespace Server.Engines.Harvest @@ -66,7 +65,13 @@ namespace Server.Engines.Harvest set { m_Veins = value; - VeinWeights = m_Veins.Aggregate(0, (current, t) => current + t.VeinChance); + var totalWeight = 0u; + for (var i = 0; i < m_Veins.Length; i++) + { + totalWeight += m_Veins[i].VeinChance; + } + + VeinWeights = totalWeight; } } diff --git a/Projects/UOContent/Engines/Harvest/Core/HarvestSystem.cs b/Projects/UOContent/Engines/Harvest/Core/HarvestSystem.cs index 78fa7e8fe..69cd892fc 100644 --- a/Projects/UOContent/Engines/Harvest/Core/HarvestSystem.cs +++ b/Projects/UOContent/Engines/Harvest/Core/HarvestSystem.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using Server.Items; using Server.Targeting; using Server.Utilities; @@ -9,9 +7,7 @@ namespace Server.Engines.Harvest { public abstract class HarvestSystem { - public HarvestSystem() => Definitions = new List(); - - public List Definitions { get; } + public HarvestDefinition[] Definitions { get; init; } public virtual bool CheckTool(Mobile from, Item tool) { @@ -311,11 +307,18 @@ namespace Server.Engines.Harvest return false; } - if (m.GetItemsInRange(0).Any(t => t.StackWith(m, item, false))) + var eable = m.GetItemsInRange(0); + foreach (var i in eable) { - return true; + if (i.StackWith(m, i, false)) + { + eable.Free(); + return true; + } } + eable.Free(); + item.MoveToWorld(m.Location, map); return true; } @@ -418,10 +421,22 @@ namespace Server.Engines.Harvest } } - public virtual HarvestDefinition GetDefinition() => Definitions.First(); + public virtual HarvestDefinition GetDefinition() => Definitions[0]; - public virtual HarvestDefinition GetDefinition(int tileID) => - Definitions.FirstOrDefault(check => check.Validate(tileID)); + public virtual HarvestDefinition GetDefinition(int tileID) + { + for (var i = 0; i < Definitions.Length; i++) + { + var check = Definitions[i]; + + if (check.Validate(tileID)) + { + return check; + } + } + + return null; + } public virtual void StartHarvesting(Mobile from, Item tool, object toHarvest) { diff --git a/Projects/UOContent/Engines/Harvest/Fishing.cs b/Projects/UOContent/Engines/Harvest/Fishing.cs index bb52f2a9f..6eb65a55e 100644 --- a/Projects/UOContent/Engines/Harvest/Fishing.cs +++ b/Projects/UOContent/Engines/Harvest/Fishing.cs @@ -93,7 +93,7 @@ namespace Server.Engines.Harvest }; } - Definitions.Add(fish); + Definitions = new[] { fish }; } public static Fishing System => m_System ?? (m_System = new Fishing()); diff --git a/Projects/UOContent/Engines/Harvest/Lumberjacking.cs b/Projects/UOContent/Engines/Harvest/Lumberjacking.cs index 53fc95f6b..dd4c3c2a7 100644 --- a/Projects/UOContent/Engines/Harvest/Lumberjacking.cs +++ b/Projects/UOContent/Engines/Harvest/Lumberjacking.cs @@ -117,10 +117,10 @@ namespace Server.Engines.Harvest lumber.RaceBonus = Core.ML; lumber.RandomizeVeins = Core.ML; - Definitions.Add(lumber); + Definitions = new[] { lumber }; } - public static Lumberjacking System => m_System ?? (m_System = new Lumberjacking()); + public static Lumberjacking System => m_System ??= new Lumberjacking(); public override bool CheckHarvest(Mobile from, Item tool) { diff --git a/Projects/UOContent/Engines/Harvest/Mining.cs b/Projects/UOContent/Engines/Harvest/Mining.cs index f14d63bef..843a716fb 100644 --- a/Projects/UOContent/Engines/Harvest/Mining.cs +++ b/Projects/UOContent/Engines/Harvest/Mining.cs @@ -225,8 +225,6 @@ namespace Server.Engines.Harvest OreAndStone.RaceBonus = Core.ML; OreAndStone.RandomizeVeins = Core.ML; - Definitions.Add(OreAndStone); - Sand = new HarvestDefinition { BankWidth = 8, @@ -267,7 +265,7 @@ namespace Server.Engines.Harvest Sand.Resources = res; Sand.Veins = veins; - Definitions.Add(Sand); + Definitions = new[] { OreAndStone, Sand }; } public static Mining System => m_System ?? (m_System = new Mining()); diff --git a/Projects/UOContent/Engines/Help/HelpGump.cs b/Projects/UOContent/Engines/Help/HelpGump.cs index da2dd98e1..d5b783117 100644 --- a/Projects/UOContent/Engines/Help/HelpGump.cs +++ b/Projects/UOContent/Engines/Help/HelpGump.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Server.Engines.ConPVP; using Server.Factions; using Server.Gumps; @@ -294,9 +293,12 @@ namespace Server.Engines.Help private static void EventSink_HelpRequest(Mobile m) { - if (m.NetState.Gumps.OfType().Any()) + foreach (var gump in m.NetState.Gumps) { - return; + if (gump is HelpGump) + { + return; + } } if (!PageQueue.CheckAllowedToPage(m)) diff --git a/Projects/UOContent/Gumps/HeritageTokenGump.cs b/Projects/UOContent/Gumps/HeritageTokenGump.cs index 2f95d1c9f..bd1dc0123 100644 --- a/Projects/UOContent/Gumps/HeritageTokenGump.cs +++ b/Projects/UOContent/Gumps/HeritageTokenGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Server.Items; using Server.Network; @@ -278,303 +277,441 @@ namespace Server.Gumps return; } - var types = new List(); - var cliloc = 0; + Type[] types; + int cliloc; switch (info.ButtonID) { + default: + { + types = null; + cliloc = 0; + break; + } // 7th anniversary case 0x64: - types.Add(typeof(LeggingsOfEmbers)); - cliloc = 1078147; - break; + { + types = new [] { typeof(LeggingsOfEmbers) }; + cliloc = 1078147; + break; + } case 0x65: - types.Add(typeof(RoseOfTrinsic)); - cliloc = 1062913; - break; + { + types = new [] { typeof(RoseOfTrinsic) }; + cliloc = 1062913; + break; + } case 0x66: - types.Add(typeof(ShaminoCrossbow)); - cliloc = 1062915; - break; + { + types = new [] { typeof(ShaminoCrossbow) }; + cliloc = 1062915; + break; + } case 0x67: - types.Add(typeof(TapestryOfSosaria)); - cliloc = 1062917; - break; + { + types = new [] { typeof(TapestryOfSosaria) }; + cliloc = 1062917; + break; + } case 0x68: - types.Add(typeof(HearthOfHomeFireDeed)); - cliloc = 1062919; - break; + { + types = new [] { typeof(HearthOfHomeFireDeed) }; + cliloc = 1062919; + break; + } case 0x69: - types.Add(typeof(HolySword)); - cliloc = 1062921; - break; + { + types = new [] { typeof(HolySword) }; + cliloc = 1062921; + break; + } case 0x6A: - types.Add(typeof(SamuraiHelm)); - cliloc = 1062923; - break; + { + types = new [] { typeof(SamuraiHelm) }; + cliloc = 1062923; + break; + } // 8th anniversary - /*case 0x6B: types.Add( typeof( SpiritualityHelm ) ); cliloc = 1075188; break; - case 0x6C: types.Add( typeof( ValorGauntlets ) ); cliloc = 1075192; break;*/ + /*case 0x6B: types = new [] { typeof( SpiritualityHelm ) }; cliloc = 1075188; break; + case 0x6C: types = new [] { typeof( ValorGauntlets ) }; cliloc = 1075192; break;*/ case 0x6D: - types.Add(typeof(DupresShield)); - cliloc = 1075196; - break; + { + types = new [] { typeof(DupresShield) }; + cliloc = 1075196; + break; + } case 0x6E: - types.Add(typeof(FountainOfLifeDeed)); - cliloc = 1075197; - break; + { + types = new [] { typeof(FountainOfLifeDeed) }; + cliloc = 1075197; + break; + } case 0x6F: - types.Add(typeof(DawnsMusicBox)); - cliloc = 1075198; - break; + { + types = new [] { typeof(DawnsMusicBox) }; + cliloc = 1075198; + break; + } case 0x70: - types.Add(typeof(OssianGrimoire)); - cliloc = 1078148; - break; + { + types = new [] { typeof(OssianGrimoire) }; + cliloc = 1078148; + break; + } case 0x71: - types.Add(typeof(FerretFormTalisman)); - cliloc = 1078142; - break; + { + types = new [] { typeof(FerretFormTalisman) }; + cliloc = 1078142; + break; + } case 0x72: - types.Add(typeof(SquirrelFormTalisman)); - cliloc = 1078143; - break; + { + types = new [] { typeof(SquirrelFormTalisman) }; + cliloc = 1078143; + break; + } case 0x73: - types.Add(typeof(CuSidheFormTalisman)); - cliloc = 1078144; - break; + { + types = new [] { typeof(CuSidheFormTalisman) }; + cliloc = 1078144; + break; + } case 0x74: - types.Add(typeof(ReptalonFormTalisman)); - cliloc = 1078145; - break; + { + types = new [] { typeof(ReptalonFormTalisman) }; + cliloc = 1078145; + break; + } case 0x75: - types.Add(typeof(QuiverOfInfinity)); - cliloc = 1075201; - break; + { + types = new [] { typeof(QuiverOfInfinity) }; + cliloc = 1075201; + break; + } // evil home decor case 0x76: - types.Add(typeof(BoneThroneDeed)); - types.Add(typeof(BoneCouchDeed)); - types.Add(typeof(BoneTableDeed)); - cliloc = 1074797; - break; + { + types = new [] { typeof(BoneThroneDeed), typeof(BoneCouchDeed), typeof(BoneTableDeed) }; + cliloc = 1074797; + break; + } case 0x77: - types.Add(typeof(CreepyPortraitDeed)); - types.Add(typeof(DisturbingPortraitDeed)); - types.Add(typeof(UnsettlingPortraitDeed)); - cliloc = 1078146; - break; + { + types = new [] + { + typeof(CreepyPortraitDeed), + typeof(DisturbingPortraitDeed), + typeof(UnsettlingPortraitDeed) + }; + cliloc = 1078146; + break; + } case 0x78: - types.Add(typeof(MountedPixieBlueDeed)); - types.Add(typeof(MountedPixieGreenDeed)); - types.Add(typeof(MountedPixieLimeDeed)); - types.Add(typeof(MountedPixieOrangeDeed)); - types.Add(typeof(MountedPixieWhiteDeed)); - cliloc = 1074799; - break; + { + types = new [] + { + typeof(MountedPixieBlueDeed), + typeof(MountedPixieGreenDeed), + typeof(MountedPixieLimeDeed), + typeof(MountedPixieOrangeDeed), + typeof(MountedPixieWhiteDeed) + }; + cliloc = 1074799; + break; + } case 0x79: - types.Add(typeof(HaunterMirrorDeed)); - cliloc = 1074800; - break; + { + types = new [] { typeof(HaunterMirrorDeed) }; + cliloc = 1074800; + break; + } case 0x7A: - types.Add(typeof(BedOfNailsDeed)); - cliloc = 1074801; - break; + { + types = new [] { typeof(BedOfNailsDeed) }; + cliloc = 1074801; + break; + } case 0x7B: - types.Add(typeof(SacrificialAltarDeed)); - cliloc = 1074818; - break; + { + types = new [] { typeof(SacrificialAltarDeed) }; + cliloc = 1074818; + break; + } // broken furniture case 0x7C: - types.Add(typeof(BrokenCoveredChairDeed)); - cliloc = 1076257; - break; + { + types = new [] { typeof(BrokenCoveredChairDeed) }; + cliloc = 1076257; + break; + } case 0x7D: - types.Add(typeof(BrokenBookcaseDeed)); - cliloc = 1076258; - break; + { + types = new [] { typeof(BrokenBookcaseDeed) }; + cliloc = 1076258; + break; + } case 0x7E: - types.Add(typeof(StandingBrokenChairDeed)); - cliloc = 1076259; - break; + { + types = new [] { typeof(StandingBrokenChairDeed) }; + cliloc = 1076259; + break; + } case 0x7F: - types.Add(typeof(BrokenVanityDeed)); - cliloc = 1076260; - break; + { + types = new [] { typeof(BrokenVanityDeed) }; + cliloc = 1076260; + break; + } case 0x80: - types.Add(typeof(BrokenChestOfDrawersDeed)); - cliloc = 1076261; - break; + { + types = new [] { typeof(BrokenChestOfDrawersDeed) }; + cliloc = 1076261; + break; + } case 0x81: - types.Add(typeof(BrokenArmoireDeed)); - cliloc = 1076262; - break; + { + types = new [] { typeof(BrokenArmoireDeed) }; + cliloc = 1076262; + break; + } case 0x82: - types.Add(typeof(BrokenBedDeed)); - cliloc = 1076263; - break; + { + types = new [] { typeof(BrokenBedDeed) }; + cliloc = 1076263; + break; + } case 0x83: - types.Add(typeof(BrokenFallenChairDeed)); - cliloc = 1076264; - break; + { + types = new [] { typeof(BrokenFallenChairDeed) }; + cliloc = 1076264; + break; + } // other case 0x84: - types.Add(typeof(SuitOfGoldArmorDeed)); - cliloc = 1076265; - break; + { + types = new [] { typeof(SuitOfGoldArmorDeed) }; + cliloc = 1076265; + break; + } case 0x85: - types.Add(typeof(SuitOfSilverArmorDeed)); - cliloc = 1076266; - break; + { + types = new [] { typeof(SuitOfSilverArmorDeed) }; + cliloc = 1076266; + break; + } case 0x86: - types.Add(typeof(BoilingCauldronDeed)); - cliloc = 1076267; - break; + { + types = new [] { typeof(BoilingCauldronDeed) }; + cliloc = 1076267; + break; + } case 0x87: - types.Add(typeof(GuillotineDeed)); - cliloc = 1024656; - break; + { + types = new [] { typeof(GuillotineDeed) }; + cliloc = 1024656; + break; + } case 0x88: - types.Add(typeof(CherryBlossomTreeDeed)); - cliloc = 1076268; - break; + { + types = new [] { typeof(CherryBlossomTreeDeed) }; + cliloc = 1076268; + break; + } case 0x89: - types.Add(typeof(AppleTreeDeed)); - cliloc = 1076269; - break; + { + types = new [] { typeof(AppleTreeDeed) }; + cliloc = 1076269; + break; + } case 0x8A: - types.Add(typeof(PeachTreeDeed)); - cliloc = 1076270; - break; + { + types = new [] { typeof(PeachTreeDeed) }; + cliloc = 1076270; + break; + } case 0x8B: - types.Add(typeof(HangingAxesDeed)); - cliloc = 1076271; - break; + { + types = new [] { typeof(HangingAxesDeed) }; + cliloc = 1076271; + break; + } case 0x8C: - types.Add(typeof(HangingSwordsDeed)); - cliloc = 1076272; - break; + { + types = new [] { typeof(HangingSwordsDeed) }; + cliloc = 1076272; + break; + } case 0x8D: - types.Add(typeof(BlueFancyRugDeed)); - cliloc = 1076273; - break; + { + types = new [] { typeof(BlueFancyRugDeed) }; + cliloc = 1076273; + break; + } case 0x8E: - types.Add(typeof(WoodenCoffinDeed)); - cliloc = 1076274; - break; + { + types = new [] { typeof(WoodenCoffinDeed) }; + cliloc = 1076274; + break; + } case 0x8F: - types.Add(typeof(VanityDeed)); - cliloc = 1074027; - break; + { + types = new [] { typeof(VanityDeed) }; + cliloc = 1074027; + break; + } case 0x90: - types.Add(typeof(TableWithPurpleClothDeed)); - cliloc = 1076635; - break; + { + types = new [] { typeof(TableWithPurpleClothDeed) }; + cliloc = 1076635; + break; + } case 0x91: - types.Add(typeof(TableWithBlueClothDeed)); - cliloc = 1076636; - break; + { + types = new [] { typeof(TableWithBlueClothDeed) }; + cliloc = 1076636; + break; + } case 0x92: - types.Add(typeof(TableWithRedClothDeed)); - cliloc = 1076637; - break; + { + types = new [] { typeof(TableWithRedClothDeed) }; + cliloc = 1076637; + break; + } case 0x93: - types.Add(typeof(TableWithOrangeClothDeed)); - cliloc = 1076638; - break; + { + types = new [] { typeof(TableWithOrangeClothDeed) }; + cliloc = 1076638; + break; + } case 0x94: - types.Add(typeof(UnmadeBedDeed)); - cliloc = 1076279; - break; + { + types = new [] { typeof(UnmadeBedDeed) }; + cliloc = 1076279; + break; + } case 0x95: - types.Add(typeof(CurtainsDeed)); - cliloc = 1076280; - break; + { + types = new [] { typeof(CurtainsDeed) }; + cliloc = 1076280; + break; + } case 0x96: - types.Add(typeof(ScarecrowDeed)); - cliloc = 1076281; - break; + { + types = new [] { typeof(ScarecrowDeed) }; + cliloc = 1076281; + break; + } case 0x97: - types.Add(typeof(WallTorchDeed)); - cliloc = 1076282; - break; + { + types = new [] { typeof(WallTorchDeed) }; + cliloc = 1076282; + break; + } case 0x98: - types.Add(typeof(FountainDeed)); - cliloc = 1076283; - break; + { + types = new [] { typeof(FountainDeed) }; + cliloc = 1076283; + break; + } case 0x99: - types.Add(typeof(StoneStatueDeed)); - cliloc = 1076284; - break; + { + types = new [] { typeof(StoneStatueDeed) }; + cliloc = 1076284; + break; + } case 0x9A: - types.Add(typeof(LargeFishingNetDeed)); - cliloc = 1076285; - break; + { + types = new [] { typeof(LargeFishingNetDeed) }; + cliloc = 1076285; + break; + } case 0x9B: - types.Add(typeof(SmallFishingNetDeed)); - cliloc = 1076286; - break; + { + types = new [] { typeof(SmallFishingNetDeed) }; + cliloc = 1076286; + break; + } case 0x9C: - types.Add(typeof(HouseLadderDeed)); - cliloc = 1076287; - break; + { + types = new [] { typeof(HouseLadderDeed) }; + cliloc = 1076287; + break; + } case 0x9D: - types.Add(typeof(IronMaidenDeed)); - cliloc = 1076288; - break; + { + types = new [] { typeof(IronMaidenDeed) }; + cliloc = 1076288; + break; + } case 0x9E: - types.Add(typeof(BluePlainRugDeed)); - cliloc = 1076585; - break; + { + types = new [] { typeof(BluePlainRugDeed) }; + cliloc = 1076585; + break; + } case 0x9F: - types.Add(typeof(GoldenDecorativeRugDeed)); - cliloc = 1076586; - break; + { + types = new [] { typeof(GoldenDecorativeRugDeed) }; + cliloc = 1076586; + break; + } case 0xA0: - types.Add(typeof(CinnamonFancyRugDeed)); - cliloc = 1076587; - break; + { + types = new [] { typeof(CinnamonFancyRugDeed) }; + cliloc = 1076587; + break; + } case 0xA1: - types.Add(typeof(RedPlainRugDeed)); - cliloc = 1076588; - break; + { + types = new [] { typeof(RedPlainRugDeed) }; + cliloc = 1076588; + break; + } case 0xA2: - types.Add(typeof(BlueDecorativeRugDeed)); - cliloc = 1076589; - break; + { + types = new [] { typeof(BlueDecorativeRugDeed) }; + cliloc = 1076589; + break; + } case 0xA3: - types.Add(typeof(PinkFancyRugDeed)); - cliloc = 1076590; - break; + { + types = new [] { typeof(PinkFancyRugDeed) }; + cliloc = 1076590; + break; + } case 0xA4: - types.Add(typeof(CherryBlossomTrunkDeed)); - cliloc = 1076784; - break; + { + types = new [] { typeof(CherryBlossomTrunkDeed) }; + cliloc = 1076784; + break; + } case 0xA5: - types.Add(typeof(AppleTrunkDeed)); - cliloc = 1076785; - break; + { + types = new [] { typeof(AppleTrunkDeed) }; + cliloc = 1076785; + break; + } case 0xA6: - types.Add(typeof(PeachTrunkDeed)); - cliloc = 1076786; - break; + { + types = new [] { typeof(PeachTrunkDeed) }; + cliloc = 1076786; + break; + } } - if (types.Count > 0 && cliloc > 0) + if (types?.Length > 0 && cliloc > 0) { sender.Mobile.CloseGump(); - sender.Mobile.SendGump(new ConfirmHeritageGump(m_Token, types.ToArray(), cliloc)); + sender.Mobile.SendGump(new ConfirmHeritageGump(m_Token, types, cliloc)); } else { - sender.Mobile - .SendLocalizedMessage( - 501311 - ); // This option is currently disabled, while we evaluate it for game balance. + // This option is currently disabled, while we evaluate it for game balance. + sender.Mobile.SendLocalizedMessage(501311); } } } diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index 89b5b1adc..ed60d93a8 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Accounting; using Server.ContextMenus; using Server.Engines.BulkOrders; @@ -1049,13 +1048,22 @@ namespace Server.Mobiles public static void EquipMacro(Mobile m, List list) { - if (m is PlayerMobile pm && pm.Backpack != null && pm.Alive) + if (m is PlayerMobile { Alive: true } pm && pm.Backpack != null) { var pack = pm.Backpack; foreach (var serial in list) { - var item = pack.Items.FirstOrDefault(i => i.Serial == serial); + Item item = null; + foreach (var i in pack.Items) + { + if (i.Serial == serial) + { + item = i; + break; + } + } + if (item == null) { continue; @@ -3275,12 +3283,20 @@ namespace Server.Mobiles public override void Serialize(IGenericWriter writer) { + var toRemove = new List(); + // cleanup our anti-macro table foreach (var t in m_AntiMacroTable.Values) { - var toRemove = t.Where(kvp => kvp.Value.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow) - .Select(kvp => kvp.Key) - .ToList(); + toRemove.Clear(); + + foreach (var (k, v) in t) + { + if (v.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow) + { + toRemove.Add(k); + } + } foreach (var key in toRemove) { diff --git a/Projects/UOContent/Mobiles/Special/Barracoon.cs b/Projects/UOContent/Mobiles/Special/Barracoon.cs index 84983dc40..caa77fa8c 100644 --- a/Projects/UOContent/Mobiles/Special/Barracoon.cs +++ b/Projects/UOContent/Mobiles/Special/Barracoon.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Server.Engines.CannedEvil; using Server.Items; using Server.Spells.Fifth; @@ -142,14 +141,23 @@ namespace Server.Mobiles } var eable = GetMobilesInRange(10); - var rats = eable.Aggregate(0, (c, m) => c + (m is Ratman || m is RatmanArcher || m is RatmanMage ? 1 : 0)); - eable.Free(); + var rats = 0; - if (rats >= 16) + foreach (var m in eable) { - return; + if (m is Ratman || m is RatmanArcher || m is RatmanMage) + { + rats++; + if (rats >= 16) + { + eable.Free(); + return; + } + } } + eable.Free(); + PlaySound(0x3D); rats = Utility.RandomMinMax(3, 6); diff --git a/Projects/UOContent/Spells/Chivalry/HolyLight.cs b/Projects/UOContent/Spells/Chivalry/HolyLight.cs index 1f117f7b3..ddb1896fb 100644 --- a/Projects/UOContent/Spells/Chivalry/HolyLight.cs +++ b/Projects/UOContent/Spells/Chivalry/HolyLight.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Server.Items; namespace Server.Spells.Chivalry @@ -55,14 +54,14 @@ namespace Server.Spells.Chivalry 0 ); - var targets = Caster.GetMobilesInRange(3) - .Where( - m => Caster != m && SpellHelper.ValidIndirectTarget(Caster, m) && Caster.CanBeHarmful(m, false) && - (!Core.AOS || Caster.InLOS(m)) - ); - - foreach (var m in targets) + foreach (var m in Caster.GetMobilesInRange(3)) { + if (Caster == m || !SpellHelper.ValidIndirectTarget(Caster, m) || !Caster.CanBeHarmful(m, false) || + Core.AOS && !Caster.InLOS(m)) + { + continue; + } + var damage = Math.Clamp(ComputePowerValue(10) + Utility.RandomMinMax(0, 2), 8, 24); Caster.DoHarmful(m); diff --git a/Projects/UOContent/Spells/Necromancy/Exorcism.cs b/Projects/UOContent/Spells/Necromancy/Exorcism.cs index e375630b7..996d74849 100644 --- a/Projects/UOContent/Spells/Necromancy/Exorcism.cs +++ b/Projects/UOContent/Spells/Necromancy/Exorcism.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Server.Engines.CannedEvil; using Server.Engines.PartySystem; using Server.Factions; @@ -95,12 +94,13 @@ namespace Server.Spells.Necromancy if (map != null) { - var targets = r.ChampionSpawn.GetMobilesInRange(Range).Where(IsValidTarget); - - foreach (var m in targets) - // Surprisingly, no sparkle type effects + // Surprisingly, no sparkle type effects + foreach (var m in r.ChampionSpawn.GetMobilesInRange(Range)) { - m.Location = GetNearestShrine(m); + if (IsValidTarget(m)) + { + m.Location = GetNearestShrine(m); + } } } } diff --git a/Projects/UOContent/Spells/Necromancy/PoisonStrike.cs b/Projects/UOContent/Spells/Necromancy/PoisonStrike.cs index 0fb74ab18..79d88a9d7 100644 --- a/Projects/UOContent/Spells/Necromancy/PoisonStrike.cs +++ b/Projects/UOContent/Spells/Necromancy/PoisonStrike.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Items; using Server.Mobiles; using Server.Targeting; @@ -84,13 +83,20 @@ namespace Server.Spells.Necromancy targets.Add(m); } - targets.AddRange( - m.GetMobilesInRange(2) - .Where( - targ => !(Caster is BaseCreature && targ is BaseCreature && targ != Caster && m != targ && - SpellHelper.ValidIndirectTarget(Caster, targ) && Caster.CanBeHarmful(targ, false)) - ) - ); + var eable = m.GetMobilesInRange(2); + + foreach (Mobile targ in eable) + { + if (!(Caster is BaseCreature && targ is BaseCreature) && + targ != Caster && m != targ && + SpellHelper.ValidIndirectTarget(Caster, targ) && + Caster.CanBeHarmful(targ, false)) + { + targets.Add(targ); + } + } + + eable.Free(); for (var i = 0; i < targets.Count; ++i) { diff --git a/Projects/UOContent/Spells/Seventh/GateTravel.cs b/Projects/UOContent/Spells/Seventh/GateTravel.cs index c446ee78b..aca38e4f7 100644 --- a/Projects/UOContent/Spells/Seventh/GateTravel.cs +++ b/Projects/UOContent/Spells/Seventh/GateTravel.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Server.Factions; using Server.Items; using Server.Misc; @@ -127,10 +126,16 @@ namespace Server.Spells.Seventh private bool GateExistsAt(Map map, Point3D loc) { var eable = map.GetItemsInRange(loc, 0); - var gateFound = eable.Any(item => item is Moongate || item is PublicMoongate); - eable.Free(); - return gateFound; + foreach (var item in eable) + { + if (item is Moongate || item is PublicMoongate) + { + return true; + } + } + + return false; } [DispellableField] diff --git a/Projects/UOContent/Spells/Seventh/MeteorSwarm.cs b/Projects/UOContent/Spells/Seventh/MeteorSwarm.cs index 7ab463e54..cfc11ee54 100644 --- a/Projects/UOContent/Spells/Seventh/MeteorSwarm.cs +++ b/Projects/UOContent/Spells/Seventh/MeteorSwarm.cs @@ -79,9 +79,7 @@ namespace Server.Spells.Seventh targets = new List(); } - double damage; - - damage = Core.AOS + double damage = Core.AOS ? GetNewAosDamage(51, 1, 5, playerVsPlayer) : Utility.Random(27, 22); diff --git a/Projects/UOContent/Spells/Spellweaving/ArcaneCircle.cs b/Projects/UOContent/Spells/Spellweaving/ArcaneCircle.cs index 13b2b87f0..86a2e1a8f 100644 --- a/Projects/UOContent/Spells/Spellweaving/ArcaneCircle.cs +++ b/Projects/UOContent/Spells/Spellweaving/ArcaneCircle.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Server.Items; using Server.Mobiles; @@ -105,14 +104,17 @@ namespace Server.Spells.Spellweaving var eable = map.GetItemsInRange(location, 0); - var found = eable.Any( - item => - item.Z + item.ItemData.CalcHeight == location.Z && IsValidTile(item.ItemID) - ); + foreach (var item in eable) + { + if (item.Z + item.ItemData.CalcHeight == location.Z && IsValidTile(item.ItemID)) + { + return true; + } + } eable.Free(); - return found; + return false; } public static bool IsValidTile(int itemID) => @@ -126,13 +128,19 @@ namespace Server.Spells.Spellweaving // OSI Verified: Even enemies/combatants count // Everyone gets the Arcane Focus, power capped elsewhere - weavers.AddRange( - Caster.GetMobilesInRange(1) - .Where( - m => m != Caster && m is PlayerMobile && Caster.CanBeBeneficial(m, false) && - Math.Abs(Caster.Skills.Spellweaving.Value - m.Skills.Spellweaving.Value) <= 20 - ) - ); + + var eable = Caster.GetMobilesInRange(1); + + foreach (var m in eable) + { + if (m != Caster && m is PlayerMobile && Caster.CanBeBeneficial(m, false) && + Math.Abs(Caster.Skills.Spellweaving.Value - m.Skills.Spellweaving.Value) <= 20) + { + weavers.Add(m); + } + } + + eable.Free(); return weavers; } diff --git a/Projects/UOContent/Targets/BladedItemTarget.cs b/Projects/UOContent/Targets/BladedItemTarget.cs index 51c99d5ae..fd2dba71c 100644 --- a/Projects/UOContent/Targets/BladedItemTarget.cs +++ b/Projects/UOContent/Targets/BladedItemTarget.cs @@ -72,7 +72,7 @@ namespace Server.Targets } HarvestSystem system = Lumberjacking.System; - var def = Lumberjacking.System.GetDefinition(); + var def = system.GetDefinition(); if (!system.GetHarvestDetails(from, m_Item, targeted, out var tileID, out var map, out var loc)) {