fix(Core/Leash): Improve leashing behavior and timer handling (#22525)

This commit is contained in:
Anton Popovichenko
2025-07-29 14:55:56 +02:00
committed by GitHub
parent 40c58123b1
commit 67aa022dbf
4 changed files with 51 additions and 7 deletions

View File

@@ -4185,6 +4185,15 @@ void Unit::InterruptNonMeleeSpells(bool withDelayed, uint32 spell_id, bool withI
InterruptSpell(CURRENT_CHANNELED_SPELL, true, true, bySelf);
}
Spell* Unit::GetFirstCurrentCastingSpell() const
{
for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++)
if (m_currentSpells[i] && m_currentSpells[i]->GetCastTimeRemaining() > 0)
return m_currentSpells[i];
return nullptr;
}
Spell* Unit::FindCurrentSpellBySpellId(uint32 spell_id) const
{
for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++)
@@ -10412,8 +10421,29 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
if (meleeAttack)
AddUnitState(UNIT_STATE_MELEE_ATTACKING);
Unit* owner = GetCharmerOrOwner();
Creature* ownerCreature = owner ? owner->ToCreature() : nullptr;
Creature* controlledCreatureWithSameVictim = nullptr;
if (creature && !m_Controlled.empty())
{
for (ControlSet::iterator itr = m_Controlled.begin(); itr != m_Controlled.end(); ++itr)
{
if ((*itr)->ToCreature() && (*itr)->GetVictim() == victim)
{
controlledCreatureWithSameVictim = (*itr)->ToCreature();
break;
}
}
}
// Share leash timer with controlled unit
if (controlledCreatureWithSameVictim)
creature->SetLastLeashExtensionTimePtr(controlledCreatureWithSameVictim->GetLastLeashExtensionTimePtr());
// Share leash timer with owner
else if (creature && ownerCreature && ownerCreature->GetVictim() == victim)
creature->SetLastLeashExtensionTimePtr(ownerCreature->GetLastLeashExtensionTimePtr());
// Update leash timer when attacking creatures
if (victim->IsCreature())
else if (victim->IsCreature())
victim->ToCreature()->UpdateLeashExtensionTime();
// set position before any AI calls/assistance