Search in sources :

Example 31 with MageObject

use of mage.MageObject in project mage by magefree.

the class PsychicIntrusionSpendAnyManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (opponent != null && sourceObject != null) {
        opponent.revealCards(sourceObject.getName(), opponent.getHand(), game);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            int cardsGraveyard = opponent.getGraveyard().count(filter, game);
            int cardsHand = opponent.getHand().count(filter, game);
            boolean fromHand = false;
            if (cardsGraveyard > 0 && cardsHand > 0) {
                if (controller.chooseUse(Outcome.Detriment, "Exile card from opponents Hand?", source, game)) {
                    fromHand = true;
                }
            } else {
                if (cardsHand > 0) {
                    fromHand = true;
                }
            }
            Card card = null;
            if (cardsHand > 0 && fromHand) {
                TargetCard target = new TargetCard(Zone.HAND, filter);
                if (controller.choose(Outcome.Benefit, opponent.getHand(), target, game)) {
                    card = opponent.getHand().get(target.getFirstTarget(), game);
                }
            }
            if (cardsGraveyard > 0 && !fromHand) {
                TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
                if (controller.choose(Outcome.Benefit, opponent.getGraveyard(), target, game)) {
                    card = opponent.getGraveyard().get(target.getFirstTarget(), game);
                }
            }
            if (card != null) {
                // move card to exile
                UUID exileId = CardUtil.getCardExileZoneId(game, source);
                controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source, game, fromHand ? Zone.HAND : Zone.GRAVEYARD, true);
                // allow to cast the card
                ContinuousEffect effect = new PsychicIntrusionCastFromExileEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
                // and you may spend mana as though it were mana of any color to cast it
                effect = new PsychicIntrusionSpendAnyManaEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 32 with MageObject

use of mage.MageObject in project mage by magefree.

the class PuresightMerrowEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card != null) {
            Cards cards = new CardsImpl(card);
            controller.lookAtCards("Puresight Merrow", cards, game);
            if (controller.chooseUse(Outcome.Removal, "Exile the card from the top of your library?", source, game)) {
                controller.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getIdName(), source, game, Zone.LIBRARY, true);
            } else {
                game.informPlayers(controller.getLogName() + " puts the card back on top of their library.");
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 33 with MageObject

use of mage.MageObject in project mage by magefree.

the class PsychoticEpisodeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player != null && controller != null && sourceObject != null) {
        TargetCard targetCard = new TargetCard(Zone.ALL, new FilterCard());
        targetCard.setRequired(true);
        Cards options = player.getHand().copy();
        Card topdeck = player.getLibrary().getFromTop(game);
        options.add(topdeck);
        controller.lookAtCards("Top of Library (Psychotic Episode)", topdeck, game);
        if (controller.choose(Outcome.Discard, options, targetCard, game)) {
            Card card = game.getCard(targetCard.getFirstTarget());
            if (card != null) {
                CardsImpl cards = new CardsImpl();
                cards.add(card);
                player.revealCards(sourceObject.getIdName(), cards, game);
                player.putCardsOnBottomOfLibrary(cards, game, source, true);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 34 with MageObject

use of mage.MageObject in project mage by magefree.

the class PucasMischiefSecondTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> possibleTargets = new HashSet<>();
    MageObject targetSource = game.getObject(sourceId);
    if (targetSource != null) {
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
            if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
                possibleTargets.add(permanent.getId());
            }
        }
    }
    return possibleTargets;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 35 with MageObject

use of mage.MageObject in project mage by magefree.

the class RenownedWeaponsmithEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Cards revealed = new CardsImpl();
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    revealed.add(card);
                    controller.revealCards(sourceObject.getIdName(), revealed, game);
                    controller.moveCards(revealed, Zone.HAND, source, game);
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Aggregations

MageObject (mage.MageObject)738 Player (mage.players.Player)554 Permanent (mage.game.permanent.Permanent)239 UUID (java.util.UUID)224 Card (mage.cards.Card)210 FilterCard (mage.filter.FilterCard)113 CardsImpl (mage.cards.CardsImpl)106 TargetCard (mage.target.TargetCard)91 Cards (mage.cards.Cards)73 Spell (mage.game.stack.Spell)68 FixedTarget (mage.target.targetpointer.FixedTarget)66 HashSet (java.util.HashSet)56 Ability (mage.abilities.Ability)52 ContinuousEffect (mage.abilities.effects.ContinuousEffect)51 TargetPermanent (mage.target.TargetPermanent)48 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)48 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)46 Target (mage.target.Target)44 Effect (mage.abilities.effects.Effect)42 OneShotEffect (mage.abilities.effects.OneShotEffect)41