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
5 changed files with 62 additions and 64 deletions

View File

@@ -1840,44 +1840,39 @@ bool Creature::IsAlwaysDetectableFor(WorldObject const* seer) const
return false;
}
bool Creature::CanStartAttack(Unit const* who) const
bool Creature::CanStartAttack(Unit const* who, bool force) const
{
if (IsCivilian())
return false;
// This set of checks is should be done only for creatures
if ((IsImmuneToNPC() && !who->IsPlayer()) || // flag is valid only for non player characters
(IsImmuneToPC() && who->IsPlayer())) // immune to PC and target is a player, return false
{
if ((IsImmuneToNPC() && !who->IsPlayer()) ||
(IsImmuneToPC() && who->IsPlayer()))
return false;
}
if (Unit* owner = who->GetOwner())
if (owner->IsPlayer() && IsImmuneToPC()) // immune to PC and target has player owner
if (owner->IsPlayer() && IsImmuneToPC())
return false;
// Do not attack non-combat pets
if (who->IsCreature() && who->GetCreatureType() == CREATURE_TYPE_NON_COMBAT_PET)
return false;
if (!CanFly() && (GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE + m_CombatDistance)) // too much Z difference, skip very costy vmap calculations here
if (!CanFly() && (GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE + m_CombatDistance))
return false;
if (!_IsTargetAcceptable(who))
return false;
if (!force)
{
if (!_IsTargetAcceptable(who))
return false;
if (IsNeutralToAll() || !IsWithinDistInMap(who, GetAggroRange(who) + m_CombatDistance, true, false, false)) // pussywizard: +m_combatDistance for turrets and similar
return false;
if (IsNeutralToAll() || !IsWithinDistInMap(who, GetAggroRange(who) + m_CombatDistance, true, false, false))
return false;
}
if (!CanCreatureAttack(who))
return false;
if (HasUnitState(UNIT_STATE_STUNNED))
return false;
if (!IsHostileTo(who))
return false;
return IsWithinLOSInMap(who);
}