use of mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility in project mage by magefree.
the class CreateTokenEffect method exileTokensCreatedAtEndOfCombat.
public void exileTokensCreatedAtEndOfCombat(Game game, Ability source) {
for (UUID tokenId : this.getLastAddedTokenIds()) {
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
ExileTargetEffect exileEffect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD);
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), source);
}
}
}
use of mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility in project mage by magefree.
the class MyriadEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourceObject != null) {
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
if (defendingPlayerId == null) {
Logger.getLogger(MyriadEffect.class).error("defending player == null source: " + sourceObject.getName() + " attacking: " + (sourceObject.isAttacking() ? "Y" : "N"));
return false;
}
List<Permanent> tokens = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (!playerId.equals(defendingPlayerId) && controller.hasOpponent(playerId, game)) {
Player opponent = game.getPlayer(playerId);
if (opponent != null && controller.chooseUse(Outcome.PutCreatureInPlay, "Put a copy of " + sourceObject.getIdName() + " onto battlefield attacking " + opponent.getName() + '?', source, game)) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(controller.getId(), null, false, 1, true, true, playerId);
effect.setTargetPointer(new FixedTarget(sourceObject, game));
effect.apply(game, source);
tokens.addAll(effect.getAddedPermanents());
}
}
}
if (!tokens.isEmpty()) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTargets(tokens, game));
game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), source);
}
return true;
}
return false;
}
use of mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility in project mage by magefree.
the class ClockworkDragonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent p = game.getPermanent(source.getSourceId());
if (p != null) {
AtTheEndOfCombatDelayedTriggeredAbility ability = new AtTheEndOfCombatDelayedTriggeredAbility(new RemoveCounterSourceEffect(CounterType.P1P1.createInstance()));
game.addDelayedTriggeredAbility(ability, source);
}
return false;
}
use of mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility in project mage by magefree.
the class ContemptEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent contempt = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (contempt != null) {
Permanent attachedToPermanent = game.getPermanent(contempt.getAttachedTo());
if (attachedToPermanent != null) {
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(attachedToPermanent.getId(), game)).setText("return " + attachedToPermanent.getName() + " to owner's hand.");
AtTheEndOfCombatDelayedTriggeredAbility ability = new AtTheEndOfCombatDelayedTriggeredAbility(effect);
game.addDelayedTriggeredAbility(ability, source);
}
Effect effect = new ReturnToHandSourceEffect();
AtTheEndOfCombatDelayedTriggeredAbility ability = new AtTheEndOfCombatDelayedTriggeredAbility(effect);
game.addDelayedTriggeredAbility(ability, source);
return true;
}
return false;
}
Aggregations