Fix some combat behaviour of NPC-Pets

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
faramir118 2012-01-20 00:42:51 +01:00 committed by Schmoozerd
parent 177bc78108
commit eca3586d74
6 changed files with 22 additions and 16 deletions

View file

@ -1766,7 +1766,8 @@ void Creature::SendAIReaction(AiReaction reactionType)
void Creature::CallAssistance()
{
if( !m_AlreadyCallAssistance && getVictim() && !IsPet() && !isCharmed())
// FIXME: should player pets call for assistance?
if (!m_AlreadyCallAssistance && getVictim() && !isCharmed())
{
SetNoCallAssistance(true);

View file

@ -1226,7 +1226,7 @@ void Spell::DoSpellHitOnUnit(Unit *unit, uint32 effectMask)
unit->SetStandState(UNIT_STAND_STATE_STAND);
if (!unit->isInCombat() && unit->GetTypeId() != TYPEID_PLAYER && ((Creature*)unit)->AI())
((Creature*)unit)->AI()->AttackedBy(realCaster);
unit->AttackedBy(realCaster);
unit->AddThreat(realCaster);
unit->SetInCombatWith(realCaster);

View file

@ -4005,9 +4005,7 @@ void Aura::HandleModPossess(bool apply, bool Real)
if(target->GetTypeId() == TYPEID_UNIT)
{
((Creature*)target)->AIM_Initialize();
if (((Creature*)target)->AI())
((Creature*)target)->AI()->AttackedBy(caster);
target->AttackedBy(caster);
}
}
}
@ -4200,8 +4198,7 @@ void Aura::HandleModCharm(bool apply, bool Real)
if(target->GetTypeId() == TYPEID_UNIT)
{
((Creature*)target)->AIM_Initialize();
if (((Creature*)target)->AI())
((Creature*)target)->AI()->AttackedBy(caster);
target->AttackedBy(caster);
}
}
}

View file

@ -5061,8 +5061,7 @@ void Spell::EffectPickPocket(SpellEffectIndex /*eff_idx*/)
{
// Reveal action + get attack
m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
if (((Creature*)unitTarget)->AI())
((Creature*)unitTarget)->AI()->AttackedBy(m_caster);
unitTarget->AttackedBy(m_caster);
}
}
}

View file

@ -324,7 +324,7 @@ void Unit::Update( uint32 update_diff, uint32 p_time )
getThreatManager().UpdateForClient(update_diff);
// update combat timer only for players and pets
if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->IsPet() || ((Creature*)this)->isCharmed()))
if (isInCombat() && GetCharmerOrOwnerPlayerOrPlayerItself())
{
// Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
// targets without stopping half way there and running off.
@ -928,8 +928,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
}
// if damage pVictim call AI reaction
if(pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI())
((Creature*)pVictim)->AI()->AttackedBy(this);
pVictim->AttackedBy(this);
}
if(damagetype == DIRECT_DAMAGE || damagetype == SPELL_DIRECT_DAMAGE)
@ -2546,8 +2545,7 @@ void Unit::AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType, bool ex
GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damageInfo.damage, damageInfo.absorb, damageInfo.blocked_amount, damageInfo.resist);
// if damage pVictim call AI reaction
if(pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI())
((Creature*)pVictim)->AI()->AttackedBy(this);
pVictim->AttackedBy(this);
// extra attack only at any non extra attack (normal case)
if(!extra && extraAttacks)
@ -5682,6 +5680,17 @@ bool Unit::Attack(Unit *victim, bool meleeAttack)
return true;
}
void Unit::AttackedBy(Unit* attacker)
{
// trigger AI reaction
if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI())
((Creature*)this)->AI()->AttackedBy(attacker);
// trigger pet AI reaction
if (Pet* pet = GetPet())
pet->AttackedBy(attacker);
}
bool Unit::AttackStop(bool targetSwitch /*=false*/)
{
if (!m_attacking)
@ -9995,8 +10004,7 @@ void Unit::SetFeared(bool apply, ObjectGuid casterGuid, uint32 spellID, uint32 t
// attack caster if can
if (Unit* caster = IsInWorld() ? GetMap()->GetUnit(casterGuid) : NULL)
if (c->AI())
c->AI()->AttackedBy(caster);
c->AttackedBy(caster);
}
}

View file

@ -1152,6 +1152,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
return NULL;
}
bool Attack(Unit *victim, bool meleeAttack);
void AttackedBy(Unit* attacker);
void CastStop(uint32 except_spellid = 0);
bool AttackStop(bool targetSwitch = false);
void RemoveAllAttackers();