Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        private static void AnalyzeGame(FullGame fullGame)
        {
            if (fullGame.Rounds.Count == 0)
            {
                fullGame.State = GameState.NoRounds;
                return;
            }

            if (fullGame.Game.Words.Count <= 10)
            {
                fullGame.State = GameState.FewAddedWords;
                return;
            }

            if (fullGame.Game.Teams.SelectMany(t => t.Players).Count() > fullGame.Rounds.Count)
            {
                fullGame.State = GameState.FewPlayedRounds;
                return;
            }

            var numberOfPlayedWords = 0;
            var totalTime           = 0;

            foreach (var round in fullGame.Rounds)
            {
                foreach (var word in round.Words)
                {
                    if (word.Time <= 0)
                    {
                        continue;
                    }

                    numberOfPlayedWords++;
                    totalTime += word.Time;
                }
            }

            if (numberOfPlayedWords == 0)
            {
                //This case is almost impossible.
                fullGame.State = GameState.ZeroPlayedWords;
                return;
            }

            var averageTime = totalTime / numberOfPlayedWords;

            if (averageTime < 2000)
            {
                fullGame.State = GameState.LowAverageTime;
                return;
            }

            fullGame.State = GameState.Real;
        }
Exemplo n.º 3
0
        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");
                }
            }
        }
        public async Task <ActionResult> Create(FullGame rawgame)
        {
            Game game = rawgame.Game;

            try
            {
                if (ModelState.IsValid)
                {
                    List <Tag> addedTags = new List <Tag>();
                    foreach (var t in rawgame.Tags)
                    {
                        if (t.Selected)
                        {
                            addedTags.Add(t.Tag);
                        }
                    }
                    game.Tags = addedTags;
                    HttpRequestMessage  request  = CreateRequest(HttpMethod.Post, "api/Game", game);
                    HttpResponseMessage response = await Client.SendAsync(request);

                    if (!response.IsSuccessStatusCode)
                    {
                        if (response.StatusCode == HttpStatusCode.Unauthorized)
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                        return(RedirectToAction("Error", "Home"));
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 5
0
        public async Task PickUserAsync(IGuildUser pickedUser)
        {
            if (!Context.Elo.Lobby.Game.IsPickingTeams)
            {
                throw new Exception("Lobby is not picking teams at the moment.");
            }

            if (Context.Elo.Lobby.Game.Team1.Captain != Context.User.Id && Context.Elo.Lobby.Game.Team2.Captain != Context.User.Id)
            {
                throw new Exception($"{Context.User.Mention} is not a captain");
            }

            if (!Context.Elo.Lobby.Game.QueuedPlayerIDs.Contains(pickedUser.Id))
            {
                throw new Exception($"{pickedUser.Mention} is not able to be picked");
            }

            int nextTeam;

            if (Context.Elo.Lobby.Game.Team1.TurnToPick)
            {
                if (Context.User.Id != Context.Elo.Lobby.Game.Team1.Captain)
                {
                    throw new Exception("It is not your turn to pick.");
                }

                Context.Elo.Lobby.Game.Team1.Players.Add(pickedUser.Id);
                nextTeam = 2;
                Context.Elo.Lobby.Game.Team2.TurnToPick = true;
                Context.Elo.Lobby.Game.Team1.TurnToPick = false;
            }
            else
            {
                if (Context.User.Id != Context.Elo.Lobby.Game.Team2.Captain)
                {
                    throw new Exception("It is not your turn to pick.");
                }

                Context.Elo.Lobby.Game.Team2.Players.Add(pickedUser.Id);
                nextTeam = 1;
                Context.Elo.Lobby.Game.Team2.TurnToPick = false;
                Context.Elo.Lobby.Game.Team1.TurnToPick = true;
            }

            Context.Elo.Lobby.Game.QueuedPlayerIDs.Remove(pickedUser.Id);

            if (Context.Elo.Lobby.Game.QueuedPlayerIDs.Count == 1)
            {
                var lastPlayer = Context.Elo.Lobby.Game.QueuedPlayerIDs.FirstOrDefault();
                if (Context.Elo.Lobby.Game.Team1.TurnToPick)
                {
                    Context.Elo.Lobby.Game.Team1.Players.Add(lastPlayer);
                }
                else
                {
                    Context.Elo.Lobby.Game.Team2.Players.Add(lastPlayer);
                }

                Context.Elo.Lobby.Game.QueuedPlayerIDs.Remove(lastPlayer);
            }

            if (Context.Elo.Lobby.Game.QueuedPlayerIDs.Count == 0)
            {
                Context.Elo.Lobby.GamesPlayed++;

                /*
                 * await ReplyAsync("**Game has Started**\n" +
                 *               $"Team1: {string.Join(", ", Context.Elo.Lobby.Game.Team1.Players.Select(x => Context.Guild.GetUser(x)?.Mention).ToList())}\n" +
                 *               $"Team2: {string.Join(", ", Context.Elo.Lobby.Game.Team2.Players.Select(x => Context.Guild.GetUser(x)?.Mention).ToList())}\n" +
                 *               $"**Game #{Context.Elo.Lobby.GamesPlayed}**");
                 */
                Context.Server.Results.Add(new GuildModel.GameResult
                {
                    Comments   = new List <GuildModel.GameResult.Comment>(),
                    GameNumber = Context.Elo.Lobby.GamesPlayed,
                    LobbyID    = Context.Elo.Lobby.ChannelID,
                    Result     = GuildModel.GameResult._Result.Undecided,
                    Team1      = Context.Elo.Lobby.Game.Team1.Players,
                    Team2      = Context.Elo.Lobby.Game.Team2.Players,
                    Time       = DateTime.UtcNow
                });
                await FullGame.AnnounceGameAsync(Context);

                Context.Elo.Lobby.Game = new GuildModel.Lobby.CurrentGame();
            }
            else
            {
                await SimpleEmbedAsync($"**Team1 Captain** {Context.Guild.GetUser(Context.Elo.Lobby.Game.Team1.Captain)?.Mention}\n" +
                                       $"**Team1:** {string.Join(", ", Context.Elo.Lobby.Game.Team1.Players.Select(x => Context.Guild.GetUser(x)?.Mention).ToList())}\n\n" +
                                       $"**Team2 Captain** {Context.Guild.GetUser(Context.Elo.Lobby.Game.Team2.Captain)?.Mention}\n" +
                                       $"**Team2:** {string.Join(", ", Context.Elo.Lobby.Game.Team2.Players.Select(x => Context.Guild.GetUser(x)?.Mention).ToList())}\n\n" +
                                       $"**Select Your Teams using `{Context.Prefix}pick <@user>`**\n" +
                                       $"**It is Captain {nextTeam}'s Turn to pick**\n\n" +
                                       "**Player Pool**\n" +
                                       $"{string.Join(" ", Context.Elo.Lobby.Game.QueuedPlayerIDs.Select(x => Context.Guild.GetUser(x)?.Mention))}");
            }

            Context.Server.Save();
        }
Exemplo n.º 6
0
 // Start is called before the first frame update
 void Start()
 {
     Game = GameObject.Find("Game").GetComponent <FullGame>();
 }
Exemplo n.º 7
0
 void Start()
 {
     FullGame   = GameObject.Find("Game").GetComponent <FullGame>();
     ParentGame = GameObject.Find(gameObject.name.Substring(0, 1)).GetComponent <ParentGame>();
     CellNo     = gameObject.name[2] - '1';
 }
Exemplo n.º 8
0
 // Start is called before the first frame update
 void Start()
 {
     Game   = GameObject.Find("Game").GetComponent <FullGame>();
     CellNo = gameObject.name[0] - '1';
 }
Exemplo n.º 9
0
        public async Task Pick2Captains(Context context, IGuildUser pickedUser)
        {
            if (context.Elo.Lobby.PickMode == GuildModel.Lobby._PickMode.Pick2)
            {
                context.Elo.Lobby.Game.PickIndex++;
                var ind      = context.Elo.Lobby.Game.PickIndex;
                var nextTeam = 1;
                if (ind == 1)
                {
                    if (Context.User.Id != Context.Elo.Lobby.Game.Team1.Captain)
                    {
                        throw new Exception("It is not your turn to pick.");
                    }

                    nextTeam = 2;
                    Context.Elo.Lobby.Game.Team2.TurnToPick = true;
                    Context.Elo.Lobby.Game.Team1.TurnToPick = false;
                    Context.Elo.Lobby.Game.Team1.Players.Add(pickedUser.Id);
                }
                else if (ind == 2 || ind == 3)
                {
                    if (Context.User.Id != Context.Elo.Lobby.Game.Team2.Captain)
                    {
                        throw new Exception("It is not your turn to pick.");
                    }

                    if (ind == 2)
                    {
                        nextTeam = 2;
                        Context.Elo.Lobby.Game.Team1.TurnToPick = false;
                        Context.Elo.Lobby.Game.Team2.TurnToPick = true;
                    }
                    else
                    {
                        nextTeam = 1;
                        Context.Elo.Lobby.Game.Team2.TurnToPick = false;
                        Context.Elo.Lobby.Game.Team1.TurnToPick = true;
                    }

                    Context.Elo.Lobby.Game.Team2.Players.Add(pickedUser.Id);
                }
                else if (ind == 4 || ind == 5)
                {
                    if (Context.User.Id != Context.Elo.Lobby.Game.Team1.Captain)
                    {
                        throw new Exception("It is not your turn to pick.");
                    }

                    if (ind == 4)
                    {
                        nextTeam = 1;
                        Context.Elo.Lobby.Game.Team1.TurnToPick = true;
                        Context.Elo.Lobby.Game.Team2.TurnToPick = false;
                    }
                    else
                    {
                        nextTeam = 2;
                        Context.Elo.Lobby.Game.Team2.TurnToPick = true;
                        Context.Elo.Lobby.Game.Team1.TurnToPick = false;
                    }

                    Context.Elo.Lobby.Game.Team1.Players.Add(pickedUser.Id);
                }
                else
                {
                    if (Context.Elo.Lobby.Game.Team1.TurnToPick)
                    {
                        if (Context.User.Id != Context.Elo.Lobby.Game.Team1.Captain)
                        {
                            throw new Exception("It is not your turn to pick.");
                        }

                        Context.Elo.Lobby.Game.Team1.Players.Add(pickedUser.Id);
                        nextTeam = 2;
                        Context.Elo.Lobby.Game.Team2.TurnToPick = true;
                        Context.Elo.Lobby.Game.Team1.TurnToPick = false;
                    }
                    else
                    {
                        if (Context.User.Id != Context.Elo.Lobby.Game.Team2.Captain)
                        {
                            throw new Exception("It is not your turn to pick.");
                        }

                        Context.Elo.Lobby.Game.Team2.Players.Add(pickedUser.Id);
                        nextTeam = 1;
                        Context.Elo.Lobby.Game.Team2.TurnToPick = false;
                        Context.Elo.Lobby.Game.Team1.TurnToPick = true;
                    }
                }

                Context.Elo.Lobby.Game.QueuedPlayerIDs.Remove(pickedUser.Id);

                if (Context.Elo.Lobby.Game.QueuedPlayerIDs.Count == 1)
                {
                    var lastPlayer = Context.Elo.Lobby.Game.QueuedPlayerIDs.FirstOrDefault();
                    if (Context.Elo.Lobby.Game.Team1.TurnToPick)
                    {
                        Context.Elo.Lobby.Game.Team1.Players.Add(lastPlayer);
                    }
                    else
                    {
                        Context.Elo.Lobby.Game.Team2.Players.Add(lastPlayer);
                    }

                    Context.Elo.Lobby.Game.QueuedPlayerIDs.Remove(lastPlayer);
                }

                if (Context.Elo.Lobby.Game.QueuedPlayerIDs.Count == 0)
                {
                    Context.Elo.Lobby.GamesPlayed++;

                    Context.Server.Results.Add(new GuildModel.GameResult
                    {
                        Comments   = new List <GuildModel.GameResult.Comment>(),
                        GameNumber = Context.Elo.Lobby.GamesPlayed,
                        LobbyID    = Context.Elo.Lobby.ChannelID,
                        Result     = GuildModel.GameResult._Result.Undecided,
                        Team1      = Context.Elo.Lobby.Game.Team1.Players,
                        Team2      = Context.Elo.Lobby.Game.Team2.Players,
                        Time       = DateTime.UtcNow
                    });
                    await FullGame.AnnounceGameAsync(Context);

                    Context.Elo.Lobby.Game = new GuildModel.Lobby.CurrentGame();
                }
                else
                {
                    await SimpleEmbedAsync($"**Team1 Captain** {Context.Guild.GetUser(Context.Elo.Lobby.Game.Team1.Captain)?.Mention}\n" +
                                           $"**Team1:** {string.Join(", ", Context.Elo.Lobby.Game.Team1.Players.Select(x => Context.Guild.GetUser(x)?.Mention).ToList())}\n\n" +
                                           $"**Team2 Captain** {Context.Guild.GetUser(Context.Elo.Lobby.Game.Team2.Captain)?.Mention}\n" +
                                           $"**Team2:** {string.Join(", ", Context.Elo.Lobby.Game.Team2.Players.Select(x => Context.Guild.GetUser(x)?.Mention).ToList())}\n\n" +
                                           $"**Select Your Teams using `{Context.Prefix}pick <@user>`**\n" +
                                           $"**It is Captain {nextTeam}'s Turn to pick**\n\n" +
                                           "**Player Pool**\n" +
                                           $"{string.Join(" ", Context.Elo.Lobby.Game.QueuedPlayerIDs.Select(x => Context.Guild.GetUser(x)?.Mention))}");
                }

                await Context.Server.Save();
            }
        }
Exemplo n.º 10
0
 // Start is called before the first frame update
 void Start()
 {
     PlayerNo = gameObject.name[6] - '1';
     Game     = GameObject.Find("Game").GetComponent <FullGame>();
     Chance   = 1;
 }