예제 #1
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            if (function == 0)
            {
                int srcMapId = packet.ReadInt();
                if (srcMapId != session.FieldManager.MapId)
                {
                    return;
                }

                int       portalId  = packet.ReadInt();
                MapPortal srcPortal = MapEntityStorage.GetPortals(srcMapId)
                                      .FirstOrDefault(portal => portal.Id == portalId);
                if (srcPortal == default)
                {
                    logger.Warning($"Unable to find portal:{portalId} in map:{srcMapId}");
                    return;
                }

                MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                                      .FirstOrDefault(portal => portal.Target == srcMapId);
                if (dstPortal == default)
                {
                    logger.Warning($"Unable to find return portal to map:{srcMapId} in map:{srcPortal.Target}");
                    return;
                }

                // TODO: There needs to be a more centralized way to set coordinates...
                session.Player.MapId = srcPortal.Target;
                session.Player.Coord = dstPortal.Coord.ToFloat();
                session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
            }
        }
예제 #2
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            if (function == 0)
            {
                int srcMapId = packet.ReadInt();
                if (srcMapId != session.FieldManager.MapId)
                {
                    return;
                }

                int       portalId  = packet.ReadInt();
                MapPortal srcPortal = MapEntityStorage.GetPortals(srcMapId)
                                      .FirstOrDefault(portal => portal.Id == portalId);
                if (srcPortal == default)
                {
                    Logger.Warning($"Unable to find portal:{portalId} in map:{srcMapId}");
                    return;
                }

                MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                                      .FirstOrDefault(portal => portal.Target == srcMapId);
                if (dstPortal == default)
                {
                    Logger.Warning($"Unable to find return portal to map:{srcMapId} in map:{srcPortal.Target}");
                    return;
                }

                // TODO: There needs to be a more centralized way to set coordinates...
                session.Player.MapId    = srcPortal.Target;
                session.Player.Rotation = dstPortal.Rotation.ToFloat();
                session.Player.Coord    = dstPortal.Coord.ToFloat();

                if (dstPortal.Name == "Portal_cube") // spawn on the next block if portal is a cube
                {
                    if (dstPortal.Rotation.Z == 0)   // Facing SE
                    {
                        session.Player.Coord.Y -= Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == 90) // Facing NE
                    {
                        session.Player.Coord.X += Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == 180) // Facing NW
                    {
                        session.Player.Coord.Y += Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == 270) // Facing SW
                    {
                        session.Player.Coord.X -= Block.BLOCK_SIZE;
                    }
                }

                session.Player.SafeBlock = session.Player.Coord;
                session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
            }
        }
예제 #3
0
    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);
        }
    }
예제 #4
0
 public void RemovePortal(MapPortal portal)
 {
     foreach (MapPortal p in portals)
     {
         if (p == portal)
         {
             portals.Remove(portal);
         }
     }
 }
예제 #5
0
 public void AddPortal(MapPortal portal)
 {
     foreach (MapPortal p in portals)
     {
         if (p == portal)
         {
             return;
         }
     }
     portals.Add(portal);
 }
예제 #6
0
    private static void HandleBeauty(GameSession session)
    {
        MapPortal portal = MapEntityStorage.GetPortals(session.Player.MapId).FirstOrDefault(portal => portal.Id == 99); // unsure how the portalId is determined

        if (portal is null)
        {
            return;
        }

        session.Send(NpcTalkPacket.Action(ActionType.Portal, "", "", portal.Id));
        NpcMetadata npcTarget = NpcMetadataStorage.GetNpcMetadata(session.Player.NpcTalk.Npc.Id);

        session.Player.ShopId = npcTarget.ShopId;

        switch (npcTarget.ShopId)
        {
        case 500:                                                                                  // Dr Dixon
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "face")); // unsure how these strings are determined
            break;

        case 501:     // Dr Zenko
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "skin"));
            break;

        case 504:     // Rosetta
        case 509:     //Lolly
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,style"));
            break;

        case 505:     // Ren
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "makeup"));
            break;

        case 506:     // Douglas
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "itemcolor"));
            break;

        case 507:     // Mirror
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "mirror"));
            break;

        case 508:     // Paulie
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,random"));
            break;

        case 510:     // Mino
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,styleSave"));
            break;
        }

        session.Send(UserMoveByPortalPacket.Move(session.Player.FieldPlayer, portal.Coord.ToFloat(), portal.Rotation.ToFloat()));
    }
예제 #7
0
        public override void Import(DCFG cfg)
        {
            MapPortal data = new MapPortal();

            this.ID                    = data.ID;
            this.Name                  = data.Name;
            this.DestMapID             = data.DestMapID;
            this.DestPos               = data.DestPos;
            this.OpenConditionRelation = (EOpenConditionRelation)data.OpenConditionRelation;
            this.OpenLevel             = data.OpenLevel;
            this.OpenItemID            = data.OpenItemID;
            this.OpenVIP               = data.OpenVIP;
            this.Pos                   = data.Pos;
            this.Scale                 = data.Scale;
        }
예제 #8
0
        public override DCFG Export()
        {
            MapPortal data = new MapPortal();

            data.ID                    = this.ID;
            data.Name                  = this.Name;
            data.DestMapID             = this.DestMapID;
            data.DestPos               = this.DestPos;
            data.OpenConditionRelation = (int)OpenConditionRelation;
            data.OpenLevel             = this.OpenLevel;
            data.OpenItemID            = this.OpenItemID;
            data.OpenVIP               = this.OpenVIP;
            data.Pos                   = this.Pos;
            data.Scale                 = this.Scale;
            return(data);
        }
예제 #9
0
        public static void HandleInstanceMove(GameSession session, int mapId)
        {
            // TODO: Revise to include instancing

            if (MapEntityStorage.HasSafePortal(session.Player.MapId))
            {
                session.Player.ReturnCoord = session.FieldPlayer.Coord;
                session.Player.ReturnMapId = session.Player.MapId;
            }

            MapPortal dstPortal = MapEntityStorage.GetPortals(mapId).First(x => x.Id == 1);

            if (dstPortal == null)
            {
                return;
            }

            session.Player.MapId    = mapId;
            session.Player.Rotation = dstPortal.Rotation.ToFloat();
            session.Player.Coord    = dstPortal.Coord.ToFloat();
            session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
        }
    public void HandleCustomProperties(GameObject gameObject,
                                       IDictionary <string, string> keyValuePairs)
    {
        if (keyValuePairs.ContainsKey("PortalTo"))
        {
            MapPortal portal = gameObject.AddComponent <MapPortal>();
            string[]  parts  = keyValuePairs["PortalTo"].Split(new char[] { ':' }, 2);
            portal.target = new MapPath(parts[0], parts.Length > 1 ? parts[1] : "default");

            gameObject.GetComponent <Collider2D>().isTrigger = true;
        }

        if (keyValuePairs.ContainsKey("PortalFrom"))
        {
            StartingPoint portal = gameObject.AddComponent <StartingPoint>();
            portal.locationName = keyValuePairs["PortalFrom"];
            Collider2D collider = gameObject.GetComponent <Collider2D>();

            gameObject.transform.position = collider.bounds.center;
            GameObject.DestroyImmediate(collider);
        }

        if (keyValuePairs.ContainsKey("ObjectName"))
        {
            PrefabSpawner spawner = gameObject.AddComponent <PrefabSpawner>();
            PrefabNames   names   = getPrefabMapping();
            if (names != null)
            {
                spawner.toSpawn    = names.GetEntry(keyValuePairs["ObjectName"]).prefab;
                spawner.condition  = keyValuePairs.ContainsKey("When") ? keyValuePairs["When"] : "";
                spawner.properties = keyValuePairs;
            }

            Debug.Log(gameObject.transform.rotation);

            BoxCollider2D collider = gameObject.GetComponent <BoxCollider2D>();

            if (collider != null)
            {
                spawner.size += new Vector3(collider.offset.x, collider.offset.y, 0.0f);
                Object.DestroyImmediate(collider);
            }

            Tiled2Unity.TileObject tileObject = gameObject.GetComponent <Tiled2Unity.TileObject>();

            if (tileObject != null)
            {
                spawner.size += new Vector3(tileObject.TileWidth * 0.5f, tileObject.TileHeight * 0.5f, 0.0f);
                Object.DestroyImmediate(tileObject);
            }

            while (gameObject.transform.childCount > 0)
            {
                Object.DestroyImmediate(gameObject.transform.GetChild(0).gameObject);
            }
        }

        if (sideAttributes.Any((key) => keyValuePairs.ContainsKey(key)))
        {
            MapAttachements attatchments = gameObject.AddComponent <MapAttachements>();
            attatchments.attachments = sideAttributes.Select((name) => {
                if (keyValuePairs.ContainsKey(name))
                {
                    return(keyValuePairs[name]);
                }
                else
                {
                    return(null);
                }
            }).ToArray();
        }

        Tiled2Unity.TiledMap map = gameObject.GetComponent <Tiled2Unity.TiledMap>();

        if (map != null)
        {
            if (keyValuePairs.ContainsKey("Name"))
            {
                mapName = keyValuePairs["Name"];
            }
            else
            {
                mapName = null;
            }
            Pathfinding pathfinding = gameObject.AddComponent <Pathfinding>();
            pathfinding.width    = map.NumTilesWide;
            pathfinding.height   = map.NumTilesHigh;
            pathfinding.tileSize = new Vector2(map.TileWidth, map.TileHeight) * map.ExportScale;
            pathfinding.layers   = new List <PathfindingLayer> {
                new PathfindingLayer(PathingTypes.Walking, (1 << LayerMask.NameToLayer("L1: Barrier")) | (1 << LayerMask.NameToLayer("L1: ProjectilePassible")) | (1 << LayerMask.NameToLayer("L1: Water"))),
                new PathfindingLayer(PathingTypes.Flying, 1 << LayerMask.NameToLayer("L1: Barrier")),
            };
        }
    }
        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 = Map.Tria;

            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.Warn($"Unknown Global Event: {globalEvent.Events[selectionIndex]}");
                return;
            }

            session.Player.Mount = null;
            MapPortal portal = MapEntityStorage.GetPortals((int)map).FirstOrDefault(portal => portal.Id == 1);

            session.Player.Warp((int)map, portal.Coord.ToFloat(), portal.Rotation.ToFloat());
        }
예제 #12
0
    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());
        }
    }
예제 #13
0
        public static void HandleMove(GameSession session, PacketReader packet)
        {
            int srcMapId = packet.ReadInt();

            if (srcMapId != session.FieldManager.MapId)
            {
                return;
            }

            int       portalId  = packet.ReadInt();
            MapPortal srcPortal = MapEntityStorage.GetPortals(srcMapId)
                                  .FirstOrDefault(portal => portal.Id == portalId);

            if (srcPortal == default)
            {
                System.Console.WriteLine($"Unable to find portal:{portalId} in map:{srcMapId}");
                return;
            }

            if (!MapEntityStorage.HasSafePortal(srcMapId)) // map is instance only
            {
                HandleLeaveInstance(session);
                return;
            }

            MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                                  .FirstOrDefault(portal => portal.Target == srcMapId);

            if (dstPortal == default)
            {
                session.Player.ReturnCoord = session.FieldPlayer.Coord;
                session.Player.ReturnMapId = session.Player.MapId;
            }

            dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                        .FirstOrDefault(portal => portal.Id == srcPortal.TargetPortalId);
            if (dstPortal == default)
            {
                System.Console.WriteLine($"Unable to find portal id:{srcPortal.TargetPortalId} in map:{srcPortal.Target}");
                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(coord, dstPortal.Rotation.ToFloat(), srcPortal.Target);
        }
        public void MoveUser(int mapId, int triggerId, int boxId)
        {
            List <IFieldObject <Player> > players = Field.State.Players.Values.ToList();

            if (boxId != 0)
            {
                MapTriggerBox box = MapEntityStorage.GetTriggerBox(Field.MapId, boxId);
                List <IFieldObject <Player> > boxedPlayers = new List <IFieldObject <Player> >();
                foreach (IFieldObject <Player> player in players)
                {
                    if (FieldManager.IsPlayerInBox(box, player))
                    {
                        boxedPlayers.Add(player);
                    }
                }
                players = boxedPlayers;
            }

            // 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.Coord    = portal.Coord;
                    player.Rotation = portal.Rotation;
                    player.Value.Session.Send(UserMoveByPortalPacket.Move(player, portal.Coord, portal.Rotation));
                }
                return;
            }

            CoordF    moveCoord;
            CoordF    moveRotation;
            MapPortal dstPortal = MapEntityStorage.GetPortals(mapId).FirstOrDefault(portal => portal.Id == triggerId);

            if (dstPortal == null)
            {
                MapPlayerSpawn spawn = MapEntityStorage.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);
            }
        }
예제 #15
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            if (function == 0)
            {
                int srcMapId = packet.ReadInt();
                if (srcMapId != session.FieldManager.MapId)
                {
                    return;
                }

                int       portalId  = packet.ReadInt();
                MapPortal srcPortal = MapEntityStorage.GetPortals(srcMapId)
                                      .FirstOrDefault(portal => portal.Id == portalId);
                if (srcPortal == default)
                {
                    Logger.Warning($"Unable to find portal:{portalId} in map:{srcMapId}");
                    return;
                }

                if (!MapEntityStorage.HasSafePortal(srcMapId)) // map is instance only
                {
                    session.Player.MapId          = session.Player.ReturnMapId;
                    session.Player.Rotation       = session.FieldPlayer.Rotation;
                    session.Player.Coord          = session.Player.ReturnCoord;
                    session.Player.ReturnCoord.Z += Block.BLOCK_SIZE;
                    session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
                    return;
                }

                MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                                      .FirstOrDefault(portal => portal.Target == srcMapId);
                if (dstPortal == default)
                {
                    session.Player.ReturnCoord = session.FieldPlayer.Coord;
                    session.Player.ReturnMapId = session.Player.MapId;
                }

                dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                            .FirstOrDefault(portal => portal.Id == srcPortal.TargetPortalId);
                if (dstPortal == default)
                {
                    Logger.Warning($"Unable to find portal id:{srcPortal.TargetPortalId} in map:{srcPortal.Target}");
                    return;
                }

                // TODO: There needs to be a more centralized way to set coordinates...
                session.Player.MapId    = srcPortal.Target;
                session.Player.Rotation = dstPortal.Rotation.ToFloat();
                session.Player.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)
                    {
                        session.Player.Coord.Y -= Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == Direction.NORTH_EAST)
                    {
                        session.Player.Coord.X += Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == Direction.NORTH_WEST)
                    {
                        session.Player.Coord.Y += Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == Direction.SOUTH_WEST)
                    {
                        session.Player.Coord.X -= Block.BLOCK_SIZE;
                    }
                }

                session.Player.SafeBlock = session.Player.Coord;
                DatabaseManager.UpdateCharacter(session.Player);
                session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
            }
        }
예제 #16
0
        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.Warn($"Unable to find portal:{portalId} in map:{srcMapId}");
                return;
            }

            Portal srcPortal = fieldPortal.Value;

            switch (srcPortal.PortalType)
            {
            case PortalTypes.Field:
                break;

            case PortalTypes.DungeonReturnToLobby:
                DungeonSession dungeonSession = GameServer.DungeonManager.GetDungeonSessionByInstanceId(session.Player.InstanceId);
                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.Warn($"unknown portal type id: {srcPortal.PortalType}");
                break;
            }

            if (!MapEntityStorage.HasSafePortal(srcMapId) || srcPortal.TargetMapId == 0) // map is instance only
            {
                HandleLeaveInstance(session);
                return;
            }

            MapPortal dstPortal = MapEntityStorage.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());
        }
예제 #17
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            switch (function)
            {
            case 0:     // Cancel
                return;

            case 1:
                int objectId = packet.ReadInt();
                if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldObject <Npc> npc))
                {
                    return;     // Invalid NPC
                }
                session.Player.NpcTalk = npc;
                // If NPC is a shop, load and open the shop
                if (npc.Value.IsShop())
                {
                    ShopHandler.HandleOpen(session, npc);
                    return;
                }
                else if (npc.Value.IsBank())
                {
                    session.Send(HomeBank.OpenBank());
                    return;
                }
                else if (npc.Value.IsBeauty())
                {
                    session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 1));
                    return;
                }
                // Stellar Chest: 11004215
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk2, DialogType.TalkOption, 0));
                break;

            case 2:                                                                                                                 // Continue chat?
                int index = packet.ReadInt();                                                                                       // selection index

                if (session.Player.NpcTalk.Value.IsBeauty())                                                                        // This may need a cleaner method
                {
                    MapPortal portal = MapEntityStorage.GetPortals(session.Player.MapId).FirstOrDefault(portal => portal.Id == 99); // unsure how the portalId is determined
                    session.Send(NpcTalkPacket.Action(ActionType.Portal, "", "", portal.Id));
                    NpcMetadata npcTarget = NpcMetadataStorage.GetNpc(session.Player.NpcTalk.Value.Id);

                    switch (npcTarget.ShopId)
                    {
                    case 500:                                                                                  // Dr Dixon
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "face")); // unsure how these strings are determined
                        break;

                    case 501:         // Dr Zenko
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "skin"));
                        break;

                    case 504:         // Rosetta
                    case 509:         //Lolly
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,style"));
                        break;

                    case 505:         // Ren
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "makeup"));
                        break;

                    case 506:         // Douglas
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "itemcolor"));
                        break;

                    case 507:         // Mirror
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "mirror"));
                        break;

                    case 508:         // Paulie
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,random"));
                        break;

                    case 510:         // Mino
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,styleSave"));
                        break;
                    }
                    session.Send(UserMoveByPortalPacket.Move(session, portal.Coord.ToFloat(), portal.Rotation.ToFloat()));
                }
                session.Send(NpcTalkPacket.Close());
                session.Player.NpcTalk = null;
                break;
            }
        }