コード例 #1
0
        private void PreventDamageAttackerWillDealToBlocker(TargetingRuleParameters p,
                                                            DamageSourceAndDamageTargetCandidates selectedCandidates)
        {
            var blockerAttackerPair = p.Candidates <Card>(selectorIndex: 1, selector: trgs => trgs.Effect)
                                      .Where(card => card.IsBlocker)
                                      .Select(blocker =>
            {
                var attacker = Combat.GetAttacker(blocker);

                return(new
                {
                    Target = blocker,
                    Source = QuickCombat.CanBlockerBeDealtLeathalCombatDamage(attacker, blocker)
                  ? attacker : null
                });
            })
                                      .Where(x => x.Source != null)
                                      .OrderByDescending(x => x.Target.Score)
                                      .FirstOrDefault();

            if (blockerAttackerPair != null)
            {
                selectedCandidates.DamageTarget.Add(blockerAttackerPair.Target);
                selectedCandidates.DamageSource.Add(blockerAttackerPair.Source);
            }
        }
コード例 #2
0
        public override bool?ShouldPlay2(TimingRuleParameters p)
        {
            var power     = _power.GetValue(p.X);
            var toughness = _toughness.GetValue(p.X);

            if (toughness > 0 && Stack.CanBeDealtLeathalDamageByTopSpell(p.Card))
            {
                return(true);
            }

            if (IsAfterOpponentDeclaresBlockers(p.Controller) && p.Card.IsAttacker)
            {
                return(QuickCombat.CalculateGainAttackerWouldGetIfPowerAndThoughnessWouldIncrease(
                           attacker: p.Card,
                           blockers: Combat.GetBlockers(p.Card),
                           powerIncrease: power,
                           toughnessIncrease: toughness) > 0);
            }

            if (IsAfterYouDeclareBlockers(p.Controller) && p.Card.IsBlocker)
            {
                return(QuickCombat.CalculateGainBlockerWouldGetIfPowerAndThougnessWouldIncrease(
                           blocker: p.Card,
                           attacker: Combat.GetAttacker(p.Card),
                           powerIncrease: power,
                           toughnessIncrease: toughness) > 0);
            }

            return(false);
        }
コード例 #3
0
        private List <ITarget> PreventDamageAttackerWillDealToPlayerOrBlocker()
        {
            var playerCandidate = _p.Candidates <Player>(ControlledBy.SpellOwner, selector: c => c.Effect)
                                  .Where(x => _game.Combat.WillAnyAttackerDealDamageToDefender());

            var creatureCandidates = _p.Candidates <Card>(ControlledBy.SpellOwner, selector: c => c.Effect)
                                     .Where(x => x.IsBlocker)
                                     .Where(x =>
            {
                var prevented = QuickCombat.GetAmountOfDamageThatNeedsToBePreventedToSafeBlockerFromDying(
                    blocker: x,
                    attacker: _game.Combat.GetAttacker(x));


                return(0 < prevented && prevented <= _amount);
            })
                                     .OrderByDescending(x => x.Score);

            var candidates = new List <ITarget>();

            candidates.AddRange(playerCandidate);
            candidates.AddRange(creatureCandidates);

            return(candidates);
        }
コード例 #4
0
        public bool CanKillAttacker()
        {
            if (Attacker == null)
            {
                return(false);
            }

            return(QuickCombat.CanAttackerBeDealtLeathalDamage(Attacker.Card, Card.ToEnumerable()));
        }
コード例 #5
0
        public bool WillBeDealtLeathalCombatDamage()
        {
            if (Attacker == null)
            {
                return(false);
            }

            return(QuickCombat.CanBlockerBeDealtLeathalCombatDamage(Attacker, Card));
        }
コード例 #6
0
        private List <ITarget> PreventDamageBlockerWillDealToAttacker()
        {
            var candidates = _p.Candidates <Card>(ControlledBy.SpellOwner, selector: c => c.Effect)
                             .Where(x => x.IsAttacker)
                             .Where(x =>
            {
                var prevented = QuickCombat.GetAmountOfDamageThatNeedsToBePreventedToSafeAttackerFromDying(
                    attacker: x,
                    blockers: _game.Combat.GetBlockers(x));

                return(0 < prevented && prevented <= _amount);
            })
                             .OrderByDescending(x => x.Score);

            return(candidates.Cast <ITarget>().ToList());
        }
コード例 #7
0
 protected IEnumerable <Card> GetBestBlockersForPTGain(int?powerIncrease,
                                                       int?toughnessIncrease, IEnumerable <Card> candidates)
 {
     return(candidates
            .Where(x => x.IsBlocker)
            .Select(
                x => new
     {
         Card = x,
         Gain =
             QuickCombat.CalculateGainBlockerWouldGetIfPowerAndThougnessWouldIncrease(
                 blocker: x,
                 attacker: Combat.GetAttacker(x),
                 powerIncrease: powerIncrease.Value,
                 toughnessIncrease: toughnessIncrease.Value)
     })
            .Where(x => x.Gain > 0)
            .OrderByDescending(x => x.Gain)
            .Select(x => x.Card));
 }
コード例 #8
0
        protected override IEnumerable <Targets> SelectTargets(TargetingRuleParameters p)
        {
            if (IsAfterOpponentDeclaresAttackers(p.Controller))
            {
                var attackerCandidates = p.Candidates <Card>(ControlledBy.Opponent)
                                         .Where(x => x.IsAttacker)
                                         .OrderByDescending(CalculateAttackerScoreForThisTurn);

                return(Group(attackerCandidates, p.MinTargetCount(), p.MaxTargetCount()));
            }

            if (IsAfterOpponentDeclaresBlockers(p.Controller))
            {
                var blockerCandidates = p.Candidates <Card>(ControlledBy.Opponent)
                                        .Where(x => x.IsBlocker)
                                        .OrderByDescending(x =>
                {
                    var attacker = Combat.FindBlocker(x).Attacker;

                    if (attacker == null)
                    {
                        return(0);
                    }

                    var blockers = attacker.Blockers.Select(b => b.Card);

                    if (QuickCombat.CanAttackerBeDealtLeathalDamage(attacker, blockers))
                    {
                        return(attacker.Card.Score);
                    }

                    return(0);
                }
                                                           );

                return(Group(blockerCandidates, p.MinTargetCount(), p.MaxTargetCount()));
            }

            return(None <Targets>());
        }
コード例 #9
0
        private void PreventDamageBlockerWillDealToAttacker(TargetingRuleParameters p,
                                                            DamageSourceAndDamageTargetCandidates selectedCandidates)
        {
            var blockerAttackerPair = p.Candidates <Card>(selectorIndex: 1, selector: trgs => trgs.Effect)
                                      .Where(x => x.IsAttacker)
                                      .Select(x => new
            {
                Target = x,
                Source =
                    QuickCombat.GetBlockerThatDealsLeathalDamageToAttacker(
                        attacker: x,
                        blockers: Combat.GetBlockers(x.Card()))
            })
                                      .Where(x => x.Source != null)
                                      .OrderByDescending(x => x.Target.Score)
                                      .FirstOrDefault();

            if (blockerAttackerPair != null)
            {
                selectedCandidates.DamageTarget.Add(blockerAttackerPair.Target);
                selectedCandidates.DamageSource.Add(blockerAttackerPair.Source);
            }
        }
コード例 #10
0
 public bool CanKillAnyBlocker()
 {
     return(QuickCombat.CanAttackerKillAnyBlocker(Card, _blockers.Select(x => x.Card)));
 }
コード例 #11
0
 public bool CanBeDealtLeathalCombatDamage()
 {
     return(QuickCombat.CanAttackerBeDealtLeathalDamage(Card, _blockers.Select(x => x.Card)));
 }
コード例 #12
0
 public int CalculateDefendingPlayerLifeloss()
 {
     return(QuickCombat.CalculateDefendingPlayerLifeloss(_card, _blockers.Select(x => x.Card)));
 }
コード例 #13
0
        public Results Evaluate()
        {
            var results = new Results
            {
                DamageDealt           = 0,
                ReceivesLeathalDamage = false
            };

            if (_p.Attacker == null)
            {
                return(results);
            }

            if (_p.Blocker.Is().Creature == false)
            {
                return(results);
            }

            if (_p.Blocker.CanBeDestroyed == false)
            {
                return(results);
            }


            if (_p.Blocker.HasFirstStrike && !_p.Attacker.HasFirstStrike && !_p.Attacker.Has().Indestructible)
            {
                var blockerDealtAmount = QuickCombat.GetAmountOfDamageCreature1WillDealToCreature2(
                    creature1: _p.Blocker,
                    creature2: _p.Attacker,
                    powerIncrease: _p.BlockerPowerIncrease);

                if (blockerDealtAmount > 0 && _p.Blocker.Has().Deathtouch)
                {
                    return(results);
                }

                if (blockerDealtAmount >= GetAttackerLifepoints())
                {
                    return(results);
                }
            }

            var attackerDealtAmount = QuickCombat.GetAmountOfDamageCreature1WillDealToCreature2(
                creature1: _p.Attacker,
                creature2: _p.Blocker,
                powerIncrease: _p.AttackerPowerIncrease);

            if (attackerDealtAmount == 0)
            {
                return(results);
            }


            if (_p.Attacker.Has().Deathtouch)
            {
                results.ReceivesLeathalDamage = true;
            }

            results.DamageDealt           = attackerDealtAmount;
            results.ReceivesLeathalDamage = results.ReceivesLeathalDamage || attackerDealtAmount >= GetBlockerLifepoints();

            return(results);
        }