Search in sources :

Example 71 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class KnowledgeExploitationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (controller == null || opponent == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
    controller.searchLibrary(target, source, game, opponent.getId());
    Card card = opponent.getLibrary().getCard(target.getFirstTarget(), game);
    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);
    }
    opponent.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 72 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MindclawShamanEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetOpponent = game.getPlayer(source.getFirstTarget());
    MageObject sourceObject = source.getSourceObject(game);
    if (targetOpponent != null && sourceObject != null) {
        if (!targetOpponent.getHand().isEmpty()) {
            targetOpponent.revealCards(sourceObject.getName(), targetOpponent.getHand(), game);
            Player controller = game.getPlayer(source.getControllerId());
            if (controller != null) {
                TargetCard target = new TargetCard(Zone.HAND, filter);
                target.setNotTarget(true);
                if (controller.choose(Outcome.PlayForFree, targetOpponent.getHand(), target, game)) {
                    Card chosenCard = targetOpponent.getHand().get(target.getFirstTarget(), game);
                    if (chosenCard != null) {
                        if (controller.chooseUse(Outcome.PlayForFree, "Cast the chosen card without " + "paying its mana cost?", source, game)) {
                            game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), Boolean.TRUE);
                            controller.cast(controller.chooseAbilityForCast(chosenCard, game, true), game, true, new ApprovingObject(source, game));
                            game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), null);
                        } else {
                            game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " canceled casting the card.");
                        }
                    }
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 73 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class OmnispellAdeptEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard realFilter = filter.copy();
    Target target = new TargetCardInHand(realFilter);
    // choose one card until it possible to cast
    if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery " + "card from your hand without paying its mana cost?", source, game)) {
        Card cardToCast;
        while (controller.canRespond() && controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
            cardToCast = game.getCard(target.getFirstTarget());
            if (cardToCast == null) {
                break;
            }
            // remove card from choose dialog (infinite fix)
            realFilter.add(Predicates.not(new CardIdPredicate(cardToCast.getId())));
            if (!cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
                continue;
            }
            game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
            Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
            if (cardWasCast) {
                break;
            } else {
                game.informPlayer(controller, "You're not able to cast " + cardToCast.getIdName() + " or you canceled the casting.");
            }
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 74 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class OmenMachineEffect2 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player != null) {
        Card card = player.getLibrary().getFromTop(game);
        if (card != null) {
            player.moveCards(card, Zone.EXILED, source, game);
            if (card.isLand(game)) {
                player.moveCards(card, Zone.BATTLEFIELD, source, game);
            } else {
                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;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Card(mage.cards.Card)

Example 75 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class PanopticMirrorCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent PanopticMirror = game.getPermanent(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (PanopticMirror == null) {
        PanopticMirror = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    }
    if (PanopticMirror != null && PanopticMirror.getImprinted() != null && !PanopticMirror.getImprinted().isEmpty() && controller != null) {
        CardsImpl cards = new CardsImpl();
        for (UUID uuid : PanopticMirror.getImprinted()) {
            Card card = game.getCard(uuid);
            if (card != null) {
                if (card instanceof SplitCard) {
                    cards.add(((SplitCard) card).getLeftHalfCard());
                    cards.add(((SplitCard) card).getRightHalfCard());
                } else if (card instanceof ModalDoubleFacesCard) {
                    cards.add(((ModalDoubleFacesCard) card).getLeftHalfCard());
                    cards.add(((ModalDoubleFacesCard) card).getRightHalfCard());
                } else {
                    cards.add(card);
                }
            }
        }
        Card cardToCopy;
        if (cards.size() == 1) {
            cardToCopy = cards.getCards(game).iterator().next();
        } else {
            TargetCard target = new TargetCard(1, Zone.EXILED, new FilterCard("card to copy"));
            controller.choose(Outcome.Copy, cards, target, game);
            cardToCopy = cards.get(target.getFirstTarget(), game);
        }
        if (cardToCopy != null) {
            Card copy = game.copyCard(cardToCopy, source, source.getControllerId());
            if (controller.chooseUse(Outcome.PlayForFree, "Cast the copied card without paying mana cost?", source, game)) {
                game.getState().setValue("PlayFromNotOwnHandZone" + copy.getId(), Boolean.TRUE);
                controller.cast(controller.chooseAbilityForCast(copy, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + copy.getId(), null);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

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