Search in sources :

Example 16 with ReturnToHandTargetEffect

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

the class ZndrspltsJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    choice.chooseFriendOrFoe(controller, source, game);
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
        filter.add(new ControllerIdPredicate(player.getId()));
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        if (!player.choose(Outcome.Copy, target, source.getSourceId(), game)) {
            continue;
        }
        Effect effect = new CreateTokenCopyTargetEffect(player.getId());
        effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
        effect.apply(game, source);
    }
    for (Player player : choice.getFoes()) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
        filter.add(new ControllerIdPredicate(player.getId()));
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        if (!player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
            continue;
        }
        Effect effect = new ReturnToHandTargetEffect();
        effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
        effect.apply(game, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect)

Example 17 with ReturnToHandTargetEffect

use of mage.abilities.effects.common.ReturnToHandTargetEffect 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 18 with ReturnToHandTargetEffect

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

the class DreamEaterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new ReturnToHandTargetEffect(), true, "you may return target nonland permanent an opponent controls to its owner's hand");
    ability.addTarget(new TargetPermanent(filter));
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) TargetPermanent(mage.target.TargetPermanent)

Example 19 with ReturnToHandTargetEffect

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

the class FeatherTheRedeemedEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Spell sourceSpell = game.getStack().getSpell(event.getTargetId());
    if (sourceSpell == null || sourceSpell.isCopy()) {
        return false;
    }
    Player player = game.getPlayer(sourceSpell.getOwnerId());
    if (player == null) {
        return false;
    }
    Effect effect = new ReturnToHandTargetEffect().setText("return " + sourceSpell.getName() + " to its owner's hand");
    player.moveCards(sourceSpell, Zone.EXILED, source, game);
    effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) Spell(mage.game.stack.Spell)

Example 20 with ReturnToHandTargetEffect

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

the class ZaraRenegadeRecruiterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller == null || player == null || player.getHand().isEmpty()) {
        return false;
    }
    TargetCardInHand targetCard = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_CREATURE);
    controller.choose(outcome, player.getHand(), targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return false;
    }
    controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return false;
    }
    UUID defenderId;
    if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), player.getId(), game) < 1) {
        defenderId = player.getId();
    } else {
        FilterPlayerOrPlaneswalker filter = new FilterPlayerOrPlaneswalker(player.getName() + " or a planeswalker controlled by " + player.getName());
        filter.getPlayerFilter().add(new PlayerIdPredicate(player.getId()));
        filter.getPermanentFilter().add(new ControllerIdPredicate(player.getId()));
        TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
        target.setNotTarget(true);
        controller.choose(outcome, target, source.getSourceId(), game);
        defenderId = target.getFirstTarget();
    }
    game.getCombat().addAttackerToCombat(permanent.getId(), defenderId, game);
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnToHandTargetEffect().setTargetPointer(new FixedTarget(permanent, game))), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) UUID(java.util.UUID) FilterPlayerOrPlaneswalker(mage.filter.common.FilterPlayerOrPlaneswalker) Card(mage.cards.Card) TargetPlayerOrPlaneswalker(mage.target.common.TargetPlayerOrPlaneswalker)

Aggregations

ReturnToHandTargetEffect (mage.abilities.effects.common.ReturnToHandTargetEffect)26 FixedTarget (mage.target.targetpointer.FixedTarget)21 Effect (mage.abilities.effects.Effect)19 OneShotEffect (mage.abilities.effects.OneShotEffect)18 Player (mage.players.Player)15 Permanent (mage.game.permanent.Permanent)14 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)13 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)9 Card (mage.cards.Card)9 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)6 FilterCard (mage.filter.FilterCard)5 TargetPermanent (mage.target.TargetPermanent)5 ContinuousEffect (mage.abilities.effects.ContinuousEffect)4 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)4 TargetCardInHand (mage.target.common.TargetCardInHand)4 UUID (java.util.UUID)3 Cost (mage.abilities.costs.Cost)3 ArrayList (java.util.ArrayList)2 MageObject (mage.MageObject)2 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)2