Search in sources :

Example 6 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class HazoretsUndyingFuryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        controller.shuffleLibrary(source, game);
        // move cards from library to exile
        controller.moveCardsToExile(controller.getLibrary().getTopCards(game, 4), source, game, true, source.getSourceId(), sourceObject.getIdName());
        // cast the possible cards without paying the mana
        ExileZone hazoretsUndyingFuryExileZone = game.getExile().getExileZone(source.getSourceId());
        Cards cardsToCast = new CardsImpl();
        if (hazoretsUndyingFuryExileZone == null) {
            return true;
        }
        cardsToCast.addAll(hazoretsUndyingFuryExileZone.getCards(filter, source.getSourceId(), source.getControllerId(), game));
        while (controller.canRespond() && !cardsToCast.isEmpty()) {
            if (!controller.chooseUse(Outcome.PlayForFree, "Cast (another) a card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("nonland card to cast for free"));
            if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                Card card = game.getCard(targetCard.getFirstTarget());
                if (card != null) {
                    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);
                    cardsToCast.remove(card);
                    if (!cardWasCast) {
                        game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 7 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MemoryPlunderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (card != null) {
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD && controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying 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;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 8 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class CardCanBeCastPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.getLibrary().hasCards()) {
            /**
             * 10/1/2005 Any card you find must be legally cast-able (for
             * example, you have to be able to choose a legal target for
             * it). If you can't find a cast-able card (or choose not to),
             * nothing happens and you shuffle your library.
             */
            FilterCard filter = new FilterCard("red or white instant card with mana value 4 or less");
            TargetCardInLibrary target = new TargetCardInLibrary(filter);
            filter.add(Predicates.or(new ColorPredicate(ObjectColor.RED), new ColorPredicate(ObjectColor.WHITE)));
            filter.add(CardType.INSTANT.getPredicate());
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 5));
            filter.add(new CardCanBeCastPredicate(source.getControllerId()));
            if (controller.searchLibrary(target, source, game, controller.getId())) {
                UUID targetId = target.getFirstTarget();
                Card card = game.getCard(targetId);
                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);
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 9 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class PlayTargetWithoutPayingManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card target = (Card) game.getObject(source.getFirstTarget());
    if (controller != null && target != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + target.getId(), Boolean.TRUE);
        Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(target, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + target.getId(), null);
        return cardWasCast;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Card(mage.cards.Card)

Example 10 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ReboundCastSpellFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ExileZone zone = game.getExile().getExileZone(source.getSourceId());
    if (zone == null || zone.isEmpty()) {
        return false;
    }
    Card reboundCard = zone.get(source.getSourceId(), game);
    Player player = game.getPlayer(source.getControllerId());
    if (player != null && reboundCard != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + reboundCard.getId(), Boolean.TRUE);
        Boolean cardWasCast = player.cast(player.chooseAbilityForCast(reboundCard, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + reboundCard.getId(), null);
        return cardWasCast;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ExileZone(mage.game.ExileZone) 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