use of mage.abilities.effects.common.CounterTargetWithReplacementEffect in project mage by magefree.
the class DelayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
if (controller != null && spell != null) {
Effect effect = new CounterTargetWithReplacementEffect(Zone.EXILED);
effect.setTargetPointer(targetPointer);
Card card = game.getCard(spell.getSourceId());
if (card != null && effect.apply(game, source) && game.getState().getZone(card.getId()) == Zone.EXILED) {
boolean hasSuspend = card.getAbilities(game).containsClass(SuspendAbility.class);
UUID exileId = SuspendAbility.getSuspendExileId(controller.getId(), game);
if (controller.moveCardToExileWithInfo(card, exileId, "Suspended cards of " + controller.getLogName(), source, game, Zone.HAND, true)) {
card.addCounters(CounterType.TIME.createInstance(3), source.getControllerId(), source, game);
if (!hasSuspend) {
game.addEffect(new GainSuspendEffect(new MageObjectReference(card, game)), source);
}
game.informPlayers(controller.getLogName() + " suspends 3 - " + card.getName());
}
}
return true;
}
return false;
}
Aggregations