예제 #1
0
        public async Task ReallyProcessMessage(object sender, MessageEventArgs e)
        {
            try
            {
                if (e.Channel.IsPrivate && _players.Select(p => p.User.PrivateChannel.Id).Contains(e.Channel.Id))
                {
                    switch (_state)
                    {
                    case GameState.VoteForGovernment:
                        if (!_votes.Any(p => p.Username == e.User.Name) && _players.Where(p => p.IsAlive).Select(p => p.User.Id).Contains(e.User.Id))
                        {
                            Vote v;
                            if (e.Message.Text.ToLowerInvariant() == _config.Yes.ToLowerInvariant())
                            {
                                v = Vote.Yes;
                            }
                            else if (e.Message.Text.ToLowerInvariant() == _config.No.ToLowerInvariant())
                            {
                                v = Vote.No;
                            }
                            else
                            {
                                await e.Channel.SendMessage("Unnacceptable parameter.");

                                return;
                            }
                            _votes.Add(new PlayerVote(e.User.Name, v));
                            PropertyChanged(_votes, new PropertyChangedEventArgs(nameof(_votes)));
                            while (_channel.Client.MessageQueue.Count > 10)
                            {
                                await Task.Delay(100);
                            }

                            await e.Channel.SendMessage("Your vote has been recorded.");
                        }
                        return;

                    case GameState.PresidentPicks:
                        int i;
                        if (e.User.Id == _currentPresident && Int32.TryParse(e.Message.Text, out i))
                        {
                            switch (i)
                            {
                            case 1:
                            case 2:
                            case 3:
                                await e.Channel.SendMessage($"Removing a {(_policies[i - 1] == PolicyType.Fascist ? _config.Fascist : _config.Liberal)} {_config.Policy}.");

                                Discards.Push(_policies[i - 1]);
                                _policies.RemoveAt(i - 1);
                                await _channel.SendMessage($"The {_config.President} has discarded one {_config.Policy}.");

                                await Task.Delay(1000);
                                await ChancellorPick();

                                return;

                            default:
                                await e.Channel.SendMessage("Out of range.");

                                return;
                            }
                        }
                        return;

                    case GameState.ChancellorPicks:
                        int j;
                        if (e.User.Id == _currentChancellor && Int32.TryParse(e.Message.Text, out j))
                        {
                            switch (j)
                            {
                            case 1:
                            case 2:
                                await e.Channel.SendMessage($"Removing a {(_policies[j - 1] == PolicyType.Fascist ? _config.Fascist : _config.Liberal)} {_config.Policy}.");

                                Discards.Push(_policies[j - 1]);
                                _policies.RemoveAt(j - 1);
                                await _channel.SendMessage($"The {_config.Chancellor} has discarded one {_config.Policy} and played a **{(_policies.Single() == PolicyType.Fascist ? _config.Fascist : _config.Liberal)}** {_config.Policy}.");

                                await Task.Delay(1000);

                                var space = (_policies.Single() == PolicyType.Fascist)
                                            ? FascistTrack.First(s => s.IsEmpty)
                                            : LiberalTrack.First(s => s.IsEmpty);
                                await ResolveEffect(space);

                                if (Deck.Count < 3)
                                {
                                    ReshuffleDeck();
                                }
                                return;

                            default:
                                await e.Channel.SendMessage("Out of range.");

                                return;
                            }
                        }
                        else if (_vetoUnlocked && e.Message.Text.ToLowerInvariant() == "veto")
                        {
                            if (!_takenVeto)
                            {
                                _state = GameState.ChancellorVetod;
                                await _channel.SendMessage($"The {_config.Chancellor} has opted to veto. Do you consent, Mr./Mrs. {_config.President}?");

                                return;
                            }
                            else
                            {
                                await e.Channel.SendMessage($"You have already attempted to veto.");

                                return;
                            }
                        }
                        return;

                    default:
                        return;
                    }
                }
                else if (e.Channel.Id == _channel.Id && e.User.Id == _currentPresident)
                {
                    switch (_state)
                    {
                    case GameState.StartOfTurn:
                        if (e.Message.Text.ToLowerInvariant().StartsWith("nominate"))
                        {
                            var nom = e.Message.MentionedUsers.FirstOrDefault();
                            if (nom != null && _players.Select(p => p.User.Id).Contains(nom.Id))
                            {
                                await NominatedChancellor(nom);
                            }
                        }
                        break;

                    case GameState.SpecialElection:
                        if (e.User.Id == _currentPresident && e.Message.Text.ToLowerInvariant().StartsWith("elect"))
                        {
                            var target = e.Message.MentionedUsers.FirstOrDefault();
                            if (target != null && _players.Where(p => p.IsAlive && p.User.Id != _currentChancellor && p.User.Id != _currentPresident).Select(p => p.User.Id).Contains(target.Id))
                            {
                                _specialElected = target.Id;
                                await _channel.SendMessage($"The {_config.President} has Special Elected **{target.Name}**.");
                            }
                            else
                            {
                                await _channel.SendMessage("Ineligable for nomination.");
                            }
                        }
                        break;

                    case GameState.Kill:
                        if (e.User.Id == _currentPresident && e.Message.Text.ToLowerInvariant().StartsWith("kill"))
                        {
                            var target = e.Message.MentionedUsers.FirstOrDefault();
                            if (target != null && _players.Any(p => p.User.Id == target.Id))
                            {
                                var player = _players.Single(p => p.User.Id == target.Id);
                                player.IsAlive = false;
                                await _channel.SendMessage(String.Format(_config.Kill, target.Name));

                                await Task.Delay(1500);

                                if (player.Role == _config.Hitler)
                                {
                                    await _channel.SendMessage(String.Format(_config.HitlerWasKilled, _config.Hitler, _config.LiberalParty));
                                    await EndGame();
                                }
                                else
                                {
                                    _confirmedNot.Add(target);
                                    await _channel.SendMessage(String.Format(_config.HitlerNotKilled, player.User.Name, _config.Hitler));
                                }
                            }
                        }
                        break;

                    case GameState.Investigating:
                        if (e.User.Id == _currentPresident && e.Message.Text.ToLowerInvariant().StartsWith("investigate"))
                        {
                            var target = e.Message.MentionedUsers.FirstOrDefault();
                            if (target != null && _players.Any(p => p.User.Id == target.Id))
                            {
                                await _channel.SendMessage($"The {_config.President} is investigating **{target.Name}**'s loyalty.");

                                await Task.Delay(1000);

                                var player = _players.Single(p => p.User.Id == target.Id);
                                await _channel.GetUser(_currentPresident).PrivateChannel.SendMessage($"**{player.User.Name}** belongs to the **{player.Party}**. You are not required to answer truthfully.");
                            }
                        }
                        break;

                    case GameState.ChancellorVetod:
                        if (!_takenVeto && e.User.Id == _currentPresident && e.Message.Text.ToLowerInvariant().StartsWith("veto"))
                        {
                            var s = e.Message.Text.ToLowerInvariant().Split(' ')[1];
                            if (s == "approved")
                            {
                                _electionTracker++;
                                _takenVeto = true;
                                await _channel.SendMessage($"The {_config.President} has approved the {_config.Chancellor}'s veto.");
                            }
                            else if (s == "denied")
                            {
                                _state     = GameState.ChancellorPicks;
                                _takenVeto = true;
                                await _channel.SendMessage($"The {_config.President} has denied veto and the {_config.Chancellor} must play.");
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                //Environment.Exit(0);
            }
        }
예제 #2
0
        //internal async Task TestNomination(User nominee, User pres)
        //{
        //    _chancellorNominee = nominee.Id;
        //    _state = GameState.VoteForGovernment;
        //    _votes = new List<PlayerVote>();
        //    await _channel.SendMessage($"**{pres.Name}** has nominated {nominee.Name} as their {_config.Chancellor}. PM me `{_config.Yes}` or `{_config.No}` to vote on this proposal.");
        //}

        public async Task VotingResults(List <PlayerVote> votes)
        {
            _state = GameState.VotingClosed;
            var sb = new StringBuilder($"The results are in.\n");

            foreach (var vote in _votes)
            {
                sb.AppendLine($"**{vote.Username}**: {(vote.Vote == Vote.Yes ? _config.Yes : _config.No)}");
            }

            sb.AppendLine($"Total in favor: {votes.Count(v => v.Vote == Vote.Yes)} - Total opposed: {votes.Count(v => v.Vote == Vote.No)}");

            if (_votes.Count(v => v.Vote == Vote.No) >= _votes.Count(v => v.Vote == Vote.Yes))
            {
                _electionTracker++;
                sb.Append($"The vote has **not** gone through. {_config.Parliament} is stalled and ");
                switch (_electionTracker)
                {
                case 1:
                    sb.Append(_config.ThePeopleOne);
                    await _channel.SendMessage(sb.ToString());

                    break;

                case 2:
                    sb.Append(_config.ThePeopleTwo);
                    await _channel.SendMessage(sb.ToString());

                    break;

                case 3:
                    sb.AppendLine(_config.ThePeopleThree);
                    await _channel.SendMessage(sb.ToString());

                    await Task.Delay(10000);

                    _electionTracker = 0;
                    var pol = Deck.Pop();
                    await _channel.SendMessage(String.Format(_config.ThePeopleEnacted, pol.ToString()));

                    if (pol == PolicyType.Fascist)
                    {
                        await ResolveEffect(FascistTrack.First(b => b.IsEmpty), true);
                    }
                    else
                    {
                        await ResolveEffect(LiberalTrack.First(b => b.IsEmpty), true);
                    }
                    if (Deck.Count == 0)
                    {
                        ReshuffleDeck();
                    }
                    break;
                }
            }
            else
            {
                _lastPresident     = _currentPresident;
                _currentChancellor = _chancellorNominee;
                _lastChancellor    = _chancellorNominee;
                _electionTracker   = 0;
                if (!FascistTrack[2].IsEmpty && !_confirmedNot.Select(u => u.Id).Contains(_currentChancellor))
                {
                    sb.Append($"The vote has gone through. Now to ask: **Are you {_config.Hitler}**?");
                    await _channel.SendMessage(sb.ToString());

                    await Task.Delay(TimeSpan.FromSeconds(5));

                    var chosen = _channel.GetUser(_currentChancellor);
                    if (_players.Single(p => p.Role == _config.Hitler).User.Id == _currentChancellor)
                    {
                        await _channel.SendMessage($"**{chosen.Name}** is, in fact, {_config.Hitler}. {_config.FascistsWin}");
                        await EndGame();
                    }
                    else
                    {
                        _confirmedNot.Add(chosen);
                        await _channel.SendMessage($"**{chosen.Name}** is Not {_config.Hitler} (Confirmed). {_config.Parliament} can function.");
                        await DrawPolicies();
                    }
                }
                else
                {
                    sb.Append($"The vote has gone through. {_config.Parliament} can function.");
                    await _channel.SendMessage(sb.ToString());
                    await DrawPolicies();
                }
            }
        }