use of mage.ApprovingObject in project mage by magefree.
the class SproutbackTrudgeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
if (player == null || !(sourceObject instanceof Card)) {
return false;
}
Card card = (Card) sourceObject;
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(card, game, false), game, false, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class SunbirdsInvocationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || sourceObject == null) {
return false;
}
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell == null) {
return false;
}
int xValue = spell.getManaValue();
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
if (!cards.isEmpty()) {
controller.revealCards(sourceObject.getIdName(), cards, game);
FilterCard filter = new FilterNonlandCard("card revealed this way with mana value " + xValue + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard target = new TargetCard(1, Zone.LIBRARY, filter);
if (controller.chooseTarget(Outcome.PlayForFree, cards, target, source, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
if (controller.chooseUse(Outcome.Benefit, "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);
if (cardWasCast) {
cards.remove(card);
}
}
}
}
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
}
return true;
}
use of mage.ApprovingObject in project mage by magefree.
the class TibaltsTrickeryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
if (spell != null) {
String spellName = spell.getName();
Player controller = game.getPlayer(spell.getControllerId());
game.getStack().counter(spell.getId(), source, game);
if (controller != null) {
int random = RandomUtil.nextInt(3) + 1;
game.informPlayers(random + " was chosen at random");
controller.millCards(random, source, game);
Card cardToCast = null;
Set<Card> cardsToExile = new HashSet<>();
FilterCard filter = new FilterCard();
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(Predicates.not(new NamePredicate(spellName)));
for (Card card : controller.getLibrary().getCards(game)) {
cardsToExile.add(card);
if (filter.match(card, game)) {
cardToCast = card;
break;
}
}
controller.moveCardsToExile(cardsToExile, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
if (cardToCast != null) {
if (controller.chooseUse(Outcome.PlayForFree, "Cast " + cardToCast.getLogName() + " for free?", source, game)) {
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);
}
}
ExileZone exile = game.getExile().getExileZone(source.getSourceId());
if (exile != null) {
controller.putCardsOnBottomOfLibrary(exile, game, source, false);
}
}
return true;
}
return false;
}
use of mage.ApprovingObject in project mage by magefree.
the class TreasureKeeperEffect 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 nonLandCard = null;
for (Card card : controller.getLibrary().getCards(game)) {
toReveal.add(card);
if (!card.isLand(game) && card.getManaValue() < 4) {
nonLandCard = card;
break;
}
}
controller.revealCards(source, toReveal, game);
if (nonLandCard != null && controller.chooseUse(Outcome.PlayForFree, "Cast " + nonLandCard.getLogName() + " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + nonLandCard.getId(), Boolean.TRUE);
cardWasCast = controller.cast(controller.chooseAbilityForCast(nonLandCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + nonLandCard.getId(), null);
if (cardWasCast) {
toReveal.remove(nonLandCard);
}
}
controller.putCardsOnBottomOfLibrary(toReveal, game, source, false);
}
return cardWasCast;
}
use of mage.ApprovingObject in project mage by magefree.
the class UnpredictableCycloneReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (player == null || stackObject == null) {
return false;
}
Card sourceCard = game.getCard(stackObject.getSourceId());
if (sourceCard == null) {
return false;
}
Cards cards = new CardsImpl();
Card toCast = null;
for (Card card : player.getLibrary().getCards(game)) {
cards.add(card);
if (card.getCardType(game).stream().anyMatch(sourceCard.getCardType(game)::contains)) {
toCast = card;
break;
}
}
player.moveCards(cards, Zone.EXILED, source, game);
if (toCast != null && player.chooseUse(outcome, "Cast the exiled card?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), Boolean.TRUE);
Boolean cardWasCast = player.cast(player.chooseAbilityForCast(toCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), null);
if (cardWasCast) {
cards.remove(toCast);
}
}
player.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
Aggregations