Search in sources :

Example 51 with ExileZone

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

the class NightveilSpecterEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    Card theCard = game.getCard(objectId);
    if (theCard == null) {
        return false;
    }
    // for split cards
    objectId = theCard.getMainCard().getId();
    if (affectedControllerId.equals(source.getControllerId()) && game.getState().getZone(objectId) == Zone.EXILED) {
        ExileZone zone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
        return zone != null && zone.contains(objectId);
    }
    return false;
}
Also used : ExileZone(mage.game.ExileZone) Card(mage.cards.Card)

Example 52 with ExileZone

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

the class PossibilityStormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
    // spell was exiled already by another effect, for example NivMagus Elemental
    boolean noLongerOnStack = false;
    if (spell == null) {
        spell = ((Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK));
        noLongerOnStack = true;
    }
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null && spell != null) {
        Player spellController = game.getPlayer(spell.getControllerId());
        if (spellController != null) {
            if (!noLongerOnStack) {
                spellController.moveCardsToExile(spell, source, game, true, source.getSourceId(), sourceObject.getIdName());
            }
            if (spellController.getLibrary().hasCards()) {
                Library library = spellController.getLibrary();
                Card card;
                do {
                    card = library.getFromTop(game);
                    if (card != null) {
                        spellController.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
                    }
                } while (library.hasCards() && card != null && !sharesType(card, spell.getCardType(game), game));
                if (card != null && sharesType(card, spell.getCardType(game), game) && !card.isLand(game) && card.getSpellAbility().canChooseTarget(game, spellController.getId())) {
                    if (spellController.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + " without paying cost?", source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                        spellController.cast(spellController.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    }
                }
                ExileZone exile = game.getExile().getExileZone(source.getSourceId());
                if (exile != null) {
                    spellController.putCardsOnBottomOfLibrary(exile, game, source, false);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) Library(mage.players.Library) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 53 with ExileZone

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

the class SaviorOfOllenbockEffect method apply.

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

Example 54 with ExileZone

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

the class SistersOfStoneDeathEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    CardsImpl cardsInExile = new CardsImpl();
    TargetCard target = new TargetCard(Zone.EXILED, StaticFilters.FILTER_CARD_CREATURE);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
        if (exile != null) {
            LinkedList<UUID> cards = new LinkedList<>(exile);
            for (UUID cardId : cards) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    cardsInExile.add(card);
                }
            }
            if (controller.choose(Outcome.PutCreatureInPlay, cardsInExile, target, game)) {
                Card chosenCard = game.getCard(target.getFirstTarget());
                return controller.moveCards(chosenCard, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ExileZone(mage.game.ExileZone) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) LinkedList(java.util.LinkedList) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 55 with ExileZone

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

the class ThreeWishesPlayFromExileEffect method applies.

@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
    UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), 0);
    ExileZone exile = game.getExile().getExileZone(exileId);
    return exile != null && getTargetPointer().getFirst(game, source) != null && getTargetPointer().getFirst(game, source).equals(sourceId) && source.isControlledBy(affectedControllerId) && game.getState().getZone(sourceId) == Zone.EXILED && exile.contains(sourceId);
}
Also used : ExileZone(mage.game.ExileZone) UUID(java.util.UUID)

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