Search in sources :

Example 1 with ReturnFromExileEffect

use of mage.abilities.effects.common.ReturnFromExileEffect in project mage by magefree.

the class PsychicTheftWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (opponent == null) {
        return false;
    }
    opponent.revealCards(CardUtil.getSourceName(game, source), opponent.getHand(), game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cardsHand = opponent.getHand().count(filter, game);
    Card chosenCard = null;
    if (cardsHand > 0) {
        TargetCard target = new TargetCard(Zone.HAND, filter);
        if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
            chosenCard = opponent.getHand().get(target.getFirstTarget(), game);
        }
    }
    if (chosenCard == null) {
        return false;
    }
    controller.moveCardToExileWithInfo(chosenCard, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source), source, game, Zone.HAND, true);
    CardUtil.makeCardPlayable(game, source, chosenCard, Duration.Custom, false);
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ConditionalOneShotEffect(new ReturnFromExileEffect(Zone.HAND), new PsychicTheftCondition(chosenCard, game), "if you haven't cast it, return it to its owner's hand.")), source);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) TargetCard(mage.target.TargetCard) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 2 with ReturnFromExileEffect

use of mage.abilities.effects.common.ReturnFromExileEffect in project mage by magefree.

the class CustomTestCard method addCustomEffect_ReturnFromAnyToHand.

/**
 * Return target card to hand that can be called by text "return from ..."
 *
 * @param controller
 */
protected void addCustomEffect_ReturnFromAnyToHand(TestPlayer controller) {
    // graveyard
    Ability ability = new SimpleActivatedAbility(new ReturnFromGraveyardToHandTargetEffect().setText("return from graveyard"), new ManaCostsImpl(""));
    ability.addTarget(new TargetCardInGraveyard(StaticFilters.FILTER_CARD));
    addCustomCardWithAbility("return from graveyard for " + controller.getName(), controller, ability);
    // exile
    ability = new SimpleActivatedAbility(new ReturnFromExileEffect(Zone.HAND).setText("return from exile"), new ManaCostsImpl(""));
    ability.addTarget(new TargetCardInExile(StaticFilters.FILTER_CARD));
    addCustomCardWithAbility("return from exile for " + controller.getName(), controller, ability);
    // library
    ability = new SimpleActivatedAbility(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD)).setText("return from library"), new ManaCostsImpl(""));
    addCustomCardWithAbility("return from library for " + controller.getName(), controller, ability);
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SpellAbility(mage.abilities.SpellAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetCardInExile(mage.target.common.TargetCardInExile) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) ReturnFromGraveyardToHandTargetEffect(mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 3 with ReturnFromExileEffect

use of mage.abilities.effects.common.ReturnFromExileEffect in project mage by magefree.

the class IgnorantBlissEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards hand = new CardsImpl(controller.getHand());
    controller.moveCardsToExile(hand.getCards(game), source, game, false, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
    hand.getCards(game).stream().filter(Objects::nonNull).filter(card -> game.getState().getZone(card.getId()) == Zone.EXILED).forEach(card -> card.setFaceDown(true, game));
    DelayedTriggeredAbility ability = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnFromExileEffect(Zone.HAND));
    ability.addEffect(new DrawCardSourceControllerEffect(1));
    game.addDelayedTriggeredAbility(ability, source);
    return true;
}
Also used : ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Ability(mage.abilities.Ability) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) Objects(java.util.Objects) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 4 with ReturnFromExileEffect

use of mage.abilities.effects.common.ReturnFromExileEffect in project mage by magefree.

the class PlaneswalkersMischiefCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (opponent != null && opponent.getHand().size() > 0) {
        Card revealedCard = opponent.getHand().getRandom(game);
        if (revealedCard == null) {
            return false;
        }
        Cards cards = new CardsImpl(revealedCard);
        opponent.revealCards(source, cards, game);
        if (revealedCard.isInstant(game) || revealedCard.isSorcery(game)) {
            opponent.moveCardToExileWithInfo(revealedCard, source.getSourceId(), "Planeswalker's Mischief", source, game, Zone.HAND, true);
            AsThoughEffect effect = new PlaneswalkersMischiefCastFromExileEffect();
            effect.setTargetPointer(new FixedTarget(revealedCard.getId()));
            game.addEffect(effect, source);
            OneShotEffect effect2 = new ReturnFromExileEffect(Zone.HAND);
            Condition condition = new PlaneswalkersMischiefCondition(source.getSourceId(), revealedCard.getId());
            ConditionalOneShotEffect effect3 = new ConditionalOneShotEffect(effect2, condition, "if you haven't cast it, return it to its owner's hand.");
            DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect3);
            delayedAbility.addWatcher(new SpellsCastWatcher());
            game.addDelayedTriggeredAbility(delayedAbility, source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Condition(mage.abilities.condition.Condition) Player(mage.players.Player) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) AsThoughEffect(mage.abilities.effects.AsThoughEffect) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect)

Aggregations

ReturnFromExileEffect (mage.abilities.effects.common.ReturnFromExileEffect)4 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)3 Player (mage.players.Player)3 Ability (mage.abilities.Ability)2 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)2 ConditionalOneShotEffect (mage.abilities.decorator.ConditionalOneShotEffect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 Objects (java.util.Objects)1 UUID (java.util.UUID)1 SpellAbility (mage.abilities.SpellAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 Condition (mage.abilities.condition.Condition)1 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)1 AsThoughEffect (mage.abilities.effects.AsThoughEffect)1 DrawCardSourceControllerEffect (mage.abilities.effects.common.DrawCardSourceControllerEffect)1 ReturnFromGraveyardToHandTargetEffect (mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect)1 SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)1 Card (mage.cards.Card)1 CardImpl (mage.cards.CardImpl)1