Search in sources :

Example 36 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class HideawayPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ExileZone zone = null;
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (permanent != null) {
        zone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), permanent.getZoneChangeCounter(game)));
    }
    if (zone == null) {
        return true;
    }
    Set<Card> cards = zone.getCards(game);
    if (cards.isEmpty()) {
        return true;
    }
    Card card = cards.iterator().next();
    Player controller = game.getPlayer(source.getControllerId());
    if (card != null && controller != null) {
        if (controller.chooseUse(Outcome.PlayForFree, "Play " + card.getIdName() + " for free?", source, game)) {
            card.setFaceDown(false, game);
            int zcc = card.getZoneChangeCounter(game);
            /* 702.74. Hideaway, rulings:
                 * If the removed card is a land, you may play it as a result of the last ability only if it's your turn
                 * and you haven't already played a land that turn. This counts as your land play for the turn.
                 */
            if (card.isLand(game)) {
                UUID playerId = controller.getId();
                if (!game.isActivePlayer(playerId) || !game.getPlayer(playerId).canPlayLand()) {
                    return false;
                }
            }
            if (!controller.playCard(card, game, true, new ApprovingObject(source, game))) {
                if (card.getZoneChangeCounter(game) == zcc) {
                    card.setFaceDown(true, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Card(mage.cards.Card)

Example 37 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class IdolOfEnduranceWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
    return exileZone != null && !exileZone.isEmpty() && player.moveCards(exileZone, Zone.GRAVEYARD, source, game);
}
Also used : Player(mage.players.Player) ExileZone(mage.game.ExileZone)

Example 38 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class PlanarGuideReturnFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (sourceObject != null && controller != null) {
        Set<Card> toExile = new HashSet<>();
        toExile.addAll(game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game));
        controller.moveCardsToExile(toExile, source, game, true, source.getSourceId(), sourceObject.getIdName());
        ExileZone exile = game.getExile().getExileZone(source.getSourceId());
        if (exile != null && !exile.isEmpty()) {
            // Create delayed triggered ability
            AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new PlanarGuideReturnFromExileEffect());
            game.addDelayedTriggeredAbility(delayedAbility, source);
            return true;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 39 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class ScrollRackEffect 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) {
        FilterCard filter = new FilterCard("card in your hand to exile");
        TargetCardInHand target = new TargetCardInHand(0, controller.getHand().size(), filter);
        target.setRequired(false);
        int amountExiled = 0;
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
            if (!target.getTargets().isEmpty()) {
                for (UUID targetId : target.getTargets()) {
                    Card card = game.getCard(targetId);
                    if (card != null) {
                        card.setFaceDown(true, game);
                        amountExiled++;
                    }
                }
                controller.moveCardsToExile(new CardsImpl(target.getTargets()).getCards(game), source, game, false, source.getSourceId(), sourceObject.getIdName());
                ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
                if (exileZone != null) {
                    for (Card card : exileZone.getCards(game)) {
                        card.setFaceDown(true, game);
                    }
                }
            }
        }
        // Put that many cards from the top of your library into your hand.
        if (amountExiled > 0) {
            controller.moveCards(controller.getLibrary().getTopCards(game, amountExiled), Zone.HAND, source, game);
        }
        // Then look at the exiled cards and put them on top of your library in any order
        controller.putCardsOnTopOfLibrary(game.getExile().getExileZone(source.getSourceId()), game, source, true);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 40 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class SharedFateLookEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (game.getState().getZone(objectId) == Zone.EXILED) {
        Permanent sourcePermanent = game.getPermanent(source.getSourceId());
        UUID exileId = CardUtil.getExileZoneId(source.getSourceId().toString() + sourcePermanent.getZoneChangeCounter(game) + affectedControllerId.toString(), game);
        ExileZone exileZone = game.getExile().getExileZone(exileId);
        if (exileZone != null && exileZone.contains(objectId)) {
            Card card = game.getCard(objectId);
            return card != null && game.getState().getZone(objectId) == Zone.EXILED;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Card(mage.cards.Card)

Aggregations

ExileZone (mage.game.ExileZone)92 Player (mage.players.Player)61 UUID (java.util.UUID)44 Card (mage.cards.Card)44 MageObject (mage.MageObject)24 Permanent (mage.game.permanent.Permanent)23 FilterCard (mage.filter.FilterCard)15 HashSet (java.util.HashSet)11 ApprovingObject (mage.ApprovingObject)9 CardsImpl (mage.cards.CardsImpl)9 TargetCard (mage.target.TargetCard)9 Cards (mage.cards.Cards)7 MageObjectReference (mage.MageObjectReference)6 Ability (mage.abilities.Ability)5 Spell (mage.game.stack.Spell)5 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 TransformSourceEffect (mage.abilities.effects.common.TransformSourceEffect)3 TargetPlayer (mage.target.TargetPlayer)3 Objects (java.util.Objects)2 Set (java.util.Set)2