use of mage.abilities.effects.common.PhaseOutAllEffect in project mage by magefree.
the class OutOfTimeReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> creatures = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
int numCreatures = creatures.size();
if (numCreatures > 0) {
Set<UUID> creatureIds = new HashSet<>(numCreatures);
for (Permanent creature : creatures) {
creature.untap(game);
creatureIds.add(creature.getId());
}
// https://magic.wizards.com/en/articles/archive/feature/modern-horizons-2-release-notes-2021-06-04
// If Out of Time leaves the battlefield before its enter the battlefield trigger resolves, creatures will untap, but they won't phase out.
Permanent outOfTime = game.getPermanent(source.getSourceId());
if (outOfTime != null) {
new PhaseOutAllEffect(new ArrayList<>(creatureIds)).apply(game, source);
new AddCountersSourceEffect(CounterType.TIME.createInstance(numCreatures)).apply(game, source);
game.getState().setValue("phasedOutCreatures" + source.getId().toString(), creatureIds);
game.getState().setValue("phasedOutBySourceId" + source.getSourceId(), source.getId());
game.addDelayedTriggeredAbility(new OutOfTimeDelayedTriggeredAbility(), source);
game.addEffect(new OutOfTimeReplacementEffect(), source);
}
}
return true;
}
use of mage.abilities.effects.common.PhaseOutAllEffect in project mage by magefree.
the class EquipoiseEffect method phaseOutCardType.
private void phaseOutCardType(Player controller, Player targetPlayer, CardType cardType, Ability source, Game game) {
FilterPermanent filter = new FilterControlledPermanent();
filter.add(cardType.getPredicate());
int numberController = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
int numberTargetPlayer = game.getBattlefield().count(filter, source.getSourceId(), targetPlayer.getId(), game);
int excess = numberTargetPlayer - numberController;
if (excess > 0) {
FilterPermanent filterChoose = new FilterPermanent(cardType.toString().toLowerCase(Locale.ENGLISH) + (excess > 1 ? "s" : "") + " of target player");
filterChoose.add(new ControllerIdPredicate(targetPlayer.getId()));
filterChoose.add(cardType.getPredicate());
Target target = new TargetPermanent(excess, excess, filterChoose, true);
controller.chooseTarget(outcome, target, source, game);
new PhaseOutAllEffect(target.getTargets()).apply(game, source);
}
}
use of mage.abilities.effects.common.PhaseOutAllEffect in project mage by magefree.
the class TeferisRealmEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (player != null && controller != null) {
Choice choiceImpl = new ChoiceImpl(true);
choiceImpl.setMessage("Phase out which kind of permanents?");
choiceImpl.setChoices(choices);
if (!player.choose(outcome, choiceImpl, game)) {
return false;
}
String choosenType = choiceImpl.getChoice();
FilterPermanent filter = new FilterPermanent();
filter.add(TokenPredicate.FALSE);
switch(choosenType) {
case ARTIFACT:
filter.add(CardType.ARTIFACT.getPredicate());
break;
case CREATURE:
filter.add(CardType.CREATURE.getPredicate());
break;
case LAND:
filter.add(CardType.LAND.getPredicate());
break;
case NON_AURA_ENCHANTMENT:
filter.add(CardType.ENCHANTMENT.getPredicate());
filter.add(Predicates.not(SubType.AURA.getPredicate()));
break;
default:
return false;
}
game.informPlayers(player.getLogName() + " chooses " + choosenType + "s to phase out");
List<UUID> permIds = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
permIds.add(permanent.getId());
}
return new PhaseOutAllEffect(permIds).apply(game, source);
}
return false;
}
Aggregations