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:
parent
ebcaddb98d
commit
48fa4d2856
5 changed files with 62 additions and 64 deletions
|
|
@ -250,13 +250,29 @@ struct npc_pet_dk_ghoul : public CombatAI
|
|||
if (!summoner || !summoner->IsPlayer())
|
||||
return;
|
||||
|
||||
Player* player = summoner->ToPlayer();
|
||||
// Remember the owner's target so we can attack it after the rising stun expires.
|
||||
if (Unit* victim = summoner->ToPlayer()->GetVictim())
|
||||
_summonTargetGUID = victim->GetGUID();
|
||||
}
|
||||
|
||||
if (Unit* victim = player->GetVictim())
|
||||
void UpdateAI(uint32 diff) override
|
||||
{
|
||||
// While stunned (rising animation), don't run CombatAI - just wait.
|
||||
if (me->HasUnitState(UNIT_STATE_STUNNED))
|
||||
return;
|
||||
|
||||
// Once the stun expires, attack the saved target from summon time.
|
||||
if (!_summonTargetGUID.IsEmpty())
|
||||
{
|
||||
me->Attack(victim, true);
|
||||
me->GetMotionMaster()->MoveChase(victim);
|
||||
if (Unit* target = ObjectAccessor::GetUnit(*me, _summonTargetGUID))
|
||||
{
|
||||
if (target->IsAlive() && me->IsValidAttackTarget(target))
|
||||
AttackStart(target);
|
||||
}
|
||||
_summonTargetGUID.Clear();
|
||||
}
|
||||
|
||||
CombatAI::UpdateAI(diff);
|
||||
}
|
||||
|
||||
void JustDied(Unit* /*who*/) override
|
||||
|
|
@ -264,6 +280,9 @@ struct npc_pet_dk_ghoul : public CombatAI
|
|||
if (me->IsGuardian() || me->IsSummon())
|
||||
me->ToTempSummon()->UnSummon();
|
||||
}
|
||||
|
||||
private:
|
||||
ObjectGuid _summonTargetGUID;
|
||||
};
|
||||
|
||||
struct npc_pet_dk_risen_ally : public PossessedAI
|
||||
|
|
@ -283,36 +302,18 @@ struct npc_pet_dk_risen_ally : public PossessedAI
|
|||
}
|
||||
};
|
||||
|
||||
struct npc_pet_dk_army_of_the_dead : public CombatAI
|
||||
struct npc_pet_dk_army_of_the_dead : public AggressorAI
|
||||
{
|
||||
npc_pet_dk_army_of_the_dead(Creature* creature) : CombatAI(creature) { }
|
||||
npc_pet_dk_army_of_the_dead(Creature* creature) : AggressorAI(creature) { }
|
||||
|
||||
void InitializeAI() override
|
||||
bool CanAIAttack(Unit const* target) const override
|
||||
{
|
||||
CombatAI::InitializeAI();
|
||||
((Minion*)me)->SetFollowAngle(rand_norm() * 2 * M_PI);
|
||||
}
|
||||
|
||||
void IsSummonedBy(WorldObject* summoner) override
|
||||
{
|
||||
if (Unit* owner = summoner->ToUnit())
|
||||
{
|
||||
Unit* victim = owner->GetVictim();
|
||||
|
||||
if (victim && me->IsValidAttackTarget(victim))
|
||||
{
|
||||
AttackStart(victim);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If there is no valid target, attack the nearest enemy within 30m
|
||||
if (Unit* nearest = me->SelectNearbyTarget(nullptr, 30.0f))
|
||||
{
|
||||
if (me->IsValidAttackTarget(nearest))
|
||||
AttackStart(nearest);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!target)
|
||||
return false;
|
||||
Unit* owner = me->GetOwner();
|
||||
if (owner && !target->IsInCombatWith(owner))
|
||||
return false;
|
||||
return AggressorAI::CanAIAttack(target);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue