Skip to content

Commit

Permalink
Combat/Threat: Split ThreatManager::NotifyDisengaged off from ThreatM…
Browse files Browse the repository at this point in the history
…anager::ClearAllThreat. NotifyDisengaged signifies intent to clear the engagement flag, and should only be called from AI. Fixes #23490.
  • Loading branch information
Treeston committed Jun 23, 2019
1 parent 0057522 commit 1158f26
Show file tree
Hide file tree
Showing 25 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/server/game/AI/CoreAI/GuardAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ void GuardAI::EnterEvadeMode(EvadeReason /*why*/)
{
me->GetMotionMaster()->MoveIdle();
me->CombatStop(true);
me->GetThreatManager().ClearAllThreat();
me->GetThreatManager().NotifyDisengaged();
return;
}

TC_LOG_TRACE("scritps.ai", "GuardAI::EnterEvadeMode: %s enters evade mode.", me->GetGUID().ToString().c_str());

me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();

me->GetMotionMaster()->MoveTargetedHome();
}
Expand Down
8 changes: 2 additions & 6 deletions src/server/game/AI/CreatureAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,16 @@ bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/)

me->RemoveAurasOnEvade();

// sometimes bosses stuck in combat?
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->LoadCreaturesAddon();
me->SetLootRecipient(nullptr);
me->ResetPlayerDamageReq();
me->SetLastDamagedTime(0);
me->SetCannotReachTarget(false);
me->DoNotReacquireTarget();

if (me->IsInEvadeMode())
return false;

return true;
return !me->IsInEvadeMode();
}

static const uint32 BOUNDARY_VISUALIZE_CREATURE = 15425;
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void EscortAI::ReturnToLastPoint()
void EscortAI::EnterEvadeMode(EvadeReason /*why*/)
{
me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->SetLootRecipient(nullptr);

if (HasEscortState(STATE_ESCORT_ESCORTING))
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ void FollowerAI::EnterEvadeMode(EvadeReason /*why*/)
return;

me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->SetLootRecipient(nullptr);
me->SetCannotReachTarget(false);
me->DoNotReacquireTarget();
Expand Down
4 changes: 4 additions & 0 deletions src/server/game/Combat/ThreatManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ void ThreatManager::ClearAllThreat()
_myThreatListEntries.begin()->second->UnregisterAndFree();
while (!_myThreatListEntries.empty());
}
}

void ThreatManager::NotifyDisengaged()
{
// note: i don't really like having this here
// (maybe engage flag should be in creature ai? it's inherently an AI property...)
if (_owner->IsEngaged())
Expand Down
3 changes: 3 additions & 0 deletions src/server/game/Combat/ThreatManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class TC_GAME_API ThreatManager
void ClearThreat(ThreatReference* ref);
// Removes all targets from the threat list (will cause evade in UpdateVictim if called)
void ClearAllThreat();
// THIS SHOULD ONLY BE CALLED FROM A CREATURE'S AI (typically in EnterEvadeMode)
// notify the unit that the AI has disengaged
void NotifyDisengaged();

// Fixate on the passed target; this target will always be selected until the fixate is cleared
// (if the target is not in the threat list, does nothing)
Expand Down
1 change: 0 additions & 1 deletion src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8613,7 +8613,6 @@ void Unit::setDeathState(DeathState s)
if (s != ALIVE && s != JUST_RESPAWNED)
{
CombatStop();
GetThreatManager().ClearAllThreat();
ClearComboPointHolders(); // any combo points pointed to unit lost at it death

if (IsNonMeleeSpellCast(false))
Expand Down
1 change: 0 additions & 1 deletion src/server/game/Grids/ObjectGridLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ void ObjectGridStoper::Visit(CreatureMapType &m)
if (iter->GetSource()->IsInCombat())
{
iter->GetSource()->CombatStop();
iter->GetSource()->GetThreatManager().ClearAllThreat();
iter->GetSource()->AI()->EnterEvadeMode();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ class instance_blackrock_depths : public InstanceMapScript
{//do not call EnterEvadeMode(), it will create infinit loops
boss->Respawn();
boss->RemoveAllAuras();
boss->GetThreatManager().ClearAllThreat();
boss->CombatStop(true);
boss->GetThreatManager().NotifyDisengaged();
boss->LoadCreaturesAddon();
boss->GetMotionMaster()->MoveTargetedHome();
boss->SetLootRecipient(nullptr);
Expand Down
4 changes: 2 additions & 2 deletions src/server/scripts/EasternKingdoms/Karazhan/bosses_opera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ class boss_romulo : public CreatureScript
Julianne->GetMotionMaster()->Clear();
Julianne->setDeathState(JUST_DIED);
Julianne->CombatStop(true);
Julianne->GetThreatManager().ClearAllThreat();
Julianne->GetThreatManager().NotifyDisengaged();
Julianne->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE);
}
return;
Expand Down Expand Up @@ -1528,7 +1528,7 @@ void boss_julianne::boss_julianneAI::DamageTaken(Unit* /*done_by*/, uint32 &dama
Romulo->GetMotionMaster()->Clear();
Romulo->setDeathState(JUST_DIED);
Romulo->CombatStop(true);
Romulo->GetThreatManager().ClearAllThreat();
Romulo->GetThreatManager().NotifyDisengaged();
Romulo->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE);
}

Expand Down
11 changes: 5 additions & 6 deletions src/server/scripts/EasternKingdoms/ScarletEnclave/chapter5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1386,8 +1386,8 @@ class npc_highlord_darion_mograine : public CreatureScript
if (me->HasAura(SPELL_THE_MIGHT_OF_MOGRAINE))
me->RemoveAurasDueToSpell(SPELL_THE_MIGHT_OF_MOGRAINE);
me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->InterruptNonMeleeSpells(false);
me->SetWalk(false);

Expand All @@ -1407,8 +1407,8 @@ class npc_highlord_darion_mograine : public CreatureScript
if (Creature* temp = ObjectAccessor::GetCreature(*me, uiKorfaxGUID))
{
temp->RemoveAllAuras();
temp->GetThreatManager().ClearAllThreat();
temp->CombatStop(true);
temp->GetThreatManager().NotifyDisengaged();
temp->AttackStop();
temp->SetFaction(me->GetFaction());
temp->SetWalk(false);
Expand All @@ -1418,7 +1418,6 @@ class npc_highlord_darion_mograine : public CreatureScript
if (Creature* temp = ObjectAccessor::GetCreature(*me, uiMaxwellGUID))
{
temp->RemoveAllAuras();
temp->GetThreatManager().ClearAllThreat();
temp->CombatStop(true);
temp->AttackStop();
temp->SetFaction(me->GetFaction());
Expand All @@ -1429,8 +1428,8 @@ class npc_highlord_darion_mograine : public CreatureScript
if (Creature* temp = ObjectAccessor::GetCreature(*me, uiEligorGUID))
{
temp->RemoveAllAuras();
temp->GetThreatManager().ClearAllThreat();
temp->CombatStop(true);
temp->GetThreatManager().NotifyDisengaged();
temp->AttackStop();
temp->SetFaction(me->GetFaction());
temp->SetWalk(false);
Expand All @@ -1441,8 +1440,8 @@ class npc_highlord_darion_mograine : public CreatureScript
if (Creature* temp = ObjectAccessor::GetCreature(*me, uiKoltiraGUID))
{
temp->RemoveAllAuras();
temp->GetThreatManager().ClearAllThreat();
temp->CombatStop(true);
temp->GetThreatManager().NotifyDisengaged();
temp->AttackStop();
temp->SetFaction(me->GetFaction());
temp->SetWalk(false);
Expand All @@ -1456,8 +1455,8 @@ class npc_highlord_darion_mograine : public CreatureScript
if (Creature* temp = ObjectAccessor::GetCreature(*me, uiThassarianGUID))
{
temp->RemoveAllAuras();
temp->GetThreatManager().ClearAllThreat();
temp->CombatStop(true);
temp->GetThreatManager().NotifyDisengaged();
temp->AttackStop();
temp->SetFaction(me->GetFaction());
temp->SetWalk(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ void hyjalAI::EnterEvadeMode(EvadeReason /*why*/)
{
if (me->GetEntry() != JAINA)
me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->LoadCreaturesAddon();

if (me->IsAlive())
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Kalimdor/zone_desolace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class npc_aged_dying_ancient_kodo : public CreatureScript

me->UpdateEntry(NPC_TAMED_KODO);
me->CombatStop();
me->GetThreatManager().ClearAllThreat();
me->GetThreatManager().NotifyDisengaged();
me->SetFaction(FACTION_FRIENDLY);
me->SetSpeedRate(MOVE_RUN, 0.6f);
me->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, me->GetFollowAngle());
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Kalimdor/zone_the_barrens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ class npc_taskmaster_fizzule : public CreatureScript
void DoFriend()
{
me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();

me->StopMoving();
me->GetMotionMaster()->MoveIdle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ class npc_dark_nucleus : public CreatureScript
if (attacker == me)
return;

me->GetThreatManager().ClearAllThreat();
me->GetThreatManager().ResetAllThreat();
AddThreat(attacker, 500000000.0f);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ struct gunship_npc_AI : public ScriptedAI
if (!me->IsAlive() || !me->IsInCombat())
return;

me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->GetMotionMaster()->MoveTargetedHome();
}

Expand Down Expand Up @@ -724,8 +724,8 @@ class npc_gunship : public CreatureScript
{
Creature* stalker = *itr;
stalker->RemoveAllAuras();
stalker->GetThreatManager().ClearAllThreat();
stalker->CombatStop(true);
stalker->GetThreatManager().NotifyDisengaged();
}

uint32 explosionSpell = isVictory ? SPELL_EXPLOSION_VICTORY : SPELL_EXPLOSION_WIPE;
Expand Down Expand Up @@ -883,8 +883,8 @@ class npc_high_overlord_saurfang_igb : public CreatureScript
if (!me->IsAlive())
return;

me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->GetMotionMaster()->MoveTargetedHome();

Reset();
Expand Down Expand Up @@ -1147,8 +1147,8 @@ class npc_muradin_bronzebeard_igb : public CreatureScript
if (!me->IsAlive())
return;

me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->GetMotionMaster()->MoveTargetedHome();

Reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ class spell_putricide_ooze_channel : public SpellScriptLoader
void StartAttack()
{
GetCaster()->ClearUnitState(UNIT_STATE_CASTING);
GetCaster()->GetThreatManager().ClearAllThreat();
GetCaster()->GetThreatManager().ResetAllThreat();
GetCaster()->ToCreature()->AI()->AttackStart(GetHitUnit());
GetCaster()->GetThreatManager().AddThreat(GetHitUnit(), 500000000.0f, nullptr, true, true); // value seen in sniff
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1800,8 +1800,8 @@ class npc_terenas_menethil : public CreatureScript
if (!me->IsAlive())
return;

me->GetThreatManager().ClearAllThreat();
me->CombatStop(false);
me->GetThreatManager().NotifyDisengaged();
}

void DamageTaken(Unit* /*attacker*/, uint32& damage) override
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Northrend/Nexus/Oculus/boss_urom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class boss_urom : public CreatureScript
{
me->RemoveAllAuras();
me->CombatStop(false);
me->GetThreatManager().ClearAllThreat();
me->GetThreatManager().NotifyDisengaged();
}

void SpellHit(Unit* /*caster*/, SpellInfo const* spellInfo) override
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Northrend/Ulduar/Ulduar/boss_freya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ class boss_freya : public CreatureScript
Elder->RemoveAllAuras();
Elder->AttackStop();
Elder->CombatStop(true);
Elder->GetThreatManager().ClearAllThreat();
Elder->GetThreatManager().NotifyDisengaged();
Elder->AI()->DoAction(ACTION_ELDER_FREYA_KILLED);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ class npc_mimiron_assault_bot : public CreatureScript
{
if (Unit* newTarget = SelectTarget(SELECT_TARGET_MINDISTANCE, 0, 30.0f, true))
{
me->GetThreatManager().ClearAllThreat();
me->GetThreatManager().ResetAllThreat();
AttackStart(newTarget);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Northrend/zone_borean_tundra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class spell_red_dragonblood : public SpellScriptLoader
Creature* owner = GetOwner()->ToCreature();
owner->RemoveAllAurasExceptType(SPELL_AURA_DUMMY);
owner->CombatStop(true);
owner->GetThreatManager().ClearAllThreat();
owner->GetThreatManager().NotifyDisengaged();
owner->GetMotionMaster()->Clear();
owner->GetMotionMaster()->MoveFollow(GetCaster(), 4.0f, 0.0f);
owner->CastSpell(owner, SPELL_SUBDUED, true);
Expand Down
4 changes: 2 additions & 2 deletions src/server/scripts/Outland/zone_hellfire_peninsula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class npc_aeranas : public CreatureScript
me->SetFaction(FACTION_FRIENDLY);
me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER);
me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
Talk(SAY_FREE);
return;
}
Expand Down Expand Up @@ -973,8 +973,8 @@ class npc_magister_aledis : public CreatureScript
_events.Reset();
me->RestoreFaction();
me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER);
me->SetImmuneToPC(true);
Talk(SAY_DEFEATED);
Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Outland/zone_terokkar_forest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class npc_unkor_the_ruthless : public CreatureScript
me->SetFaction(FACTION_FRIENDLY);
me->SetStandState(UNIT_STAND_STATE_SIT);
me->RemoveAllAuras();
me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
UnkorUnfriendly_Timer = 60000;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Pet/pet_priest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class npc_pet_pri_lightwell : public CreatureScript
if (!me->IsAlive())
return;

me->GetThreatManager().ClearAllThreat();
me->CombatStop(true);
me->GetThreatManager().NotifyDisengaged();
me->ResetPlayerDamageReq();
}
};
Expand Down

0 comments on commit 1158f26

Please sign in to comment.