Search in sources :

Example 1 with PayLifeCost

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

the class EmberwildeDjinnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player == null || sourceObject == null) {
        return false;
    }
    Cost cost = new OrCost(new ManaCostsImpl("{R}{R}"), new PayLifeCost(2), "{R}{R} or 2 life");
    if (player.chooseUse(Outcome.GainControl, "Gain control of " + sourceObject.getLogName() + "?", source, game)) {
        if (cost.pay(source, game, source, player.getId(), false)) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, false, player.getId());
            effect.setTargetPointer(new FixedTarget(source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
            game.addEffect(effect, source);
            player.resetStoredBookmark(game);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) OrCost(mage.abilities.costs.OrCost) MageObject(mage.MageObject) PayLifeCost(mage.abilities.costs.common.PayLifeCost) ContinuousEffect(mage.abilities.effects.ContinuousEffect) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) OrCost(mage.abilities.costs.OrCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 2 with PayLifeCost

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

the class LorcanWarlockCollectorReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (player == null || card == null) {
        return false;
    }
    Cost cost = new PayLifeCost(card.getManaValue());
    if (!cost.canPay(source, source, source.getControllerId(), game) || !cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    game.addEffect(new AddCardSubTypeTargetEffect(SubType.WARLOCK, Duration.Custom).setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game) + 1)), source);
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card) AddCardSubTypeTargetEffect(mage.abilities.effects.common.continuous.AddCardSubTypeTargetEffect)

Example 3 with PayLifeCost

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

the class WandOfIthEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (player != null && !player.getHand().isEmpty()) {
        Cards revealed = new CardsImpl();
        Card card = player.getHand().getRandom(game);
        if (card != null) {
            revealed.add(card);
            player.revealCards(sourcePermanent.getName(), revealed, game);
            int lifeToPay = card.isLand(game) ? 1 : card.getManaValue();
            PayLifeCost cost = new PayLifeCost(lifeToPay);
            if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(outcome, "Pay " + lifeToPay + " life to prevent discarding " + card.getLogName() + "?", source, game) && cost.pay(source, game, source, player.getId(), false, null)) {
                game.informPlayers(player.getLogName() + " has paid " + lifeToPay + " life to prevent discarding " + card.getLogName() + " (" + sourcePermanent.getLogName() + ')');
            } else {
                player.discard(card, false, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) PayLifeCost(mage.abilities.costs.common.PayLifeCost) MyTurnHint(mage.abilities.hint.common.MyTurnHint)

Example 4 with PayLifeCost

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

the class ZursWeirdingReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    boolean paid = false;
    Player player = game.getPlayer(event.getTargetId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player == null || sourceObject == null) {
        return false;
    }
    Card card = player.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    // Reveals it instead
    player.revealCards(sourceObject.getIdName() + " next draw of " + player.getName() + " (" + game.getTurnNum() + '|' + game.getPhase().getType() + ')', new CardsImpl(card), game);
    // Then any other player may pay 2 life. If a player does, put that card into its owner's graveyard
    String message = "Pay 2 life to put " + card.getLogName() + " into " + player.getLogName() + " graveyard?";
    for (UUID playerId : game.getState().getPlayersInRange(player.getId(), game)) {
        if (playerId.equals(player.getId())) {
            continue;
        }
        Player otherPlayer = game.getPlayer(playerId);
        if (otherPlayer == null || !otherPlayer.canPayLifeCost(source) || otherPlayer.getLife() < 2) {
            continue;
        }
        PayLifeCost lifeCost = new PayLifeCost(2);
        if (otherPlayer.chooseUse(Outcome.Benefit, message, source, game) && lifeCost.pay(source, game, source, otherPlayer.getId(), true)) {
            player.moveCards(card, Zone.GRAVEYARD, source, game);
            return true;
        }
    }
    // This is still replacing the draw, so we still return true
    player.drawCards(1, source, game, event);
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) PayLifeCost(mage.abilities.costs.common.PayLifeCost) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 5 with PayLifeCost

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

the class ManaCostsImpl method handlePhyrexianManaCosts.

private void handlePhyrexianManaCosts(Ability abilityToPay, Player payingPlayer, Ability source, Game game) {
    if (this.isEmpty()) {
        // nothing to be done without any mana costs. prevents NRE from occurring here
        return;
    }
    Iterator<T> manaCostIterator = this.iterator();
    Costs<PayLifeCost> tempCosts = new CostsImpl<>();
    while (manaCostIterator.hasNext()) {
        ManaCost manaCost = manaCostIterator.next();
        if (!manaCost.isPhyrexian()) {
            continue;
        }
        PayLifeCost payLifeCost = new PayLifeCost(2);
        if (payLifeCost.canPay(abilityToPay, source, payingPlayer.getId(), game) && payingPlayer.chooseUse(Outcome.LoseLife, "Pay 2 life instead of " + manaCost.getText().replace("/P", "") + '?', source, game)) {
            manaCostIterator.remove();
            tempCosts.add(payLifeCost);
            this.incrPhyrexianPaid();
        }
    }
    tempCosts.pay(source, game, source, payingPlayer.getId(), false, null);
}
Also used : PayLifeCost(mage.abilities.costs.common.PayLifeCost)

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