Example #1
0
        bool CreateServer(Map map, AreaTriggerTemplate areaTriggerTemplate, AreaTriggerSpawn position)
        {
            SetMap(map);
            Relocate(position.Location);
            if (!IsPositionValid())
            {
                Log.outError(LogFilter.AreaTrigger, $"AreaTriggerServer (id {areaTriggerTemplate.Id}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})");
                return(false);
            }

            _areaTriggerTemplate = areaTriggerTemplate;

            _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), areaTriggerTemplate.Id.Id, GetMap().GenerateLowGuid(HighGuid.AreaTrigger)));

            SetEntry(areaTriggerTemplate.Id.Id);

            SetObjectScale(1.0f);

            if (position.PhaseUseFlags != 0 || position.PhaseId != 0 || position.PhaseGroup != 0)
            {
                PhasingHandler.InitDbPhaseShift(GetPhaseShift(), (PhaseUseFlagsValues)position.PhaseUseFlags, position.PhaseId, position.PhaseGroup);
            }

            UpdateShape();

            AI_Initialize();

            _ai.OnCreate();

            return(true);
        }
Example #2
0
        public void LoadSignatures()
        {
            uint oldMSTime = Time.GetMSTime();

            SQLResult result = DB.Characters.Query("SELECT petitionguid, player_account, playerguid FROM petition_sign");

            if (result.IsEmpty())
            {
                Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Petition signs!");
                return;
            }

            uint count = 0;

            do
            {
                Petition petition = GetPetition(ObjectGuid.Create(HighGuid.Item, result.Read <ulong>(0)));
                if (petition == null)
                {
                    continue;
                }

                petition.AddSignature(petition.PetitionGuid, result.Read <uint>(1), ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(2)), true);
                ++count;
            } while (result.NextRow());

            Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} Petition signs in {Time.GetMSTimeDiffToNow(oldMSTime)} ms.");
        }
Example #3
0
        bool Create(ulong lowGuid, SceneType type, uint sceneId, uint scriptPackageId, Map map, Unit creator, Position pos, ObjectGuid privateObjectOwner)
        {
            SetMap(map);
            Relocate(pos);
            RelocateStationaryPosition(pos);

            SetPrivateObjectOwner(privateObjectOwner);

            _Create(ObjectGuid.Create(HighGuid.SceneObject, GetMapId(), sceneId, lowGuid));
            PhasingHandler.InheritPhaseShift(this, creator);

            SetEntry(scriptPackageId);
            SetObjectScale(1.0f);

            SetUpdateFieldValue(m_values.ModifyValue(m_sceneObjectData).ModifyValue(m_sceneObjectData.ScriptPackageID), (int)scriptPackageId);
            SetUpdateFieldValue(m_values.ModifyValue(m_sceneObjectData).ModifyValue(m_sceneObjectData.RndSeedVal), GameTime.GetGameTimeMS());
            SetUpdateFieldValue(m_values.ModifyValue(m_sceneObjectData).ModifyValue(m_sceneObjectData.CreatedBy), creator.GetGUID());
            SetUpdateFieldValue(m_values.ModifyValue(m_sceneObjectData).ModifyValue(m_sceneObjectData.SceneType), (uint)type);

            if (!GetMap().AddToMap(this))
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        public bool Create(ulong guidlow, uint entry, uint mapid, float x, float y, float z, float ang, uint animprogress)
        {
            Relocate(x, y, z, ang);

            if (!IsPositionValid())
            {
                Log.outError(LogFilter.Transport, "Transport (GUID: {0}) not created. Suggested coordinates isn't valid (X: {1} Y: {2})",
                             guidlow, x, y);
                return(false);
            }

            _Create(ObjectGuid.Create(HighGuid.Transport, guidlow));

            GameObjectTemplate goinfo = Global.ObjectMgr.GetGameObjectTemplate(entry);

            if (goinfo == null)
            {
                Log.outError(LogFilter.Sql, "Transport not created: entry in `gameobject_template` not found, guidlow: {0} map: {1}  (X: {2} Y: {3} Z: {4}) ang: {5}", guidlow, mapid, x, y, z, ang);
                return(false);
            }

            m_goInfo          = goinfo;
            m_goTemplateAddon = Global.ObjectMgr.GetGameObjectTemplateAddon(entry);

            TransportTemplate tInfo = Global.TransportMgr.GetTransportTemplate(entry);

            if (tInfo == null)
            {
                Log.outError(LogFilter.Sql, "Transport {0} (name: {1}) will not be created, missing `transport_template` entry.", entry, goinfo.name);
                return(false);
            }

            _transportInfo           = tInfo;
            _nextFrame               = 0;
            _currentFrame            = tInfo.keyFrames[_nextFrame++];
            _triggeredArrivalEvent   = false;
            _triggeredDepartureEvent = false;

            if (m_goTemplateAddon != null)
            {
                SetFaction(m_goTemplateAddon.faction);
                SetUInt32Value(GameObjectFields.Flags, m_goTemplateAddon.flags);
            }

            m_goValue.Transport.PathProgress = 0;
            SetFloatValue(ObjectFields.ScaleX, goinfo.size);
            SetPeriod(tInfo.pathTime);
            SetEntry(goinfo.entry);
            SetDisplayId(goinfo.displayId);
            SetGoState(goinfo.MoTransport.allowstopping == 0 ? GameObjectState.Ready : GameObjectState.Active);
            SetGoType(GameObjectTypes.MapObjTransport);
            SetGoAnimProgress(animprogress);
            SetName(goinfo.name);
            SetWorldRotation(0.0f, 0.0f, 0.0f, 1.0f);
            SetParentRotation(Quaternion.WAxis);

            m_model = CreateModel();
            return(true);
        }
Example #5
0
        public bool CreateDynamicObject(ulong guidlow, Unit caster, SpellInfo spell, Position pos, float radius, DynamicObjectType type, SpellCastVisualField spellVisual)
        {
            SetMap(caster.GetMap());
            Relocate(pos);
            if (!IsPositionValid())
            {
                Log.outError(LogFilter.Server, "DynamicObject (spell {0}) not created. Suggested coordinates isn't valid (X: {1} Y: {2})", spell.Id, GetPositionX(), GetPositionY());
                return(false);
            }

            _Create(ObjectGuid.Create(HighGuid.DynamicObject, GetMapId(), spell.Id, guidlow));
            PhasingHandler.InheritPhaseShift(this, caster);

            SetEntry(spell.Id);
            SetObjectScale(1f);

            SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.Caster), caster.GetGUID());
            SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.Type), (byte)type);

            SpellCastVisualField spellCastVisual = m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.SpellVisual);

            SetUpdateFieldValue(ref spellCastVisual.SpellXSpellVisualID, spellVisual.SpellXSpellVisualID);
            SetUpdateFieldValue(ref spellCastVisual.ScriptVisualID, spellVisual.ScriptVisualID);

            SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.SpellID), spell.Id);
            SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.Radius), radius);
            SetUpdateFieldValue(m_values.ModifyValue(m_dynamicObjectData).ModifyValue(m_dynamicObjectData.CastTime), GameTime.GetGameTimeMS());

            if (IsWorldObject())
            {
                SetActive(true);    //must before add to map to be put in world container
            }
            Transport transport = caster.GetTransport();

            if (transport)
            {
                float x, y, z, o;
                pos.GetPosition(out x, out y, out z, out o);
                transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o);
                m_movementInfo.transport.pos.Relocate(x, y, z, o);

                // This object must be added to transport before adding to map for the client to properly display it
                transport.AddPassenger(this);
            }

            if (!GetMap().AddToMap(this))
            {
                // Returning false will cause the object to be deleted - remove from transport
                if (transport)
                {
                    transport.RemovePassenger(this);
                }
                return(false);
            }

            return(true);
        }
Example #6
0
        public bool LoadCorpseFromDB(ulong guid, SQLFields field)
        {
            //        0     1     2     3            4      5          6          7       8       9      10        11    12          13          14
            // SELECT posX, posY, posZ, orientation, mapId, displayId, itemCache, bytes1, bytes2, flags, dynFlags, time, corpseType, instanceId, guid FROM corpse WHERE mapId = ? AND instanceId = ?

            float  posX  = field.Read <float>(0);
            float  posY  = field.Read <float>(1);
            float  posZ  = field.Read <float>(2);
            float  o     = field.Read <float>(3);
            ushort mapId = field.Read <ushort>(4);

            _Create(ObjectGuid.Create(HighGuid.Corpse, mapId, 0, guid));

            SetObjectScale(1.0f);
            SetDisplayId(field.Read <uint>(5));
            StringArray items = new StringArray(field.Read <string>(6), ' ');

            for (uint index = 0; index < EquipmentSlot.End; ++index)
            {
                SetItem(index, uint.Parse(items[(int)index]));
            }

            uint bytes1 = field.Read <uint>(7);
            uint bytes2 = field.Read <uint>(8);

            SetRace((Race)((bytes1 >> 8) & 0xFF));
            SetSex((Gender)((bytes1 >> 16) & 0xFF));
            SetSkin((byte)((bytes1 >> 24) & 0xFF));
            SetFace((byte)(bytes2 & 0xFF));
            SetHairStyle((byte)((bytes2 >> 8) & 0xFF));
            SetHairColor((byte)((bytes2 >> 16) & 0xFF));
            SetFacialHairStyle((byte)((bytes2 >> 24) & 0xFF));
            SetFlags((CorpseFlags)field.Read <byte>(9));
            SetCorpseDynamicFlags((CorpseDynFlags)field.Read <byte>(10));
            SetOwnerGUID(ObjectGuid.Create(HighGuid.Player, field.Read <ulong>(14)));
            SetFactionTemplate(CliDB.ChrRacesStorage.LookupByKey(m_corpseData.RaceID).FactionID);

            m_time = field.Read <uint>(11);

            uint instanceId = field.Read <uint>(13);

            // place
            SetLocationInstanceId(instanceId);
            SetMapId(mapId);
            Relocate(posX, posY, posZ, o);

            if (!IsPositionValid())
            {
                Log.outError(LogFilter.Player, "Corpse ({0}, owner: {1}) is not created, given coordinates are not valid (X: {2}, Y: {3}, Z: {4})",
                             GetGUID().ToString(), GetOwnerGUID().ToString(), posX, posY, posZ);
                return(false);
            }

            _cellCoord = GridDefines.ComputeCellCoord(GetPositionX(), GetPositionY());
            return(true);
        }
Example #7
0
        public bool CreateDynamicObject(ulong guidlow, Unit caster, SpellInfo spell, Position pos, float radius, DynamicObjectType type, uint spellXSpellVisualId)
        {
            _spellXSpellVisualId = spellXSpellVisualId;
            SetMap(caster.GetMap());
            Relocate(pos);
            if (!IsPositionValid())
            {
                Log.outError(LogFilter.Server, "DynamicObject (spell {0}) not created. Suggested coordinates isn't valid (X: {1} Y: {2})", spell.Id, GetPositionX(), GetPositionY());
                return(false);
            }

            _Create(ObjectGuid.Create(HighGuid.DynamicObject, GetMapId(), spell.Id, guidlow));
            SetPhaseMask(caster.GetPhaseMask(), false);

            SetEntry(spell.Id);
            SetObjectScale(1f);
            SetGuidValue(DynamicObjectFields.Caster, caster.GetGUID());

            SetUInt32Value(DynamicObjectFields.Type, (uint)type);
            SetUInt32Value(DynamicObjectFields.SpellXSpellVisualId, spellXSpellVisualId);
            SetUInt32Value(DynamicObjectFields.SpellId, spell.Id);
            SetFloatValue(DynamicObjectFields.Radius, radius);
            SetUInt32Value(DynamicObjectFields.CastTime, Time.GetMSTime());

            if (IsWorldObject())
            {
                setActive(true);    //must before add to map to be put in world container
            }
            Transport transport = caster.GetTransport();

            if (transport)
            {
                float x, y, z, o;
                pos.GetPosition(out x, out y, out z, out o);
                transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o);
                m_movementInfo.transport.pos.Relocate(x, y, z, o);

                // This object must be added to transport before adding to map for the client to properly display it
                transport.AddPassenger(this);
            }

            if (!GetMap().AddToMap(this))
            {
                // Returning false will cause the object to be deleted - remove from transport
                if (transport)
                {
                    transport.RemovePassenger(this);
                }
                return(false);
            }

            return(true);
        }
Example #8
0
        bool Create(ulong lowGuid, uint conversationEntry, Map map, Unit creator, Position pos, List <ObjectGuid> participants, SpellInfo spellInfo = null)
        {
            ConversationTemplate conversationTemplate = Global.ConversationDataStorage.GetConversationTemplate(conversationEntry);

            //ASSERT(conversationTemplate);

            _creatorGuid  = creator.GetGUID();
            _participants = participants;

            SetMap(map);
            Relocate(pos);

            base._Create(ObjectGuid.Create(HighGuid.Conversation, GetMapId(), conversationEntry, lowGuid));
            SetPhaseMask(creator.GetPhaseMask(), false);
            CopyPhaseFrom(creator);

            SetEntry(conversationEntry);
            SetObjectScale(1.0f);

            SetUInt32Value(ConversationFields.LastLineEndTime, conversationTemplate.LastLineEndTime);
            _duration = conversationTemplate.LastLineEndTime;

            ushort actorsIndex = 0;

            foreach (ConversationActorTemplate actor in conversationTemplate.Actors)
            {
                if (actor != null)
                {
                    ConversationDynamicFieldActor actorField = new ConversationDynamicFieldActor();
                    actorField.ActorTemplate = actor;
                    actorField.Type          = ConversationDynamicFieldActor.ActorType.CreatureActor;
                    SetDynamicStructuredValue(ConversationDynamicFields.Actors, actorsIndex++, actorField);
                }
                else
                {
                    ++actorsIndex;
                }
            }

            ushort linesIndex = 0;

            foreach (ConversationLineTemplate line in conversationTemplate.Lines)
            {
                SetDynamicStructuredValue(ConversationDynamicFields.Lines, linesIndex++, line);
            }

            if (!GetMap().AddToMap(this))
            {
                return(false);
            }

            return(true);
        }
Example #9
0
        public bool LoadCorpseFromDB(ulong guid, SQLFields field)
        {
            //        0     1     2     3            4      5          6          7       8       9      10        11    12          13          14
            // SELECT posX, posY, posZ, orientation, mapId, displayId, itemCache, bytes1, bytes2, flags, dynFlags, time, corpseType, instanceId, guid FROM corpse WHERE mapId = ? AND instanceId = ?

            float  posX  = field.Read <float>(0);
            float  posY  = field.Read <float>(1);
            float  posZ  = field.Read <float>(2);
            float  o     = field.Read <float>(3);
            ushort mapId = field.Read <ushort>(4);

            _Create(ObjectGuid.Create(HighGuid.Corpse, mapId, 0, guid));

            SetObjectScale(1.0f);
            SetUInt32Value(CorpseFields.DisplayId, field.Read <uint>(5));
            _LoadIntoDataField(field.Read <string>(6), (int)CorpseFields.Item, EquipmentSlot.End);
            SetUInt32Value(CorpseFields.Bytes1, field.Read <uint>(7));
            SetUInt32Value(CorpseFields.Bytes2, field.Read <uint>(8));
            SetUInt32Value(CorpseFields.Flags, field.Read <byte>(9));
            SetUInt32Value(CorpseFields.DynamicFlags, field.Read <byte>(10));
            SetGuidValue(CorpseFields.Owner, ObjectGuid.Create(HighGuid.Player, field.Read <ulong>(14)));
            CharacterInfo characterInfo = Global.WorldMgr.GetCharacterInfo(GetGuidValue(CorpseFields.Owner));

            if (characterInfo != null)
            {
                SetUInt32Value(CorpseFields.FactionTemplate, CliDB.ChrRacesStorage.LookupByKey(characterInfo.RaceID).FactionID);
            }

            m_time = field.Read <uint>(11);

            uint instanceId = field.Read <uint>(13);

            // place
            SetLocationInstanceId(instanceId);
            SetMapId(mapId);
            Relocate(posX, posY, posZ, o);

            if (!IsPositionValid())
            {
                Log.outError(LogFilter.Player, "Corpse ({0}, owner: {1}) is not created, given coordinates are not valid (X: {2}, Y: {3}, Z: {4})",
                             GetGUID().ToString(), GetOwnerGUID().ToString(), posX, posY, posZ);
                return(false);
            }

            _cellCoord = GridDefines.ComputeCellCoord(GetPositionX(), GetPositionY());
            return(true);
        }
Example #10
0
        public override bool Create(ulong guidlow, uint itemid, ItemContext context, Player owner)
        {
            var itemProto = Global.ObjectMgr.GetItemTemplate(itemid);

            if (itemProto == null || itemProto.GetContainerSlots() > ItemConst.MaxBagSize)
            {
                return(false);
            }

            _Create(ObjectGuid.Create(HighGuid.Item, guidlow));

            _bonusData = new BonusData(itemProto);

            SetEntry(itemid);
            SetObjectScale(1.0f);

            if (owner)
            {
                SetOwnerGUID(owner.GetGUID());
                SetContainedIn(owner.GetGUID());
            }

            SetUpdateFieldValue(m_values.ModifyValue(m_itemData).ModifyValue(m_itemData.MaxDurability), itemProto.MaxDurability);
            SetDurability(itemProto.MaxDurability);
            SetCount(1);
            SetContext(context);

            // Setting the number of Slots the Container has
            SetBagSize(itemProto.GetContainerSlots());

            // Cleaning 20 slots
            for (byte i = 0; i < ItemConst.MaxBagSize; ++i)
            {
                SetSlot(i, ObjectGuid.Empty);
            }

            m_bagslot = new Item[ItemConst.MaxBagSize];
            return(true);
        }
Example #11
0
        public PlayerSocial LoadFromDB(SQLResult result, ObjectGuid guid)
        {
            PlayerSocial social = new PlayerSocial();

            social.SetPlayerGUID(guid);

            if (!result.IsEmpty())
            {
                do
                {
                    ObjectGuid friendGuid        = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(0));
                    ObjectGuid friendAccountGuid = ObjectGuid.Create(HighGuid.WowAccount, result.Read <uint>(1));
                    SocialFlag flags             = (SocialFlag)result.Read <byte>(2);

                    social._playerSocialMap[friendGuid] = new FriendInfo(friendAccountGuid, flags, result.Read <string>(3));
                }while (result.NextRow());
            }

            _socialMap[guid] = social;

            return(social);
        }
Example #12
0
        public override bool Create(ulong guidlow, uint itemid, Player owner)
        {
            var itemProto = Global.ObjectMgr.GetItemTemplate(itemid);

            if (itemProto == null || itemProto.GetContainerSlots() > ItemConst.MaxBagSize)
            {
                return(false);
            }

            _Create(ObjectGuid.Create(HighGuid.Item, guidlow));

            _bonusData = new BonusData(itemProto);

            SetEntry(itemid);
            SetObjectScale(1.0f);

            if (owner)
            {
                SetGuidValue(ItemFields.Owner, owner.GetGUID());
                SetGuidValue(ItemFields.Contained, owner.GetGUID());
            }

            SetUInt32Value(ItemFields.MaxDurability, itemProto.MaxDurability);
            SetUInt32Value(ItemFields.Durability, itemProto.MaxDurability);
            SetUInt32Value(ItemFields.StackCount, 1);

            // Setting the number of Slots the Container has
            SetUInt32Value(ContainerFields.NumSlots, itemProto.GetContainerSlots());

            // Cleaning 20 slots
            for (byte i = 0; i < ItemConst.MaxBagSize; ++i)
            {
                SetGuidValue(ContainerFields.Slot1 + (i * 4), ObjectGuid.Empty);
            }

            m_bagslot = new Item[ItemConst.MaxBagSize];
            return(true);
        }
Example #13
0
        public void LoadPetitions()
        {
            uint oldMSTime = Time.GetMSTime();

            _petitionStorage.Clear();

            SQLResult result = DB.Characters.Query("SELECT petitionguid, ownerguid, name FROM petition");

            if (result.IsEmpty())
            {
                Log.outInfo(LogFilter.ServerLoading, "Loaded 0 petitions.");
                return;
            }

            uint count = 0;

            do
            {
                AddPetition(ObjectGuid.Create(HighGuid.Item, result.Read <ulong>(0)), ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(1)), result.Read <string>(2), true);
                ++count;
            } while (result.NextRow());

            Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} petitions in: {Time.GetMSTimeDiffToNow(oldMSTime)} ms.");
        }
Example #14
0
        public bool Create(ulong guidlow, Player owner)
        {
            Cypher.Assert(owner != null);

            Relocate(owner.GetPositionX(), owner.GetPositionY(), owner.GetPositionZ(), owner.GetOrientation());

            if (!IsPositionValid())
            {
                Log.outError(LogFilter.Player, "Corpse (guidlow {0}, owner {1}) not created. Suggested coordinates isn't valid (X: {2} Y: {3})",
                             guidlow, owner.GetName(), owner.GetPositionX(), owner.GetPositionY());
                return(false);
            }

            _Create(ObjectGuid.Create(HighGuid.Corpse, owner.GetMapId(), 0, guidlow));

            SetObjectScale(1);
            SetOwnerGUID(owner.GetGUID());

            _cellCoord = GridDefines.ComputeCellCoord(GetPositionX(), GetPositionY());

            PhasingHandler.InheritPhaseShift(this, owner);

            return(true);
        }
Example #15
0
        bool Create(uint spellMiscId, Unit caster, Unit target, SpellInfo spell, Position pos, int duration, uint spellXSpellVisualId, ObjectGuid castId, AuraEffect aurEff)
        {
            _targetGuid = target ? target.GetGUID() : ObjectGuid.Empty;
            _aurEff     = aurEff;

            SetMap(caster.GetMap());
            Relocate(pos);
            if (!IsPositionValid())
            {
                Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (spell {spell.Id}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})");
                return(false);
            }

            _areaTriggerMiscTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerMiscTemplate(spellMiscId);
            if (_areaTriggerMiscTemplate == null)
            {
                Log.outError(LogFilter.AreaTrigger, "AreaTrigger (spellMiscId {0}) not created. Invalid areatrigger miscid ({1})", spellMiscId, spellMiscId);
                return(false);
            }

            _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), GetTemplate().Id, caster.GetMap().GenerateLowGuid(HighGuid.AreaTrigger)));

            SetEntry(GetTemplate().Id);
            SetDuration(duration);

            SetObjectScale(1.0f);

            SetGuidValue(AreaTriggerFields.Caster, caster.GetGUID());
            SetGuidValue(AreaTriggerFields.CreatingEffectGuid, castId);

            SetUInt32Value(AreaTriggerFields.SpellId, spell.Id);
            SetUInt32Value(AreaTriggerFields.SpellForVisuals, spell.Id);
            SetUInt32Value(AreaTriggerFields.SpellXSpellVisualId, spellXSpellVisualId);
            SetUInt32Value(AreaTriggerFields.TimeToTargetScale, GetMiscTemplate().TimeToTargetScale != 0 ? GetMiscTemplate().TimeToTargetScale : GetUInt32Value(AreaTriggerFields.Duration));
            SetFloatValue(AreaTriggerFields.BoundsRadius2d, GetTemplate().MaxSearchRadius);
            SetUInt32Value(AreaTriggerFields.DecalPropertiesId, GetMiscTemplate().DecalPropertiesId);

            for (byte scaleCurveIndex = 0; scaleCurveIndex < SharedConst.MaxAreatriggerScale; ++scaleCurveIndex)
            {
                if (GetMiscTemplate().ScaleInfo.ExtraScale[scaleCurveIndex].AsInt32 != 0)
                {
                    SetUInt32Value(AreaTriggerFields.ExtraScaleCurve + scaleCurveIndex, (uint)GetMiscTemplate().ScaleInfo.ExtraScale[scaleCurveIndex].AsInt32);
                }
            }

            PhasingHandler.InheritPhaseShift(this, caster);

            if (target && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached))
            {
                m_movementInfo.transport.guid = target.GetGUID();
            }

            UpdateShape();

            uint timeToTarget = GetMiscTemplate().TimeToTarget != 0 ? GetMiscTemplate().TimeToTarget : GetUInt32Value(AreaTriggerFields.Duration);

            if (GetTemplate().HasFlag(AreaTriggerFlags.HasCircularMovement))
            {
                AreaTriggerCircularMovementInfo cmi = GetMiscTemplate().CircularMovementInfo;
                if (target && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached))
                {
                    cmi.TargetGUID.Set(target.GetGUID());
                }
                else
                {
                    cmi.Center.Set(new Vector3(pos.posX, pos.posY, pos.posZ));
                }

                InitCircularMovement(cmi, timeToTarget);
            }
            else if (GetMiscTemplate().HasSplines())
            {
                InitSplineOffsets(GetMiscTemplate().SplinePoints, timeToTarget);
            }

            // movement on transport of areatriggers on unit is handled by themself
            Transport transport = m_movementInfo.transport.guid.IsEmpty() ? caster.GetTransport() : null;

            if (transport)
            {
                float x, y, z, o;
                pos.GetPosition(out x, out y, out z, out o);
                transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o);
                m_movementInfo.transport.pos.Relocate(x, y, z, o);

                // This object must be added to transport before adding to map for the client to properly display it
                transport.AddPassenger(this);
            }

            AI_Initialize();

            // Relocate areatriggers with circular movement again
            if (HasCircularMovement())
            {
                Relocate(CalculateCircularMovementPosition());
            }

            if (!GetMap().AddToMap(this))
            {         // Returning false will cause the object to be deleted - remove from transport
                if (transport)
                {
                    transport.RemovePassenger(this);
                }
                return(false);
            }

            caster._RegisterAreaTrigger(this);

            _ai.OnCreate();

            return(true);
        }
Example #16
0
        bool Create(ulong lowGuid, uint conversationEntry, Map map, Unit creator, Position pos, List <ObjectGuid> participants, SpellInfo spellInfo = null)
        {
            ConversationTemplate conversationTemplate = Global.ConversationDataStorage.GetConversationTemplate(conversationEntry);

            //ASSERT(conversationTemplate);

            _creatorGuid  = creator.GetGUID();
            _participants = participants;

            SetMap(map);
            Relocate(pos);

            _Create(ObjectGuid.Create(HighGuid.Conversation, GetMapId(), conversationEntry, lowGuid));
            PhasingHandler.InheritPhaseShift(this, creator);

            SetEntry(conversationEntry);
            SetObjectScale(1.0f);

            SetUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.LastLineEndTime), conversationTemplate.LastLineEndTime);
            _duration     = conversationTemplate.LastLineEndTime;
            _textureKitId = conversationTemplate.TextureKitId;

            for (ushort actorIndex = 0; actorIndex < conversationTemplate.Actors.Count; ++actorIndex)
            {
                ConversationActorTemplate actor = conversationTemplate.Actors[actorIndex];
                if (actor != null)
                {
                    ConversationActor actorField = new ConversationActor();
                    actorField.CreatureID            = actor.CreatureId;
                    actorField.CreatureDisplayInfoID = actor.CreatureModelId;
                    actorField.Type = ConversationActorType.CreatureActor;

                    AddDynamicUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.Actors), actorField);
                }
            }

            for (ushort actorIndex = 0; actorIndex < conversationTemplate.ActorGuids.Count; ++actorIndex)
            {
                ulong actorGuid = conversationTemplate.ActorGuids[actorIndex];
                if (actorGuid == 0)
                {
                    continue;
                }

                foreach (var creature in map.GetCreatureBySpawnIdStore().LookupByKey(actorGuid))
                {
                    // we just need the last one, overriding is legit
                    AddActor(creature.GetGUID(), actorIndex);
                }
            }

            Global.ScriptMgr.OnConversationCreate(this, creator);

            List <ushort>           actorIndices = new List <ushort>();
            List <ConversationLine> lines        = new List <ConversationLine>();

            foreach (ConversationLineTemplate line in conversationTemplate.Lines)
            {
                actorIndices.Add(line.ActorIdx);

                ConversationLine lineField = new ConversationLine();
                lineField.ConversationLineID = line.Id;
                lineField.StartTime          = line.StartTime;
                lineField.UiCameraID         = line.UiCameraID;
                lineField.ActorIndex         = line.ActorIdx;
                lineField.Flags = line.Flags;

                lines.Add(lineField);
            }

            SetUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.Lines), lines);

            Global.ScriptMgr.OnConversationCreate(this, creator);

            // All actors need to be set
            foreach (ushort actorIndex in actorIndices)
            {
                ConversationActor actor = actorIndex < m_conversationData.Actors.Size() ? m_conversationData.Actors[actorIndex] : null;
                if (actor == null || (actor.CreatureID == 0 && actor.ActorGUID.IsEmpty()))
                {
                    Log.outError(LogFilter.Conversation, $"Failed to create conversation (Id: {conversationEntry}) due to missing actor (Idx: {actorIndex}).");
                    return(false);
                }
            }

            if (!GetMap().AddToMap(this))
            {
                return(false);
            }

            return(true);
        }
Example #17
0
        bool Create(uint spellMiscId, Unit caster, Unit target, SpellInfo spell, Position pos, int duration, SpellCastVisualField spellVisual, ObjectGuid castId, AuraEffect aurEff)
        {
            _targetGuid = target ? target.GetGUID() : ObjectGuid.Empty;
            _aurEff     = aurEff;

            SetMap(caster.GetMap());
            Relocate(pos);
            if (!IsPositionValid())
            {
                Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (spell {spell.Id}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})");
                return(false);
            }

            _areaTriggerMiscTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerMiscTemplate(spellMiscId);
            if (_areaTriggerMiscTemplate == null)
            {
                Log.outError(LogFilter.AreaTrigger, "AreaTrigger (spellMiscId {0}) not created. Invalid areatrigger miscid ({1})", spellMiscId, spellMiscId);
                return(false);
            }

            _areaTriggerTemplate = _areaTriggerMiscTemplate.Template;

            _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), GetTemplate().Id.Id, caster.GetMap().GenerateLowGuid(HighGuid.AreaTrigger)));

            SetEntry(GetTemplate().Id.Id);
            SetDuration(duration);

            SetObjectScale(1.0f);

            SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.Caster), caster.GetGUID());
            SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.CreatingEffectGUID), castId);

            SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.SpellID), spell.Id);
            SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.SpellForVisuals), spell.Id);

            SpellCastVisualField spellCastVisual = m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.SpellVisual);

            SetUpdateFieldValue(ref spellCastVisual.SpellXSpellVisualID, spellVisual.SpellXSpellVisualID);
            SetUpdateFieldValue(ref spellCastVisual.ScriptVisualID, spellVisual.ScriptVisualID);

            SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.TimeToTargetScale), GetMiscTemplate().TimeToTargetScale != 0 ? GetMiscTemplate().TimeToTargetScale : m_areaTriggerData.Duration);
            SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.BoundsRadius2D), GetTemplate().MaxSearchRadius);
            SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.DecalPropertiesID), GetMiscTemplate().DecalPropertiesId);

            ScaleCurve extraScaleCurve = m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.ExtraScaleCurve);

            if (GetMiscTemplate().ExtraScale.Structured.StartTimeOffset != 0)
            {
                SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.StartTimeOffset), GetMiscTemplate().ExtraScale.Structured.StartTimeOffset);
            }
            if (GetMiscTemplate().ExtraScale.Structured.X != 0 || GetMiscTemplate().ExtraScale.Structured.Y != 0)
            {
                Vector2 point = new(GetMiscTemplate().ExtraScale.Structured.X, GetMiscTemplate().ExtraScale.Structured.Y);
                SetUpdateFieldValue(ref extraScaleCurve.ModifyValue(extraScaleCurve.Points, 0), point);
            }
            if (GetMiscTemplate().ExtraScale.Structured.Z != 0 || GetMiscTemplate().ExtraScale.Structured.W != 0)
            {
                Vector2 point = new(GetMiscTemplate().ExtraScale.Structured.Z, GetMiscTemplate().ExtraScale.Structured.W);
                SetUpdateFieldValue(ref extraScaleCurve.ModifyValue(extraScaleCurve.Points, 1), point);
            }
            unsafe
            {
                if (GetMiscTemplate().ExtraScale.Raw.Data[5] != 0)
                {
                    SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.ParameterCurve), GetMiscTemplate().ExtraScale.Raw.Data[5]);
                }
                if (GetMiscTemplate().ExtraScale.Structured.OverrideActive != 0)
                {
                    SetUpdateFieldValue(extraScaleCurve.ModifyValue(extraScaleCurve.OverrideActive), GetMiscTemplate().ExtraScale.Structured.OverrideActive != 0 ? true : false);
                }
            }


            PhasingHandler.InheritPhaseShift(this, caster);

            if (target && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached))
            {
                m_movementInfo.transport.guid = target.GetGUID();
            }

            UpdateShape();

            uint timeToTarget = GetMiscTemplate().TimeToTarget != 0 ? GetMiscTemplate().TimeToTarget : m_areaTriggerData.Duration;

            if (GetTemplate().HasFlag(AreaTriggerFlags.HasCircularMovement))
            {
                AreaTriggerOrbitInfo cmi = GetMiscTemplate().OrbitInfo;
                if (target && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached))
                {
                    cmi.PathTarget.Set(target.GetGUID());
                }
                else
                {
                    cmi.Center.Set(new Vector3(pos.posX, pos.posY, pos.posZ));
                }

                InitOrbit(cmi, timeToTarget);
            }
            else if (GetMiscTemplate().HasSplines())
            {
                InitSplineOffsets(GetMiscTemplate().SplinePoints, timeToTarget);
            }

            // movement on transport of areatriggers on unit is handled by themself
            Transport transport = m_movementInfo.transport.guid.IsEmpty() ? caster.GetTransport() : null;

            if (transport)
            {
                float x, y, z, o;
                pos.GetPosition(out x, out y, out z, out o);
                transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o);
                m_movementInfo.transport.pos.Relocate(x, y, z, o);

                // This object must be added to transport before adding to map for the client to properly display it
                transport.AddPassenger(this);
            }

            AI_Initialize();

            // Relocate areatriggers with circular movement again
            if (HasOrbit())
            {
                Relocate(CalculateOrbitPosition());
            }

            if (!GetMap().AddToMap(this))
            {         // Returning false will cause the object to be deleted - remove from transport
                if (transport)
                {
                    transport.RemovePassenger(this);
                }
                return(false);
            }

            caster._RegisterAreaTrigger(this);

            _ai.OnCreate();

            return(true);
        }
Example #18
0
 public static ObjectGuid CreateNewMovementForceId(Map map, uint areaTriggerId)
 {
     return(ObjectGuid.Create(HighGuid.AreaTrigger, map.GetId(), areaTriggerId, map.GenerateLowGuid(HighGuid.AreaTrigger)));
 }
Example #19
0
 public bool Create(ulong guidlow, Map map)
 {
     _Create(ObjectGuid.Create(HighGuid.Corpse, map.GetId(), 0, guidlow));
     return(true);
 }
Example #20
0
        bool Create(ulong lowGuid, uint conversationEntry, Map map, Unit creator, Position pos, List <ObjectGuid> participants, SpellInfo spellInfo = null)
        {
            ConversationTemplate conversationTemplate = Global.ConversationDataStorage.GetConversationTemplate(conversationEntry);

            //ASSERT(conversationTemplate);

            _creatorGuid  = creator.GetGUID();
            _participants = participants;

            SetMap(map);
            Relocate(pos);

            base._Create(ObjectGuid.Create(HighGuid.Conversation, GetMapId(), conversationEntry, lowGuid));
            CopyPhaseFrom(creator);

            SetEntry(conversationEntry);
            SetObjectScale(1.0f);

            SetUInt32Value(ConversationFields.LastLineEndTime, conversationTemplate.LastLineEndTime);
            _duration = conversationTemplate.LastLineEndTime;

            for (ushort actorIndex = 0; actorIndex < conversationTemplate.Actors.Count; ++actorIndex)
            {
                ConversationActorTemplate actor = conversationTemplate.Actors[actorIndex];
                if (actor != null)
                {
                    ConversationDynamicFieldActor actorField = new ConversationDynamicFieldActor();
                    actorField.ActorTemplate = actor;
                    actorField.Type          = ConversationDynamicFieldActor.ActorType.CreatureActor;
                    SetDynamicStructuredValue(ConversationDynamicFields.Actors, actorIndex, actorField);
                }
            }

            for (ushort actorIndex = 0; actorIndex < conversationTemplate.ActorGuids.Count; ++actorIndex)
            {
                ulong actorGuid = conversationTemplate.ActorGuids[actorIndex];
                if (actorGuid == 0)
                {
                    continue;
                }

                foreach (var creature in map.GetCreatureBySpawnIdStore().LookupByKey(actorGuid))
                {
                    // we just need the last one, overriding is legit
                    AddActor(creature.GetGUID(), actorIndex);
                }
            }

            Global.ScriptMgr.OnConversationCreate(this, creator);

            List <ushort> actorIndices = new List <ushort>();

            foreach (ConversationLineTemplate line in conversationTemplate.Lines)
            {
                actorIndices.Add(line.ActorIdx);
                AddDynamicStructuredValue(ConversationDynamicFields.Lines, line);
            }

            // All actors need to be set
            foreach (ushort actorIndex in actorIndices)
            {
                ConversationDynamicFieldActor actor = GetDynamicStructuredValue <ConversationDynamicFieldActor>(ConversationDynamicFields.Actors, actorIndex);
                if (actor == null || actor.IsEmpty())
                {
                    Log.outError(LogFilter.Conversation, $"Failed to create conversation (Id: {conversationEntry}) due to missing actor (Idx: {actorIndex}).");
                    return(false);
                }
            }

            if (!GetMap().AddToMap(this))
            {
                return(false);
            }

            return(true);
        }
Example #21
0
        bool Create(ulong lowGuid, uint conversationEntry, Map map, Unit creator, Position pos, ObjectGuid privateObjectOwner, SpellInfo spellInfo = null)
        {
            ConversationTemplate conversationTemplate = Global.ConversationDataStorage.GetConversationTemplate(conversationEntry);

            //ASSERT(conversationTemplate);

            _creatorGuid = creator.GetGUID();
            SetPrivateObjectOwner(privateObjectOwner);

            SetMap(map);
            Relocate(pos);
            RelocateStationaryPosition(pos);

            _Create(ObjectGuid.Create(HighGuid.Conversation, GetMapId(), conversationEntry, lowGuid));
            PhasingHandler.InheritPhaseShift(this, creator);

            SetEntry(conversationEntry);
            SetObjectScale(1.0f);

            _textureKitId = conversationTemplate.TextureKitId;

            if (conversationTemplate.Actors != null)
            {
                foreach (var actor in conversationTemplate.Actors)
                {
                    if (actor != null)
                    {
                        ConversationActorField actorField = new();
                        actorField.CreatureID            = actor.CreatureId;
                        actorField.CreatureDisplayInfoID = actor.CreatureDisplayInfoId;
                        actorField.Id   = (int)actor.ActorId;
                        actorField.Type = ConversationActorType.CreatureActor;

                        AddDynamicUpdateFieldValue(m_values.ModifyValue(m_conversationData).ModifyValue(m_conversationData.Actors), actorField);
                    }
                }
            }

            if (conversationTemplate.ActorGuids != null)
            {
                for (ushort actorIndex = 0; actorIndex < conversationTemplate.ActorGuids.Count; ++actorIndex)
                {
                    ulong actorGuid = conversationTemplate.ActorGuids[actorIndex];
                    if (actorGuid == 0)
                    {
                        continue;
                    }

                    foreach (var creature in map.GetCreatureBySpawnIdStore().LookupByKey(actorGuid))
                    {
                        // we just need the last one, overriding is legit
                        AddActor(creature.GetGUID(), actorIndex);
                    }
                }
            }

            Global.ScriptMgr.OnConversationCreate(this, creator);

            List <ushort>           actorIndices = new();
            List <ConversationLine> lines        = new();

            foreach (ConversationLineTemplate line in conversationTemplate.Lines)
            {
                if (!Global.ConditionMgr.IsObjectMeetingNotGroupedConditions(ConditionSourceType.ConversationLine, line.Id, creator))
                {
                    continue;
                }

                actorIndices.Add(line.ActorIdx);

                ConversationLine lineField = new();
                lineField.ConversationLineID = line.Id;
                lineField.UiCameraID         = line.UiCameraID;
                lineField.ActorIndex         = line.ActorIdx;
                lineField.Flags = line.Flags;

                ConversationLineRecord convoLine = CliDB.ConversationLineStorage.LookupByKey(line.Id); // never null for conversationTemplate->Lines

                for (Locale locale = Locale.enUS; locale < Locale.Total; locale = locale + 1)
                {
                    if (locale == Locale.None)
                    {
                        continue;
                    }

                    _lineStartTimes[(locale, line.Id)] = _lastLineEndTimes[(int)locale];