From 5720b89b7e2c424f82aeae6a4106246491e06fb8 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 25 Feb 2022 19:43:04 -0500 Subject: [PATCH] Core/Player: Added PlayerCreateMode field to playercreateinfo_cast_spell to only cast spells based on related mode Port From (https://github.com/TrinityCore/TrinityCore/commit/8a61024cfad05279791badf33fcdb5a608ad6e94) --- Source/Framework/Constants/PlayerConst.cs | 4 +++- Source/Game/Entities/Player/Player.Fields.cs | 8 +++++++- Source/Game/Globals/ObjectManager.cs | 17 ++++++++++++----- Source/Game/Handlers/CharacterHandler.cs | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Source/Framework/Constants/PlayerConst.cs b/Source/Framework/Constants/PlayerConst.cs index 7cb92d028..19c34aa24 100644 --- a/Source/Framework/Constants/PlayerConst.cs +++ b/Source/Framework/Constants/PlayerConst.cs @@ -794,7 +794,9 @@ namespace Framework.Constants public enum PlayerCreateMode { Normal = 0, - NPE = 1 + NPE = 1, + + Max } public enum DuelState diff --git a/Source/Game/Entities/Player/Player.Fields.cs b/Source/Game/Entities/Player/Player.Fields.cs index e030decfc..38711139c 100644 --- a/Source/Game/Entities/Player/Player.Fields.cs +++ b/Source/Game/Entities/Player/Player.Fields.cs @@ -269,7 +269,7 @@ namespace Game.Entities public List item = new(); public List customSpells = new(); - public List castSpells = new(); + public List[] castSpells = new List[(int)PlayerCreateMode.Max]; public List action = new(); public List skills = new(); @@ -279,6 +279,12 @@ namespace Game.Entities public PlayerLevelInfo[] levelInfo = new PlayerLevelInfo[WorldConfig.GetIntValue(WorldCfg.MaxPlayerLevel)]; + public PlayerInfo() + { + for (var i = 0; i < castSpells.Length; ++i) + castSpells[i] = new List(); + } + public struct CreatePosition { public WorldLocation Loc; diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index ded3f0055..210f7cf49 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -6123,7 +6123,7 @@ namespace Game { uint oldMSTime = Time.GetMSTime(); - SQLResult result = DB.World.Query("SELECT raceMask, classMask, spell FROM playercreateinfo_cast_spell"); + SQLResult result = DB.World.Query("SELECT raceMask, classMask, spell, createMode FROM playercreateinfo_cast_spell"); if (result.IsEmpty()) Log.outInfo(LogFilter.ServerLoading, "Loaded 0 player create cast spells. DB table `playercreateinfo_cast_spell` is empty."); @@ -6136,16 +6136,23 @@ namespace Game ulong raceMask = result.Read(0); uint classMask = result.Read(1); uint spellId = result.Read(2); + sbyte playerCreateMode = result.Read(3); if (raceMask != 0 && (raceMask & SharedConst.RaceMaskAllPlayable) == 0) { - Log.outError(LogFilter.Sql, "Wrong race mask {0} in `playercreateinfo_cast_spell` table, ignoring.", raceMask); + Log.outError(LogFilter.Sql, $"Wrong race mask {raceMask} in `playercreateinfo_cast_spell` table, ignoring."); continue; } - if (classMask != 0 && !classMask.HasAnyFlag((uint)Class.ClassMaskAllPlayable)) + if (classMask != 0 && !classMask.HasAnyFlag((uint)Class.ClassMaskAllPlayable)) { - Log.outError(LogFilter.Sql, "Wrong class mask {0} in `playercreateinfo_cast_spell` table, ignoring.", classMask); + Log.outError(LogFilter.Sql, $"Wrong class mask {classMask} in `playercreateinfo_cast_spell` table, ignoring."); + continue; + } + + if (playerCreateMode < 0 || playerCreateMode >= (sbyte)PlayerCreateMode.Max) + { + Log.outError(LogFilter.Sql, $"Uses invalid createMode {playerCreateMode} in `playercreateinfo_cast_spell` table, ignoring."); continue; } @@ -6160,7 +6167,7 @@ namespace Game PlayerInfo info = _playerInfo[(int)raceIndex][classIndex]; if (info != null) { - info.castSpells.Add(spellId); + info.castSpells[playerCreateMode].Add(spellId); ++count; } } diff --git a/Source/Game/Handlers/CharacterHandler.cs b/Source/Game/Handlers/CharacterHandler.cs index 7c1010544..743476642 100644 --- a/Source/Game/Handlers/CharacterHandler.cs +++ b/Source/Game/Handlers/CharacterHandler.cs @@ -963,7 +963,7 @@ namespace Game pCurrChar.RemoveAtLoginFlag(AtLoginFlags.FirstLogin); PlayerInfo info = Global.ObjectMgr.GetPlayerInfo(pCurrChar.GetRace(), pCurrChar.GetClass()); - foreach (var spellId in info.castSpells) + foreach (var spellId in info.castSpells[(int)pCurrChar.GetCreateMode()]) pCurrChar.CastSpell(pCurrChar, spellId, new CastSpellExtraArgs(true)); // start with every map explored