Search in sources :

Example 1 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class CracklingDoomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> toSacrifice = new ArrayList<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (controller.hasOpponent(playerId, game)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null) {
                    int greatestPower = Integer.MIN_VALUE;
                    int numberOfCreatures = 0;
                    Permanent permanentToSacrifice = null;
                    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                        if (permanent.getPower().getValue() > greatestPower) {
                            greatestPower = permanent.getPower().getValue();
                            numberOfCreatures = 1;
                            permanentToSacrifice = permanent;
                        } else if (permanent.getPower().getValue() == greatestPower) {
                            numberOfCreatures++;
                        }
                    }
                    if (numberOfCreatures == 1) {
                        if (permanentToSacrifice != null) {
                            toSacrifice.add(permanentToSacrifice);
                        }
                    } else if (greatestPower != Integer.MIN_VALUE) {
                        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
                        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
                        Target target = new TargetControlledCreaturePermanent(filter);
                        if (opponent.choose(outcome, target, playerId, game)) {
                            Permanent permanent = game.getPermanent(target.getFirstTarget());
                            if (permanent != null) {
                                toSacrifice.add(permanent);
                            }
                        }
                    }
                }
            }
        }
        for (Permanent permanent : toSacrifice) {
            permanent.sacrifice(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 2 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class MayaelsAriaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // put a +1/+1 counter on each creature you control if you control a creature with power 5 or greater.
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 4));
    if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
        for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
            creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
        }
    }
    // needed because otehrwise the +1/+1 counters wouldn't be taken into account
    game.getState().processAction(game);
    // Then you gain 10 life if you control a creature with power 10 or greater.
    filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 9));
    if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
        controller.gainLife(10, game, source);
    }
    // Then you win the game if you control a creature with power 20 or greater.
    filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 19));
    if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
        controller.won(game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 3 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class SlaughterTheStrongEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                boolean selectionDone = false;
                Set<UUID> selectedCreatures = new HashSet<>();
                while (player.canRespond() && selectionDone == false) {
                    int powerSum = 0;
                    for (UUID creatureId : selectedCreatures) {
                        Permanent creature = game.getPermanent(creatureId);
                        if (creature != null) {
                            powerSum += creature.getPower().getValue();
                        }
                    }
                    FilterControlledCreaturePermanent currentFilter = new FilterControlledCreaturePermanent("any number of creatures you control with total power 4 or less (already selected total power " + powerSum + ")");
                    Set<PermanentIdPredicate> alreadySelectedCreatures = new HashSet<>();
                    if (!selectedCreatures.isEmpty()) {
                        for (UUID creatureId : selectedCreatures) {
                            alreadySelectedCreatures.add(new PermanentIdPredicate(creatureId));
                        }
                        currentFilter.add(Predicates.or(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum), Predicates.or(alreadySelectedCreatures)));
                    } else {
                        currentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum));
                    }
                    // human can de-select targets, but AI must choose only one time
                    Target target;
                    if (player.isComputer()) {
                        // AI settings
                        FilterControlledCreaturePermanent strictFilter = currentFilter.copy();
                        selectedCreatures.stream().forEach(id -> {
                            strictFilter.add(Predicates.not(new PermanentIdPredicate(id)));
                        });
                        target = new TargetPermanent(0, 1, strictFilter, true);
                    } else {
                        // Human settings
                        target = new TargetPermanent(0, 1, currentFilter, true);
                    }
                    player.chooseTarget(Outcome.BoostCreature, target, source, game);
                    if (target.getFirstTarget() != null) {
                        if (selectedCreatures.contains(target.getFirstTarget())) {
                            selectedCreatures.remove(target.getFirstTarget());
                        } else {
                            selectedCreatures.add(target.getFirstTarget());
                        }
                    } else {
                        if (player.isComputer()) {
                            // AI stops
                            selectionDone = true;
                        } else {
                            // Human can continue
                            String selected = "Selected: ";
                            for (UUID creatureId : selectedCreatures) {
                                Permanent creature = game.getPermanent(creatureId);
                                if (creature != null) {
                                    selected += creature.getLogName() + " ";
                                }
                            }
                            selectionDone = player.chooseUse(Outcome.Detriment, "Creature selection", selected, "End the selection", "Continue the selection", source, game);
                        }
                    }
                }
                for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                    if (!selectedCreatures.contains(creature.getId())) {
                        creature.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Target(mage.target.Target) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 4 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class ValiantEndeavorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Integer> results = controller.rollDice(outcome, source, game, 6, 2, 0);
    int firstResult = results.get(0);
    int secondResult = results.get(1);
    int first, second;
    if (firstResult != secondResult && controller.chooseUse(outcome, "Destroy each creature with power greater than or equal to your choice", "The other number will be the amount of 2/2 white Knight tokens with vigilance.", "" + firstResult, "" + secondResult, source, game)) {
        first = firstResult;
        second = secondResult;
    } else {
        first = secondResult;
        second = firstResult;
    }
    final FilterCreaturePermanent filter = new FilterCreaturePermanent(String.format("creatures with power greater than or equal to %s", first));
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, first - 1));
    Effect wrathEffect = new DestroyAllEffect(filter);
    wrathEffect.apply(game, source);
    new KnightToken().putOntoBattlefield(second, game, source, source.getControllerId());
    return true;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect) KnightToken(mage.game.permanent.token.KnightToken) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 5 with PowerPredicate

use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.

the class CelestialJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
    Map<Integer, List<Permanent>> powerMap = permanents.stream().collect(Collectors.toMap(permanent -> permanent.getPower().getValue(), permanent -> Arrays.asList(permanent), (a1, a2) -> {
        a1.addAll(a2);
        return a1;
    }));
    Set<UUID> toKeep = new HashSet<>();
    for (Map.Entry<Integer, List<Permanent>> entry : powerMap.entrySet()) {
        if (entry.getValue().size() == 1) {
            toKeep.add(entry.getValue().get(0).getId());
            continue;
        }
        FilterPermanent filter = new FilterCreaturePermanent("creature with power " + entry.getKey() + " to save");
        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, entry.getKey()));
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        toKeep.add(target.getFirstTarget());
    }
    for (Permanent permanent : permanents) {
        if (!toKeep.contains(permanent.getId())) {
            permanent.destroy(source, game);
        }
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) java.util(java.util) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) ComparisonType(mage.constants.ComparisonType) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Aggregations

PowerPredicate (mage.filter.predicate.mageobject.PowerPredicate)20 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)16 Permanent (mage.game.permanent.Permanent)16 Player (mage.players.Player)15 TargetPermanent (mage.target.TargetPermanent)8 Target (mage.target.Target)6 FilterPermanent (mage.filter.FilterPermanent)5 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 UUID (java.util.UUID)4 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)4 OneShotEffect (mage.abilities.effects.OneShotEffect)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 Effect (mage.abilities.effects.Effect)2 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)2 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1