use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.
the class SentinelOfThePearlTridentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
int zcc = permanent.getZoneChangeCounter(game);
controller.moveCards(permanent, Zone.EXILED, source, game);
// create delayed triggered ability
Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
effect.setTargetPointer(new FixedTarget(permanent.getId(), zcc + 1));
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
return true;
}
return false;
}
use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.
the class SemestersEndReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(targetPointer.getTargets(game, source));
player.moveCards(cards, Zone.EXILED, source, game);
cards.retainZone(Zone.EXILED, game);
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new SemestersEndReturnEffect(cards, game)), source);
return true;
}
use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.
the class VoyagerStaffEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && creature != null && sourcePermanent != null) {
if (controller.moveCardToExileWithInfo(creature, source.getSourceId(), sourcePermanent.getIdName(), source, game, Zone.BATTLEFIELD, true)) {
// create delayed triggered ability
Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, true);
effect.setText("Return the exiled card to the battlefield under its owner's control at the beginning of the next end step");
effect.setTargetPointer(new FixedTarget(creature.getId(), game.getState().getZoneChangeCounter(creature.getId())));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
return true;
}
}
return false;
}
use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility 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.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.
the class EncoreSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
Set<MageObjectReference> addedTokens = new HashSet<>();
int opponentCount = OpponentsCount.instance.calculate(game, source, this);
if (opponentCount < 1) {
return false;
}
token.putOntoBattlefield(opponentCount, game, source, source.getControllerId());
Iterator<UUID> it = token.getLastAddedTokenIds().iterator();
while (it.hasNext()) {
for (UUID playerId : game.getOpponents(source.getControllerId())) {
if (game.getPlayer(playerId) == null) {
continue;
}
UUID tokenId = it.next();
MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game);
game.addEffect(new EncoreRequirementEffect(mageObjectReference, playerId), source);
game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom).setTargetPointer(new FixedTarget(mageObjectReference)), source);
addedTokens.add(mageObjectReference);
}
}
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new EncoreSacrificeEffect(addedTokens)), source);
return true;
}
Aggregations