Search in sources :

Example 1 with PhaseOutAllEffect

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;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Permanent(mage.game.permanent.Permanent) PhaseOutAllEffect(mage.abilities.effects.common.PhaseOutAllEffect)

Example 2 with PhaseOutAllEffect

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);
    }
}
Also used : Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PhaseOutAllEffect(mage.abilities.effects.common.PhaseOutAllEffect) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 3 with PhaseOutAllEffect

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;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) PhaseOutAllEffect(mage.abilities.effects.common.PhaseOutAllEffect) ArrayList(java.util.ArrayList) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID)

Aggregations

PhaseOutAllEffect (mage.abilities.effects.common.PhaseOutAllEffect)3 FilterPermanent (mage.filter.FilterPermanent)2 Permanent (mage.game.permanent.Permanent)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)1 Choice (mage.choices.Choice)1 ChoiceImpl (mage.choices.ChoiceImpl)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetPermanent (mage.target.TargetPermanent)1