Search in sources :

Example 11 with ReturnToHandTargetEffect

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

the class NahiriTheHarbingerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
                if (card != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    Permanent permanent = game.getPermanent(card.getId());
                    if (permanent != null) {
                        ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
                        effect.setTargetPointer(new FixedTarget(permanent.getId(), permanent.getZoneChangeCounter(game)));
                        game.addEffect(effect, source);
                        Effect effect2 = new ReturnToHandTargetEffect();
                        effect2.setTargetPointer(new FixedTarget(permanent.getId(), permanent.getZoneChangeCounter(game)));
                        DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect2);
                        game.addDelayedTriggeredAbility(delayedAbility, source);
                    }
                }
            }
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SearchEffect(mage.abilities.effects.SearchEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 12 with ReturnToHandTargetEffect

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

the class SurpriseDeploymentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
            TargetCardInHand target = new TargetCardInHand(filter);
            if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                        Permanent permanent = game.getPermanent(card.getId());
                        if (permanent != null) {
                            ReturnToHandTargetEffect effect = new ReturnToHandTargetEffect();
                            effect.setTargetPointer(new FixedTarget(permanent, game));
                            DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
                            game.addDelayedTriggeredAbility(delayedAbility, source);
                            return true;
                        }
                    }
                }
                return false;
            }
        }
        return true;
    }
    return false;
}
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) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 13 with ReturnToHandTargetEffect

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

the class TheLocustGodEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Create delayed triggered ability
    Effect effect = new ReturnToHandTargetEffect();
    effect.setText("return {this} to its owner's hand");
    effect.setTargetPointer(new FixedTarget(source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
    game.addDelayedTriggeredAbility(delayedAbility, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) DrawDiscardControllerEffect(mage.abilities.effects.common.DrawDiscardControllerEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect)

Example 14 with ReturnToHandTargetEffect

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

the class AtBeginningOfUntapDelayedTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        Effect effect = new ReturnToHandTargetEffect();
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addDelayedTriggeredAbility(new AtBeginningOfUntapDelayedTriggeredAbility(effect), source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect)

Example 15 with ReturnToHandTargetEffect

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

the class HolisticWisdomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getFirstTarget());
    if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
        for (Cost cost : source.getCosts()) {
            if (cost instanceof ExileFromHandCost) {
                List<CardType> cardtypes = new ArrayList<>();
                ExileFromHandCost exileCost = (ExileFromHandCost) cost;
                for (CardType cardtype : exileCost.getCards().get(0).getCardType(game)) {
                    cardtypes.add(cardtype);
                }
                for (CardType cardtype : card.getCardType(game)) {
                    if (cardtypes.contains(cardtype)) {
                        Effect effect = new ReturnToHandTargetEffect();
                        effect.setTargetPointer(new FixedTarget(card.getId(), game));
                        return effect.apply(game, source);
                    }
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) CardType(mage.constants.CardType) ArrayList(java.util.ArrayList) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) Cost(mage.abilities.costs.Cost) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

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