use of mage.abilities.effects.common.ExileTargetEffect 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.effects.common.ExileTargetEffect 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.effects.common.ExileTargetEffect 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.effects.common.ExileTargetEffect 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;
}
use of mage.abilities.effects.common.ExileTargetEffect in project mage by magefree.
the class NacatlWarPrideEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent origNactalWarPride = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (origNactalWarPride == null) {
return false;
}
CreatureAttackedWhichPlayerWatcher PlayerAttackedWatcher = game.getState().getWatcher(CreatureAttackedWhichPlayerWatcher.class);
// Count the number of creatures attacked opponent controls
UUID defenderId = PlayerAttackedWatcher.getPlayerAttackedThisTurnByCreature(source.getSourceId());
int count = 0;
if (defenderId != null) {
count = game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), defenderId, game);
}
if (count == 0) {
return false;
}
List<Permanent> copies = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(controller.getId(), null, false, count, true, true);
effect.setTargetPointer(new FixedTarget(origNactalWarPride, game));
effect.apply(game, source);
copies.addAll(effect.getAddedPermanents());
if (!copies.isEmpty()) {
FixedTargets fixedTargets = new FixedTargets(copies, game);
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(fixedTargets).setText("exile the tokens");
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
return true;
}
return false;
}
Aggregations