Ejemplo n.º 1
0
        bool InitTamedPet(Pet pet, uint level, uint spell_id)
        {
            pet.SetCreatorGUID(GetGUID());
            pet.SetFaction(GetFaction());
            pet.SetCreatedBySpell(spell_id);

            if (IsTypeId(TypeId.Player))
            {
                pet.AddUnitFlag(UnitFlags.PvpAttackable);
            }

            if (!pet.InitStatsForLevel(level))
            {
                Log.outError(LogFilter.Unit, "Pet:InitStatsForLevel() failed for creature (Entry: {0})!", pet.GetEntry());
                return(false);
            }

            PhasingHandler.InheritPhaseShift(pet, this);

            pet.GetCharmInfo().SetPetNumber(Global.ObjectMgr.GeneratePetNumber(), true);
            // this enables pet details window (Shift+P)
            pet.InitPetCreateSpells();
            pet.SetFullHealth();
            return(true);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public TempSummon SummonPassenger(uint entry, Position pos, TempSummonType summonType, SummonPropertiesRecord properties = null, uint duration = 0, Unit summoner = null, uint spellId = 0, uint vehId = 0)
        {
            Map map = GetMap();

            if (map == null)
            {
                return(null);
            }

            UnitTypeMask mask = UnitTypeMask.Summon;

            if (properties != null)
            {
                switch (properties.Control)
                {
                case SummonCategory.Pet:
                    mask = UnitTypeMask.Guardian;
                    break;

                case SummonCategory.Puppet:
                    mask = UnitTypeMask.Puppet;
                    break;

                case SummonCategory.Vehicle:
                    mask = UnitTypeMask.Minion;
                    break;

                case SummonCategory.Wild:
                case SummonCategory.Ally:
                case SummonCategory.Unk:
                {
                    switch (properties.Title)
                    {
                    case SummonType.Minion:
                    case SummonType.Guardian:
                    case SummonType.Guardian2:
                        mask = UnitTypeMask.Guardian;
                        break;

                    case SummonType.Totem:
                    case SummonType.LightWell:
                        mask = UnitTypeMask.Totem;
                        break;

                    case SummonType.Vehicle:
                    case SummonType.Vehicle2:
                        mask = UnitTypeMask.Summon;
                        break;

                    case SummonType.Minipet:
                        mask = UnitTypeMask.Minion;
                        break;

                    default:
                        if (properties.Flags.HasAnyFlag(SummonPropFlags.Unk10))             // Mirror Image, Summon Gargoyle
                        {
                            mask = UnitTypeMask.Guardian;
                        }
                        break;
                    }
                    break;
                }

                default:
                    return(null);
                }
            }

            TempSummon summon = null;

            switch (mask)
            {
            case UnitTypeMask.Summon:
                summon = new TempSummon(properties, summoner, false);
                break;

            case UnitTypeMask.Guardian:
                summon = new Guardian(properties, summoner, false);
                break;

            case UnitTypeMask.Puppet:
                summon = new Puppet(properties, summoner);
                break;

            case UnitTypeMask.Totem:
                summon = new Totem(properties, summoner);
                break;

            case UnitTypeMask.Minion:
                summon = new Minion(properties, summoner, false);
                break;
            }

            float x, y, z, o;

            pos.GetPosition(out x, out y, out z, out o);
            CalculatePassengerPosition(ref x, ref y, ref z, ref o);

            if (!summon.Create(map.GenerateLowGuid(HighGuid.Creature), map, entry, x, y, z, o, null, vehId))
            {
                return(null);
            }

            PhasingHandler.InheritPhaseShift(summon, summoner ? (WorldObject)summoner : this);

            summon.SetUInt32Value(UnitFields.CreatedBySpell, spellId);

            summon.SetTransport(this);
            summon.m_movementInfo.transport.guid = GetGUID();
            summon.m_movementInfo.transport.pos.Relocate(pos);
            summon.Relocate(x, y, z, o);
            summon.SetHomePosition(x, y, z, o);
            summon.SetTransportHomePosition(pos);

            // @HACK - transport models are not added to map's dynamic LoS calculations
            //         because the current GameObjectModel cannot be moved without recreating
            summon.AddUnitState(UnitState.IgnorePathfinding);

            summon.InitStats(duration);

            if (!map.AddToMap(summon))
            {
                return(null);
            }

            _staticPassengers.Add(summon);

            summon.InitSummon();
            summon.SetTempSummonType(summonType);

            return(summon);
        }
Ejemplo n.º 6
0
        static bool HandleWpShowCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            // first arg: on, off, first, last
            string show = args.NextString();

            if (string.IsNullOrEmpty(show))
            {
                return(false);
            }

            // second arg: GUID (optional, if a creature is selected)
            string guid_str = args.NextString();

            uint     pathid;
            Creature target = handler.GetSelectedCreature();

            // Did player provide a PathID?

            if (string.IsNullOrEmpty(guid_str))
            {
                // No PathID provided
                // . Player must have selected a creature

                if (!target)
                {
                    handler.SendSysMessage(CypherStrings.SelectCreature);
                    return(false);
                }

                pathid = target.GetWaypointPath();
            }
            else
            {
                // PathID provided
                // Warn if player also selected a creature
                // . Creature selection is ignored <-
                if (target)
                {
                    handler.SendSysMessage(CypherStrings.WaypointCreatselected);
                }

                if (!uint.TryParse(guid_str, out pathid))
                {
                    return(false);
                }
            }

            // Show info for the selected waypoint
            if (show == "info")
            {
                // Check if the user did specify a visual waypoint
                if (!target || target.GetEntry() != 1)
                {
                    handler.SendSysMessage(CypherStrings.WaypointVpSelect);
                    return(false);
                }

                PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_ALL_BY_WPGUID);
                stmt.AddValue(0, target.GetSpawnId());
                SQLResult result = DB.World.Query(stmt);

                if (result.IsEmpty())
                {
                    handler.SendSysMessage(CypherStrings.WaypointNotfounddbproblem, target.GetSpawnId());
                    return(true);
                }

                handler.SendSysMessage("|cff00ffffDEBUG: wp show info:|r");
                do
                {
                    pathid = result.Read <uint>(0);
                    uint point     = result.Read <uint>(1);
                    uint delay     = result.Read <uint>(2);
                    uint flag      = result.Read <uint>(3);
                    uint ev_id     = result.Read <uint>(4);
                    uint ev_chance = result.Read <uint>(5);

                    handler.SendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff{0}|r|cff00ff00, Path ID: |r|cff00ffff{1}|r", point, pathid);
                    handler.SendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff{0}|r", delay);
                    handler.SendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff{0}|r", flag);
                    handler.SendSysMessage("|cff00ff00Show info: Waypoint event: |r|cff00ffff{0}|r", ev_id);
                    handler.SendSysMessage("|cff00ff00Show info: Event chance: |r|cff00ffff{0}|r", ev_chance);
                }while (result.NextRow());

                return(true);
            }

            if (show == "on")
            {
                PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_BY_ID);
                stmt.AddValue(0, pathid);
                SQLResult result = DB.World.Query(stmt);

                if (result.IsEmpty())
                {
                    handler.SendSysMessage("|cffff33ffPath no found.|r");
                    return(false);
                }

                handler.SendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff{0}|r", pathid);

                // Delete all visuals for this NPC
                stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_WPGUID_BY_ID);
                stmt.AddValue(0, pathid);
                SQLResult result2 = DB.World.Query(stmt);

                if (!result2.IsEmpty())
                {
                    bool hasError = false;
                    do
                    {
                        ulong wpguid = result2.Read <ulong>(0);

                        Creature creature = handler.GetCreatureFromPlayerMapByDbGuid(wpguid);
                        if (!creature)
                        {
                            handler.SendSysMessage(CypherStrings.WaypointNotremoved, wpguid);
                            hasError = true;

                            stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_CREATURE);
                            stmt.AddValue(0, wpguid);
                            DB.World.Execute(stmt);
                        }
                        else
                        {
                            creature.CombatStop();
                            creature.DeleteFromDB();
                            creature.AddObjectToRemoveList();
                        }
                    }while (result2.NextRow());

                    if (hasError)
                    {
                        handler.SendSysMessage(CypherStrings.WaypointToofar1);
                        handler.SendSysMessage(CypherStrings.WaypointToofar2);
                        handler.SendSysMessage(CypherStrings.WaypointToofar3);
                    }
                }

                do
                {
                    uint  point = result.Read <uint>(0);
                    float x     = result.Read <float>(1);
                    float y     = result.Read <float>(2);
                    float z     = result.Read <float>(3);

                    uint id = 1;

                    Player   chr = handler.GetSession().GetPlayer();
                    Map      map = chr.GetMap();
                    Position pos = new Position(x, y, z, chr.GetOrientation());

                    Creature creature = Creature.CreateCreature(id, map, pos);
                    if (!creature)
                    {
                        handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id);
                        return(false);
                    }

                    PhasingHandler.InheritPhaseShift(creature, chr);
                    creature.SaveToDB(map.GetId(), new List <Difficulty>()
                    {
                        map.GetDifficultyID()
                    });

                    ulong dbGuid = creature.GetSpawnId();

                    // current "wpCreature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
                    creature.CleanupsBeforeDelete();
                    creature.Dispose();

                    // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
                    creature = Creature.CreateCreatureFromDB(dbGuid, map);
                    if (!creature)
                    {
                        handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id);
                        return(false);
                    }

                    if (target)
                    {
                        creature.SetDisplayId(target.GetDisplayId());
                        creature.SetObjectScale(0.5f);
                        creature.SetLevel(Math.Min(point, SharedConst.StrongMaxLevel));
                    }

                    // Set "wpguid" column to the visual waypoint
                    stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_WPGUID);
                    stmt.AddValue(0, creature.GetSpawnId());
                    stmt.AddValue(1, pathid);
                    stmt.AddValue(2, point);
                    DB.World.Execute(stmt);
                }while (result.NextRow());

                handler.SendSysMessage("|cff00ff00Showing the current creature's path.|r");
                return(true);
            }

            if (show == "first")
            {
                handler.SendSysMessage("|cff00ff00DEBUG: wp first, pathid: {0}|r", pathid);

                PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_FIRST_BY_ID);
                stmt.AddValue(0, pathid);
                SQLResult result = DB.World.Query(stmt);

                if (result.IsEmpty())
                {
                    handler.SendSysMessage(CypherStrings.WaypointNotfound, pathid);
                    return(false);
                }

                float x = result.Read <float>(0);
                float y = result.Read <float>(1);
                float z = result.Read <float>(2);

                Player   chr = handler.GetSession().GetPlayer();
                Map      map = chr.GetMap();
                Position pos = new Position(x, y, z, chr.GetOrientation());

                Creature creature = Creature.CreateCreature(1, map, pos);
                if (!creature)
                {
                    handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
                    return(false);
                }

                PhasingHandler.InheritPhaseShift(creature, chr);
                creature.SaveToDB(map.GetId(), new List <Difficulty>()
                {
                    map.GetDifficultyID()
                });

                ulong dbGuid = creature.GetSpawnId();

                // current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
                creature.CleanupsBeforeDelete();
                creature.Dispose();

                creature = Creature.CreateCreatureFromDB(dbGuid, map);
                if (!creature)
                {
                    handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
                    return(false);
                }

                if (target)
                {
                    creature.SetDisplayId(target.GetDisplayId());
                    creature.SetObjectScale(0.5f);
                }

                return(true);
            }

            if (show == "last")
            {
                handler.SendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff{0}|r", pathid);

                PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_LAST_BY_ID);
                stmt.AddValue(0, pathid);
                SQLResult result = DB.World.Query(stmt);

                if (result.IsEmpty())
                {
                    handler.SendSysMessage(CypherStrings.WaypointNotfoundlast, pathid);
                    return(false);
                }

                float x = result.Read <float>(0);
                float y = result.Read <float>(1);
                float z = result.Read <float>(2);
                float o = result.Read <float>(3);

                Player   chr = handler.GetSession().GetPlayer();
                Map      map = chr.GetMap();
                Position pos = new Position(x, y, z, o);

                Creature creature = Creature.CreateCreature(1, map, pos);
                if (!creature)
                {
                    handler.SendSysMessage(CypherStrings.WaypointNotcreated, 1);
                    return(false);
                }

                PhasingHandler.InheritPhaseShift(creature, chr);
                creature.SaveToDB(map.GetId(), new List <Difficulty>()
                {
                    map.GetDifficultyID()
                });

                ulong dbGuid = creature.GetSpawnId();

                // current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
                creature.CleanupsBeforeDelete();
                creature.Dispose();

                creature = Creature.CreateCreatureFromDB(dbGuid, map);
                if (!creature)
                {
                    handler.SendSysMessage(CypherStrings.WaypointNotcreated, 1);
                    return(false);
                }

                if (target)
                {
                    creature.SetDisplayId(target.GetDisplayId());
                    creature.SetObjectScale(0.5f);
                }

                return(true);
            }

            if (show == "off")
            {
                PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_CREATURE_BY_ID);
                stmt.AddValue(0, 1);
                SQLResult result = DB.World.Query(stmt);

                if (result.IsEmpty())
                {
                    handler.SendSysMessage(CypherStrings.WaypointVpNotfound);
                    return(false);
                }
                bool hasError = false;
                do
                {
                    ulong lowguid = result.Read <ulong>(0);

                    Creature creature = handler.GetCreatureFromPlayerMapByDbGuid(lowguid);
                    if (!creature)
                    {
                        handler.SendSysMessage(CypherStrings.WaypointNotremoved, lowguid);
                        hasError = true;

                        stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_CREATURE);
                        stmt.AddValue(0, lowguid);
                        DB.World.Execute(stmt);
                    }
                    else
                    {
                        creature.CombatStop();
                        creature.DeleteFromDB();
                        creature.AddObjectToRemoveList();
                    }
                }while (result.NextRow());
                // set "wpguid" column to "empty" - no visual waypoint spawned
                stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_ALL_WPGUID);

                DB.World.Execute(stmt);
                //DB.World.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");

                if (hasError)
                {
                    handler.SendSysMessage(CypherStrings.WaypointToofar1);
                    handler.SendSysMessage(CypherStrings.WaypointToofar2);
                    handler.SendSysMessage(CypherStrings.WaypointToofar3);
                }

                handler.SendSysMessage(CypherStrings.WaypointVpAllremoved);
                return(true);
            }

            handler.SendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r");
            return(true);
        }
Ejemplo n.º 7
0
        static bool HandleWpModifyCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            // first arg: add del text emote spell waittime move
            string show = args.NextString();

            if (string.IsNullOrEmpty(show))
            {
                return(false);
            }

            // Check
            // Remember: "show" must also be the name of a column!
            if ((show != "delay") && (show != "action") && (show != "action_chance") &&
                (show != "move_flag") && (show != "del") && (show != "move"))
            {
                return(false);
            }

            // Did user provide a GUID
            // or did the user select a creature?
            // . variable lowguid is filled with the GUID of the NPC
            uint     pathid;
            uint     point;
            Creature target = handler.GetSelectedCreature();

            // User did select a visual waypoint?
            if (!target || target.GetEntry() != 1)
            {
                handler.SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
                return(false);
            }

            // Check the creature
            PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_WPGUID);

            stmt.AddValue(0, target.GetSpawnId());
            SQLResult result = DB.World.Query(stmt);

            if (result.IsEmpty())
            {
                handler.SendSysMessage(CypherStrings.WaypointNotfoundsearch, target.GetGUID().ToString());
                // Select waypoint number from database
                // Since we compare float values, we have to deal with
                // some difficulties.
                // Here we search for all waypoints that only differ in one from 1 thousand
                // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
                string maxDiff = "0.01";

                stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_POS);
                stmt.AddValue(0, target.GetPositionX());
                stmt.AddValue(1, maxDiff);
                stmt.AddValue(2, target.GetPositionY());
                stmt.AddValue(3, maxDiff);
                stmt.AddValue(4, target.GetPositionZ());
                stmt.AddValue(5, maxDiff);
                result = DB.World.Query(stmt);

                if (result.IsEmpty())
                {
                    handler.SendSysMessage(CypherStrings.WaypointNotfounddbproblem, target.GetGUID().ToString());
                    return(true);
                }
            }

            do
            {
                pathid = result.Read <uint>(0);
                point  = result.Read <uint>(1);
            }while (result.NextRow());

            // We have the waypoint number and the GUID of the "master npc"
            // Text is enclosed in "<>", all other arguments not
            string arg_str = args.NextString();

            // Check for argument
            if (show != "del" && show != "move" && arg_str == null)
            {
                handler.SendSysMessage(CypherStrings.WaypointArgumentreq, show);
                return(false);
            }

            if (show == "del")
            {
                handler.SendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff{0}|r", pathid);

                target.DeleteFromDB();
                target.AddObjectToRemoveList();

                stmt = DB.World.GetPreparedStatement(WorldStatements.DEL_WAYPOINT_DATA);
                stmt.AddValue(0, pathid);
                stmt.AddValue(1, point);
                DB.World.Execute(stmt);

                stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_POINT);
                stmt.AddValue(0, pathid);
                stmt.AddValue(1, point);
                DB.World.Execute(stmt);

                handler.SendSysMessage(CypherStrings.WaypointRemoved);
                return(true);
            }                                                       // del

            if (show == "move")
            {
                handler.SendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff{0}|r", pathid);

                Player chr = handler.GetSession().GetPlayer();
                Map    map = chr.GetMap();
                // What to do:
                // Move the visual spawnpoint
                // Respawn the owner of the waypoints
                target.DeleteFromDB();
                target.AddObjectToRemoveList();

                // re-create
                Creature creature = Creature.CreateCreature(1, map, chr.GetPosition());
                if (!creature)
                {
                    handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
                    return(false);
                }

                PhasingHandler.InheritPhaseShift(creature, chr);
                creature.SaveToDB(map.GetId(), new List <Difficulty>()
                {
                    map.GetDifficultyID()
                });

                ulong dbGuid = creature.GetSpawnId();

                // current "wpCreature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
                creature.CleanupsBeforeDelete();
                creature.Dispose();

                // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
                creature = Creature.CreateCreatureFromDB(dbGuid, map);
                if (!creature)
                {
                    handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
                    return(false);
                }

                stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_POSITION);
                stmt.AddValue(0, chr.GetPositionX());
                stmt.AddValue(1, chr.GetPositionY());
                stmt.AddValue(2, chr.GetPositionZ());
                stmt.AddValue(3, pathid);
                stmt.AddValue(4, point);
                DB.World.Execute(stmt);

                handler.SendSysMessage(CypherStrings.WaypointChanged);

                return(true);
            }                                                     // move

            if (string.IsNullOrEmpty(arg_str))
            {
                // show_str check for present in list of correct values, no sql injection possible
                DB.World.Execute("UPDATE waypoint_data SET {0}=null WHERE id='{1}' AND point='{2}'", show, pathid, point); // Query can't be a prepared statement
            }
            else
            {
                // show_str check for present in list of correct values, no sql injection possible
                DB.World.Execute("UPDATE waypoint_data SET {0}='{1}' WHERE id='{2}' AND point='{3}'", show, arg_str, pathid, point); // Query can't be a prepared statement
            }

            handler.SendSysMessage(CypherStrings.WaypointChangedNo, show);
            return(true);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
            static bool HandleGameObjectAddCommand(StringArguments args, CommandHandler handler)
            {
                if (args.Empty())
                {
                    return(false);
                }

                // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
                string idStr = handler.extractKeyFromLink(args, "Hgameobject_entry");

                if (string.IsNullOrEmpty(idStr))
                {
                    return(false);
                }

                if (!uint.TryParse(idStr, out uint objectId) || objectId == 0)
                {
                    return(false);
                }

                uint spawntimeSecs = args.NextUInt32();

                GameObjectTemplate objectInfo = Global.ObjectMgr.GetGameObjectTemplate(objectId);

                if (objectInfo == null)
                {
                    handler.SendSysMessage(CypherStrings.GameobjectNotExist, objectId);
                    return(false);
                }

                if (objectInfo.displayId != 0 && !CliDB.GameObjectDisplayInfoStorage.ContainsKey(objectInfo.displayId))
                {
                    // report to DB errors log as in loading case
                    Log.outError(LogFilter.Sql, "Gameobject (Entry {0} GoType: {1}) have invalid displayId ({2}), not spawned.", objectId, objectInfo.type, objectInfo.displayId);
                    handler.SendSysMessage(CypherStrings.GameobjectHaveInvalidData, objectId);
                    return(false);
                }

                Player player = handler.GetPlayer();
                Map    map    = player.GetMap();

                GameObject obj = GameObject.CreateGameObject(objectInfo.entry, map, player, Quaternion.fromEulerAnglesZYX(player.GetOrientation(), 0.0f, 0.0f), 255, GameObjectState.Ready);

                if (!obj)
                {
                    return(false);
                }

                PhasingHandler.InheritPhaseShift(obj, player);

                if (spawntimeSecs != 0)
                {
                    obj.SetRespawnTime((int)spawntimeSecs);
                }

                // fill the gameobject data and save to the db
                obj.SaveToDB(map.GetId(), new List <Difficulty>()
                {
                    map.GetDifficultyID()
                });
                ulong spawnId = obj.GetSpawnId();

                // this will generate a new guid if the object is in an instance
                obj = GameObject.CreateGameObjectFromDB(spawnId, map);
                if (!obj)
                {
                    return(false);
                }

                // TODO: is it really necessary to add both the real and DB table guid here ?
                Global.ObjectMgr.AddGameObjectToGrid(spawnId, Global.ObjectMgr.GetGOData(spawnId));
                handler.SendSysMessage(CypherStrings.GameobjectAdd, objectId, objectInfo.name, spawnId, player.GetPositionX(), player.GetPositionY(), player.GetPositionZ());
                return(true);
            }
Ejemplo n.º 12
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];
Ejemplo n.º 13
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));
            PhasingHandler.InheritPhaseShift(this, 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);
        }