Search in sources :

Example 56 with ApprovingObject

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;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 57 with ApprovingObject

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;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 58 with ApprovingObject

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;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 59 with ApprovingObject

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;
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ApprovingObject(mage.ApprovingObject) PlayerList(mage.players.PlayerList) Card(mage.cards.Card)

Example 60 with ApprovingObject

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);
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInExile(mage.target.common.TargetCardInExile) ArrayList(java.util.ArrayList) GameEvent(mage.game.events.GameEvent)

Aggregations

ApprovingObject (mage.ApprovingObject)111 Player (mage.players.Player)109 Card (mage.cards.Card)77 FilterCard (mage.filter.FilterCard)53 TargetCard (mage.target.TargetCard)30 MageObject (mage.MageObject)20 FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)17 CardsImpl (mage.cards.CardsImpl)16 Permanent (mage.game.permanent.Permanent)16 UUID (java.util.UUID)15 TargetCardInHand (mage.target.common.TargetCardInHand)13 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 FilterNonlandCard (mage.filter.common.FilterNonlandCard)10 TargetCardInExile (mage.target.common.TargetCardInExile)10 ExileZone (mage.game.ExileZone)9 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)9 Cards (mage.cards.Cards)8 Spell (mage.game.stack.Spell)8 Target (mage.target.Target)7 FixedTarget (mage.target.targetpointer.FixedTarget)7