Esempio n. 1
0
        void HandleMirrorImageDataRequest(GetMirrorImageData packet)
        {
            ObjectGuid guid = packet.UnitGUID;

            // Get unit for which data is needed by client
            Unit unit = Global.ObjAccessor.GetUnit(GetPlayer(), guid);

            if (!unit)
            {
                return;
            }

            if (!unit.HasAuraType(AuraType.CloneCaster))
            {
                return;
            }

            // Get creator of the unit (SPELL_AURA_CLONE_CASTER does not stack)
            Unit creator = unit.GetAuraEffectsByType(AuraType.CloneCaster).FirstOrDefault().GetCaster();

            if (!creator)
            {
                return;
            }

            Player player = creator.ToPlayer();

            if (player)
            {
                MirrorImageComponentedData data = new MirrorImageComponentedData();
                data.UnitGUID  = guid;
                data.DisplayID = (int)creator.GetDisplayId();
                data.RaceID    = (byte)creator.GetRace();
                data.Gender    = (byte)creator.GetGender();
                data.ClassID   = (byte)creator.GetClass();

                Guild guild = player.GetGuild();

                data.SkinColor      = player.GetByteValue(PlayerFields.Bytes, PlayerFieldOffsets.BytesOffsetSkinId);
                data.FaceVariation  = player.GetByteValue(PlayerFields.Bytes, PlayerFieldOffsets.BytesOffsetFaceId);
                data.HairVariation  = player.GetByteValue(PlayerFields.Bytes, PlayerFieldOffsets.BytesOffsetHairStyleId);
                data.HairColor      = player.GetByteValue(PlayerFields.Bytes, PlayerFieldOffsets.BytesOffsetHairColorId);
                data.BeardVariation = player.GetByteValue(PlayerFields.Bytes2, PlayerFieldOffsets.Bytes2OffsetFacialStyle);
                for (int i = 0; i < PlayerConst.CustomDisplaySize; ++i)
                {
                    data.CustomDisplay[i] = player.GetByteValue(PlayerFields.Bytes2, (byte)(PlayerFieldOffsets.Bytes2OffsetCustomDisplayOption + i));
                }
                data.GuildGUID = (guild ? guild.GetGUID() : ObjectGuid.Empty);

                byte[] itemSlots =
                {
                    EquipmentSlot.Head,
                    EquipmentSlot.Shoulders,
                    EquipmentSlot.Shirt,
                    EquipmentSlot.Chest,
                    EquipmentSlot.Waist,
                    EquipmentSlot.Legs,
                    EquipmentSlot.Feet,
                    EquipmentSlot.Wrist,
                    EquipmentSlot.Hands,
                    EquipmentSlot.Tabard,
                    EquipmentSlot.Cloak
                };

                // Display items in visible slots
                foreach (var slot in itemSlots)
                {
                    uint itemDisplayId;
                    Item item = player.GetItemByPos(InventorySlots.Bag0, slot);
                    if ((slot == EquipmentSlot.Head && player.HasFlag(PlayerFields.Flags, PlayerFlags.HideHelm)) ||
                        (slot == EquipmentSlot.Cloak && player.HasFlag(PlayerFields.Flags, PlayerFlags.HideCloak)))
                    {
                        itemDisplayId = 0;
                    }
                    else if (item)
                    {
                        itemDisplayId = item.GetDisplayId(player);
                    }
                    else
                    {
                        itemDisplayId = 0;
                    }

                    data.ItemDisplayID.Add((int)itemDisplayId);
                }

                SendPacket(data);
            }
            else
            {
                MirrorImageCreatureData data = new MirrorImageCreatureData();
                data.UnitGUID  = guid;
                data.DisplayID = (int)creator.GetDisplayId();
                SendPacket(data);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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 pair in phaseShift.Phases.ToList())
            {
                if (pair.Value.AreaConditions != null && !Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, pair.Value.AreaConditions))
                {
                    newSuppressions.AddPhase(pair.Key, pair.Value.Flags, pair.Value.AreaConditions, pair.Value.References);
                    phaseShift.ModifyPhasesReferences(pair.Key, pair.Value, -pair.Value.References);
                    phaseShift.Phases.Remove(pair.Key);
                }
            }

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

            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 uiMapPhaseId in pair.Value.VisibleMapInfo.UiMapPhaseIDs)
                    {
                        changed = phaseShift.RemoveUiMapPhaseId(uiMapPhaseId) || 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 uiMapPhaseId in pair.Value.VisibleMapInfo.UiMapPhaseIDs)
                    {
                        changed = phaseShift.AddUiMapPhaseId(uiMapPhaseId) || 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 pair in newSuppressions.Phases)
            {
                suppressedPhaseShift.AddPhase(pair.Key, pair.Value.Flags, pair.Value.AreaConditions, pair.Value.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);
        }
Esempio n. 4
0
        void HandleMirrorImageDataRequest(GetMirrorImageData packet)
        {
            ObjectGuid guid = packet.UnitGUID;

            // Get unit for which data is needed by client
            Unit unit = Global.ObjAccessor.GetUnit(GetPlayer(), guid);

            if (!unit)
            {
                return;
            }

            if (!unit.HasAuraType(AuraType.CloneCaster))
            {
                return;
            }

            // Get creator of the unit (SPELL_AURA_CLONE_CASTER does not stack)
            Unit creator = unit.GetAuraEffectsByType(AuraType.CloneCaster).FirstOrDefault().GetCaster();

            if (!creator)
            {
                return;
            }

            Player player = creator.ToPlayer();

            if (player)
            {
                MirrorImageComponentedData mirrorImageComponentedData = new();
                mirrorImageComponentedData.UnitGUID  = guid;
                mirrorImageComponentedData.DisplayID = (int)creator.GetDisplayId();
                mirrorImageComponentedData.RaceID    = (byte)creator.GetRace();
                mirrorImageComponentedData.Gender    = (byte)creator.GetGender();
                mirrorImageComponentedData.ClassID   = (byte)creator.GetClass();

                foreach (var customization in player.m_playerData.Customizations)
                {
                    var chrCustomizationChoice = new ChrCustomizationChoice();
                    chrCustomizationChoice.ChrCustomizationOptionID = customization.ChrCustomizationOptionID;
                    chrCustomizationChoice.ChrCustomizationChoiceID = customization.ChrCustomizationChoiceID;
                    mirrorImageComponentedData.Customizations.Add(chrCustomizationChoice);
                }

                Guild guild = player.GetGuild();
                mirrorImageComponentedData.GuildGUID = (guild ? guild.GetGUID() : ObjectGuid.Empty);

                byte[] itemSlots =
                {
                    EquipmentSlot.Head,
                    EquipmentSlot.Shoulders,
                    EquipmentSlot.Shirt,
                    EquipmentSlot.Chest,
                    EquipmentSlot.Waist,
                    EquipmentSlot.Legs,
                    EquipmentSlot.Feet,
                    EquipmentSlot.Wrist,
                    EquipmentSlot.Hands,
                    EquipmentSlot.Tabard,
                    EquipmentSlot.Cloak
                };

                // Display items in visible slots
                foreach (var slot in itemSlots)
                {
                    uint itemDisplayId;
                    Item item = player.GetItemByPos(InventorySlots.Bag0, slot);
                    if (item != null)
                    {
                        itemDisplayId = item.GetDisplayId(player);
                    }
                    else
                    {
                        itemDisplayId = 0;
                    }

                    mirrorImageComponentedData.ItemDisplayID.Add((int)itemDisplayId);
                }

                SendPacket(mirrorImageComponentedData);
            }
            else
            {
                MirrorImageCreatureData data = new();
                data.UnitGUID  = guid;
                data.DisplayID = (int)creator.GetDisplayId();
                SendPacket(data);
            }
        }