Search in sources :

Example 1 with SacrificeSourceCost

use of mage.abilities.costs.common.SacrificeSourceCost in project mage by magefree.

the class YasharnImplacableEarthEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    boolean canTargetLand = true;
    Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
    if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY || event.getType() == GameEvent.EventType.CAST_SPELL) {
        if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
            if (permanent == null) {
                return false;
            }
        }
        Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
        for (Cost cost : ability.get().getCosts()) {
            if (cost instanceof PayLifeCost || cost instanceof PayVariableLifeCost) {
                // can't pay with life
                return true;
            }
            if (cost instanceof SacrificeSourceCost && !permanent.isLand()) {
                return true;
            }
            if (cost instanceof SacrificeTargetCost) {
                SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
                Filter filter = sacrificeCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAllCost) {
                SacrificeAllCost sacrificeAllCost = (SacrificeAllCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAttachedCost) {
                SacrificeAttachedCost sacrificeAllCost = (SacrificeAttachedCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAttachmentCost) {
                SacrificeAttachmentCost sacrificeAllCost = (SacrificeAttachmentCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeXTargetCost) {
                SacrificeXTargetCost sacrificeCost = (SacrificeXTargetCost) cost;
                Filter filter = sacrificeCost.getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) SacrificeAllCost(mage.abilities.costs.common.SacrificeAllCost) PayVariableLifeCost(mage.abilities.costs.common.PayVariableLifeCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) SacrificeXTargetCost(mage.abilities.costs.common.SacrificeXTargetCost) SacrificeAttachedCost(mage.abilities.costs.common.SacrificeAttachedCost) SacrificeAttachmentCost(mage.abilities.costs.common.SacrificeAttachmentCost) SacrificeAttachedCost(mage.abilities.costs.common.SacrificeAttachedCost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Filter(mage.filter.Filter) SacrificeAttachmentCost(mage.abilities.costs.common.SacrificeAttachmentCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) MageObject(mage.MageObject) SacrificeAllCost(mage.abilities.costs.common.SacrificeAllCost) PayVariableLifeCost(mage.abilities.costs.common.PayVariableLifeCost) SacrificeXTargetCost(mage.abilities.costs.common.SacrificeXTargetCost)

Example 2 with SacrificeSourceCost

use of mage.abilities.costs.common.SacrificeSourceCost in project mage by magefree.

the class OldGrowthTrollContinuousEffect method makeAbility.

private static final Ability makeAbility() {
    Ability activatedAbility = new SimpleActivatedAbility(new CreateTokenEffect(new TrollWarriorToken(), 1, true, false), new GenericManaCost(1));
    activatedAbility.addCost(new TapSourceCost());
    Cost cost = new SacrificeSourceCost();
    cost.setText("sacrifice this land");
    activatedAbility.addCost(cost);
    Ability ability = new SimpleStaticAbility(new GainAbilityAttachedEffect(new SimpleManaAbility(Zone.BATTLEFIELD, Mana.GreenMana(2), new TapSourceCost()), AttachmentType.AURA).setText("enchanted Forest has \"{T}: Add {G}{G}\""));
    ability.addEffect(new GainAbilityAttachedEffect(activatedAbility, AttachmentType.AURA).setText("and \"{1}, {T}, Sacrifice this land: Create a tapped 4/4 green Troll Warrior creature token with trample.\""));
    return ability;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) EnchantAbility(mage.abilities.keyword.EnchantAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleManaAbility(mage.abilities.mana.SimpleManaAbility) SpellAbility(mage.abilities.SpellAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) TrampleAbility(mage.abilities.keyword.TrampleAbility) Ability(mage.abilities.Ability) TrollWarriorToken(mage.game.permanent.token.TrollWarriorToken) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) GainAbilityAttachedEffect(mage.abilities.effects.common.continuous.GainAbilityAttachedEffect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) SimpleManaAbility(mage.abilities.mana.SimpleManaAbility) TapSourceCost(mage.abilities.costs.common.TapSourceCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost)

Example 3 with SacrificeSourceCost

use of mage.abilities.costs.common.SacrificeSourceCost in project mage by magefree.

the class PreferredSelectionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 2));
    player.lookAtCards(source, "Top two cards", cards, game);
    Cost cost = new CompositeCost(new SacrificeSourceCost(), new ManaCostsImpl<>("{2}{G}{G}"), "sacrifice this permanent and pay {2}{G}{G}");
    return new DoIfCostPaid(new LookLibraryAndPickControllerEffect(StaticValue.get(2), false, StaticValue.get(1), StaticFilters.FILTER_CARD, Zone.HAND, true, false), new LookLibraryAndPickControllerEffect(StaticValue.get(2), false, StaticValue.get(1), StaticFilters.FILTER_CARD, Zone.HAND, true, false, false, Zone.LIBRARY, false, true, false), cost).apply(game, source);
}
Also used : Player(mage.players.Player) CompositeCost(mage.abilities.costs.CompositeCost) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) LookLibraryAndPickControllerEffect(mage.abilities.effects.common.LookLibraryAndPickControllerEffect) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) Cost(mage.abilities.costs.Cost) CompositeCost(mage.abilities.costs.CompositeCost) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Aggregations

Cost (mage.abilities.costs.Cost)3 SacrificeSourceCost (mage.abilities.costs.common.SacrificeSourceCost)3 Ability (mage.abilities.Ability)2 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)2 MageObject (mage.MageObject)1 SpellAbility (mage.abilities.SpellAbility)1 DiesSourceTriggeredAbility (mage.abilities.common.DiesSourceTriggeredAbility)1 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 CompositeCost (mage.abilities.costs.CompositeCost)1 PayLifeCost (mage.abilities.costs.common.PayLifeCost)1 PayVariableLifeCost (mage.abilities.costs.common.PayVariableLifeCost)1 SacrificeAllCost (mage.abilities.costs.common.SacrificeAllCost)1 SacrificeAttachedCost (mage.abilities.costs.common.SacrificeAttachedCost)1 SacrificeAttachmentCost (mage.abilities.costs.common.SacrificeAttachmentCost)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 SacrificeXTargetCost (mage.abilities.costs.common.SacrificeXTargetCost)1 TapSourceCost (mage.abilities.costs.common.TapSourceCost)1 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)1 ConditionalInterveningIfTriggeredAbility (mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility)1