diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 25ceec590..517b18362 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -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); diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index ed28e00c0..bf5130a71 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -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); diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index f354cffde..b66875af1 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -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); } } } diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index ccb8a77e6..b01b44960 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -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); } } } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 518779c64..49fc924e8 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -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); } } diff --git a/src/game/Unit.h b/src/game/Unit.h index 119543993..646d54ef2 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -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();