Ejemplo n.º 1
0
        public async Task Mafia(string lead, string roles = "")
        {
            try
            {
                SocketGuildChannel voiceChannel = Context.Guild?.Channels.First(x => x.Name == "Основной");

                if (voiceChannel == null)
                {
                    throw new Exception("Ошибка. Голосовой канал не обнаружен!");
                }

                Mafia game = new Mafia(roles, voiceChannel.Users.Count);

                var leader = voiceChannel.Users.Single(s => s.Username == lead);

                var result = game.Start();

                SendToAllUsers(voiceChannel, result, leader);

                await ReplyAsync($"Бот распределил роли.\nКоличество человек в голосовом канале: {voiceChannel.Users.Count}." +
                                 $"\nВедущий - {lead}!" +
                                 $"\nУдачи и веселой игры!");

                return;
            }
            catch (Exception e)
            {
                await ReplyAsync($"Что-то пошло не по плану! {e.Message}");

                Console.WriteLine(e.StackTrace);
            }
        }
Ejemplo n.º 2
0
        public Game(
            Dictionary <string, string> userProfileMap,
            Dictionary <string, List <string> > roleToUsers,
            List <string> activePlayers,
            string mafiaTarget,
            string doctorTarget,
            string voteTarget,
            GameState currentState
            )
        {
            CurrentState = currentState;
            List <string> mafiaIdList;  // all mafias
            List <string> doctorIdList;

            roleToUsers.TryGetValue(Role.Mafia.ToString(), out mafiaIdList);
            roleToUsers.TryGetValue(Role.Doctor.ToString(), out doctorIdList);

            foreach (KeyValuePair <string, string> idWithName in userProfileMap)
            {
                Player newPlayer = new Player(idWithName.Key, idWithName.Value);
                AddPlayer(newPlayer);
                newPlayer.Vote   = voteTarget;
                newPlayer.Active = true;

                if (activePlayers.Contains(newPlayer.Id))
                {
                    // TODO: Sheriff
                    if (mafiaIdList != null && mafiaIdList.Contains(newPlayer.Id))
                    {
                        var mafia = new Mafia(newPlayer);
                        mafia.Target = mafiaTarget;
                        Mafias.Add(mafia);
                        PlayerMapping[newPlayer.Id] = mafia;
                        ActivePlayers.Add(mafia);
                    }
                    else if (doctorIdList != null && doctorIdList.Contains(newPlayer.Id))
                    {
                        var doctor = new Doctor(newPlayer);
                        doctor.Target = doctorTarget;
                        Doctors.Add(doctor);
                        PlayerMapping[newPlayer.Id] = doctor;
                        ActivePlayers.Add(doctor);
                    }
                    else
                    {
                        var village = new Villager(newPlayer);
                        PlayerMapping[newPlayer.Id] = village;
                        ActivePlayers.Add(village);
                    }
                }
                else
                {
                    newPlayer.Active            = false;
                    PlayerMapping[newPlayer.Id] = newPlayer;
                }
            }
        }
Ejemplo n.º 3
0
 public void LoadAssetbundleAsync(string path, Action <AssetBundle> callback)
 {
     StartCoroutine(Mafia.AsyncLoadAssetBundle(path, callback));
 }
Ejemplo n.º 4
0
        public void InitializeGameBoard()
        {
            FillRolesToAssign();

            Random        random          = new Random();
            List <Player> inactivePlayers = PlayerMapping.Select(p => p.Value).ToList();

            // TODO: Add some validation to make sure aggregate roles and role counts do not exceed number of players
            foreach (Role role in RolesToAssign.Keys)
            {
                if (inactivePlayers.Count == 0)
                {
                    break;
                }
                for (int i = 0; i < RolesToAssign[role]; i++)
                {
                    //remove later
                    if (role == Role.Mafia && i == 0)
                    {
                        foreach (Player p in inactivePlayers)
                        {
                            if (p.Name == "Kunyi Liu")
                            {
                                p.Role   = role;
                                p.Active = true;
                                inactivePlayers.Remove(p);

                                Mafia mafia = new Mafia(p);
                                Mafias.Add(mafia);
                                PlayerMapping[p.Id] = mafia;
                                ActivePlayers.Add(mafia);
                                break;
                            }
                        }
                        continue;
                    }
                    Player playerToModify = inactivePlayers[random.Next(inactivePlayers.Count)];

                    playerToModify.Role   = role;
                    playerToModify.Active = true;
                    inactivePlayers.Remove(playerToModify);

                    if (role == Role.Mafia)
                    {
                        Mafia mafia = new Mafia(playerToModify);
                        Mafias.Add(mafia);
                        PlayerMapping[playerToModify.Id] = mafia;
                        ActivePlayers.Add(mafia);
                    }
                    else if (role == Role.Doctor)
                    {
                        Doctor doctor = new Doctor(playerToModify);
                        Doctors.Add(doctor);
                        PlayerMapping[playerToModify.Id] = doctor;
                        ActivePlayers.Add(doctor);
                    }
                }
            }

            foreach (Player player in inactivePlayers)
            {
                player.Role   = Role.Villager;
                player.Active = true;
                Villager villager = new Villager(player);
                PlayerMapping[player.Id] = villager;
                ActivePlayers.Add(villager);
            }

            ShowRolesToPlayers();
            CurrentState = GameState.Night;
        }