fix(Core/Scripts): Fix DK pets not correctly attacking (#25128)

Co-authored-by: blinkysc <blinkysc@users.noreply.github.com>
Co-authored-by: Treeston <treeston.mmoc@gmail.com>
Co-authored-by: Malcrom <malcromdev@gmail.com>
Co-authored-by: Aqua Deus <95978183+aquadeus@users.noreply.github.com>
This commit is contained in:
blinkysc 2026-03-20 07:14:58 -05:00 committed by GitHub
parent ebcaddb98d
commit 48fa4d2856
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 62 additions and 64 deletions

View file

@ -943,13 +943,13 @@ uint32 Unit::DealDamage(Unit* attacker, Unit* victim, uint32 damage, CleanDamage
// Hook for OnDamage Event
sScriptMgr->OnDamage(attacker, victim, damage);
if (victim->IsPlayer() && attacker != victim)
// Signal to pets that their owner was attacked - except when DOT.
if (attacker != victim && damagetype != DOT)
{
// Signal to pets that their owner was attacked
Pet* pet = victim->ToPlayer()->GetPet();
if (pet && pet->IsAlive())
pet->AI()->OwnerAttackedBy(attacker);
for (Unit* controlled : victim->m_Controlled)
if (Creature* cControlled = controlled->ToCreature())
if (CreatureAI* controlledAI = cControlled->AI())
controlledAI->OwnerAttackedBy(attacker);
}
//Dont deal damage to unit if .cheat god is enable.
@ -2766,13 +2766,6 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType /*= BASE_A
LOG_DEBUG("entities.unit", "AttackerStateUpdate: (NPC) {} attacked {} for {} dmg, absorbed {}, blocked {}, resisted {}.",
GetGUID().ToString(), victim->GetGUID().ToString(), dmgInfo.GetDamage(), dmgInfo.GetAbsorb(), dmgInfo.GetBlock(), dmgInfo.GetResist());
// Let the pet know we've started attacking someting. Handles melee attacks only
// Spells such as auto-shot and others handled in WorldSession::HandleCastSpellOpcode
if (IsPlayer() && !m_Controlled.empty())
for (Unit::ControlSet::iterator itr = m_Controlled.begin(); itr != m_Controlled.end(); ++itr)
if (Unit* pet = *itr)
if (pet->IsAlive() && pet->IsCreature())
pet->ToCreature()->AI()->OwnerAttacked(victim);
}
}
@ -7342,7 +7335,6 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
// ToCreature()->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
if (creature && !IsControlledByPlayer())
{
// should not let player enter combat by right clicking target - doesn't helps
EngageWithTarget(victim);
creature->SendAIReaction(AI_REACTION_HOSTILE);
@ -7363,6 +7355,16 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
if (meleeAttack)
SendMeleeAttackStart(victim);
// Let the pet know we've started attacking someting. Handles melee attacks only
// Spells such as auto-shot and others handled in WorldSession::HandleCastSpellOpcode
if (IsPlayer())
{
for (Unit* controlled : m_Controlled)
if (Creature* cControlled = controlled->ToCreature())
if (CreatureAI* controlledAI = cControlled->AI())
controlledAI->OwnerAttacked(victim);
}
return true;
}