Exemplo n.º 1
0
        /// <summary>
        /// Resolves a combat between a group of Hunters and an Opponent
        /// </summary>
        /// <param name="game">The GameState</param>
        /// <param name="huntersInvolved">A list of HunterPlayers involved in the combat</param>
        /// <param name="opponent">The Opponent type</param>
        /// <param name="logic">The artificial intelligence component</param>
        /// <returns>True if the Hunters can continue resolving Encounters</returns>
        private static bool ResolveCombat(GameState game, List<HunterPlayer> huntersInvolved, Opponent opponent,
            DecisionMaker logic)
        {
            var roundsWithoutEscaping = 0;
            var answer = -1;
            do
            {
                Console.WriteLine(
                    "Is anyone playing an Event at the start of this combat? 0= Nobody, {0}= {1}, {2}= {3}, {4}= {5}, {6}= {7}",
                    (int)Hunter.LordGodalming, Hunter.LordGodalming.Name(), (int)Hunter.DrSeward,
                    Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name(), (int)Hunter.MinaHarker,
                    Hunter.MinaHarker.Name());
                while (answer == -1)
                {
                    if (int.TryParse(Console.ReadLine(), out answer))
                    {
                        if (answer < 0 || answer > 4)
                        {
                            answer = -1;
                        }
                    }
                }
                if (answer > 0)
                {
                    var line = "";
                    Console.WriteLine("What Event is {0} playing? (cancel to cancel)", ((Hunter)answer).Name());
                    var eventBeingPlayed = Event.None;
                    while (eventBeingPlayed != Event.AdvancePlanning && eventBeingPlayed != Event.EscapeRoute &&
                           eventBeingPlayed != Event.HeroicLeap && line.ToLower() != "cancel")
                    {
                        line = Console.ReadLine();
                        eventBeingPlayed = Enumerations.GetEventFromString(line);
                    }
                    if (line.ToLower() == "cancel")
                    {
                        answer = -1;
                    }
                    else
                    {
                        switch (eventBeingPlayed)
                        {
                            case Event.AdvancePlanning:
                                game.Hunters[answer].DiscardEvent(game, Event.AdvancePlanning);
                                if (!DraculaIsPlayingDevilishPowerToCancelEvent(game, Event.AdvancePlanning, Event.AdvancePlanning, logic, game.Hunters[answer]))
                                {
                                    Console.WriteLine("One participant of your choice has combat rolls at +1 for this combat");
                                    CheckForCardsRevealedForBeingBitten(game);
                                }
                                else
                                {
                                    Console.WriteLine("Advance Planning cancelled");
                                    CheckForCardsRevealedForBeingBitten(game);
                                }
                                break;
                            case Event.EscapeRoute:
                                game.Hunters[answer].DiscardEvent(game, Event.EscapeRoute);
                                if (!DraculaIsPlayingDevilishPowerToCancelEvent(game, Event.EscapeRoute, Event.EscapeRoute, logic, game.Hunters[answer]))
                                {
                                    Console.WriteLine("Combat cancelled", ((Hunter)answer).Name());
                                    CheckForCardsRevealedForBeingBitten(game);
                                    return false;
                                }
                                CheckForCardsRevealedForBeingBitten(game);
                                Console.WriteLine("Escape Route cancelled"); break;
                            case Event.HeroicLeap:
                                game.Hunters[answer].DiscardEvent(game, Event.HeroicLeap);
                                if (!DraculaIsPlayingDevilishPowerToCancelEvent(game, Event.HeroicLeap, Event.HeroicLeap, logic, game.Hunters[answer]))
                                {
                                    Console.WriteLine("Roll a die and enter the result");
                                    var dieRoll = 0;
                                    while (dieRoll == 0)
                                    {
                                        if (int.TryParse(Console.ReadLine(), out dieRoll))
                                        {
                                            if (dieRoll < 1 || dieRoll > 7)
                                            {
                                                dieRoll = 0;
                                            }
                                        }
                                    }
                                    game.Hunters[answer].AdjustHealth(-dieRoll);
                                    game.Dracula.AdjustBlood(-dieRoll);
                                    CheckForHunterDeath(game);
                                    CheckForCardsRevealedForBeingBitten(game);
                                    return false;
                                }
                                Console.WriteLine("Heroic Leap cancelled"); break;
                                CheckForCardsRevealedForBeingBitten(game);
                        }
                    }
                    answer = -1;
                }
            } while (answer != 0);
            answer = -1;
            if (opponent == Opponent.Dracula || opponent == Opponent.NewVampire)
            {
                Console.WriteLine("Is anyone playing Garlic at the start of this combat? 0= Nobody, {0}{1}{2}{3}", huntersInvolved.Find(h => h.Hunter == Hunter.LordGodalming) == null ? "" : "1= Lord Godalming", huntersInvolved.Find(h => h.Hunter == Hunter.DrSeward) == null ? "" : "2= Dr. Seward", huntersInvolved.Find(h => h.Hunter == Hunter.VanHelsing) == null ? "" : "3= Van Helsing", huntersInvolved.Find(h => h.Hunter == Hunter.MinaHarker) == null ? "" : "4= Mina Harker");

                while (answer == -1)
                {
                    if (int.TryParse(Console.ReadLine(), out answer))
                    {
                        if (answer < 0 || answer > 4)
                        {
                            answer = -1;
                        }
                        else if (answer != 0 && huntersInvolved.Find(h => (int)h.Hunter == answer) == null)
                        {
                            answer = -1;
                        }
                    }
                    else
                    {
                        answer = -1;
                    }
                }
                if (answer > 0)
                {
                    game.Hunters[answer].DiscardItem(game, Item.Garlic);
                    CheckForCardsRevealedForBeingBitten(game);
                    roundsWithoutEscaping = 3;
                }
            }
            if (DraculaIsPlayingTrap(game, huntersInvolved, opponent, logic))
            {
                Console.WriteLine("Dracula played Trap. All of his combat rolls are at +1 for this combat");
            }
            var rageTarget = DraculaIsPlayingRageAgainstHunter(game, huntersInvolved, logic);
            if (rageTarget != Hunter.Nobody)
            {
                Console.WriteLine("Dracula played Rage against {0} and must reveal all Items", rageTarget.Name());
                DraculaLooksAtAllHuntersItems(game, game.Hunters[(int)rageTarget]);
                var itemDiscarded = logic.ChooseItemToDiscardWithRage(game, rageTarget);
                game.Hunters[(int)rageTarget].DiscardItem(game, itemDiscarded);
                Console.WriteLine("Dracula discarded {0}", itemDiscarded.Name());
                roundsWithoutEscaping = 3;
            }
            var basicHunterCombatCards = new List<ItemCard>
            {
                new ItemCard(Item.Punch),
                new ItemCard(Item.Dodge),
                new ItemCard(Item.Escape)
            };
            var enemyCombatCards = new List<EnemyCombatCard>();
            switch (opponent)
            {
                case Opponent.MinionWithKnife:
                    enemyCombatCards.Add(EnemyCombatCard.Punch);
                    enemyCombatCards.Add(EnemyCombatCard.Dodge);
                    enemyCombatCards.Add(EnemyCombatCard.Knife); break;
                case Opponent.MinionWithKnifeAndPistol:
                    enemyCombatCards.Add(EnemyCombatCard.Punch);
                    enemyCombatCards.Add(EnemyCombatCard.Dodge);
                    enemyCombatCards.Add(EnemyCombatCard.Knife);
                    enemyCombatCards.Add(EnemyCombatCard.Pistol); break;
                case Opponent.MinionWithKnifeAndRifle:
                    enemyCombatCards.Add(EnemyCombatCard.Punch);
                    enemyCombatCards.Add(EnemyCombatCard.Dodge);
                    enemyCombatCards.Add(EnemyCombatCard.Knife);
                    enemyCombatCards.Add(EnemyCombatCard.Rifle); break;
                case Opponent.Assassin:
                    enemyCombatCards.Add(EnemyCombatCard.Punch);
                    enemyCombatCards.Add(EnemyCombatCard.Dodge);
                    enemyCombatCards.Add(EnemyCombatCard.Knife);
                    enemyCombatCards.Add(EnemyCombatCard.Pistol);
                    enemyCombatCards.Add(EnemyCombatCard.Rifle); break;
                case Opponent.Dracula:
                    enemyCombatCards.Add(EnemyCombatCard.Claws);
                    enemyCombatCards.Add(EnemyCombatCard.Dodge);
                    enemyCombatCards.Add(EnemyCombatCard.EscapeMan);
                    switch (game.TimeOfDay)
                    {
                        case TimeOfDay.Twilight:
                        case TimeOfDay.Midnight:
                        case TimeOfDay.SmallHours:
                            enemyCombatCards.Add(EnemyCombatCard.EscapeBat);
                            enemyCombatCards.Add(EnemyCombatCard.EscapeMist);
                            enemyCombatCards.Add(EnemyCombatCard.Fangs);
                            enemyCombatCards.Add(EnemyCombatCard.Mesmerize);
                            enemyCombatCards.Add(EnemyCombatCard.Strength);
                            break;
                    }
                    break;
                case Opponent.NewVampire:
                    enemyCombatCards.Add(EnemyCombatCard.Claws);
                    enemyCombatCards.Add(EnemyCombatCard.Dodge);
                    switch (game.TimeOfDay)
                    {
                        case TimeOfDay.Twilight:
                        case TimeOfDay.Midnight:
                        case TimeOfDay.SmallHours:
                            enemyCombatCards.Add(EnemyCombatCard.Fangs);
                            enemyCombatCards.Add(EnemyCombatCard.Mesmerize);
                            enemyCombatCards.Add(EnemyCombatCard.Strength);
                            break;
                    }
                    break;
            }
            var firstRound = true;
            var repelled = false;
            var continueCombat = true;
            var sisterAgathaInEffect = (opponent == Opponent.Dracula && game.HunterAlly != null && game.HunterAlly.Event == Event.SisterAgatha);
            var enemyCombatCardChosen = EnemyCombatCard.None;
            var enemyTarget = Hunter.Nobody;
            while (continueCombat)
            {
                foreach (var h in huntersInvolved)
                {
                    var itemUsedByHunterLastRound = h.LastCombatCardChosen;
                    do
                    {
                        Console.WriteLine("Which combat card is {0} using this round?", h.Hunter.Name());
                        h.LastCombatCardChosen = Enumerations.GetItemFromString(Console.ReadLine());
                    } while (h.LastCombatCardChosen == Item.None);

                    if (basicHunterCombatCards.Find(card => card.Item == h.LastCombatCardChosen) == null &&
                        h.ItemsKnownToDracula.Find(item => item.Item == h.LastCombatCardChosen) == null)
                    {
                        var itemDraculaNowKnowsAbout = game.ItemDeck.Find(card => card.Item == h.LastCombatCardChosen);
                        h.ItemsKnownToDracula.Add(itemDraculaNowKnowsAbout);
                        game.ItemDeck.Remove(itemDraculaNowKnowsAbout);
                    }
                    else if (itemUsedByHunterLastRound == h.LastCombatCardChosen && basicHunterCombatCards.Find(card => card.Item == h.LastCombatCardChosen) == null)
                    {
                        var itemDraculaAlreadyKnewAbout =
                            h.ItemsKnownToDracula.Find(card => card.Item == itemUsedByHunterLastRound);
                        if (itemDraculaAlreadyKnewAbout != null)
                        {
                            h.ItemsKnownToDracula.Remove(itemDraculaAlreadyKnewAbout);
                        }
                        if (h.ItemsKnownToDracula.Find(card => card.Item == itemUsedByHunterLastRound) == null)
                        {
                            var itemDraculaNowKnowsAbout =
                                game.ItemDeck.Find(card => card.Item == h.LastCombatCardChosen);
                            h.ItemsKnownToDracula.Add(itemDraculaNowKnowsAbout);
                            game.ItemDeck.Remove(itemDraculaNowKnowsAbout);
                        }
                        h.ItemsKnownToDracula.Add(itemDraculaAlreadyKnewAbout);
                    }
                }
                enemyCombatCardChosen = logic.ChooseCombatCardAndTarget(game, huntersInvolved, enemyCombatCards,
                    firstRound, out enemyTarget, enemyCombatCardChosen, repelled, sisterAgathaInEffect,
                    roundsWithoutEscaping);
                roundsWithoutEscaping--;
                var bloodCost = false;
                if (sisterAgathaInEffect &&
                    (enemyCombatCardChosen == EnemyCombatCard.Fangs ||
                     enemyCombatCardChosen == EnemyCombatCard.EscapeBat ||
                     enemyCombatCardChosen == EnemyCombatCard.EscapeMan ||
                     enemyCombatCardChosen == EnemyCombatCard.EscapeMist))
                {
                    game.Dracula.AdjustBlood(-2);
                    bloodCost = true;
                }
                Console.WriteLine("{0} used {1} against {2}{3}", opponent.Name(), enemyCombatCardChosen.Name(),
                    enemyTarget.Name(), bloodCost ? " at a cost of 2 blood" : "");
                var line = "";
                var index = 0;
                do
                {
                    Console.WriteLine("What was the outcome? 1= Continue 2= Repel 3= Item destroyed or Event discarded 4= End");
                    line = Console.ReadLine();
                    if (int.TryParse(line, out index))
                    {
                        if (index < 1 || index > 4)
                        {
                            index = 0;
                        }
                    }
                } while (index == 0);
                switch (index)
                {
                    case 1: break;
                    case 2:
                        repelled = true; break;
                    case 3:
                        HunterPlayer hunterToDiscardCard = null;
                        if (huntersInvolved.Count == 1)
                        {
                            hunterToDiscardCard = huntersInvolved.First();
                        }
                        else
                        {
                            var hunterIndex = 0;
                            do
                            {
                                Console.Write("Whose card is being discarded? ");
                                foreach (var h in huntersInvolved)
                                {
                                    Console.Write("{0}= {1} ", (int)h.Hunter, h.Hunter.Name());
                                }
                                line = Console.ReadLine();
                                if (int.TryParse(line, out hunterIndex))
                                {
                                    foreach (var h in huntersInvolved)
                                    {
                                        if ((int)h.Hunter == hunterIndex)
                                        {
                                            hunterToDiscardCard = h;
                                            break;
                                        }
                                    }
                                }
                            } while (hunterToDiscardCard == null);
                        }
                        var itemDestroyed = Item.None;
                        var eventDiscarded = Event.None;
                        while (itemDestroyed == Item.None && eventDiscarded == Event.None)
                        {
                            Console.WriteLine("What card was discarded?");
                            line = Console.ReadLine();
                            itemDestroyed = Enumerations.GetItemFromString(line);
                            eventDiscarded = Enumerations.GetEventFromString(line);
                        }
                        if (itemDestroyed != Item.None)
                        {
                            hunterToDiscardCard.DiscardItem(game, itemDestroyed);
                        }
                        else if (eventDiscarded != Event.None)
                        {
                            hunterToDiscardCard.DiscardEvent(game, eventDiscarded);
                        }
                        break;
                    case 4:
                        continueCombat = false; break;
                }
                firstRound = false;
            }
            var health = -1;
            foreach (var h in huntersInvolved)
            {
                Console.WriteLine("How much health does {0} have now?", h.Hunter.Name());
                do
                {
                    if (int.TryParse(Console.ReadLine(), out health))
                    {
                        health = Math.Max(0, Math.Min(h.MaxHealth, health));
                        Console.WriteLine(health);
                    }
                } while (health == -1);
                h.AdjustHealth(health - h.Health);
            }
            if (opponent == Opponent.Dracula)
            {
                Console.WriteLine("How much blood does Dracula have now?");
                do
                {
                    if (int.TryParse(Console.ReadLine(), out health))
                    {
                        health = Math.Max(0, Math.Min(15, health));
                        Console.WriteLine(health);
                    }
                } while (health == -1);
                game.Dracula.AdjustBlood(health - game.Dracula.Blood);
            }
            Console.WriteLine("Did {0} win? (An end result is a no)", huntersInvolved.Count() > 1 ? "the Hunters" : huntersInvolved.First().Hunter.Name());
            string input;
            do
            {
                input = Console.ReadLine();
            } while (!"yes".StartsWith(input.ToLower()) && !"no".StartsWith(input.ToLower()));
            if ("yes".StartsWith(input.ToLower()))
            {
                if (opponent == Opponent.NewVampire)
                {
                    game.AdjustVampires(-1);
                }
                Console.WriteLine("Don't forget to register any cards discarded, such as Great Strength used to prevent health loss, Events due to enemy Knife wounds, Items consumed, etc.");
                return true;
            }
            if (opponent == Opponent.Dracula)
            {
                switch (enemyCombatCardChosen)
                {
                    case EnemyCombatCard.Mesmerize:
                        Console.WriteLine("{0} is bitten and must discard all Items!", enemyTarget.Name());
                        if (!HunterPlayingGreatStrengthToCancelBite(game, enemyTarget, logic))
                        {
                            game.Hunters[(int)enemyTarget].AdjustBites(1);
                        }
                        while (game.Hunters[(int)enemyTarget].ItemCount > 0)
                        {
                            var line = "";
                            var itemDiscarded = Item.None;
                            do
                            {
                                Console.WriteLine("What is the name of the Item being discarded?");
                                line = Console.ReadLine();
                                itemDiscarded = Enumerations.GetItemFromString(line);
                            } while (itemDiscarded == Item.None);
                            game.Hunters[(int)enemyTarget].DiscardItem(game, itemDiscarded);
                        }
                        CheckForHunterDeath(game); break;
                    case EnemyCombatCard.Fangs:
                        Console.WriteLine("{0} is bitten!", enemyTarget.Name());
                        if (!HunterPlayingGreatStrengthToCancelBite(game, enemyTarget, logic))
                        {
                            game.Hunters[(int)enemyTarget].AdjustBites(1);
                        }
                        CheckForHunterDeath(game);
                        goto case EnemyCombatCard.EscapeBat;
                    case EnemyCombatCard.EscapeBat:
                        Console.WriteLine("Dracula escaped in the form of a bat");
                        Location destination = logic.ChooseEscapeAsBatDestination(game);
                        game.Dracula.EscapeAsBat(game, destination);
                        logic.AddEscapeAsBatCardToAllTrails(game);
                        int position = -1;
                        if (game.HuntersAt(destination).Any() || destination == Location.CastleDracula)
                        {
                            position = game.Dracula.RevealCardInTrailWithLocation(destination);
                            logic.EliminateTrailsThatDoNotContainLocationAtPosition(game, destination, position);
                        }
                        else
                        {
                            logic.EliminateTrailsThatHaveHuntersAtPosition(game, game.Dracula.CurrentLocationPosition);
                        }
                        break;
                }
            }
            Console.WriteLine("Don't forget to register any cards discarded, such as Great Strength used to prevent health loss or Items due to enemy Knife wounds");
            foreach (HunterPlayer h in huntersInvolved)
            {
                h.LastCombatCardChosen = Item.None;
            }
            return false;
        }