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
This commit is contained in:
SaW
2025-02-02 01:39:57 +01:00
committed by GitHub
parent e07a9e194a
commit f5a8b3017e
2 changed files with 26 additions and 0 deletions

View File

@@ -146,8 +146,33 @@ bool AutoReleaseSpiritAction::isUseful()
if (bot->InArena()) if (bot->InArena())
return false; 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()) 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; return true;
}
if (bot->HasPlayerFlag(PLAYER_FLAGS_GHOST)) if (bot->HasPlayerFlag(PLAYER_FLAGS_GHOST))
return false; return false;

View File

@@ -33,6 +33,7 @@ public:
bool isUseful() override; bool isUseful() override;
private: private:
inline static std::unordered_map<uint32_t, time_t> botReleaseTimes;
uint32_t bg_gossip_time = 0; uint32_t bg_gossip_time = 0;
}; };