Search in sources :

Example 1 with Filter

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

the class MoveTargetAuraEffect method apply.

@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
    Permanent potentialAttachment = input.getObject();
    for (TargetAddress addr : TargetAddress.walk(aura)) {
        Target target = addr.getTarget(aura);
        Filter filter = target.getFilter();
        return filter.match(potentialAttachment, game);
    }
    return false;
}
Also used : Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Filter(mage.filter.Filter) TargetAddress(mage.util.TargetAddress)

Example 2 with Filter

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

the class CardTestPlayerAPIImpl method assertAbilityCount.

public void assertAbilityCount(Player player, String cardName, Class<? extends Ability> searchedAbility, int amount) {
    Permanent found = null;
    for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
        if (isObjectHaveTargetNameOrAlias(player, permanent, cardName)) {
            found = permanent;
            break;
        }
    }
    Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, found);
    Assert.assertEquals(amount, found.getAbilities(currentGame).stream().filter(a -> searchedAbility.isAssignableFrom(a.getClass())).collect(Collectors.toList()).size());
}
Also used : java.util(java.util) CardScanner(mage.cards.repository.CardScanner) mage.game(mage.game) ComputerPlayer7(mage.player.ai.ComputerPlayer7) PlayerAction(org.mage.test.player.PlayerAction) Player(mage.players.Player) CardTestAPI(org.mage.test.serverside.base.CardTestAPI) Matcher(java.util.regex.Matcher) MatchOptions(mage.game.match.MatchOptions) ManaPool(mage.players.ManaPool) MageObject(mage.MageObject) SystemUtil(mage.server.util.SystemUtil) ObjectColor(mage.ObjectColor) Card(mage.cards.Card) DeckCardLists(mage.cards.decks.DeckCardLists) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ComputerPlayerMCTS(mage.player.ai.ComputerPlayerMCTS) Before(org.junit.Before) FilterCard(mage.filter.FilterCard) TestPlayer(org.mage.test.player.TestPlayer) CardTestCodePayload(org.mage.test.serverside.base.CardTestCodePayload) DeckImporter(mage.cards.decks.importer.DeckImporter) GameSessionPlayer(mage.server.game.GameSessionPlayer) Deck(mage.cards.decks.Deck) Assert.assertTrue(org.junit.Assert.assertTrue) CardUtil(mage.util.CardUtil) CardRepository(mage.cards.repository.CardRepository) GameView(mage.view.GameView) Collectors(java.util.stream.Collectors) Filter(mage.filter.Filter) CommandObject(mage.game.command.CommandObject) FileNotFoundException(java.io.FileNotFoundException) CardInfo(mage.cards.repository.CardInfo) Permanent(mage.game.permanent.Permanent) PermanentCard(mage.game.permanent.PermanentCard) MageTestPlayerBase(org.mage.test.serverside.base.MageTestPlayerBase) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) Mana(mage.Mana) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent)

Example 3 with Filter

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

the class SteamVinesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent steamVines = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (steamVines != null) {
        Permanent enchantedLand = game.getPermanentOrLKIBattlefield(steamVines.getAttachedTo());
        Player controller = game.getPlayer(source.getControllerId());
        if (enchantedLand != null && controller != null) {
            Player landsController = game.getPlayer(enchantedLand.getControllerId());
            if (game.getState().getZone(enchantedLand.getId()) == Zone.BATTLEFIELD) {
                // if 2 or more Steam Vines were on a land
                enchantedLand.destroy(source, game, false);
                if (landsController != null) {
                    landsController.damage(1, source.getSourceId(), source, game);
                }
            }
            if (!game.getBattlefield().getAllActivePermanents(CardType.LAND, game).isEmpty()) {
                // lands are available on the battlefield
                Target target = new TargetLandPermanent();
                // not a target, it is chosen
                target.setNotTarget(true);
                Card steamVinesCard = game.getCard(source.getSourceId());
                if (steamVinesCard != null && landsController != null) {
                    if (landsController.choose(Outcome.DestroyPermanent, target, source.getId(), game)) {
                        if (target.getFirstTarget() != null) {
                            Permanent landChosen = game.getPermanent(target.getFirstTarget());
                            if (landChosen != null) {
                                for (Target targetTest : steamVinesCard.getSpellAbility().getTargets()) {
                                    Filter filterTest = targetTest.getFilter();
                                    if (filterTest.match(landChosen, game)) {
                                        if (game.getBattlefield().containsPermanent(landChosen.getId())) {
                                            // verify that it is still on the battlefield
                                            game.informPlayers(landsController.getLogName() + " attaches " + steamVines.getLogName() + " to " + landChosen.getLogName());
                                            Effect effect = new AttachEffect(Outcome.Neutral);
                                            effect.setTargetPointer(new FixedTarget(landChosen, game));
                                            return effect.apply(game, source);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Filter(mage.filter.Filter) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) AttachEffect(mage.abilities.effects.common.AttachEffect) TargetLandPermanent(mage.target.common.TargetLandPermanent) Card(mage.cards.Card) AttachEffect(mage.abilities.effects.common.AttachEffect)

Example 4 with Filter

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

the class YasharnImplacableEarthEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    boolean canTargetLand = true;
    Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
    if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY || event.getType() == GameEvent.EventType.CAST_SPELL) {
        if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
            if (permanent == null) {
                return false;
            }
        }
        Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
        for (Cost cost : ability.get().getCosts()) {
            if (cost instanceof PayLifeCost || cost instanceof PayVariableLifeCost) {
                // can't pay with life
                return true;
            }
            if (cost instanceof SacrificeSourceCost && !permanent.isLand()) {
                return true;
            }
            if (cost instanceof SacrificeTargetCost) {
                SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
                Filter filter = sacrificeCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAllCost) {
                SacrificeAllCost sacrificeAllCost = (SacrificeAllCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAttachedCost) {
                SacrificeAttachedCost sacrificeAllCost = (SacrificeAttachedCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAttachmentCost) {
                SacrificeAttachmentCost sacrificeAllCost = (SacrificeAttachmentCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeXTargetCost) {
                SacrificeXTargetCost sacrificeCost = (SacrificeXTargetCost) cost;
                Filter filter = sacrificeCost.getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) SacrificeAllCost(mage.abilities.costs.common.SacrificeAllCost) PayVariableLifeCost(mage.abilities.costs.common.PayVariableLifeCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) SacrificeXTargetCost(mage.abilities.costs.common.SacrificeXTargetCost) SacrificeAttachedCost(mage.abilities.costs.common.SacrificeAttachedCost) SacrificeAttachmentCost(mage.abilities.costs.common.SacrificeAttachmentCost) SacrificeAttachedCost(mage.abilities.costs.common.SacrificeAttachedCost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Filter(mage.filter.Filter) SacrificeAttachmentCost(mage.abilities.costs.common.SacrificeAttachmentCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) MageObject(mage.MageObject) SacrificeAllCost(mage.abilities.costs.common.SacrificeAllCost) PayVariableLifeCost(mage.abilities.costs.common.PayVariableLifeCost) SacrificeXTargetCost(mage.abilities.costs.common.SacrificeXTargetCost)

Example 5 with Filter

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

the class AuraPermanentCanAttachToPermanentId method apply.

@Override
public boolean apply(Permanent input, Game game) {
    final Permanent permanent = game.getPermanent(toBeCheckedPermanentId);
    Filter filter;
    if (input.getSpellAbility() != null && input.getSpellAbility().getTargets() != null) {
        for (Target target : input.getSpellAbility().getTargets()) {
            filter = target.getFilter();
            if (filter.match(permanent, game)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) Filter(mage.filter.Filter)

Aggregations

Filter (mage.filter.Filter)10 Permanent (mage.game.permanent.Permanent)8 Target (mage.target.Target)5 MageObject (mage.MageObject)3 Player (mage.players.Player)3 TargetPermanent (mage.target.TargetPermanent)3 java.util (java.util)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 Mana (mage.Mana)2 ObjectColor (mage.ObjectColor)2 Ability (mage.abilities.Ability)2 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)2 Effect (mage.abilities.effects.Effect)2 Card (mage.cards.Card)2 Deck (mage.cards.decks.Deck)2 mage.constants (mage.constants)2 CounterType (mage.counters.CounterType)2 FilterCard (mage.filter.FilterCard)2 FilterPermanent (mage.filter.FilterPermanent)2