use of mage.ApprovingObject in project mage by magefree.
the class AugustaDeanOfOrderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean cardWasCast = false;
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && controller.getLibrary().hasCards()) {
CardsImpl toReveal = new CardsImpl();
Card eligibleCard = null;
for (Card card : controller.getLibrary().getCards(game)) {
toReveal.add(card);
if (!card.isLand(game) && !card.isLegendary() && card.getManaValue() < 4) {
eligibleCard = card;
break;
}
}
controller.revealCards(source, toReveal, game);
if (eligibleCard != null && controller.chooseUse(Outcome.PlayForFree, "Cast " + eligibleCard.getLogName() + " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + eligibleCard.getId(), Boolean.TRUE);
cardWasCast = controller.cast(controller.chooseAbilityForCast(eligibleCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + eligibleCard.getId(), null);
if (cardWasCast) {
toReveal.remove(eligibleCard);
}
}
controller.putCardsOnBottomOfLibrary(toReveal, game, source, false);
}
return cardWasCast;
}
use of mage.ApprovingObject in project mage by magefree.
the class TargetYouPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getExileZoneId(game, source.getSourceId(), sourcePermanent.getZoneChangeCounter(game)));
if (controller.choose(Outcome.PlayForFree, game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), sourcePermanent.getZoneChangeCounter(game))), target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null && controller.chooseUse(outcome, "Cast " + card.getLogName() + " without paying its mana cost?", 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);
return cardWasCast;
}
}
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class TwinningGlassEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Spell> spells = new ArrayList<>();
Permanent twinningGlass = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (twinningGlass == null) {
twinningGlass = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (twinningGlass != null && controller != null && watcher != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (watcher.getSpellsCastThisTurn(playerId) != null) {
for (Spell spell : watcher.getSpellsCastThisTurn(playerId)) {
spells.add(spell);
}
}
}
if (spells.isEmpty()) {
return false;
}
List<NamePredicate> predicates = spells.stream().map(Spell::getName).filter(Objects::nonNull).filter(s -> !s.isEmpty()).map(NamePredicate::new).collect(Collectors.toList());
FilterNonlandCard filterCard = new FilterNonlandCard("nonland card that was cast this turn");
filterCard.add(Predicates.or(predicates));
TargetCard target = new TargetCard(0, 1, Zone.HAND, filterCard);
target.withChooseHint("free cast");
if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) {
Card chosenCard = game.getCard(target.getFirstTarget());
if (chosenCard != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(chosenCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), null);
return cardWasCast;
}
}
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class YennettCrypticSovereignEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.getLibrary().hasCards()) {
return false;
}
Card card = player.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
player.revealCards(source, new CardsImpl(card), game);
if (card.getManaValue() % 2 == 1) {
if (player.chooseUse(outcome, "Cast " + card.getLogName() + " without paying its mana cost?", source, game)) {
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 {
/*
7/13/2018 | If the revealed card doesn’t have an odd converted mana cost or if that card does but you
choose not to cast it, you draw a card. Keep in mind that revealing a card doesn’t cause it to change
zones. This means that the card you draw will be the card you revealed.
*/
player.drawCards(1, source, game);
}
} else {
player.drawCards(1, source, game);
}
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class JaceMindseekerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Cards cardsToCast = new CardsImpl();
Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
if (targetOpponent != null) {
Set<Card> allCards = targetOpponent.millCards(5, source, game).getCards(game);
for (Card card : allCards) {
if (filter.match(card, game)) {
Zone zone = game.getState().getZone(card.getId());
// you can cast one of those instant or sorcery cards from that zone.
if (zone == Zone.GRAVEYARD || zone == Zone.EXILED) {
cardsToCast.add(card);
}
}
}
// cast an instant or sorcery for free
if (!cardsToCast.isEmpty()) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// zone should be ignored here
TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
target.setNotTarget(true);
if (controller.chooseUse(outcome, "Cast an instant or sorcery card from among them for free?", source, game) && controller.choose(Outcome.PlayForFree, cardsToCast, target, game)) {
Card card = cardsToCast.get(target.getFirstTarget(), game);
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;
}
Aggregations