Skip to content

Commit fb02876

Browse files
committed
PetAI: Fix handling of scripted combat with pets
1 parent a28848a commit fb02876

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/game/AI/BaseAI/PetAI.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void PetAI::MoveInLineOfSight(Unit* who)
7979
&& m_unit->IsWithinDistInMap(who, m_unit->GetAttackDistance(who))
8080
&& m_unit->GetDistanceZ(who) <= CREATURE_Z_ATTACK_RANGE_MELEE
8181
&& m_unit->IsWithinLOSInMap(who, true)
82+
&& !GetCombatScriptStatus()
8283
&& !who->IsCrowdControlled()
8384
&& !who->HasAuraPetShouldAvoidBreaking(m_pet, charmInfo->GetPetLastAttackCommandTime()))
8485
{
@@ -94,6 +95,9 @@ void PetAI::AttackStart(Unit* who)
9495
if (m_pet && m_pet->HasActionsDisabled())
9596
return;
9697

98+
if (GetCombatScriptStatus())
99+
return;
100+
97101
if (m_unit->Attack(who, m_meleeEnabled))
98102
{
99103
// TMGs call CreatureRelocation which via MoveInLineOfSight can call this function
@@ -129,6 +133,12 @@ void PetAI::UpdateAI(const uint32 diff)
129133
if (!owner)
130134
return;
131135

136+
if (GetCombatScriptStatus())
137+
{
138+
m_inCombat = false;
139+
return;
140+
}
141+
132142
Unit* victim = m_pet && m_pet->HasActionsDisabled() ? nullptr : m_unit->GetVictim();
133143

134144
CharmInfo* charmInfo = m_unit->GetCharmInfo();
@@ -186,7 +196,7 @@ void PetAI::UpdateAI(const uint32 diff)
186196
}
187197

188198
// if pet misses its target, it will also be the first in threat list
189-
if (m_meleeEnabled && m_unit->CanReachWithMeleeAttack(victim))
199+
if (m_inCombat && m_meleeEnabled && m_unit->CanReachWithMeleeAttack(victim))
190200
{
191201
if (!m_unit->HasInArc(victim, 2 * M_PI_F / 3))
192202
m_unit->SetFacingToObject(victim);
@@ -374,6 +384,6 @@ void PetAI::AttackedBy(Unit* attacker)
374384
MANGOS_ASSERT(charmInfo);
375385

376386
// when attacked, fight back if no victim unless we have a charm state set to passive
377-
if (!(m_unit->GetVictim() || charmInfo->GetIsRetreating() || HasReactState(REACT_PASSIVE)))
387+
if (!(m_unit->GetVictim() || GetCombatScriptStatus() || charmInfo->GetIsRetreating() || HasReactState(REACT_PASSIVE)))
378388
AttackStart(attacker);
379389
}

0 commit comments

Comments
 (0)