use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class TatsumaTheDragonsFangTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
CreateTokenEffect effect = new CreateTokenEffect(new TatsumaDragonToken());
effect.apply(game, source);
for (UUID tokenId : effect.getLastAddedTokenIds()) {
// by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
FixedTarget fixedTarget = new FixedTarget(tokenPermanent, game);
Effect returnEffect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
returnEffect.setTargetPointer(new FixedTarget(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId())));
DelayedTriggeredAbility delayedAbility = new TatsumaTheDragonsFangTriggeredAbility(fixedTarget, returnEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
return true;
}
use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class TheScorpionGodEffect 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;
}
use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class WakeTheDeadReturnFromGraveyardToBattlefieldTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl(getTargetPointer().getTargets(game, source));
controller.moveCards(cards, Zone.BATTLEFIELD, source, game);
List<Permanent> toSacrifice = new ArrayList<>(cards.size());
for (UUID targetId : cards) {
Permanent creature = game.getPermanent(targetId);
if (creature != null) {
toSacrifice.add(creature);
}
}
Effect effect = new SacrificeTargetEffect("Sacrifice those creatures at the beginning of the next end step", source.getControllerId());
effect.setTargetPointer(new FixedTargets(toSacrifice, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
return false;
}
use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class CreateDelayedTriggeredAbilityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
DelayedTriggeredAbility delayedAbility = ability.copy();
if (this.copyTargets) {
if (source.getTargets().isEmpty()) {
delayedAbility.getEffects().setTargetPointer(targetPointer);
} else {
delayedAbility.getTargets().addAll(source.getTargets());
for (Effect effect : delayedAbility.getEffects()) {
effect.getTargetPointer().init(game, source);
}
}
}
if (initAbility) {
delayedAbility.init(game);
}
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class CogworkAssemblerCreateTokenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent copiedPermanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (copiedPermanent != null) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(null, CardType.ARTIFACT, true);
if (effect.apply(game, source)) {
for (Permanent copyPermanent : effect.getAddedPermanents()) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(copyPermanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
return true;
}
}
return false;
}
Aggregations