Ejemplo n.º 1
0
        public void Warp(int mapId, CoordF coord = default, CoordF rotation = default, long instanceId = 0)
        {
            if (MapEntityStorage.HasSafePortal(MapId))
            {
                ReturnCoord = Coord;
                ReturnMapId = MapId;
            }
            Coord      = coord;
            Rotation   = rotation;
            SafeBlock  = coord;
            MapId      = mapId;
            InstanceId = instanceId;

            if (coord == default || rotation == default)
            {
                MapPlayerSpawn spawn = MapEntityStorage.GetRandomPlayerSpawn(mapId);
                if (spawn == null)
                {
                    Session.SendNotice($"Could not find a spawn for map {mapId}");
                    return;
                }
                if (coord == default)
                {
                    Coord     = spawn.Coord.ToFloat();
                    SafeBlock = spawn.Coord.ToFloat();
                }
                if (rotation == default)
                {
                    Rotation = spawn.Rotation.ToFloat();
                }
            }

            if (!UnlockedMaps.Contains(MapId))
            {
                UnlockedMaps.Add(MapId);
            }

            DatabaseManager.Characters.Update(this);
            Session.Send(FieldPacket.RequestEnter(this));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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;
                session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
            }
        }
Ejemplo n.º 5
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);
        }