Search in sources :

Example 26 with FilterLandPermanent

use of mage.filter.common.FilterLandPermanent in project mage by magefree.

the class AnathemancerCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    if (sourceAbility != null) {
        UUID playerId = (UUID) game.getState().getValue(sourceAbility.getSourceId() + ChooseOpponentEffect.VALUE_KEY);
        Player chosenPlayer = game.getPlayer(playerId);
        if (chosenPlayer != null) {
            FilterLandPermanent filter = new FilterLandPermanent("tapped lands the chosen player controls");
            filter.add(TappedPredicate.TAPPED);
            filter.add(new ControllerIdPredicate(playerId));
            return game.getBattlefield().count(filter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
        }
    }
    return 0;
}
Also used : Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 27 with FilterLandPermanent

use of mage.filter.common.FilterLandPermanent in project mage by magefree.

the class WardOfBonesEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
        final Card card = game.getCard(event.getSourceId());
        final Player opponent = game.getPlayer(event.getPlayerId());
        if (card == null || opponent == null) {
            return false;
        }
        if (card.isCreature(game) && game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game) > game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
            return true;
        }
        if (card.isArtifact(game) && game.getBattlefield().countAll(new FilterArtifactPermanent(), opponent.getId(), game) > game.getBattlefield().countAll(new FilterArtifactPermanent(), source.getControllerId(), game)) {
            return true;
        }
        if (card.isEnchantment(game) && game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_ENCHANTMENT, opponent.getId(), game) > game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_ENCHANTMENT, source.getControllerId(), game)) {
            return true;
        }
        final int yourLands = game.getBattlefield().countAll(new FilterLandPermanent(), source.getControllerId(), game);
        if (card.isLand(game) && game.getBattlefield().countAll(new FilterLandPermanent(), opponent.getId(), game) > yourLands) {
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Card(mage.cards.Card)

Example 28 with FilterLandPermanent

use of mage.filter.common.FilterLandPermanent in project mage by magefree.

the class PreventRepeatedActionsTest method testEquipOnlyOnce.

/**
 * Check that an equipment is not switched again an again between creatures
 */
@Test
public void testEquipOnlyOnce() {
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
    // Equipped creature gets +1/+1.
    // Equip {1}({1}: Attach to target creature you control. Equip only as a sorcery.)
    addCard(Zone.BATTLEFIELD, playerA, "Fireshrieker", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 2);
    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();
    int tappedLands = 0;
    for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), playerA.getId(), currentGame)) {
        if (permanent.isTapped()) {
            tappedLands++;
        }
    }
    Assert.assertEquals("AI should only used Equipment once", 2, tappedLands);
}
Also used : FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) Test(org.junit.Test)

Example 29 with FilterLandPermanent

use of mage.filter.common.FilterLandPermanent in project mage by magefree.

the class HeraldOfLeshracLeavesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        if (playerId.equals(source.getControllerId())) {
            continue;
        }
        FilterPermanent filter = new FilterLandPermanent();
        filter.add(new OwnerIdPredicate(playerId));
        filter.add(new ControllerIdPredicate(source.getControllerId()));
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, playerId);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 30 with FilterLandPermanent

use of mage.filter.common.FilterLandPermanent in project mage by magefree.

the class SasayasEssenceManaEffect method produceMana.

/**
 * RULINGS 6/1/2005 If Sasaya’s Essence’s controller has four Forests and
 * taps one of them for Green, the Essence will add GreenGreenGreen to that
 * player’s mana pool for a total of GreenGreenGreenGreen.
 *
 * 6/1/2005 If Sasaya’s Essence’s controller has four Mossfire Valley and
 * taps one of them for RedGreen, the Essence will add three mana (one for
 * each other Mossfire Valley) of any combination of Red and/or Green to
 * that player’s mana pool.
 *
 * 6/1/2005 If Sasaya’s Essence’s controller has two Brushlands and taps one
 * of them for White, Sasaya’s Essence adds another White to that player’s
 * mana pool. It won’t produce Green or Colorless unless the land was tapped
 * for Green or Colorless instead.
 */
@Override
public Mana produceMana(Game game, Ability source) {
    Mana newMana = new Mana();
    if (game == null) {
        return newMana;
    }
    Player controller = game.getPlayer(source.getControllerId());
    Mana mana = (Mana) this.getValue("mana");
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && mana != null && permanent != null) {
        FilterPermanent filter = new FilterLandPermanent();
        filter.add(Predicates.not(new PermanentIdPredicate(permanent.getId())));
        filter.add(new NamePredicate(permanent.getName()));
        int count = game.getBattlefield().countAll(filter, controller.getId(), game);
        if (count > 0) {
            Choice choice = new ChoiceColor(true);
            choice.getChoices().clear();
            choice.setMessage("Pick the type of mana to produce");
            if (mana.getBlack() > 0) {
                choice.getChoices().add("Black");
            }
            if (mana.getRed() > 0) {
                choice.getChoices().add("Red");
            }
            if (mana.getBlue() > 0) {
                choice.getChoices().add("Blue");
            }
            if (mana.getGreen() > 0) {
                choice.getChoices().add("Green");
            }
            if (mana.getWhite() > 0) {
                choice.getChoices().add("White");
            }
            if (mana.getColorless() > 0) {
                choice.getChoices().add("Colorless");
            }
            if (!choice.getChoices().isEmpty()) {
                for (int i = 0; i < count; i++) {
                    choice.clearChoice();
                    if (choice.getChoices().size() == 1) {
                        choice.setChoice(choice.getChoices().iterator().next());
                    } else {
                        if (!controller.choose(outcome, choice, game)) {
                            return newMana;
                        }
                    }
                    switch(choice.getChoice()) {
                        case "Black":
                            newMana.increaseBlack();
                            break;
                        case "Blue":
                            newMana.increaseBlue();
                            break;
                        case "Red":
                            newMana.increaseRed();
                            break;
                        case "Green":
                            newMana.increaseGreen();
                            break;
                        case "White":
                            newMana.increaseWhite();
                            break;
                        case "Colorless":
                            newMana.increaseColorless();
                            break;
                    }
                }
            }
        }
    }
    return newMana;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Mana(mage.Mana) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ChoiceColor(mage.choices.ChoiceColor)

Aggregations

FilterLandPermanent (mage.filter.common.FilterLandPermanent)32 Player (mage.players.Player)22 Permanent (mage.game.permanent.Permanent)18 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)13 UUID (java.util.UUID)12 TargetLandPermanent (mage.target.common.TargetLandPermanent)10 Target (mage.target.Target)8 FilterPermanent (mage.filter.FilterPermanent)6 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)5 ArrayList (java.util.ArrayList)4 TargetPermanent (mage.target.TargetPermanent)4 TargetPlayer (mage.target.TargetPlayer)4 MageObject (mage.MageObject)3 CardsImpl (mage.cards.CardsImpl)3 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)3 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)3 HashSet (java.util.HashSet)2 MageObjectReference (mage.MageObjectReference)2 Mana (mage.Mana)2 Ability (mage.abilities.Ability)2