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