Search in sources :

Example 1 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class ComputerPlayer method findBestPermanentTargets.

protected void findBestPermanentTargets(Outcome outcome, UUID abilityControllerId, UUID sourceId, FilterPermanent filter, Game game, Target target, List<Permanent> goodList, List<Permanent> badList, List<Permanent> allList) {
    // searching for most valuable/powerfull permanents
    goodList.clear();
    badList.clear();
    allList.clear();
    List<UUID> usedTargets = target.getTargets();
    // search all
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, abilityControllerId, sourceId, game)) {
        if (usedTargets.contains(permanent.getId())) {
            continue;
        }
        if (outcome.isGood()) {
            // good effect
            if (permanent.isControlledBy(abilityControllerId)) {
                goodList.add(permanent);
            } else {
                badList.add(permanent);
            }
        } else {
            // bad effect
            if (permanent.isControlledBy(abilityControllerId)) {
                badList.add(permanent);
            } else {
                goodList.add(permanent);
            }
        }
    }
    // sort from tiny to big (more valuable)
    PermanentComparator comparator = new PermanentComparator(game);
    goodList.sort(comparator);
    badList.sort(comparator);
    // most valueable goes first in good list
    Collections.reverse(goodList);
    // most weakest goes first in bad list (no need to reverse)
    // Collections.reverse(badList);
    allList.addAll(goodList);
    allList.addAll(badList);
    // "can target all mode" don't need your/opponent lists -- all targets goes with same value
    if (outcome.isCanTargetAll()) {
        // bad sort
        allList.sort(comparator);
        if (outcome.isGood()) {
            // good sort
            Collections.reverse(allList);
        }
        goodList.clear();
        goodList.addAll(allList);
        badList.clear();
        badList.addAll(allList);
    }
}
Also used : Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent)

Example 2 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class BeamsplitterMageApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) getValue("spellCast");
    if (player == null || spell == null) {
        return false;
    }
    FilterPermanent filter = new FilterControlledCreaturePermanent("a creature you control that can be targeted by " + spell.getName());
    filter.add(AnotherPredicate.instance);
    filter.add(new BeamsplitterMagePredicate(spell));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    spell.createCopyOnStack(game, source, player.getId(), false, 1, new BeamsplitterMageApplier(permanent, game));
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Spell(mage.game.stack.Spell)

Example 3 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class ChaosLordEffect method checkInterveningIfClause.

@Override
public boolean checkInterveningIfClause(Game game) {
    Condition condition = new ControlsPermanentsComparedToOpponentsCondition(ComparisonType.EQUAL_TO, new FilterPermanent());
    Player controller = game.getPlayer(controllerId);
    if (controller != null && condition.apply(game, this)) {
        return super.checkInterveningIfClause(game);
    }
    return false;
}
Also used : ControlsPermanentsComparedToOpponentsCondition(mage.abilities.condition.common.ControlsPermanentsComparedToOpponentsCondition) Condition(mage.abilities.condition.Condition) ControlsPermanentsComparedToOpponentsCondition(mage.abilities.condition.common.ControlsPermanentsComparedToOpponentsCondition) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent)

Example 4 with FilterPermanent

use of mage.filter.FilterPermanent 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 5 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class JuxtaposeEffect method getPermanentsWithTheHighestCMC.

private List<Permanent> getPermanentsWithTheHighestCMC(Game game, UUID playerId, FilterPermanent filter) {
    List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(filter, playerId, game);
    int highestCMC = -1;
    for (Permanent permanent : permanents) {
        if (highestCMC < permanent.getManaValue()) {
            highestCMC = permanent.getManaValue();
        }
    }
    List<Permanent> result = new ArrayList<>();
    for (Permanent permanent : permanents) {
        if (permanent.getManaValue() == highestCMC) {
            result.add(permanent);
        }
    }
    return result;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent)

Aggregations

FilterPermanent (mage.filter.FilterPermanent)155 Permanent (mage.game.permanent.Permanent)99 Player (mage.players.Player)99 TargetPermanent (mage.target.TargetPermanent)62 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)49 UUID (java.util.UUID)41 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)30 Target (mage.target.Target)24 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)18 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)17 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)13 FilterCard (mage.filter.FilterCard)11 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)11 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)11 CardsImpl (mage.cards.CardsImpl)10