use of mage.abilities.common.BeginningOfEndStepTriggeredAbility in project mage by magefree.
the class AethermagesTouchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 4));
if (!cards.isEmpty()) {
FilterCreatureCard filter = new FilterCreatureCard("a creature card to put onto the battlefield");
controller.revealCards(sourceObject.getIdName(), cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, filter);
if (cards.count(filter, game) > 0 && controller.choose(outcome, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cards.remove(card);
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
// It gains \"At the beginning of your end step, return this creature to its owner's hand.\"
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
Ability ability = new BeginningOfEndStepTriggeredAbility(Zone.BATTLEFIELD, new ReturnToHandSourceEffect(true), TargetController.YOU, null, false);
ContinuousEffect effect = new GainAbilityTargetEffect(ability, Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
}
}
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
}
return true;
}
return false;
}
use of mage.abilities.common.BeginningOfEndStepTriggeredAbility in project mage by magefree.
the class MinionReflectorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (permanent != null) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);
for (Permanent addedToken : effect.getAddedPermanents()) {
ContinuousEffect continuousEffect = new GainAbilityTargetEffect(new BeginningOfEndStepTriggeredAbility(new SacrificeSourceEffect(), TargetController.ANY, false), Duration.Custom);
continuousEffect.setTargetPointer(new FixedTarget(addedToken.getId()));
game.addEffect(continuousEffect, source);
}
return true;
}
return false;
}
Aggregations