aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTraesh <Traesh@users.noreply.github.com>2018-01-10 17:57:13 +0100
committerShauren <shauren.trinity@gmail.com>2018-01-10 17:57:12 +0100
commit5b90538919cdf8b1984049bd203104128bec5bf2 (patch)
tree789c1e2cdc3032a65545514137ff3cf0e71c32c1
parentb3baa7f4bc774756befa0aac634ba7630d2020b7 (diff)
Core/Entities: Improved UpdateAreaAndZonePhase() to allow easier building of database phase conditions (#21214)
Closes #18190 Closes #21196
-rw-r--r--src/server/game/Entities/Object/Object.cpp44
1 files changed, 18 insertions, 26 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index 332e80125ea..46db4f0d390 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -2888,35 +2888,27 @@ bool WorldObject::HasInPhaseList(uint32 phase)
void WorldObject::UpdateAreaAndZonePhase()
{
bool updateNeeded = false;
- PhaseInfo const& phases = sObjectMgr->GetAreaAndZonePhases();
- for (PhaseInfo::const_iterator itr = phases.begin(); itr != phases.end(); ++itr)
- {
- uint32 areaOrZoneId = itr->first;
+ PhaseInfo const& allAreasPhases = sObjectMgr->GetAreaAndZonePhases();
+ uint32 zoneAndArea[] = { GetZoneId(), GetAreaId() };
+
+ // We first remove all phases from other areas & zones
+ for (auto itr = allAreasPhases.begin(); itr != allAreasPhases.end(); ++itr)
for (PhaseInfoStruct const& phase : itr->second)
+ if (!DB2Manager::IsInArea(GetAreaId(), itr->first))
+ updateNeeded = SetInPhase(phase.Id, false, false) || updateNeeded; // not in area, remove phase, true if there was something removed
+
+ // Then we add the phases from this area and zone if conditions are met
+ // Zone is done before Area, so if Area does not meet condition, the phase will be removed
+ for (uint32 area : zoneAndArea)
+ {
+ if (std::vector<PhaseInfoStruct> const* currentPhases = sObjectMgr->GetPhasesForArea(area))
{
- if (areaOrZoneId == GetAreaId() || areaOrZoneId == GetZoneId())
- {
- if (sConditionMgr->IsObjectMeetToConditions(this, phase.Conditions))
- {
- // add new phase if condition passed, true if it wasnt added before
- bool up = SetInPhase(phase.Id, false, true);
- if (!updateNeeded && up)
- updateNeeded = true;
- }
- else
- {
- // condition failed, remove phase, true if there was something removed
- bool up = SetInPhase(phase.Id, false, false);
- if (!updateNeeded && up)
- updateNeeded = true;
- }
- }
- else
+ for (PhaseInfoStruct const& phaseInfoStruct : *currentPhases)
{
- // not in area, remove phase, true if there was something removed
- bool up = SetInPhase(phase.Id, false, false);
- if (!updateNeeded && up)
- updateNeeded = true;
+ bool apply = sConditionMgr->IsObjectMeetToConditions(this, phaseInfoStruct.Conditions);
+
+ // add or remove phase depending of condition
+ updateNeeded = SetInPhase(phaseInfoStruct.Id, false, apply) || updateNeeded;
}
}
}