fix(Core/Combat): Creatures should evade if its only victim is teleporting to other map (#7975)

This commit is contained in:
UltraNix
2021-09-21 00:05:45 +02:00
committed by GitHub
parent 73bac1777c
commit 1bf4f54b32
6 changed files with 22 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/
#include "CreatureAI.h"
#include "HostileRefMgr.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
@@ -99,13 +100,28 @@ void HostileRefMgr::updateThreatTables()
// The references are not needed anymore
// tell the source to remove them from the list and free the mem
void HostileRefMgr::deleteReferences()
void HostileRefMgr::deleteReferences(bool removeFromMap /*= false*/)
{
HostileReference* ref = getFirst();
while (ref)
{
HostileReference* nextRef = ref->next();
ref->removeReference();
if (removeFromMap)
{
if (ThreatMgr const* threatMgr = ref->GetSource())
{
if (threatMgr->areThreatListsEmpty())
{
if (Creature* creature = threatMgr->GetOwner()->ToCreature())
{
creature->AI()->EnterEvadeMode();
}
}
}
}
delete ref;
ref = nextRef;
}

View File

@@ -38,7 +38,7 @@ public:
// The references are not needed anymore
// tell the source to remove them from the list and free the mem
void deleteReferences();
void deleteReferences(bool removeFromMap = false);
// Remove specific faction references
void deleteReferencesForFaction(uint32 faction);

View File

@@ -14769,7 +14769,7 @@ void Unit::CleanupBeforeRemoveFromMap(bool finalCleanup)
CombatStop();
ClearComboPointHolders();
DeleteThreatList();
getHostileRefMgr().deleteReferences();
getHostileRefMgr().deleteReferences(true);
GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
}

View File

@@ -116,7 +116,7 @@ void WorldSession::HandleMoveWorldportAck()
}
if (!_player->getHostileRefMgr().isEmpty())
_player->getHostileRefMgr().deleteReferences(); // pussywizard: multithreading crashfix
_player->getHostileRefMgr().deleteReferences(true); // pussywizard: multithreading crashfix
CellCoord pair(Acore::ComputeCellCoord(GetPlayer()->GetPositionX(), GetPlayer()->GetPositionY()));
Cell cell(pair);

View File

@@ -882,7 +882,7 @@ struct ResetNotifier
void Map::RemovePlayerFromMap(Player* player, bool remove)
{
player->getHostileRefMgr().deleteReferences(); // pussywizard: multithreading crashfix
player->getHostileRefMgr().deleteReferences(true); // pussywizard: multithreading crashfix
bool inWorld = player->IsInWorld();
player->RemoveFromWorld();

View File

@@ -524,7 +524,7 @@ void WorldSession::LogoutPlayer(bool save)
//FIXME: logout must be delayed in case lost connection with client in time of combat
if (_player->GetDeathTimer())
{
_player->getHostileRefMgr().deleteReferences();
_player->getHostileRefMgr().deleteReferences(true);
_player->BuildPlayerRepop();
_player->RepopAtGraveyard();
}