Skip to content

Commit

Permalink
fix(Core/Unit): Fix fast creatures chasing indefinitely (#21200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyeriah authored Jan 18, 2025
1 parent 4a3fab4 commit 882951c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10384,6 +10384,10 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
if (meleeAttack)
AddUnitState(UNIT_STATE_MELEE_ATTACKING);

// Update leash timer when attacking creatures
if (victim->IsCreature())
victim->ToCreature()->UpdateLeashExtensionTime();

// set position before any AI calls/assistance
//if (IsCreature())
// ToCreature()->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
Expand All @@ -10393,6 +10397,7 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
SetInCombatWith(victim);
if (victim->IsPlayer())
victim->SetInCombatWith(this);

AddThreat(victim, 0.0f);

creature->SendAIReaction(AI_REACTION_HOSTILE);
Expand Down Expand Up @@ -13623,9 +13628,6 @@ void Unit::SetInCombatWith(Unit* enemy, uint32 duration)
}
}

if (Creature* pCreature = ToCreature())
pCreature->UpdateLeashExtensionTime();

SetInCombatState(false, enemy, duration);
}

Expand Down Expand Up @@ -13700,6 +13702,10 @@ void Unit::CombatStart(Unit* victim, bool initialAggro)
SetInCombatWith(victim);
victim->SetInCombatWith(this);

// Update leash timer when attacking creatures
if (victim->IsCreature())
victim->ToCreature()->UpdateLeashExtensionTime();

// Xinef: If pet started combat - put owner in combat
if (!alreadyInCombat && IsInCombat())
{
Expand Down Expand Up @@ -13736,6 +13742,12 @@ void Unit::CombatStartOnCast(Unit* target, bool initialAggro, uint32 duration)
// Xinef: If pet started combat - put owner in combat
if (Unit* owner = GetOwner())
owner->SetInCombatWith(target, duration);

// Update leash timer when attacking creatures
if (target->IsCreature())
target->ToCreature()->UpdateLeashExtensionTime();
else if (ToCreature()) // Reset leash if it is a spell caster, else it may evade inbetween casts
ToCreature()->UpdateLeashExtensionTime();
}

Unit* who = target->GetCharmerOrOwnerOrSelf();
Expand Down

0 comments on commit 882951c

Please sign in to comment.