mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
[9186] Templated functions for apply some code to all controlled units.
Also fix some related problems with not updates totems/etc
This commit is contained in:
parent
7272b52daf
commit
6704929d56
7 changed files with 165 additions and 76 deletions
|
|
@ -8199,43 +8199,31 @@ void Unit::CombatStop(bool includingCast)
|
|||
ClearInCombat();
|
||||
}
|
||||
|
||||
struct CombatStopWithPetsHelper
|
||||
{
|
||||
explicit CombatStopWithPetsHelper(bool _includingCast) : includingCast(_includingCast) {}
|
||||
void operator()(Unit* unit) const { unit->CombatStop(includingCast); }
|
||||
bool includingCast;
|
||||
};
|
||||
|
||||
void Unit::CombatStopWithPets(bool includingCast)
|
||||
{
|
||||
CombatStop(includingCast);
|
||||
if(Pet* pet = GetPet())
|
||||
pet->CombatStop(includingCast);
|
||||
if(Unit* charm = GetCharm())
|
||||
charm->CombatStop(includingCast);
|
||||
|
||||
for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
|
||||
if(Unit* guardian = Unit::GetUnit(*this,*itr))
|
||||
guardian->CombatStop(includingCast);
|
||||
CallForAllControlledUnits(CombatStopWithPetsHelper(includingCast),false,true,true);
|
||||
}
|
||||
|
||||
struct IsAttackingPlayerHelper
|
||||
{
|
||||
explicit IsAttackingPlayerHelper() {}
|
||||
bool operator()(Unit* unit) const { return unit->isAttackingPlayer(); }
|
||||
};
|
||||
|
||||
bool Unit::isAttackingPlayer() const
|
||||
{
|
||||
if(hasUnitState(UNIT_STAT_ATTACK_PLAYER))
|
||||
return true;
|
||||
|
||||
Pet* pet = GetPet();
|
||||
if(pet && pet->isAttackingPlayer())
|
||||
return true;
|
||||
|
||||
Unit* charmed = GetCharm();
|
||||
if(charmed && charmed->isAttackingPlayer())
|
||||
return true;
|
||||
|
||||
for (int8 i = 0; i < MAX_TOTEM; ++i)
|
||||
{
|
||||
if(m_TotemSlot[i])
|
||||
{
|
||||
Creature *totem = GetMap()->GetCreature(m_TotemSlot[i]);
|
||||
if(totem && totem->isAttackingPlayer())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return CheckAllControlledUnits(IsAttackingPlayerHelper(),true,true,true);
|
||||
}
|
||||
|
||||
void Unit::RemoveAllAttackers()
|
||||
|
|
@ -11063,7 +11051,7 @@ void Unit::ApplyDiminishingAura( DiminishingGroup group, bool apply )
|
|||
}
|
||||
}
|
||||
|
||||
Unit* Unit::GetUnit(WorldObject& object, uint64 guid)
|
||||
Unit* Unit::GetUnit(WorldObject const& object, uint64 guid)
|
||||
{
|
||||
return ObjectAccessor::GetUnit(object,guid);
|
||||
}
|
||||
|
|
@ -12980,6 +12968,13 @@ void Unit::NearTeleportTo( float x, float y, float z, float orientation, bool ca
|
|||
}
|
||||
}
|
||||
|
||||
struct SetPvPHelper
|
||||
{
|
||||
explicit SetPvPHelper(bool _state) : state(_state) {}
|
||||
void operator()(Unit* unit) const { unit->SetPvP(state); }
|
||||
bool state;
|
||||
};
|
||||
|
||||
void Unit::SetPvP( bool state )
|
||||
{
|
||||
if(state)
|
||||
|
|
@ -12987,15 +12982,7 @@ void Unit::SetPvP( bool state )
|
|||
else
|
||||
RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP);
|
||||
|
||||
if(Pet* pet = GetPet())
|
||||
pet->SetPvP(state);
|
||||
if(Unit* charmed = GetCharm())
|
||||
charmed->SetPvP(state);
|
||||
|
||||
for (int8 i = 0; i < MAX_TOTEM; ++i)
|
||||
if(m_TotemSlot[i])
|
||||
if(Creature *totem = GetMap()->GetCreature(m_TotemSlot[i]))
|
||||
totem->SetPvP(state);
|
||||
CallForAllControlledUnits(SetPvPHelper(state),true,true,true);
|
||||
}
|
||||
|
||||
void Unit::KnockBackFrom(Unit* target, float horizintalSpeed, float verticalSpeed)
|
||||
|
|
@ -13119,6 +13106,13 @@ void Unit::SendThreatRemove(HostileReference* pHostileReference)
|
|||
SendMessageToSet(&data, false);
|
||||
}
|
||||
|
||||
struct StopAttackFactionHelper
|
||||
{
|
||||
explicit StopAttackFactionHelper(uint32 _faction_id) : faction_id(_faction_id) {}
|
||||
void operator()(Unit* unit) const { unit->StopAttackFaction(faction_id); }
|
||||
uint32 faction_id;
|
||||
};
|
||||
|
||||
void Unit::StopAttackFaction(uint32 faction_id)
|
||||
{
|
||||
if (Unit* victim = getVictim())
|
||||
|
|
@ -13149,14 +13143,7 @@ void Unit::StopAttackFaction(uint32 faction_id)
|
|||
|
||||
getHostileRefManager().deleteReferencesForFaction(faction_id);
|
||||
|
||||
if(Pet* pet = GetPet())
|
||||
pet->StopAttackFaction(faction_id);
|
||||
if(Unit* charm = GetCharm())
|
||||
charm->StopAttackFaction(faction_id);
|
||||
|
||||
for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
|
||||
if(Unit* guardian = Unit::GetUnit(*this,*itr))
|
||||
guardian->StopAttackFaction(faction_id);
|
||||
CallForAllControlledUnits(StopAttackFactionHelper(faction_id),false,true,true);
|
||||
}
|
||||
|
||||
void Unit::CleanupDeletedAuras()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue