Skip to content

Commit

Permalink
NPCBots: Fix a bug where bot would not stop attacking a target after …
Browse files Browse the repository at this point in the history
…they use Vanish or Feign Death

(cherry picked from commit 09dcb8ec0e4051e58a6d764d7e7f1c3c7cee3784)

# Conflicts:
#	src/server/game/Entities/Unit/Unit.cpp
  • Loading branch information
trickerer committed Nov 7, 2024
1 parent 18ac8f0 commit 7ac618b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/server/game/AI/NpcBots/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11366,6 +11366,13 @@ void bot_ai::OnOwnerVehicleDamagedBy(Unit* attacker)
SetBotCommandState(BOT_COMMAND_ATTACK);
me->GetVehicleBase()->Attack(attacker, false);
}
void bot_ai::OnAttackStop(Unit const* target)
{
if (opponent == target)
opponent = nullptr;
if (disttarget == target)
disttarget = nullptr;
}
//////////
///LOOT///
//////////
Expand Down
1 change: 1 addition & 0 deletions src/server/game/AI/NpcBots/bot_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class bot_ai : public CreatureAI
void OnBotOwnerSpellGo(Spell const* spell, bool ok = true);
void OnBotChannelFinish(Spell const* spell);
void OnOwnerVehicleDamagedBy(Unit* attacker);
void OnAttackStop(Unit const* target);
virtual void OnClassSpellStart(SpellInfo const* /*spellInfo*/) {}
virtual void OnClassSpellGo(SpellInfo const* /*spell*/) {}
virtual void OnClassChannelFinish(Spell const* /*spell*/) {}
Expand Down
8 changes: 8 additions & 0 deletions src/server/game/AI/NpcBots/botmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,14 @@ void BotMgr::OnBotPartyEngage(Player const* owner)
owner->GetBotMgr()->PropagateEngageTimers();
}

void BotMgr::OnBotAttackStop(Creature const* bot, Unit const* target)
{
if (bot->IsNPCBot())
bot->GetBotAI()->OnAttackStop(target);
else if (bot->IsNPCBotPet())
bot->GetBotPetAI()->OnAttackStop(target);
}

void BotMgr::ApplyBotEffectMods(Unit const* caster, SpellInfo const* spellInfo, uint8 effIndex, float& value)
{
caster->ToCreature()->GetBotAI()->ApplyBotEffectMods(spellInfo, effIndex, value);
Expand Down
1 change: 1 addition & 0 deletions src/server/game/AI/NpcBots/botmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class AC_GAME_API BotMgr
static void OnBotOwnerEnterVehicle(Player const* passenger, Vehicle const* vehicle);
static void OnBotOwnerExitVehicle(Player const* passenger, Vehicle const* vehicle);
static void OnBotPartyEngage(Player const* owner);
static void OnBotAttackStop(Creature const* bot, Unit const* target);
//mod hooks
static void ApplyBotEffectMods(Unit const* caster, SpellInfo const* spellInfo, uint8 effIndex, float& value);
static void ApplyBotThreatMods(Unit const* attacker, SpellInfo const* spellInfo, float& threat);
Expand Down
5 changes: 5 additions & 0 deletions src/server/game/AI/NpcBots/bpet_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,11 @@ void bot_pet_ai::OnOwnerDamagedBy(Unit* attacker)
SetBotCommandState(BOT_COMMAND_COMBATRESET);
me->Attack(attacker, IsPetMelee());
}
void bot_pet_ai::OnAttackStop(Unit const* target)
{
if (opponent == target)
opponent = nullptr;
}

bool bot_pet_ai::IsPetMelee() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/server/game/AI/NpcBots/bpet_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class bot_pet_ai : public CreatureAI
//virtual uint32 GetAIMiscValue(uint32 /*data*/) const { return 0; }
//virtual void SetAIMiscValue(uint32 /*data*/, uint32 /*value*/) {}

void OnAttackStop(Unit const* target);

void OnBotPetSpellInterrupted(SpellSchoolMask schoolMask, uint32 unTimeMs);
void OnBotPetSpellGo(Spell const* spell, bool ok = true);
virtual void OnPetClassSpellGo(SpellInfo const* /*spellInfo*/) {}
Expand Down
5 changes: 5 additions & 0 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11061,6 +11061,11 @@ bool Unit::AttackStop()
{
creature->SetNoSearchAssistance(false);
}

//npcbot
if (IsNPCBotOrPet())
BotMgr::OnBotAttackStop(creature, victim);
//end npcbot
}

SendMeleeAttackStop(victim);
Expand Down

0 comments on commit 7ac618b

Please sign in to comment.