コード例 #1
0
        public override IEffectHandle GetHandle(IGame game)
        {
            var characters  = GetCharactersWithResourceMatch();
            var description = costlyCard != null ? "card" : "effect";
            var sum         = characters.Sum(x => x.Resources);

            var builder =
                new ChoiceBuilder(GetChoiceText(), game, player);

            if (characters.Count == 0)
            {
                builder.Question("You do not have any characters with a resource match to pay this cost")
                .Answer("Ok, cancel this payment", false, (source, handle, item) => UnableToPayCost(source, handle, player));
            }
            else if (isVariableCost)
            {
                if (characters.Count == 1)
                {
                    var first   = characters.First();
                    var amounts = new List <byte>();
                    for (byte i = 1; i <= first.Resources; i++)
                    {
                        amounts.Add(i);
                    }

                    builder.Question(string.Format("'{0}' has a resource match, and this {1} has a variable cost. How many resources do you want to spend from their resource pool?", first.Title, description))
                    .Answers(amounts, (item) => item == 1 ? "1 resource" : string.Format("{0} resources", item), (source, handle, number) => PayResourcesFromCharacter(source, handle, first, player, number))
                    .LastAnswer("No, cancel this payment", false, (source, handle, item) => CancelPayingCost(source, handle, player));
                }
                else
                {
                    builder.Question(string.Format("This {0} has a variable cost. Do you want to pay this cost?", description))
                    .Answer("Yes, pay this cost", true);

                    foreach (var character in characters)
                    {
                        var amounts = new List <byte>();
                        for (byte i = 1; i <= character.Resources; i++)
                        {
                            amounts.Add(i);
                        }

                        builder.Question(string.Format("'{0}' has a resource match, and this {1} has a variable cost. How many resources do you want to spend from their resource pool?", character.Title, description))
                        .LastAnswers(amounts, (item) => item == 1 ? "1 resource" : string.Format("{0} resources", item), (source, handle, number) => PayResourcesFromCharacter(source, handle, character, player, number));
                    }

                    builder.LastAnswer("No, cancel this payment", false, (source, handle, item) => CancelPayingCost(source, handle, player));
                }
            }
            else if (numberOfResources == 0)
            {
                var character = characters.First();

                if (costlyCard != null)
                {
                    builder.Question("This card does not have any cost. Do you want to play it?")
                    .Answer("Yes, I want to play this card", true, (source, handle, item) => PayResourcesFromCharacter(game, handle, character, player, 0))
                    .LastAnswer("No, I do not want to play this card", false, (source, handle, item) => CancelPayingCost(game, handle, player));
                }
                else if (cardEffect != null)
                {
                    builder.Question("This card effect does not have any cost. Do you want to trigger it?")
                    .Answer("Yes, I want to trigger this card effect", true, (source, handle, item) => PayResourcesFromCharacter(game, handle, character, player, 0))
                    .LastAnswer("No, I do not want to trigger this card effect", false, (source, handle, item) => CancelPayingCost(game, handle, player));
                }
            }
            else if (sum < numberOfResources)
            {
                builder.Question("You do not have characters with enough resources available to pay this cost")
                .LastAnswer("Ok, cancel this payment", false, (source, handle, item) => UnableToPayCost(source, handle, player));
            }
            else if (characters.Count == 1)
            {
                var first = characters.First();
                if (first.Resources < numberOfResources)
                {
                    builder.Question(string.Format("'{0}' has a resource match but does not have enough resources to pay this cost", first.Title))
                    .LastAnswer("Ok, cancel this payment", false, (source, handle, item) => CancelPayingCost(source, handle, player));
                }
                else
                {
                    var paymentText = numberOfResources == 1 ? "1 resource" : string.Format("{0} resources", numberOfResources);

                    builder.Question(string.Format("'{0}' has a resource match, do you want to pay {1} from their resource pool?", first.Title, paymentText))
                    .Answer("Yes, make this payment", first, (source, handle, character) => PayResourcesFromCharacter(source, handle, character, player, numberOfResources))
                    .LastAnswer("No, cancel this payment", false, (source, handle, item) => CancelPayingCost(source, handle, player));
                }
            }
            else
            {
                if (numberOfResources == 1)
                {
                    builder.Question(string.Format("Multiple characters have a resource match, and this {0} costs 1 resource. Which character do you want to use to pay this cost?", description))
                    .Answers(characters, (item) => item.Title, (source, handle, character) => PayResourcesFromCharacter(source, handle, character, player, numberOfResources))
                    .LastAnswer("No, cancel this payment", false, (source, handle, item) => CancelPayingCost(source, handle, player));
                }
                else
                {
                    if (sum == numberOfResources)
                    {
                        var paymentText           = GetPaymentText(characters);
                        var charactersAndPayments = new List <Tuple <ICharacterInPlay, byte> >();

                        foreach (var character in characters)
                        {
                            charactersAndPayments.Add(new Tuple <ICharacterInPlay, byte>(character, character.Resources));
                        }

                        builder.Question("You have just enough resources on your character to pay this cost. Do you want to pay all of the resources from matching characters?")
                        .Answer(string.Format("Yes, pay {0}", paymentText), characters, (source, handle, item) => PayResourcesFromCharacters(source, handle, charactersAndPayments, player))
                        .LastAnswer("No, cancel this payment", false, (source, handle, item) => CancelPayingCost(source, handle, player));
                    }
                    else
                    {
                        var characterNames = GetCharacterNames(characters);

                        builder.Question("You have muliple characters with a resource match to pay this cost. Do you want to choose the resources to pay from matching characters?")
                        .Answer(string.Format("Yes, pay resources as follows:", characterNames), true);

                        AddPaymentAnswers(builder, characters, numberOfResources);

                        builder.LastAnswer("No, cancel this payment", false, (source, handle, item) => CancelPayingCost(source, handle, player));
                    }
                }
            }

            return(new EffectHandle(this, builder.ToChoice()));
        }
コード例 #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());
        }