Merge pull request #6070 from MrSmite/PetAI_3.1
Core/Pets: Improve PetAI Closes #6048 Closes #6070
This commit is contained in:
@@ -109,17 +109,25 @@ void PetAI::UpdateAI(const uint32 diff)
|
||||
}
|
||||
else if (owner && me->GetCharmInfo()) //no victim
|
||||
{
|
||||
Unit* nextTarget = SelectNextTarget();
|
||||
// Only aggressive pets do target search every update.
|
||||
// Defensive pets do target search only in these cases:
|
||||
// * Owner attacks something - handled by OwnerAttacked()
|
||||
// * Owner receives damage - handled by OwnerDamagedBy()
|
||||
// * Pet is in combat and current target dies - handled by KilledUnit()
|
||||
if (me->HasReactState(REACT_AGGRESSIVE))
|
||||
{
|
||||
Unit* nextTarget = SelectNextTarget();
|
||||
|
||||
if (me->HasReactState(REACT_PASSIVE))
|
||||
_stopAttack();
|
||||
else if (nextTarget)
|
||||
AttackStart(nextTarget);
|
||||
if (nextTarget)
|
||||
AttackStart(nextTarget);
|
||||
else
|
||||
HandleReturnMovement();
|
||||
}
|
||||
else
|
||||
HandleReturnMovement();
|
||||
}
|
||||
else if (owner && !me->HasUnitState(UNIT_STATE_FOLLOW)) // no charm info and no victim
|
||||
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle());
|
||||
HandleReturnMovement();
|
||||
|
||||
if (!me->GetCharmInfo())
|
||||
return;
|
||||
@@ -302,6 +310,47 @@ void PetAI::AttackStart(Unit* target)
|
||||
DoAttack(target, true);
|
||||
}
|
||||
|
||||
void PetAI::OwnerDamagedBy(Unit* attacker)
|
||||
{
|
||||
// Called when owner takes damage. Allows defensive pets to know
|
||||
// that their owner might need help
|
||||
|
||||
if (!attacker)
|
||||
return;
|
||||
|
||||
// Passive pets don't do anything
|
||||
if (me->HasReactState(REACT_PASSIVE))
|
||||
return;
|
||||
|
||||
// Prevent pet from disengaging from current target
|
||||
if (me->getVictim() && me->getVictim()->isAlive())
|
||||
return;
|
||||
|
||||
// Continue to evaluate and attack if necessary
|
||||
AttackStart(attacker);
|
||||
}
|
||||
|
||||
void PetAI::OwnerAttacked(Unit* target)
|
||||
{
|
||||
// Called when owner attacks something. Allows defensive pets to know
|
||||
// that they need to assist
|
||||
|
||||
// Target might be NULL if called from spell with invalid cast targets
|
||||
if (!target)
|
||||
return;
|
||||
|
||||
// Passive pets don't do anything
|
||||
if (me->HasReactState(REACT_PASSIVE))
|
||||
return;
|
||||
|
||||
// Prevent pet from disengaging from current target
|
||||
if (me->getVictim() && me->getVictim()->isAlive())
|
||||
return;
|
||||
|
||||
// Continue to evaluate and attack if necessary
|
||||
AttackStart(target);
|
||||
}
|
||||
|
||||
Unit* PetAI::SelectNextTarget()
|
||||
{
|
||||
// Provides next target selection after current target death
|
||||
|
||||
@@ -40,6 +40,8 @@ class PetAI : public CreatureAI
|
||||
void KilledUnit(Unit* /*victim*/);
|
||||
void AttackStart(Unit* target);
|
||||
void MovementInform(uint32 moveType, uint32 data);
|
||||
void OwnerDamagedBy(Unit* attacker);
|
||||
void OwnerAttacked(Unit* target);
|
||||
|
||||
private:
|
||||
bool _isVisible(Unit*) const;
|
||||
|
||||
@@ -138,6 +138,12 @@ class CreatureAI : public UnitAI
|
||||
// Called at text emote receive from player
|
||||
virtual void ReceiveEmote(Player* /*player*/, uint32 /*emoteId*/) {}
|
||||
|
||||
// Called when owner takes damage
|
||||
virtual void OwnerDamagedBy(Unit* /*attacker*/) {}
|
||||
|
||||
// Called when owner attacks something
|
||||
virtual void OwnerAttacked(Unit* /*target*/) {}
|
||||
|
||||
/// == Triggered Actions Requested ==================
|
||||
|
||||
// Called when creature attack expected (if creature can and no have current victim)
|
||||
|
||||
@@ -572,6 +572,15 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
if (IsAIEnabled)
|
||||
GetAI()->DamageDealt(victim, damage, damagetype);
|
||||
|
||||
// Signal to pets that their owner was attacked
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
Pet* pet = victim->ToPlayer()->GetPet();
|
||||
|
||||
if (pet && pet->isAlive())
|
||||
pet->AI()->OwnerDamagedBy(this);
|
||||
}
|
||||
|
||||
if (damagetype != NODAMAGE)
|
||||
{
|
||||
// interrupting auras with AURA_INTERRUPT_FLAG_DAMAGE before checking !damage (absorbed damage breaks that type of auras)
|
||||
@@ -9515,6 +9524,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 (this->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
Pet* playerPet = this->ToPlayer()->GetPet();
|
||||
|
||||
if (playerPet && playerPet->isAlive())
|
||||
playerPet->AI()->OwnerAttacked(victim);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,8 +153,6 @@ void WorldSession::HandlePetActionHelper(Unit* pet, uint64 guid1, uint16 spellid
|
||||
switch (spellid)
|
||||
{
|
||||
case COMMAND_STAY: //flat=1792 //STAY
|
||||
pet->AttackStop();
|
||||
pet->InterruptNonMeleeSpells(false);
|
||||
pet->StopMoving();
|
||||
pet->GetMotionMaster()->Clear(false);
|
||||
pet->GetMotionMaster()->MoveIdle();
|
||||
|
||||
@@ -3101,11 +3101,20 @@ void Spell::cast(bool skipCheck)
|
||||
return;
|
||||
}
|
||||
|
||||
// now that we've done the basic check, now run the scripts
|
||||
// should be done before the spell is actually executed
|
||||
if (Player* playerCaster = m_caster->ToPlayer())
|
||||
{
|
||||
// now that we've done the basic check, now run the scripts
|
||||
// should be done before the spell is actually executed
|
||||
sScriptMgr->OnPlayerSpellCast(playerCaster, this, skipCheck);
|
||||
|
||||
// Let any pets know we've attacked something. As of 3.0.2 pets begin
|
||||
// attacking their owner's target immediately
|
||||
if (Pet* playerPet = playerCaster->GetPet())
|
||||
{
|
||||
if (playerPet->isAlive() && playerPet->isControlled() && (m_targets.GetTargetMask() & TARGET_FLAG_UNIT))
|
||||
playerPet->AI()->OwnerAttacked(m_targets.GetObjectTarget()->ToUnit());
|
||||
}
|
||||
}
|
||||
SetExecutedCurrently(true);
|
||||
|
||||
if (m_caster->GetTypeId() != TYPEID_PLAYER && m_targets.GetUnitTarget() && m_targets.GetUnitTarget() != m_caster)
|
||||
|
||||
Reference in New Issue
Block a user