From 52e43853fee6f4c37c04be0c0cdc120999660164 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 8 Jun 2021 12:56:09 -0400 Subject: [PATCH] More Cleanups --- Source/BNetServer/Managers/Global.cs | 3 - Source/BNetServer/Networking/RestSession.cs | 19 ++- .../Networking/Services/Authentication.cs | 11 +- .../Networking/Services/Connection.cs | 8 +- .../Networking/Services/GameUtilities.cs | 2 +- Source/BNetServer/Networking/Session.cs | 14 +- Source/BNetServer/Server.cs | 9 +- Source/Framework/Constants/AuctionConst.cs | 3 + Source/Framework/Constants/PlayerConst.cs | 1 + .../Framework/Constants/Spells/SpellConst.cs | 2 + Source/Game/Arenas/Arena.cs | 8 +- Source/Game/Arenas/ArenaTeam.cs | 2 +- Source/Game/AuctionHouse/AuctionManager.cs | 2 +- .../BattleFields/Zones/WinterGraspConst.cs | 4 +- Source/Game/BattleGrounds/BattleGround.cs | 2 - .../Game/BattleGrounds/BattleGroundQueue.cs | 2 +- Source/Game/Calendar/CalendarManager.cs | 2 +- Source/Game/Chat/Channels/Channel.cs | 3 +- Source/Game/Chat/Commands/AccountCommands.cs | 2 +- .../Game/Chat/Commands/BNetAccountCommands.cs | 4 +- .../Game/Chat/Commands/CharacterCommands.cs | 2 +- Source/Game/Chat/Commands/ListCommands.cs | 4 +- Source/Game/Chat/Commands/MiscCommands.cs | 2 +- .../Collision/BoundingIntervalHierarchy.cs | 2 +- .../BoundingIntervalHierarchyWrap.cs | 2 +- Source/Game/Collision/DynamicTree.cs | 6 +- Source/Game/Collision/Maps/MapTree.cs | 126 +++++++++--------- .../Game/Collision/Models/GameObjectModel.cs | 38 +++--- Source/Game/Collision/Models/WorldModel.cs | 54 ++++---- Source/Game/Combat/ThreatManager.cs | 3 +- Source/Game/Conditions/Condition.cs | 6 +- Source/Game/Conditions/ConditionManager.cs | 5 +- Source/Game/DataStorage/M2Storage.cs | 36 +++-- Source/Game/DungeonFinding/LFGManager.cs | 2 +- .../Game/Entities/AreaTrigger/AreaTrigger.cs | 2 +- Source/Game/Entities/Creature/Creature.cs | 2 +- Source/Game/Entities/Creature/Gossip.cs | 2 +- Source/Game/Entities/GameObject/GameObject.cs | 4 +- Source/Game/Entities/Object/Position.cs | 4 +- .../Entities/Object/Update/UpdateField.cs | 3 +- Source/Game/Entities/Player/Player.DB.cs | 4 +- Source/Game/Entities/Player/Player.Items.cs | 3 +- Source/Game/Entities/Player/Player.Spells.cs | 10 +- Source/Game/Entities/Player/PlayerTaxi.cs | 6 +- Source/Game/Entities/Taxi/TaxiPathGraph.cs | 3 +- Source/Game/Entities/TemporarySummon.cs | 2 +- Source/Game/Entities/Transport.cs | 2 +- Source/Game/Entities/Unit/CharmInfo.cs | 2 +- Source/Game/Entities/Unit/Unit.Combat.cs | 8 +- Source/Game/Entities/Unit/Unit.Fields.cs | 2 - Source/Game/Entities/Unit/Unit.Movement.cs | 7 +- Source/Game/Entities/Unit/Unit.cs | 2 +- Source/Game/Entities/Vehicle.cs | 1 - Source/Game/Garrisons/Garrisons.cs | 2 +- Source/Game/Globals/ObjectManager.cs | 2 +- Source/Game/Groups/Group.cs | 8 +- Source/Game/Reputation/ReputationManager.cs | 4 +- Source/WorldServer/Server.cs | 4 +- 58 files changed, 223 insertions(+), 257 deletions(-) diff --git a/Source/BNetServer/Managers/Global.cs b/Source/BNetServer/Managers/Global.cs index 7a5aadccf..ec618b59d 100644 --- a/Source/BNetServer/Managers/Global.cs +++ b/Source/BNetServer/Managers/Global.cs @@ -1,9 +1,6 @@ // Copyright (c) CypherCore All rights reserved. // Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; using BNetServer; public static class Global diff --git a/Source/BNetServer/Networking/RestSession.cs b/Source/BNetServer/Networking/RestSession.cs index f1c7e7efc..e33684290 100644 --- a/Source/BNetServer/Networking/RestSession.cs +++ b/Source/BNetServer/Networking/RestSession.cs @@ -1,17 +1,16 @@ // Copyright (c) CypherCore All rights reserved. // Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; -using Framework.Networking; -using System.Net.Sockets; -using Framework.Web; +using Framework.Configuration; using Framework.Constants; using Framework.Database; -using Framework.Configuration; +using Framework.Networking; using Framework.Serialization; +using Framework.Web; +using System; +using System.Net.Sockets; using System.Security.Cryptography; +using System.Text; namespace BNetServer.Networking { @@ -53,7 +52,7 @@ namespace BNetServer.Networking public void HandleLoginRequest(HttpHeader request) { LogonData loginForm = Json.CreateObject(request.Content); - LogonResult loginResult = new LogonResult(); + LogonResult loginResult = new(); if (loginForm == null) { loginResult.AuthenticationState = "LOGIN"; @@ -96,7 +95,7 @@ namespace BNetServer.Networking { if (loginTicket.IsEmpty() || loginTicketExpiry < Time.UnixTime) { - byte[] ticket = new byte[0].GenerateRandomKey(20); + byte[] ticket = Array.Empty().GenerateRandomKey(20); loginTicket = "TC-" + ticket.ToHexString(); } @@ -117,7 +116,7 @@ namespace BNetServer.Networking if (maxWrongPassword != 0) { - SQLTransaction trans = new SQLTransaction(); + SQLTransaction trans = new(); stmt = DB.Login.GetPreparedStatement(LoginStatements.UpdBnetFailedLogins); stmt.AddValue(0, accountId); trans.Append(stmt); diff --git a/Source/BNetServer/Networking/Services/Authentication.cs b/Source/BNetServer/Networking/Services/Authentication.cs index 548ae0ce5..95b49e005 100644 --- a/Source/BNetServer/Networking/Services/Authentication.cs +++ b/Source/BNetServer/Networking/Services/Authentication.cs @@ -6,10 +6,9 @@ using Bgs.Protocol.Authentication.V1; using Bgs.Protocol.Challenge.V1; using Framework.Constants; using Framework.Database; +using Framework.Realm; using Google.Protobuf; using System; -using Framework.Realm; -using System.Net; namespace BNetServer.Networking { @@ -42,7 +41,7 @@ namespace BNetServer.Networking var endpoint = Global.LoginServiceMgr.GetAddressForClient(GetRemoteIpEndPoint().Address); - ChallengeExternalRequest externalChallenge = new ChallengeExternalRequest(); + ChallengeExternalRequest externalChallenge = new(); externalChallenge.PayloadType = "web_auth_url"; externalChallenge.Payload = ByteString.CopyFromUtf8($"https://{endpoint.Address}:{endpoint.Port}/bnetserver/login/"); @@ -92,7 +91,7 @@ namespace BNetServer.Networking { var realmId = new RealmId(lastPlayerCharactersResult.Read(1), lastPlayerCharactersResult.Read(2), lastPlayerCharactersResult.Read(3)); - LastPlayedCharacterInfo lastPlayedCharacter = new LastPlayedCharacterInfo(); + LastPlayedCharacterInfo lastPlayedCharacter = new(); lastPlayedCharacter.RealmId = realmId; lastPlayedCharacter.CharacterName = lastPlayerCharactersResult.Read(4); lastPlayedCharacter.CharacterGUID = lastPlayerCharactersResult.Read(5); @@ -142,14 +141,14 @@ namespace BNetServer.Networking } } - LogonResult logonResult = new LogonResult(); + LogonResult logonResult = new(); logonResult.ErrorCode = 0; logonResult.AccountId = new EntityId(); logonResult.AccountId.Low = accountInfo.Id; logonResult.AccountId.High = 0x100000000000000; foreach (var pair in accountInfo.GameAccounts) { - EntityId gameAccountId = new EntityId(); + EntityId gameAccountId = new(); gameAccountId.Low = pair.Value.Id; gameAccountId.High = 0x200000200576F57; logonResult.GameAccountId.Add(gameAccountId); diff --git a/Source/BNetServer/Networking/Services/Connection.cs b/Source/BNetServer/Networking/Services/Connection.cs index 0d1f84c47..716e268e8 100644 --- a/Source/BNetServer/Networking/Services/Connection.cs +++ b/Source/BNetServer/Networking/Services/Connection.cs @@ -1,12 +1,10 @@ // Copyright (c) CypherCore All rights reserved. // Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. +using Bgs.Protocol; using Bgs.Protocol.Connection.V1; using Framework.Constants; -using System.Collections.Generic; -using Google.Protobuf; -using Bgs.Protocol; -using System.Diagnostics; +using System; namespace BNetServer.Networking { @@ -19,7 +17,7 @@ namespace BNetServer.Networking response.ClientId.MergeFrom(request.ClientId); response.ServerId = new ProcessId(); - response.ServerId.Label = (uint)Process.GetCurrentProcess().Id; + response.ServerId.Label = (uint)Environment.ProcessId; response.ServerId.Epoch = (uint)Time.UnixTime; response.ServerTime = (ulong)Time.UnixTimeMilliseconds; diff --git a/Source/BNetServer/Networking/Services/GameUtilities.cs b/Source/BNetServer/Networking/Services/GameUtilities.cs index 1df466b39..ee72a8f59 100644 --- a/Source/BNetServer/Networking/Services/GameUtilities.cs +++ b/Source/BNetServer/Networking/Services/GameUtilities.cs @@ -22,7 +22,7 @@ namespace BNetServer.Networking return BattlenetRpcErrorCode.Denied; Bgs.Protocol.Attribute command = null; - Dictionary Params = new Dictionary(); + Dictionary Params = new(); for (int i = 0; i < request.Attribute.Count; ++i) { diff --git a/Source/BNetServer/Networking/Session.cs b/Source/BNetServer/Networking/Session.cs index 73d95499d..44bedd543 100644 --- a/Source/BNetServer/Networking/Session.cs +++ b/Source/BNetServer/Networking/Session.cs @@ -125,12 +125,12 @@ namespace BNetServer.Networking public async void SendResponse(uint token, IMessage response) { - Header header = new Header(); + Header header = new(); header.Token = token; header.ServiceId = 0xFE; header.Size = (uint)response.CalculateSize(); - ByteBuffer buffer = new ByteBuffer(); + ByteBuffer buffer = new(); buffer.WriteBytes(GetHeaderSize(header), 2); buffer.WriteBytes(header.ToByteArray()); buffer.WriteBytes(response.ToByteArray()); @@ -140,12 +140,12 @@ namespace BNetServer.Networking public async void SendResponse(uint token, BattlenetRpcErrorCode status) { - Header header = new Header(); + Header header = new(); header.Token = token; header.Status = (uint)status; header.ServiceId = 0xFE; - ByteBuffer buffer = new ByteBuffer(); + ByteBuffer buffer = new(); buffer.WriteBytes(GetHeaderSize(header), 2); buffer.WriteBytes(header.ToByteArray()); @@ -154,14 +154,14 @@ namespace BNetServer.Networking public async void SendRequest(uint serviceHash, uint methodId, IMessage request) { - Header header = new Header(); + Header header = new(); header.ServiceId = 0; header.ServiceHash = serviceHash; header.MethodId = methodId; header.Size = (uint)request.CalculateSize(); header.Token = requestToken++; - ByteBuffer buffer = new ByteBuffer(); + ByteBuffer buffer = new(); buffer.WriteBytes(GetHeaderSize(header), 2); buffer.WriteBytes(header.ToByteArray()); buffer.WriteBytes(request.ToByteArray()); @@ -260,7 +260,7 @@ namespace BNetServer.Networking int hashPos = Name.IndexOf('#'); if (hashPos != -1) - DisplayName = "WoW" + Name.Substring(hashPos + 1); + DisplayName = "WoW" + Name[(hashPos + 1)..]; else DisplayName = Name; diff --git a/Source/BNetServer/Server.cs b/Source/BNetServer/Server.cs index ae6efb548..526fd49ab 100644 --- a/Source/BNetServer/Server.cs +++ b/Source/BNetServer/Server.cs @@ -3,19 +3,12 @@ using BNetServer.Networking; using Framework.Configuration; +using Framework.Cryptography; using Framework.Database; using Framework.Networking; -using Framework.Web.API; using System; using System.Globalization; -using System.Net.Http; -using System.Text; -using System.Text.Json; -using System.Text.Json.Serialization; using System.Timers; -using System.Collections.Generic; -using System.Threading.Tasks; -using Framework.Cryptography; namespace BNetServer { diff --git a/Source/Framework/Constants/AuctionConst.cs b/Source/Framework/Constants/AuctionConst.cs index c10f1db22..5fe92234e 100644 --- a/Source/Framework/Constants/AuctionConst.cs +++ b/Source/Framework/Constants/AuctionConst.cs @@ -15,6 +15,8 @@ * along with this program. If not, see . */ +using System; + namespace Framework.Constants { public enum AuctionResult @@ -59,6 +61,7 @@ namespace Framework.Constants Items = 50 } + [Flags] public enum AuctionHouseFilterMask { None = 0x0, diff --git a/Source/Framework/Constants/PlayerConst.cs b/Source/Framework/Constants/PlayerConst.cs index 4e6b65287..1c6223ebf 100644 --- a/Source/Framework/Constants/PlayerConst.cs +++ b/Source/Framework/Constants/PlayerConst.cs @@ -764,6 +764,7 @@ namespace Framework.Constants LoadedFromDB = 0x02 } + [Flags] public enum ItemSearchLocation { Equipment = 0x01, diff --git a/Source/Framework/Constants/Spells/SpellConst.cs b/Source/Framework/Constants/Spells/SpellConst.cs index 85d802295..c654c9205 100644 --- a/Source/Framework/Constants/Spells/SpellConst.cs +++ b/Source/Framework/Constants/Spells/SpellConst.cs @@ -115,6 +115,7 @@ namespace Framework.Constants DamageCancels = 0x400 } + [Flags] public enum SpellAuraInterruptFlags : uint { None = 0, @@ -154,6 +155,7 @@ namespace Framework.Constants NotVictim = (HostileActionReceived | Damage | NonPeriodicDamage) } + [Flags] public enum SpellAuraInterruptFlags2 { None = 0, diff --git a/Source/Game/Arenas/Arena.cs b/Source/Game/Arenas/Arena.cs index 14b8f3746..a3707b990 100644 --- a/Source/Game/Arenas/Arena.cs +++ b/Source/Game/Arenas/Arena.cs @@ -153,12 +153,12 @@ namespace Game.Arenas // arena rating calculation if (IsRated()) { - uint loserTeamRating = 0; - uint loserMatchmakerRating = 0; + uint loserTeamRating; + uint loserMatchmakerRating; int loserChange = 0; int loserMatchmakerChange = 0; - uint winnerTeamRating = 0; - uint winnerMatchmakerRating = 0; + uint winnerTeamRating; + uint winnerMatchmakerRating; int winnerChange = 0; int winnerMatchmakerChange = 0; bool guildAwarded = false; diff --git a/Source/Game/Arenas/ArenaTeam.cs b/Source/Game/Arenas/ArenaTeam.cs index ca65d252f..ef2be1b9a 100644 --- a/Source/Game/Arenas/ArenaTeam.cs +++ b/Source/Game/Arenas/ArenaTeam.cs @@ -144,7 +144,7 @@ namespace Game.Arenas newMember.WeekGames = 0; newMember.SeasonWins = 0; newMember.WeekWins = 0; - newMember.PersonalRating = 0; + newMember.PersonalRating = (ushort)personalRating; newMember.MatchMakerRating = (ushort)matchMakerRating; Members.Add(newMember); diff --git a/Source/Game/AuctionHouse/AuctionManager.cs b/Source/Game/AuctionHouse/AuctionManager.cs index 5afdb3d0a..5a043579a 100644 --- a/Source/Game/AuctionHouse/AuctionManager.cs +++ b/Source/Game/AuctionHouse/AuctionManager.cs @@ -2031,7 +2031,7 @@ namespace Game public Span GetResultRange() { Span h = _items.ToArray(); - return h.Slice((int)_offset); + return h[(int)_offset..]; } public bool HasMoreResults() diff --git a/Source/Game/BattleFields/Zones/WinterGraspConst.cs b/Source/Game/BattleFields/Zones/WinterGraspConst.cs index bb9528ff1..dc1e52f7b 100644 --- a/Source/Game/BattleFields/Zones/WinterGraspConst.cs +++ b/Source/Game/BattleFields/Zones/WinterGraspConst.cs @@ -715,8 +715,8 @@ namespace Game.BattleFields { public WintergraspTowerCannonData() { - TowerCannonBottom = new Position[0]; - TurretTop = new Position[0]; + TowerCannonBottom = System.Array.Empty(); + TurretTop = System.Array.Empty(); } public uint towerEntry; diff --git a/Source/Game/BattleGrounds/BattleGround.cs b/Source/Game/BattleGrounds/BattleGround.cs index eb10eed02..f53544d97 100644 --- a/Source/Game/BattleGrounds/BattleGround.cs +++ b/Source/Game/BattleGrounds/BattleGround.cs @@ -2088,12 +2088,10 @@ namespace Game.BattleGrounds // Arena team ids by team uint[] m_ArenaTeamIds = new uint[SharedConst.BGTeamsCount]; - int[] m_ArenaTeamRatingChanges = new int[SharedConst.BGTeamsCount]; uint[] m_ArenaTeamMMR = new uint[SharedConst.BGTeamsCount]; // Start location BattlegroundMap m_Map; - Position[] StartPosition = new Position[SharedConst.BGTeamsCount]; BattlegroundTemplate _battlegroundTemplate; PvpDifficultyRecord _pvpDifficultyEntry; diff --git a/Source/Game/BattleGrounds/BattleGroundQueue.cs b/Source/Game/BattleGrounds/BattleGroundQueue.cs index f95246991..f0191bf36 100644 --- a/Source/Game/BattleGrounds/BattleGroundQueue.cs +++ b/Source/Game/BattleGrounds/BattleGroundQueue.cs @@ -194,7 +194,7 @@ namespace Game.BattleGrounds m_SumOfWaitTimes[team_index][(int)bracket_id] += timeInQueue; //set index of last player added to next one lastPlayerAddedPointer++; - lastPlayerAddedPointer %= SharedConst.CountOfPlayersToAverageWaitTime; + m_WaitTimeLastPlayer[team_index][(int)bracket_id] = lastPlayerAddedPointer % SharedConst.CountOfPlayersToAverageWaitTime; } public uint GetAverageQueueWaitTime(GroupQueueInfo ginfo, BattlegroundBracketId bracket_id) diff --git a/Source/Game/Calendar/CalendarManager.cs b/Source/Game/Calendar/CalendarManager.cs index a457814dd..d6fc7f09d 100644 --- a/Source/Game/Calendar/CalendarManager.cs +++ b/Source/Game/Calendar/CalendarManager.cs @@ -410,7 +410,7 @@ namespace Game packet.ResponseTime = invite.ResponseTime; packet.Status = invite.Status; packet.Type = (byte)(calendarEvent != null ? calendarEvent.IsGuildEvent() ? 1 : 0 : 0); // Correct ? - packet.ClearPending = calendarEvent != null ? !calendarEvent.IsGuildEvent() : true; // Correct ? + packet.ClearPending = calendarEvent == null || !calendarEvent.IsGuildEvent(); // Correct ? if (calendarEvent == null) // Pre-invite { diff --git a/Source/Game/Chat/Channels/Channel.cs b/Source/Game/Chat/Channels/Channel.cs index 3fe1bec98..f6746561e 100644 --- a/Source/Game/Chat/Channels/Channel.cs +++ b/Source/Game/Chat/Channels/Channel.cs @@ -21,7 +21,6 @@ using Framework.Database; using Game.DataStorage; using Game.Entities; using Game.Maps; -using Game.Networking; using Game.Networking.Packets; using System; using System.Collections.Generic; @@ -83,7 +82,7 @@ namespace Game.Chat for (var i = 0; i < tokens.Length; ++i) { ObjectGuid bannedGuid = new(); - if (ulong.TryParse(tokens[i].Substring(0, 16), out ulong highguid) && ulong.TryParse(tokens[i].Substring(16), out ulong lowguid)) + if (ulong.TryParse(tokens[i].Substring(0, 16), out ulong highguid) && ulong.TryParse(tokens[i][16..], out ulong lowguid)) bannedGuid.SetRawValue(highguid, lowguid); if (!bannedGuid.IsEmpty()) diff --git a/Source/Game/Chat/Commands/AccountCommands.cs b/Source/Game/Chat/Commands/AccountCommands.cs index 036eed366..fc2a115b9 100644 --- a/Source/Game/Chat/Commands/AccountCommands.cs +++ b/Source/Game/Chat/Commands/AccountCommands.cs @@ -39,7 +39,7 @@ namespace Game.Chat // Security level required WorldSession session = handler.GetSession(); - bool hasRBAC = (session.HasPermission(RBACPermissions.EmailConfirmForPassChange) ? true : false); + bool hasRBAC = (session.HasPermission(RBACPermissions.EmailConfirmForPassChange)); uint pwConfig = 0; // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC handler.SendSysMessage(CypherStrings.AccountSecType, (pwConfig == 0 ? "Lowest level: No Email input required." : diff --git a/Source/Game/Chat/Commands/BNetAccountCommands.cs b/Source/Game/Chat/Commands/BNetAccountCommands.cs index e6d730ddc..8bbec9938 100644 --- a/Source/Game/Chat/Commands/BNetAccountCommands.cs +++ b/Source/Game/Chat/Commands/BNetAccountCommands.cs @@ -100,7 +100,7 @@ namespace Game.Chat.Commands string accountName = accountId.ToString() + '#' + index; // Generate random hex string for password, these accounts must not be logged on with GRUNT - byte[] randPassword = new byte[0].GenerateRandomKey(8); + byte[] randPassword = Array.Empty().GenerateRandomKey(8); switch (Global.AccountMgr.CreateAccount(accountName, randPassword.ToHexString(), bnetAccountName, accountId, index)) { case AccountOpResult.Ok: @@ -179,7 +179,7 @@ namespace Game.Chat.Commands { int index = name.IndexOf('#'); if (index > 0) - return "WoW" + name.Substring(++index); + return "WoW" + name[++index..]; else return name; }); diff --git a/Source/Game/Chat/Commands/CharacterCommands.cs b/Source/Game/Chat/Commands/CharacterCommands.cs index c6028dd4c..65092d82e 100644 --- a/Source/Game/Chat/Commands/CharacterCommands.cs +++ b/Source/Game/Chat/Commands/CharacterCommands.cs @@ -288,7 +288,7 @@ namespace Game.Chat } uint oldAccountId = characterInfo.AccountId; - uint newAccountId = oldAccountId; + uint newAccountId; PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ID_BY_NAME); stmt.AddValue(0, accountName); diff --git a/Source/Game/Chat/Commands/ListCommands.cs b/Source/Game/Chat/Commands/ListCommands.cs index 455a816e7..28d084d3b 100644 --- a/Source/Game/Chat/Commands/ListCommands.cs +++ b/Source/Game/Chat/Commands/ListCommands.cs @@ -369,17 +369,15 @@ namespace Game.Chat.Commands if (args.Empty()) return false; - Player target; ObjectGuid targetGuid; string targetName; ObjectGuid parseGUID = ObjectGuid.Create(HighGuid.Player, args.NextUInt64()); if (Global.CharacterCacheStorage.GetCharacterNameByGuid(parseGUID, out targetName)) { - target = Global.ObjAccessor.FindPlayer(parseGUID); targetGuid = parseGUID; } - else if (!handler.ExtractPlayerTarget(args, out target, out targetGuid, out targetName)) + else if (!handler.ExtractPlayerTarget(args, out _, out targetGuid, out targetName)) return false; PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_LIST_COUNT); diff --git a/Source/Game/Chat/Commands/MiscCommands.cs b/Source/Game/Chat/Commands/MiscCommands.cs index 6711e4ec4..728ff2262 100644 --- a/Source/Game/Chat/Commands/MiscCommands.cs +++ b/Source/Game/Chat/Commands/MiscCommands.cs @@ -1580,7 +1580,7 @@ namespace Game.Chat Locale locale = handler.GetSessionDbcLocale(); uint totalPlayerTime; uint level; - string alive = handler.GetCypherString(CypherStrings.Error); + string alive; ulong money; uint xp = 0; uint xptotal = 0; diff --git a/Source/Game/Collision/BoundingIntervalHierarchy.cs b/Source/Game/Collision/BoundingIntervalHierarchy.cs index 6b4078ed7..b7e16f646 100644 --- a/Source/Game/Collision/BoundingIntervalHierarchy.cs +++ b/Source/Game/Collision/BoundingIntervalHierarchy.cs @@ -33,7 +33,7 @@ namespace Game.Collision void InitEmpty() { tree= new uint[3]; - objects = new uint[0]; + objects = Array.Empty(); // create space for the first node tree[0] = (3u << 30); // dummy leaf } diff --git a/Source/Game/Collision/BoundingIntervalHierarchyWrap.cs b/Source/Game/Collision/BoundingIntervalHierarchyWrap.cs index 86a6a3e3d..f5bdc1ef1 100644 --- a/Source/Game/Collision/BoundingIntervalHierarchyWrap.cs +++ b/Source/Game/Collision/BoundingIntervalHierarchyWrap.cs @@ -30,7 +30,7 @@ namespace Game.Collision public void Remove(T obj) { ++unbalanced_times; - uint Idx = 0; + uint Idx; if (m_obj2Idx.TryGetValue(obj, out Idx)) m_objects[(int)Idx] = null; else diff --git a/Source/Game/Collision/DynamicTree.cs b/Source/Game/Collision/DynamicTree.cs index 3f9ad3d30..185a0112d 100644 --- a/Source/Game/Collision/DynamicTree.cs +++ b/Source/Game/Collision/DynamicTree.cs @@ -51,7 +51,7 @@ namespace Game.Collision impl.Update(diff); } - public bool GetIntersectionTime(Ray ray, Vector3 endPos, PhaseShift phaseShift, float maxDist) + public bool GetIntersectionTime(Ray ray, Vector3 endPos, PhaseShift phaseShift, ref float maxDist) { float distance = maxDist; DynamicTreeIntersectionCallback callback = new(phaseShift); @@ -63,7 +63,7 @@ namespace Game.Collision public bool GetObjectHitPos(Vector3 startPos, Vector3 endPos, ref Vector3 resultHitPos, float modifyDist, PhaseShift phaseShift) { - bool result = false; + bool result; float maxDist = (endPos - startPos).magnitude(); // valid map coords should *never ever* produce float overflow, but this would produce NaNs too Cypher.Assert(maxDist < float.MaxValue); @@ -76,7 +76,7 @@ namespace Game.Collision Vector3 dir = (endPos - startPos) / maxDist; // direction with length of 1 Ray ray = new(startPos, dir); float dist = maxDist; - if (GetIntersectionTime(ray, endPos, phaseShift, dist)) + if (GetIntersectionTime(ray, endPos, phaseShift, ref dist)) { resultHitPos = startPos + dir * dist; if (modifyDist < 0) diff --git a/Source/Game/Collision/Maps/MapTree.cs b/Source/Game/Collision/Maps/MapTree.cs index 1711a49e6..2cbfcd06c 100644 --- a/Source/Game/Collision/Maps/MapTree.cs +++ b/Source/Game/Collision/Maps/MapTree.cs @@ -121,60 +121,58 @@ namespace Game.Collision if (fileResult.File != null) { result = LoadResult.Success; - using (BinaryReader reader = new(fileResult.File)) + using BinaryReader reader = new(fileResult.File); + if (reader.ReadStringFromChars(8) != MapConst.VMapMagic) + result = LoadResult.VersionMismatch; + + if (result == LoadResult.Success) { - if (reader.ReadStringFromChars(8) != MapConst.VMapMagic) - result = LoadResult.VersionMismatch; - - if (result == LoadResult.Success) + uint numSpawns = reader.ReadUInt32(); + for (uint i = 0; i < numSpawns && result == LoadResult.Success; ++i) { - uint numSpawns = reader.ReadUInt32(); - for (uint i = 0; i < numSpawns && result == LoadResult.Success; ++i) + // read model spawns + if (ModelSpawn.ReadFromFile(reader, out ModelSpawn spawn)) { - // read model spawns - if (ModelSpawn.ReadFromFile(reader, out ModelSpawn spawn)) - { - // acquire model instance - WorldModel model = vm.AcquireModelInstance(spawn.name, spawn.flags); - if (model == null) - Log.outError(LogFilter.Server, "StaticMapTree.LoadMapTile() : could not acquire WorldModel [{0}, {1}]", tileX, tileY); + // acquire model instance + WorldModel model = vm.AcquireModelInstance(spawn.name, spawn.flags); + if (model == null) + Log.outError(LogFilter.Server, "StaticMapTree.LoadMapTile() : could not acquire WorldModel [{0}, {1}]", tileX, tileY); - // update tree - if (iSpawnIndices.ContainsKey(spawn.Id)) + // update tree + if (iSpawnIndices.ContainsKey(spawn.Id)) + { + uint referencedVal = iSpawnIndices[spawn.Id]; + if (!iLoadedSpawns.ContainsKey(referencedVal)) { - uint referencedVal = iSpawnIndices[spawn.Id]; - if (!iLoadedSpawns.ContainsKey(referencedVal)) + if (referencedVal >= iNTreeValues) { - if (referencedVal >= iNTreeValues) - { - Log.outError(LogFilter.Maps, "StaticMapTree.LoadMapTile() : invalid tree element ({0}/{1}) referenced in tile {2}", referencedVal, iNTreeValues, fileResult.Name); - continue; - } - - iTreeValues[referencedVal] = new ModelInstance(spawn, model); - iLoadedSpawns[referencedVal] = 1; + Log.outError(LogFilter.Maps, "StaticMapTree.LoadMapTile() : invalid tree element ({0}/{1}) referenced in tile {2}", referencedVal, iNTreeValues, fileResult.Name); + continue; } - else - ++iLoadedSpawns[referencedVal]; - } - else if (iMapID == fileResult.UsedMapId) - { - // unknown parent spawn might appear in because it overlaps multiple tiles - // in case the original tile is swapped but its neighbour is now (adding this spawn) - // we want to not mark it as loading error and just skip that model - Log.outError(LogFilter.Maps, $"StaticMapTree.LoadMapTile() : invalid tree element (spawn {spawn.Id}) referenced in tile fileResult.Name{fileResult.Name} by map {iMapID}"); - result = LoadResult.ReadFromFileFailed; + + iTreeValues[referencedVal] = new ModelInstance(spawn, model); + iLoadedSpawns[referencedVal] = 1; } + else + ++iLoadedSpawns[referencedVal]; } - else + else if (iMapID == fileResult.UsedMapId) { - Log.outError(LogFilter.Maps, $"StaticMapTree.LoadMapTile() : cannot read model from file (spawn index {i}) referenced in tile {fileResult.Name} by map {iMapID}"); + // unknown parent spawn might appear in because it overlaps multiple tiles + // in case the original tile is swapped but its neighbour is now (adding this spawn) + // we want to not mark it as loading error and just skip that model + Log.outError(LogFilter.Maps, $"StaticMapTree.LoadMapTile() : invalid tree element (spawn {spawn.Id}) referenced in tile fileResult.Name{fileResult.Name} by map {iMapID}"); result = LoadResult.ReadFromFileFailed; } } + else + { + Log.outError(LogFilter.Maps, $"StaticMapTree.LoadMapTile() : cannot read model from file (spawn index {i}) referenced in tile {fileResult.Name} by map {iMapID}"); + result = LoadResult.ReadFromFileFailed; + } } - iLoadedTiles[PackTileID(tileX, tileY)] = true; } + iLoadedTiles[PackTileID(tileX, tileY)] = true; } else { @@ -197,38 +195,36 @@ namespace Game.Collision TileFileOpenResult fileResult = OpenMapTileFile(VMapManager.VMapPath, iMapID, tileX, tileY, vm); if (fileResult.File != null) { - using (BinaryReader reader = new(fileResult.File)) + using BinaryReader reader = new(fileResult.File); + bool result = true; + if (reader.ReadStringFromChars(8) != MapConst.VMapMagic) + result = false; + + uint numSpawns = reader.ReadUInt32(); + for (uint i = 0; i < numSpawns && result; ++i) { - bool result = true; - if (reader.ReadStringFromChars(8) != MapConst.VMapMagic) - result = false; - - uint numSpawns = reader.ReadUInt32(); - for (uint i = 0; i < numSpawns && result; ++i) + // read model spawns + ModelSpawn spawn; + result = ModelSpawn.ReadFromFile(reader, out spawn); + if (result) { - // read model spawns - ModelSpawn spawn; - result = ModelSpawn.ReadFromFile(reader, out spawn); - if (result) - { - // release model instance - vm.ReleaseModelInstance(spawn.name); + // release model instance + vm.ReleaseModelInstance(spawn.name); - // update tree - if (iSpawnIndices.ContainsKey(spawn.Id)) + // update tree + if (iSpawnIndices.ContainsKey(spawn.Id)) + { + uint referencedNode = iSpawnIndices[spawn.Id]; + if (!iLoadedSpawns.ContainsKey(referencedNode)) + Log.outError(LogFilter.Server, "StaticMapTree.UnloadMapTile() : trying to unload non-referenced model '{0}' (ID:{1})", spawn.name, spawn.Id); + else if (--iLoadedSpawns[referencedNode] == 0) { - uint referencedNode = iSpawnIndices[spawn.Id]; - if (!iLoadedSpawns.ContainsKey(referencedNode)) - Log.outError(LogFilter.Server, "StaticMapTree.UnloadMapTile() : trying to unload non-referenced model '{0}' (ID:{1})", spawn.name, spawn.Id); - else if (--iLoadedSpawns[referencedNode] == 0) - { - iTreeValues[referencedNode].SetUnloaded(); - iLoadedSpawns.Remove(referencedNode); - } + iTreeValues[referencedNode].SetUnloaded(); + iLoadedSpawns.Remove(referencedNode); } - else if (iMapID == fileResult.UsedMapId) // logic documented in StaticMapTree::LoadMapTile - result = false; } + else if (iMapID == fileResult.UsedMapId) // logic documented in StaticMapTree::LoadMapTile + result = false; } } } diff --git a/Source/Game/Collision/Models/GameObjectModel.cs b/Source/Game/Collision/Models/GameObjectModel.cs index b964ed50b..d20f0decb 100644 --- a/Source/Game/Collision/Models/GameObjectModel.cs +++ b/Source/Game/Collision/Models/GameObjectModel.cs @@ -189,30 +189,28 @@ namespace Game.Collision } try { - using (BinaryReader reader = new(new FileStream(filename, FileMode.Open, FileAccess.Read))) + using BinaryReader reader = new(new FileStream(filename, FileMode.Open, FileAccess.Read)); + string magic = reader.ReadStringFromChars(8); + if (magic != MapConst.VMapMagic) { - string magic = reader.ReadStringFromChars(8); - if (magic != MapConst.VMapMagic) - { - Log.outError(LogFilter.Misc, $"File '{filename}' has wrong header, expected {MapConst.VMapMagic}."); - return; - } + Log.outError(LogFilter.Misc, $"File '{filename}' has wrong header, expected {MapConst.VMapMagic}."); + return; + } - long length = reader.BaseStream.Length; - while (true) - { - if (reader.BaseStream.Position >= length) - break; + long length = reader.BaseStream.Length; + while (true) + { + if (reader.BaseStream.Position >= length) + break; - uint displayId = reader.ReadUInt32(); - bool isWmo = reader.ReadBoolean(); - int name_length = reader.ReadInt32(); - string name = reader.ReadString(name_length); - Vector3 v1 = reader.Read(); - Vector3 v2 = reader.Read(); + uint displayId = reader.ReadUInt32(); + bool isWmo = reader.ReadBoolean(); + int name_length = reader.ReadInt32(); + string name = reader.ReadString(name_length); + Vector3 v1 = reader.Read(); + Vector3 v2 = reader.Read(); - StaticModelList.models.Add(displayId, new GameobjectModelData(name, v1, v2, isWmo)); - } + StaticModelList.models.Add(displayId, new GameobjectModelData(name, v1, v2, isWmo)); } } catch (EndOfStreamException ex) diff --git a/Source/Game/Collision/Models/WorldModel.cs b/Source/Game/Collision/Models/WorldModel.cs index 540e3405e..5cb650c39 100644 --- a/Source/Game/Collision/Models/WorldModel.cs +++ b/Source/Game/Collision/Models/WorldModel.cs @@ -371,40 +371,38 @@ namespace Game.Collision { if (!File.Exists(filename)) { - filename = filename + ".vmo"; + filename += ".vmo"; if (!File.Exists(filename)) return false; } - using (BinaryReader reader = new(new FileStream(filename, FileMode.Open, FileAccess.Read))) + using BinaryReader reader = new(new FileStream(filename, FileMode.Open, FileAccess.Read)); + if (reader.ReadStringFromChars(8) != MapConst.VMapMagic) + return false; + + if (reader.ReadStringFromChars(4) != "WMOD") + return false; + + reader.ReadUInt32(); //chunkSize notused + RootWMOID = reader.ReadUInt32(); + + // read group models + if (reader.ReadStringFromChars(4) != "GMOD") + return false; + + uint count = reader.ReadUInt32(); + for (var i = 0; i < count; ++i) { - if (reader.ReadStringFromChars(8) != MapConst.VMapMagic) - return false; - - if (reader.ReadStringFromChars(4) != "WMOD") - return false; - - reader.ReadUInt32(); //chunkSize notused - RootWMOID = reader.ReadUInt32(); - - // read group models - if (reader.ReadStringFromChars(4) != "GMOD") - return false; - - uint count = reader.ReadUInt32(); - for (var i = 0; i < count; ++i) - { - GroupModel group = new(); - group.ReadFromFile(reader); - groupModels.Add(group); - } - - // read group BIH - if (reader.ReadStringFromChars(4) != "GBIH") - return false; - - return groupTree.ReadFromFile(reader); + GroupModel group = new(); + group.ReadFromFile(reader); + groupModels.Add(group); } + + // read group BIH + if (reader.ReadStringFromChars(4) != "GBIH") + return false; + + return groupTree.ReadFromFile(reader); } } } diff --git a/Source/Game/Combat/ThreatManager.cs b/Source/Game/Combat/ThreatManager.cs index 03ea1f53d..cddfd5a2b 100644 --- a/Source/Game/Combat/ThreatManager.cs +++ b/Source/Game/Combat/ThreatManager.cs @@ -628,7 +628,7 @@ namespace Game.Combat void PutThreatListRef(ObjectGuid guid, ThreatReference refe) { - Cypher.Assert(!_myThreatListEntries.ContainsKey(guid), $"Duplicate threat reference being inserted on {_owner.GetGUID()} for {guid.ToString()}!"); + Cypher.Assert(!_myThreatListEntries.ContainsKey(guid), $"Duplicate threat reference being inserted on {_owner.GetGUID()} for {guid}!"); _myThreatListEntries[guid] = refe; _sortedThreatList.Add(refe); _sortedThreatList.Sort(); @@ -771,7 +771,6 @@ namespace Game.Combat if (onlineState == _online) return; - bool increase = (onlineState > _online); _online = onlineState; ListNotifyChanged(); diff --git a/Source/Game/Conditions/Condition.cs b/Source/Game/Conditions/Condition.cs index ed23c7706..1081b7300 100644 --- a/Source/Game/Conditions/Condition.cs +++ b/Source/Game/Conditions/Condition.cs @@ -62,7 +62,7 @@ namespace Game.Conditions { // don't allow 0 items (it's checked during table load) Cypher.Assert(ConditionValue2 != 0); - bool checkBank = ConditionValue3 != 0 ? true : false; + bool checkBank = ConditionValue3 != 0; condMeets = player.HasItemCount(ConditionValue1, ConditionValue2, checkBank); } break; @@ -176,7 +176,7 @@ namespace Game.Conditions condMeets = (uint)Player.GetDrunkenstateByValue(player.GetDrunkValue()) >= ConditionValue1; break; case ConditionTypes.NearCreature: - condMeets = obj.FindNearestCreature(ConditionValue1, ConditionValue2, ConditionValue3 == 0 ? true : false) != null; + condMeets = obj.FindNearestCreature(ConditionValue1, ConditionValue2, ConditionValue3 == 0) != null; break; case ConditionTypes.NearGameobject: condMeets = obj.FindNearestGameObject(ConditionValue1, ConditionValue2) != null; @@ -550,7 +550,7 @@ namespace Game.Conditions ss.Append(" (Unknown)"); } - ss.Append("]"); + ss.Append(']'); return ss.ToString(); } diff --git a/Source/Game/Conditions/ConditionManager.cs b/Source/Game/Conditions/ConditionManager.cs index b12d211b2..209362433 100644 --- a/Source/Game/Conditions/ConditionManager.cs +++ b/Source/Game/Conditions/ConditionManager.cs @@ -1529,7 +1529,7 @@ namespace Game } case ConditionTypes.StandState: { - bool valid = false; + bool valid; switch (cond.ConditionValue1) { case 0: @@ -1677,8 +1677,7 @@ namespace Game public static uint GetPlayerConditionLfgValue(Player player, PlayerConditionLfgStatus status) { - Group group = player.GetGroup(); - if (group = null) + if (player.GetGroup() == null) return 0; switch (status) diff --git a/Source/Game/DataStorage/M2Storage.cs b/Source/Game/DataStorage/M2Storage.cs index 335f2c773..6b43bcba0 100644 --- a/Source/Game/DataStorage/M2Storage.cs +++ b/Source/Game/DataStorage/M2Storage.cs @@ -170,27 +170,25 @@ namespace Game.DataStorage try { - using (BinaryReader m2file = new(new FileStream(filename, FileMode.Open, FileAccess.Read))) + using BinaryReader m2file = new(new FileStream(filename, FileMode.Open, FileAccess.Read)); + // Check file has correct magic (MD21) + if (m2file.ReadUInt32() != 0x3132444D) //"MD21" { - // Check file has correct magic (MD21) - if (m2file.ReadUInt32() != 0x3132444D) //"MD21" - { - Log.outError(LogFilter.ServerLoading, "Camera file {0} is damaged. File identifier not found.", filename); - continue; - } - - m2file.ReadUInt32(); //unknown size - - // Read header - M2Header header = m2file.Read(); - - // Get camera(s) - Main header, then dump them. - m2file.BaseStream.Position = 8 + header.ofsCameras; - M2Camera cam = m2file.Read(); - - m2file.BaseStream.Position = 8; - ReadCamera(cam, new BinaryReader(new MemoryStream(m2file.ReadBytes((int)m2file.BaseStream.Length - 8))), cameraEntry); + Log.outError(LogFilter.ServerLoading, "Camera file {0} is damaged. File identifier not found.", filename); + continue; } + + m2file.ReadUInt32(); //unknown size + + // Read header + M2Header header = m2file.Read(); + + // Get camera(s) - Main header, then dump them. + m2file.BaseStream.Position = 8 + header.ofsCameras; + M2Camera cam = m2file.Read(); + + m2file.BaseStream.Position = 8; + ReadCamera(cam, new BinaryReader(new MemoryStream(m2file.ReadBytes((int)m2file.BaseStream.Length - 8))), cameraEntry); } catch (EndOfStreamException) { diff --git a/Source/Game/DungeonFinding/LFGManager.cs b/Source/Game/DungeonFinding/LFGManager.cs index 9d02e5bac..74efbd14a 100644 --- a/Source/Game/DungeonFinding/LFGManager.cs +++ b/Source/Game/DungeonFinding/LFGManager.cs @@ -987,7 +987,7 @@ namespace Game.DungeonFinding ObjectGuid pguid = it.Key; ObjectGuid gguid = it.Value.group; uint dungeonId = GetSelectedDungeons(pguid).First(); - int waitTime = -1; + int waitTime; if (sendUpdate) SendLfgUpdateProposal(pguid, proposal); diff --git a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs index e0f081eac..aaff82e7d 100644 --- a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs +++ b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs @@ -140,7 +140,7 @@ namespace Game.Entities if (GetMiscTemplate().ExtraScale.Raw.Data[5] != 0) SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.ParameterCurve), GetMiscTemplate().ExtraScale.Raw.Data[5]); if (GetMiscTemplate().ExtraScale.Structured.OverrideActive != 0) - SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.OverrideActive), GetMiscTemplate().ExtraScale.Structured.OverrideActive != 0 ? true : false); + SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.OverrideActive), GetMiscTemplate().ExtraScale.Structured.OverrideActive != 0); } diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 1b031aaa9..4a2d45ce4 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -921,7 +921,7 @@ namespace Game.Entities public Unit SelectVictim() { - Unit target = null; + Unit target; ThreatManager mgr = GetThreatManager(); diff --git a/Source/Game/Entities/Creature/Gossip.cs b/Source/Game/Entities/Creature/Gossip.cs index c0ff3319f..481ec2770 100644 --- a/Source/Game/Entities/Creature/Gossip.cs +++ b/Source/Game/Entities/Creature/Gossip.cs @@ -86,7 +86,7 @@ namespace Game.Misc continue; // Store texts for localization. - string strOptionText = "", strBoxText = ""; + string strOptionText, strBoxText; BroadcastTextRecord optionBroadcastText = CliDB.BroadcastTextStorage.LookupByKey(item.OptionBroadcastTextId); BroadcastTextRecord boxBroadcastText = CliDB.BroadcastTextStorage.LookupByKey(item.BoxBroadcastTextId); diff --git a/Source/Game/Entities/GameObject/GameObject.cs b/Source/Game/Entities/GameObject/GameObject.cs index 4ee05e0a7..dc14de92b 100644 --- a/Source/Game/Entities/GameObject/GameObject.cs +++ b/Source/Game/Entities/GameObject/GameObject.cs @@ -635,7 +635,7 @@ namespace Game.Entities else radius = goInfo.Trap.radius / 2.0f; - Unit target = null; + Unit target; // @todo this hack with search required until GO casting not implemented Unit owner = GetOwner(); if (owner) @@ -1169,7 +1169,7 @@ namespace Game.Entities } long thisRespawnTime = forceDelay != 0 ? GameTime.GetGameTime() + forceDelay : m_respawnTime; - GetMap().SaveRespawnTime(SpawnObjectType.GameObject, m_spawnId, GetEntry(), thisRespawnTime, GetZoneId(), GridDefines.ComputeGridCoord(GetPositionX(), GetPositionY()).GetId(), m_goData.dbData ? savetodb : false); + GetMap().SaveRespawnTime(SpawnObjectType.GameObject, m_spawnId, GetEntry(), thisRespawnTime, GetZoneId(), GridDefines.ComputeGridCoord(GetPositionX(), GetPositionY()).GetId(), m_goData.dbData && savetodb); } } diff --git a/Source/Game/Entities/Object/Position.cs b/Source/Game/Entities/Object/Position.cs index 6dc7d20d1..723cc834c 100644 --- a/Source/Game/Entities/Object/Position.cs +++ b/Source/Game/Entities/Object/Position.cs @@ -98,7 +98,7 @@ namespace Game.Entities { posX = (float)(posX + (offset.posX * Math.Cos(Orientation) + offset.posY * Math.Sin(Orientation + MathFunctions.PI))); posY = (float)(posY + (offset.posY * Math.Cos(Orientation) + offset.posX * Math.Sin(Orientation))); - posZ = posZ + offset.posZ; + posZ += offset.posZ; SetOrientation(Orientation + offset.Orientation); } @@ -162,7 +162,7 @@ namespace Game.Entities if (o < 0) { float mod = o * -1; - mod = mod % (2.0f * MathFunctions.PI); + mod %= (2.0f * MathFunctions.PI); mod = -mod + 2.0f * MathFunctions.PI; return mod; } diff --git a/Source/Game/Entities/Object/Update/UpdateField.cs b/Source/Game/Entities/Object/Update/UpdateField.cs index c5d113d83..38e9f169b 100644 --- a/Source/Game/Entities/Object/Update/UpdateField.cs +++ b/Source/Game/Entities/Object/Update/UpdateField.cs @@ -26,9 +26,8 @@ namespace Game.Entities public class UpdateFieldHolder { UpdateMask _changesMask = new((int)TypeId.Max); - WorldObject _owner; - public UpdateFieldHolder(WorldObject owner) { _owner = owner; } + public UpdateFieldHolder(WorldObject owner) { } public BaseUpdateData ModifyValue(BaseUpdateData updateData) { diff --git a/Source/Game/Entities/Player/Player.DB.cs b/Source/Game/Entities/Player/Player.DB.cs index 3802c811b..a3267b5b8 100644 --- a/Source/Game/Entities/Player/Player.DB.cs +++ b/Source/Game/Entities/Player/Player.DB.cs @@ -98,7 +98,7 @@ namespace Game.Entities } else { - Log.outError(LogFilter.Player, $"Player._LoadInventory: Player '{GetName()}' ({GetGUID().ToString()}) has child item ({item.GetGUID()}, entry: {item.GetEntry()}) which can't be loaded into inventory because parent item was not found (Bag {bagGuid}, slot: {slot}). Item will be sent by mail."); + Log.outError(LogFilter.Player, $"Player._LoadInventory: Player '{GetName()}' ({GetGUID()}) has child item ({item.GetGUID()}, entry: {item.GetEntry()}) which can't be loaded into inventory because parent item was not found (Bag {bagGuid}, slot: {slot}). Item will be sent by mail."); item.DeleteFromInventoryDB(trans); problematicItems.Enqueue(item); continue; @@ -1891,7 +1891,7 @@ namespace Game.Entities void _SaveActions(SQLTransaction trans) { - PreparedStatement stmt = null; + PreparedStatement stmt; foreach (var pair in m_actionButtons.ToList()) { diff --git a/Source/Game/Entities/Player/Player.Items.cs b/Source/Game/Entities/Player/Player.Items.cs index cd8f5e382..ae0295e2e 100644 --- a/Source/Game/Entities/Player/Player.Items.cs +++ b/Source/Game/Entities/Player/Player.Items.cs @@ -495,8 +495,7 @@ namespace Game.Entities } InventoryResult CanStoreItem(byte bag, byte slot, List dest, uint entry, uint count, Item pItem, bool swap) { - uint throwaway; - return CanStoreItem(bag, slot, dest, entry, count, pItem, swap, out throwaway); + return CanStoreItem(bag, slot, dest, entry, count, pItem, swap, out _); } InventoryResult CanStoreItem(byte bag, byte slot, List dest, uint entry, uint count, Item pItem, bool swap, out uint no_space_count) { diff --git a/Source/Game/Entities/Player/Player.Spells.cs b/Source/Game/Entities/Player/Player.Spells.cs index 62d8d6231..392a95453 100644 --- a/Source/Game/Entities/Player/Player.Spells.cs +++ b/Source/Game/Entities/Player/Player.Spells.cs @@ -1413,13 +1413,13 @@ namespace Game.Entities switch (Condition.Operator[i]) { case 2: // requires less than ( || ) gems - activate &= (_cur_gem < _cmp_gem) ? true : false; + activate &= (_cur_gem < _cmp_gem); break; case 3: // requires more than ( || ) gems - activate &= (_cur_gem > _cmp_gem) ? true : false; + activate &= (_cur_gem > _cmp_gem); break; case 5: // requires at least than ( || ) gems - activate &= (_cur_gem >= _cmp_gem) ? true : false; + activate &= (_cur_gem >= _cmp_gem); break; } } @@ -2039,7 +2039,7 @@ namespace Game.Entities { PlayerSpell spell = m_spells.LookupByKey(spellId); - bool disabled = (spell != null) ? spell.Disabled : false; + bool disabled = (spell != null) && spell.Disabled; bool active = !disabled || spell.Active; bool learning = AddSpell(spellId, active, true, dependent, false, false, fromSkill); @@ -2989,7 +2989,7 @@ namespace Game.Entities public void SetRuneCooldown(byte index, uint cooldown) { m_runes.Cooldown[index] = cooldown; - m_runes.SetRuneState(index, (cooldown == 0) ? true : false); + m_runes.SetRuneState(index, (cooldown == 0)); int activeRunes = m_runes.Cooldown.Count(p => p == 0); if (activeRunes != GetPower(PowerType.Runes)) SetPower(PowerType.Runes, activeRunes); diff --git a/Source/Game/Entities/Player/PlayerTaxi.cs b/Source/Game/Entities/Player/PlayerTaxi.cs index 4b648d21d..b107b6a9c 100644 --- a/Source/Game/Entities/Player/PlayerTaxi.cs +++ b/Source/Game/Entities/Player/PlayerTaxi.cs @@ -155,9 +155,8 @@ namespace Game.Entities for (int i = 1; i < m_TaxiDestinations.Count; ++i) { - uint cost; uint path; - Global.ObjectMgr.GetTaxiPath(m_TaxiDestinations[i - 1], m_TaxiDestinations[i], out path, out cost); + Global.ObjectMgr.GetTaxiPath(m_TaxiDestinations[i - 1], m_TaxiDestinations[i], out path, out _); if (path == 0) return false; } @@ -189,9 +188,8 @@ namespace Game.Entities return 0; uint path; - uint cost; - Global.ObjectMgr.GetTaxiPath(m_TaxiDestinations[0], m_TaxiDestinations[1], out path, out cost); + Global.ObjectMgr.GetTaxiPath(m_TaxiDestinations[0], m_TaxiDestinations[1], out path, out _); return path; } diff --git a/Source/Game/Entities/Taxi/TaxiPathGraph.cs b/Source/Game/Entities/Taxi/TaxiPathGraph.cs index d02f26acc..781b31b2d 100644 --- a/Source/Game/Entities/Taxi/TaxiPathGraph.cs +++ b/Source/Game/Entities/Taxi/TaxiPathGraph.cs @@ -137,8 +137,7 @@ namespace Game.Entities */ // Find if we have a direct path - uint pathId, goldCost; - Global.ObjectMgr.GetTaxiPath(from.Id, to.Id, out pathId, out goldCost); + Global.ObjectMgr.GetTaxiPath(from.Id, to.Id, out uint pathId, out _); if (pathId != 0) { shortestPath.Add(from.Id); diff --git a/Source/Game/Entities/TemporarySummon.cs b/Source/Game/Entities/TemporarySummon.cs index fad09c2ef..9bdd6af97 100644 --- a/Source/Game/Entities/TemporarySummon.cs +++ b/Source/Game/Entities/TemporarySummon.cs @@ -833,7 +833,7 @@ namespace Game.Entities if (ranged) return; - float val = 0.0f; + float val; float bonusAP = 0.0f; UnitMods unitMod = UnitMods.AttackPower; diff --git a/Source/Game/Entities/Transport.cs b/Source/Game/Entities/Transport.cs index ba7a61c37..dd240a76a 100644 --- a/Source/Game/Entities/Transport.cs +++ b/Source/Game/Entities/Transport.cs @@ -188,7 +188,7 @@ namespace Game.Entities if (_pendingStop && GetGoState() != GameObjectState.Ready) { SetGoState(GameObjectState.Ready); - m_goValue.Transport.PathProgress = (m_goValue.Transport.PathProgress / GetTransportPeriod()); + m_goValue.Transport.PathProgress /= GetTransportPeriod(); m_goValue.Transport.PathProgress *= GetTransportPeriod(); m_goValue.Transport.PathProgress += _currentFrame.ArriveTime; } diff --git a/Source/Game/Entities/Unit/CharmInfo.cs b/Source/Game/Entities/Unit/CharmInfo.cs index 33826e897..83a91c940 100644 --- a/Source/Game/Entities/Unit/CharmInfo.cs +++ b/Source/Game/Entities/Unit/CharmInfo.cs @@ -150,7 +150,7 @@ namespace Game.Entities { _charmspells[x].SetActionAndType(spellId, ActiveStates.Disabled); - ActiveStates newstate = ActiveStates.Passive; + ActiveStates newstate; if (!spellInfo.IsAutocastable()) newstate = ActiveStates.Passive; diff --git a/Source/Game/Entities/Unit/Unit.Combat.cs b/Source/Game/Entities/Unit/Unit.Combat.cs index 1f8cb4bff..eb2d9f417 100644 --- a/Source/Game/Entities/Unit/Unit.Combat.cs +++ b/Source/Game/Entities/Unit/Unit.Combat.cs @@ -1337,7 +1337,7 @@ namespace Game.Entities // 1. > 2. > 3. > 4. > 5. > 6. > 7. > 8. // MISS > DODGE > PARRY > GLANCING > BLOCK > CRIT > CRUSHING > HIT - int sum = 0, tmp = 0; + int sum = 0; int roll = RandomHelper.IRand(0, 9999); uint attackerLevel = GetLevelForTarget(victim); @@ -1357,7 +1357,7 @@ namespace Game.Entities } // 1. MISS - tmp = miss_chance; + int tmp = miss_chance; if (tmp > 0 && roll < (sum += tmp)) return MeleeHitOutcome.Miss; @@ -1477,9 +1477,9 @@ namespace Game.Entities if (minDamage > maxDamage) { - minDamage = minDamage + maxDamage; + minDamage += maxDamage; maxDamage = minDamage - maxDamage; - minDamage = minDamage - maxDamage; + minDamage -= maxDamage; } if (maxDamage == 0.0f) diff --git a/Source/Game/Entities/Unit/Unit.Fields.cs b/Source/Game/Entities/Unit/Unit.Fields.cs index 90bac110f..98568f237 100644 --- a/Source/Game/Entities/Unit/Unit.Fields.cs +++ b/Source/Game/Entities/Unit/Unit.Fields.cs @@ -84,7 +84,6 @@ namespace Game.Entities //Spells protected Dictionary m_currentSpells = new((int)CurrentSpellTypes.Max); - Dictionary CustomSpellValueMod = new(); MultiMap[] m_spellImmune = new MultiMap[(int)SpellImmunity.Max]; SpellAuraInterruptFlags m_interruptMask; SpellAuraInterruptFlags2 m_interruptMask2; @@ -93,7 +92,6 @@ namespace Game.Entities SpellHistory _spellHistory; //Auras - List AuraEffectList = new(); MultiMap m_modAuras = new(); List m_removedAuras = new(); List m_interruptableAuras = new(); // auras which have interrupt mask applied on unit diff --git a/Source/Game/Entities/Unit/Unit.Movement.cs b/Source/Game/Entities/Unit/Unit.Movement.cs index 7f7be2e01..4b4e79f6d 100644 --- a/Source/Game/Entities/Unit/Unit.Movement.cs +++ b/Source/Game/Entities/Unit/Unit.Movement.cs @@ -687,8 +687,8 @@ namespace Game.Entities uint areaId = GetAreaId(); uint ridingSkill = 5000; AreaMountFlags mountFlags = 0; - bool isSubmerged = false; - bool isInWater = false; + bool isSubmerged; + bool isInWater; if (IsTypeId(TypeId.Player)) ridingSkill = ToPlayer().GetSkillValue(SkillType.Riding); @@ -705,8 +705,7 @@ namespace Game.Entities mountFlags = (AreaMountFlags)areaTable.MountFlags; } - LiquidData liquid; - ZLiquidStatus liquidStatus = GetMap().GetLiquidStatus(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ(), LiquidHeaderTypeFlags.AllLiquids, out liquid); + ZLiquidStatus liquidStatus = GetMap().GetLiquidStatus(GetPhaseShift(), GetPositionX(), GetPositionY(), GetPositionZ(), LiquidHeaderTypeFlags.AllLiquids, out _); isSubmerged = liquidStatus.HasAnyFlag(ZLiquidStatus.UnderWater) || HasUnitMovementFlag(MovementFlag.Swimming); isInWater = liquidStatus.HasAnyFlag(ZLiquidStatus.InWater | ZLiquidStatus.UnderWater); diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 6b479b8b9..bd4c0e5a7 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -1371,7 +1371,7 @@ namespace Game.Entities public bool IsVisible() { - return (m_serverSideVisibility.GetValue(ServerSideVisibilityType.GM) > (uint)AccountTypes.Player) ? false : true; + return m_serverSideVisibility.GetValue(ServerSideVisibilityType.GM) <= (uint)AccountTypes.Player; } public void SetVisible(bool val) diff --git a/Source/Game/Entities/Vehicle.cs b/Source/Game/Entities/Vehicle.cs index b897f0b15..715975a33 100644 --- a/Source/Game/Entities/Vehicle.cs +++ b/Source/Game/Entities/Vehicle.cs @@ -527,7 +527,6 @@ namespace Game.Entities Unit _me; VehicleRecord _vehicleInfo; //< DBC data for vehicle - List vehiclePlayers = new(); uint _creatureEntry; //< Can be different than the entry of _me in case of players Status _status; //< Internal variable for sanity checks diff --git a/Source/Game/Garrisons/Garrisons.cs b/Source/Game/Garrisons/Garrisons.cs index 877ba0c48..edf66aa4d 100644 --- a/Source/Game/Garrisons/Garrisons.cs +++ b/Source/Game/Garrisons/Garrisons.cs @@ -782,7 +782,7 @@ namespace Game.Garrisons foreach (var guid in BuildingInfo.Spawns) { - WorldObject obj = null; + WorldObject obj; switch (guid.GetHigh()) { case HighGuid.Creature: diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index d2c4ae145..e20134883 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -70,7 +70,7 @@ namespace Game { int pos = name.IndexOf('-'); if (pos != -1) - return new ExtendedPlayerName(name.Substring(0, pos), name.Substring(pos + 1)); + return new ExtendedPlayerName(name.Substring(0, pos), name[(pos + 1)..]); else return new ExtendedPlayerName(name, ""); } diff --git a/Source/Game/Groups/Group.cs b/Source/Game/Groups/Group.cs index 1d6658df6..33dca6b81 100644 --- a/Source/Game/Groups/Group.cs +++ b/Source/Game/Groups/Group.cs @@ -195,7 +195,7 @@ namespace Game.Groups public void ConvertToRaid() { - m_groupFlags = (m_groupFlags | GroupFlags.Raid); + m_groupFlags |= GroupFlags.Raid; _initRaidSubGroupsCounter(); @@ -1144,7 +1144,7 @@ namespace Game.Groups { byte maxresul = 0; ObjectGuid maxguid = ObjectGuid.Empty; - Player player = null; + Player player; foreach (var pair in roll.playerVote) { @@ -1205,7 +1205,7 @@ namespace Game.Groups { byte maxresul = 0; ObjectGuid maxguid = ObjectGuid.Empty; - Player player = null; + Player player; RollType rollVote = RollType.NotValid; foreach (var pair in roll.playerVote) @@ -2102,7 +2102,7 @@ namespace Game.Groups public void ResetMaxEnchantingLevel() { m_maxEnchantingLevel = 0; - Player member = null; + Player member; foreach (var memberSlot in m_memberSlots) { member = Global.ObjAccessor.FindPlayer(memberSlot.guid); diff --git a/Source/Game/Reputation/ReputationManager.cs b/Source/Game/Reputation/ReputationManager.cs index 5c555ec8d..40f0e144f 100644 --- a/Source/Game/Reputation/ReputationManager.cs +++ b/Source/Game/Reputation/ReputationManager.cs @@ -783,7 +783,7 @@ namespace Game bool _sendFactionIncreased; //! Play visual effect on next SMSG_SET_FACTION_STANDING sent #endregion - static int[] ReputationRankThresholds = + public static int[] ReputationRankThresholds = { -42000, // Hated @@ -803,7 +803,7 @@ namespace Game // Exalted }; - static CypherStrings[] ReputationRankStrIndex = + public static CypherStrings[] ReputationRankStrIndex = { CypherStrings.RepHated, CypherStrings.RepHostile, CypherStrings.RepUnfriendly, CypherStrings.RepNeutral, CypherStrings.RepFriendly, CypherStrings.RepHonored, CypherStrings.RepRevered, CypherStrings.RepExalted diff --git a/Source/WorldServer/Server.cs b/Source/WorldServer/Server.cs index 66b1a5db3..50cc81a67 100644 --- a/Source/WorldServer/Server.cs +++ b/Source/WorldServer/Server.cs @@ -98,7 +98,7 @@ namespace WorldServer //- Launch CliRunnable thread if (ConfigMgr.GetDefaultValue("Console.Enable", true)) { - Thread commandThread = new Thread(CommandManager.InitConsole); + Thread commandThread = new(CommandManager.InitConsole); commandThread.Start(); } @@ -143,7 +143,7 @@ namespace WorldServer static bool StartDB() { // Load databases - DatabaseLoader loader = new DatabaseLoader(DatabaseTypeFlags.All); + DatabaseLoader loader = new(DatabaseTypeFlags.All); loader.AddDatabase(DB.Login, "Login"); loader.AddDatabase(DB.Characters, "Character"); loader.AddDatabase(DB.World, "World");