From 001e1ce93525de9955dce8a10cd334aa4f2a8cff Mon Sep 17 00:00:00 2001 From: Rat Date: Mon, 27 Oct 2014 22:56:21 +0100 Subject: [PATCH] Core/Phases: fix logic in SetInPhase() - we should not remove the terrain swap if another phase still use it (cherry picked from commit 299c693b8420d81951ef67b8481e4ad6b192473f) --- src/server/game/Entities/Object/Object.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 62835ae903d..4858e6b81a8 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2726,23 +2726,21 @@ void WorldObject::SetPhaseMask(uint32 newPhaseMask, bool update) void WorldObject::SetInPhase(uint32 id, bool update, bool apply) { - std::list terrainSwaps = sObjectMgr->GetPhaseTerrainSwaps(id); - if (apply) - { _phases.insert(id); - _terrainSwaps.insert(terrainSwaps.begin(), terrainSwaps.end()); - } else - { _phases.erase(id); - // Remove the terrain swaps that were applied by this phase - // Iterator pointing to the start of the sequence of elements that we're going to delete - // other phases could use the same terrain swaps too, check for them before remove!!! + // Clear all terrain swaps, will be rebuilt below + // Reason for this is, multiple phases can have the same terrain swap, we should not remove the swap if another phase still use it + _terrainSwaps.clear(); - //std::set::iterator endRange = std::set_difference(_terrainSwaps.begin(), _terrainSwaps.end(), terrainSwaps.begin(), terrainSwaps.end(), _terrainSwaps.begin()); - //terrainSwaps.erase(endRange, _terrainSwaps.end()); + // Check all applied phases for terrain swap and add it only once + for (auto phaseId : _phases) + { + std::list swaps = sObjectMgr->GetPhaseTerrainSwaps(phaseId); + for (auto swap : swaps) + _terrainSwaps.insert(swap); } if (update && IsInWorld())