use of mage.ApprovingObject in project mage by magefree.
the class IzzetChemisterCastFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ExileZone exile = game.getExile().getExileZone(exileId);
Player controller = game.getPlayer(source.getControllerId());
FilterCard filter = new FilterCard();
if (controller != null && exile != null) {
Cards cardsToExile = new CardsImpl();
cardsToExile.addAll(exile.getCards(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);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
cardsToExile.remove(card);
} else {
break OuterLoop;
}
target.clearChosen();
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class KasminaEnigmaSageSearchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentOrLKI(game);
if (controller == null || permanent == null) {
return false;
}
FilterCard filter = new FilterInstantOrSorceryCard("an instant, or sorcery card which shares a color with " + permanent.getLogName());
filter.add(new SharesColorPredicate(permanent.getColor(game)));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
controller.searchLibrary(target, source, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
}
controller.shuffleLibrary(source, game);
if (card == null || !controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
return true;
}
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);
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class MuseVortexEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int xValue = source.getManaCostsToPay().getX();
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
controller.moveCards(cards, Zone.EXILED, source, game);
cards.retainZone(Zone.EXILED, game);
FilterCard filter = new FilterInstantOrSorceryCard("an instant or sorcery card with mana value " + xValue + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCardInExile target = new TargetCardInExile(filter);
target.setNotTarget(true);
if (controller.choose(Outcome.Benefit, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
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);
cards.remove(card);
if (cardWasCast) {
cards.remove(card);
} else {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
controller.putCardsOnTopOfLibrary(cards, game, source, true);
return true;
}
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class ReversalOfFortuneEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller != null && opponent != null) {
// Target opponent reveals their hand
Cards revealedCards = new CardsImpl();
revealedCards.addAll(opponent.getHand());
opponent.revealCards("Reveal", revealedCards, game);
// You may copy an instant or sorcery card in it
TargetCard target = new TargetCard(1, Zone.HAND, new FilterInstantOrSorceryCard());
target.setRequired(false);
if (controller.choose(Outcome.PlayForFree, revealedCards, target, game)) {
Card card = revealedCards.get(target.getFirstTarget(), game);
// If you do, you may cast the copy without paying its mana cost
if (card != null) {
Card copiedCard = game.copyCard(card, source, source.getControllerId());
if (controller.chooseUse(Outcome.PlayForFree, "Cast the copied card without paying mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
}
} else {
return false;
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class SilentBladeOniEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (opponent == null || controller == null) {
return false;
}
Cards cardsInHand = new CardsImpl();
cardsInHand.addAll(opponent.getHand());
if (cardsInHand.isEmpty()) {
return true;
}
TargetCard target = new TargetCard(0, 1, Zone.HAND, StaticFilters.FILTER_CARD_A_NON_LAND);
if (!controller.chooseUse(outcome, "Cast a card from " + opponent.getName() + "'s hand?", source, game) || !controller.chooseTarget(outcome, cardsInHand, target, source, game)) {
return true;
}
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
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);
return cardWasCast;
}
Aggregations