diff --git a/Source/Framework/Configuration/ConfigManager.cs b/Source/Framework/Configuration/ConfigManager.cs index 320014248..ff2b8b6a4 100644 --- a/Source/Framework/Configuration/ConfigManager.cs +++ b/Source/Framework/Configuration/ConfigManager.cs @@ -74,9 +74,9 @@ namespace Framework.Configuration return (T)Convert.ChangeType(temp, type); } - public static List GetKeysByString(string name) + public static IEnumerable GetKeysByString(string name) { - return _configList.Where(p => p.Key.Contains(name)).Select(p => p.Key).ToList(); + return _configList.Where(p => p.Key.Contains(name)).Select(p => p.Key); } static Dictionary _configList = new Dictionary(); diff --git a/Source/Framework/Database/MySqlBase.cs b/Source/Framework/Database/MySqlBase.cs index f10bf2cde..f00004720 100644 --- a/Source/Framework/Database/MySqlBase.cs +++ b/Source/Framework/Database/MySqlBase.cs @@ -202,50 +202,53 @@ namespace Framework.Database public async Task> DelayQueryHolder(SQLQueryHolder holder) { - string query = ""; - - try + return await Task.Run(() => { - using (var Connection = _connectionInfo.GetConnection()) + string query = ""; + + try { - await Connection.OpenAsync(); - - foreach (var pair in holder.m_queries) + using (var Connection = _connectionInfo.GetConnection()) { - List rows = new List(); - using (MySqlCommand cmd = Connection.CreateCommand()) + Connection.OpenAsync(); + + foreach (var pair in holder.m_queries) { - cmd.CommandText = pair.Value.stmt.CommandText; - foreach (var parameter in pair.Value.stmt.Parameters) - cmd.Parameters.AddWithValue("@" + parameter.Key, parameter.Value); - - query = cmd.CommandText; - using (var reader = await cmd.ExecuteReaderAsync()) + List rows = new List(); + using (MySqlCommand cmd = Connection.CreateCommand()) { - if (reader.HasRows) - { - while (await reader.ReadAsync()) - { - var row = new object[reader.FieldCount]; + cmd.CommandText = pair.Value.stmt.CommandText; + foreach (var parameter in pair.Value.stmt.Parameters) + cmd.Parameters.AddWithValue("@" + parameter.Key, parameter.Value); - reader.GetValues(row); - rows.Add(row); + query = cmd.CommandText; + using (var reader = cmd.ExecuteReader()) + { + if (reader.HasRows) + { + while (reader.Read()) + { + var row = new object[reader.FieldCount]; + + reader.GetValues(row); + rows.Add(row); + } } } } + + holder.SetResult(pair.Key, new SQLResult(rows)); } - - holder.SetResult(pair.Key, new SQLResult(rows)); } - } - return holder; - } - catch (MySqlException ex) - { - HandleMySQLException(ex, query); - return holder; - } + return holder; + } + catch (MySqlException ex) + { + HandleMySQLException(ex, query); + return holder; + } + }); } public void LoadPreparedStatements() @@ -359,11 +362,8 @@ namespace Framework.Database MySqlErrorCode HandleMySQLException(MySqlException ex, string query = "") { MySqlErrorCode code = (MySqlErrorCode)ex.Number; - if (ex.InnerException != null) - { - if (ex.InnerException is MySqlException) - code = (MySqlErrorCode)((MySqlException)ex.InnerException).Number; - } + if (ex.InnerException is MySqlException) + code = (MySqlErrorCode)((MySqlException)ex.InnerException).Number; switch (code) { diff --git a/Source/Framework/Networking/NetworkThread.cs b/Source/Framework/Networking/NetworkThread.cs index 1740d3ff7..7d07c8191 100644 --- a/Source/Framework/Networking/NetworkThread.cs +++ b/Source/Framework/Networking/NetworkThread.cs @@ -86,8 +86,9 @@ namespace Framework.Networking AddNewSockets(); - foreach (var socket in _Sockets.ToList()) + for (var i =0; i < _Sockets.Count; ++i) { + TSocketType socket = _Sockets[i]; if (!socket.Update()) { if (socket.IsOpen()) diff --git a/Source/Framework/Realm/RealmManager.cs b/Source/Framework/Realm/RealmManager.cs index fd9a815d0..8d9986603 100644 --- a/Source/Framework/Realm/RealmManager.cs +++ b/Source/Framework/Realm/RealmManager.cs @@ -310,7 +310,7 @@ public class RealmManager : Singleton return BattlenetRpcErrorCode.UtilServerUnknownRealm; } - public List GetRealms() { return _realms.Values.ToList(); } + public ICollection GetRealms() { return _realms.Values; } List GetSubRegions() { return _subRegions; } ConcurrentDictionary _realms = new ConcurrentDictionary(); diff --git a/Source/Game/AI/ScriptedAI/ScriptedAI.cs b/Source/Game/AI/ScriptedAI/ScriptedAI.cs index d971441ae..40f56e7df 100644 --- a/Source/Game/AI/ScriptedAI/ScriptedAI.cs +++ b/Source/Game/AI/ScriptedAI/ScriptedAI.cs @@ -711,7 +711,7 @@ namespace Game.AI public void RemoveNotExisting() { - foreach (var id in this.ToList()) + foreach (var id in this) { if (!ObjectAccessor.GetCreature(me, id)) Remove(id); diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index 800839de2..87d42c013 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -3832,7 +3832,7 @@ namespace Game.AI if (mTimedActionList.Empty()) return; int i = 0; - foreach (var holder in mTimedActionList) + foreach (var holder in mTimedActionList.ToList()) { if (i++ == 0) { diff --git a/Source/Game/BattleFields/BattleField.cs b/Source/Game/BattleFields/BattleField.cs index c62bf8f13..33f0f619f 100644 --- a/Source/Game/BattleFields/BattleField.cs +++ b/Source/Game/BattleFields/BattleField.cs @@ -1147,7 +1147,7 @@ namespace Game.BattleFields for (byte team = 0; team < SharedConst.BGTeamsCount; ++team) { - foreach (var guid in m_activePlayers[team].ToList()) + foreach (var guid in m_activePlayers[team]) { Player player = Global.ObjAccessor.FindPlayer(guid); if (player) diff --git a/Source/Game/BattleGrounds/BattleGroundManager.cs b/Source/Game/BattleGrounds/BattleGroundManager.cs index 16ade7ddd..14c27ecf4 100644 --- a/Source/Game/BattleGrounds/BattleGroundManager.cs +++ b/Source/Game/BattleGrounds/BattleGroundManager.cs @@ -59,7 +59,7 @@ namespace Game.BattleGrounds var bgs = data.m_Battlegrounds; // first one is template and should not be deleted - foreach (var pair in bgs.ToList()) + foreach (var pair in bgs) { Battleground bg = pair.Value; bg.Update(m_UpdateTimer); @@ -834,7 +834,7 @@ namespace Game.BattleGrounds public void RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uint instanceId) { var queues = bgDataStore[bgTypeId].BGFreeSlotQueue; - foreach (var bg in queues.ToList()) + foreach (var bg in queues) { if (bg.GetInstanceID() == instanceId) { diff --git a/Source/Game/BattlePets/BattlePetManager.cs b/Source/Game/BattlePets/BattlePetManager.cs index e36dd8030..c82bd7e7d 100644 --- a/Source/Game/BattlePets/BattlePetManager.cs +++ b/Source/Game/BattlePets/BattlePetManager.cs @@ -195,7 +195,7 @@ namespace Game.BattlePets { PreparedStatement stmt; - foreach (var pair in _pets.ToList()) + foreach (var pair in _pets) { switch (pair.Value.SaveInfo) { diff --git a/Source/Game/BlackMarket/BlackMarketManager.cs b/Source/Game/BlackMarket/BlackMarketManager.cs index 3e4177ea1..ed05e63c8 100644 --- a/Source/Game/BlackMarket/BlackMarketManager.cs +++ b/Source/Game/BlackMarket/BlackMarketManager.cs @@ -121,7 +121,7 @@ namespace Game.BlackMarket { SQLTransaction trans = new SQLTransaction(); // Delete completed auctions - foreach (var pair in _auctions.ToList()) + foreach (var pair in _auctions) { if (!pair.Value.IsCompleted()) continue; diff --git a/Source/Game/Chat/CommandHandler.cs b/Source/Game/Chat/CommandHandler.cs index de98469ee..893f8b8a7 100644 --- a/Source/Game/Chat/CommandHandler.cs +++ b/Source/Game/Chat/CommandHandler.cs @@ -71,7 +71,7 @@ namespace Game.Chat return true; } - public bool ExecuteCommandInTable(List table, string text, string fullcmd) + public bool ExecuteCommandInTable(ICollection table, string text, string fullcmd) { StringArguments args = new StringArguments(text); string cmd = args.NextString(); @@ -168,7 +168,7 @@ namespace Game.Chat return false; } - public bool ShowHelpForCommand(List table, string text) + public bool ShowHelpForCommand(ICollection table, string text) { StringArguments args = new StringArguments(text); if (!args.Empty()) @@ -226,7 +226,7 @@ namespace Game.Chat return ShowHelpForSubCommands(table, "", text); } - public bool ShowHelpForSubCommands(List table, string cmd, string subcmd) + public bool ShowHelpForSubCommands(ICollection table, string cmd, string subcmd) { string list = ""; foreach (var command in table) diff --git a/Source/Game/Chat/CommandManager.cs b/Source/Game/Chat/CommandManager.cs index 54a02713d..a7a7c0fe8 100644 --- a/Source/Game/Chat/CommandManager.cs +++ b/Source/Game/Chat/CommandManager.cs @@ -69,7 +69,7 @@ namespace Game.Chat } } - static bool SetDataForCommandInTable(List table, string text, uint permission, string help, string fullcommand) + static bool SetDataForCommandInTable(ICollection table, string text, uint permission, string help, string fullcommand) { StringArguments args = new StringArguments(text); string cmd = args.NextString().ToLower(); @@ -135,9 +135,9 @@ namespace Game.Chat } } - public static List GetCommands() + public static ICollection GetCommands() { - return _commands.Values.ToList(); + return _commands.Values; } static SortedDictionary _commands = new SortedDictionary(); diff --git a/Source/Game/DataStorage/Structs/A_Records.cs b/Source/Game/DataStorage/Structs/A_Records.cs index 874bd5d71..4ca4a56ac 100644 --- a/Source/Game/DataStorage/Structs/A_Records.cs +++ b/Source/Game/DataStorage/Structs/A_Records.cs @@ -23,9 +23,9 @@ namespace Game.DataStorage { public class AchievementRecord { - public LocalizedString Title; - public LocalizedString Description; - public LocalizedString Reward; + public string Title; + public string Description; + public string Reward; public AchievementFlags Flags; public short InstanceID; public ushort Supercedes; @@ -123,7 +123,7 @@ namespace Game.DataStorage public sealed class ArtifactRecord { public uint Id; - public LocalizedString Name; + public string Name; public uint UiBarOverlayColor; public uint UiBarBackgroundColor; public uint UiNameColor; @@ -137,7 +137,7 @@ namespace Game.DataStorage public sealed class ArtifactAppearanceRecord { - public LocalizedString Name; + public string Name; public uint UiSwatchColor; public float UiModelSaturation; public float UiModelOpacity; @@ -156,8 +156,8 @@ namespace Game.DataStorage public sealed class ArtifactAppearanceSetRecord { - public LocalizedString Name; - public LocalizedString Description; + public string Name; + public string Description; public ushort UiCameraID; public ushort AltHandUICameraID; public byte DisplayIndex; @@ -217,7 +217,7 @@ namespace Game.DataStorage public sealed class AuctionHouseRecord { public uint Id; - public LocalizedString Name; + public string Name; public ushort FactionID; public byte DepositRate; public byte ConsignmentRate; diff --git a/Source/Game/DataStorage/Structs/B_Records.cs b/Source/Game/DataStorage/Structs/B_Records.cs index 569048126..96f6ab303 100644 --- a/Source/Game/DataStorage/Structs/B_Records.cs +++ b/Source/Game/DataStorage/Structs/B_Records.cs @@ -33,8 +33,8 @@ namespace Game.DataStorage public sealed class BarberShopStyleRecord { - public LocalizedString DisplayName; - public LocalizedString Description; + public string DisplayName; + public string Description; public float CostModifier; public byte Type; public byte Race; @@ -60,8 +60,8 @@ namespace Game.DataStorage public sealed class BattlePetSpeciesRecord { - public LocalizedString SourceText; - public LocalizedString Description; + public string SourceText; + public string Description; public uint CreatureID; public uint IconFileDataID; public uint SummonSpellID; @@ -85,9 +85,9 @@ namespace Game.DataStorage { public uint Id; public LocalizedString Name; - public LocalizedString GameType; - public LocalizedString ShortDescription; - public LocalizedString LongDescription; + public string GameType; + public string ShortDescription; + public string LongDescription; public int IconFileDataID; public short[] MapId = new short[16]; public ushort HolidayWorldState; diff --git a/Source/Game/DataStorage/Structs/C_Records.cs b/Source/Game/DataStorage/Structs/C_Records.cs index 38aec1cf9..c65676e1f 100644 --- a/Source/Game/DataStorage/Structs/C_Records.cs +++ b/Source/Game/DataStorage/Structs/C_Records.cs @@ -74,7 +74,7 @@ namespace Game.DataStorage { public uint Id; public LocalizedString Name; - public LocalizedString Shortcut; + public string Shortcut; public ChannelDBCFlags Flags; public sbyte FactionGroup; } @@ -83,8 +83,8 @@ namespace Game.DataStorage { public string PetNameToken; public LocalizedString Name; - public LocalizedString NameFemale; - public LocalizedString NameMale; + public string NameFemale; + public string NameMale; public uint FileName; public uint CreateScreenFileDataID; public uint SelectScreenFileDataID; @@ -297,7 +297,7 @@ namespace Game.DataStorage public sealed class CreatureTypeRecord { public uint Id; - public LocalizedString Name; + public string Name; public byte Flags; } diff --git a/Source/Game/DataStorage/Structs/D_Records.cs b/Source/Game/DataStorage/Structs/D_Records.cs index efe22d70f..462a86c3f 100644 --- a/Source/Game/DataStorage/Structs/D_Records.cs +++ b/Source/Game/DataStorage/Structs/D_Records.cs @@ -49,7 +49,7 @@ namespace Game.DataStorage public sealed class DifficultyRecord { public uint Id; - public LocalizedString Name; + public string Name; public ushort GroupSizeHealthCurveID; public ushort GroupSizeDmgCurveID; public ushort GroupSizeSpellPointsCurveID; diff --git a/Source/Game/DataStorage/Structs/G_Records.cs b/Source/Game/DataStorage/Structs/G_Records.cs index f77821f7f..1da290810 100644 --- a/Source/Game/DataStorage/Structs/G_Records.cs +++ b/Source/Game/DataStorage/Structs/G_Records.cs @@ -49,8 +49,8 @@ namespace Game.DataStorage public sealed class GarrAbilityRecord { - public LocalizedString Name; - public LocalizedString Description; + public string Name; + public string Description; public uint IconFileDataID; public GarrisonAbilityFlags Flags; public ushort FactionChangeGarrAbilityID; @@ -99,9 +99,9 @@ namespace Game.DataStorage public sealed class GarrClassSpecRecord { - public LocalizedString ClassSpec; - public LocalizedString ClassSpecMale; - public LocalizedString ClassSpecFemale; + public string ClassSpec; + public string ClassSpecMale; + public string ClassSpecFemale; public ushort UiTextureAtlasMemberID; // UiTextureAtlasMember.db2 ref public ushort GarrFollItemSetID; public byte FollowerClassLimit; @@ -156,7 +156,7 @@ namespace Game.DataStorage public sealed class GarrPlotRecord { public uint Id; - public LocalizedString Name; + public string Name; public uint AllianceConstructObjID; public uint HordeConstructObjID; public byte UiCategoryID; diff --git a/Source/Game/DataStorage/Structs/I_Records.cs b/Source/Game/DataStorage/Structs/I_Records.cs index 1d55193a9..301904fdc 100644 --- a/Source/Game/DataStorage/Structs/I_Records.cs +++ b/Source/Game/DataStorage/Structs/I_Records.cs @@ -228,7 +228,7 @@ namespace Game.DataStorage public sealed class ItemLimitCategoryRecord { public uint Id; - public LocalizedString Name; + public string Name; public byte Quantity; public byte Flags; } @@ -277,7 +277,7 @@ namespace Game.DataStorage public sealed class ItemSearchNameRecord { public ulong AllowableRace; - public LocalizedString Display; + public string Display; public uint Id; public uint[] Flags = new uint[3]; public ushort ItemLevel; diff --git a/Source/Game/DataStorage/Structs/M_Records.cs b/Source/Game/DataStorage/Structs/M_Records.cs index 876429cd0..166620c01 100644 --- a/Source/Game/DataStorage/Structs/M_Records.cs +++ b/Source/Game/DataStorage/Structs/M_Records.cs @@ -29,7 +29,7 @@ namespace Game.DataStorage public sealed class MapRecord { public uint Id; - public uint Directory; + public string Directory; public LocalizedString MapName; public string MapDescription0; // Horde public string MapDescription1; // Alliance diff --git a/Source/Game/DataStorage/Structs/P_Records.cs b/Source/Game/DataStorage/Structs/P_Records.cs index 96190cd52..8c6016b10 100644 --- a/Source/Game/DataStorage/Structs/P_Records.cs +++ b/Source/Game/DataStorage/Structs/P_Records.cs @@ -186,7 +186,7 @@ namespace Game.DataStorage public sealed class PvpTalentRecord { public uint Id; - public LocalizedString Description; + public string Description; public uint SpellID; public uint OverridesSpellID; public int ActionBarSpellID; diff --git a/Source/Game/DataStorage/Structs/Q_Records.cs b/Source/Game/DataStorage/Structs/Q_Records.cs index a0a340256..b2816123c 100644 --- a/Source/Game/DataStorage/Structs/Q_Records.cs +++ b/Source/Game/DataStorage/Structs/Q_Records.cs @@ -43,7 +43,7 @@ namespace Game.DataStorage public sealed class QuestSortRecord { public uint Id; - public LocalizedString SortName; + public string SortName; public byte UiOrderIndex; } diff --git a/Source/Game/DataStorage/Structs/S_Records.cs b/Source/Game/DataStorage/Structs/S_Records.cs index 933410a29..1a9f44100 100644 --- a/Source/Game/DataStorage/Structs/S_Records.cs +++ b/Source/Game/DataStorage/Structs/S_Records.cs @@ -40,7 +40,7 @@ namespace Game.DataStorage public sealed class ScenarioRecord { public uint Id; - public LocalizedString Name; + public string Name; public ushort AreaTableID; public byte Flags; public byte Type; @@ -49,8 +49,8 @@ namespace Game.DataStorage public sealed class ScenarioStepRecord { public uint Id; - public LocalizedString Description; - public LocalizedString Title; + public string Description; + public string Title; public ushort ScenarioID; public ushort Supersedes; // Used in conjunction with Proving Grounds scenarios, when sequencing steps (Not using step order?) public ushort RewardQuestID; @@ -97,8 +97,8 @@ namespace Game.DataStorage { public uint Id; public LocalizedString DisplayName; - public LocalizedString Description; - public LocalizedString AlternateVerb; + public string Description; + public string AlternateVerb; public ushort Flags; public SkillCategory CategoryID; public byte CanLink; @@ -240,7 +240,7 @@ namespace Game.DataStorage public sealed class SpellCategoryRecord { public uint Id; - public LocalizedString Name; + public string Name; public int ChargeRecoveryTime; public SpellCategoryFlags Flags; public byte UsesPerWeek; @@ -321,7 +321,7 @@ namespace Game.DataStorage public sealed class SpellFocusObjectRecord { public uint Id; - public LocalizedString Name; + public string Name; } public sealed class SpellInterruptsRecord @@ -495,7 +495,7 @@ namespace Game.DataStorage public sealed class SpellShapeshiftFormRecord { public uint Id; - public LocalizedString Name; + public string Name; public float DamageVariance; public SpellShapeshiftFormFlags Flags; public ushort CombatRoundTime; diff --git a/Source/Game/DataStorage/Structs/T_Records.cs b/Source/Game/DataStorage/Structs/T_Records.cs index fec9202a6..26d1917bf 100644 --- a/Source/Game/DataStorage/Structs/T_Records.cs +++ b/Source/Game/DataStorage/Structs/T_Records.cs @@ -81,14 +81,14 @@ namespace Game.DataStorage public sealed class TotemCategoryRecord { public uint Id; - public LocalizedString Name; + public string Name; public uint TotemCategoryMask; public byte TotemCategoryType; } public sealed class ToyRecord { - public LocalizedString SourceText; + public string SourceText; public uint ItemID; public byte Flags; public byte SourceTypeEnum; @@ -103,7 +103,7 @@ namespace Game.DataStorage public sealed class TransmogSetRecord { - public LocalizedString Name; + public string Name; public ushort ParentTransmogSetID; public ushort UIOrder; public byte ExpansionID; @@ -117,7 +117,7 @@ namespace Game.DataStorage public sealed class TransmogSetGroupRecord { - public LocalizedString Name; + public string Name; public uint Id; } diff --git a/Source/Game/DataStorage/Structs/V_Records.cs b/Source/Game/DataStorage/Structs/V_Records.cs index 414037d96..263011e4d 100644 --- a/Source/Game/DataStorage/Structs/V_Records.cs +++ b/Source/Game/DataStorage/Structs/V_Records.cs @@ -109,7 +109,6 @@ namespace Game.DataStorage public uint EnterUISoundID; public ushort ExitUISoundID; - public bool CanEnterOrExit() { return (Flags.HasAnyFlag(VehicleSeatFlags.CanEnterOrExit) || diff --git a/Source/Game/Entities/Player/Player.DB.cs b/Source/Game/Entities/Player/Player.DB.cs index f1f00ec0b..c143258d9 100644 --- a/Source/Game/Entities/Player/Player.DB.cs +++ b/Source/Game/Entities/Player/Player.DB.cs @@ -1972,10 +1972,9 @@ namespace Game.Entities stmt.AddValue(0, GetGUID().GetCounter()); trans.Append(stmt); - Dictionary talents; for (byte group = 0; group < PlayerConst.MaxSpecializations; ++group) { - talents = GetTalentMap(group); + Dictionary talents = GetTalentMap(group); foreach (var pair in talents.ToList()) { if (pair.Value == PlayerSpellState.Removed) @@ -1998,7 +1997,7 @@ namespace Game.Entities for (byte group = 0; group < PlayerConst.MaxSpecializations; ++group) { - talents = GetPvpTalentMap(group); + Dictionary talents = GetPvpTalentMap(group); foreach (var pair in talents.ToList()) { if (pair.Value == PlayerSpellState.Removed) diff --git a/Source/Game/Entities/Unit/Unit.Combat.cs b/Source/Game/Entities/Unit/Unit.Combat.cs index 978deddfc..c1dc5180d 100644 --- a/Source/Game/Entities/Unit/Unit.Combat.cs +++ b/Source/Game/Entities/Unit/Unit.Combat.cs @@ -2338,8 +2338,9 @@ namespace Game.Entities vSchoolAbsorbCopy.Sort(new AbsorbAuraOrderPred()); // absorb without mana cost - foreach (var absorbAurEff in vSchoolAbsorbCopy.ToList()) + for (var i = 0; i < vSchoolAbsorbCopy.Count; ++i ) { + var absorbAurEff = vSchoolAbsorbCopy[i]; if (damageInfo.GetDamage() == 0) break; diff --git a/Source/Game/Entities/Unit/Unit.Fields.cs b/Source/Game/Entities/Unit/Unit.Fields.cs index a510b6e12..ce1daf569 100644 --- a/Source/Game/Entities/Unit/Unit.Fields.cs +++ b/Source/Game/Entities/Unit/Unit.Fields.cs @@ -578,7 +578,7 @@ namespace Game.Entities return obj.GetExactDist2dSq(i_source) <= i_distSq; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var target in objs) { @@ -598,7 +598,7 @@ namespace Game.Entities } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var target in objs) { @@ -614,7 +614,7 @@ namespace Game.Entities } } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var target in objs) { diff --git a/Source/Game/Entities/Unit/Unit.Pets.cs b/Source/Game/Entities/Unit/Unit.Pets.cs index 7fa9fe429..bf1248e7d 100644 --- a/Source/Game/Entities/Unit/Unit.Pets.cs +++ b/Source/Game/Entities/Unit/Unit.Pets.cs @@ -566,8 +566,9 @@ namespace Game.Entities public void GetAllMinionsByEntry(List Minions, uint entry) { - foreach (var unit in m_Controlled) + for (var i = 0; i < m_Controlled.Count; ++i) { + Unit unit = m_Controlled[i]; if (unit.GetEntry() == entry && unit.IsSummon()) // minion, actually Minions.Add(unit.ToTempSummon()); } @@ -575,8 +576,9 @@ namespace Game.Entities void RemoveAllMinionsByEntry(uint entry) { - foreach (var unit in m_Controlled.ToList()) + for (var i = 0; i < m_Controlled.Count; ++i) { + Unit unit = m_Controlled[i]; if (unit.GetEntry() == entry && unit.IsTypeId(TypeId.Unit) && unit.ToCreature().IsSummon()) // minion, actually unit.ToTempSummon().UnSummon(); diff --git a/Source/Game/Entities/Unit/Unit.Spells.cs b/Source/Game/Entities/Unit/Unit.Spells.cs index efc8c9042..5cbc08ca2 100644 --- a/Source/Game/Entities/Unit/Unit.Spells.cs +++ b/Source/Game/Entities/Unit/Unit.Spells.cs @@ -2290,11 +2290,11 @@ namespace Game.Entities public void RemoveAllGroupBuffsFromCaster(ObjectGuid casterGUID) { - foreach (var iter in m_ownedAuras.KeyValueList) + foreach (var pair in GetOwnedAuras()) { - Aura aura = iter.Value; + Aura aura = pair.Value; if (aura.GetCasterGUID() == casterGUID && aura.GetSpellInfo().IsGroupBuff()) - RemoveOwnedAura(iter); + RemoveOwnedAura(pair); } } @@ -3345,20 +3345,19 @@ namespace Game.Entities // Such situation occurs when player is logging in inside an instance and fails the entry check for any reason. // The aura that was loaded from db (indirectly, via linked casts) gets removed before it has a chance // to register in m_appliedAuras - var list = GetOwnedAuras().ToList(); - for (var i = 0; i < list.Count; i++) + foreach (var pair in GetOwnedAuras()) { - Aura aura = list[i].Value; + Aura aura = pair.Value; if (aura.GetCasterGUID() != GetGUID() && aura.IsSingleTarget()) { if (onPhaseChange) - RemoveOwnedAura(list[i]); + RemoveOwnedAura(pair); else { Unit caster = aura.GetCaster(); if (!caster || !caster.IsInPhase(this)) - RemoveOwnedAura(list[i]); + RemoveOwnedAura(pair); } } } @@ -3372,12 +3371,13 @@ namespace Game.Entities } } // All aura base removes should go threw this function! - public void RemoveOwnedAura(KeyValuePair pair, AuraRemoveMode removeMode = AuraRemoveMode.Default) + public void RemoveOwnedAura(KeyValuePair keyValuePair, AuraRemoveMode removeMode = AuraRemoveMode.Default) { - Aura aura = pair.Value; + Aura aura = keyValuePair.Value; + Contract.Assert(!aura.IsRemoved()); - m_ownedAuras.Remove(pair); + m_ownedAuras.Remove(keyValuePair); m_removedAuras.Add(aura); // Unregister single target aura @@ -3388,32 +3388,37 @@ namespace Game.Entities } public void RemoveOwnedAura(uint spellId, ObjectGuid casterGUID = default(ObjectGuid), uint reqEffMask = 0, AuraRemoveMode removeMode = AuraRemoveMode.Default) { - var list = m_ownedAuras.Where(p => p.Key == spellId); - foreach (var pair in list.ToList()) + foreach (var pair in GetOwnedAuras()) { + if (pair.Key != spellId) + continue; + if (((pair.Value.GetEffectMask() & reqEffMask) == reqEffMask) && (casterGUID.IsEmpty() || pair.Value.GetCasterGUID() == casterGUID)) RemoveOwnedAura(pair, removeMode); } } - public void RemoveOwnedAura(Aura aura, AuraRemoveMode removeMode = AuraRemoveMode.Default) + public void RemoveOwnedAura(Aura auraToRemove, AuraRemoveMode removeMode = AuraRemoveMode.Default) { - if (aura.IsRemoved()) + if (auraToRemove.IsRemoved()) return; - Contract.Assert(aura.GetOwner() == this); + Contract.Assert(auraToRemove.GetOwner() == this); if (removeMode == AuraRemoveMode.None) { - Log.outError(LogFilter.Spells, "Unit.RemoveOwnedAura() called with unallowed removeMode AURA_REMOVE_NONE, spellId {0}", aura.GetId()); + Log.outError(LogFilter.Spells, "Unit.RemoveOwnedAura() called with unallowed removeMode AURA_REMOVE_NONE, spellId {0}", auraToRemove.GetId()); return; } - uint spellId = aura.GetId(); + uint spellId = auraToRemove.GetId(); - var range = m_ownedAuras.Where(p => p.Key == spellId); - foreach (var pair in range.ToList()) + var range = m_ownedAuras.LookupByKey(spellId); + foreach (var pair in GetOwnedAuras()) { - if (pair.Value == aura) + if (pair.Key != spellId) + continue; + + if (pair.Value == auraToRemove) { RemoveOwnedAura(pair, removeMode); return; @@ -3425,25 +3430,27 @@ namespace Game.Entities public void RemoveAurasDueToSpell(uint spellId, ObjectGuid casterGUID = default(ObjectGuid), uint reqEffMask = 0, AuraRemoveMode removeMode = AuraRemoveMode.Default) { - var list = m_appliedAuras.LookupByKey(spellId); - if (list.Empty()) - return; - - foreach (var spell in list.ToList()) + foreach (var pair in GetAppliedAuras()) { - Aura aura = spell.GetBase(); - if (((aura.GetEffectMask() & reqEffMask) == reqEffMask) - && (casterGUID.IsEmpty() || aura.GetCasterGUID() == casterGUID)) + if (pair.Key != spellId) + continue; + + Aura aura = pair.Value.GetBase(); + if (((aura.GetEffectMask() & reqEffMask) == reqEffMask) && (casterGUID.IsEmpty() || aura.GetCasterGUID() == casterGUID)) { - RemoveAura(spell, removeMode); + RemoveAura(pair, removeMode); } } } public void RemoveAurasDueToSpellByDispel(uint spellId, uint dispellerSpellId, ObjectGuid casterGUID, Unit dispeller, byte chargesRemoved = 1) { var range = m_ownedAuras.LookupByKey(spellId); - foreach (var aura in range) + foreach (var pair in GetOwnedAuras()) { + if (pair.Key != spellId) + continue; + + Aura aura = pair.Value; if (aura.GetCasterGUID() == casterGUID) { DispelInfo dispelInfo = new DispelInfo(dispeller, dispellerSpellId, chargesRemoved); @@ -3458,7 +3465,6 @@ namespace Game.Entities // Call AfterDispel hook on AuraScript aura.CallScriptAfterDispel(dispelInfo); - return; } } @@ -3523,7 +3529,7 @@ namespace Game.Entities uint spellId = aurApp.GetBase().GetId(); var range = m_appliedAuras.Where(p => p.Key == spellId); - foreach (var pair in range.ToList()) + foreach (var pair in range) { if (aurApp == pair.Value) { @@ -3568,7 +3574,7 @@ namespace Game.Entities public void RemoveAppliedAuras(Func check) { - foreach (var pair in m_appliedAuras.KeyValueList) + foreach (var pair in GetAppliedAuras()) { if (check(pair.Value)) RemoveAura(pair); @@ -3577,7 +3583,7 @@ namespace Game.Entities public void RemoveOwnedAuras(Func check) { - foreach (var pair in m_ownedAuras) + foreach (var pair in GetOwnedAuras()) { if (check(pair.Value)) RemoveOwnedAura(pair); @@ -3627,7 +3633,7 @@ namespace Game.Entities foreach (var pair in GetOwnedAuras()) { var appMap = pair.Value.GetApplicationMap(); - foreach (var aurApp in appMap.Values.ToList()) + foreach (var aurApp in appMap.Values) { Unit target = aurApp.GetTarget(); if (target == this) @@ -3681,6 +3687,7 @@ namespace Game.Entities { if (pair.Value == null) continue; + Aura aura = pair.Value; if (!aura.GetSpellInfo().HasAura(GetMap().GetDifficultyID(), type)) RemoveOwnedAura(pair, AuraRemoveMode.Default); @@ -4174,9 +4181,10 @@ namespace Game.Entities } bool remove = false; - for (var i = 0; i < m_appliedAuras.KeyValueList.Count; i++) + var appliedAuraList = GetAppliedAuras(); + for (var i = 0; i < appliedAuraList.Count; i++) { - var app = m_appliedAuras.KeyValueList[i]; + var app = appliedAuraList[i]; if (remove) { remove = false; @@ -4187,8 +4195,9 @@ namespace Game.Entities continue; RemoveAura(app, AuraRemoveMode.Default); - if (i == m_appliedAuras.KeyValueList.Count - 1) + if (i == appliedAuraList.Count - 1) break; + remove = true; } } diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 4e9cb9002..18dd47f3a 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -202,14 +202,15 @@ namespace Game.Entities Aura i_aura = app.Value; if (i_aura == null) continue; + i_aura.UpdateOwner(diff, this); } // remove expired auras - do that after updates(used in scripts?) - foreach (var aura in GetOwnedAuras()) + foreach (var pair in GetOwnedAuras()) { - if (aura.Value != null && aura.Value.IsExpired()) - RemoveOwnedAura(aura, AuraRemoveMode.Expire); + if (pair.Value != null && pair.Value.IsExpired()) + RemoveOwnedAura(pair, AuraRemoveMode.Expire); } foreach (var aura in m_visibleAurasToUpdate) @@ -221,8 +222,9 @@ namespace Game.Entities if (!m_gameObj.Empty()) { - foreach (var go in m_gameObj.ToList()) + for (var i = 0; i < m_gameObj.Count; ++i) { + GameObject go = m_gameObj[i]; if (!go.isSpawned()) { go.SetOwnerGUID(ObjectGuid.Empty); @@ -547,8 +549,9 @@ namespace Game.Entities public void RemoveDynObject(uint spellId) { - foreach (var dynObj in m_dynObj.ToList()) + for (var i = 0; i < m_dynObj.Count; ++i) { + var dynObj = m_dynObj[i]; if (dynObj.GetSpellId() == spellId) dynObj.Remove(); } @@ -699,8 +702,9 @@ namespace Game.Entities if (m_areaTrigger.Empty()) return; - foreach (var areaTrigger in m_areaTrigger.ToList()) + for (var i = 0; i < m_areaTrigger.Count; ++i) { + AreaTrigger areaTrigger = m_areaTrigger[i]; if (areaTrigger.GetSpellId() == spellId) areaTrigger.Remove(); } @@ -710,6 +714,7 @@ namespace Game.Entities { if (m_areaTrigger.Empty()) return; + foreach (AreaTrigger areaTrigger in m_areaTrigger) { if (areaTrigger.GetAuraEffect() == aurEff) diff --git a/Source/Game/Entities/Vehicle.cs b/Source/Game/Entities/Vehicle.cs index ffb8bd716..9d4074b59 100644 --- a/Source/Game/Entities/Vehicle.cs +++ b/Source/Game/Entities/Vehicle.cs @@ -476,24 +476,26 @@ namespace Game.Entities public void RemovePendingEventsForSeat(sbyte seatId) { - foreach (var Event in _pendingJoinEvents.ToList()) + for (var i = 0; i < _pendingJoinEvents.Count; ++i) { - if (Event.Seat.Key == seatId) + var joinEvent = _pendingJoinEvents[i]; + if (joinEvent.Seat.Key == seatId) { - Event.ScheduleAbort(); - _pendingJoinEvents.Remove(Event); + joinEvent.ScheduleAbort(); + _pendingJoinEvents.Remove(joinEvent); } } } public void RemovePendingEventsForPassenger(Unit passenger) { - foreach (var Event in _pendingJoinEvents.ToList()) + for (var i = 0; i< _pendingJoinEvents.Count; ++i) { - if (Event.Passenger == passenger) + var joinEvent = _pendingJoinEvents[i]; + if (joinEvent.Passenger == passenger) { - Event.ScheduleAbort(); - _pendingJoinEvents.Remove(Event); + joinEvent.ScheduleAbort(); + _pendingJoinEvents.Remove(joinEvent); } } } diff --git a/Source/Game/Events/GameEventManager.cs b/Source/Game/Events/GameEventManager.cs index 719c78321..24eb5d48e 100644 --- a/Source/Game/Events/GameEventManager.cs +++ b/Source/Game/Events/GameEventManager.cs @@ -1687,13 +1687,13 @@ namespace Game _activate = activate; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) if (creature.IsInWorld && creature.IsAIEnabled) creature.GetAI().sOnGameEvent(_activate, _eventId); } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var gameobject in objs) if (gameobject.IsInWorld) diff --git a/Source/Game/Garrisons/GarrisonManager.cs b/Source/Game/Garrisons/GarrisonManager.cs index c303564b3..5533ba043 100644 --- a/Source/Game/Garrisons/GarrisonManager.cs +++ b/Source/Game/Garrisons/GarrisonManager.cs @@ -245,7 +245,7 @@ namespace Game.Garrisons if (slots[0] > forcedAbilities.Count + abilityList.Count) { List classSpecAbilities = GetClassSpecAbilities(follower, faction); - List classSpecAbilitiesTemp = classSpecAbilities.Except(forcedAbilities).ToList(); + IEnumerable classSpecAbilitiesTemp = classSpecAbilities.Except(forcedAbilities); abilityList = classSpecAbilitiesTemp.Union(abilityList).ToList(); abilityList.RandomResize((uint)Math.Max(0, slots[0] - forcedAbilities.Count)); diff --git a/Source/Game/Garrisons/GarrisonMap.cs b/Source/Game/Garrisons/GarrisonMap.cs index ceb609df7..db38fe6f6 100644 --- a/Source/Game/Garrisons/GarrisonMap.cs +++ b/Source/Game/Garrisons/GarrisonMap.cs @@ -108,9 +108,9 @@ namespace Game.Garrisons Log.outDebug(LogFilter.Maps, "{0} GameObjects and {1} Creatures loaded for grid {2} on map {3}", i_gameObjects, i_creatures, i_grid.GetGridId(), i_map.GetId()); } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { - List plots = i_garrison.GetPlots().ToList(); + ICollection plots = i_garrison.GetPlots(); if (!plots.Empty()) { CellCoord cellCoord = i_cell.GetCellCoord(); diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index 3971805f2..271585714 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -24,19 +24,20 @@ using Game.Spells; using System; using System.Collections.Generic; using System.Linq; +using System.Collections.Concurrent; namespace Game.Maps { public abstract class Notifier { - public virtual void Visit(ICollection objs) { } - public virtual void Visit(ICollection objs) { } - public virtual void Visit(ICollection objs) { } - public virtual void Visit(ICollection objs) { } - public virtual void Visit(ICollection objs) { } - public virtual void Visit(ICollection objs) { } - public virtual void Visit(ICollection objs) { } - public virtual void Visit(ICollection objs) { } + public virtual void Visit(IList objs) { } + public virtual void Visit(IList objs) { } + public virtual void Visit(IList objs) { } + public virtual void Visit(IList objs) { } + public virtual void Visit(IList objs) { } + public virtual void Visit(IList objs) { } + public virtual void Visit(IList objs) { } + public virtual void Visit(IList objs) { } public void CreatureUnitRelocationWorker(Creature c, Unit u) { @@ -64,16 +65,16 @@ namespace Game.Maps _mask = mask; } - public void Visit(ICollection collection) { _notifier.Visit(collection); } - public void Visit(ICollection creatures) { _notifier.Visit(creatures); } - public void Visit(ICollection areatriggers) { _notifier.Visit(areatriggers); } - public void Visit(ICollection conversations) { _notifier.Visit(conversations); } - public void Visit(ICollection gameobjects) { _notifier.Visit(gameobjects); } - public void Visit(ICollection dynamicobjects) { _notifier.Visit(dynamicobjects); } - public void Visit(ICollection corpses) { _notifier.Visit(corpses); } - public void Visit(ICollection players) { _notifier.Visit(players); } + public void Visit(IList collection) { _notifier.Visit(collection); } + public void Visit(IList creatures) { _notifier.Visit(creatures); } + public void Visit(IList areatriggers) { _notifier.Visit(areatriggers); } + public void Visit(IList conversations) { _notifier.Visit(conversations); } + public void Visit(IList gameobjects) { _notifier.Visit(gameobjects); } + public void Visit(IList dynamicobjects) { _notifier.Visit(dynamicobjects); } + public void Visit(IList corpses) { _notifier.Visit(corpses); } + public void Visit(IList players) { _notifier.Visit(players); } - public void Visit(Dictionary dict) { Visit(dict.Values); } + public void Visit(Dictionary dict) { Visit(dict.Values.ToList()); } Notifier _notifier; internal GridMapTypeMask _mask; @@ -89,7 +90,7 @@ namespace Game.Maps i_visibleNow = new List(); } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { @@ -171,7 +172,7 @@ namespace Game.Maps i_object = obj; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -191,7 +192,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -204,7 +205,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var dynamicObj in objs) { @@ -225,7 +226,7 @@ namespace Game.Maps { public PlayerRelocationNotifier(Player player) : base(player) { } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { base.Visit(objs); @@ -242,13 +243,13 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { base.Visit(objs); bool relocated_for_ai = (i_player == i_player.seerView); - foreach (var creature in objs.ToList()) + foreach (var creature in objs) { vis_guids.Remove(creature.GetGUID()); @@ -267,7 +268,7 @@ namespace Game.Maps i_creature = c; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -278,7 +279,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { if (!i_creature.IsAlive()) return; @@ -305,7 +306,7 @@ namespace Game.Maps i_radius = radius; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -324,7 +325,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -355,7 +356,7 @@ namespace Game.Maps isCreature = unit.IsTypeId(TypeId.Unit); } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -380,9 +381,9 @@ namespace Game.Maps skipped_receiver = skipped; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { - foreach (var player in objs.ToList()) + foreach (var player in objs) { if (!player.IsInPhase(i_source)) continue; @@ -403,7 +404,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -427,7 +428,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { @@ -474,9 +475,9 @@ namespace Game.Maps i_timeDiff = diff; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { - foreach (var obj in objs.ToList()) + foreach (var obj in objs) { if (obj.IsTypeId(TypeId.Player) || obj.IsTypeId(TypeId.Corpse)) continue; @@ -497,7 +498,7 @@ namespace Game.Maps action = _action; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) if (player.IsInPhase(_searcher)) @@ -516,7 +517,7 @@ namespace Game.Maps Do = _Do; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -537,7 +538,7 @@ namespace Game.Maps _searcher = searcher; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) if (obj.IsInPhase(_searcher)) @@ -557,7 +558,7 @@ namespace Game.Maps i_do = _do; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { @@ -605,12 +606,12 @@ namespace Game.Maps public class ResetNotifier : Notifier { - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) player.ResetAllNotifies(); } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) creature.ResetAllNotifies(); @@ -625,7 +626,7 @@ namespace Game.Maps worldObject = obj; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -639,7 +640,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -650,7 +651,7 @@ namespace Game.Maps } } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { @@ -691,7 +692,7 @@ namespace Game.Maps Do = _Do; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -830,7 +831,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { // already found if (i_object) @@ -898,7 +899,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { @@ -959,7 +960,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { @@ -1014,7 +1015,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { // already found if (i_object) @@ -1047,7 +1048,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var go in objs) { @@ -1074,7 +1075,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { @@ -1097,7 +1098,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -1112,7 +1113,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -1141,7 +1142,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -1153,7 +1154,7 @@ namespace Game.Maps } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -1180,7 +1181,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -1189,7 +1190,7 @@ namespace Game.Maps i_objects.Add(player); } } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -1212,7 +1213,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { // already found if (i_object) @@ -1245,7 +1246,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) { @@ -1272,7 +1273,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var creature in objs) if (creature.IsInPhase(_searcher)) @@ -1293,7 +1294,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { // already found if (i_object) @@ -1326,7 +1327,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) { @@ -1353,7 +1354,7 @@ namespace Game.Maps i_check = check; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var player in objs) if (player.IsInPhase(_searcher)) diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index da1092494..dfece569d 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -1632,8 +1632,8 @@ namespace Game.Maps } } - foreach (Transport transport in _transports.ToList()) - RemoveFromMap(transport, true); + for (var i = 0; i < _transports.Count; ++i) + RemoveFromMap(_transports[i], true); _transports.Clear(); @@ -1650,8 +1650,9 @@ namespace Game.Maps Global.ScriptMgr.OnDestroyMap(this); - foreach (WorldObject obj in i_worldObjects.ToList()) + for (var i = 0; i < i_worldObjects.Count; ++i) { + WorldObject obj = i_worldObjects[i]; Contract.Assert(obj.IsWorldObject()); obj.RemoveFromWorld(); obj.ResetMap(); diff --git a/Source/Game/Maps/ObjectGridLoader.cs b/Source/Game/Maps/ObjectGridLoader.cs index f84b73ace..a84152044 100644 --- a/Source/Game/Maps/ObjectGridLoader.cs +++ b/Source/Game/Maps/ObjectGridLoader.cs @@ -19,6 +19,7 @@ using Framework.Constants; using Game.Entities; using System.Collections.Generic; using System.Linq; +using System.Collections.Concurrent; namespace Game.Maps { @@ -56,7 +57,7 @@ namespace Game.Maps Log.outDebug(LogFilter.Maps, "{0} GameObjects, {1} Creatures, and {2} Corpses/Bones loaded for grid {3} on map {4}", i_gameObjects, i_creatures, i_corpses, i_grid.GetGridId(), i_map.GetId()); } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { CellCoord cellCoord = i_cell.GetCellCoord(); CellObjectGuids cellguids = Global.ObjectMgr.GetCellObjectGuids(i_map.GetId(), (byte)i_map.GetSpawnMode(), cellCoord.GetId()); @@ -66,7 +67,7 @@ namespace Game.Maps LoadHelper(cellguids.gameobjects, cellCoord, ref i_gameObjects, i_map); } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { CellCoord cellCoord = i_cell.GetCellCoord(); CellObjectGuids cellguids = Global.ObjectMgr.GetCellObjectGuids(i_map.GetId(), (byte)i_map.GetSpawnMode(), cellCoord.GetId()); @@ -125,7 +126,7 @@ namespace Game.Maps i_corpses = gloader.i_corpses; } - public override void Visit(ICollection objs) + public override void Visit(IList objs) { CellCoord cellCoord = i_cell.GetCellCoord(); var corpses = i_map.GetCorpsesInCell(cellCoord.GetId()); @@ -158,7 +159,7 @@ namespace Game.Maps //Stop the creatures before unloading the NGrid class ObjectGridStoper : Notifier { - public override void Visit(ICollection objs) + public override void Visit(IList objs) { // stop any fights at grid de-activation and remove dynobjects/areatriggers created at cast by creatures foreach (var creature in objs) @@ -180,20 +181,23 @@ namespace Game.Maps //Move the foreign creatures back to respawn positions before unloading the NGrid class ObjectGridEvacuator : Notifier { - public override void Visit(ICollection objs) + public override void Visit(IList objs) { - foreach (var creature in objs.ToList()) + for (var i = 0; i < objs.Count; ++i) { + Creature creature = objs[i]; // creature in unloading grid can have respawn point in another grid // if it will be unloaded then it will not respawn in original grid until unload/load original grid // move to respawn point to prevent this case. For player view in respawn grid this will be normal respawn. creature.GetMap().CreatureRespawnRelocation(creature, true); } } - public override void Visit(ICollection objs) + + public override void Visit(IList objs) { - foreach (var go in objs.ToList()) + for (var i = 0; i < objs.Count; ++i) { + GameObject go = objs[i]; // gameobject in unloading grid can have respawn point in another grid // if it will be unloaded then it will not respawn in original grid until unload/load original grid // move to respawn point to prevent this case. For player view in respawn grid this will be normal respawn. @@ -205,7 +209,7 @@ namespace Game.Maps //Clean up and remove from world class ObjectGridCleaner : Notifier { - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { @@ -220,7 +224,7 @@ namespace Game.Maps //Delete objects before deleting NGrid class ObjectGridUnloader : Notifier { - public override void Visit(ICollection objs) + public override void Visit(IList objs) { foreach (var obj in objs) { diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 378124e09..9b8db6022 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -112,8 +112,8 @@ namespace Game.Spells public virtual void Dispose() { // unload scripts - foreach (var script in m_loadedScripts.ToList()) - script._Unload(); + for (var i = 0; i < m_loadedScripts.Count; ++i) + m_loadedScripts[i]._Unload(); if (m_referencedFromCurrentSpell && m_selfContainer && m_selfContainer == this) { @@ -1460,8 +1460,9 @@ namespace Game.Spells // for some spells allow only chain targets in front of caster (swipe for example) if (!isBouncingFar) { - foreach (var obj in tempTargets.ToList()) + for (var i = 0; i < tempTargets.Count; ++i) { + var obj = tempTargets[i]; if (!m_caster.HasInArc(MathFunctions.PI, obj)) tempTargets.Remove(obj); }