Пример #1
0
        public IEnumerable <GameAction> GetAllAttackActions(GameState gameState, Player player)
        {
            var validPlayerAttackers = gameState.Of(player).Minions.Where(x => x.CanAttack);
            var opponentChars        = gameState.OfOpponent(player).AllTargets;
            var validOpponentTargets = GetValidAttackTargets(opponentChars);

            return(validPlayerAttackers.SelectMany(attacker => validOpponentTargets.Select(target => new AttackAction(player, attacker, target))));
        }
        public IEnumerable <Character> GetValidTargets(GameState gameState, Player player)
        {
            var returnValue = new List <Character>();

            if (Target.HasFlag(Target.FriendlyMinions))
            {
                returnValue.AddRange(gameState.Of(player).Minions);
            }
            if (Target.HasFlag(Target.FriendlyFaces))
            {
                returnValue.Add(gameState.Of(player).Face);
            }
            if (Target.HasFlag(Target.EnemyMinions))
            {
                returnValue.AddRange(gameState.OfOpponent(player).Minions);
            }
            if (Target.HasFlag(Target.EnemyFaces))
            {
                returnValue.Add(gameState.OfOpponent(player).Face);
            }

            return(returnValue.Where(x => _isTargetValid(x)).Where(x => !x.IsDead));
        }
Пример #3
0
        public GameState ApplyAction(GameState gameState, GameAction gameAction)
        {
            var newGameState = TypeSwitchExpr.On <GameAction, GameState>(gameAction)
                               .Case <SummonBattlecryTargetable>(action =>
            {
                var withMinionSummoned = SummonMinnion(gameState, action);
                return(action.ApplyEffect(withMinionSummoned, action.Owner));
            })
                               .Case <SummonBattlecryTargetless>(action =>
            {
                var minionToSummon     = new Minion(action.Card);
                var withMinionSummoned = SummonMinnion(gameState, action, minionToSummon);
                return(action.ApplyBattlecry(withMinionSummoned, action.Owner, minionToSummon));
            })
                               .Case <SummonAction>(action => SummonMinnion(gameState, action))
                               .Case <CastSpell>(action =>
            {
                var handManaUpdated  = CardPlayUpdateHandMana(gameState, action.Card, action.Owner);
                var withSpellApplied = action.ApplyEffect(handManaUpdated, action.Owner);
                return(withSpellApplied.PlayerEventOccured(new Event(EventType.SpellCasted, Target.FriendlyPlayer), action.Owner));
            })
                               .Case <AttackAction>(action =>
                                                    TypeSwitchExpr.On <ITarget <Character>, GameState>(action.Target)
                                                    .Case <Minion>(target =>
            {
                var updatedAttacker     = action.Attacker.RecieveDamage(target.Attack);
                var updatedTarget       = target.RecieveDamage(action.Attacker.Attack);
                var withAttackerUpdated = gameState.UpdateCharacter(action.Attacker, updatedAttacker);
                var withBothUpdated     = withAttackerUpdated.UpdateCharacter(target, updatedTarget);
                return(withBothUpdated);
            })
                                                    .Case <Face>(target =>
                                                                 gameState.With(gameState.OfOpponent(action.Owner).With(face: x => x.RecieveDamage(action.Attacker.Attack))))
                                                    .ElseThrow())
                               .ElseThrow();

            newGameState = ProcessChainReactions(newGameState);

            return(newGameState.RemoveDeadBodies());
        }