Search in sources :

Example 46 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class InSearchOfGreatnessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = 0;
    UUID permId = source.getSourceId();
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controller.getId())) {
        if (permanent != null && !permanent.getId().equals(permId)) {
            int permCmc = permanent.getManaValue();
            if (permCmc > cmc) {
                cmc = permCmc;
            }
        }
    }
    if (controller.chooseUse(outcome, "Cast a permanent spell from your hand with CMC equal to " + ++cmc + "?", source, game)) {
        FilterPermanentCard filter = new FilterPermanentCard("permanent spell from your hand");
        filter.add(Predicates.not(CardType.LAND.getPredicate()));
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc));
        TargetCardInHand target = new TargetCardInHand(filter);
        if (controller.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.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);
                if (cardWasCast) {
                    return true;
                }
            }
        }
    }
    return controller.scry(1, source, game);
}
Also used : Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Example 47 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class LeafCrownedElderPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller != null && card != null) {
        if (controller.chooseUse(Outcome.PlayForFree, "Play " + card.getIdName() + " without paying its mana cost?", source, game)) {
            controller.playCard(card, game, true, new ApprovingObject(source, game));
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Card(mage.cards.Card)

Example 48 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MnemonicDelugeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getFirstTarget());
    if (player == null || card == null) {
        return false;
    }
    player.moveCards(card, Zone.EXILED, source, game);
    Cards cards = new CardsImpl();
    for (int i = 0; i < 3; i++) {
        Card copiedCard = game.copyCard(card, source, source.getControllerId());
        game.getExile().add(source.getSourceId(), "", copiedCard);
        game.getState().setZone(copiedCard.getId(), Zone.EXILED);
        cards.add(copiedCard);
    }
    for (Card copiedCard : cards.getCards(game)) {
        if (!player.chooseUse(outcome, "Cast the copied card?", source, game)) {
            continue;
        }
        if (copiedCard.getSpellAbility() != null) {
            game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
            player.cast(player.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
        } else {
            Logger.getLogger(MnemonicDelugeEffect.class).error("Mnemonic Deluge: " + "spell ability == null " + copiedCard.getName());
        }
    }
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject)

Example 49 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class PossibilityStormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
    // spell was exiled already by another effect, for example NivMagus Elemental
    boolean noLongerOnStack = false;
    if (spell == null) {
        spell = ((Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK));
        noLongerOnStack = true;
    }
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null && spell != null) {
        Player spellController = game.getPlayer(spell.getControllerId());
        if (spellController != null) {
            if (!noLongerOnStack) {
                spellController.moveCardsToExile(spell, source, game, true, source.getSourceId(), sourceObject.getIdName());
            }
            if (spellController.getLibrary().hasCards()) {
                Library library = spellController.getLibrary();
                Card card;
                do {
                    card = library.getFromTop(game);
                    if (card != null) {
                        spellController.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
                    }
                } while (library.hasCards() && card != null && !sharesType(card, spell.getCardType(game), game));
                if (card != null && sharesType(card, spell.getCardType(game), game) && !card.isLand(game) && card.getSpellAbility().canChooseTarget(game, spellController.getId())) {
                    if (spellController.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + " without paying cost?", source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                        spellController.cast(spellController.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    }
                }
                ExileZone exile = game.getExile().getExileZone(source.getSourceId());
                if (exile != null) {
                    spellController.putCardsOnBottomOfLibrary(exile, game, source, false);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) Library(mage.players.Library) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 50 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ScholarOfTheLostTroveReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
    if (card == null) {
        return true;
    }
    if (!controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + '?', source, game)) {
        return true;
    }
    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 || !card.isInstantOrSorcery(game)) {
        return true;
    }
    ContinuousEffect effect = new ScholarOfTheLostTroveReplacementEffect(card.getId());
    effect.setTargetPointer(new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
    game.addEffect(effect, source);
    return true;
}
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)

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