use of mage.abilities.costs.Cost in project mage by magefree.
the class ShroudedLoreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (you != null && opponent != null) {
FilterCard filter = new FilterCard();
filter.add(new OwnerIdPredicate(you.getId()));
Cost cost = new ManaCostsImpl("{B}");
TargetCardInGraveyard chosenCard;
Card card = null;
boolean done = false;
do {
chosenCard = new TargetCardInGraveyard(filter);
chosenCard.setNotTarget(true);
if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
card = game.getCard(chosenCard.getFirstTarget());
if (card != null) {
filter.add(Predicates.not(new CardIdPredicate(card.getId())));
game.informPlayers("Shrouded Lore: " + opponent.getLogName() + " has chosen " + card.getLogName());
}
} else {
done = true;
}
if (!done) {
done = true;
if (cost.canPay(source, source, you.getId(), game) && you.chooseUse(Outcome.Benefit, "Pay {B} to choose a different card ?", source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, you.getId(), false, null)) {
done = false;
}
}
}
} while (!done);
if (card != null) {
Cards cardsToHand = new CardsImpl();
cardsToHand.add(card);
you.moveCards(cardsToHand, Zone.HAND, source, game);
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class WolfOfDevilsBreachDiscardCostCardConvertedManaCount method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for (Effect sourceEffect : sourceAbility.getEffects()) {
if (sourceEffect instanceof DoIfCostPaid) {
Cost doCosts = ((DoIfCostPaid) sourceEffect).getCost();
if (doCosts instanceof Costs) {
Costs costs = (Costs) doCosts;
for (Object cost : costs) {
if (cost instanceof DiscardCardCost) {
DiscardCardCost discardCost = (DiscardCardCost) cost;
int cmc = 0;
for (Card card : discardCost.getCards()) {
cmc += card.getManaValue();
}
return cmc;
}
}
}
}
}
return 0;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class CounterUnlessPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell == null) {
return false;
}
Player player = game.getPlayer(spell.getControllerId());
if (player == null) {
return false;
}
Cost costToPay;
String costValueMessage;
if (cost != null) {
costToPay = cost.copy();
costValueMessage = costToPay.getText();
} else {
costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
}
String message = "";
if (costToPay instanceof ManaCost) {
message += "Pay ";
}
message += costValueMessage + '?';
costToPay.clearPaid();
if (!(player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, spell.getControllerId(), false, null))) {
game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the counter effect");
if (exile) {
game.getStack().counter(spell.getId(), source, game, Zone.EXILED, false, ZoneDetail.NONE);
} else {
return game.getStack().counter(spell.getId(), source, game);
}
}
game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the counter effect");
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class CrystalShardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller == null || targetCreature == null) {
return true;
}
Player player = game.getPlayer(targetCreature.getControllerId());
if (player == null) {
return true;
}
Cost cost = ManaUtil.createManaCost(1, false);
String message = "Pay {1}? (Otherwise " + targetCreature.getName() + " will be returned to its owner's hand)";
if (player.chooseUse(Outcome.Benefit, message, source, game)) {
cost.pay(source, game, source, targetCreature.getControllerId(), false, null);
}
return cost.isPaid() || controller.moveCards(targetCreature, Zone.HAND, source, game);
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class CrypticGatewayPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
if (source.getCosts() == null) {
return false;
}
FilterCard filter = new FilterCreatureCard("creature card from your hand that shares a creature type with each creature tapped this way");
for (Cost cost : source.getCosts()) {
if (cost instanceof CrypticGatewayCost) {
Predicate predicate = ((CrypticGatewayCost) cost).getPredicate();
filter.add(predicate);
return new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source);
}
}
return false;
}
Aggregations