Skip to content

Commit

Permalink
BattleGround: Fix bot's already cast (ranged) spells to be redirected…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
nl-saw authored Feb 2, 2025
1 parent e07a9e1 commit f5a8b30
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/strategy/actions/ReleaseSpiritAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/strategy/actions/ReleaseSpiritAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AutoReleaseSpiritAction : public ReleaseSpiritAction
bool isUseful() override;

private:
inline static std::unordered_map<uint32_t, time_t> botReleaseTimes;
uint32_t bg_gossip_time = 0;
};

Expand Down

0 comments on commit f5a8b30

Please sign in to comment.