From bceaddb73b3b58ea3bbed9bd1bfefa1db7eca5ff Mon Sep 17 00:00:00 2001 From: Andrew <47818697+Nyeriah@users.noreply.github.com> Date: Thu, 7 May 2026 21:24:27 -0300 Subject: [PATCH] feat(Core/Scripting): Add OnBattlefieldWarEnd script hook (#25754) Co-authored-by: Claude Sonnet 4.6 --- src/server/game/Battlefield/Battlefield.cpp | 1 + .../Scripting/ScriptDefines/BattlefieldScript.cpp | 5 +++++ .../game/Scripting/ScriptDefines/BattlefieldScript.h | 12 ++++++++++++ src/server/game/Scripting/ScriptMgr.h | 1 + 4 files changed, 19 insertions(+) diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp index a7494f1e6f..a37534dbb6 100644 --- a/src/server/game/Battlefield/Battlefield.cpp +++ b/src/server/game/Battlefield/Battlefield.cpp @@ -364,6 +364,7 @@ void Battlefield::EndBattle(bool endByTimer) DoPlaySoundToAll(BF_HORDE_WINS); OnBattleEnd(endByTimer); + sScriptMgr->OnBattlefieldWarEnd(this, endByTimer); // Reset battlefield timer Timer = NoWarBattleTime; diff --git a/src/server/game/Scripting/ScriptDefines/BattlefieldScript.cpp b/src/server/game/Scripting/ScriptDefines/BattlefieldScript.cpp index d614f1a8d9..18dabf3af5 100644 --- a/src/server/game/Scripting/ScriptDefines/BattlefieldScript.cpp +++ b/src/server/game/Scripting/ScriptDefines/BattlefieldScript.cpp @@ -44,6 +44,11 @@ void ScriptMgr::OnBattlefieldBeforeInvitePlayerToWar(Battlefield* bf, Player* pl CALL_ENABLED_HOOKS(BattlefieldScript, BATTLEFIELDHOOK_BEFORE_INVITE_PLAYER_TO_WAR, script->OnBattlefieldBeforeInvitePlayerToWar(bf, player)); } +void ScriptMgr::OnBattlefieldWarEnd(Battlefield* bf, bool endByTimer) +{ + CALL_ENABLED_HOOKS(BattlefieldScript, BATTLEFIELDHOOK_ON_WAR_END, script->OnBattlefieldWarEnd(bf, endByTimer)); +} + BattlefieldScript::BattlefieldScript(char const* name, std::vector enabledHooks) : ScriptObject(name, BATTLEFIELDHOOK_END) { diff --git a/src/server/game/Scripting/ScriptDefines/BattlefieldScript.h b/src/server/game/Scripting/ScriptDefines/BattlefieldScript.h index f2a4e19d9b..df17e570f8 100644 --- a/src/server/game/Scripting/ScriptDefines/BattlefieldScript.h +++ b/src/server/game/Scripting/ScriptDefines/BattlefieldScript.h @@ -28,6 +28,7 @@ enum BattlefieldHook BATTLEFIELDHOOK_ON_PLAYER_JOIN_WAR, // 2 - fires after player is added to the active war BATTLEFIELDHOOK_ON_PLAYER_LEAVE_WAR, // 3 - fires after player is removed from the active war BATTLEFIELDHOOK_BEFORE_INVITE_PLAYER_TO_WAR, // 4 - fires in InvitePlayerToWar before InvitedPlayers insert + BATTLEFIELDHOOK_ON_WAR_END, // 5 - fires in EndBattle after OnBattleEnd(), before timer reset BATTLEFIELDHOOK_END }; @@ -87,6 +88,17 @@ public: * @param player The player being invited to war */ virtual void OnBattlefieldBeforeInvitePlayerToWar(Battlefield* /*bf*/, Player* /*player*/) { } + + /** + * @brief Called in EndBattle() after OnBattleEnd() completes, before the timer is reset. + * All core PlayersInWar/InvitedPlayers structures have already been cleared. + * Modules that maintain their own per-war player tracking should use this hook + * to perform end-of-war cleanup (e.g. restoring cross-faction disguises). + * + * @param bf The Battlefield instance + * @param endByTimer True if the war ended by the countdown timer expiring + */ + virtual void OnBattlefieldWarEnd(Battlefield* /*bf*/, bool /*endByTimer*/) { } }; #endif // SCRIPT_OBJECT_BATTLEFIELD_SCRIPT_H_ diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index bce4a8214c..7d9e426786 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -587,6 +587,7 @@ public: /* BattlefieldScript */ void OnBattlefieldPlayerJoinWar(Battlefield* bf, Player* player); void OnBattlefieldPlayerLeaveWar(Battlefield* bf, Player* player); void OnBattlefieldBeforeInvitePlayerToWar(Battlefield* bf, Player* player); + void OnBattlefieldWarEnd(Battlefield* bf, bool endByTimer); public: /* BGScript */ void OnBattlegroundStart(Battleground* bg);