use of mage.abilities.effects.common.ReturnToHandTargetEffect in project mage by magefree.
the class ZndrspltsJudgmentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
choice.chooseFriendOrFoe(controller, source, game);
for (Player player : choice.getFriends()) {
if (player == null) {
continue;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
filter.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
if (!player.choose(Outcome.Copy, target, source.getSourceId(), game)) {
continue;
}
Effect effect = new CreateTokenCopyTargetEffect(player.getId());
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
effect.apply(game, source);
}
for (Player player : choice.getFoes()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
filter.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
if (!player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
continue;
}
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
effect.apply(game, source);
}
return true;
}
use of mage.abilities.effects.common.ReturnToHandTargetEffect in project mage by magefree.
the class DashAddDelayedTriggeredAbilityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
if (game.getPermanentEntering(source.getSourceId()) != null) {
OneShotEffect returnToHandEffect = new ReturnToHandTargetEffect();
ConditionalOneShotEffect mustBeOnBattlefieldToReturn = new ConditionalOneShotEffect(returnToHandEffect, DashAddDelayedTriggeredAbilityEffect::check);
mustBeOnBattlefieldToReturn.setText("return the dashed creature from the battlefield to its owner's hand");
// init target pointer now because the dashed creature will only be returned from battlefield zone (now in entering state so zone change counter is not raised yet)
mustBeOnBattlefieldToReturn.setTargetPointer(new FixedTarget(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()) + 1));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(mustBeOnBattlefieldToReturn);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
return false;
}
use of mage.abilities.effects.common.ReturnToHandTargetEffect in project mage by magefree.
the class DreamEaterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new ReturnToHandTargetEffect(), true, "you may return target nonland permanent an opponent controls to its owner's hand");
ability.addTarget(new TargetPermanent(filter));
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.abilities.effects.common.ReturnToHandTargetEffect in project mage by magefree.
the class FeatherTheRedeemedEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Spell sourceSpell = game.getStack().getSpell(event.getTargetId());
if (sourceSpell == null || sourceSpell.isCopy()) {
return false;
}
Player player = game.getPlayer(sourceSpell.getOwnerId());
if (player == null) {
return false;
}
Effect effect = new ReturnToHandTargetEffect().setText("return " + sourceSpell.getName() + " to its owner's hand");
player.moveCards(sourceSpell, Zone.EXILED, source, game);
effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
return true;
}
use of mage.abilities.effects.common.ReturnToHandTargetEffect in project mage by magefree.
the class ZaraRenegadeRecruiterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (controller == null || player == null || player.getHand().isEmpty()) {
return false;
}
TargetCardInHand targetCard = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_CREATURE);
controller.choose(outcome, player.getHand(), targetCard, game);
Card card = game.getCard(targetCard.getFirstTarget());
if (card == null) {
return false;
}
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return false;
}
UUID defenderId;
if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), player.getId(), game) < 1) {
defenderId = player.getId();
} else {
FilterPlayerOrPlaneswalker filter = new FilterPlayerOrPlaneswalker(player.getName() + " or a planeswalker controlled by " + player.getName());
filter.getPlayerFilter().add(new PlayerIdPredicate(player.getId()));
filter.getPermanentFilter().add(new ControllerIdPredicate(player.getId()));
TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
target.setNotTarget(true);
controller.choose(outcome, target, source.getSourceId(), game);
defenderId = target.getFirstTarget();
}
game.getCombat().addAttackerToCombat(permanent.getId(), defenderId, game);
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnToHandTargetEffect().setTargetPointer(new FixedTarget(permanent, game))), source);
return true;
}
Aggregations