Core: Combat/threat system rewrite (PR #19930)
- PvE combat is now always mutual. UNIT_FLAG_IN_COMBAT is backed by actual references to the units we're in combat with. - PvP combat is now also tracked, and almost always mutual; spells like Vanish and Feign Death can break this rule. That means we can easily determine a list of players we're fighting. - By extension, IsInCombatWith now has sensible behavior when invoked on nonplayers. - Threat and combat systems are no longer the same. - They still have an enforced relationship (threat implies combat - clearing combat clears threat)... - ...but we can have combat without threat. A creature (with threat list) isn't considered to be engaged until it has an entry on its threat list... - ...which means we can now faithfully replicate retail engage behavior. Combat on projectile launch - engagement start on projectile impact. Yay for progress! - AI method refactor, as already ported in 6113b9d - `JustEngagedWith`, `JustEnteredCombat` and `JustExitedCombat`. - Vehicle threat is now properly pooled on the main vehicle body (fixes #16542). - Various edge case bug fixes for threat redirects (Misdirection "cancelling" Vigilance and similar). - Target re-selection is now significantly faster. - Fixed a ton of other smaller edge case bugs, probably. Closes #7951 and #19998.
This commit is contained in:
1 parent
280b8dc799
commit
942c3a77da
53 files changed
+1607
-2232
No files matched your search
@@ -325,9 +325,9 @@ Unit::Unit(bool isWorldObject) :
|
||||
IsAIEnabled(false), NeedChangeAI(false), LastCharmerGUID(),
|
||||
m_ControlledByPlayer(false), movespline(new Movement::MoveSpline()),
|
||||
i_AI(nullptr), i_disabledAI(nullptr), m_AutoRepeatFirstCast(false), m_procDeep(0),
|
||||
m_removedAurasCount(0), i_motionMaster(new MotionMaster(this)), m_ThreatManager(this),
|
||||
m_removedAurasCount(0), i_motionMaster(new MotionMaster(this)), m_combatManager(this),
|
||||
m_vehicle(nullptr), m_vehicleKit(nullptr), m_unitTypeMask(UNIT_MASK_NONE),
|
||||
m_Diminishing(), m_HostileRefManager(this), _lastDamagedTime(0),
|
||||
m_Diminishing(), m_threatManager(this), _lastDamagedTime(0),
|
||||
m_spellHistory(new SpellHistory(this))
|
||||
{
|
||||
m_objectType |= TYPEMASK_UNIT;
|
||||
@@ -390,18 +390,11 @@ Unit::Unit(bool isWorldObject) :
|
||||
m_modSpellHitChance = 0.0f;
|
||||
m_baseSpellCritChance = 5;
|
||||
|
||||
m_CombatTimer = 0;
|
||||
|
||||
for (uint8 i = 0; i < MAX_SPELL_SCHOOL; ++i)
|
||||
m_threatModifier[i] = 1.0f;
|
||||
|
||||
for (uint8 i = 0; i < MAX_MOVE_TYPE; ++i)
|
||||
m_speed_rate[i] = 1.0f;
|
||||
|
||||
m_charmInfo = nullptr;
|
||||
|
||||
_redirectThreadInfo = RedirectThreatInfo();
|
||||
|
||||
// remove aurastates allowing special moves
|
||||
for (uint8 i = 0; i < MAX_REACTIVE; ++i)
|
||||
m_reactiveTimer[i] = 0;
|
||||
@@ -458,28 +451,6 @@ Unit::~Unit()
|
||||
ASSERT(m_dynObj.empty());
|
||||
}
|
||||
|
||||
// Check if unit in combat with specific unit
|
||||
bool Unit::IsInCombatWith(Unit const* who) const
|
||||
{
|
||||
// Check target exists
|
||||
if (!who)
|
||||
return false;
|
||||
|
||||
// Search in threat list
|
||||
ObjectGuid guid = who->GetGUID();
|
||||
for (ThreatContainer::StorageType::const_iterator i = m_ThreatManager.getThreatList().begin(); i != m_ThreatManager.getThreatList().end(); ++i)
|
||||
{
|
||||
HostileReference* ref = (*i);
|
||||
|
||||
// Return true if the unit matches
|
||||
if (ref && ref->getUnitGuid() == guid)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Nothing found, false.
|
||||
return false;
|
||||
}
|
||||
|
||||
void Unit::Update(uint32 p_time)
|
||||
{
|
||||
// WARNING! Order of execution here is important, do not change.
|
||||
@@ -496,24 +467,7 @@ void Unit::Update(uint32 p_time)
|
||||
// Having this would prevent spells from being proced, so let's crash
|
||||
ASSERT(!m_procDeep);
|
||||
|
||||
if (CanHaveThreatList() && GetThreatManager().isNeedUpdateToClient(p_time))
|
||||
SendThreatListUpdate();
|
||||
|
||||
// update combat timer only for players and pets (only pets with PetAI)
|
||||
if (IsInCombat() && (GetTypeId() == TYPEID_PLAYER || (IsPet() && IsControlledByPlayer())))
|
||||
{
|
||||
// Check UNIT_STATE_MELEE_ATTACKING or UNIT_STATE_CHASE (without UNIT_STATE_FOLLOW in this case) so pets can reach far away
|
||||
// targets without stopping half way there and running off.
|
||||
// These flags are reset after target dies or another command is given.
|
||||
if (m_HostileRefManager.isEmpty())
|
||||
{
|
||||
// m_CombatTimer set at aura start and it will be freeze until aura removing
|
||||
if (m_CombatTimer <= p_time)
|
||||
ClearInCombat();
|
||||
else
|
||||
m_CombatTimer -= p_time;
|
||||
}
|
||||
}
|
||||
m_combatManager.Update(p_time);
|
||||
|
||||
// not implemented before 3.0.2
|
||||
if (uint32 base_att = getAttackTimer(BASE_ATTACK))
|
||||
@@ -2124,7 +2078,7 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extr
|
||||
if ((attType == BASE_ATTACK || attType == OFF_ATTACK) && !IsWithinLOSInMap(victim))
|
||||
return;
|
||||
|
||||
CombatStart(victim);
|
||||
AttackedTarget(victim, true);
|
||||
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MELEE_ATTACK);
|
||||
|
||||
if (attType != BASE_ATTACK && attType != OFF_ATTACK)
|
||||
@@ -2224,7 +2178,7 @@ void Unit::FakeAttackerStateUpdate(Unit* victim, WeaponAttackType attType /*= BA
|
||||
if ((attType == BASE_ATTACK || attType == OFF_ATTACK) && !IsWithinLOSInMap(victim))
|
||||
return;
|
||||
|
||||
CombatStart(victim);
|
||||
AttackedTarget(victim, true);
|
||||
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MELEE_ATTACK);
|
||||
|
||||
if (attType != BASE_ATTACK && attType != OFF_ATTACK)
|
||||
@@ -5701,20 +5655,20 @@ Unit* Unit::getAttackerForHelper() const // If someone wants to
|
||||
return nullptr;
|
||||
|
||||
if (Unit* victim = GetVictim())
|
||||
if ((!IsPet() && !GetPlayerMovingMe()) || IsInCombatWith(victim) || victim->IsInCombatWith(this))
|
||||
if ((!IsPet() && !GetPlayerMovingMe()) || IsInCombatWith(victim))
|
||||
return victim;
|
||||
|
||||
if (!m_attackers.empty())
|
||||
return *(m_attackers.begin());
|
||||
|
||||
if (Player* owner = GetCharmerOrOwnerPlayerOrPlayerItself())
|
||||
{
|
||||
HostileRefManager& refs = owner->getHostileRefManager();
|
||||
for (Reference<Unit, ThreatManager> const& ref : refs)
|
||||
if (Unit* hostile = ref.GetSource()->GetOwner())
|
||||
return hostile;
|
||||
}
|
||||
|
||||
CombatManager const& mgr = GetCombatManager();
|
||||
// pick arbitrary targets; our pvp combat > owner's pvp combat > our pve combat > owner's pve combat
|
||||
Unit* owner = GetCharmerOrOwner();
|
||||
if (mgr.HasPvPCombat())
|
||||
return mgr.GetPvPCombatRefs().begin()->second->GetOther(this);
|
||||
if (owner && (owner->GetCombatManager().HasPvPCombat()))
|
||||
return owner->GetCombatManager().GetPvPCombatRefs().begin()->second->GetOther(owner);
|
||||
if (mgr.HasPvECombat())
|
||||
return mgr.GetPvECombatRefs().begin()->second->GetOther(this);
|
||||
if (owner && (owner->GetCombatManager().HasPvECombat()))
|
||||
return owner->GetCombatManager().GetPvECombatRefs().begin()->second->GetOther(owner);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -5795,19 +5749,7 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
|
||||
|
||||
if (creature && !IsPet())
|
||||
{
|
||||
// should not let player enter combat by right clicking target - doesn't helps
|
||||
GetThreatManager().AddThreat(victim, 0.0f);
|
||||
SetInCombatWith(victim);
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
victim->SetInCombatWith(this);
|
||||
|
||||
if (Unit* owner = victim->GetOwner())
|
||||
{
|
||||
GetThreatManager().AddThreat(victim, 0.0f);
|
||||
SetInCombatWith(owner);
|
||||
if (owner->GetTypeId() == TYPEID_PLAYER)
|
||||
owner->SetInCombatWith(this);
|
||||
}
|
||||
EngageWithTarget(victim); // ensure that anything we're attacking has threat
|
||||
|
||||
creature->SendAIReaction(AI_REACTION_HOSTILE);
|
||||
creature->CallAssistance();
|
||||
@@ -5863,7 +5805,25 @@ bool Unit::AttackStop()
|
||||
return true;
|
||||
}
|
||||
|
||||
void Unit::CombatStop(bool includingCast)
|
||||
void Unit::ValidateAttackersAndOwnTarget()
|
||||
{
|
||||
// iterate attackers
|
||||
UnitVector toRemove;
|
||||
AttackerSet const& attackers = getAttackers();
|
||||
for (Unit* attacker : attackers)
|
||||
if (!attacker->IsValidAttackTarget(this))
|
||||
toRemove.push_back(attacker);
|
||||
|
||||
for (Unit* attacker : toRemove)
|
||||
attacker->AttackStop();
|
||||
|
||||
// remove our own victim
|
||||
if (Unit* victim = GetVictim())
|
||||
if (!IsValidAttackTarget(victim))
|
||||
AttackStop();
|
||||
}
|
||||
|
||||
void Unit::CombatStop(bool includingCast, bool mutualPvP)
|
||||
{
|
||||
if (includingCast && IsNonMeleeSpellCast(false))
|
||||
InterruptNonMeleeSpells(false);
|
||||
@@ -5872,19 +5832,22 @@ void Unit::CombatStop(bool includingCast)
|
||||
RemoveAllAttackers();
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
ToPlayer()->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
|
||||
ClearInCombat();
|
||||
|
||||
// just in case
|
||||
if (IsPetInCombat() && GetTypeId() != TYPEID_PLAYER)
|
||||
ClearInPetCombat();
|
||||
if (mutualPvP)
|
||||
ClearInCombat();
|
||||
else
|
||||
{ // vanish and brethren are weird
|
||||
m_combatManager.EndAllPvECombat();
|
||||
m_combatManager.SuppressPvPCombat();
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::CombatStopWithPets(bool includingCast)
|
||||
{
|
||||
CombatStop(includingCast);
|
||||
|
||||
for (ControlList::const_iterator itr = m_Controlled.begin(); itr != m_Controlled.end(); ++itr)
|
||||
(*itr)->CombatStop(includingCast);
|
||||
for (Unit* minion : m_Controlled)
|
||||
minion->CombatStop(includingCast);
|
||||
}
|
||||
|
||||
bool Unit::isAttackingPlayer() const
|
||||
@@ -6262,6 +6225,7 @@ void Unit::SetMinion(Minion* minion, bool apply)
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdatePetCombatState();
|
||||
}
|
||||
|
||||
void Unit::GetAllMinionsByEntry(std::list<Creature*>& Minions, uint32 entry)
|
||||
@@ -6359,6 +6323,7 @@ void Unit::SetCharm(Unit* charm, bool apply)
|
||||
m_Controlled.erase(charm);
|
||||
}
|
||||
}
|
||||
UpdatePetCombatState();
|
||||
}
|
||||
|
||||
void Unit::DealHeal(HealInfo& healInfo)
|
||||
@@ -6497,6 +6462,8 @@ void Unit::RemoveAllControlled()
|
||||
TC_LOG_FATAL("entities.unit", "Unit %u is not able to release its minion %s", GetEntry(), GetMinionGUID().ToString().c_str());
|
||||
if (GetCharmGUID())
|
||||
TC_LOG_FATAL("entities.unit", "Unit %u is not able to release its charm %s", GetEntry(), GetCharmGUID().ToString().c_str());
|
||||
if (!IsPet()) // pets don't use the flag for this
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); // m_controlled is now empty, so we know none of our minions are in combat
|
||||
}
|
||||
|
||||
bool Unit::isPossessedByPlayer() const
|
||||
@@ -8426,169 +8393,119 @@ bool Unit::IsServiceProvider() const
|
||||
UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER);
|
||||
}
|
||||
|
||||
void Unit::SetInCombatWith(Unit* enemy)
|
||||
void Unit::EngageWithTarget(Unit* enemy)
|
||||
{
|
||||
Unit* eOwner = enemy->GetCharmerOrOwnerOrSelf();
|
||||
if (eOwner->IsPvP() || eOwner->IsFFAPvP())
|
||||
{
|
||||
SetInCombatState(true, enemy);
|
||||
if (!enemy)
|
||||
return;
|
||||
}
|
||||
|
||||
// check for duel
|
||||
if (eOwner->GetTypeId() == TYPEID_PLAYER && eOwner->ToPlayer()->duel)
|
||||
if (IsEngagedBy(enemy))
|
||||
return;
|
||||
|
||||
if (CanHaveThreatList())
|
||||
m_threatManager.AddThreat(enemy, 0.0f, nullptr, true, true);
|
||||
else
|
||||
SetInCombatWith(enemy);
|
||||
|
||||
if (Creature* creature = ToCreature())
|
||||
if (CreatureGroup* formation = creature->GetFormation())
|
||||
formation->MemberEngagingTarget(creature, enemy);
|
||||
}
|
||||
|
||||
void Unit::AttackedTarget(Unit* target, bool canInitialAggro)
|
||||
{
|
||||
if (!target->IsEngaged() && !canInitialAggro)
|
||||
return;
|
||||
target->EngageWithTarget(this);
|
||||
if (Unit* targetOwner = target->GetCharmerOrOwner())
|
||||
targetOwner->EngageWithTarget(this);
|
||||
|
||||
Player* myPlayerOwner = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
Player* targetPlayerOwner = target->GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
if (myPlayerOwner && targetPlayerOwner && !(myPlayerOwner->duel && myPlayerOwner->duel->opponent == targetPlayerOwner))
|
||||
{
|
||||
Unit const* myOwner = GetCharmerOrOwnerOrSelf();
|
||||
if (((Player const*)eOwner)->duel->opponent == myOwner)
|
||||
{
|
||||
SetInCombatState(true, enemy);
|
||||
return;
|
||||
}
|
||||
myPlayerOwner->UpdatePvP(true);
|
||||
myPlayerOwner->SetContestedPvP(targetPlayerOwner);
|
||||
myPlayerOwner->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::SetImmuneToAll(bool apply, bool keepCombat)
|
||||
{
|
||||
if (apply)
|
||||
{
|
||||
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
|
||||
ValidateAttackersAndOwnTarget();
|
||||
if (keepCombat)
|
||||
m_threatManager.UpdateOnlineStates(true, true);
|
||||
else
|
||||
m_combatManager.EndAllCombat();
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
|
||||
m_threatManager.UpdateOnlineStates(true, true);
|
||||
}
|
||||
SetInCombatState(false, enemy);
|
||||
}
|
||||
|
||||
void Unit::SetImmuneToPC(bool apply, bool keepCombat)
|
||||
{
|
||||
(void)keepCombat;
|
||||
if (apply)
|
||||
{
|
||||
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC);
|
||||
ValidateAttackersAndOwnTarget();
|
||||
if (keepCombat)
|
||||
m_threatManager.UpdateOnlineStates(true, true);
|
||||
else
|
||||
{
|
||||
std::list<CombatReference*> toEnd;
|
||||
for (auto const& pair : m_combatManager.GetPvECombatRefs())
|
||||
if (pair.second->GetOther(this)->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE))
|
||||
toEnd.push_back(pair.second);
|
||||
for (auto const& pair : m_combatManager.GetPvPCombatRefs())
|
||||
if (pair.second->GetOther(this)->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE))
|
||||
toEnd.push_back(pair.second);
|
||||
for (CombatReference* ref : toEnd)
|
||||
ref->EndCombat();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC);
|
||||
m_threatManager.UpdateOnlineStates(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::SetImmuneToNPC(bool apply, bool keepCombat)
|
||||
{
|
||||
(void)keepCombat;
|
||||
if (apply)
|
||||
{
|
||||
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC);
|
||||
ValidateAttackersAndOwnTarget();
|
||||
if (keepCombat)
|
||||
m_threatManager.UpdateOnlineStates(true, true);
|
||||
else
|
||||
{
|
||||
std::list<CombatReference*> toEnd;
|
||||
for (auto const& pair : m_combatManager.GetPvECombatRefs())
|
||||
if (!pair.second->GetOther(this)->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE))
|
||||
toEnd.push_back(pair.second);
|
||||
for (auto const& pair : m_combatManager.GetPvPCombatRefs())
|
||||
if (!pair.second->GetOther(this)->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE))
|
||||
toEnd.push_back(pair.second);
|
||||
for (CombatReference* ref : toEnd)
|
||||
ref->EndCombat();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC);
|
||||
}
|
||||
|
||||
void Unit::CombatStart(Unit* target, bool initialAggro)
|
||||
{
|
||||
if (initialAggro)
|
||||
{
|
||||
if (!target->IsStandState())
|
||||
target->SetStandState(UNIT_STAND_STATE_STAND);
|
||||
|
||||
if (!target->IsInCombat() && target->GetTypeId() != TYPEID_PLAYER
|
||||
&& !target->ToCreature()->HasReactState(REACT_PASSIVE) && target->ToCreature()->IsAIEnabled)
|
||||
target->ToCreature()->AI()->AttackStart(this);
|
||||
|
||||
SetInCombatWith(target);
|
||||
target->SetInCombatWith(this);
|
||||
}
|
||||
|
||||
Player* me = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
Unit* who = target->GetCharmerOrOwnerOrSelf();
|
||||
if (me && who->GetTypeId() == TYPEID_PLAYER)
|
||||
me->SetContestedPvP(who->ToPlayer());
|
||||
if (me && who->IsPvP()
|
||||
&& (who->GetTypeId() != TYPEID_PLAYER
|
||||
|| !me->duel || me->duel->opponent != who))
|
||||
{
|
||||
me->UpdatePvP(true);
|
||||
me->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
|
||||
m_threatManager.UpdateOnlineStates(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::SetInCombatState(bool PvP, Unit* enemy)
|
||||
bool Unit::IsThreatened() const
|
||||
{
|
||||
// only alive units can be in combat
|
||||
if (!IsAlive())
|
||||
return;
|
||||
|
||||
if (PvP)
|
||||
m_CombatTimer = 5000;
|
||||
|
||||
if (IsInCombat() || HasUnitState(UNIT_STATE_EVADE))
|
||||
return;
|
||||
|
||||
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT);
|
||||
|
||||
if (Creature* creature = ToCreature())
|
||||
{
|
||||
// Set home position at place of engaging combat for escorted creatures
|
||||
if ((IsAIEnabled && creature->AI()->IsEscorted()) ||
|
||||
GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE ||
|
||||
GetMotionMaster()->GetCurrentMovementGeneratorType() == POINT_MOTION_TYPE)
|
||||
creature->SetHomePosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation());
|
||||
|
||||
if (enemy)
|
||||
{
|
||||
if (IsAIEnabled)
|
||||
creature->AI()->JustEngagedWith(enemy);
|
||||
|
||||
if (creature->GetFormation())
|
||||
creature->GetFormation()->MemberEngagingTarget(creature, enemy);
|
||||
}
|
||||
|
||||
if (IsPet())
|
||||
{
|
||||
UpdateSpeed(MOVE_RUN);
|
||||
UpdateSpeed(MOVE_SWIM);
|
||||
UpdateSpeed(MOVE_FLIGHT);
|
||||
}
|
||||
|
||||
if (!(creature->GetCreatureTemplate()->type_flags & CREATURE_TYPE_FLAG_MOUNTED_COMBAT_ALLOWED))
|
||||
Dismount();
|
||||
}
|
||||
|
||||
for (Unit::ControlList::iterator itr = m_Controlled.begin(); itr != m_Controlled.end();)
|
||||
{
|
||||
Unit* controlled = *itr;
|
||||
++itr;
|
||||
|
||||
controlled->SetInCombatState(PvP, enemy);
|
||||
controlled->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::ClearInCombat()
|
||||
{
|
||||
m_CombatTimer = 0;
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT);
|
||||
|
||||
// Reset rune flags after combat
|
||||
if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_DEATH_KNIGHT)
|
||||
{
|
||||
for (uint8 i = 0; i < MAX_RUNES; ++i)
|
||||
{
|
||||
ToPlayer()->SetRuneTimer(i, 0xFFFFFFFF);
|
||||
ToPlayer()->SetLastRuneGraceTimer(i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Player's state will be cleared in Player::UpdateContestedPvP
|
||||
if (Creature* creature = ToCreature())
|
||||
{
|
||||
ClearUnitState(UNIT_STATE_ATTACK_PLAYER);
|
||||
if (HasFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TAPPED))
|
||||
SetUInt32Value(UNIT_DYNAMIC_FLAGS, creature->GetCreatureTemplate()->dynamicflags);
|
||||
|
||||
if (creature->IsPet() || creature->IsGuardian())
|
||||
{
|
||||
if (Unit* owner = GetOwner())
|
||||
for (uint8 i = 0; i < MAX_MOVE_TYPE; ++i)
|
||||
if (owner->GetSpeedRate(UnitMoveType(i)) > GetSpeedRate(UnitMoveType(i)))
|
||||
SetSpeedRate(UnitMoveType(i), owner->GetSpeedRate(UnitMoveType(i)));
|
||||
}
|
||||
else if (!IsCharmed())
|
||||
return;
|
||||
}
|
||||
else
|
||||
ToPlayer()->UpdatePotionCooldown();
|
||||
|
||||
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_LEAVE_COMBAT);
|
||||
}
|
||||
|
||||
void Unit::ClearInPetCombat()
|
||||
{
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT);
|
||||
if (Unit* owner = GetOwner())
|
||||
owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT);
|
||||
return !m_threatManager.IsThreatListEmpty();
|
||||
}
|
||||
|
||||
bool Unit::isTargetableForAttack(bool checkFakeDeath) const
|
||||
@@ -8638,7 +8555,7 @@ bool Unit::_IsValidAttackTarget(Unit const* target, SpellInfo const* bySpell, Wo
|
||||
{
|
||||
// ignore stealth for aoe spells. Ignore stealth if target is player and unit in combat with same player
|
||||
bool const ignoreStealthCheck = (bySpell && bySpell->IsAffectingArea()) ||
|
||||
(target->GetTypeId() == TYPEID_PLAYER && target->HasStealthAura() && target->IsInCombat() && IsInCombatWith(target));
|
||||
(target->GetTypeId() == TYPEID_PLAYER && target->HasStealthAura() && IsInCombatWith(target));
|
||||
|
||||
if (!CanSeeOrDetect(target, ignoreStealthCheck))
|
||||
return false;
|
||||
@@ -9316,7 +9233,6 @@ void Unit::setDeathState(DeathState s)
|
||||
{
|
||||
CombatStop();
|
||||
GetThreatManager().ClearAllThreat();
|
||||
getHostileRefManager().deleteReferences();
|
||||
ClearComboPointHolders(); // any combo points pointed to unit lost at it death
|
||||
|
||||
if (IsNonMeleeSpellCast(false))
|
||||
@@ -9361,240 +9277,31 @@ void Unit::setDeathState(DeathState s)
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); // clear skinnable for creature and player (at battleground)
|
||||
}
|
||||
|
||||
/*########################################
|
||||
######## ########
|
||||
######## AGGRO SYSTEM ########
|
||||
######## ########
|
||||
########################################*/
|
||||
bool Unit::CanHaveThreatList(bool skipAliveCheck) const
|
||||
{
|
||||
// only creatures can have threat list
|
||||
if (GetTypeId() != TYPEID_UNIT)
|
||||
return false;
|
||||
|
||||
// only alive units can have threat list
|
||||
if (!skipAliveCheck && !IsAlive())
|
||||
return false;
|
||||
|
||||
// totems can not have threat list
|
||||
if (IsTotem())
|
||||
return false;
|
||||
|
||||
// vehicles can not have threat list
|
||||
//if (ToCreature()->IsVehicle())
|
||||
// return false;
|
||||
|
||||
// summons can not have a threat list, unless they are controlled by a creature
|
||||
if (HasUnitTypeMask(UNIT_MASK_MINION | UNIT_MASK_GUARDIAN | UNIT_MASK_CONTROLABLE_GUARDIAN) && GetOwnerOrCreatorGUID().IsPlayer())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
float Unit::ApplyTotalThreatModifier(float fThreat, SpellSchoolMask schoolMask)
|
||||
void Unit::AtExitCombat()
|
||||
{
|
||||
if (!HasAuraType(SPELL_AURA_MOD_THREAT) || fThreat < 0)
|
||||
return fThreat;
|
||||
|
||||
SpellSchools school = GetFirstSchoolInMask(schoolMask);
|
||||
|
||||
return fThreat * m_threatModifier[school];
|
||||
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_LEAVE_COMBAT);
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
void Unit::TauntApply(Unit* taunter)
|
||||
void Unit::UpdatePetCombatState()
|
||||
{
|
||||
ASSERT(GetTypeId() == TYPEID_UNIT);
|
||||
ASSERT(!IsPet()); // player pets do not use UNIT_FLAG_PET_IN_COMBAT for this purpose - but player pets should also never have minions of their own to call this
|
||||
|
||||
if (!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && taunter->ToPlayer()->IsGameMaster()))
|
||||
return;
|
||||
|
||||
if (!CanHaveThreatList())
|
||||
return;
|
||||
|
||||
Creature* creature = ToCreature();
|
||||
|
||||
if (creature->HasReactState(REACT_PASSIVE))
|
||||
return;
|
||||
|
||||
Unit* target = GetVictim();
|
||||
if (target && target == taunter)
|
||||
return;
|
||||
|
||||
SetInFront(taunter);
|
||||
if (creature->IsAIEnabled)
|
||||
creature->AI()->AttackStart(taunter);
|
||||
|
||||
//m_ThreatManager.tauntApply(taunter);
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
void Unit::TauntFadeOut(Unit* taunter)
|
||||
{
|
||||
ASSERT(GetTypeId() == TYPEID_UNIT);
|
||||
|
||||
if (!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && taunter->ToPlayer()->IsGameMaster()))
|
||||
return;
|
||||
|
||||
if (!CanHaveThreatList())
|
||||
return;
|
||||
|
||||
Creature* creature = ToCreature();
|
||||
|
||||
if (creature->HasReactState(REACT_PASSIVE))
|
||||
return;
|
||||
|
||||
Unit* target = GetVictim();
|
||||
if (!target || target != taunter)
|
||||
return;
|
||||
|
||||
if (m_ThreatManager.isThreatListEmpty())
|
||||
{
|
||||
if (creature->IsAIEnabled)
|
||||
creature->AI()->EnterEvadeMode(CreatureAI::EVADE_REASON_NO_HOSTILES);
|
||||
return;
|
||||
}
|
||||
|
||||
target = creature->SelectVictim(); // might have more taunt auras remaining
|
||||
|
||||
if (target && target != taunter)
|
||||
{
|
||||
SetInFront(target);
|
||||
if (creature->IsAIEnabled)
|
||||
creature->AI()->AttackStart(target);
|
||||
}
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
Unit* Creature::SelectVictim()
|
||||
{
|
||||
// function provides main threat functionality
|
||||
// next-victim-selection algorithm and evade mode are called
|
||||
// threat list sorting etc.
|
||||
|
||||
Unit* target = nullptr;
|
||||
// First checking if we have some taunt on us
|
||||
AuraEffectList const& tauntAuras = GetAuraEffectsByType(SPELL_AURA_MOD_TAUNT);
|
||||
if (!tauntAuras.empty())
|
||||
{
|
||||
Unit* caster = tauntAuras.back()->GetCaster();
|
||||
|
||||
// The last taunt aura caster is alive an we are happy to attack him
|
||||
if (caster && caster->IsAlive())
|
||||
return GetVictim();
|
||||
else if (tauntAuras.size() > 1)
|
||||
bool state = false;
|
||||
for (Unit* minion : m_Controlled)
|
||||
if (minion->IsInCombat())
|
||||
{
|
||||
// We do not have last taunt aura caster but we have more taunt auras,
|
||||
// so find first available target
|
||||
|
||||
// Auras are pushed_back, last caster will be on the end
|
||||
AuraEffectList::const_iterator aura = --tauntAuras.end();
|
||||
do
|
||||
{
|
||||
--aura;
|
||||
caster = (*aura)->GetCaster();
|
||||
if (caster && CanSeeOrDetect(caster, true) && IsValidAttackTarget(caster) && caster->isInAccessiblePlaceFor(ToCreature()))
|
||||
{
|
||||
target = caster;
|
||||
break;
|
||||
}
|
||||
} while (aura != tauntAuras.begin());
|
||||
state = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
target = GetVictim();
|
||||
}
|
||||
|
||||
if (CanHaveThreatList())
|
||||
{
|
||||
if (!target && !m_ThreatManager.isThreatListEmpty())
|
||||
// No taunt aura or taunt aura caster is dead standard target selection
|
||||
target = m_ThreatManager.getHostilTarget();
|
||||
}
|
||||
else if (!HasReactState(REACT_PASSIVE))
|
||||
{
|
||||
// We have player pet probably
|
||||
target = getAttackerForHelper();
|
||||
if (!target && IsSummon())
|
||||
{
|
||||
if (Unit* owner = ToTempSummon()->GetOwner())
|
||||
{
|
||||
if (owner->IsInCombat())
|
||||
target = owner->getAttackerForHelper();
|
||||
if (!target)
|
||||
{
|
||||
for (ControlList::const_iterator itr = owner->m_Controlled.begin(); itr != owner->m_Controlled.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->IsInCombat())
|
||||
{
|
||||
target = (*itr)->getAttackerForHelper();
|
||||
if (target)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state)
|
||||
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT);
|
||||
else
|
||||
return nullptr;
|
||||
|
||||
if (target && _IsTargetAcceptable(target) && CanCreatureAttack(target))
|
||||
{
|
||||
if (!HasSpellFocus())
|
||||
SetInFront(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
// last case when creature must not go to evade mode:
|
||||
// it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
|
||||
// Note: creature does not have targeted movement generator but has attacker in this case
|
||||
for (AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr)
|
||||
{
|
||||
if ((*itr) && CanCreatureAttack(*itr) && (*itr)->GetTypeId() != TYPEID_PLAYER
|
||||
&& !(*itr)->ToCreature()->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// @todo a vehicle may eat some mob, so mob should not evade
|
||||
if (GetVehicle())
|
||||
return nullptr;
|
||||
|
||||
// search nearby enemy before enter evade mode
|
||||
if (HasReactState(REACT_AGGRESSIVE))
|
||||
{
|
||||
target = SelectNearestTargetInAttackDistance(m_CombatDistance ? m_CombatDistance : ATTACK_DISTANCE);
|
||||
|
||||
if (target && _IsTargetAcceptable(target) && CanCreatureAttack(target))
|
||||
return target;
|
||||
}
|
||||
|
||||
Unit::AuraEffectList const& iAuras = GetAuraEffectsByType(SPELL_AURA_MOD_INVISIBILITY);
|
||||
if (!iAuras.empty())
|
||||
{
|
||||
for (Unit::AuraEffectList::const_iterator itr = iAuras.begin(); itr != iAuras.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->GetBase()->IsPermanent())
|
||||
{
|
||||
AI()->EnterEvadeMode(CreatureAI::EVADE_REASON_OTHER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// enter in evade mode in other case
|
||||
AI()->EnterEvadeMode(CreatureAI::EVADE_REASON_NO_HOSTILES);
|
||||
|
||||
return nullptr;
|
||||
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT);
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
//======================================================================
|
||||
//======================================================================
|
||||
|
||||
float Unit::ApplyEffectModifiers(SpellInfo const* spellProto, uint8 effect_index, float value) const
|
||||
@@ -10532,7 +10239,6 @@ void Unit::CleanupBeforeRemoveFromMap(bool finalCleanup)
|
||||
CombatStop();
|
||||
ClearComboPointHolders();
|
||||
GetThreatManager().ClearAllThreat();
|
||||
getHostileRefManager().deleteReferences();
|
||||
}
|
||||
|
||||
void Unit::CleanupsBeforeDelete(bool finalCleanup)
|
||||
@@ -11945,7 +11651,6 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
|
||||
}
|
||||
|
||||
// 10% durability loss on death
|
||||
// clean InHateListOf
|
||||
if (Player* plrVictim = victim->ToPlayer())
|
||||
{
|
||||
// remember victim PvP death for corpse type and corpse reclaim delay
|
||||
@@ -12337,7 +12042,6 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au
|
||||
|
||||
CastStop();
|
||||
CombatStop(); /// @todo CombatStop(true) may cause crash (interrupt spells)
|
||||
GetThreatManager().ClearAllThreat();
|
||||
|
||||
Player* playerCharmer = charmer->ToPlayer();
|
||||
|
||||
@@ -12482,8 +12186,6 @@ void Unit::RemoveCharmedBy(Unit* charmer)
|
||||
|
||||
CastStop();
|
||||
CombatStop(); /// @todo CombatStop(true) may cause crash (interrupt spells)
|
||||
getHostileRefManager().deleteReferences();
|
||||
GetThreatManager().ClearAllThreat();
|
||||
|
||||
if (_oldFactionId)
|
||||
{
|
||||
@@ -12563,6 +12265,8 @@ void Unit::RemoveCharmedBy(Unit* charmer)
|
||||
player->SetClientControl(this, true);
|
||||
}
|
||||
|
||||
EngageWithTarget(charmer);
|
||||
|
||||
// a guardian should always have charminfo
|
||||
if (playerCharmer && this != charmer->GetFirstControlled())
|
||||
playerCharmer->SendRemoveControlBar();
|
||||
@@ -12593,11 +12297,6 @@ void Unit::RestoreFaction()
|
||||
}
|
||||
}
|
||||
|
||||
Unit* Unit::GetRedirectThreatTarget()
|
||||
{
|
||||
return _redirectThreadInfo.GetTargetGUID() ? ObjectAccessor::GetUnit(*this, _redirectThreadInfo.GetTargetGUID()) : nullptr;
|
||||
}
|
||||
|
||||
bool Unit::CreateVehicleKit(uint32 id, uint32 creatureEntry)
|
||||
{
|
||||
VehicleEntry const* vehInfo = sVehicleStore.LookupEntry(id);
|
||||
@@ -12894,35 +12593,7 @@ void Unit::OnPhaseChange()
|
||||
return;
|
||||
|
||||
if (GetTypeId() == TYPEID_UNIT || !ToPlayer()->GetSession()->PlayerLogout())
|
||||
{
|
||||
HostileRefManager& refManager = getHostileRefManager();
|
||||
HostileReference* ref = refManager.getFirst();
|
||||
|
||||
while (ref)
|
||||
{
|
||||
if (Unit* unit = ref->GetSource()->GetOwner())
|
||||
if (Creature* creature = unit->ToCreature())
|
||||
refManager.setOnlineOfflineState(creature, creature->IsInPhase(this));
|
||||
|
||||
ref = ref->next();
|
||||
}
|
||||
|
||||
// modify threat lists for new phasemask
|
||||
if (GetTypeId() != TYPEID_PLAYER)
|
||||
{
|
||||
std::list<HostileReference*> threatList = GetThreatManager().getThreatList();
|
||||
std::list<HostileReference*> offlineThreatList = GetThreatManager().getOfflineThreatList();
|
||||
|
||||
// merge expects sorted lists
|
||||
threatList.sort();
|
||||
offlineThreatList.sort();
|
||||
threatList.merge(offlineThreatList);
|
||||
|
||||
for (std::list<HostileReference*>::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
|
||||
if (Unit* unit = (*itr)->getTarget())
|
||||
unit->getHostileRefManager().setOnlineOfflineState(ToCreature(), unit->IsInPhase(this));
|
||||
}
|
||||
}
|
||||
m_threatManager.UpdateOnlineStates(true, true);
|
||||
}
|
||||
|
||||
void Unit::UpdateObjectVisibility(bool forced)
|
||||
@@ -12931,6 +12602,7 @@ void Unit::UpdateObjectVisibility(bool forced)
|
||||
AddToNotify(NOTIFY_VISIBILITY_CHANGED);
|
||||
else
|
||||
{
|
||||
m_threatManager.UpdateOnlineStates(true, true);
|
||||
WorldObject::UpdateObjectVisibility(true);
|
||||
// call MoveInLineOfSight for nearby creatures
|
||||
Trinity::AIRelocationNotifier notifier(*this);
|
||||
@@ -14093,60 +13765,6 @@ void Unit::UpdateHeight(float newZ)
|
||||
GetVehicleKit()->RelocatePassengers();
|
||||
}
|
||||
|
||||
void Unit::SendThreatListUpdate()
|
||||
{
|
||||
if (!GetThreatManager().isThreatListEmpty())
|
||||
{
|
||||
WorldPackets::Combat::ThreatUpdate packet;
|
||||
packet.UnitGUID = GetGUID();
|
||||
ThreatContainer::StorageType const& tlist = GetThreatManager().getThreatList();
|
||||
packet.ThreatList.reserve(tlist.size());
|
||||
for (ThreatContainer::StorageType::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr)
|
||||
{
|
||||
WorldPackets::Combat::ThreatInfo info;
|
||||
info.UnitGUID = (*itr)->getUnitGuid();
|
||||
info.Threat = uint32((*itr)->getThreat());
|
||||
packet.ThreatList.push_back(info);
|
||||
}
|
||||
SendMessageToSet(packet.Write(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::SendChangeCurrentVictimOpcode(HostileReference* pHostileReference)
|
||||
{
|
||||
if (!GetThreatManager().isThreatListEmpty())
|
||||
{
|
||||
WorldPackets::Combat::HighestThreatUpdate packet;
|
||||
packet.UnitGUID = GetGUID();
|
||||
packet.HighestThreatGUID = pHostileReference->getUnitGuid();
|
||||
ThreatContainer::StorageType const& tlist = GetThreatManager().getThreatList();
|
||||
packet.ThreatList.reserve(tlist.size());
|
||||
for (ThreatContainer::StorageType::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr)
|
||||
{
|
||||
WorldPackets::Combat::ThreatInfo info;
|
||||
info.UnitGUID = (*itr)->getUnitGuid();
|
||||
info.Threat = uint32((*itr)->getThreat());
|
||||
packet.ThreatList.push_back(info);
|
||||
}
|
||||
SendMessageToSet(packet.Write(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::SendClearThreatListOpcode()
|
||||
{
|
||||
WorldPackets::Combat::ThreatClear packet;
|
||||
packet.UnitGUID = GetGUID();
|
||||
SendMessageToSet(packet.Write(), false);
|
||||
}
|
||||
|
||||
void Unit::SendRemoveFromThreatListOpcode(HostileReference* pHostileReference)
|
||||
{
|
||||
WorldPackets::Combat::ThreatRemove packet;
|
||||
packet.UnitGUID = GetGUID();
|
||||
packet.AboutGUID = pHostileReference->getUnitGuid();
|
||||
SendMessageToSet(packet.Write(), false);
|
||||
}
|
||||
|
||||
// baseRage means damage taken when attacker = false
|
||||
void Unit::RewardRage(uint32 baseRage, bool attacker)
|
||||
{
|
||||
@@ -14200,10 +13818,15 @@ void Unit::StopAttackFaction(uint32 faction_id)
|
||||
++itr;
|
||||
}
|
||||
|
||||
getHostileRefManager().deleteReferencesForFaction(faction_id);
|
||||
std::vector<CombatReference*> refsToEnd;
|
||||
for (auto const& pair : m_combatManager.GetPvECombatRefs())
|
||||
if (pair.second->GetOther(this)->GetFactionTemplateEntry()->Faction == faction_id)
|
||||
refsToEnd.push_back(pair.second);
|
||||
for (CombatReference* ref : refsToEnd)
|
||||
ref->EndCombat();
|
||||
|
||||
for (ControlList::const_iterator itr = m_Controlled.begin(); itr != m_Controlled.end(); ++itr)
|
||||
(*itr)->StopAttackFaction(faction_id);
|
||||
for (Unit* minion : m_Controlled)
|
||||
minion->StopAttackFaction(faction_id);
|
||||
}
|
||||
|
||||
void Unit::OutDebugInfo() const
|
||||
|
||||
Reference in new issue
Block a user