use of mage.ApprovingObject in project mage by magefree.
the class EmergentUltimatumTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetCardInLibrary targetCardInLibrary = new EmergentUltimatumTarget();
targetCardInLibrary.setNotTarget(true);
boolean searched = player.searchLibrary(targetCardInLibrary, source, game);
Cards cards = new CardsImpl(targetCardInLibrary.getTargets());
player.moveCards(cards, Zone.EXILED, source, game);
if (cards.isEmpty()) {
if (searched) {
player.shuffleLibrary(source, game);
}
return false;
}
TargetOpponent targetOpponent = new TargetOpponent();
targetOpponent.setNotTarget(true);
player.choose(outcome, targetOpponent, source.getSourceId(), game);
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent == null) {
if (searched) {
player.shuffleLibrary(source, game);
}
return false;
}
TargetCardInExile targetCardInExile = new TargetCardInExile(StaticFilters.FILTER_CARD);
targetCardInExile.setNotTarget(true);
opponent.choose(outcome, cards, targetCardInExile, game);
Card toShuffle = game.getCard(targetCardInExile.getFirstTarget());
if (toShuffle != null) {
player.putCardsOnBottomOfLibrary(toShuffle, game, source, false);
player.shuffleLibrary(source, game);
cards.remove(toShuffle);
}
while (!cards.isEmpty()) {
if (!player.chooseUse(Outcome.PlayForFree, "Cast an exiled card without paying its mana cost?", source, game)) {
break;
}
targetCardInExile.clearChosen();
if (!player.choose(Outcome.PlayForFree, cards, targetCardInExile, game)) {
continue;
}
Card card = game.getCard(targetCardInExile.getFirstTarget());
if (card == null) {
continue;
}
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
// remove on non cast too (infinite freeze fix)
cards.remove(card);
if (cardWasCast) {
cards.remove(card);
} else {
game.informPlayer(player, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
}
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class MaelstromArchangelCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetCardInHand(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Cast a spell from your hand without paying its mana cost?", source, game)) {
Card cardToCast = null;
boolean cancel = false;
while (controller.canRespond() && !cancel) {
if (controller.chooseTarget(outcome, target, source, game)) {
cardToCast = game.getCard(target.getFirstTarget());
if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
cancel = true;
}
} else {
cancel = true;
}
}
if (cardToCast != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class MizzixsMasteryOverloadEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null) {
if (controller.moveCards(card, Zone.EXILED, source, game)) {
Card cardCopy = game.copyCard(card, source, source.getControllerId());
if (cardCopy.getSpellAbility().canChooseTarget(game, controller.getId()) && controller.chooseUse(outcome, "Cast copy of " + card.getName() + " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardCopy.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardCopy, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardCopy.getId(), null);
}
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class SurtlandElementalistEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
TargetCardInHand target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
if (player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
boolean cardWasCast = player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
return cardWasCast;
}
}
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class SvellaIceShaperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 4);
Cards cards = new CardsImpl(cardsSet);
TargetCard target = new TargetCardInLibrary(0, 1, new FilterNonlandCard("card to cast without paying its mana cost"));
controller.choose(Outcome.PlayForFree, cards, target, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card == null) {
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
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);
if (cardWasCast) {
cards.remove(card);
}
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
Aggregations