public override bool ShouldPlayBeforeTargets(TimingRuleParameters p)
 {
     return
         (Stack.TopSpell != null &&
          Stack.TopSpell.Controller == p.Controller.Opponent &&
          Stack.TopSpell.Targets.Effect.Any(c => Target.Zone(c) == Zone.Graveyard));
 }
Ejemplo n.º 2
0
        public override bool ShouldPlayAfterTargets(TimingRuleParameters p)
        {
            if (!Stack.IsEmpty)
            {
                return(false);
            }

            if (!p.Controller.IsActive)
            {
                return(false);
            }

            if (Turn.Step != Step.SecondMain)
            {
                return(false);
            }

            var availableMana = p.Controller.GetAvailableManaCount(
                new ConvokeAndDelveOptions
            {
                CanUseConvoke = p.Card.Has().Convoke,
                CanUseDelve   = p.Card.Has().Delve
            });

            return(SpellsNeedMana(p, availableMana) || AbilitiesNeedMana(p, availableMana));
        }
Ejemplo n.º 3
0
        public override bool?ShouldPlay2(TimingRuleParameters p)
        {
            var controllerCount = p.Controller.Battlefield.Count(_selector);
            var opponentCount   = p.Controller.Opponent.Battlefield.Count(_selector);

            return(controllerCount > opponentCount);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public override bool ShouldPlayBeforeTargets(TimingRuleParameters p)
        {
            var level           = p.Card.Level ?? 0;
            int?costToNextLevel = null;

            foreach (var definition in _levelDefinitions)
            {
                if (definition.Max == null)
                {
                    break;
                }

                if (level < definition.Min)
                {
                    costToNextLevel = definition.Min - level;
                    break;
                }

                if (definition.Min <= level && definition.Max >= level)
                {
                    costToNextLevel = definition.Max + 1 - level;
                    break;
                }
            }

            if (costToNextLevel == null)
            {
                return(false);
            }

            var totalCostToNextLevel = _cost.Repeat(costToNextLevel.Value);

            return(p.Controller.HasMana(totalCostToNextLevel, ManaUsage.Abilities));
        }
Ejemplo n.º 6
0
        private bool AbilitiesNeedMana(TimingRuleParameters p, int availableMana)
        {
            return(p.Controller.Battlefield.Any(x =>
            {
                var manaCosts = x.GetActivatedAbilitiesManaCost();

                foreach (var manaCost in manaCosts)
                {
                    if (manaCost.Converted <= availableMana)
                    {
                        continue;
                    }

                    if (_amount == null)
                    {
                        return true;
                    }

                    if (manaCost.Converted <= availableMana + _amount)
                    {
                        return true;
                    }
                }

                return false;
            }));
        }
Ejemplo n.º 7
0
        public override bool?ShouldPlay1(TimingRuleParameters p)
        {
            if (StackHasInterestingSpells())
            {
                return(true);
            }

            if (IsBeforeYouDeclareAttackers(p.Controller))
            {
                return(p.Controller.Opponent.Battlefield.CreaturesThatCanBlock.Count() > 0);
            }

            if (IsAfterOpponentDeclaresAttackers(p.Controller))
            {
                return(Combat.Attackers.Count() > 0);
            }

            if (Stack.CanBeDestroyedByTopSpell(p.Card))
            {
                return(true);
            }

            if (IsEndOfOpponentsTurn(p.Controller))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        public override bool ShouldPlayBeforeTargets(TimingRuleParameters p)
        {
            _cached = _rules
                      .Where(rule => !rule.ShouldPlayBeforeTargets(p))
                      .ToList();

            return(_cached.Count < _rules.Count);
        }
Ejemplo n.º 9
0
        private bool EotRemoval(TimingRuleParameters p)
        {
            if (_combatOnly)
            {
                return(false);
            }

            return(IsEndOfOpponentsTurn(p.Controller));
        }
Ejemplo n.º 10
0
        public void Process1(ActivationContext c)
        {
            var p      = new TimingRuleParameters(c.Card);
            var result = ShouldPlayBeforeTargets(p);

            if (result == false)
            {
                c.CancelActivation = true;
            }
        }
Ejemplo n.º 11
0
        public override bool?ShouldPlay2(TimingRuleParameters p)
        {
            bool?result = null;

            foreach (var rule in _rules)
            {
                result = rule.ShouldPlay2(p);

                if (result == true)
                {
                    return(true);
                }
            }

            return(result);
        }
Ejemplo n.º 12
0
        public override bool ShouldPlayAfterTargets(TimingRuleParameters p)
        {
            var result = true;

            if (_minCount.HasValue)
            {
                result = result && p.Controller.Hand.Count(_selector) >= _minCount;
            }

            if (_maxCount.HasValue)
            {
                result = result && p.Controller.Hand.Count(_selector) <= _maxCount;
            }

            return(result);
        }
Ejemplo n.º 13
0
        public override bool?ShouldPlay2(TimingRuleParameters p)
        {
            foreach (var target in p.Targets <Card>())
            {
                if (TargetCreatureRemoval(target, p))
                {
                    return(true);
                }

                if (TargetAuraRemoval(target, p))
                {
                    return(true);
                }
            }

            return(EotRemoval(p));
        }
Ejemplo n.º 14
0
        public override bool?ShouldPlay2(TimingRuleParameters p)
        {
            if (Stack.IsEmpty)
            {
                return(false);
            }

            if (Stack.TopSpell.Controller == p.Controller)
            {
                return(false);
            }

            var counterCost = _counterCost(p);

            return(!counterCost.HasValue ||
                   !p.Controller.Opponent.HasMana(counterCost.Value));
        }
Ejemplo n.º 15
0
        private bool SpellsNeedMana(TimingRuleParameters p, int availableMana)
        {
            return(p.Controller.Hand.Any(x =>
            {
                if (x.ConvertedCost <= availableMana)
                {
                    return false;
                }

                if (_amount == null)
                {
                    return true;
                }

                return x.ConvertedCost <= availableMana + _amount;
            }));
        }
Ejemplo n.º 16
0
        public override bool ShouldPlayAfterTargets(TimingRuleParameters p)
        {
            if (Stack.IsEmpty)
            {
                return(false);
            }

            var spellController = Stack.TopSpell.Controller;

            if (_controlledBy == ControlledBy.Any ||
                spellController == p.Controller && _controlledBy == ControlledBy.SpellOwner ||
                spellController != p.Controller && _controlledBy == ControlledBy.Opponent)
            {
                return(_selector(Stack.TopSpell.Source.OwningCard));
            }

            return(false);
        }
Ejemplo n.º 17
0
        public override bool?ShouldPlay2(TimingRuleParameters p)
        {
            var result = true;

            var count = p.Controller.Graveyard.Count(c => _selector(c, Game));

            if (_minCount.HasValue)
            {
                result = count >= _minCount;
            }

            if (_maxCount.HasValue)
            {
                result = result && count <= _maxCount;
            }

            return(result);
        }
Ejemplo n.º 18
0
        public override bool?ShouldPlay1(TimingRuleParameters p)
        {
            // quick check before target generation
            if (Stack.IsEmpty)
            {
                if (_removalTags.Contains(EffectTag.DealDamage) || _removalTags.Contains(EffectTag.CreaturesOnly) ||
                    _removalTags.Contains(EffectTag.ReduceToughness) || _removalTags.Contains(EffectTag.Humble) || _removalTags.Contains(EffectTag.CombatDisabler))
                {
                    return(IsBeforeYouDeclareAttackers(p.Controller) || IsBeforeYouDeclareBlockers(p.Controller) ||
                           IsEndOfOpponentsTurn(p.Controller));
                }

                return(IsBeforeYouDeclareAttackers(p.Controller) || IsBeforeYouDeclareBlockers(p.Controller) ||
                       IsAfterOpponentDeclaresAttackers(p.Controller) || IsAfterOpponentDeclaresAttackers(p.Controller) ||
                       IsEndOfOpponentsTurn(p.Controller));
            }

            return(StackHasInterestingSpells());
        }
Ejemplo n.º 19
0
        private bool TargetAuraRemoval(Card target, TimingRuleParameters p)
        {
            if ((!target.Is().Aura&& !target.Is().Equipment) || target.AttachedTo == null)
            {
                return(false);
            }

            if (IsAfterOpponentDeclaresBlockers(p.Controller) && target.AttachedTo.IsBlocker)
            {
                return(true);
            }

            if (IsAfterOpponentDeclaresAttackers(p.Controller) && target.AttachedTo.IsAttacker)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 20
0
        public void Process2(ActivationContext c)
        {
            if (c.HasTargets == false)
            {
                // timing aplied before targeting, or
                // spell with no targets, evaluate just
                // one possiblility

                var p      = new TimingRuleParameters(c.Card, x: c.X);
                var result = ShouldPlayAfterTargets(p);

                if (result == false)
                {
                    c.CancelActivation = true;
                }

                return;
            }

            // check each target timing, if ok keep
            // the target otherwise remove it

            var targetsCombinations = c.TargetsCombinations().ToList();

            foreach (var targetsCombination in targetsCombinations)
            {
                var p = new TimingRuleParameters(c.Card, targetsCombination.Targets, targetsCombination.X);

                var result = ShouldPlayAfterTargets(p);
                if (result == false)
                {
                    c.RemoveTargetCombination(targetsCombination);
                }
            }

            if (c.TargetsCombinations().None())
            {
                // if not targets are appropriate, cancel activation
                c.CancelActivation = true;
            }
        }
Ejemplo n.º 21
0
        public override bool?ShouldPlay2(TimingRuleParameters p)
        {
            if (!Stack.IsEmpty)
            {
                return(false);
            }

            if (!p.Controller.IsActive)
            {
                return(false);
            }

            if (Turn.Step != Step.SecondMain)
            {
                return(false);
            }

            var availableMana = p.Controller.GetAvailableConvertedMana();

            return(SpellsNeedMana(p, availableMana) || AbilitiesNeedMana(p, availableMana));
        }
Ejemplo n.º 22
0
        private bool Sorcery(TimingRuleParameters p)
        {
            var opponentCreatureCount = p.Controller.Opponent.Battlefield.Creatures.Count();

            if (opponentCreatureCount == 0)
            {
                return(false);
            }

            if (opponentCreatureCount == 1)
            {
                return(Turn.Step == Step.FirstMain);
            }

            if (opponentCreatureCount > 2 * _count + 1)
            {
                return(false);
            }

            return(Turn.Step == Step.SecondMain);
        }
Ejemplo n.º 23
0
        private bool Instant(TimingRuleParameters p)
        {
            var opponentCreatureCount = p.Controller.Opponent.Battlefield.Creatures.Count();

            if (opponentCreatureCount == 0)
            {
                return(false);
            }

            if (opponentCreatureCount == 1)
            {
                return(IsBeforeYouDeclareBlockers(p.Controller) || IsBeforeYouDeclareAttackers(p.Controller));
            }

            if (opponentCreatureCount > 2 * _count + 1)
            {
                return(false);
            }

            return(IsEndOfOpponentsTurn(p.Controller));
        }
Ejemplo n.º 24
0
        public override bool ShouldPlayAfterTargets(TimingRuleParameters p)
        {
            foreach (var target in p.Targets <Card>())
            {
                if (target.Controller == p.Controller)
                {
                    continue;
                }

                if (TargetCreatureRemoval(target, p))
                {
                    return(true);
                }

                if (TargetAuraRemoval(target, p))
                {
                    return(true);
                }
            }

            return(EotRemoval(p));
        }
Ejemplo n.º 25
0
        private bool TargetCreatureRemoval(Card target, TimingRuleParameters p)
        {
            if (!target.Is().Creature)
            {
                return(false);
            }

            if (IsBeforeYouDeclareAttackers(p.Controller))
            {
                return(target.CanBlock());
            }

            if (IsBeforeYouDeclareBlockers(p.Controller))
            {
                return(target.IsAttacker);
            }

            if (_combatOnly)
            {
                return(false);
            }

            if (StackHasInterestingSpells())
            {
                if (Stack.TopSpell.HasEffectTargets())
                {
                    return(Stack.TopSpell.HasEffectTarget(target));
                }

                // e.g Nantuko Shade gives self a +1/+1 boost
                if (Stack.TopSpell.TargetsEffectSource)
                {
                    return(target == Stack.TopSpell.Source.OwningCard);
                }
            }

            return(false);
        }
Ejemplo n.º 26
0
 public virtual bool ShouldPlayBeforeTargets(TimingRuleParameters p)
 {
     return(true);
 }
Ejemplo n.º 27
0
 public override bool ShouldPlayAfterTargets(TimingRuleParameters p)
 {
     return(_rules.Select(rule => !_cached.Contains(rule) && rule.ShouldPlayAfterTargets(p)).Any(x => x));
 }
Ejemplo n.º 28
0
 public override bool ShouldPlayAfterTargets(TimingRuleParameters p)
 {
     return(Players.Permanents().Count(x => _selector(x) && x.Controller != p.Controller) >= _minCount);
 }
Ejemplo n.º 29
0
 public override bool?ShouldPlay1(TimingRuleParameters p)
 {
     return(p.Card.IsPermanent || p.Card.Is().Instant
 ? Instant(p)
 : Sorcery(p));
 }
Ejemplo n.º 30
0
 public override bool?ShouldPlay2(TimingRuleParameters p)
 {
     return(Players.Permanents().Count(x => _selector(x)) >= _minCount);
 }