Beispiel #1
0
        private void ExhaustReadyCharacter(IEffectHandle handle, IExhaustableInPlay character, IPlayer player, ExhaustChoiceStatus choiceStatus)
        {
            character.Exhaust();

            choiceStatus.Append(string.Format("{0} chose to exhaust {1}", player.Name, character.Title));

            if (choiceStatus.IsComplete)
            {
                handle.Resolve(choiceStatus.GetStatus());
            }
        }
Beispiel #2
0
        public IChoice GetChoice <T>(IGame game, IPlayer chosingPlayer, IEnumerable <IPlayer> players, string description, bool isOptional, uint minimumChosen)
            where T : ICardInPlay
        {
            var readyCharacters = GetReadyCharacters <T>(players);

            var playerNames = GetPlayerNamesList(game, players);

            string type = "character";

            if (minimumChosen == 1)
            {
                type = (typeof(T) == typeof(IHeroInPlay)) ? "1 hero" : "1 character";
            }
            else
            {
                type = (typeof(T) == typeof(IHeroInPlay)) ? string.Format("{0} heroes", minimumChosen) : string.Format("{0} characters", minimumChosen);
            }

            var builder =
                new ChoiceBuilder(string.Format("{0} must exhaust {1} they control {2}", playerNames, type, description), game, chosingPlayer, isOptional);

            if (isOptional)
            {
                builder.Question(string.Format("Do you want to {0}?", description));
            }
            else
            {
                builder.Question(string.Format("This effect is not optional. {0} must exhaust {1} they control", playerNames, type));
            }

            if (!isOptional || (isOptional && readyCharacters.All(x => x.Value.Count >= minimumChosen)))
            {
                var totalToExhaust = 0;
                if (isOptional)
                {
                    builder.Answer(string.Format("Yes, each player will exhaust {0} they control", type), 1);

                    var numberOfPlayers = readyCharacters.Where(x => x.Value.Count >= minimumChosen).Count();
                    totalToExhaust = (int)(numberOfPlayers * minimumChosen);
                }
                else
                {
                    builder.Answer(string.Format("Each player must exhaust {0} they control, if able", type), 1);

                    foreach (var count in readyCharacters.Values.Select(x => x.Count))
                    {
                        if (count >= minimumChosen)
                        {
                            totalToExhaust += (int)minimumChosen;
                        }
                        else
                        {
                            totalToExhaust += count;
                        }
                    }
                }

                var choiceStatus = new ExhaustChoiceStatus(totalToExhaust);

                foreach (var player in players)
                {
                    var items = readyCharacters[player.StateId];
                    if (items.Count == 0)
                    {
                        continue;
                    }

                    var min = items.Count >= minimumChosen ? minimumChosen : (uint)items.Count;
                    var max = min;

                    builder.Question(string.Format("{0}, which character do you want to exhaust?", player.Name), min, max)
                    .Answers(items, (item) => item.Title, (source, handle, character) => ExhaustReadyCharacter(handle, character, player, choiceStatus));
                }

                if (isOptional)
                {
                    builder.LastAnswer(string.Format("No, each player will not exhaust {0} they control", type), 2, (source, handle, item) => handle.Cancel(string.Format("{0} chose not to {1}", chosingPlayer.Name, description)));
                }
            }
            else
            {
                if (isOptional)
                {
                    if (players.Count() == 1)
                    {
                        builder.LastAnswer(string.Format("{0} does not have a ready hero to exhaust", playerNames), 1, (source, handle, item) => handle.Cancel(string.Format("{0} did not have a ready hero to exhaust, cancelling {1}", playerNames, description)));
                    }
                    else
                    {
                        builder.LastAnswer(string.Format("{0} do not each have a ready hero to exhaust", playerNames), 1, (source, handle, item) => handle.Cancel(string.Format("{0} did not each have a ready hero to exhaust, cancelling {1}", playerNames, description)));
                    }
                }
            }

            return(builder.ToChoice());
        }