use of mage.abilities.costs.Cost in project mage by magefree.
the class HolisticWisdomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getFirstTarget());
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
for (Cost cost : source.getCosts()) {
if (cost instanceof ExileFromHandCost) {
List<CardType> cardtypes = new ArrayList<>();
ExileFromHandCost exileCost = (ExileFromHandCost) cost;
for (CardType cardtype : exileCost.getCards().get(0).getCardType(game)) {
cardtypes.add(cardtype);
}
for (CardType cardtype : card.getCardType(game)) {
if (cardtypes.contains(cardtype)) {
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), game));
return effect.apply(game, source);
}
}
}
}
}
return false;
}
use of mage.abilities.costs.Cost 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.Cost in project mage by magefree.
the class LegacyOfTheBelovedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
Permanent p = (Permanent) game.getLastKnownInformation(((SacrificeTargetCost) cost).getPermanents().get(0).getId(), Zone.BATTLEFIELD);
if (p != null) {
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, p.getManaValue()));
TargetCardInLibrary target = new TargetCardInLibrary(0, 2, filter);
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.searchLibrary(target, source, game)) {
player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
player.shuffleLibrary(source, game);
return true;
}
}
}
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class PowerSinkCounterUnlessPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell != null) {
Player player = game.getPlayer(spell.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null && controller != null && sourceObject != null) {
int amount = source.getManaCostsToPay().getX();
if (amount > 0) {
Cost cost = ManaUtil.createManaCost(amount, true);
if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " to prevent?", source, game)) {
if (cost.pay(source, game, source, player.getId(), false)) {
game.informPlayers(sourceObject.getName() + ": additional cost was paid");
return true;
}
}
game.informPlayers(sourceObject.getName() + ": additional cost wasn't paid - countering " + spell.getName());
// Counter target spell unless its controller pays {X}
game.getStack().counter(source.getFirstTarget(), source, game);
// that player taps all lands with mana abilities they control...
List<Permanent> lands = game.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), player.getId(), game);
for (Permanent land : lands) {
Abilities<Ability> landAbilities = land.getAbilities();
for (Ability ability : landAbilities) {
if (ability instanceof ActivatedManaAbilityImpl) {
land.tap(source, game);
break;
}
}
}
// ...and empties their mana pool
player.getManaPool().emptyPool(game);
}
return true;
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class PossessedPortalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
Cost discardCost = new DiscardCardCost();
if (player != null && discardCost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Discard, "Discard a card? (Otherwise sacrifice a permanent)", source, game)) {
discardCost.pay(source, game, source, playerId, true, null);
} else {
Cost sacrificeCost = new SacrificeTargetCost(new TargetControlledPermanent());
sacrificeCost.pay(source, game, source, playerId, true, null);
}
}
return true;
}
Aggregations