Beispiel #1
0
 public async Task CancelGame(IUser user, bool forceClose = false)
 {
     if (Status > GameStatus.Cancelled && (user.Id == Hoster?.Id || forceClose))
     {
         if (Status < GameStatus.GaiaEnding)
         {
             await(await ServerHost.GetTextChannelsAsync()).First((x) => x.Name == "public_gvg").SendMessageAsync("The game has been cancelled by the host.");
         }
         Status = GameStatus.Cancelled;
         foreach (var mem in GaiaMembers.Concat(GuardianMembers).Concat(OCMembers).Concat(Civilians))
         {
             try
             {
                 await mem.RemoveRolesAsync(new IRole[] { GvG_Player, GvG_Dead_Player });
             } catch (Exception)
             {
                 // do nothing
             }
         }
         GaiaMembers.Clear();
         GuardianMembers.Clear();
         OCMembers.Clear();
         Civilians.Clear();
         PhaseTimer?.Change(Timeout.Infinite, Timeout.Infinite);
     }
 }
Beispiel #2
0
        internal EmbedBuilder GetFullStatus(bool showExactGameStatus)
        {
            var embed = new EmbedBuilder().WithTitle($"Status [{ServerHost.Name}]")
                        .WithDescription("As of " + DateTime.Now)
                        .WithThumbnailUrl(Links.LinkRewriteBlue1)
                        .AddField(new EmbedFieldBuilder()
                                  .WithName("Status Code")
                                  .WithValue(Status)
                                  );

            if (Status == GameStatus.GamePreparation)
            {
                embed = embed
                        .WithColor(new Color(0, 0, 1f))
                        .AddField(new EmbedFieldBuilder()
                                  .WithName("# of Players who Joined")
                                  .WithValue(GaiaMembers.Count + GuardianMembers.Count + OCMembers.Count + Civilians.Count));
            }
            else if (Status == GameStatus.ActionPhase || Status == GameStatus.IdlePhase)
            {
                var every_player = GaiaMembers.Concat(GuardianMembers).Concat(OCMembers).Concat(Civilians);
                embed = (Status == GameStatus.IdlePhase) ? embed.WithColor(new Color(1f, 1f, 0f)) : embed.WithColor(new Color(0.125f, 0.125f, 1f));
                var countDead = every_player.Count((x) => x.RoleIds.Contains(GvG_Dead_Player.Id));
                var listDead  = (countDead > 0) ? (" [" + every_player
                                                   .Where((x) => x.RoleIds.Contains(GvG_Dead_Player.Id))
                                                   .Select((x) => (string.IsNullOrEmpty(x.Nickname)) ? x.Username : x.Nickname)
                                                   .Aggregate((x, y) => x + ", " + y) + "]") : "";
                embed = embed.AddField(new EmbedFieldBuilder()
                                       .WithName("Day")
                                       .WithValue(Day))
                        .AddField(new EmbedFieldBuilder()
                                  .WithName("Alive Players")
                                  .WithValue(every_player
                                             .Count((x) => x.RoleIds.Contains(GvG_Player.Id))
                                             + " [" + every_player
                                             .Where((x) => x.RoleIds.Contains(GvG_Player.Id))
                                             .Select((x) => (string.IsNullOrEmpty(x.Nickname)) ? x.Username : x.Nickname)
                                             .Aggregate((x, y) => x + ", " + y) + "]"
                                             )
                                  ).AddField(new EmbedFieldBuilder()
                                             .WithName("Dead Players")
                                             .WithValue(countDead + listDead
                                                        )
                                             );
            }
            return(embed);
        }
Beispiel #3
0
        public async Task <IEnumerable <IGameRole> > GenerateCivilianRoles(int count)
        {
            var everyone = GaiaMembers.Concat(GuardianMembers).Concat(OCMembers).Concat(Civilians);
            var all_ids  = new ulong[] { Occult_Club.Id, Guardian.Id, Gaia.Id };

            if (count < 4)
            {
                var random_players = (await ServerHost.GetUsersAsync())
                                     .Where((x) => !x.IsBot &&
                                            !everyone.Contains(x) &&
                                            !x.RoleIds.Any((y) => all_ids.Contains(y))
                                            );
                var random_numbers    = new int[4 - count];
                var total_non_playing = random_players.Count();
                var resultMsg         = String.Empty;
                for (int i = 0; i < 4 - count; i++)
                {
                    do
                    {
                        random_numbers[i] = Randomizer.Next(total_non_playing);
                    } while (random_numbers.Take(i).Contains(random_numbers[i]));
                    var memToAdd = random_players.ElementAt(random_numbers[i]);
                    Civilians.Add(memToAdd);
                    await memToAdd.AddRoleAsync(GvG_Player);

                    resultMsg += $"Because there are too few players, {memToAdd.Mention} is forced to join the game as a Civilian" + ((i == count - 1) ? "" : Environment.NewLine);
                }
                Public_GvG.SendMessageAsync(resultMsg);
            }
            IEnumerable <IGameRole> result = new IGameRole[] { new Kagari(), new NormalCivilian(), new NormalCivilian(), new NormalCivilian() };

            if (count > 4)
            {
                for (int i = 0; i < count - 4; i++)
                {
                    result = result.Append(new NormalCivilian());
                }
            }
            return(result.OrderBy((x) => Randomizer.Next()));
        }