Search in sources :

Example 6 with ExileZone

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

the class HideawayLookAtFaceDownCardEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (game.getState().getZone(objectId) != Zone.EXILED || !game.getState().getCardState(objectId).isFaceDown()) {
        return false;
    }
    // TODO: Does not handle if a player had the control of the land permanent some time before
    // we would need to add a watcher to handle this
    Permanent sourcePermanet = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourcePermanet != null && sourcePermanet.isControlledBy(affectedControllerId)) {
        ExileZone exile = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
        Card card = game.getCard(objectId);
        if (exile != null && exile.contains(objectId) && card != null) {
            Player player = game.getPlayer(affectedControllerId);
            if (player != null) {
                player.lookAtCards("Hideaway by " + sourcePermanet.getIdName(), card, game);
            }
        }
    }
    // only the current or a previous controller can see the card, so always return false for reveal request
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 7 with ExileZone

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

the class ReboundCastSpellFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ExileZone zone = game.getExile().getExileZone(source.getSourceId());
    if (zone == null || zone.isEmpty()) {
        return false;
    }
    Card reboundCard = zone.get(source.getSourceId(), game);
    Player player = game.getPlayer(source.getControllerId());
    if (player != null && reboundCard != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + reboundCard.getId(), Boolean.TRUE);
        Boolean cardWasCast = player.cast(player.chooseAbilityForCast(reboundCard, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + reboundCard.getId(), null);
        return cardWasCast;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ExileZone(mage.game.ExileZone) Card(mage.cards.Card)

Example 8 with ExileZone

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

the class AminatousAuguryCastFromExileEffect 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) {
        // move cards from library to exile
        controller.moveCardsToExile(controller.getLibrary().getTopCards(game, 8), source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
        ExileZone auguryExileZone = game.getExile().getExileZone(source.getSourceId());
        if (auguryExileZone == null) {
            return true;
        }
        Cards cardsToCast = new CardsImpl();
        cardsToCast.addAll(auguryExileZone.getCards(game));
        // put a land card from among them onto the battlefield
        TargetCard target = new TargetCard(Zone.EXILED, StaticFilters.FILTER_CARD_LAND_A);
        if (cardsToCast.count(StaticFilters.FILTER_CARD_LAND, game) > 0) {
            if (controller.chooseUse(Outcome.PutLandInPlay, "Put a land from among the exiled cards into play?", source, game)) {
                if (controller.choose(Outcome.PutLandInPlay, cardsToCast, target, game)) {
                    Card card = cardsToCast.get(target.getFirstTarget(), game);
                    if (card != null) {
                        cardsToCast.remove(card);
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
                    }
                }
            }
        }
        for (Card card : cardsToCast.getCards(StaticFilters.FILTER_CARD_NON_LAND, game)) {
            AminatousAuguryCastFromExileEffect effect = new AminatousAuguryCastFromExileEffect();
            effect.setTargetPointer(new FixedTarget(card, game));
            game.addEffect(effect, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 9 with ExileZone

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

the class BagOfHoldingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
    if (exileZone == null) {
        return true;
    }
    return controller.moveCards(exileZone, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) ExileZone(mage.game.ExileZone)

Example 10 with ExileZone

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

the class CemeteryIlluminatorWatcher method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    // Once per turn clause checked by Watcher same as Lurrus of the Dream Den
    if (affectedControllerId.equals(source.getControllerId())) {
        Player controller = game.getPlayer(source.getControllerId());
        CemeteryIlluminatorWatcher watcher = game.getState().getWatcher(CemeteryIlluminatorWatcher.class);
        Permanent sourceObject = game.getPermanent(source.getSourceId());
        if (controller != null && watcher != null && sourceObject != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game))) {
            Card card = game.getCard(objectId);
            Card topCard = controller.getLibrary().getFromTop(game);
            if (card != null && topCard != null && topCard.getId().equals(card.getMainCard().getId()) && !card.isLand(game) && !card.getManaCost().isEmpty()) {
                // Check if it shares a card type with exiled cards
                UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()));
                ExileZone exileZone = game.getExile().getExileZone(exileId);
                if (exileZone != null) {
                    HashSet<CardType> cardTypes = new HashSet<>(card.getCardType(game));
                    for (UUID exileCardId : exileZone) {
                        Card exileCard = game.getCard(exileCardId);
                        if (exileCard != null) {
                            for (CardType exileType : exileCard.getCardType(game)) {
                                if (cardTypes.contains(exileType)) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) HashSet(java.util.HashSet)

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