Search in sources :

Example 16 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class DreadhordeArcanistReplacementEffect 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 && controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + '?', source, game)) {
        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);
    }
    ContinuousEffect effect = new DreadhordeArcanistReplacementEffect(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) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) ApprovingObject(mage.ApprovingObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 17 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class GoblinDarkDwellersReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
        if (card != null) {
            if (controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + '?', 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);
                if (cardWasCast) {
                    ContinuousEffect effect = new GoblinDarkDwellersReplacementEffect(card.getId());
                    effect.setTargetPointer(new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
                    game.addEffect(effect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 18 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class JourneyToTheOracleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    controller.revealCards(source, new CardsImpl(card), game);
    if (card.isLand(game)) {
        // note that MDFC land cards are handled differently: they can't be moved
        return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    // query player
    if (!controller.chooseUse(outcome, "Cast " + card.getName() + " by paying {1}?", source, game)) {
        return false;
    }
    // handle split-cards
    if (card instanceof SplitCard) {
        SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
        SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
        // get additional cost if any
        Costs additionalCostsLeft = leftHalfCard.getSpellAbility().getCosts();
        Costs additionalCostsRight = rightHalfCard.getSpellAbility().getCosts();
        // set alternative cost and any additional cost
        controller.setCastSourceIdWithAlternateMana(leftHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsLeft);
        controller.setCastSourceIdWithAlternateMana(rightHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsRight);
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), Boolean.TRUE);
    }
    // handle MDFC
    if (card instanceof ModalDoubleFacesCard) {
        ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
        ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
        // some MDFC cards are lands.  IE: sea gate restoration
        if (!leftHalfCard.isLand(game)) {
            // get additional cost if any
            Costs additionalCostsMDFCLeft = leftHalfCard.getSpellAbility().getCosts();
            // set alternative cost and any additional cost
            controller.setCastSourceIdWithAlternateMana(leftHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsMDFCLeft);
        }
        if (!rightHalfCard.isLand(game)) {
            // get additional cost if any
            Costs additionalCostsMDFCRight = rightHalfCard.getSpellAbility().getCosts();
            // set alternative cost and any additional cost
            controller.setCastSourceIdWithAlternateMana(rightHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsMDFCRight);
        }
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), Boolean.TRUE);
    }
    // handle adventure cards
    if (card instanceof AdventureCard) {
        Card creatureCard = card.getMainCard();
        Card spellCard = ((AdventureCard) card).getSpellCard();
        // get additional cost if any
        Costs additionalCostsCreature = creatureCard.getSpellAbility().getCosts();
        Costs additionalCostsSpellCard = spellCard.getSpellAbility().getCosts();
        // set alternative cost and any additional cost
        controller.setCastSourceIdWithAlternateMana(creatureCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsCreature);
        controller.setCastSourceIdWithAlternateMana(spellCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsSpellCard);
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + creatureCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + spellCard.getId(), Boolean.TRUE);
    }
    // normal card
    if (!(card instanceof SplitCard) || !(card instanceof ModalDoubleFacesCard) || !(card instanceof AdventureCard)) {
        // get additional cost if any
        Costs additionalCostsNormalCard = card.getSpellAbility().getCosts();
        controller.setCastSourceIdWithAlternateMana(card.getMainCard().getId(), new ManaCostsImpl<>("{1}"), additionalCostsNormalCard);
    }
    // cast it
    controller.cast(controller.chooseAbilityForCast(card.getMainCard(), game, false), game, false, new ApprovingObject(source, game));
    // turn off effect after cast on every possible card-face
    if (card instanceof SplitCard) {
        SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
        SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), null);
    }
    if (card instanceof ModalDoubleFacesCard) {
        ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
        ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), null);
    }
    if (card instanceof AdventureCard) {
        Card creatureCard = card.getMainCard();
        Card spellCard = ((AdventureCard) card).getSpellCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + creatureCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + spellCard.getId(), null);
    }
    // turn off effect on a normal card
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    return true;
}
Also used : Player(mage.players.Player) Costs(mage.abilities.costs.Costs) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) ApprovingObject(mage.ApprovingObject) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) SplitCardHalf(mage.cards.SplitCardHalf) CardsImpl(mage.cards.CardsImpl) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard)

Example 19 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MasterOfPredicamentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (!controller.getHand().isEmpty()) {
            Card cardFromHand = null;
            if (controller.getHand().size() > 1) {
                TargetCard target = new TargetCardInHand(new FilterCard());
                if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) {
                    cardFromHand = game.getCard(target.getFirstTarget());
                }
            } else {
                cardFromHand = controller.getHand().getRandom(game);
            }
            if (cardFromHand == null) {
                return false;
            }
            Player attackedPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
            if (attackedPlayer == null) {
                return false;
            }
            boolean guessWrong;
            if (attackedPlayer.chooseUse(Outcome.Detriment, "Is the chosen card's " + "mana value greater than 4?", source, game)) {
                game.informPlayers(attackedPlayer.getLogName() + " guessed that the chosen " + "card's mana value is greater than 4");
                guessWrong = cardFromHand.getManaValue() <= 4;
            } else {
                game.informPlayers(attackedPlayer.getLogName() + " guessed that the chosen " + "card's mana value is not greater than 4");
                guessWrong = cardFromHand.getManaValue() > 4;
            }
            game.informPlayers(attackedPlayer.getLogName() + " guessed " + (guessWrong ? "wrong" : "right"));
            if (guessWrong) {
                if (cardFromHand.isLand(game)) {
                // If the revealed card is a land, you can't cast it. So nothing happens
                } else {
                    if (controller.chooseUse(outcome, "Cast " + cardFromHand.getName() + " without paying its mana cost?", source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + cardFromHand.getId(), Boolean.TRUE);
                        controller.cast(controller.chooseAbilityForCast(cardFromHand, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + cardFromHand.getId(), null);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 20 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class OracleOfBonesCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetCardInHand(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Cast an instant or sorcery " + "card from your hand without paying its mana cost?", source, game)) {
            Card cardToCast = null;
            boolean cancel = false;
            while (controller.canRespond() && !cancel) {
                if (controller.chooseTarget(outcome, target, source, game)) {
                    cardToCast = game.getCard(target.getFirstTarget());
                    if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
                        cancel = true;
                    }
                } else {
                    cancel = true;
                }
            }
            if (cardToCast != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
                controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
            }
        }
        return true;
    }
    return false;
}
Also used : 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)

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