Beispiel #1
0
        public bool CanSee(PhaseShift other)
        {
            if (Flags.HasFlag(PhaseShiftFlags.Unphased) && other.Flags.HasFlag(PhaseShiftFlags.Unphased))
            {
                return(true);
            }
            if (Flags.HasFlag(PhaseShiftFlags.AlwaysVisible) || other.Flags.HasFlag(PhaseShiftFlags.AlwaysVisible))
            {
                return(true);
            }
            if (Flags.HasFlag(PhaseShiftFlags.Inverse) && other.Flags.HasFlag(PhaseShiftFlags.Inverse))
            {
                return(true);
            }

            PhaseFlags excludePhasesWithFlag = PhaseFlags.None;

            if (Flags.HasFlag(PhaseShiftFlags.NoCosmetic) && other.Flags.HasFlag(PhaseShiftFlags.NoCosmetic))
            {
                excludePhasesWithFlag = PhaseFlags.Cosmetic;
            }

            if (!Flags.HasFlag(PhaseShiftFlags.Inverse) && !other.Flags.HasFlag(PhaseShiftFlags.Inverse))
            {
                ObjectGuid ownerGuid         = PersonalGuid;
                ObjectGuid otherPersonalGuid = other.PersonalGuid;
                return(Phases.Intersect(other.Phases, (myPhase, otherPhase) => !myPhase.Value.Flags.HasAnyFlag(excludePhasesWithFlag) && (!myPhase.Value.Flags.HasFlag(PhaseFlags.Personal) || ownerGuid == otherPersonalGuid)).Any());
            }

            var checkInversePhaseShift = new Func <PhaseShift, PhaseShift, bool>((phaseShift, excludedPhaseShift) =>
            {
                if (phaseShift.Flags.HasFlag(PhaseShiftFlags.Unphased) && !excludedPhaseShift.Flags.HasFlag(PhaseShiftFlags.InverseUnphased))
                {
                    return(true);
                }

                var list = excludedPhaseShift.Phases.ToList();
                foreach (var pair in phaseShift.Phases)
                {
                    if (pair.Value.Flags.HasAnyFlag(excludePhasesWithFlag))
                    {
                        continue;
                    }

                    var ExcludedPhaseRef = excludedPhaseShift.Phases.LookupByKey(pair.Key);
                    if (ExcludedPhaseRef == null || ExcludedPhaseRef.Flags.HasAnyFlag(excludePhasesWithFlag))
                    {
                        return(true);
                    }
                }

                return(false);
            });

            if (other.Flags.HasFlag(PhaseShiftFlags.Inverse))
            {
                return(checkInversePhaseShift(this, other));
            }

            return(checkInversePhaseShift(other, this));
        }
Beispiel #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();
                    // 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);
        }
Beispiel #3
0
        public static void FillPartyMemberPhase(PartyMemberPhaseStates partyMemberPhases, PhaseShift phaseShift)
        {
            partyMemberPhases.PhaseShiftFlags = (int)phaseShift.Flags;
            partyMemberPhases.PersonalGUID    = phaseShift.PersonalGuid;

            foreach (var phase in phaseShift.Phases)
            {
                partyMemberPhases.List.Add(new PartyMemberPhase((uint)phase.Flags, phase.Id));
            }
        }
Beispiel #4
0
        public static void OnAreaChange(WorldObject obj)
        {
            PhaseShift          phaseShift           = obj.GetPhaseShift();
            PhaseShift          suppressedPhaseShift = obj.GetSuppressedPhaseShift();
            var                 oldPhases            = phaseShift.GetPhases(); // for comparison
            ConditionSourceInfo srcInfo = new ConditionSourceInfo(obj);

            obj.GetPhaseShift().ClearPhases();
            obj.GetSuppressedPhaseShift().ClearPhases();

            uint            areaId    = obj.GetAreaId();
            AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId);

            while (areaEntry != null)
            {
                var newAreaPhases = Global.ObjectMgr.GetPhasesForArea(areaEntry.Id);
                if (!newAreaPhases.Empty())
                {
                    foreach (PhaseAreaInfo phaseArea in newAreaPhases)
                    {
                        if (phaseArea.SubAreaExclusions.Contains(areaId))
                        {
                            continue;
                        }

                        uint phaseId = phaseArea.PhaseInfo.Id;
                        if (Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, phaseArea.Conditions))
                        {
                            phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), phaseArea.Conditions);
                        }
                        else
                        {
                            suppressedPhaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), phaseArea.Conditions);
                        }
                    }
                }

                areaEntry = CliDB.AreaTableStorage.LookupByKey(areaEntry.ParentAreaID);
            }

            bool changed = phaseShift.GetPhases() != oldPhases;
            Unit unit    = obj.ToUnit();

            if (unit)
            {
                foreach (AuraEffect aurEff in unit.GetAuraEffectsByType(AuraType.Phase))
                {
                    uint phaseId = (uint)aurEff.GetMiscValueB();
                    changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), null) || changed;
                }

                foreach (AuraEffect aurEff in unit.GetAuraEffectsByType(AuraType.PhaseGroup))
                {
                    var phasesInGroup = Global.DB2Mgr.GetPhasesForGroup((uint)aurEff.GetMiscValueB());
                    foreach (uint phaseId in phasesInGroup)
                    {
                        changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), null) || changed;
                    }
                }

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

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

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

            UpdateVisibilityIfNeeded(obj, true, changed);
        }