Search in sources :

Example 1 with BeginningOfEndStepTriggeredAbility

use of mage.abilities.common.BeginningOfEndStepTriggeredAbility in project mage by magefree.

the class AethermagesTouchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 4));
        if (!cards.isEmpty()) {
            FilterCreatureCard filter = new FilterCreatureCard("a creature card to put onto the battlefield");
            controller.revealCards(sourceObject.getIdName(), cards, game);
            TargetCard target = new TargetCard(Zone.LIBRARY, filter);
            if (cards.count(filter, game) > 0 && controller.choose(outcome, cards, target, game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    cards.remove(card);
                    if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                        // It gains \"At the beginning of your end step, return this creature to its owner's hand.\"
                        Permanent permanent = game.getPermanent(card.getId());
                        if (permanent != null) {
                            Ability ability = new BeginningOfEndStepTriggeredAbility(Zone.BATTLEFIELD, new ReturnToHandSourceEffect(true), TargetController.YOU, null, false);
                            ContinuousEffect effect = new GainAbilityTargetEffect(ability, Duration.Custom);
                            effect.setTargetPointer(new FixedTarget(permanent, game));
                            game.addEffect(effect, source);
                        }
                    }
                }
            }
            controller.putCardsOnBottomOfLibrary(cards, game, source, true);
        }
        return true;
    }
    return false;
}
Also used : BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ReturnToHandSourceEffect(mage.abilities.effects.common.ReturnToHandSourceEffect) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) FilterCreatureCard(mage.filter.common.FilterCreatureCard) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 2 with BeginningOfEndStepTriggeredAbility

use of mage.abilities.common.BeginningOfEndStepTriggeredAbility in project mage by magefree.

the class MinionReflectorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (permanent != null) {
        CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        effect.apply(game, source);
        for (Permanent addedToken : effect.getAddedPermanents()) {
            ContinuousEffect continuousEffect = new GainAbilityTargetEffect(new BeginningOfEndStepTriggeredAbility(new SacrificeSourceEffect(), TargetController.ANY, false), Duration.Custom);
            continuousEffect.setTargetPointer(new FixedTarget(addedToken.getId()));
            game.addEffect(continuousEffect, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) SacrificeSourceEffect(mage.abilities.effects.common.SacrificeSourceEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility)

Aggregations

BeginningOfEndStepTriggeredAbility (mage.abilities.common.BeginningOfEndStepTriggeredAbility)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)2 Permanent (mage.game.permanent.Permanent)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 MageObject (mage.MageObject)1 Ability (mage.abilities.Ability)1 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)1 ReturnToHandSourceEffect (mage.abilities.effects.common.ReturnToHandSourceEffect)1 SacrificeSourceEffect (mage.abilities.effects.common.SacrificeSourceEffect)1 FilterCreatureCard (mage.filter.common.FilterCreatureCard)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 Player (mage.players.Player)1 TargetCard (mage.target.TargetCard)1