Search in sources :

Example 66 with ExileZone

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

the class GrimoireThiefCounterspellEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (affectedControllerId.equals(source.getControllerId()) && game.getState().getZone(objectId) == Zone.EXILED) {
        Player controller = game.getPlayer(source.getControllerId());
        MageObject sourceObject = source.getSourceObject(game);
        if (controller != null && sourceObject != null) {
            Card card = game.getCard(objectId);
            if (card != null && card.isFaceDown(game)) {
                Set<UUID> exileZones = (Set<UUID>) game.getState().getValue(GrimoireThief.VALUE_PREFIX + source.getSourceId().toString());
                if (exileZones != null) {
                    for (ExileZone exileZone : game.getExile().getExileZones()) {
                        if (exileZone.contains(objectId)) {
                            if (!exileZones.contains(exileZone.getId())) {
                                return false;
                            }
                        }
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Set(java.util.Set) HashSet(java.util.HashSet) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) UUID(java.util.UUID)

Example 67 with ExileZone

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

the class HedonistsTroveWatcher method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    Card cardToCheck = game.getCard(objectId);
    if (cardToCheck == null || !cardToCheck.isLand(game) || !source.isControlledBy(affectedControllerId)) {
        return false;
    }
    // use the correct exileId
    UUID exileId = (UUID) game.getState().getValue(source.getSourceId().toString());
    ExileZone exileZone = game.getExile().getExileZone(exileId);
    return exileZone != null && exileZone.contains(cardToCheck.getMainCard().getId());
}
Also used : ExileZone(mage.game.ExileZone) Card(mage.cards.Card)

Example 68 with ExileZone

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

the class JeskaiInfiltratorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> cardsToManifest = new HashSet<>();
        cardsToManifest.add(source.getSourcePermanentIfItStillExists(game));
        cardsToManifest.add(controller.getLibrary().getFromTop(game));
        UUID exileId = UUID.randomUUID();
        controller.moveCardsToExile(cardsToManifest, source, game, false, exileId, "");
        ExileZone exileZone = game.getExile().getExileZone(exileId);
        for (Card card : exileZone.getCards(game)) {
            card.setFaceDown(true, game);
        }
        // removes Jeskai Infiltrator from Battlefield, so Jeskai Infiltrator returns as a fresh permanent to the battlefield with new position
        game.fireUpdatePlayersEvent();
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        // the Set will mimic the Shuffling
        exileZone.getCards(game).forEach(card -> {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        });
        controller.moveCards(exileZone.getCards(game), Zone.BATTLEFIELD, source, game, false, true, false, null);
        return true;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DealsCombatDamageToAPlayerTriggeredAbility(mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility) Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) HashSet(java.util.HashSet) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 69 with ExileZone

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

the class KitesailFreebooterReturnExiledCardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null && controller != null) {
        ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
        Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
        if (exile != null && sourcePermanent != null) {
            controller.moveCards(exile, Zone.HAND, source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone)

Example 70 with ExileZone

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

the class KnowledgeVaultReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (sourcePermanent != null && controller != null) {
        if (sourcePermanent.sacrifice(source, game)) {
            new DiscardHandControllerEffect().apply(game, source);
            ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
            if (exileZone != null) {
                controller.moveCards(exileZone, Zone.HAND, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) DiscardHandControllerEffect(mage.abilities.effects.common.discard.DiscardHandControllerEffect)

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