refactor(Core/Combat): DeleteThreatLists() become ClearAllThreat() (#11824)

refactor(Chore/Combat): DeleteThreatLists() become ClearAllThreat()
This commit is contained in:
Maelthyr
2022-05-23 05:51:52 -03:00
committed by GitHub
parent ae3ecb0f1a
commit dfc6adb081
40 changed files with 62 additions and 63 deletions
+2 -2
View File
@@ -43,14 +43,14 @@ void GuardAI::EnterEvadeMode(EvadeReason /*why*/)
{
me->GetMotionMaster()->MoveIdle();
me->CombatStop(true);
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
return;
}
LOG_DEBUG("entities.unit", "Guard entry: {} enters evade mode.", me->GetEntry());
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
// Remove ChaseMovementGenerator from MotionMaster stack list, and add HomeMovementGenerator instead
+1 -1
View File
@@ -563,7 +563,7 @@ void PetAI::HandleReturnMovement()
me->GetCharmInfo()->SetForcedTargetGUID();
// xinef: remember that npcs summoned by npcs can also be pets
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->ClearInPetCombat();
}
+1 -1
View File
@@ -305,7 +305,7 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/)
me->ClearComboPointHolders(); // Remove all combo points targeting this unit
// sometimes bosses stuck in combat?
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->LoadCreaturesAddon(true);
me->SetLootRecipient(nullptr);
@@ -201,7 +201,7 @@ void npc_escortAI::ReturnToLastPoint()
void npc_escortAI::EnterEvadeMode(EvadeReason /*why*/)
{
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->SetLootRecipient(nullptr);
@@ -153,7 +153,7 @@ void FollowerAI::JustRespawned()
void FollowerAI::EnterEvadeMode(EvadeReason /*why*/)
{
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->SetLootRecipient(nullptr);
+7
View File
@@ -406,6 +406,13 @@ ThreatMgr::ThreatMgr(Unit* owner) : iCurrentVictim(nullptr), iOwner(owner), iUpd
{
}
void ThreatMgr::ClearAllThreat()
{
if (iOwner->CanHaveThreatList() && !isThreatListEmpty())
iOwner->SendClearThreatListOpcode();
clearReferences();
}
//============================================================
void ThreatMgr::clearReferences()
+2
View File
@@ -236,6 +236,8 @@ public:
// -- compatibility layer for combat rewrite
void ResetAllThreat() { resetAllAggro(); }
void ClearAllThreat();
// Reset all aggro of unit in threadlist satisfying the predicate.
template<class PREDICATE> void resetAggro(PREDICATE predicate)
{
+3 -12
View File
@@ -13917,7 +13917,7 @@ void Unit::setDeathState(DeathState s, bool despawn)
if (s != ALIVE && s != JUST_RESPAWNED)
{
CombatStop();
DeleteThreatList();
GetThreatMgr().ClearAllThreat();
getHostileRefMgr().deleteReferences();
ClearComboPointHolders(); // any combo points pointed to unit lost at it death
@@ -14018,15 +14018,6 @@ void Unit::AddThreat(Unit* victim, float fThreat, SpellSchoolMask schoolMask, Sp
//======================================================================
void Unit::DeleteThreatList()
{
if (CanHaveThreatList() && !m_ThreatMgr.isThreatListEmpty())
SendClearThreatListOpcode();
m_ThreatMgr.clearReferences();
}
//======================================================================
void Unit::TauntApply(Unit* taunter)
{
ASSERT(GetTypeId() == TYPEID_UNIT);
@@ -15097,7 +15088,7 @@ void Unit::CleanupBeforeRemoveFromMap(bool finalCleanup)
CombatStop();
ClearComboPoints();
ClearComboPointHolders();
DeleteThreatList();
GetThreatMgr().ClearAllThreat();
getHostileRefMgr().deleteReferences();
GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
}
@@ -17446,7 +17437,7 @@ void Unit::Kill(Unit* killer, Unit* victim, bool durabilityLoss, WeaponAttackTyp
if (!creature->IsPet() && creature->GetLootMode() > 0)
{
creature->DeleteThreatList();
creature->GetThreatMgr().ClearAllThreat();
// must be after setDeathState which resets dynamic flags
if (!creature->loot.isLooted())
-1
View File
@@ -2105,7 +2105,6 @@ public:
[[nodiscard]] bool CanHaveThreatList() const;
void AddThreat(Unit* victim, float fThreat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellInfo const* threatSpell = nullptr);
float ApplyTotalThreatModifier(float fThreat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL);
void DeleteThreatList();
void TauntApply(Unit* victim);
void TauntFadeOut(Unit* taunter);
ThreatMgr& GetThreatMgr() { return m_ThreatMgr; }
@@ -203,7 +203,7 @@ public:
void EnterEvadeMode(EvadeReason /*why*/) override
{
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->LoadCreaturesAddon(true);
if (me->IsAlive())
@@ -779,7 +779,7 @@ public:
//do not call EnterEvadeMode(), it will create infinit loops
boss->Respawn();
boss->RemoveAllAuras();
boss->DeleteThreatList();
boss->GetThreatMgr().ClearAllThreat();
boss->CombatStop(true);
boss->LoadCreaturesAddon(true);
boss->GetMotionMaster()->MoveTargetedHome();
@@ -1243,7 +1243,7 @@ public:
Julianne->GetMotionMaster()->Clear();
Julianne->setDeathState(JUST_DIED);
Julianne->CombatStop(true);
Julianne->DeleteThreatList();
Julianne->GetThreatMgr().ClearAllThreat();
Julianne->ReplaceAllDynamicFlags(UNIT_DYNFLAG_LOOTABLE);
}
return;
@@ -1546,7 +1546,7 @@ void boss_julianne::boss_julianneAI::DamageTaken(Unit* /*done_by*/, uint32& dama
Romulo->GetMotionMaster()->Clear();
Romulo->setDeathState(JUST_DIED);
Romulo->CombatStop(true);
Romulo->DeleteThreatList();
Romulo->GetThreatMgr().ClearAllThreat();
Romulo->ReplaceAllDynamicFlags(UNIT_DYNFLAG_LOOTABLE);
}
@@ -242,7 +242,7 @@ public:
void EnterEvadeMode(EvadeReason /*why*/) override
{
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(false);
me->SetLootRecipient(nullptr);
@@ -697,13 +697,13 @@ public:
if (Creature* summon = ObjectAccessor::GetCreature(*me, *itr))
{
summon->CombatStop(true);
summon->DeleteThreatList();
summon->GetThreatMgr().ClearAllThreat();
summon->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
summon->SetReactState(REACT_PASSIVE);
summon->GetMotionMaster()->Clear(false);
}
me->CombatStop(true);
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->SetReactState(REACT_PASSIVE);
me->GetMotionMaster()->Clear(false);
@@ -329,7 +329,7 @@ public:
me->SetTarget();
me->SetReactState(REACT_PASSIVE);
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->SetRegeneratingHealth(false);
me->SetUnitFlag(UNIT_FLAG_NON_ATTACKABLE);
me->HandleEmoteCommand(EMOTE_ONESHOT_DROWN);
@@ -71,8 +71,8 @@ public:
if (player->GetQuestStatus(592) == QUEST_STATUS_INCOMPLETE) //Yenniku's Release
{
me->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_STATE_STUN);
me->CombatStop(); //stop combat
me->DeleteThreatList(); //unsure of this
me->CombatStop(); //stop combat
me->GetThreatMgr().ClearAllThreat(); //unsure of this
me->SetFaction(FACTION_HORDE_GENERIC);
bReset = true;
@@ -104,7 +104,7 @@ public:
if (player->GetTeamId() == TEAM_HORDE)
{
me->CombatStop();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
}
}
}
@@ -1013,7 +1013,7 @@ public:
void EnterEvadeMode(EvadeReason /*why*/) override
{
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->SetLootRecipient(nullptr);
@@ -2356,7 +2356,7 @@ public:
void EnterEvadeMode(EvadeReason /*why*/) override
{
me->RemoveAura(SPELL_HEROIC_VANGUARD);
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->SetLootRecipient(nullptr);
@@ -118,7 +118,7 @@ public:
me->RestoreFaction();
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
SetRun(false);
@@ -410,7 +410,7 @@ void hyjalAI::EnterEvadeMode(EvadeReason /*why*/)
{
if (me->GetEntry() != JAINA)
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->LoadCreaturesAddon(true);
@@ -178,7 +178,7 @@ public:
void DoFriend()
{
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->StopMoving();
@@ -550,7 +550,7 @@ public:
me->SetReactState(REACT_PASSIVE);
me->RemoveAllAuras();
AddCreatureAddonAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->GetMotionMaster()->Clear();
me->StopMoving();
@@ -580,7 +580,7 @@ public:
me->SetReactState(REACT_PASSIVE);
me->RemoveAllAuras();
AddCreatureAddonAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->GetMotionMaster()->Clear();
me->SetRegeneratingHealth(false);
@@ -133,7 +133,7 @@ public:
{
t->RemoveAura(SPELL_CHANGE_VEHICLE);
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->SetHealth(me->GetMaxHealth());
if( pInstance )
@@ -523,7 +523,7 @@ public:
if (TeamIdInInstance == TEAM_ALLIANCE)
c->UpdateEntry(NPC_JAINA_PART2);
}
c->DeleteThreatList();
c->GetThreatMgr().ClearAllThreat();
c->CombatStop(true);
c->InterruptNonMeleeSpells(true);
c->GetMotionMaster()->Clear();
@@ -540,7 +540,7 @@ public:
}
if (Creature* c = instance->GetCreature(NPC_LichKingGUID))
{
c->DeleteThreatList();
c->GetThreatMgr().ClearAllThreat();
c->CombatStop(true);
c->InterruptNonMeleeSpells(true);
c->GetMotionMaster()->Clear();
@@ -915,7 +915,7 @@ public:
if (TrashActive[i])
if (Creature* c = instance->GetCreature(NPC_TrashGUID[i]))
{
c->DeleteThreatList();
c->GetThreatMgr().ClearAllThreat();
c->CombatStop(true);
c->InterruptNonMeleeSpells(true);
c->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC | UNIT_FLAG_NOT_SELECTABLE);
@@ -1126,7 +1126,7 @@ public:
if (Creature* c = instance->GetCreature(NPC_LichKingGUID))
{
c->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_ONESHOT_NONE);
c->DeleteThreatList();
c->GetThreatMgr().ClearAllThreat();
c->CombatStop(true);
c->InterruptNonMeleeSpells(true);
c->SetVisible(false);
@@ -1123,7 +1123,7 @@ public:
return;
me->RemoveEvadeAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->LoadCreaturesAddon(true);
me->SetLootRecipient(nullptr);
@@ -1202,7 +1202,7 @@ public:
if (!attacker || attacker == me || attacker == me->GetVictim() || (det != DIRECT_DAMAGE && det != SPELL_DIRECT_DAMAGE))
return;
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->AddThreat(attacker, 500000000.0f);
}
@@ -784,7 +784,7 @@ public:
{
if (!me->IsAlive())
return;
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->GetMotionMaster()->MoveTargetedHome();
Reset();
@@ -1120,7 +1120,7 @@ public:
{
if (!me->IsAlive())
return;
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->GetMotionMaster()->MoveTargetedHome();
Reset();
@@ -1496,7 +1496,7 @@ struct gunship_npc_AI : public ScriptedAI
{
if (!me->IsAlive() || !me->IsInCombat())
return;
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->GetMotionMaster()->MoveTargetedHome();
Reset();
@@ -1557,7 +1557,7 @@ struct npc_gunship_boarding_addAI : public ScriptedAI
{
if (!me->IsAlive() || !me->IsInCombat())
return;
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->GetMotionMaster()->MoveTargetedHome();
Reset();
@@ -515,7 +515,7 @@ public:
{
darnavan->RemoveAllAuras();
darnavan->SetFaction(FACTION_FRIENDLY);
darnavan->DeleteThreatList();
darnavan->GetThreatMgr().ClearAllThreat();
darnavan->CombatStop(true);
darnavan->GetMotionMaster()->MoveIdle();
darnavan->StopMoving();
@@ -1139,7 +1139,7 @@ public:
void StartAttack()
{
GetCaster()->ClearUnitState(UNIT_STATE_CASTING);
GetCaster()->DeleteThreatList();
GetCaster()->GetThreatMgr().ClearAllThreat();
GetCaster()->ToCreature()->SetInCombatWithZone();
GetCaster()->ToCreature()->AI()->AttackStart(GetHitUnit());
GetCaster()->AddThreat(GetHitUnit(), 500000000.0f); // value seen in sniff
@@ -1647,7 +1647,7 @@ public:
return;
}
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(false);
}
@@ -3370,7 +3370,7 @@ public:
if (!me->IsAlive())
return;
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(false);
}
};
@@ -766,7 +766,7 @@ public:
_handledWP4 = false;
me->CombatStop();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
}
}
@@ -710,7 +710,7 @@ public:
me->SendMeleeAttackStop(me->GetVictim());
me->GetMotionMaster()->MoveTakeoff(MI_POINT_PH_3_FIGHT_POSITION, CenterPos.GetPositionX(), CenterPos.GetPositionY(), CenterPos.GetPositionZ() - 5.0f, me->GetSpeed(MOVE_RUN));
me->DeleteThreatList(); // players on vehicle are unattackable -> leads to EnterEvadeMode() because target is not acceptable!
me->GetThreatMgr().ClearAllThreat(); // players on vehicle are unattackable -> leads to EnterEvadeMode() because target is not acceptable!
// mount players:
Map::PlayerList const& PlayerList = me->GetMap()->GetPlayers();
@@ -239,7 +239,7 @@ public:
if (!_allowDeath)
{
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
damage = 0;
@@ -208,7 +208,7 @@ public:
void LeaveCombat()
{
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->LoadCreaturesAddon(true);
me->SetLootRecipient(nullptr);
@@ -258,7 +258,7 @@ public:
if (param == ACTION_CALLBACK)
{
me->SetSpeed(MOVE_RUN, 2.5f);
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->GetMotionMaster()->MoveTargetedHome();
returning = true;
@@ -384,7 +384,7 @@ struct violet_hold_trashAI : public npc_escortAI
me->SetHomePosition(1845.577759f + rand_norm() * 5 - 2.5f, 800.681152f + rand_norm() * 5 - 2.5f, 44.104248f, M_PI);
}
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
if (HasEscortState(STATE_ESCORT_ESCORTING))
{
@@ -74,7 +74,7 @@ public:
Creature* owner = GetOwner()->ToCreature();
owner->RemoveAllAurasExceptType(SPELL_AURA_DUMMY);
owner->CombatStop(true);
owner->DeleteThreatList();
owner->GetThreatMgr().ClearAllThreat();
owner->GetMotionMaster()->Clear(false);
owner->GetMotionMaster()->MoveFollow(GetCaster(), 4.0f, M_PI, MOTION_SLOT_ACTIVE);
owner->CastSpell(owner, SPELL_SUBDUED, true);
@@ -127,7 +127,7 @@ public:
me->SetFaction(FACTION_FRIENDLY);
me->SetNpcFlag(UNIT_NPC_FLAG_QUESTGIVER);
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
Talk(SAY_FREE);
return;
@@ -374,7 +374,7 @@ public:
me->SetFaction(FACTION_FRIENDLY);
me->SetStandState(UNIT_STAND_STATE_SIT);
me->RemoveAllAuras();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
UnkorUnfriendly_Timer = 60000;
}
+1 -1
View File
@@ -52,7 +52,7 @@ struct npc_pet_hunter_snake_trap : public ScriptedAI
void EnterEvadeMode(EvadeReason /*why*/) override
{
// _EnterEvadeMode();
me->DeleteThreatList();
me->GetThreatMgr().ClearAllThreat();
me->CombatStop(true);
me->LoadCreaturesAddon(true);
me->SetLootRecipient(nullptr);
+1 -1
View File
@@ -283,7 +283,7 @@ class spell_hun_taming_the_beast : public AuraScript
{
if (Creature* creature = target->ToCreature())
{
creature->DeleteThreatList();
creature->GetThreatMgr().ClearAllThreat();
}
}
}