Search in sources :

Example 6 with AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility

use of mage.abilities.common.delayed.AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility in project mage by magefree.

the class KayaGhostAssassinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        if (getTargetPointer().getFirst(game, source) != null) {
            Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
            if (targetCreature != null) {
                int zcc = targetCreature.getZoneChangeCounter(game);
                if (controller.moveCards(targetCreature, Zone.EXILED, source, game)) {
                    Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
                    effect.setTargetPointer(new FixedTarget(targetCreature.getId(), zcc + 1));
                    AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(effect);
                    game.addDelayedTriggeredAbility(delayedAbility, source);
                }
            }
        } else {
            int zcc = sourcePermanent.getZoneChangeCounter(game);
            if (controller.moveCards(sourcePermanent, Zone.EXILED, source, game)) {
                Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
                effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), zcc + 1));
                AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(effect);
                game.addDelayedTriggeredAbility(delayedAbility, source);
            }
        }
        controller.loseLife(2, game, source, false);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) DiscardEachPlayerEffect(mage.abilities.effects.common.discard.DiscardEachPlayerEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect) Effect(mage.abilities.effects.Effect) LoseLifeOpponentsEffect(mage.abilities.effects.common.LoseLifeOpponentsEffect) AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility)

Aggregations

AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility)6 Effect (mage.abilities.effects.Effect)5 OneShotEffect (mage.abilities.effects.OneShotEffect)5 Player (mage.players.Player)4 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)3 Permanent (mage.game.permanent.Permanent)3 ArrayList (java.util.ArrayList)2 FixedTargets (mage.target.targetpointer.FixedTargets)2 UUID (java.util.UUID)1 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)1 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)1 DrawCardSourceControllerEffect (mage.abilities.effects.common.DrawCardSourceControllerEffect)1 ExileAllEffect (mage.abilities.effects.common.ExileAllEffect)1 ExileSpellEffect (mage.abilities.effects.common.ExileSpellEffect)1 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)1 GainLifeEffect (mage.abilities.effects.common.GainLifeEffect)1 LoseLifeOpponentsEffect (mage.abilities.effects.common.LoseLifeOpponentsEffect)1 ReturnSourceFromGraveyardToBattlefieldEffect (mage.abilities.effects.common.ReturnSourceFromGraveyardToBattlefieldEffect)1 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)1 SacrificeTargetEffect (mage.abilities.effects.common.SacrificeTargetEffect)1