Exemplo n.º 1
0
        public static void OnMapChange(WorldObject obj)
        {
            PhaseShift          phaseShift           = obj.GetPhaseShift();
            PhaseShift          suppressedPhaseShift = obj.GetSuppressedPhaseShift();
            ConditionSourceInfo srcInfo = new ConditionSourceInfo(obj);

            obj.GetPhaseShift().VisibleMapIds.Clear();
            obj.GetPhaseShift().UiWorldMapAreaIdSwaps.Clear();
            obj.GetSuppressedPhaseShift().VisibleMapIds.Clear();

            var visibleMapIds = Global.ObjectMgr.GetTerrainSwapsForMap(obj.GetMapId());

            if (!visibleMapIds.Empty())
            {
                foreach (TerrainSwapInfo visibleMapInfo in visibleMapIds)
                {
                    if (Global.ConditionMgr.IsObjectMeetingNotGroupedConditions(ConditionSourceType.TerrainSwap, visibleMapInfo.Id, srcInfo))
                    {
                        phaseShift.AddVisibleMapId(visibleMapInfo.Id, visibleMapInfo);
                        foreach (uint uiWorldMapAreaIdSwap in visibleMapInfo.UiWorldMapAreaIDSwaps)
                        {
                            phaseShift.AddUiWorldMapAreaIdSwap(uiWorldMapAreaIdSwap);
                        }
                    }
                    else
                    {
                        suppressedPhaseShift.AddVisibleMapId(visibleMapInfo.Id, visibleMapInfo);
                    }
                }
            }

            UpdateVisibilityIfNeeded(obj, false, true);
        }
Exemplo n.º 2
0
        public static void OnConditionChange(WorldObject obj)
        {
            PhaseShift          phaseShift           = obj.GetPhaseShift();
            PhaseShift          suppressedPhaseShift = obj.GetSuppressedPhaseShift();
            PhaseShift          newSuppressions      = new PhaseShift();
            ConditionSourceInfo srcInfo = new ConditionSourceInfo(obj);
            bool changed = false;

            foreach (var phaseRef in phaseShift.Phases.ToArray())
            {
                if (!phaseRef.AreaConditions.Empty() && !Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, phaseRef.AreaConditions))
                {
                    newSuppressions.AddPhase(phaseRef.Id, phaseRef.Flags, phaseRef.AreaConditions, phaseRef.References);
                    phaseShift.ModifyPhasesReferences(phaseRef, -phaseRef.References);
                    phaseShift.Phases.Remove(phaseRef);
                }
            }

            foreach (var phaseRef in suppressedPhaseShift.Phases.ToArray())
            {
                if (Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, phaseRef.AreaConditions))
                {
                    changed = phaseShift.AddPhase(phaseRef.Id, phaseRef.Flags, phaseRef.AreaConditions, phaseRef.References) || changed;
                    suppressedPhaseShift.ModifyPhasesReferences(phaseRef, -phaseRef.References);
                    suppressedPhaseShift.Phases.Remove(phaseRef);
                }
            }

            foreach (var pair in phaseShift.VisibleMapIds.ToList())
            {
                if (!Global.ConditionMgr.IsObjectMeetingNotGroupedConditions(ConditionSourceType.TerrainSwap, pair.Key, srcInfo))
                {
                    newSuppressions.AddVisibleMapId(pair.Key, pair.Value.VisibleMapInfo, pair.Value.References);
                    foreach (uint uiWorldMapAreaIdSwap in pair.Value.VisibleMapInfo.UiWorldMapAreaIDSwaps)
                    {
                        changed = phaseShift.RemoveUiWorldMapAreaIdSwap(uiWorldMapAreaIdSwap) || changed;
                    }

                    phaseShift.VisibleMapIds.Remove(pair.Key);
                }
            }

            foreach (var pair in suppressedPhaseShift.VisibleMapIds.ToList())
            {
                if (Global.ConditionMgr.IsObjectMeetingNotGroupedConditions(ConditionSourceType.TerrainSwap, pair.Key, srcInfo))
                {
                    changed = phaseShift.AddVisibleMapId(pair.Key, pair.Value.VisibleMapInfo, pair.Value.References) || changed;
                    foreach (uint uiWorldMapAreaIdSwap in pair.Value.VisibleMapInfo.UiWorldMapAreaIDSwaps)
                    {
                        changed = phaseShift.AddUiWorldMapAreaIdSwap(uiWorldMapAreaIdSwap) || changed;
                    }

                    suppressedPhaseShift.VisibleMapIds.Remove(pair.Key);
                }
            }

            Unit unit = obj.ToUnit();

            if (unit)
            {
                foreach (AuraEffect aurEff in unit.GetAuraEffectsByType(AuraType.Phase))
                {
                    uint phaseId     = (uint)aurEff.GetMiscValueB();
                    var  eraseResult = newSuppressions.RemovePhase(phaseId);
                    // if condition was met previously there is nothing to erase
                    if (newSuppressions.RemovePhase(phaseId))
                    {
                        phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), null);//todo needs checked
                    }
                }

                foreach (AuraEffect aurEff in unit.GetAuraEffectsByType(AuraType.PhaseGroup))
                {
                    var phasesInGroup = Global.DB2Mgr.GetPhasesForGroup((uint)aurEff.GetMiscValueB());
                    if (!phasesInGroup.Empty())
                    {
                        foreach (uint phaseId in phasesInGroup)
                        {
                            var eraseResult = newSuppressions.RemovePhase(phaseId);
                            // if condition was met previously there is nothing to erase
                            if (eraseResult)
                            {
                                phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), null);
                            }
                        }
                    }
                }
            }

            changed = changed || !newSuppressions.Phases.Empty() || !newSuppressions.VisibleMapIds.Empty();
            foreach (var phaseRef in newSuppressions.Phases)
            {
                suppressedPhaseShift.AddPhase(phaseRef.Id, phaseRef.Flags, phaseRef.AreaConditions, phaseRef.References);
            }

            foreach (var pair in newSuppressions.VisibleMapIds)
            {
                suppressedPhaseShift.AddVisibleMapId(pair.Key, pair.Value.VisibleMapInfo, pair.Value.References);
            }

            if (unit)
            {
                if (changed)
                {
                    unit.OnPhaseChange();
                }

                ForAllControlled(unit, controlled =>
                {
                    InheritPhaseShift(controlled, unit);
                });

                if (changed)
                {
                    unit.RemoveNotOwnSingleTargetAuras(true);
                }
            }

            UpdateVisibilityIfNeeded(obj, true, changed);
        }