Search in sources :

Example 1 with ConditionalOneShotEffect

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;
}
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 ConditionalOneShotEffect

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;
}
Also used : InvertCondition(mage.abilities.condition.InvertCondition) TriggeredAbility(mage.abilities.TriggeredAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect)

Example 3 with ConditionalOneShotEffect

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;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect)

Example 4 with ConditionalOneShotEffect

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

ConditionalOneShotEffect (mage.abilities.decorator.ConditionalOneShotEffect)4 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)3 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 ReturnFromExileEffect (mage.abilities.effects.common.ReturnFromExileEffect)2 Player (mage.players.Player)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 TriggeredAbility (mage.abilities.TriggeredAbility)1 Condition (mage.abilities.condition.Condition)1 InvertCondition (mage.abilities.condition.InvertCondition)1 ConditionalInterveningIfTriggeredAbility (mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility)1 AsThoughEffect (mage.abilities.effects.AsThoughEffect)1 ReturnToHandTargetEffect (mage.abilities.effects.common.ReturnToHandTargetEffect)1 Card (mage.cards.Card)1 FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)1 TargetCard (mage.target.TargetCard)1 TargetPlayer (mage.target.TargetPlayer)1 SpellsCastWatcher (mage.watchers.common.SpellsCastWatcher)1