public async Task ReplaceAsync(SocketGuildUser userToReplace) { var g = Context.Elo.Lobby.Game; await CheckReplacePermissionAsync(g, userToReplace.Id); if (g.QueuedPlayerIDs.Contains(userToReplace.Id)) { Context.Elo.Lobby.Game.QueuedPlayerIDs.Remove(userToReplace.Id); Context.Elo.Lobby.Game.QueuedPlayerIDs.Add(Context.User.Id); } else if (g.Team1.Players.Contains(userToReplace.Id)) { Context.Elo.Lobby.Game.QueuedPlayerIDs.Remove(userToReplace.Id); Context.Elo.Lobby.Game.QueuedPlayerIDs.Add(Context.User.Id); } else if (g.Team2.Players.Contains(userToReplace.Id)) { Context.Elo.Lobby.Game.QueuedPlayerIDs.Remove(userToReplace.Id); Context.Elo.Lobby.Game.QueuedPlayerIDs.Add(Context.User.Id); } else { throw new Exception("Unknown Player Exception!"); } Context.Server.Save(); await SimpleEmbedAsync($"Success, {Context.User.Mention} replaced {userToReplace.Mention}"); if (Context.Elo.Lobby.UserLimit >= Context.Elo.Lobby.Game.QueuedPlayerIDs.Count) { // Game is ready to be played await FullGame.FullQueueAsync(Context); } }
public async Task JoinLobbyAsync() { if (!Context.Elo.Lobby.Game.QueuedPlayerIDs.Contains(Context.User.Id)) { if (Context.Server.Settings.GameSettings.BlockMultiQueuing) { if (Context.Server.Lobbies.Any(x => x.Game.QueuedPlayerIDs.Contains(Context.User.Id) || x.Game.Team1.Players.Contains(Context.User.Id) || x.Game.Team2.Players.Contains(Context.User.Id))) { throw new Exception("MultiQueuing is disabled by the server Admins"); } } if (Context.Elo.User.Banned.Banned) { throw new Exception($"You are banned from matchmaking for another {(Context.Elo.User.Banned.ExpiryTime - DateTime.UtcNow).TotalMinutes}"); } if (Context.Elo.Lobby.Game.IsPickingTeams) { throw new Exception("Currently Picking teams. Please wait until this is completed"); } var previous = Context.Server.Results.Where(x => x.LobbyID == Context.Elo.Lobby.ChannelID && (x.Team1.Contains(Context.User.Id) || x.Team2.Contains(Context.User.Id))).OrderByDescending(x => x.Time).FirstOrDefault(); if (previous != null && previous.Time + Context.Server.Settings.GameSettings.ReQueueDelay > DateTime.UtcNow) { if (previous.Result == GuildModel.GameResult._Result.Undecided) { throw new Exception($"You must wait another {(previous.Time + Context.Server.Settings.GameSettings.ReQueueDelay - DateTime.UtcNow).TotalMinutes} minutes before rejoining the queue"); } } Context.Elo.Lobby.Game.QueuedPlayerIDs.Add(Context.User.Id); Context.Server.Save(); await SimpleEmbedAsync($"[{Context.Elo.Lobby.Game.QueuedPlayerIDs.Count}/{Context.Elo.Lobby.UserLimit}] Added {Context.User.Mention} to queue"); if (Context.Elo.Lobby.UserLimit >= Context.Elo.Lobby.Game.QueuedPlayerIDs.Count) { // Game is ready to be played await FullGame.FullQueueAsync(Context); } } else { if (Context.Server.Settings.Readability.JoinLeaveErrors) { throw new Exception("You are already queued for this lobby"); } } }