Search in sources :

Example 11 with PayLifeCost

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

the class AthreosDiesCreatureTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    UUID creatureId = (UUID) this.getValue("creatureId");
    Card creature = game.getCard(creatureId);
    if (creature == null) {
        return true;
    }
    Player opponent = game.getPlayer(source.getFirstTarget());
    boolean paid = false;
    if (opponent != null) {
        Cost cost = new PayLifeCost(3);
        if (cost.canPay(source, source, opponent.getId(), game) && opponent.chooseUse(outcome, "Pay 3 life to prevent that " + creature.getLogName() + " returns to " + controller.getLogName() + "'s hand?", source, game) && cost.pay(source, game, source, opponent.getId(), false, null)) {
            paid = true;
        }
    }
    if ((opponent != null && paid) || game.getState().getZone(creature.getId()) != Zone.GRAVEYARD) {
        return true;
    }
    controller.moveCards(creature, Zone.HAND, source, game);
    return true;
}
Also used : Player(mage.players.Player) PayLifeCost(mage.abilities.costs.common.PayLifeCost) UUID(java.util.UUID) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card)

Example 12 with PayLifeCost

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

the class PhyrexianProcessorCreateTokenEffect 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.getName() : "") + ": " + controller.getLogName() + " pays " + payAmount + " life.");
    String key = CardUtil.getCardZoneString("lifePaid", source.getSourceId(), game);
    game.getState().setValue(key, payAmount);
    permanent.addInfo("life paid", CardUtil.addToolTipMarkTags("Life paid: " + payAmount), game);
    return true;
}
Also used : 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) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) Card(mage.cards.Card)

Example 13 with PayLifeCost

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

the class TivashGloomSummonerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    PlayerGainedLifeWatcher watcher = game.getState().getWatcher(PlayerGainedLifeWatcher.class);
    if (player == null || watcher == null) {
        return false;
    }
    int lifeGained = watcher.getLifeGained(source.getControllerId());
    Cost cost = new PayLifeCost(lifeGained);
    if (!cost.canPay(source, source, source.getControllerId(), game) || !player.chooseUse(Outcome.PutCreatureInPlay, "Pay " + lifeGained + " life?", source, game) || !cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    new DemonFlyingToken(lifeGained).putOntoBattlefield(1, game, source, source.getControllerId());
    return true;
}
Also used : Player(mage.players.Player) PlayerGainedLifeWatcher(mage.watchers.common.PlayerGainedLifeWatcher) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) DemonFlyingToken(mage.game.permanent.token.DemonFlyingToken)

Example 14 with PayLifeCost

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

the class TymnaTheWeaverWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TymnaTheWeaverWatcher watcher = game.getState().getWatcher(TymnaTheWeaverWatcher.class);
        if (watcher != null) {
            int cardsToDraw = watcher.opponentsThatGotCombatDamage(source.getControllerId(), game);
            Cost cost = new PayLifeCost(cardsToDraw);
            if (cost.canPay(source, source, source.getControllerId(), game) && cost.pay(source, game, source, source.getControllerId(), false)) {
                controller.drawCards(cardsToDraw, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost)

Example 15 with PayLifeCost

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

the class BolassCitadelPlayTheTopCardEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    // current card's part
    Card cardToCheck = game.getCard(objectId);
    if (cardToCheck == null) {
        return false;
    }
    // must be you
    if (!affectedControllerId.equals(source.getControllerId())) {
        return false;
    }
    // must be your card
    Player player = game.getPlayer(cardToCheck.getOwnerId());
    if (player == null || !player.getId().equals(affectedControllerId)) {
        return false;
    }
    // must be from your library
    Card topCard = player.getLibrary().getFromTop(game);
    if (topCard == null || !topCard.getId().equals(cardToCheck.getMainCard().getId())) {
        return false;
    }
    // allows to play/cast with alternative life cost
    if (!cardToCheck.isLand(game)) {
        PayLifeCost lifeCost = new PayLifeCost(cardToCheck.getSpellAbility().getManaCosts().manaValue());
        Costs newCosts = new CostsImpl();
        newCosts.add(lifeCost);
        newCosts.addAll(cardToCheck.getSpellAbility().getCosts());
        player.setCastSourceIdWithAlternateMana(cardToCheck.getId(), null, newCosts);
    }
    return true;
}
Also used : Player(mage.players.Player) Costs(mage.abilities.costs.Costs) CostsImpl(mage.abilities.costs.CostsImpl) PayLifeCost(mage.abilities.costs.common.PayLifeCost) 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