use of mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect in project mage by magefree.
the class GuardianAngelDelayedTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
String targetName = "";
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer == null) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent == null) {
return true;
}
targetName = targetPermanent.getIdName();
} else {
targetName = "player " + targetPlayer.getName();
}
ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, source.getManaCostsToPay().getX(), false);
effect.setTargetPointer(getTargetPointer());
game.addEffect(effect, source);
SpecialAction specialAction = new GuardianAngelAction();
specialAction.getEffects().get(0).setTargetPointer(getTargetPointer());
specialAction.getEffects().get(0).setText("Prevent the next 1 damage that would be dealt to any target this turn (" + targetName + ").");
new CreateSpecialActionEffect(specialAction).apply(game, source);
// Create a hidden delayed triggered ability to remove the special action at end of turn.
new CreateDelayedTriggeredAbilityEffect(new GuardianAngelDelayedTriggeredAbility(specialAction.getId()), false).apply(game, source);
return true;
}
return false;
}
use of mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect in project mage by magefree.
the class TimeToFeedDiesTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (creature != null) {
DelayedTriggeredAbility ability = new TimeToFeedDiesTriggeredAbility(creature.getId(), creature.getZoneChangeCounter(game));
new CreateDelayedTriggeredAbilityEffect(ability, false).apply(game, source);
}
return true;
}
use of mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect in project mage by magefree.
the class LatNamsLegacyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && !controller.getHand().isEmpty()) {
TargetCard target = new TargetCard(Zone.HAND, new FilterCard("card to shuffle into your library"));
controller.choose(Outcome.Detriment, controller.getHand(), target, game);
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
boolean successful = controller.moveCards(card, Zone.LIBRARY, source, game);
controller.shuffleLibrary(source, game);
if (successful) {
new CreateDelayedTriggeredAbilityEffect(new AtTheBeginOfNextUpkeepDelayedTriggeredAbility(new DrawCardSourceControllerEffect(2)), false).apply(game, source);
}
}
return true;
}
return true;
}
use of mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect in project mage by magefree.
the class DeputyOfDetentionExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
Permanent targeted = game.getPermanent(source.getFirstTarget());
if (permanent == null || controller == null || targeted == null) {
return false;
}
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new ControllerIdPredicate(targeted.getControllerId()));
filter.add(new NamePredicate(targeted.getName()));
Set<Card> toExile = new LinkedHashSet<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
toExile.add(creature);
}
if (!toExile.isEmpty()) {
controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
}
return true;
}
use of mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect in project mage by magefree.
the class AlignedHedronNetworkExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
// the target creature won't be exiled.
if (controller != null && permanent != null) {
Set<Card> toExile = new LinkedHashSet<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), source.getSourceId(), game)) {
toExile.add(creature);
}
if (!toExile.isEmpty()) {
controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
}
return true;
}
return false;
}
Aggregations