Exemplo n.º 1
0
    public bool IsDungeonUsingFieldInstance(FieldManager fieldManager, Player player) //alternatively this could be: IsFieldInstanceUsed in FieldManagerFactory
    {
        // fieldManager.MapId: left map that is to be destroyed
        // player.MapId: travel destination of the player
        DungeonSession currentDungeonSession = GetDungeonSessionBySessionId(player.DungeonSessionId);

        if (currentDungeonSession == null) // is not null after entering dungeon via directory
        {
            return(false);                 // no dungeon session -> the map is unused by dungeon
        }

        // check map that is left:
        if (!currentDungeonSession.IsDungeonSessionMap(fieldManager.MapId)) // left map is not dungeon map e.g. tria
        {
            return(false);
        }

        // travel destination is a dungeon map: lobby to dungeon or dungeon to lobby
        if (!currentDungeonSession.IsDungeonSessionMap(player.MapId))
        {
            return(false);
        }

        // if travel destination is a dungeon it has to be the same instance or it does not pertain to the same DungeonSession.
        return(player.InstanceId == currentDungeonSession.DungeonInstanceId);
    }
Exemplo n.º 2
0
        public void EnterField(Player player)
        {
            // If moving maps, need to get the FieldManager for new map
            if (player.MapId != FieldManager.MapId || player.InstanceId != FieldManager.InstanceId)
            {
                FieldManager.RemovePlayer(this, FieldPlayer); // Leave previous field

                if (FieldManagerFactory.Release(FieldManager.MapId, FieldManager.InstanceId, player))
                {
                    //If instance is destroyed, reset dungeonSession
                    DungeonSession dungeonSession = GameServer.DungeonManager.GetDungeonSessionByInstanceId(FieldManager.InstanceId);
                    //check if the destroyed map was a dungeon map
                    if (dungeonSession != null && FieldManager.InstanceId == dungeonSession.DungeonInstanceId &&
                        dungeonSession.IsDungeonSessionMap(FieldManager.MapId))
                    {
                        GameServer.DungeonManager.ResetDungeonSession(player, dungeonSession);
                    }
                }

                // Initialize for new Map
                FieldManager = FieldManagerFactory.GetManager(player);
                FieldPlayer  = FieldManager.RequestFieldObject(Player);
            }

            FieldManager.AddPlayer(this, FieldPlayer); // Add player
        }
Exemplo n.º 3
0
 public static DungeonSession GetSession()
 {
     if (instance == null)
     {
         instance = new DungeonSession();
     }
     return(instance);
 }
Exemplo n.º 4
0
        public DungeonSession CreateDungeonSession(int dungeonId, DungeonType dungeonType)
        {
            int            dungeonSessionId  = GetUniqueSessionId();
            int            dungeonInstanceId = GetMapInstanceId();
            DungeonSession dungeonSession    = new DungeonSession(dungeonSessionId, dungeonId, dungeonInstanceId, dungeonType);

            DungeonSessionList.Add(dungeonSessionId, dungeonSession);
            return(dungeonSession);
        }
Exemplo n.º 5
0
    public static void HandleEnterDungeonPortal(GameSession session)
    {
        DungeonSession dungeonSession = GameServer.DungeonManager.GetDungeonSessionBySessionId(session.Player.DungeonSessionId);

        if (dungeonSession == null)
        {
            return;
        }
        session.Player.Warp(dungeonSession.DungeonMapIds.First(), instanceId: dungeonSession.DungeonInstanceId);
    }
Exemplo n.º 6
0
        public async Task SetDifficulty(CommandContext ctx, string difficulty)
        {
            // Sets the difficulty when in a save zone
            DungeonSession session =
                _context.DungeonSession.FirstOrDefault(ds => ds.UserId == Convert.ToInt64(ctx.User.Id));

            if (session == null)
            {
                _context.UserSettings.Find(Convert.ToInt64(ctx.User.Id)).DungeonDifficulty =
                    (int)Enum.Parse(typeof(UserSettingsExtension.DungeonDifficulty), difficulty);
                await _context.SaveChangesAsync();
            }
        }
Exemplo n.º 7
0
        public async Task SetDifficulty(CommandContext ctx, string difficulty)
        {
            // Sets the difficulty when in a save zone
            DungeonSession session =
                _context.DungeonSession.FirstOrDefault(ds => ds.UserId == Convert.ToInt64(ctx.User.Id));

            if (session == null)
            {
                var userSetting = _context.UserSetting.Where(setting => setting.UserId == Convert.ToInt64(ctx.User.Id)).FirstOrDefault(setting => setting.SettingId == (int)UserSetting.SettingID.DungeonDifficulty);

                userSetting.Value = ((int)Enum.Parse(typeof(UserSetting.DungeonDifficulty), difficulty)).ToString();
                await _context.SaveChangesAsync();
            }
        }
Exemplo n.º 8
0
    public static void HandleCreateDungeon(GameSession session, PacketReader packet)
    {
        int    dungeonId  = packet.ReadInt();
        bool   groupEnter = packet.ReadBool();
        Player player     = session.Player;

        if (player.DungeonSessionId != -1)
        {
            session.SendNotice("Leave your current dungeon before opening another.");
            return;
        }

        int            dungeonLobbyId = DungeonStorage.GetDungeonByDungeonId(dungeonId).LobbyFieldId;
        MapPlayerSpawn spawn          = MapEntityStorage.GetRandomPlayerSpawn(dungeonLobbyId);

        DungeonSession dungeonSession = GameServer.DungeonManager.CreateDungeonSession(dungeonId, groupEnter ? DungeonType.Group : DungeonType.Solo);

        //TODO: Send packet that greys out enter alone / enter as party when already in a dungeon session (sendRoomDungeon packet/s).
        //the session belongs to the party leader
        if (groupEnter)
        {
            Party party = player.Party;
            if (party.DungeonSessionId != -1)
            {
                session.SendNotice("Need to reset dungeon before entering another instance");
                return;
            }
            foreach (Player member in party.Members)
            {
                if (member.DungeonSessionId != -1)
                {
                    session.SendNotice($"{member.Name} is still in a Dungeon Instance.");
                    return;
                }
            }
            party.DungeonSessionId = dungeonSession.SessionId;
            party.BroadcastPacketParty(PartyPacket.PartyHelp(dungeonId));
            //TODO: Update Party with dungeon Info via party packets (0d,0e and others are involved).
        }
        else // solo join dungeon
        {
            player.DungeonSessionId = dungeonSession.SessionId;
        }
        session.Player.Warp(dungeonLobbyId, instanceId: dungeonSession.DungeonInstanceId);
        //TODO: things after map is created here: spawn doctor npc.
        //This packet sets the banner in the dungeon that displays the dungeonname and the playersize it was created for.
        //party.BroadcastPacketParty(DungeonWaitPacket.Show(dungeonId, DungeonStorage.GetDungeonByDungeonId(dungeonId).MaxUserCount));
    }
Exemplo n.º 9
0
    public static void HandleEnterDungeonButton(GameSession session)
    {
        Party          party          = session.Player.Party;
        DungeonSession dungeonSession = GameServer.DungeonManager.GetDungeonSessionBySessionId(party.DungeonSessionId);

        if (dungeonSession == null) //Can be removed when enter dungeon button is removed on dungeonsession deletion.
        {
            return;
        }
        if (dungeonSession.IsDungeonSessionMap(session.Player.MapId))
        {
            session.SendNotice("You are already in a dungeon");
            return;
        }
        session.Player.Warp(dungeonSession.DungeonLobbyId, instanceId: dungeonSession.DungeonInstanceId);
    }
Exemplo n.º 10
0
    public void ResetDungeonSession(Player player, DungeonSession dungeonSession)
    {
        if (dungeonSession is null)
        {
            return;
        }

        RemoveDungeonSession(dungeonSession.SessionId);
        // if last player leaves lobby or dungeon map -> destroy dungeonSession.
        if (dungeonSession.DungeonType is DungeonType.Group && player.Party is not null)
        {
            player.Party.DungeonSessionId = -1;
            return;
        }

        player.DungeonSessionId = -1;
    }
Exemplo n.º 11
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());
        }
Exemplo n.º 12
0
        public async Task ContinueLength(CommandContext ctx, string length)
        {
            DungeonSession session =
                _context.DungeonSession.FirstOrDefault(ds => ds.UserId == Convert.ToInt64(ctx.User.Id));

            DungeonLogic.Dungeon dungeon = null;
            Room room = null;

            DungeonLogic.Dungeon.DungeonDifficulty dungeonDifficulty = DungeonLogic.Dungeon.DungeonDifficulty.Medium;
            var difficulty = _context.UserSetting.Where(setting => setting.UserId == Convert.ToInt64(ctx.User.Id)).FirstOrDefault(setting => setting.SettingId == (int)UserSetting.SettingID.DungeonDifficulty);

            if (difficulty == null)
            {
                dungeonDifficulty = DungeonLogic.Dungeon.DungeonDifficulty.Medium;
            }

            if (difficulty != null)
            {
                dungeonDifficulty = (DungeonLogic.Dungeon.DungeonDifficulty)Int32.Parse(difficulty.Value);
            }

            if (session != null)
            {
                // Pre-Existing Session found
                dungeon = JsonConvert.DeserializeObject <DungeonLogic.Dungeon>(session.DungeonData);
                room    = dungeon.Rooms.First(r => r.RoomID == Guid.Parse(session.RoomGuid));
            }
            else
            {
                DungeonLogic.Dungeon.DungeonLength dungeonLength =
                    (DungeonLogic.Dungeon.DungeonLength)Enum.Parse(typeof(DungeonLogic.Dungeon.DungeonLength), length);

                // Start new Session
                dungeon = new DungeonLogic.Dungeon(1, dungeonLength, dungeonDifficulty);
                room    = dungeon.Rooms.First();

                try
                {
                    var dungeonJson = JsonConvert.SerializeObject(dungeon, new JsonSerializerSettings
                    {
                        TypeNameHandling = TypeNameHandling.Auto
                    });

                    session = new DungeonSession
                    {
                        DungeonData = dungeonJson,
                        UserId      = Convert.ToInt64(ctx.User.Id),
                        RoomGuid    = room.RoomID.ToString()
                    };

                    await _context.DungeonSession.AddAsync(session);

                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            }

            room.SetDifficulty(dungeonDifficulty);

            //Enter Room Message
            DiscordEmbedBuilder builder = new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Grayple,
                Description = room.GetText(DungeonTextExtension.TextType.RoomEnter)
            };

            await ctx.RespondAsync(embed : builder.Build());

            await ctx.TriggerTypingAsync();

            await Task.Delay(room.WaitAfterMessage);

            if (room.Type == DungeonTextExtension.RoomType.LesserMob || room.Type == DungeonTextExtension.RoomType.Boss)
            {
                //Greeting Message
                builder = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Chartreuse,
                    Description = room.GetText(DungeonTextExtension.TextType.Greeting)
                };

                await ctx.RespondAsync(embed : builder.Build());

                await ctx.TriggerTypingAsync();

                await Task.Delay(room.WaitAfterMessage);
            }

            // Main Message (Task or Chest opening f.e.)
            builder = new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Blue,
                Description = room.GetText(DungeonTextExtension.TextType.Main)
            };

            await ctx.RespondAsync(embed : builder.Build());

            await Task.Delay(room.WaitAfterMessage);

            if (room.Type == DungeonTextExtension.RoomType.Loot)
            {
                // TODO: Save Loot
                builder = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Chartreuse,
                    Description = "The Items have been placed into your current Inventory."
                };

                await ctx.RespondAsync(embed : builder.Build());

                await ctx.TriggerTypingAsync();

                await Task.Delay(room.WaitAfterMessage);
            }
            else if (room.Type == DungeonTextExtension.RoomType.LesserMob)
            {
                await ctx.RespondAsync("Did you finish my Task?");

                var m = await ctx.Client.GetInteractivity().WaitForMessageAsync(
                    x => x.Channel.Id == ctx.Channel.Id && x.Author.Id == ctx.Member.Id &&
                    Helpers.RegexHelper.ConfirmRegex.IsMatch(x.Content),
                    TimeSpan.FromMilliseconds(room.WaitAfterMessage / 4));

                if (!m.TimedOut)
                {
                    await ctx.RespondAsync("Well, time\'s up.");

                    // TODO: On Loose

                    // Loose Message
                    builder = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = room.GetText(DungeonTextExtension.TextType.Failure)
                    };

                    await ctx.RespondAsync(embed : builder.Build());

                    await ctx.TriggerTypingAsync();

                    await Task.Delay(room.WaitAfterMessage);
                }

                // If Task Successful
                if (Helpers.RegexHelper.YesRegex.IsMatch(m.Result.Content))
                {
                    // Win Message
                    builder = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Chartreuse,
                        Description = room.GetText(DungeonTextExtension.TextType.Success)
                    };

                    await ctx.RespondAsync(embed : builder.Build());

                    await ctx.TriggerTypingAsync();

                    await Task.Delay(room.WaitAfterMessage);
                }

                // If Task failed
                else if (Helpers.RegexHelper.NoRegex.IsMatch(m.Result.Content))
                {
                    // TODO: On Loose Loose Message
                    builder = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = room.GetText(DungeonTextExtension.TextType.Failure)
                    };

                    await ctx.RespondAsync(embed : builder.Build());

                    await ctx.TriggerTypingAsync();

                    await Task.Delay(room.WaitAfterMessage);
                }
            }

            if (room.AdjacentRooms == null || room.AdjacentRooms.Length == 0)
            {
                // TODO: Last Room. End Dungeon
            }

            await _context.SaveChangesAsync();
        }
 public List <DungeonCoridorModel> LoadDungeonCoridorSession()
 {
     return(DungeonSession.GetSession().GetDungeonCoridor());
 }
 public List <DungeonModelNew> LoadDungeonRoomSession()
 {
     return(DungeonSession.GetSession().GetDungeonRoom());
 }
 public void SaveSession()
 {
     DungeonSession.GetSession().SetDungeonRoom(dungeonModel);
     DungeonSession.GetSession().SetDungeonCoridor(dungeonCoridorModel);
 }