use of mage.abilities.decorator.ConditionalOneShotEffect 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.decorator.ConditionalOneShotEffect in project mage by magefree.
the class SanctuaryInterveningIfTriggeredAbility method makeTrigger.
private static TriggeredAbility makeTrigger(OneShotEffect effect1, OneShotEffect effect2, ObjectColor color1, ObjectColor color2) {
TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(new ConditionalOneShotEffect(effect1, new InvertCondition(makeAndCondition(color1, color2))), TargetController.YOU, false);
ability.addEffect(new ConditionalOneShotEffect(effect2, makeAndCondition(color1, color2)));
return ability;
}
use of mage.abilities.decorator.ConditionalOneShotEffect in project mage by magefree.
the class DashAddDelayedTriggeredAbilityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
if (game.getPermanentEntering(source.getSourceId()) != null) {
OneShotEffect returnToHandEffect = new ReturnToHandTargetEffect();
ConditionalOneShotEffect mustBeOnBattlefieldToReturn = new ConditionalOneShotEffect(returnToHandEffect, DashAddDelayedTriggeredAbilityEffect::check);
mustBeOnBattlefieldToReturn.setText("return the dashed creature from the battlefield to its owner's hand");
// init target pointer now because the dashed creature will only be returned from battlefield zone (now in entering state so zone change counter is not raised yet)
mustBeOnBattlefieldToReturn.setTargetPointer(new FixedTarget(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()) + 1));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(mustBeOnBattlefieldToReturn);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
return false;
}
use of mage.abilities.decorator.ConditionalOneShotEffect 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