use of mage.abilities.costs.Cost 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;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class CrookedScalesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent yourGuy = game.getPermanent(getTargetPointer().getFirst(game, source));
Permanent theirGuy = game.getPermanent(source.getTargets().get(1).getFirstTarget());
boolean keepGoing;
Cost cost;
String message = "You lost the flip. Pay {3} to prevent your creature from being destroyed?";
do {
if (controller.flipCoin(source, game, true)) {
if (theirGuy != null) {
theirGuy.destroy(source, game, false);
}
keepGoing = false;
} else {
cost = ManaUtil.createManaCost(3, false);
if (!(controller.chooseUse(Outcome.Benefit, message, source, game) && cost.pay(source, game, source, controller.getId(), false, null))) {
if (yourGuy != null) {
yourGuy.destroy(source, game, false);
}
keepGoing = false;
} else {
keepGoing = true;
}
}
} while (keepGoing && controller.canRespond());
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class EldritchEvolutionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent != null && controller != null) {
int newConvertedCost = sacrificedPermanent.getManaValue() + 2;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, newConvertedCost + 1));
filter.add(CardType.CREATURE.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class NeoformReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent == null || controller == null) {
return false;
}
int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
filter.add(CardType.CREATURE.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
ContinuousEffectImpl effect = new NeoformReplacementEffect();
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
if (!controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
effect.discard();
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.abilities.costs.Cost 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;
}
Aggregations