use of mage.ApprovingObject in project mage by magefree.
the class TorrentialGearhulkReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
if (controller != null && card != null) {
if (controller.chooseUse(outcome, "Cast " + card.getLogName() + '?', source, game)) {
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) {
ContinuousEffect effect = new TorrentialGearhulkReplacementEffect(card.getId());
effect.setTargetPointer(new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class WildfireEternalCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCard filter = new FilterInstantOrSorceryCard();
int cardsToCast = controller.getHand().count(filter, source.getControllerId(), source.getSourceId(), game);
if (cardsToCast > 0 && controller.chooseUse(outcome, "Cast an instant or sorcery card from your " + "hand without paying its mana cost?", source, game)) {
TargetCardInHand target = new TargetCardInHand(filter);
controller.chooseTarget(outcome, target, source, 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);
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class WildEvocationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (player != null && sourceObject != null) {
Card card = player.getHand().getRandom(game);
if (card != null) {
Cards cards = new CardsImpl(card);
player.revealCards(sourceObject.getIdName() + " Turn: " + game.getTurnNum(), cards, game);
if (card.isLand(game)) {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
} else if (card.getSpellAbility() != 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);
} else {
game.informPlayers(GameLog.getColoredObjectName(card) + " can't be cast now by " + player.getLogName());
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class WildfireDevilsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
PlayerList players = game.getState().getPlayersInRange(controller.getId(), game);
if (players == null) {
return false;
}
Player randomPlayer = game.getPlayer(players.get(RandomUtil.nextInt(players.size())));
if (randomPlayer == null) {
return false;
}
game.informPlayers("The chosen random player is " + randomPlayer.getLogName());
if (randomPlayer.getGraveyard().getCards(game).stream().noneMatch(card1 -> card1.isInstantOrSorcery(game))) {
return false;
}
TargetCardInGraveyard targetCard = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
targetCard.setNotTarget(true);
if (!randomPlayer.choose(Outcome.Discard, randomPlayer.getGraveyard(), targetCard, game)) {
return false;
}
Card card = game.getCard(targetCard.getFirstTarget());
if (card == null) {
return false;
}
randomPlayer.moveCards(card, Zone.EXILED, source, game);
if (game.getState().getZone(card.getId()) != Zone.EXILED) {
return false;
}
Card copiedCard = game.copyCard(card, source, controller.getId());
if (copiedCard == null) {
return false;
}
randomPlayer.moveCards(copiedCard, Zone.EXILED, source, game);
if (!controller.chooseUse(outcome, "Cast the copy of the exiled card?", source, game)) {
return false;
}
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
return cardWasCast;
}
use of mage.ApprovingObject in project mage by magefree.
the class CascadeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard == null) {
return false;
}
// exile cards from the top of your library until you exile a nonland card whose converted mana cost is less than this spell's converted mana cost
Cards cardsToExile = new CardsImpl();
int sourceCost = sourceCard.getManaValue();
Card cardToCast = null;
for (Card card : controller.getLibrary().getCards(game)) {
cardsToExile.add(card);
// the card move is sequential, not all at once.
controller.moveCards(card, Zone.EXILED, source, game);
// Laelia, the Blade Reforged
game.getState().processAction(game);
if (!card.isLand(game) && card.getManaValue() < sourceCost) {
cardToCast = card;
break;
}
}
// set back empty draw state if that caused an empty draw
controller.getLibrary().reset();
// additional replacement effect: As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped
GameEvent event = GameEvent.getEvent(GameEvent.EventType.CASCADE_LAND, source.getSourceId(), source, source.getControllerId(), 0);
game.replaceEvent(event);
if (event.getAmount() > 0) {
TargetCardInExile target = new TargetCardInExile(0, event.getAmount(), StaticFilters.FILTER_CARD_LAND, null, true);
target.withChooseHint("land to put onto battlefield tapped");
controller.choose(Outcome.PutCardInPlay, cardsToExile, target, game);
controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
}
// You may cast that spell without paying its mana cost if its converted mana cost is less than this spell's converted mana cost.
List<Card> partsToCast = new ArrayList<>();
if (cardToCast != null) {
if (cardToCast instanceof SplitCard) {
partsToCast.add(((SplitCard) cardToCast).getLeftHalfCard());
partsToCast.add(((SplitCard) cardToCast).getRightHalfCard());
partsToCast.add(cardToCast);
} else if (cardToCast instanceof AdventureCard) {
partsToCast.add(((AdventureCard) cardToCast).getSpellCard());
partsToCast.add(cardToCast);
} else if (cardToCast instanceof ModalDoubleFacesCard) {
partsToCast.add(((ModalDoubleFacesCard) cardToCast).getLeftHalfCard());
partsToCast.add(((ModalDoubleFacesCard) cardToCast).getRightHalfCard());
} else {
partsToCast.add(cardToCast);
}
// remove too big cmc
partsToCast.removeIf(card -> card.getManaValue() >= sourceCost);
// remove non spells
partsToCast.removeIf(card -> card.getSpellAbility() == null);
}
String partsInfo = partsToCast.stream().map(MageObject::getIdName).collect(Collectors.joining(" or "));
if (cardToCast != null && partsToCast.size() > 0 && controller.chooseUse(outcome, "Cast spell without paying its mana cost (" + partsInfo + ")?", source, game)) {
try {
// enable free cast for all compatible parts
partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE));
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
} finally {
partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null));
}
}
// Then put all cards exiled this way that weren't cast on the bottom of your library in a random order.
cardsToExile.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
return controller.putCardsOnBottomOfLibrary(cardsToExile, game, source, false);
}
Aggregations