From f5a8b3017e8732810375ac5645a733471cf36044 Mon Sep 17 00:00:00 2001 From: SaW Date: Sun, 2 Feb 2025 01:39:57 +0100 Subject: [PATCH] BattleGround: Fix bot's already cast (ranged) spells to be redirected to bot's ghost on death (#934) * Update ReleaseSpiritAction.h - add bg_release_time * Update ReleaseSpiritAction.cpp * Update ReleaseSpiritAction.cpp - Move LOG_DEBUG Correct LOG_DEBUG position. * Reliable fix (#67) Reliable fix * Reduced wait time from 8 to 6 min * Update comment --- src/strategy/actions/ReleaseSpiritAction.cpp | 25 ++++++++++++++++++++ src/strategy/actions/ReleaseSpiritAction.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/strategy/actions/ReleaseSpiritAction.cpp b/src/strategy/actions/ReleaseSpiritAction.cpp index 6f49574d..70f7e33c 100644 --- a/src/strategy/actions/ReleaseSpiritAction.cpp +++ b/src/strategy/actions/ReleaseSpiritAction.cpp @@ -146,8 +146,33 @@ bool AutoReleaseSpiritAction::isUseful() if (bot->InArena()) return false; + // if (bot->InBattleground()) + // return true; + + // When bot dies in BG, wait a couple of seconds before release. + // This prevents currently casted (ranged) spells to be re-directed to the bot's ghost. + // Use a static map to track release times for each bot. if (bot->InBattleground()) + { + auto botId = bot->GetGUID().GetRawValue(); + + // If the bot is not a ghost yet, delay release some. + if (!bot->HasPlayerFlag(PLAYER_FLAGS_GHOST)) + { + time_t now = time(nullptr); + + // If this bot has no recorded release time yet, set it to now. + if (botReleaseTimes.find(botId) == botReleaseTimes.end()) + botReleaseTimes[botId] = now; + + // Wait 6 seconds before releasing. + if (now - botReleaseTimes[botId] < 6) + return false; + } + // Erase the release time for this bot. + botReleaseTimes.erase(botId); return true; + } if (bot->HasPlayerFlag(PLAYER_FLAGS_GHOST)) return false; diff --git a/src/strategy/actions/ReleaseSpiritAction.h b/src/strategy/actions/ReleaseSpiritAction.h index f21b3cdd..4fcb8c44 100644 --- a/src/strategy/actions/ReleaseSpiritAction.h +++ b/src/strategy/actions/ReleaseSpiritAction.h @@ -33,6 +33,7 @@ public: bool isUseful() override; private: + inline static std::unordered_map botReleaseTimes; uint32_t bg_gossip_time = 0; };