Search in sources :

Example 26 with SacrificeTargetCost

use of mage.abilities.costs.common.SacrificeTargetCost 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 27 with SacrificeTargetCost

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

the class DroughtAdditionalCostEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    int blackSymbols = abilityToModify.getManaCosts().getMana().getBlack();
    TargetControlledPermanent target = new TargetControlledPermanent(blackSymbols, blackSymbols, filter, true);
    target.setRequired(false);
    abilityToModify.addCost(new SacrificeTargetCost(target));
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 28 with SacrificeTargetCost

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

the class EndemicPlagueEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Permanent permanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
            permanent = ((SacrificeTargetCost) cost).getPermanents().get(0);
            break;
        }
    }
    if (permanent == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new SharesCreatureTypePredicate(permanent));
    return new DestroyAllEffect(filter, true).apply(game, source);
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 29 with SacrificeTargetCost

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

the class FalkenrathTorturerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            Permanent sacrificedCreature = ((SacrificeTargetCost) cost).getPermanents().get(0);
            Permanent sourceCreature = game.getPermanent(source.getSourceId());
            if (sacrificedCreature.hasSubtype(SubType.HUMAN, game) && sourceCreature != null) {
                sourceCreature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 30 with SacrificeTargetCost

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

the class EyeOfYawgmothEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int power = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
            power = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
            break;
        }
    }
    if (power > 0) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, power));
        controller.revealCards(source, cards, game);
        TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put into your hand"));
        if (controller.choose(Outcome.DrawCard, cards, target, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.HAND, source, game);
                cards.remove(card);
            }
        }
        controller.moveCards(cards, Zone.EXILED, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCard(mage.target.TargetCard) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)51 Cost (mage.abilities.costs.Cost)38 Player (mage.players.Player)37 Permanent (mage.game.permanent.Permanent)30 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)25 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)13 Card (mage.cards.Card)12 UUID (java.util.UUID)11 FilterCard (mage.filter.FilterCard)8 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)8 TapSourceCost (mage.abilities.costs.common.TapSourceCost)7 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)7 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)4 CardsImpl (mage.cards.CardsImpl)4 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)4 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)4 MageObject (mage.MageObject)3 Ability (mage.abilities.Ability)3 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)3 TargetPlayer (mage.target.TargetPlayer)3