Esempio n. 1
0
        /// <summary>
        /// Indicates a simple acknowledgement from a client.
        /// </summary>
        /// <param name="acknowledge">Favorable or unfavorable response, or null if not applicable.</param>
        public async Task Acknowledge(bool?acknowledge)
        {
            switch (GameData.MachineState)
            {
            case StateMachineState.AwaitingVetoResponse:
                if (!acknowledge.HasValue)
                {
                    throw new GameStateException("Expecting true or false response for veto approval, not null.");
                }
                else if (acknowledge.Value)
                {
                    // TODO test
                    PolicyDeck.Discard(GameData.DrawnPolicies);
                    GameData.DrawnPolicies = null;
                    await UpdateElectionTrackerAndHandleChaos("The policies were successfully vetoed!");
                }
                else
                {
                    // TODO test
                    await Director.Broadcast("Unsuccessful veto. The chancellor must choose a policy.");

                    GameData.MachineState = StateMachineState.AwaitingEnactedPolicy;
                    await Director.GetEnactedPolicy(GameData.Chancellor, GameData.DrawnPolicies, false);
                }

                break;

            case StateMachineState.AwaitingSpecialPowerAcknowledgment:
                await PrepareNextElection();

                break;

            default:
                throw new GameStateException($"{nameof(Acknowledge)} called for invalid state {GameData.MachineState}.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Indicates that one or more policies were selected by the client asked to select policies.
        /// </summary>
        /// <param name="policies">The selected policies.</param>
        public async Task PoliciesSelected(IEnumerable <PolicyType> policies)
        {
            var myPolicies = policies.ToList();

            switch (GameData.MachineState)
            {
            case StateMachineState.AwaitingEnactedPolicy:
                // TODO Validate policy was actually drawn, delivered by correct player
                if (myPolicies.Count != Constants.ChancellorPolicySelectionCount)
                {
                    throw new GameStateException("Too many policies selected for the current game state.");
                }

                var policy = myPolicies.First();
                if (policy == PolicyType.None)
                {
                    if (!AllowVetoes)
                    {
                        throw new GameStateException("Currently not eligible to veto policies.");
                    }

                    await Director.Broadcast("A veto has been requested.");

                    GameData.MachineState = StateMachineState.AwaitingVetoResponse;
                    await Director.ApproveVeto(GameData.President);

                    return;
                }

                foreach (var p in myPolicies)
                {
                    GameData.DrawnPolicies.Remove(p);
                }

                PolicyDeck.Discard(GameData.DrawnPolicies);
                GameData.DrawnPolicies = null;

                if (policy == PolicyType.Fascist)
                {
                    await Director.Broadcast("A fascist policy has been enacted!");

                    GameData.EnactedFascistPolicyCount++;
                    await DisseminateGameData();

                    if (InvokeCurrentPresidentialPower())
                    {
                        return;
                    }
                }
                else if (policy == PolicyType.Liberal)
                {
                    await Director.Broadcast("A liberal policy has been enacted!");

                    GameData.EnactedLiberalPolicyCount++;
                }

                await PrepareNextElection();

                break;

            case StateMachineState.AwaitingPresidentialPolicies:
                // TODO Validate policy was actually drawn, delivered by correct player
                // TODO Test me.
                if (myPolicies.Count != Constants.PresidentialPolicyPassCount)
                {
                    throw new GameStateException("Too many/few policies selected for the current game state.");
                }

                foreach (var p in myPolicies)
                {
                    GameData.DrawnPolicies.Remove(p);
                }

                PolicyDeck.Discard(GameData.DrawnPolicies);
                GameData.DrawnPolicies = policies.ToList();

                await Director.Broadcast("The president has offered policies to the chancellor.");

                GameData.MachineState = StateMachineState.AwaitingEnactedPolicy;
                await Director.GetEnactedPolicy(GameData.Chancellor, policies, AllowVetoes);

                break;

            default:
                throw new GameStateException($"{nameof(PoliciesSelected)} called for invalid state {GameData.MachineState}.");
            }
        }