public void MoveUser(int mapId, int triggerId, int boxId) { List <Character> players = Field.State.Players.Values.ToList(); if (boxId != 0) { MapTriggerBox box = MapEntityMetadataStorage.GetTriggerBox(Field.MapId, boxId); if (box is null) { return; } players = players.Where(player => FieldManager.IsPlayerInBox(box, player)).ToList(); } // move player back to return map if (mapId == 0 && triggerId == 0) { foreach (IFieldObject <Player> player in players) { player.Value.Warp(player.Value.ReturnMapId, player.Value.ReturnCoord); } return; } if (mapId == Field.MapId) { IFieldObject <Portal> portal = Field.State.Portals.Values.First(p => p.Value.Id == triggerId); foreach (IFieldObject <Player> player in players) { player.Value.Move(portal.Coord, portal.Rotation, isTrigger: true); } return; } CoordF moveCoord; CoordF moveRotation; MapPortal dstPortal = MapEntityMetadataStorage.GetPortals(mapId).FirstOrDefault(portal => portal.Id == triggerId); if (dstPortal == null) { MapPlayerSpawn spawn = MapEntityMetadataStorage.GetRandomPlayerSpawn(mapId); moveCoord = spawn.Coord.ToFloat(); moveRotation = spawn.Rotation.ToFloat(); } else { moveCoord = dstPortal.Coord.ToFloat(); moveRotation = dstPortal.Rotation.ToFloat(); } foreach (IFieldObject <Player> player in players) { player.Value.Warp(mapId, moveCoord, moveRotation, instanceId: 1); } }
private static void HandleEnter(GameSession session, PacketReader packet) { int globalEventId = packet.ReadInt(); int selectionIndex = packet.ReadInt(); GlobalEvent globalEvent = GameServer.GlobalEventManager.GetEventById(globalEventId); if (globalEvent == null) { return; } Map map; switch (globalEvent.Events[selectionIndex]) { case GlobalEventType.oxquiz: map = Map.MapleOXQuiz; break; case GlobalEventType.trap_master: map = Map.TrapMaster; break; case GlobalEventType.spring_beach: map = Map.SpringBeach; break; case GlobalEventType.crazy_runner: map = Map.CrazyRunners; break; case GlobalEventType.final_surviver: map = Map.SoleSurvivor; break; case GlobalEventType.great_escape: map = Map.LudibriumEscape; break; case GlobalEventType.dancedance_stop: map = Map.DanceDanceStop; break; case GlobalEventType.crazy_runner_shanghai: map = Map.ShanghaiCrazyRunners; break; case GlobalEventType.hideandseek: map = Map.HideAndSeek; break; case GlobalEventType.red_arena: map = Map.RedArena; break; case GlobalEventType.blood_mine: map = Map.CrimsonTearMine; break; case GlobalEventType.treasure_island: map = Map.TreasureIsland; break; case GlobalEventType.christmas_dancedance_stop: map = Map.HolidayDanceDanceStop; break; default: Logger.Warning("Unknown Global Event: {event}", globalEvent.Events[selectionIndex]); return; } session.Player.Mount = null; MapPortal portal = MapEntityMetadataStorage.GetPortals((int)map).FirstOrDefault(portal => portal.Id == 1); session.Player.Warp(map, portal.Coord.ToFloat(), portal.Rotation.ToFloat()); }
public void TalkFunction(GameSession session, int functionId, string function) { if (functionId == 0) { return; } List <ActionType> actions = new(); Script npcScript = ScriptLoader.GetScript($"Npcs/{Npc.Id}"); DynValue actionResults = npcScript?.RunFunction(function); if (actionResults == null) { return; } switch (actionResults.Type) { case DataType.Number: actions.Add((ActionType)actionResults.Number); break; case DataType.Tuple: foreach (DynValue value in actionResults.Tuple) { actions.Add((ActionType)value.Number); } break; default: return; } MapPortal portal = new(); foreach (ActionType action in actions) { switch (action) { case ActionType.OpenWindow: DynValue windowResults = npcScript.RunFunction("actionWindow"); session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, windowResults.Tuple[0].String, windowResults.Tuple[1].String)); break; case ActionType.Portal: DynValue portalResults = npcScript.RunFunction("actionPortal"); portal = MapEntityMetadataStorage.GetPortals(session.Player.MapId).FirstOrDefault(portal => portal.Id == portalResults.Number); if (portal is null) { return; } session.Send(NpcTalkPacket.Action(ActionType.Portal, "", "", portal.Id)); break; case ActionType.ItemReward: DynValue itemResults = npcScript.RunFunction("actionItemReward"); // TODO: Support > 1 item Item item = new(id : (int)itemResults.Tuple[0].Number, amount : (int)itemResults.Tuple[2].Number, rarity : (int)itemResults.Tuple[1].Number); session.Player.Inventory.AddItem(session, item, true); session.Send(NpcTalkPacket.Action(action, "", "", 0, item)); break; case ActionType.MoveMap: DynValue map = npcScript.RunFunction("actionMoveMap"); int mapId = (int)map.Tuple[0].Number; int portalId = (int)map.Tuple[1].Number; MapPortal portalDst = MapEntityMetadataStorage.GetPortals(mapId).FirstOrDefault(x => x.Id == portalId); if (portalDst is null) { session.Player.Warp(mapId); return; } session.Player.Warp(mapId, portalDst.Coord, portalDst.Rotation); break; } } // this needs to be sent after the UI window action if (actions.Contains(ActionType.Portal)) { session.Player.Move(portal.Coord.ToFloat(), portal.Rotation.ToFloat()); } }
private static void HandleMove(GameSession session, PacketReader packet) { int srcMapId = packet.ReadInt(); if (srcMapId != session.FieldManager.MapId) { return; } int portalId = packet.ReadInt(); IFieldObject <Portal> fieldPortal = session.FieldManager.State.Portals.Values.FirstOrDefault(x => x.Value.Id == portalId); if (fieldPortal == default) { Logger.Warning("Unable to find portal: {portalId} in map: {srcMapId}", portalId, srcMapId); return; } Portal srcPortal = fieldPortal.Value; switch (srcPortal.PortalType) { case PortalTypes.Field: break; case PortalTypes.DungeonReturnToLobby: DungeonSession dungeonSession = GameServer.DungeonManager.GetDungeonSessionBySessionId(session.Player.DungeonSessionId); if (dungeonSession == null) { return; } session.Player.Warp(dungeonSession.DungeonLobbyId, instanceId: dungeonSession.DungeonInstanceId); return; case PortalTypes.LeaveDungeon: HandleLeaveInstance(session); return; case PortalTypes.Home: HandleHomePortal(session, fieldPortal); return; default: Logger.Warning("unknown portal type id: {portalType}", srcPortal.PortalType); break; } if (!MapEntityMetadataStorage.HasSafePortal(srcMapId) || srcPortal.TargetMapId == 0) // map is instance only { HandleLeaveInstance(session); return; } MapPortal dstPortal = MapEntityMetadataStorage.GetPortals(srcPortal.TargetMapId) .FirstOrDefault(portal => portal.Id == srcPortal.TargetPortalId); // target map's portal id == source portal's targetPortalId if (dstPortal == default) { session.Player.Warp(srcPortal.TargetMapId); return; } CoordF coord = dstPortal.Coord.ToFloat(); if (dstPortal.Name == "Portal_cube") // spawn on the next block if portal is a cube { if (dstPortal.Rotation.Z == Direction.SOUTH_EAST) { coord.Y -= Block.BLOCK_SIZE; } else if (dstPortal.Rotation.Z == Direction.NORTH_EAST) { coord.X += Block.BLOCK_SIZE; } else if (dstPortal.Rotation.Z == Direction.NORTH_WEST) { coord.Y += Block.BLOCK_SIZE; } else if (dstPortal.Rotation.Z == Direction.SOUTH_WEST) { coord.X -= Block.BLOCK_SIZE; } } session.Player.Warp(srcPortal.TargetMapId, coord, dstPortal.Rotation.ToFloat()); }