Search in sources :

Example 16 with PayLifeCost

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

the class NamelessRaceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (controller == null || permanent == null) {
        return false;
    }
    int permanentsInPlay = new PermanentsOnBattlefieldCount(filter).calculate(game, source, null);
    int cardsInGraveyards = new CardsInAllGraveyardsCount(filter2).calculate(game, source, null);
    int maxAmount = Math.min(permanentsInPlay + cardsInGraveyards, controller.getLife());
    int payAmount = controller.getAmount(0, maxAmount, "Pay up to " + maxAmount + " life", game);
    Cost cost = new PayLifeCost(payAmount);
    if (!cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    Card sourceCard = game.getCard(source.getSourceId());
    game.informPlayers((sourceCard != null ? sourceCard.getLogName() : "") + ": " + controller.getLogName() + " pays " + payAmount + " life");
    game.addEffect(new SetPowerToughnessSourceEffect(payAmount, payAmount, Duration.Custom, SubLayer.CharacteristicDefining_7a), source);
    permanent.addInfo("life paid", CardUtil.addToolTipMarkTags("Life paid: " + payAmount), game);
    return true;
}
Also used : SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) CardsInAllGraveyardsCount(mage.abilities.dynamicvalue.common.CardsInAllGraveyardsCount) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) Cost(mage.abilities.costs.Cost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 17 with PayLifeCost

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

the class IndulgentTormentorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (opponent != null) {
        Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
        if (cost.canPay(source, source, opponent.getId(), game) && opponent.chooseUse(outcome, "Sacrifice a creature to prevent the card draw?", source, game)) {
            if (cost.pay(source, game, source, opponent.getId(), false, null)) {
                return true;
            }
        }
        cost = new PayLifeCost(3);
        if (cost.canPay(source, source, opponent.getId(), game) && opponent.chooseUse(outcome, "Pay 3 life to prevent the card draw?", source, game)) {
            if (cost.pay(source, game, source, opponent.getId(), false, null)) {
                return true;
            }
        }
        game.getPlayer(source.getControllerId()).drawCards(1, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 18 with PayLifeCost

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

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

the class ManaCostsImpl method handleLikePhyrexianManaCosts.

private void handleLikePhyrexianManaCosts(Player player, Ability source, Game game) {
    if (this.isEmpty()) {
        // nothing to be done without any mana costs. prevents NRE from occurring here
        return;
    }
    FilterMana phyrexianColors = player.getPhyrexianColors();
    if (player.getPhyrexianColors() == null) {
        return;
    }
    Costs<PayLifeCost> tempCosts = new CostsImpl<>();
    Iterator<T> manaCostIterator = this.iterator();
    while (manaCostIterator.hasNext()) {
        ManaCost manaCost = manaCostIterator.next();
        Mana mana = manaCost.getMana();
        /* find which color mana is in the cost and set it in the temp Phyrexian cost */
        if ((!phyrexianColors.isWhite() || mana.getWhite() <= 0) && (!phyrexianColors.isBlue() || mana.getBlue() <= 0) && (!phyrexianColors.isBlack() || mana.getBlack() <= 0) && (!phyrexianColors.isRed() || mana.getRed() <= 0) && (!phyrexianColors.isGreen() || mana.getGreen() <= 0)) {
            continue;
        }
        PayLifeCost payLifeCost = new PayLifeCost(2);
        if (payLifeCost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.LoseLife, "Pay 2 life (using an active ability) instead of " + manaCost.getMana() + '?', source, game)) {
            manaCostIterator.remove();
            tempCosts.add(payLifeCost);
        }
    }
    tempCosts.pay(source, game, source, player.getId(), false, null);
}
Also used : FilterMana(mage.filter.FilterMana) Mana(mage.Mana) FilterMana(mage.filter.FilterMana) PayLifeCost(mage.abilities.costs.common.PayLifeCost)

Example 20 with PayLifeCost

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

the class MinionOfTheWastesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (controller == null || permanent == null) {
        return false;
    }
    int payAmount = controller.getAmount(0, controller.getLife(), "Pay any amount of life", game);
    Cost cost = new PayLifeCost(payAmount);
    if (!cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    Card sourceCard = game.getCard(source.getSourceId());
    game.informPlayers((sourceCard != null ? sourceCard.getLogName() : "") + ": " + controller.getLogName() + " pays " + payAmount + " life");
    game.addEffect(new SetPowerToughnessSourceEffect(payAmount, payAmount, Duration.Custom, SubLayer.CharacteristicDefining_7a), source);
    permanent.addInfo("life paid", CardUtil.addToolTipMarkTags("Life paid: " + payAmount), game);
    return true;
}
Also used : SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card)

Aggregations

PayLifeCost (mage.abilities.costs.common.PayLifeCost)33 Player (mage.players.Player)26 Cost (mage.abilities.costs.Cost)17 Card (mage.cards.Card)12 Permanent (mage.game.permanent.Permanent)12 UUID (java.util.UUID)6 MageObject (mage.MageObject)6 CostsImpl (mage.abilities.costs.CostsImpl)3 CardsImpl (mage.cards.CardsImpl)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 Ability (mage.abilities.Ability)2 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)2 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)2 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)2 ManaCost (mage.abilities.costs.mana.ManaCost)2 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)2 SetPowerToughnessSourceEffect (mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect)2 Cards (mage.cards.Cards)2 ApprovingObject (mage.ApprovingObject)1 MageObjectReference (mage.MageObjectReference)1