Search in sources :

Example 1 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class DispersalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<PermanentIdPredicate> permsToReturn = new HashSet<>();
    for (UUID opponentId : game.getOpponents(player.getId())) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null) {
            continue;
        }
        int highestCMC = 0;
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
            if (permanent != null) {
                highestCMC = Math.max(highestCMC, permanent.getManaValue());
            }
        }
        FilterPermanent filter = new FilterNonlandPermanent("permanent you control with mana value " + highestCMC);
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, highestCMC));
        filter.add(new ControllerIdPredicate(opponentId));
        Target target = new TargetPermanent(1, 1, filter, true);
        if (opponent.choose(outcome, target, source.getSourceId(), game)) {
            if (target.getFirstTarget() == null) {
                continue;
            }
            permsToReturn.add(new PermanentIdPredicate(target.getFirstTarget()));
        }
    }
    FilterPermanent filter = new FilterPermanent();
    filter.add(Predicates.or(permsToReturn));
    new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
    new DiscardEachPlayerEffect(StaticValue.get(1), false, TargetController.OPPONENT).apply(game, source);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReturnToHandFromBattlefieldAllEffect(mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect) DiscardEachPlayerEffect(mage.abilities.effects.common.discard.DiscardEachPlayerEffect) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) HashSet(java.util.HashSet)

Example 2 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class MutinyFirstTarget method addTarget.

@Override
public void addTarget(UUID id, Ability source, Game game, boolean skipEvent) {
    super.addTarget(id, source, game, skipEvent);
    // Update the second target
    UUID firstController = game.getControllerId(id);
    if (firstController != null && source.getTargets().size() > 1) {
        Player controllingPlayer = game.getPlayer(firstController);
        TargetCreaturePermanent targetCreaturePermanent = (TargetCreaturePermanent) source.getTargets().get(1);
        // Set a new filter to the second target with the needed restrictions
        FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature that player " + controllingPlayer.getName() + " controls");
        filter.add(new ControllerIdPredicate(firstController));
        filter.add(Predicates.not(new PermanentIdPredicate(id)));
        targetCreaturePermanent.replaceFilter(filter);
    }
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 3 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate 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 PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class AlphaBrawlEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID targetId = source.getFirstTarget();
    FilterCreaturePermanent filter = new FilterCreaturePermanent("each other creature that player controls");
    filter.add(Predicates.not(new PermanentIdPredicate(targetId)));
    Permanent creature = game.getPermanent(targetId);
    if (creature != null) {
        Player player = game.getPlayer(creature.getControllerId());
        if (player != null) {
            int power = creature.getPower().getValue();
            for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) {
                perm.damage(power, creature.getId(), source, game, false, true);
            }
            for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) {
                creature.damage(perm.getPower().getValue(), perm.getId(), source, game, false, true);
            }
            return true;
        }
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) UUID(java.util.UUID)

Example 5 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class TreefolkUmbraEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null || permanent.getAttachedTo() == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new PermanentIdPredicate(permanent.getAttachedTo()));
    game.getCombat().setUseToughnessForDamage(true);
    game.getCombat().addUseToughnessForDamageFilter(filter);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Aggregations

PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)45 Permanent (mage.game.permanent.Permanent)38 Player (mage.players.Player)26 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)24 FilterPermanent (mage.filter.FilterPermanent)19 TargetPermanent (mage.target.TargetPermanent)19 Target (mage.target.Target)17 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)17 UUID (java.util.UUID)14 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)7 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)5 MageObject (mage.MageObject)4 Predicate (mage.filter.predicate.Predicate)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 BecomesFaceDownCreatureAllEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect)3 BoostAllEffect (mage.abilities.effects.common.continuous.BoostAllEffect)3 AbilityPredicate (mage.filter.predicate.mageobject.AbilityPredicate)3 ArrayList (java.util.ArrayList)2