use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class OtherworldlyJourneyEntersBattlefieldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
if (permanent.moveToExile(source.getSourceId(), "Otherworldly Journey", source, game)) {
ExileZone exile = game.getExile().getExileZone(source.getSourceId());
// only if permanent is in exile (tokens would be stop to exist)
if (exile != null && !exile.isEmpty()) {
Card card = game.getCard(permanent.getId());
if (card != null) {
// create delayed triggered ability
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new OtherworldlyJourneyReturnFromExileEffect(new MageObjectReference(card, game)));
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
return true;
}
}
return false;
}
use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class SaheeliRaiTarget 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;
}
use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class WakeToSlaughterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Cards pickedCards = new CardsImpl(getTargetPointer().getTargets(game, source));
if (player != null && !pickedCards.isEmpty()) {
Card cardToHand;
if (pickedCards.size() == 1) {
cardToHand = pickedCards.getRandom(game);
} else {
Player opponent;
Set<UUID> opponents = game.getOpponents(player.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target targetOpponent = new TargetOpponent(true);
player.chooseTarget(Outcome.Detriment, targetOpponent, source, game);
opponent = game.getPlayer(targetOpponent.getFirstTarget());
}
TargetCard target = new TargetCard(1, Zone.GRAVEYARD, new FilterCard());
target.withChooseHint("Card to go to opponent's hand (other goes to battlefield)");
opponent.chooseTarget(outcome, pickedCards, target, source, game);
cardToHand = game.getCard(target.getFirstTarget());
}
for (Card card : pickedCards.getCards(game)) {
if (card == cardToHand) {
player.moveCards(cardToHand, Zone.HAND, source, game);
} else {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
FixedTarget fixedTarget = new FixedTarget(card, game);
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfGame);
effect.setTargetPointer(fixedTarget);
game.addEffect(effect, source);
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(fixedTarget);
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
pickedCards.clear();
return true;
}
return false;
}
use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class DawnOfTheDeadEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && card != null) {
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent creature = game.getPermanent(card.getId());
if (creature != null) {
// gains haste
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature, game));
game.addEffect(effect, source);
// Exile at begin of next end step
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(new FixedTarget(creature, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
return true;
}
return false;
}
use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.
the class GruesomeEncoreReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = game.getCard(getTargetPointer().getFirst(game, source));
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, game));
game.addEffect(effect, source);
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(permanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
return true;
}
return false;
}
Aggregations