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;
}
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);
}
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;
}
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;
}
Aggregations