Search in sources :

Example 21 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class RashmiEternitiesCrafterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Boolean cardWasCast = false;
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card != null) {
            controller.revealCards("Rashmi, Eternities Crafter", new CardsImpl(card), game);
            if (card.isLand(game)) {
                controller.moveCards(card, Zone.HAND, source, game);
                return true;
            }
            Object cmcObject = this.getValue("RashmiEternitiesCrafterCMC");
            if (cmcObject != null && card.getManaValue() < (int) cmcObject && controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
            }
            if (!cardWasCast) {
                controller.moveCards(card, Zone.HAND, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ApprovingObject(mage.ApprovingObject) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 22 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ToshiroUmezawaReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = game.getCard(getTargetPointer().getFirst(game, source));
        if (card != null && controller.getGraveyard().contains(card.getId())) {
            // must be in graveyard
            game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
            controller.cast(controller.chooseAbilityForCast(card, game, false), game, false, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
            game.addEffect(new ToshiroUmezawaReplacementEffect(card.getId()), source);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 23 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class GarthOneEyeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    initMap();
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<String> alreadyChosen = getAlreadyChosen(game, source);
    Set<String> choices = new HashSet<>(names);
    choices.removeAll(alreadyChosen);
    String chosen;
    switch(choices.size()) {
        case 0:
            return false;
        case 1:
            chosen = choices.stream().findAny().orElse(null);
            break;
        default:
            Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD);
            choice.setChoices(choices);
            player.choose(outcome, choice, game);
            chosen = choice.getChoice();
    }
    alreadyChosen.add(chosen);
    Card card = cardMap.get(chosen);
    if (card == null || !player.chooseUse(outcome, "Cast " + card.getName() + '?', source, game)) {
        return false;
    }
    Card copiedCard = game.copyCard(card, source, source.getControllerId());
    copiedCard.setZone(Zone.OUTSIDE, game);
    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
    player.cast(player.chooseAbilityForCast(copiedCard, game, false), game, false, new ApprovingObject(source, game));
    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ApprovingObject(mage.ApprovingObject) ChoiceImpl(mage.choices.ChoiceImpl) Card(mage.cards.Card)

Example 24 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class HarnessTheStormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = controller.getGraveyard().get(getTargetPointer().getFirst(game, source), game);
        if (card != null) {
            if (controller.chooseUse(outcome.Benefit, "Cast " + card.getIdName() + " from your graveyard?", source, game)) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                controller.cast(controller.chooseAbilityForCast(card, game, false), game, false, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 25 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MindleechMassEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (opponent != null && controller != null) {
        Cards cardsInHand = new CardsImpl();
        cardsInHand.addAll(opponent.getHand());
        opponent.revealCards("Opponents hand", cardsInHand, game);
        if (!cardsInHand.isEmpty() && !cardsInHand.getCards(new FilterNonlandCard(), game).isEmpty()) {
            TargetCard target = new TargetCard(1, Zone.HAND, new FilterNonlandCard());
            if (controller.chooseTarget(Outcome.PlayForFree, cardsInHand, target, source, game)) {
                Card card = game.getCard(target.getFirstTarget());
                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);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) 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