Ejemplo n.º 1
0
        void FillPointMovementListForCreature()
        {
            WaypointPath path = Global.WaypointMgr.GetPath(me.GetEntry());

            if (path == null)
            {
                return;
            }

            foreach (WaypointNode value in path.nodes)
            {
                WaypointNode node = value;
                GridDefines.NormalizeMapCoord(ref node.x);
                GridDefines.NormalizeMapCoord(ref node.y);
                node.moveType = _running ? WaypointMoveType.Run : WaypointMoveType.Walk;

                _path.nodes.Add(node);
            }
        }
Ejemplo n.º 2
0
        static bool HandleGoAreaTriggerCommand(StringArguments args, CommandHandler handler)
        {
            Player player = handler.GetSession().GetPlayer();

            if (args.Empty())
            {
                return(false);
            }

            uint areaTriggerId = args.NextUInt32();

            if (areaTriggerId == 0)
            {
                return(false);
            }

            AreaTriggerRecord at = CliDB.AreaTriggerStorage.LookupByKey(areaTriggerId);

            if (at == null)
            {
                handler.SendSysMessage(CypherStrings.CommandGoareatrnotfound, areaTriggerId);
                return(false);
            }

            if (!GridDefines.IsValidMapCoord(at.ContinentID, at.Pos.X, at.Pos.Y, at.Pos.Z))
            {
                handler.SendSysMessage(CypherStrings.InvalidTargetCoord, at.Pos.X, at.Pos.Y, at.ContinentID);
                return(false);
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.FinishTaxiFlight();
            }
            else
            {
                player.SaveRecallPosition(); // save only in non-flight case
            }
            player.TeleportTo(at.ContinentID, at.Pos.X, at.Pos.Y, at.Pos.Z, player.GetOrientation());
            return(true);
        }
Ejemplo n.º 3
0
        static bool HandleGoGraveyardCommand(StringArguments args, CommandHandler handler)
        {
            Player player = handler.GetSession().GetPlayer();

            if (args.Empty())
            {
                return(false);
            }

            uint graveyardId = args.NextUInt32();

            if (graveyardId == 0)
            {
                return(false);
            }

            WorldSafeLocsEntry gy = Global.ObjectMgr.GetWorldSafeLoc(graveyardId);

            if (gy == null)
            {
                handler.SendSysMessage(CypherStrings.CommandGraveyardnoexist, graveyardId);
                return(false);
            }

            if (!GridDefines.IsValidMapCoord(gy.Loc))
            {
                handler.SendSysMessage(CypherStrings.InvalidTargetCoord, gy.Loc.GetPositionX(), gy.Loc.GetPositionY(), gy.Loc.GetMapId());
                return(false);
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.FinishTaxiFlight();
            }
            else
            {
                player.SaveRecallPosition(); // save only in non-flight case
            }
            player.TeleportTo(gy.Loc);
            return(true);
        }
Ejemplo n.º 4
0
        public void AddWaypoint(uint id, float x, float y, float z, float orientation = 0, uint waitTime = 0)
        {
            GridDefines.NormalizeMapCoord(ref x);
            GridDefines.NormalizeMapCoord(ref y);

            WaypointNode waypoint = new WaypointNode();

            waypoint.id          = id;
            waypoint.x           = x;
            waypoint.y           = y;
            waypoint.z           = z;
            waypoint.orientation = orientation;
            waypoint.moveType    = _running ? WaypointMoveType.Run : WaypointMoveType.Walk;
            waypoint.delay       = waitTime;
            waypoint.eventId     = 0;
            waypoint.eventChance = 100;
            _path.nodes.Add(waypoint);

            _manualPath = true;
        }
Ejemplo n.º 5
0
        public void LoadAreaTriggerSpawns()
        {
            uint oldMSTime = Time.GetMSTime();
            // Load area trigger positions (to put them on the server)
            //                                            0        1              2             3      4     5     6     7            8              9        10
            SQLResult templates = DB.World.Query("SELECT SpawnId, AreaTriggerId, IsServerSide, MapId, PosX, PosY, PosZ, Orientation, PhaseUseFlags, PhaseId, PhaseGroup FROM `areatrigger`");

            if (!templates.IsEmpty())
            {
                do
                {
                    ulong         spawnId       = templates.Read <ulong>(0);
                    AreaTriggerId areaTriggerId = new(templates.Read <uint>(1), templates.Read <byte>(2) == 1);
                    WorldLocation location      = new(templates.Read <uint>(3), templates.Read <float>(4), templates.Read <float>(5), templates.Read <float>(6), templates.Read <float>(7));

                    if (GetAreaTriggerTemplate(areaTriggerId) == null)
                    {
                        Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed areatrigger that doesn't exist: Id: {areaTriggerId.Id}, IsServerSide: {areaTriggerId.IsServerSide} for SpawnId {spawnId}");
                        continue;
                    }

                    if (!GridDefines.IsValidMapCoord(location))
                    {
                        Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed an invalid position: SpawnId: {spawnId}, MapId: {location.GetMapId()}, Position: {location}");
                        continue;
                    }

                    AreaTriggerSpawn spawn = new();
                    spawn.SpawnId  = spawnId;
                    spawn.Id       = areaTriggerId;
                    spawn.Location = new WorldLocation(location);

                    spawn.PhaseUseFlags = templates.Read <byte>(8);
                    spawn.PhaseId       = templates.Read <uint>(9);
                    spawn.PhaseGroup    = templates.Read <uint>(10);

                    // Add the trigger to a map::cell map, which is later used by GridLoader to query
                    CellCoord cellCoord = GridDefines.ComputeCellCoord(spawn.Location.GetPositionX(), spawn.Location.GetPositionY());
                    if (!_areaTriggerSpawnsByLocation.ContainsKey((spawn.Location.GetMapId(), cellCoord.GetId())))
                    {
                        _areaTriggerSpawnsByLocation[(spawn.Location.GetMapId(), cellCoord.GetId())] = new SortedSet <ulong>();
Ejemplo n.º 6
0
        bool LoadPath(uint entry)
        {
            if (HasEscortState(SmartEscortState.Escorting))
            {
                return(false);
            }

            var path = Global.SmartAIMgr.GetPath(entry);

            if (path.Empty())
            {
                GetScript().SetPathId(0);
                return(false);
            }

            foreach (WayPoint waypoint in path)
            {
                float x = waypoint.x;
                float y = waypoint.y;
                float z = waypoint.z;

                GridDefines.NormalizeMapCoord(ref x);
                GridDefines.NormalizeMapCoord(ref y);

                WaypointNode wp = new WaypointNode();
                wp.id          = waypoint.id;
                wp.x           = x;
                wp.y           = y;
                wp.z           = z;
                wp.orientation = 0.0f;
                wp.moveType    = mRun ? WaypointMoveType.Run : WaypointMoveType.Walk;
                wp.delay       = 0;
                wp.eventId     = 0;
                wp.eventChance = 100;

                _path.nodes.Add(wp);
            }

            GetScript().SetPathId(entry);
            return(true);
        }
Ejemplo n.º 7
0
        public bool CalculatePath(float destX, float destY, float destZ, bool forceDest = false, bool straightLine = false)
        {
            float x, y, z;

            _source.GetPosition(out x, out y, out z);

            if (!GridDefines.IsValidMapCoord(destX, destY, destZ) || !GridDefines.IsValidMapCoord(x, y, z))
            {
                return(false);
            }

            Vector3 dest = new(destX, destY, destZ);

            SetEndPosition(dest);

            Vector3 start = new(x, y, z);

            SetStartPosition(start);

            _forceDestination = forceDest;
            _straightLine     = straightLine;

            Log.outDebug(LogFilter.Maps, "PathGenerator.CalculatePath() for {0} \n", _source.GetGUID().ToString());

            // make sure navMesh works - we can run on map w/o mmap
            // check if the start and end point have a .mmtile loaded (can we pass via not loaded tile on the way?)
            Unit _sourceUnit = _source.ToUnit();

            if (_navMesh == null || _navMeshQuery == null || (_sourceUnit != null && _sourceUnit.HasUnitState(UnitState.IgnorePathfinding)) ||
                !HaveTile(start) || !HaveTile(dest))
            {
                BuildShortcut();
                pathType = PathType.Normal | PathType.NotUsingPath;
                return(true);
            }

            UpdateFilter();
            BuildPolyPath(start, dest);
            return(true);
        }
Ejemplo n.º 8
0
        public void AddWaypoint(uint id, float x, float y, float z, uint waitTime = 0)
        {
            GridDefines.NormalizeMapCoord(ref x);
            GridDefines.NormalizeMapCoord(ref y);

            WaypointNode wp = new WaypointNode();

            wp.id          = id;
            wp.x           = x;
            wp.y           = y;
            wp.z           = z;
            wp.orientation = 0.0f;
            wp.moveType    = m_bIsRunning ? WaypointMoveType.Run : WaypointMoveType.Walk;
            wp.delay       = waitTime;
            wp.eventId     = 0;
            wp.eventChance = 100;

            _path.nodes.Add(wp);

            LastWP = id;

            ScriptWP = true;
        }
Ejemplo n.º 9
0
        public static uint GetTerrainMapId(PhaseShift phaseShift, Map map, float x, float y)
        {
            if (phaseShift.VisibleMapIds.Empty())
            {
                return(map.GetId());
            }

            if (phaseShift.VisibleMapIds.Count == 1)
            {
                return(phaseShift.VisibleMapIds.First().Key);
            }

            GridCoord gridCoord = GridDefines.ComputeGridCoord(x, y);
            uint      gx        = (uint)((MapConst.MaxGrids - 1) - gridCoord.x_coord);
            uint      gy        = (uint)((MapConst.MaxGrids - 1) - gridCoord.y_coord);

            uint gxbegin = Math.Max(gx - 1, 0);
            uint gxend   = Math.Min(gx + 1, MapConst.MaxGrids);
            uint gybegin = Math.Max(gy - 1, 0);
            uint gyend   = Math.Min(gy + 1, MapConst.MaxGrids);

            foreach (var itr in phaseShift.VisibleMapIds)
            {
                for (uint gxi = gxbegin; gxi < gxend; ++gxi)
                {
                    for (uint gyi = gybegin; gyi < gyend; ++gyi)
                    {
                        if (map.HasGridMap(itr.Key, gxi, gyi))
                        {
                            return(itr.Key);
                        }
                    }
                }
            }

            return(map.GetId());
        }
Ejemplo n.º 10
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.º 11
0
        static bool HandleGoObjectCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            Player player = handler.GetSession().GetPlayer();

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

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

            if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
            {
                return(false);
            }

            float x, y, z, o;
            uint  mapId;

            // by DB guid
            GameObjectData goData = Global.ObjectMgr.GetGOData(guidLow);

            if (goData != null)
            {
                x     = goData.posX;
                y     = goData.posY;
                z     = goData.posZ;
                o     = goData.orientation;
                mapId = goData.mapid;
            }
            else
            {
                handler.SendSysMessage(CypherStrings.CommandGoobjnotfound);
                return(false);
            }

            if (!GridDefines.IsValidMapCoord(mapId, x, y, z, o) || Global.ObjectMgr.IsTransportMap(mapId))
            {
                handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
                return(false);
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.GetMotionMaster().MovementExpired();
                player.CleanupAfterTaxiFlight();
            }
            // save only in non-flight case
            else
            {
                player.SaveRecallPosition();
            }

            player.TeleportTo(mapId, x, y, z, o);
            return(true);
        }
Ejemplo n.º 12
0
        void HandleMovementOpcode(ClientOpcodes opcode, MovementInfo movementInfo)
        {
            Unit   mover    = GetPlayer().m_unitMovedByMe;
            Player plrMover = mover.ToPlayer();

            if (plrMover && plrMover.IsBeingTeleported())
            {
                return;
            }

            GetPlayer().ValidateMovementInfo(movementInfo);

            if (movementInfo.Guid != mover.GetGUID())
            {
                Log.outError(LogFilter.Network, "HandleMovementOpcodes: guid error");
                return;
            }
            if (!movementInfo.Pos.IsPositionValid())
            {
                Log.outError(LogFilter.Network, "HandleMovementOpcodes: Invalid Position");
                return;
            }

            // stop some emotes at player move
            if (plrMover && (plrMover.GetEmoteState() != 0))
            {
                plrMover.SetEmoteState(Emote.OneshotNone);
            }

            //handle special cases
            if (!movementInfo.transport.guid.IsEmpty())
            {
                // We were teleported, skip packets that were broadcast before teleport
                if (movementInfo.Pos.GetExactDist2d(mover) > MapConst.SizeofGrids)
                {
                    return;
                }

                if (Math.Abs(movementInfo.transport.pos.GetPositionX()) > 75f || Math.Abs(movementInfo.transport.pos.GetPositionY()) > 75f || Math.Abs(movementInfo.transport.pos.GetPositionZ()) > 75f)
                {
                    return;
                }

                if (!GridDefines.IsValidMapCoord(movementInfo.Pos.posX + movementInfo.transport.pos.posX, movementInfo.Pos.posY + movementInfo.transport.pos.posY,
                                                 movementInfo.Pos.posZ + movementInfo.transport.pos.posZ, movementInfo.Pos.Orientation + movementInfo.transport.pos.Orientation))
                {
                    return;
                }

                if (plrMover)
                {
                    if (!plrMover.GetTransport())
                    {
                        Transport transport = plrMover.GetMap().GetTransport(movementInfo.transport.guid);
                        if (transport)
                        {
                            transport.AddPassenger(plrMover);
                        }
                    }
                    else if (plrMover.GetTransport().GetGUID() != movementInfo.transport.guid)
                    {
                        plrMover.GetTransport().RemovePassenger(plrMover);
                        Transport transport = plrMover.GetMap().GetTransport(movementInfo.transport.guid);
                        if (transport)
                        {
                            transport.AddPassenger(plrMover);
                        }
                        else
                        {
                            movementInfo.ResetTransport();
                        }
                    }
                }

                if (!mover.GetTransport() && !mover.GetVehicle())
                {
                    GameObject go = mover.GetMap().GetGameObject(movementInfo.transport.guid);
                    if (!go || go.GetGoType() != GameObjectTypes.Transport)
                    {
                        movementInfo.transport.Reset();
                    }
                }
            }
            else if (plrMover && plrMover.GetTransport())                // if we were on a transport, leave
            {
                plrMover.GetTransport().RemovePassenger(plrMover);
            }

            // fall damage generation (ignore in flight case that can be triggered also at lags in moment teleportation to another map).
            if (opcode == ClientOpcodes.MoveFallLand && plrMover && !plrMover.IsInFlight())
            {
                plrMover.HandleFall(movementInfo);
            }

            // interrupt parachutes upon falling or landing in water
            if (opcode == ClientOpcodes.MoveFallLand || opcode == ClientOpcodes.MoveStartSwim)
            {
                mover.RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Landing); // Parachutes
            }
            if (plrMover && movementInfo.HasMovementFlag(MovementFlag.Swimming) != plrMover.IsInWater())
            {
                // now client not include swimming flag in case jumping under water
                plrMover.SetInWater(!plrMover.IsInWater() || plrMover.GetMap().IsUnderWater(plrMover.GetPhaseShift(), movementInfo.Pos.posX, movementInfo.Pos.posY, movementInfo.Pos.posZ));
            }

            uint mstime = GameTime.GetGameTimeMS();

            if (m_clientTimeDelay == 0)
            {
                m_clientTimeDelay = mstime - movementInfo.Time;
            }

            movementInfo.Time = movementInfo.Time + m_clientTimeDelay;

            movementInfo.Guid    = mover.GetGUID();
            mover.m_movementInfo = movementInfo;

            // Some vehicles allow the passenger to turn by himself
            Vehicle vehicle = mover.GetVehicle();

            if (vehicle)
            {
                VehicleSeatRecord seat = vehicle.GetSeatForPassenger(mover);
                if (seat != null)
                {
                    if (seat.HasSeatFlag(VehicleSeatFlags.AllowTurning))
                    {
                        if (movementInfo.Pos.GetOrientation() != mover.GetOrientation())
                        {
                            mover.SetOrientation(movementInfo.Pos.GetOrientation());
                            mover.RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Turning);
                        }
                    }
                }
                return;
            }

            mover.UpdatePosition(movementInfo.Pos);

            MoveUpdate moveUpdate = new MoveUpdate();

            moveUpdate.Status = mover.m_movementInfo;
            mover.SendMessageToSet(moveUpdate, GetPlayer());

            if (plrMover)                                            // nothing is charmed, or player charmed
            {
                if (plrMover.IsSitState() && movementInfo.HasMovementFlag(MovementFlag.MaskMoving | MovementFlag.MaskTurning))
                {
                    plrMover.SetStandState(UnitStandStateType.Stand);
                }

                plrMover.UpdateFallInformationIfNeed(movementInfo, opcode);

                if (movementInfo.Pos.posZ < plrMover.GetMap().GetMinHeight(plrMover.GetPhaseShift(), movementInfo.Pos.GetPositionX(), movementInfo.Pos.GetPositionY()))
                {
                    if (!(plrMover.GetBattleground() && plrMover.GetBattleground().HandlePlayerUnderMap(GetPlayer())))
                    {
                        // NOTE: this is actually called many times while falling
                        // even after the player has been teleported away
                        // @todo discard movement packets after the player is rooted
                        if (plrMover.IsAlive())
                        {
                            plrMover.AddPlayerFlag(PlayerFlags.IsOutOfBounds);
                            plrMover.EnvironmentalDamage(EnviromentalDamage.FallToVoid, (uint)GetPlayer().GetMaxHealth());
                            // player can be alive if GM/etc
                            // change the death state to CORPSE to prevent the death timer from
                            // starting in the next player update
                            if (plrMover.IsAlive())
                            {
                                plrMover.KillPlayer();
                            }
                        }
                    }
                }
                else
                {
                    plrMover.RemovePlayerFlag(PlayerFlags.IsOutOfBounds);
                }

                if (opcode == ClientOpcodes.MoveJump)
                {
                    plrMover.RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Jump, 605); // Mind Control
                    plrMover.ProcSkillsAndAuras(null, ProcFlags.Jump, ProcFlags.None, ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, null, null, null);
                }
            }
        }
Ejemplo n.º 13
0
        void HandleMoveWorldportAck()
        {
            // ignore unexpected far teleports
            if (!GetPlayer().IsBeingTeleportedFar())
            {
                return;
            }

            bool seamlessTeleport = GetPlayer().IsBeingTeleportedSeamlessly();

            GetPlayer().SetSemaphoreTeleportFar(false);

            // get the teleport destination
            WorldLocation loc = GetPlayer().GetTeleportDest();

            // possible errors in the coordinate validity check
            if (!GridDefines.IsValidMapCoord(loc))
            {
                LogoutPlayer(false);
                return;
            }

            // get the destination map entry, not the current one, this will fix homebind and reset greeting
            MapRecord        mapEntry  = CliDB.MapStorage.LookupByKey(loc.GetMapId());
            InstanceTemplate mInstance = Global.ObjectMgr.GetInstanceTemplate(loc.GetMapId());

            // reset instance validity, except if going to an instance inside an instance
            if (!GetPlayer().m_InstanceValid&& mInstance == null)
            {
                GetPlayer().m_InstanceValid = true;
            }

            Map oldMap = GetPlayer().GetMap();
            Map newMap = Global.MapMgr.CreateMap(loc.GetMapId(), GetPlayer());

            if (GetPlayer().IsInWorld)
            {
                Log.outError(LogFilter.Network, "Player (Name {0}) is still in world when teleported from map {1} to new map {2}", GetPlayer().GetName(), oldMap.GetId(), loc.GetMapId());
                oldMap.RemovePlayerFromMap(GetPlayer(), false);
            }

            // relocate the player to the teleport destination
            // the CannotEnter checks are done in TeleporTo but conditions may change
            // while the player is in transit, for example the map may get full
            if (newMap == null || newMap.CannotEnter(GetPlayer()) != 0)
            {
                Log.outError(LogFilter.Network, "Map {0} could not be created for {1} ({2}), porting player to homebind", loc.GetMapId(), newMap ? newMap.GetMapName() : "Unknown", GetPlayer().GetGUID().ToString());
                GetPlayer().TeleportTo(GetPlayer().GetHomebind());
                return;
            }

            float z = loc.GetPositionZ();

            if (GetPlayer().HasUnitMovementFlag(MovementFlag.Hover))
            {
                z += GetPlayer().m_unitData.HoverHeight;
            }

            GetPlayer().Relocate(loc.GetPositionX(), loc.GetPositionY(), z, loc.GetOrientation());
            GetPlayer().SetFallInformation(0, GetPlayer().GetPositionZ());

            GetPlayer().ResetMap();
            GetPlayer().SetMap(newMap);

            ResumeToken resumeToken = new ResumeToken();

            resumeToken.SequenceIndex = _player.m_movementCounter;
            resumeToken.Reason        = seamlessTeleport ? 2 : 1u;
            SendPacket(resumeToken);

            if (!seamlessTeleport)
            {
                GetPlayer().SendInitialPacketsBeforeAddToMap();
            }

            if (!GetPlayer().GetMap().AddPlayerToMap(GetPlayer(), !seamlessTeleport))
            {
                Log.outError(LogFilter.Network, "WORLD: failed to teleport player {0} ({1}) to map {2} ({3}) because of unknown reason!",
                             GetPlayer().GetName(), GetPlayer().GetGUID().ToString(), loc.GetMapId(), newMap ? newMap.GetMapName() : "Unknown");
                GetPlayer().ResetMap();
                GetPlayer().SetMap(oldMap);
                GetPlayer().TeleportTo(GetPlayer().GetHomebind());
                return;
            }

            // Battleground state prepare (in case join to BG), at relogin/tele player not invited
            // only add to bg group and object, if the player was invited (else he entered through command)
            if (GetPlayer().InBattleground())
            {
                // cleanup setting if outdated
                if (!mapEntry.IsBattlegroundOrArena())
                {
                    // We're not in BG
                    GetPlayer().SetBattlegroundId(0, BattlegroundTypeId.None);
                    // reset destination bg team
                    GetPlayer().SetBGTeam(0);
                }
                // join to bg case
                else
                {
                    Battleground bg = GetPlayer().GetBattleground();
                    if (bg)
                    {
                        if (GetPlayer().IsInvitedForBattlegroundInstance(GetPlayer().GetBattlegroundId()))
                        {
                            bg.AddPlayer(GetPlayer());
                        }
                    }
                }
            }

            if (!seamlessTeleport)
            {
                GetPlayer().SendInitialPacketsAfterAddToMap();
            }
            else
            {
                GetPlayer().UpdateVisibilityForPlayer();
                Garrison garrison = GetPlayer().GetGarrison();
                if (garrison != null)
                {
                    garrison.SendRemoteInfo();
                }
            }

            // flight fast teleport case
            if (GetPlayer().GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Flight)
            {
                if (!GetPlayer().InBattleground())
                {
                    if (!seamlessTeleport)
                    {
                        // short preparations to continue flight
                        IMovementGenerator movementGenerator = GetPlayer().GetMotionMaster().Top();
                        movementGenerator.Initialize(GetPlayer());
                    }
                    return;
                }

                // Battlegroundstate prepare, stop flight
                GetPlayer().GetMotionMaster().MovementExpired();
                GetPlayer().CleanupAfterTaxiFlight();
            }

            // resurrect character at enter into instance where his corpse exist after add to map
            if (mapEntry.IsDungeon() && !GetPlayer().IsAlive())
            {
                if (GetPlayer().GetCorpseLocation().GetMapId() == mapEntry.Id)
                {
                    GetPlayer().ResurrectPlayer(0.5f, false);
                    GetPlayer().SpawnCorpseBones();
                }
            }

            bool allowMount = !mapEntry.IsDungeon() || mapEntry.IsBattlegroundOrArena();

            if (mInstance != null)
            {
                // check if this instance has a reset time and send it to player if so
                Difficulty          diff    = newMap.GetDifficultyID();
                MapDifficultyRecord mapDiff = Global.DB2Mgr.GetMapDifficultyData(mapEntry.Id, diff);
                if (mapDiff != null)
                {
                    if (mapDiff.GetRaidDuration() != 0)
                    {
                        long timeReset = Global.InstanceSaveMgr.GetResetTimeFor(mapEntry.Id, diff);
                        if (timeReset != 0)
                        {
                            uint timeleft = (uint)(timeReset - Time.UnixTime);
                            GetPlayer().SendInstanceResetWarning(mapEntry.Id, diff, timeleft, true);
                        }
                    }
                }

                // check if instance is valid
                if (!GetPlayer().CheckInstanceValidity(false))
                {
                    GetPlayer().m_InstanceValid = false;
                }

                // instance mounting is handled in InstanceTemplate
                allowMount = mInstance.AllowMount;
            }

            // mount allow check
            if (!allowMount)
            {
                GetPlayer().RemoveAurasByType(AuraType.Mounted);
            }

            // update zone immediately, otherwise leave channel will cause crash in mtmap
            uint newzone, newarea;

            GetPlayer().GetZoneAndAreaId(out newzone, out newarea);
            GetPlayer().UpdateZone(newzone, newarea);

            // honorless target
            if (GetPlayer().pvpInfo.IsHostile)
            {
                GetPlayer().CastSpell(GetPlayer(), 2479, true);
            }

            // in friendly area
            else if (GetPlayer().IsPvP() && !GetPlayer().HasPlayerFlag(PlayerFlags.InPVP))
            {
                GetPlayer().UpdatePvP(false, false);
            }

            // resummon pet
            GetPlayer().ResummonPetTemporaryUnSummonedIfAny();

            //lets process all delayed operations on successful teleport
            GetPlayer().ProcessDelayedOperations();
        }
Ejemplo n.º 14
0
 public bool IsPositionValid()
 {
     return(GridDefines.IsValidMapCoord(posX, posY, posZ, Orientation));
 }
Ejemplo n.º 15
0
        public void LoadAreaTriggerSpawns()
        {
            uint oldMSTime = Time.GetMSTime();
            // Load area trigger positions (to put them on the server)
            //                                            0        1              2             3      4     5     6     7            8              9        10
            SQLResult templates = DB.World.Query("SELECT SpawnId, AreaTriggerId, IsServerSide, MapId, PosX, PosY, PosZ, Orientation, PhaseUseFlags, PhaseId, PhaseGroup, " +
                                                 //11     12          13          14          15          16          17          18
                                                 "Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ScriptName FROM `areatrigger`");

            if (!templates.IsEmpty())
            {
                do
                {
                    ulong            spawnId       = templates.Read <ulong>(0);
                    AreaTriggerId    areaTriggerId = new(templates.Read <uint>(1), templates.Read <byte>(2) == 1);
                    WorldLocation    location      = new(templates.Read <uint>(3), templates.Read <float>(4), templates.Read <float>(5), templates.Read <float>(6), templates.Read <float>(7));
                    AreaTriggerTypes shape         = (AreaTriggerTypes)templates.Read <byte>(11);

                    if (GetAreaTriggerTemplate(areaTriggerId) == null)
                    {
                        Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed areatrigger that doesn't exist: Id: {areaTriggerId.Id}, IsServerSide: {areaTriggerId.IsServerSide} for SpawnId {spawnId}");
                        continue;
                    }

                    if (!GridDefines.IsValidMapCoord(location))
                    {
                        Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed an invalid position: SpawnId: {spawnId}, MapId: {location.GetMapId()}, Position: {location}");
                        continue;
                    }

                    if (shape >= AreaTriggerTypes.Max)
                    {
                        Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed areatrigger SpawnId: {spawnId} with invalid shape {shape}.");
                        continue;
                    }

                    AreaTriggerSpawn spawn = new();
                    spawn.SpawnId  = spawnId;
                    spawn.Id       = areaTriggerId;
                    spawn.Location = new WorldLocation(location);

                    spawn.PhaseUseFlags = templates.Read <byte>(8);
                    spawn.PhaseId       = templates.Read <uint>(9);
                    spawn.PhaseGroup    = templates.Read <uint>(10);

                    spawn.Shape.TriggerType = shape;
                    unsafe
                    {
                        for (var i = 0; i < SharedConst.MaxAreatriggerEntityData; ++i)
                        {
                            spawn.Shape.DefaultDatas.Data[i] = templates.Read <float>(12 + i);
                        }
                    }

                    spawn.ScriptId = Global.ObjectMgr.GetScriptId(templates.Read <string>(18));

                    // Add the trigger to a map::cell map, which is later used by GridLoader to query
                    CellCoord cellCoord = GridDefines.ComputeCellCoord(spawn.Location.GetPositionX(), spawn.Location.GetPositionY());
                    if (!_areaTriggerSpawnsByLocation.ContainsKey((spawn.Location.GetMapId(), cellCoord.GetId())))
                    {
                        _areaTriggerSpawnsByLocation[(spawn.Location.GetMapId(), cellCoord.GetId())] = new SortedSet <ulong>();
Ejemplo n.º 16
0
        public void _setRandomLocation(Creature creature)
        {
            if (creature.IsMovementPreventedByCasting())
            {
                creature.CastStop();
                return;
            }

            float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ;

            creature.GetHomePosition(out respX, out respY, out respZ, out respO);
            Map map = creature.GetMap();

            bool is_air_ok = creature.CanFly();

            float angle     = (float)(RandomHelper.NextDouble() * MathFunctions.TwoPi);
            float range     = (float)(RandomHelper.NextDouble() * wander_distance);
            float distanceX = (float)(range * Math.Cos(angle));
            float distanceY = (float)(range * Math.Sin(angle));

            destX = respX + distanceX;
            destY = respY + distanceY;

            // prevent invalid coordinates generation
            GridDefines.NormalizeMapCoord(ref destX);
            GridDefines.NormalizeMapCoord(ref destY);

            travelDistZ = range;   // sin^2+cos^2=1, so travelDistZ=range^2; no need for sqrt below

            if (is_air_ok)         // 3D system above ground and above water (flying mode)
            {
                // Limit height change
                float distanceZ = (float)(RandomHelper.NextDouble() * travelDistZ / 2.0f);
                destZ = respZ + distanceZ;
                float levelZ = map.GetWaterOrGroundLevel(creature.GetPhases(), destX, destY, destZ - 2.5f);

                // Problem here, we must fly above the ground and water, not under. Let's try on next tick
                if (levelZ >= destZ)
                {
                    return;
                }
            }
            else                                                    // 2D only
            {
                // 10.0 is the max that vmap high can check (MAX_CAN_FALL_DISTANCE)
                travelDistZ = travelDistZ >= 10.0f ? 10.0f : travelDistZ;

                // The fastest way to get an accurate result 90% of the time.
                // Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long.
                destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ + travelDistZ - 2.0f, false);

                if (Math.Abs(destZ - respZ) > travelDistZ)              // Map check
                {
                    // Vmap Horizontal or above
                    destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ - 2.0f, true);

                    if (Math.Abs(destZ - respZ) > travelDistZ)
                    {
                        // Vmap Higher
                        destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ + travelDistZ - 2.0f, true);

                        // let's forget this bad coords where a z cannot be find and retry at next tick
                        if (Math.Abs(destZ - respZ) > travelDistZ)
                        {
                            return;
                        }
                    }
                }
            }

            if (is_air_ok)
            {
                i_nextMoveTime.Reset(0);
            }
            else
            {
                if (RandomHelper.randChance(50))
                {
                    i_nextMoveTime.Reset(RandomHelper.IRand(5000, 10000));
                }
                else
                {
                    i_nextMoveTime.Reset(RandomHelper.IRand(50, 400));
                }
            }

            creature.AddUnitState(UnitState.RoamingMove);

            MoveSplineInit init = new MoveSplineInit(creature);

            init.MoveTo(destX, destY, destZ);
            init.SetWalk(true);
            init.Launch();

            //Call for creature group update
            if (creature.GetFormation() != null && creature.GetFormation().getLeader() == creature)
            {
                creature.GetFormation().LeaderMoveTo(destX, destY, destZ);
            }
        }
Ejemplo n.º 17
0
        static bool HandleGoXYZCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            Player player = handler.GetSession().GetPlayer();

            string goX  = args.NextString();
            string goY  = args.NextString();
            string goZ  = args.NextString();
            string id   = args.NextString();
            string port = args.NextString();

            if (goX.IsEmpty() || goY.IsEmpty())
            {
                return(false);
            }

            float x = float.Parse(goX);
            float y = float.Parse(goY);
            float z;
            float ort   = !port.IsEmpty() ? float.Parse(port) : player.GetOrientation();
            uint  mapId = !id.IsEmpty() ? uint.Parse(id) : player.GetMapId();

            if (!goZ.IsEmpty())
            {
                z = float.Parse(goZ);
                if (!GridDefines.IsValidMapCoord(mapId, x, y, z))
                {
                    handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
                    return(false);
                }
            }
            else
            {
                if (!GridDefines.IsValidMapCoord(mapId, x, y))
                {
                    handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
                    return(false);
                }
                Map map = Global.MapMgr.CreateBaseMap(mapId);
                z = Math.Max(map.GetHeight(x, y, MapConst.MaxHeight), map.GetWaterLevel(x, y));
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.GetMotionMaster().MovementExpired();
                player.CleanupAfterTaxiFlight();
            }
            // save only in non-flight case
            else
            {
                player.SaveRecallPosition();
            }

            player.TeleportTo(mapId, x, y, z, ort);
            return(true);
        }
Ejemplo n.º 18
0
        static bool HandleGoZoneXYCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            Player player = handler.GetSession().GetPlayer();

            if (!float.TryParse(args.NextString(), out float x))
            {
                return(false);
            }

            if (!float.TryParse(args.NextString(), out float y))
            {
                return(false);
            }

            // prevent accept wrong numeric args
            if (x == 0.0f || y == 0.0f)
            {
                return(false);
            }

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

            if (!uint.TryParse(idStr, out uint areaId))
            {
                areaId = player.GetZoneId();
            }

            AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId);

            if (x < 0 || x > 100 || y < 0 || y > 100 || areaEntry == null)
            {
                handler.SendSysMessage(CypherStrings.InvalidZoneCoord, x, y, areaId);
                return(false);
            }

            // update to parent zone if exist (client map show only zones without parents)
            AreaTableRecord zoneEntry = areaEntry.ParentAreaID != 0 ? CliDB.AreaTableStorage.LookupByKey(areaEntry.ParentAreaID) : areaEntry;

            Cypher.Assert(zoneEntry != null);

            Map map = Global.MapMgr.CreateBaseMap(zoneEntry.ContinentID);

            if (map.Instanceable())
            {
                handler.SendSysMessage(CypherStrings.InvalidZoneMap, areaId, areaEntry.AreaName[handler.GetSessionDbcLocale()], map.GetId(), map.GetMapName());
                return(false);
            }

            Global.DB2Mgr.Zone2MapCoordinates(areaEntry.ParentAreaID != 0 ? areaEntry.ParentAreaID : areaId, ref x, ref y);

            if (!GridDefines.IsValidMapCoord(zoneEntry.ContinentID, x, y))
            {
                handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, zoneEntry.ContinentID);
                return(false);
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.GetMotionMaster().MovementExpired();
                player.CleanupAfterTaxiFlight();
            }
            // save only in non-flight case
            else
            {
                player.SaveRecallPosition();
            }

            float z = Math.Max(map.GetStaticHeight(PhasingHandler.EmptyPhaseShift, x, y, MapConst.MaxHeight), map.GetWaterLevel(PhasingHandler.EmptyPhaseShift, x, y));

            player.TeleportTo(zoneEntry.ContinentID, x, y, z, player.GetOrientation());
            return(true);
        }
Ejemplo n.º 19
0
        static bool HandleGoQuestCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            Player player = handler.GetSession().GetPlayer();

            string id = handler.extractKeyFromLink(args, "Hquest");

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

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

            if (Global.ObjectMgr.GetQuestTemplate(questID) == null)
            {
                handler.SendSysMessage(CypherStrings.CommandQuestNotfound, questID);
                return(false);
            }

            float x, y, z = 0;
            uint  mapId = 0;

            var poiData = Global.ObjectMgr.GetQuestPOIList(questID);

            if (poiData != null)
            {
                var data = poiData[0];

                mapId = (uint)data.MapID;

                x = data.points[0].X;
                y = data.points[0].Y;
            }
            else
            {
                handler.SendSysMessage(CypherStrings.CommandQuestNotfound, questID);
                return(false);
            }

            if (!GridDefines.IsValidMapCoord(mapId, x, y) || Global.ObjectMgr.IsTransportMap(mapId))
            {
                handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
                return(false);
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.GetMotionMaster().MovementExpired();
                player.CleanupAfterTaxiFlight();
            }
            // save only in non-flight case
            else
            {
                player.SaveRecallPosition();
            }

            Map map = Global.MapMgr.CreateBaseMap(mapId);

            z = Math.Max(map.GetStaticHeight(PhasingHandler.EmptyPhaseShift, x, y, MapConst.MaxHeight), map.GetWaterLevel(PhasingHandler.EmptyPhaseShift, x, y));

            player.TeleportTo(mapId, x, y, z, 0.0f);
            return(true);
        }
Ejemplo n.º 20
0
        static bool HandleGameObjectMoveCommand(StringArguments args, CommandHandler handler)
        {
            // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
            string id = handler.extractKeyFromLink(args, "Hgameobject");

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

            if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
            {
                return(false);
            }

            GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);

            if (!obj)
            {
                handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow);
                return(false);
            }

            string toX = args.NextString();
            string toY = args.NextString();
            string toZ = args.NextString();

            float x, y, z;

            if (string.IsNullOrEmpty(toX))
            {
                Player player = handler.GetSession().GetPlayer();
                player.GetPosition(out x, out y, out z);
            }
            else
            {
                if (!float.TryParse(toX, out x))
                {
                    return(false);
                }

                if (!float.TryParse(toY, out y))
                {
                    return(false);
                }

                if (!float.TryParse(toZ, out z))
                {
                    return(false);
                }

                if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z))
                {
                    handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, obj.GetMapId());
                    return(false);
                }
            }

            obj.DestroyForNearbyPlayers();
            obj.RelocateStationaryPosition(x, y, z, obj.GetOrientation());
            obj.GetMap().GameObjectRelocation(obj, x, y, z, obj.GetOrientation());

            obj.SaveToDB();

            handler.SendSysMessage(CypherStrings.CommandMoveobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString());

            return(true);
        }
Ejemplo n.º 21
0
        static bool HandleGoCreatureCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            Player player = handler.GetSession().GetPlayer();

            // "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
            string param1 = handler.extractKeyFromLink(args, "Hcreature", "Hcreature_entry");

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

            string whereClause = "";

            // User wants to teleport to the NPC's template entry
            if (param1.IsNumber())
            {
                if (!int.TryParse(param1, out int entry) || entry == 0)
                {
                    if (!ulong.TryParse(param1, out ulong guidLow) || guidLow == 0)
                    {
                        return(false);
                    }

                    whereClause += "WHERE guid = '" + guidLow + '\'';
                }
                else
                {
                    whereClause += "WHERE id = '" + entry + '\'';
                }
            }
            else
            {
                // param1 is not a number, must be mob's name
                whereClause += ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name LIKE '" + param1 + '\'';
            }

            SQLResult result = DB.World.Query("SELECT position_x, position_y, position_z, orientation, map FROM creature {0}", whereClause);

            if (result.IsEmpty())
            {
                handler.SendSysMessage(CypherStrings.CommandGocreatnotfound);
                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);
            uint  mapId = result.Read <ushort>(4);

            if (result.NextRow())
            {
                handler.SendSysMessage(CypherStrings.CommandGocreatmultiple);
            }

            if (!GridDefines.IsValidMapCoord(mapId, x, y, z, o) || Global.ObjectMgr.IsTransportMap(mapId))
            {
                handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
                return(false);
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.GetMotionMaster().MovementExpired();
                player.CleanupAfterTaxiFlight();
            }
            // save only in non-flight case
            else
            {
                player.SaveRecallPosition();
            }

            player.TeleportTo(mapId, x, y, z, o);

            return(true);
        }
Ejemplo n.º 22
0
        static bool HandleGameObjectMoveCommand(StringArguments args, CommandHandler handler)
        {
            // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
            string id = handler.extractKeyFromLink(args, "Hgameobject");

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

            if (!ulong.TryParse(id, out ulong guidLow) || guidLow == 0)
            {
                return(false);
            }

            GameObject obj = handler.GetObjectFromPlayerMapByDbGuid(guidLow);

            if (!obj)
            {
                handler.SendSysMessage(CypherStrings.CommandObjnotfound, guidLow);
                return(false);
            }

            string toX = args.NextString();
            string toY = args.NextString();
            string toZ = args.NextString();

            float x, y, z;

            if (string.IsNullOrEmpty(toX))
            {
                Player player = handler.GetSession().GetPlayer();
                player.GetPosition(out x, out y, out z);
            }
            else
            {
                if (!float.TryParse(toX, out x))
                {
                    return(false);
                }

                if (!float.TryParse(toY, out y))
                {
                    return(false);
                }

                if (!float.TryParse(toZ, out z))
                {
                    return(false);
                }

                if (!GridDefines.IsValidMapCoord(obj.GetMapId(), x, y, z))
                {
                    handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, obj.GetMapId());
                    return(false);
                }
            }

            Map map = obj.GetMap();

            obj.Relocate(x, y, z, obj.GetOrientation());
            obj.SaveToDB();

            // Generate a completely new spawn with new guid
            // client caches recently deleted objects and brings them back to life
            // when CreateObject block for this guid is received again
            // however it entirely skips parsing that block and only uses already known location
            obj.Delete();

            obj = GameObject.CreateGameObjectFromDB(guidLow, map);
            if (!obj)
            {
                return(false);
            }

            handler.SendSysMessage(CypherStrings.CommandMoveobjmessage, obj.GetSpawnId(), obj.GetGoInfo().name, obj.GetGUID().ToString());

            return(true);
        }
Ejemplo n.º 23
0
        static bool HandleGoXYZCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            Player player = handler.GetSession().GetPlayer();

            if (!float.TryParse(args.NextString(), out float x))
            {
                return(false);
            }

            if (!float.TryParse(args.NextString(), out float y))
            {
                return(false);
            }

            string goZ = args.NextString();

            if (!uint.TryParse(args.NextString(), out uint mapId))
            {
                mapId = player.GetMapId();
            }

            if (!float.TryParse(args.NextString(), out float ort))
            {
                ort = player.GetOrientation();
            }

            float z;

            if (!goZ.IsEmpty())
            {
                if (!float.TryParse(goZ, out z))
                {
                    return(false);
                }

                if (!GridDefines.IsValidMapCoord(mapId, x, y, z))
                {
                    handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
                    return(false);
                }
            }
            else
            {
                if (!GridDefines.IsValidMapCoord(mapId, x, y))
                {
                    handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId);
                    return(false);
                }
                Map map = Global.MapMgr.CreateBaseMap(mapId);
                z = Math.Max(map.GetStaticHeight(PhasingHandler.EmptyPhaseShift, x, y, MapConst.MaxHeight), map.GetWaterLevel(PhasingHandler.EmptyPhaseShift, x, y));
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.GetMotionMaster().MovementExpired();
                player.CleanupAfterTaxiFlight();
            }
            // save only in non-flight case
            else
            {
                player.SaveRecallPosition();
            }

            player.TeleportTo(mapId, x, y, z, ort);
            return(true);
        }
Ejemplo n.º 24
0
 public bool IsValidMapCoord(uint mapid, float x, float y, float z, float o)
 {
     return(IsValidMAP(mapid, false) && GridDefines.IsValidMapCoord(x, y, z, o));
 }