[10778] Make AI call OwnerKilledUnit() more proper.

Affect any pet that are not being controlled (minipet/guardian/protector) and will also apply to pets owned by another creature.

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-11-23 11:06:24 +01:00
parent 962acb5198
commit 0c85afea79
3 changed files with 27 additions and 12 deletions

View file

@ -785,18 +785,10 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
// Call KilledUnit for creatures
if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI())
{
((Creature*)this)->AI()->KilledUnit(pVictim);
}
else if (GetTypeId() == TYPEID_PLAYER)
{
// currently not known if other pet types (not controllable) may have some action at owner kills
if (Pet* pProtector = GetProtectorPet())
{
if (pProtector->AI())
pProtector->AI()->OwnerKilledUnit(pVictim);
}
}
// Call AI OwnerKilledUnit (for any current summoned minipet/guardian/protector)
PetOwnerKilledUnit(pVictim);
// achievement stuff
if (pVictim->GetTypeId() == TYPEID_PLAYER)
@ -1082,6 +1074,27 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
return damage;
}
struct PetOwnerKilledUnitHelper
{
explicit PetOwnerKilledUnitHelper(Unit* pVictim) : m_victim(pVictim) {}
void operator()(Unit* pTarget) const
{
if (pTarget->GetTypeId() == TYPEID_UNIT)
{
if (((Creature*)pTarget)->AI())
((Creature*)pTarget)->AI()->OwnerKilledUnit(m_victim);
}
}
Unit* m_victim;
};
void Unit::PetOwnerKilledUnit(Unit* pVictim)
{
// for minipet and guardians (including protector)
CallForAllControlledUnits(PetOwnerKilledUnitHelper(pVictim), CONTROLLED_MINIPET|CONTROLLED_GUARDIANS);
}
void Unit::CastStop(uint32 except_spellid)
{
for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)