From ae9b786784ab67574012f60da980a28f918e14d1 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 10 Jan 2018 12:15:38 -0500 Subject: [PATCH] Core/Entities: Improved UpdateAreaAndZonePhase() to allow easier building of database phase conditions --- Source/Game/Entities/Object/WorldObject.cs | 44 ++++++++++------------ 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 547deb42e..01a71e859 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -2175,34 +2175,28 @@ namespace Game.Entities public void UpdateAreaAndZonePhase() { bool updateNeeded = false; - var phases = Global.ObjectMgr.GetAreaAndZonePhases(); - foreach (var areaOrZoneId in phases.Keys) + var allAreasPhases = Global.ObjectMgr.GetAreaAndZonePhases(); + uint[] zoneAndArea = { GetZoneId(), GetAreaId() }; + + // We first remove all phases from other areas & zones + foreach (var key in allAreasPhases.Keys) + foreach (PhaseInfoStruct phase in allAreasPhases[key]) + if (!Global.DB2Mgr.IsInArea(GetAreaId(), key)) + 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 + foreach (uint area in zoneAndArea) { - foreach (var phase in phases[areaOrZoneId]) + var currentPhases = Global.ObjectMgr.GetPhasesForArea(area); + if (currentPhases != null) { - if (areaOrZoneId == GetAreaId() || areaOrZoneId == GetZoneId()) + foreach (PhaseInfoStruct phaseInfoStruct in currentPhases) { - if (Global.ConditionMgr.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 - { - // 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 = Global.ConditionMgr.IsObjectMeetToConditions(this, phaseInfoStruct.Conditions); + + // add or remove phase depending of condition + updateNeeded = SetInPhase(phaseInfoStruct.Id, false, apply) || updateNeeded; } } }