Search in sources :

Example 1 with ColorPredicate

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

the class HatcherySpiderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this);
    FilterCard filter = new FilterPermanentCard("green permanent card with mana value " + xValue + " or less");
    filter.add(new ColorPredicate(ObjectColor.GREEN));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard target = new TargetCardInLibrary(filter);
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
    if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) && player.choose(outcome, cards, target, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
            cards.remove(card);
        }
    }
    while (!cards.isEmpty()) {
        Card card = cards.getRandom(game);
        player.getLibrary().putOnBottom(card, game);
        cards.remove(card);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCard(mage.target.TargetCard) CardsInControllerGraveyardCount(mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

Example 2 with ColorPredicate

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

the class MausoleumSecretsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int critterCount = player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game);
    FilterCard filter = new FilterCard("a black card with mana value less than or equal to " + critterCount);
    filter.add(new ColorPredicate(ObjectColor.BLACK));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, critterCount + 1));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 3 with ColorPredicate

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

the class SehtsTigerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    ChoiceColor choice = new ChoiceColor();
    if (controller != null && mageObject != null && controller.choose(Outcome.Protect, choice, game)) {
        game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
        FilterCard filter = new FilterCard();
        filter.add(new ColorPredicate(choice.getColor()));
        filter.setMessage(choice.getChoice());
        Ability ability = new ProtectionAbility(filter);
        game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) MageObject(mage.MageObject) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ChoiceColor(mage.choices.ChoiceColor) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect)

Example 4 with ColorPredicate

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

the class CardCanBeCastPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.getLibrary().hasCards()) {
            /**
             * 10/1/2005 Any card you find must be legally cast-able (for
             * example, you have to be able to choose a legal target for
             * it). If you can't find a cast-able card (or choose not to),
             * nothing happens and you shuffle your library.
             */
            FilterCard filter = new FilterCard("red or white instant card with mana value 4 or less");
            TargetCardInLibrary target = new TargetCardInLibrary(filter);
            filter.add(Predicates.or(new ColorPredicate(ObjectColor.RED), new ColorPredicate(ObjectColor.WHITE)));
            filter.add(CardType.INSTANT.getPredicate());
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 5));
            filter.add(new CardCanBeCastPredicate(source.getControllerId()));
            if (controller.searchLibrary(target, source, game, controller.getId())) {
                UUID targetId = target.getFirstTarget();
                Card card = game.getCard(targetId);
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 5 with ColorPredicate

use of mage.filter.predicate.mageobject.ColorPredicate 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)

Aggregations

ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)54 Player (mage.players.Player)28 FilterCard (mage.filter.FilterCard)20 ObjectColor (mage.ObjectColor)18 FilterPermanent (mage.filter.FilterPermanent)16 Permanent (mage.game.permanent.Permanent)16 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)14 ChoiceColor (mage.choices.ChoiceColor)14 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 Ability (mage.abilities.Ability)6 UUID (java.util.UUID)5 MageObject (mage.MageObject)5 Card (mage.cards.Card)5 FilterObject (mage.filter.FilterObject)5 CardsImpl (mage.cards.CardsImpl)4 ArrayList (java.util.ArrayList)3 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)3 TargetPlayer (mage.target.TargetPlayer)3 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)3