Search in sources :

Example 41 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class SpellshiftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player spellController = game.getPlayer(((Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK)).getControllerId());
    if (spellController != null) {
        Cards cardsToReveal = new CardsImpl();
        Card toCast = null;
        for (Card card : spellController.getLibrary().getCards(game)) {
            cardsToReveal.add(card);
            if (card.isSorcery(game) || card.isInstant(game)) {
                toCast = card;
                break;
            }
        }
        spellController.revealCards(source, cardsToReveal, game);
        if (toCast != null && spellController.chooseUse(outcome, "Cast " + toCast.getLogName() + " without paying its mana cost?", source, game)) {
            game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), Boolean.TRUE);
            spellController.cast(spellController.chooseAbilityForCast(toCast, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), null);
        }
        spellController.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 42 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class SpelltwineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card cardOne = game.getCard(source.getTargets().get(0).getFirstTarget());
    Card cardTwo = game.getCard(source.getTargets().get(1).getFirstTarget());
    if (controller != null) {
        if (cardOne != null) {
            controller.moveCards(cardOne, Zone.EXILED, source, game);
        }
        if (cardTwo != null) {
            controller.moveCards(cardTwo, Zone.EXILED, source, game);
        }
        boolean castCardOne = true;
        ApprovingObject approvingObject = new ApprovingObject(source, game);
        if (cardOne != null && controller.chooseUse(Outcome.Neutral, "Cast the copy of " + cardOne.getName() + " first?", source, game)) {
            Card copyOne = game.copyCard(cardOne, source, controller.getId());
            game.getState().setValue("PlayFromNotOwnHandZone" + copyOne.getId(), Boolean.TRUE);
            controller.cast(controller.chooseAbilityForCast(copyOne, game, true), game, true, approvingObject);
            game.getState().setValue("PlayFromNotOwnHandZone" + copyOne.getId(), null);
            castCardOne = false;
        }
        if (cardTwo != null) {
            Card copyTwo = game.copyCard(cardTwo, source, controller.getId());
            game.getState().setValue("PlayFromNotOwnHandZone" + copyTwo.getId(), Boolean.TRUE);
            controller.cast(controller.chooseAbilityForCast(copyTwo, game, true), game, true, approvingObject);
            game.getState().setValue("PlayFromNotOwnHandZone" + copyTwo.getId(), null);
        }
        if (cardOne != null && castCardOne) {
            Card copyOne = game.copyCard(cardOne, source, controller.getId());
            game.getState().setValue("PlayFromNotOwnHandZone" + copyOne.getId(), Boolean.TRUE);
            controller.cast(controller.chooseAbilityForCast(copyOne, game, true), game, true, approvingObject);
            game.getState().setValue("PlayFromNotOwnHandZone" + copyOne.getId(), null);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 43 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ThunderbladeChargeCastEffect 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 && Zone.GRAVEYARD == game.getState().getZone(sourceCard.getId())) {
        game.getState().setValue("PlayFromNotOwnHandZone" + sourceCard.getId(), Boolean.TRUE);
        Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(sourceCard, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + sourceCard.getId(), null);
        return cardWasCast;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Card(mage.cards.Card)

Example 44 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class VelomachusLoreholdEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentOrLKI(game);
    if (controller == null || permanent == null) {
        return false;
    }
    Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 7);
    Cards cards = new CardsImpl(cardsSet);
    FilterCard filter = new FilterInstantOrSorceryCard("instant or sorcery card with mana value " + permanent.getPower().getValue() + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getPower().getValue() + 1));
    TargetCard target = new TargetCardInLibrary(0, 1, filter);
    controller.choose(Outcome.PlayForFree, cards, target, game);
    Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
    if (card == null) {
        controller.putCardsOnBottomOfLibrary(cards, game, source, false);
        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) {
        cards.remove(card);
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) FilterCard(mage.filter.FilterCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate)

Example 45 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class DjinnOfWishesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null && controller.getLibrary().hasCards()) {
        Card card = controller.getLibrary().getFromTop(game);
        Cards cards = new CardsImpl(card);
        controller.revealCards(sourceObject.getIdName(), cards, game);
        if (!controller.chooseUse(Outcome.PlayForFree, "Play " + card.getName() + " without paying its mana cost?", source, game) || !controller.playCard(card, game, true, new ApprovingObject(source, game))) {
            controller.moveCards(card, Zone.EXILED, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject)

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