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