Search in sources :

Example 96 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class UnexpectedResultEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card sourceCard = game.getCard(source.getSourceId());
    if (controller == null || sourceCard == null) {
        return false;
    }
    if (controller.getLibrary().hasCards()) {
        controller.shuffleLibrary(source, game);
        Card card = controller.getLibrary().getFromTop(game);
        if (card == null) {
            return false;
        }
        controller.revealCards(sourceCard.getName(), new CardsImpl(card), game);
        if (card.isLand(game)) {
            String message = "Put " + card.getName() + " onto the battlefield?";
            if (controller.chooseUse(Outcome.PutLandInPlay, message, source, game)) {
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                controller.moveCards(sourceCard, Zone.HAND, source, game);
                return true;
            }
        } else {
            if (controller.chooseUse(outcome, "Cast " + card.getName() + " 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 true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 97 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class WrexialReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getFirstTarget());
    if (controller == null || card == null) {
        return false;
    }
    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);
    game.addEffect(new WrexialReplacementEffect(card.getId()), source);
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 98 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class CastCardFromOutsideTheGameEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    while (player.chooseUse(Outcome.Benefit, choiceText, source, game)) {
        Cards cards = player.getSideboard();
        if (cards.isEmpty()) {
            if (!game.isSimulation()) {
                game.informPlayer(player, "You have no cards outside the game.");
            }
            return false;
        }
        Set<Card> filtered = cards.getCards(filterCard, source.getSourceId(), source.getControllerId(), game);
        if (filtered.isEmpty()) {
            if (!game.isSimulation()) {
                game.informPlayer(player, "You have no " + filterCard.getMessage() + " outside the game.");
            }
            return false;
        }
        Cards filteredCards = new CardsImpl();
        for (Card card : filtered) {
            filteredCards.add(card.getId());
        }
        TargetCard target = new TargetCard(Zone.OUTSIDE, filterCard);
        if (player.choose(Outcome.Benefit, filteredCards, target, game)) {
            Card card = player.getSideboard().get(target.getFirstTarget(), game);
            if (card != 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);
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 99 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MadnessCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getSourceId());
    if (card == null) {
        return false;
    }
    Player owner = game.getPlayer(card.getOwnerId());
    if (owner == null) {
        return false;
    }
    // Replace with the new cost
    SpellAbility castByMadness = card.getSpellAbility().copy();
    ManaCosts<ManaCost> costRef = castByMadness.getManaCostsToPay();
    castByMadness.setSpellAbilityType(SpellAbilityType.BASE_ALTERNATE);
    castByMadness.setSpellAbilityCastMode(SpellAbilityCastMode.MADNESS);
    castByMadness.getCosts().clear();
    castByMadness.addCost(new PayLifeCost(this.lifeCost));
    costRef.clear();
    costRef.add(madnessCost);
    return owner.cast(castByMadness, game, false, new ApprovingObject(source, game));
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ManaCost(mage.abilities.costs.mana.ManaCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Card(mage.cards.Card)

Example 100 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class RippleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player != null) {
        if (!player.chooseUse(Outcome.Neutral, "Reveal " + rippleNumber + " cards from the top of your library?", source, game)) {
            // fizzle
            return true;
        }
        // reveal top cards from library
        Cards cards = new CardsImpl();
        cards.addAll(player.getLibrary().getTopCards(game, rippleNumber));
        player.revealCards(sourceObject.getIdName(), cards, game);
        // determine which card should be rippled
        String cardNameToRipple = sourceObject.getName();
        FilterCard sameNameFilter = new FilterCard("card(s) with the name: \"" + cardNameToRipple + "\" to cast without paying their mana cost");
        sameNameFilter.add(new NamePredicate(cardNameToRipple));
        TargetCard target1 = new TargetCard(Zone.LIBRARY, sameNameFilter);
        target1.setRequired(false);
        // choose cards to play for free
        while (player.canRespond() && cards.count(sameNameFilter, game) > 0 && player.choose(Outcome.PlayForFree, cards, target1, game)) {
            Card card = cards.get(target1.getFirstTarget(), game);
            if (card != 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);
                cards.remove(card);
            }
            target1.clearChosen();
        }
        // move cards that weren't cast to the bottom of the library
        player.putCardsOnBottomOfLibrary(cards, game, source, true);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

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