Skip to content

Instantly share code, notes, and snippets.

@vermie
Created January 12, 2011 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vermie/777044 to your computer and use it in GitHub Desktop.
Save vermie/777044 to your computer and use it in GitHub Desktop.
pet behavior
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 52f78e9..e21f71b 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -1431,6 +1431,10 @@ void Creature::SetDeathState(DeathState s)
UpdateSpeed(MOVE_RUN, false);
}
+ // FIXME: may not be blizzlike
+ if (Pet* pet = GetPet())
+ pet->Unsummon(PET_SAVE_AS_DELETED, this);
+
// return, since we promote to CORPSE_FALLING. CORPSE_FALLING is promoted to CORPSE at next update.
if (CanFly() && FallGround())
return;
@@ -1717,7 +1721,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 11df7b1..a0f7fa3 100644
--- a/src/game/Spell.cpp
+++ b/src/game/Spell.cpp
@@ -1187,7 +1187,7 @@ void Spell::DoSpellHitOnUnit(Unit *unit, const 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 0c9588c..a39904f 100644
--- a/src/game/SpellAuras.cpp
+++ b/src/game/SpellAuras.cpp
@@ -3704,9 +3704,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);
}
}
}
@@ -3900,8 +3898,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 3884285..587ae03 100644
--- a/src/game/SpellEffects.cpp
+++ b/src/game/SpellEffects.cpp
@@ -4586,8 +4586,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 38b78c1..7c043b0 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -321,7 +321,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.
@@ -929,8 +929,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);
}
// polymorphed, hex and other negative transformed cases
@@ -2563,8 +2562,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)
@@ -5678,6 +5676,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)
@@ -9982,8 +9991,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 ecaf544..0373844 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -1239,6 +1239,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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment