Search in sources :

Example 11 with FilterPermanent

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

the class ZombieApocalypseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        controller.moveCards(controller.getGraveyard().getCards(filterZombie, game), Zone.BATTLEFIELD, source, game, true, false, false, null);
        game.getState().processAction(game);
        for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(SubType.HUMAN, "Humans"), source.getControllerId(), game)) {
            permanent.destroy(source, game, false);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent)

Example 12 with FilterPermanent

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

the class MostCommonColorCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent[] colorFilters = new FilterPermanent[6];
    int i = 0;
    for (ObjectColor color : ObjectColor.getAllColors()) {
        colorFilters[i] = new FilterPermanent();
        colorFilters[i].add(new ColorPredicate(color));
        if (predicate != null) {
            colorFilters[i].add(predicate);
        }
        i++;
    }
    int[] colorCounts = new int[6];
    i = 0;
    for (ObjectColor color : ObjectColor.getAllColors()) {
        colorFilters[i].add(new ColorPredicate(color));
        colorCounts[i] = game.getBattlefield().count(colorFilters[i], source.getId(), source.getControllerId(), game);
        i++;
    }
    int max = 0;
    for (i = 0; i < 5; i++) {
        if (colorCounts[i] > max) {
            max = colorCounts[i] * 1;
        }
    }
    i = 0;
    ObjectColor commonest = new ObjectColor();
    for (ObjectColor color : ObjectColor.getAllColors()) {
        if (colorCounts[i] == max) {
            commonest.addColor(color);
        }
        i++;
    }
    if (compareColor.shares(commonest)) {
        if (isMono) {
            return !commonest.isMulticolored();
        } else {
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) FilterPermanent(mage.filter.FilterPermanent) ObjectColor(mage.ObjectColor)

Example 13 with FilterPermanent

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

the class PermanentsOnTheBattlefieldCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent localFilter;
    if (onlyControlled) {
        localFilter = filter.copy();
        localFilter.add(new ControllerIdPredicate(source.getControllerId()));
    } else {
        localFilter = filter;
    }
    return ComparisonType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, count);
}
Also used : FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Example 14 with FilterPermanent

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

the class AlpineMoonEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (cardName == null) {
        return false;
    }
    FilterPermanent filter2 = filter.copy();
    filter2.add(new NamePredicate(cardName));
    for (Permanent land : game.getBattlefield().getActivePermanents(filter2, source.getControllerId(), game)) {
        switch(layer) {
            case TypeChangingEffects_4:
                // 305.7 Note that this doesn't remove any abilities that were granted to the land by other effects
                // So the ability removing has to be done before Layer 6
                land.removeAllAbilities(source.getSourceId(), game);
                land.removeAllSubTypes(game, SubTypeSet.NonBasicLandType);
                break;
            case AbilityAddingRemovingEffects_6:
                land.addAbility(new AnyColorManaAbility(), source.getSourceId(), game);
                break;
        }
    }
    return true;
}
Also used : NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) AnyColorManaAbility(mage.abilities.mana.AnyColorManaAbility)

Example 15 with FilterPermanent

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

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