Search in sources :

Example 56 with ExileZone

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

the class VoltaicVisionaryWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.ZONE_CHANGE || ((ZoneChangeEvent) event).getToZone() != Zone.EXILED) {
        return;
    }
    Card card = game.getCard(event.getTargetId());
    UUID exileId = game.getExile().getExileZones().stream().filter(exileZone -> exileZone.contains(card)).map(ExileZone::getId).findFirst().orElse(null);
    if (exileId == null) {
        return;
    }
    map.computeIfAbsent(exileId, x -> new HashSet<>()).add(new MageObjectReference(card, game));
}
Also used : java.util(java.util) Zone(mage.constants.Zone) MageObjectReference(mage.MageObjectReference) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) SubType(mage.constants.SubType) TransformSourceEffect(mage.abilities.effects.common.TransformSourceEffect) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ExileZone(mage.game.ExileZone) GameEvent(mage.game.events.GameEvent) ExileTopXMayPlayUntilEndOfTurnEffect(mage.abilities.effects.common.ExileTopXMayPlayUntilEndOfTurnEffect) TransformAbility(mage.abilities.keyword.TransformAbility) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) CardImpl(mage.cards.CardImpl) ActivateAsSorceryActivatedAbility(mage.abilities.common.ActivateAsSorceryActivatedAbility) CardType(mage.constants.CardType) WatcherScope(mage.constants.WatcherScope) Card(mage.cards.Card) DamageControllerEffect(mage.abilities.effects.common.DamageControllerEffect) Ability(mage.abilities.Ability) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) ExileZone(mage.game.ExileZone) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 57 with ExileZone

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

the class ReturnExiledPermanentsEffect 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 = getExileIfPossible(game, source);
        if (exile != null) {
            return controller.moveCards(new LinkedHashSet<>(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)

Example 58 with ExileZone

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

the class ReturnToBattlefieldUnderYourControlSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    ExileZone exileZone = game.getExile().getExileZone(exileZoneId);
    if (exileZone != null && exileZone.contains(source.getSourceId())) {
        Card card = game.getCard(source.getSourceId());
        if (card != null && controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Card(mage.cards.Card)

Example 59 with ExileZone

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

the class EpicExperimentEffect 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, source.getManaCostsToPay().getX()), source, game, true, source.getSourceId(), sourceObject.getIdName());
        // cast the possible cards without paying the mana
        ExileZone epicExperimentExileZone = game.getExile().getExileZone(source.getSourceId());
        FilterCard filter = new FilterInstantOrSorceryCard();
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        filter.setMessage("instant and sorcery cards with mana value " + source.getManaCostsToPay().getX() + " or less");
        Cards cardsToCast = new CardsImpl();
        if (epicExperimentExileZone == null) {
            return true;
        }
        cardsToCast.addAll(epicExperimentExileZone.getCards(filter, source.getSourceId(), source.getControllerId(), game));
        while (controller.canRespond() && !cardsToCast.isEmpty()) {
            if (!controller.chooseUse(Outcome.PlayForFree, "Cast (another) a card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("instant or sorcery card to cast for free"));
            if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                Card card = game.getCard(targetCard.getFirstTarget());
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    if (!cardWasCast) {
                        game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
                    }
                    cardsToCast.remove(card);
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        // move cards not cast to graveyard
        ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
        if (exileZone != null) {
            controller.moveCards(exileZone.getCards(game), Zone.GRAVEYARD, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Example 60 with ExileZone

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

the class IdolOfEnduranceWatcher method applies.

@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
    if (!IdolOfEnduranceWatcher.checkPermission(affectedControllerId, source, game)) {
        return false;
    }
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
    if (exileZone == null || !exileZone.contains(sourceId)) {
        return false;
    }
    Card card = game.getCard(sourceId);
    if (card == null || !card.isCreature(game) || card.isLand(game)) {
        return false;
    }
    return allowCardToPlayWithoutMana(sourceId, source, affectedControllerId, game);
}
Also used : ExileZone(mage.game.ExileZone) FilterCreatureCard(mage.filter.common.FilterCreatureCard) FilterCard(mage.filter.FilterCard)

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