Search in sources :

Example 71 with ExileZone

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

the class TibaltsTrickeryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
    if (spell != null) {
        String spellName = spell.getName();
        Player controller = game.getPlayer(spell.getControllerId());
        game.getStack().counter(spell.getId(), source, game);
        if (controller != null) {
            int random = RandomUtil.nextInt(3) + 1;
            game.informPlayers(random + " was chosen at random");
            controller.millCards(random, source, game);
            Card cardToCast = null;
            Set<Card> cardsToExile = new HashSet<>();
            FilterCard filter = new FilterCard();
            filter.add(Predicates.not(CardType.LAND.getPredicate()));
            filter.add(Predicates.not(new NamePredicate(spellName)));
            for (Card card : controller.getLibrary().getCards(game)) {
                cardsToExile.add(card);
                if (filter.match(card, game)) {
                    cardToCast = card;
                    break;
                }
            }
            controller.moveCardsToExile(cardsToExile, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
            if (cardToCast != null) {
                if (controller.chooseUse(Outcome.PlayForFree, "Cast " + cardToCast.getLogName() + " for free?", source, game)) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
                }
            }
            ExileZone exile = game.getExile().getExileZone(source.getSourceId());
            if (exile != null) {
                controller.putCardsOnBottomOfLibrary(exile, game, source, false);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ApprovingObject(mage.ApprovingObject) ExileZone(mage.game.ExileZone) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 72 with ExileZone

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

the class WizardsSpellbookEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (player == null || card == null) {
        return false;
    }
    UUID exileId = CardUtil.getExileZoneId(game, source);
    player.moveCardsToExile(card, source, game, true, exileId, CardUtil.getSourceName(game, source));
    if (level < 3) {
        Card copiedCard = game.copyCard(card, source, source.getControllerId());
        if (!player.chooseUse(Outcome.Benefit, "Cast " + copiedCard.getName() + (level == 1 ? "?" : " by paying {1}?"), source, game)) {
            return false;
        }
        SpellAbility spellAbility = player.chooseAbilityForCast(copiedCard, game, level == 2);
        if (spellAbility == null) {
            return false;
        }
        game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
        if (level == 2) {
            player.setCastSourceIdWithAlternateMana(copiedCard.getId(), new ManaCostsImpl<>("{1}"), null);
        }
        player.cast(spellAbility, game, false, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
        return true;
    }
    ExileZone exile = game.getExile().getExileZone(exileId);
    if (exile == null || exile.isEmpty()) {
        return true;
    }
    Set<Card> cards = new HashSet<>();
    for (Card exiledCard : exile.getCards(game)) {
        cards.add(game.copyCard(exiledCard, source, source.getControllerId()));
    }
    while (!cards.isEmpty()) {
        for (Card copiedCard : cards) {
            if (!player.chooseUse(Outcome.PlayForFree, "Cast " + copiedCard.getName() + " without paying its mana cost?", source, game)) {
                continue;
            }
            game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
            player.cast(player.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
        }
        if (!player.chooseUse(Outcome.Neutral, "Continue casting exiled cards?", source, game)) {
            break;
        }
        cards.removeIf(c -> game.getState().getZone(c.getId()) != Zone.EXILED);
    }
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ExileZone(mage.game.ExileZone) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 73 with ExileZone

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

the class WorldgorgerDragonLeavesEffect 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) {
        int zoneChangeCounter = (sourceObject instanceof PermanentToken) ? source.getSourceObjectZoneChangeCounter() : source.getSourceObjectZoneChangeCounter() - 1;
        ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), zoneChangeCounter));
        if (exile != null) {
            return controller.moveCards(exile.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) PermanentToken(mage.game.permanent.PermanentToken)

Example 74 with ExileZone

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

the class ReturnFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || exile == null) {
        return false;
    }
    if (zone == Zone.LIBRARY) {
        return controller.putCardsOnTopOfLibrary(exile, game, source, false);
    }
    return controller.moveCards(exile.getCards(game), zone, source, game, tapped, false, true, null);
}
Also used : Player(mage.players.Player) ExileZone(mage.game.ExileZone)

Example 75 with ExileZone

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

the class ReturnCreaturesFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ExileZone exile = game.getExile().getExileZone(exileId);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && exile != null) {
        controller.moveCards(exile.getCards(new FilterCreatureCard(), game), Zone.BATTLEFIELD, source, game, false, false, this.byOwner, null);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ExileZone(mage.game.ExileZone)

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