static bool DoTeleport(CommandHandler handler, Position pos, uint mapId = 0xFFFFFFFF) { Player player = handler.GetSession().GetPlayer(); if (mapId == 0xFFFFFFFF) { mapId = player.GetMapId(); } if (!GridDefines.IsValidMapCoord(mapId, pos) || Global.ObjectMgr.IsTransportMap(mapId)) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, pos.GetPositionX(), pos.GetPositionY(), mapId); return(false); } // stop flight if need if (player.IsInFlight()) { player.FinishTaxiFlight(); } else { player.SaveRecallPosition(); // save only in non-flight case } player.TeleportTo(new WorldLocation(mapId, pos)); return(true); }
static bool HandleGoXYZCommand(CommandHandler handler, float x, float y, float?z, uint?id, float?o) { Player player = handler.GetSession().GetPlayer(); uint mapId = id.HasValue ? id.Value : player.GetMapId(); if (z.HasValue) { if (!GridDefines.IsValidMapCoord(mapId, x, y, z.Value)) { 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)); } return(DoTeleport(handler, new Position(x, y, z.Value, o.Value), mapId)); }
static bool HandleGoGridCommand(CommandHandler handler, float gridX, float gridY, uint mapId) { Player player = handler.GetSession().GetPlayer(); // center of grid float x = (gridX - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids; float y = (gridY - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids; if (!GridDefines.IsValidMapCoord(mapId, x, y)) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, mapId); return(false); } // stop flight if need if (player.IsInFlight()) { player.FinishTaxiFlight(); } else { player.SaveRecallPosition(); // save only in non-flight case } Map map = Global.MapMgr.CreateBaseMap(mapId); float z = Math.Max(map.GetStaticHeight(PhasingHandler.EmptyPhaseShift, x, y, MapConst.MaxHeight), map.GetWaterLevel(PhasingHandler.EmptyPhaseShift, x, y)); player.TeleportTo(mapId, x, y, z, player.GetOrientation()); return(true); }
static bool HandleGoGraveyardCommand(CommandHandler handler, uint graveyardId) { 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); } Player player = handler.GetSession().GetPlayer(); // stop flight if need if (player.IsInFlight()) { player.FinishTaxiFlight(); } else { player.SaveRecallPosition(); // save only in non-flight case } player.TeleportTo(gy.Loc); return(true); }
static bool HandleGoOffsetCommand(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(); float x, y, z, o; player.GetPosition(out x, out y, out z, out o); if (!goX.IsEmpty()) { x += float.Parse(goX); } if (!goY.IsEmpty()) { y += float.Parse(goY); } if (!goZ.IsEmpty()) { z += float.Parse(goZ); } if (!port.IsEmpty()) { o += float.Parse(port); } if (!GridDefines.IsValidMapCoord(x, y, z, o)) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, player.GetMapId()); 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(player.GetMapId(), x, y, z, o); return(true); }
static bool HandleGoTaxinodeCommand(StringArguments args, CommandHandler handler) { Player player = handler.GetSession().GetPlayer(); if (args.Empty()) { return(false); } string id = handler.extractKeyFromLink(args, "Htaxinode"); if (string.IsNullOrEmpty(id)) { return(false); } uint nodeId = uint.Parse(id); if (nodeId == 0) { return(false); } TaxiNodesRecord node = CliDB.TaxiNodesStorage.LookupByKey(nodeId); if (node == null) { handler.SendSysMessage(CypherStrings.CommandGotaxinodenotfound, nodeId); return(false); } if ((node.Pos.X == 0.0f && node.Pos.Y == 0.0f && node.Pos.Z == 0.0f) || !GridDefines.IsValidMapCoord(node.MapID, node.Pos.X, node.Pos.Y, node.Pos.Z)) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, node.Pos.X, node.Pos.Y, node.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(node.MapID, node.Pos.X, node.Pos.Y, node.Pos.Z, player.GetOrientation()); return(true); }
static bool HandleGoGridCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) { return(false); } Player player = handler.GetSession().GetPlayer(); if (!float.TryParse(args.NextString(), out float gridX)) { return(false); } if (!float.TryParse(args.NextString(), out float gridY)) { return(false); } if (!uint.TryParse(args.NextString(), out uint mapId)) { mapId = player.GetMapId(); } // center of grid float x = (gridX - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids; float y = (gridY - MapConst.CenterGridId + 0.5f) * MapConst.SizeofGrids; if (!GridDefines.IsValidMapCoord(mapId, x, y)) { 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); float z = Math.Max(map.GetStaticHeight(PhasingHandler.EmptyPhaseShift, x, y, MapConst.MaxHeight), map.GetWaterLevel(PhasingHandler.EmptyPhaseShift, x, y)); player.TeleportTo(mapId, x, y, z, player.GetOrientation()); return(true); }
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); } // by DB guid GameObjectData goData = Global.ObjectMgr.GetGameObjectData(guidLow); if (goData == null) { handler.SendSysMessage(CypherStrings.CommandGoobjnotfound); return(false); } if (!GridDefines.IsValidMapCoord(goData.spawnPoint) || Global.ObjectMgr.IsTransportMap(goData.spawnPoint.GetMapId())) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, goData.spawnPoint.GetPositionX(), goData.spawnPoint.GetPositionY(), goData.spawnPoint.GetMapId()); 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(goData.spawnPoint); return(true); }
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.GetMotionMaster().MovementExpired(); player.CleanupAfterTaxiFlight(); } // save only in non-flight case else { player.SaveRecallPosition(); } player.TeleportTo(gy.Loc); return(true); }
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); } WorldSafeLocsRecord gy = CliDB.WorldSafeLocsStorage.LookupByKey(graveyardId); if (gy == null) { handler.SendSysMessage(CypherStrings.CommandGraveyardnoexist, graveyardId); return(false); } if (!GridDefines.IsValidMapCoord(gy.MapID, gy.Loc.X, gy.Loc.Y, gy.Loc.Z)) { handler.SendSysMessage(CypherStrings.InvalidTargetCoord, gy.Loc.X, gy.Loc.Y, gy.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(gy.MapID, gy.Loc.X, gy.Loc.Y, gy.Loc.Z, (gy.Facing * MathFunctions.PI) / 180); // Orientation is initially in degrees return(true); }
static bool HandleGoTriggerCommand(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.GetMotionMaster().MovementExpired(); player.CleanupAfterTaxiFlight(); } // save only in non-flight case else { player.SaveRecallPosition(); } player.TeleportTo(at.ContinentID, at.Pos.X, at.Pos.Y, at.Pos.Z, player.GetOrientation()); return(true); }
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>();
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); }
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); }
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); }
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); }
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); } ulong guidLow = ulong.Parse(id); if (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); }
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); } } }
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); }
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(); }
public bool IsPositionValid() { return(GridDefines.IsValidMapCoord(posX, posY, posZ, Orientation)); }
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>();
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); }
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); }
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); }
public bool IsValidMapCoord(uint mapid, float x, float y, float z, float o) { return(IsValidMAP(mapid, false) && GridDefines.IsValidMapCoord(x, y, z, o)); }