Skip to content

Commit 46f0d40

Browse files
authored
fix(Core/Combat): drop dangling current victim on phase change crash (azerothcore#26020)
Co-authored-by: blinkysc <blinkysc@users.noreply.github.com>
1 parent c029eab commit 46f0d40

2 files changed

Lines changed: 5 additions & 21 deletions

File tree

src/server/game/Entities/Unit/Unit.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15321,30 +15321,10 @@ void Unit::SetPhaseMask(uint32 newPhaseMask, bool update)
1532115321

1532215322
if (!sScriptMgr->CanSetPhaseMask(this, newPhaseMask, update))
1532315323
return;
15324-
15325-
// Phase-related threat updates are done AFTER the phase change below
1532615324
}
1532715325

1532815326
WorldObject::SetPhaseMask(newPhaseMask, false);
1532915327

15330-
// Now update threat online states with the new phase mask applied
15331-
if (IsCreature() || (IsPlayer() && !ToPlayer()->IsGameMaster() && !ToPlayer()->GetSession()->PlayerLogout()))
15332-
{
15333-
// Update online state for units that have me on their threat list
15334-
for (auto const& pair : GetThreatMgr().GetThreatenedByMeList())
15335-
{
15336-
if (ThreatReference* ref = pair.second)
15337-
ref->UpdateOffline();
15338-
}
15339-
15340-
// Update online state for units on my threat list
15341-
if (!IsPlayer())
15342-
{
15343-
for (ThreatReference* ref : GetThreatMgr().GetModifiableThreatList())
15344-
ref->UpdateOffline();
15345-
}
15346-
}
15347-
1534815328
if (!IsInWorld())
1534915329
{
1535015330
return;

src/test/server/game/Combat/ThreatManagerTest.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ TEST_F(ThreatManagerIntegrationTest,
734734
}
735735

736736
// ============================================================================
737-
// Phase Change + Threat Offline State Tests (SetPhaseMask order fix)
737+
// Phase Change + Threat Offline State Tests
738738
// ============================================================================
739739

740740
TEST_F(ThreatManagerIntegrationTest,
@@ -748,6 +748,10 @@ TEST_F(ThreatManagerIntegrationTest,
748748
// Move B to a different phase
749749
_creatureB->SetPhase(2);
750750

751+
// Online state is refreshed lazily on the next threat update tick (matches
752+
// TrinityCore - SetPhaseMask itself does not touch threat)
753+
_creatureA->TestGetThreatMgr().Update(ThreatManager::THREAT_UPDATE_INTERVAL);
754+
751755
// B should now be offline on A's threat list (different phases)
752756
// The list is not empty if we include offline, but empty if we don't
753757
EXPECT_TRUE(_creatureA->TestGetThreatMgr().IsThreatenedBy(_creatureB, true)); // includeOffline

0 commit comments

Comments
 (0)