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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations