use of mage.ApprovingObject in project mage by magefree.
the class VillainousWealthEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
FilterCard filter = new FilterNonlandCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
UUID exileId = CardUtil.getCardExileZoneId(game, source);
if (player != null) {
Cards cardsToExile = new CardsImpl();
cardsToExile.addAll(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
if (controller.chooseUse(Outcome.PlayForFree, "Cast cards exiled with " + mageObject.getLogName() + " without paying its mana cost?", source, game)) {
OuterLoop: while (cardsToExile.count(filter, game) > 0) {
if (!controller.canRespond()) {
return false;
}
TargetCardInExile target = new TargetCardInExile(0, 1, filter, exileId, false);
target.setNotTarget(true);
while (controller.canRespond() && cardsToExile.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, cardsToExile, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
if (cardWasCast) {
cardsToExile.remove(card);
}
} else {
break OuterLoop;
}
target.clearChosen();
}
}
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class ChandraAblazeEffect5 method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
FilterCard filter = new FilterCard("red instant or sorcery card from your graveyard to play");
filter.add(new ColorPredicate(ObjectColor.RED));
filter.add(Predicates.or(CardType.INSTANT.getPredicate(), CardType.SORCERY.getPredicate()));
String message = "Play red instant or sorcery card from your graveyard without paying its mana cost?";
Set<Card> cards = player.getGraveyard().getCards(filter, game);
TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
while (!cards.isEmpty() && player.chooseUse(outcome, message, source, game)) {
target.clearChosen();
if (player.choose(outcome, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
cards.remove(card);
}
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class ChandraTorchOfDefianceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null && controller.getLibrary().hasCards()) {
Library library = controller.getLibrary();
Card card = library.getFromTop(game);
if (card != null) {
boolean cardWasCast = false;
controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
if (!card.getManaCost().isEmpty() || !card.isLand(game)) {
if (controller.chooseUse(Outcome.Benefit, "Cast " + card.getName() + "? (You still pay the costs)", source, game) && (game.getState().getZone(card.getId()) == Zone.EXILED)) {
// card must be in the exile zone
// enable the card to be cast from the exile zone
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, false), game, false, new ApprovingObject(source, game));
// reset to null
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
if (!cardWasCast) {
new DamagePlayersEffect(Outcome.Damage, StaticValue.get(2), TargetController.OPPONENT).apply(game, source);
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class EtaliPrimalStormEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
// move cards from library to exile
Set<Card> currentExiledCards = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (!player.getLibrary().getTopCards(game, 1).isEmpty()) {
Card topCard = player.getLibrary().getFromTop(game);
if (topCard != null) {
if (filter.match(topCard, source.getSourceId(), source.getControllerId(), game)) {
currentExiledCards.add(topCard);
}
controller.moveCardsToExile(topCard, source, game, true, source.getSourceId(), sourceObject.getIdName());
}
}
}
}
// cast the possible cards without paying the mana
Cards cardsToCast = new CardsImpl();
cardsToCast.addAll(currentExiledCards);
boolean alreadyCast = false;
while (controller.canRespond() && !cardsToCast.isEmpty()) {
if (!controller.chooseUse(Outcome.PlayForFree, "Cast a" + (alreadyCast ? "nother" : "") + " card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
break;
}
TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("nonland card to cast for free"));
if (!controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
break;
}
alreadyCast = true;
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
if (!cardWasCast) {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
cardsToCast.remove(card);
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class GeodeGolemEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card selectedCommander = null;
Set<Card> commandersInCommandZone = game.getCommanderCardsFromCommandZone(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER);
if (commandersInCommandZone.isEmpty()) {
return false;
}
// select from commanders
if (commandersInCommandZone.size() == 1) {
selectedCommander = commandersInCommandZone.stream().findFirst().get();
} else {
TargetCard target = new TargetCard(Zone.COMMAND, new FilterCard("commander to cast without mana cost"));
target.setNotTarget(true);
if (controller.canRespond() && controller.choose(Outcome.PlayForFree, new CardsImpl(commandersInCommandZone), target, game)) {
selectedCommander = commandersInCommandZone.stream().filter(c -> c.getId().equals(target.getFirstTarget())).findFirst().orElse(null);
}
}
if (selectedCommander == null) {
return false;
}
// commander tax applies as additional cost
if (selectedCommander.getSpellAbility() != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + selectedCommander.getId(), Boolean.TRUE);
Boolean commanderWasCast = controller.cast(controller.chooseAbilityForCast(selectedCommander, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + selectedCommander.getId(), null);
return commanderWasCast;
} else {
// TODO: improve lands support for "cast your commander" (allow land play from mdf cards)?
return controller.playLand(selectedCommander, game, true);
}
}
return false;
}
Aggregations