Search in sources :

Example 1 with FilterLandPermanent

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

the class SunderingTitanDestroyLandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Set<UUID> lands = new HashSet<>();
    if (controller != null && sourcePermanent != null) {
        for (SubType landName : SubType.getBasicLands()) {
            FilterLandPermanent filter = new FilterLandPermanent(landName + " to destroy");
            filter.add(landName.getPredicate());
            Target target = new TargetLandPermanent(1, 1, filter, true);
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                controller.chooseTarget(outcome, target, source, game);
                lands.add(target.getFirstTarget());
            }
        }
        if (!lands.isEmpty()) {
            int destroyedLands = 0;
            for (UUID landId : lands) {
                Permanent land = game.getPermanent(landId);
                if (land != null) {
                    if (land.destroy(source, game, false)) {
                        destroyedLands++;
                    }
                }
            }
            game.informPlayers(sourcePermanent.getLogName() + ": " + destroyedLands + (destroyedLands > 1 ? " lands were" : "land was") + " destroyed");
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) SubType(mage.constants.SubType) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 2 with FilterLandPermanent

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

the class TraverseTheOutlandsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterLandPermanent filter = new FilterLandPermanent();
    filter.add(TargetController.YOU.getControllerPredicate());
    List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game);
    int amount = 0;
    for (Permanent creature : creatures) {
        int power = creature.getPower().getValue();
        if (amount < power) {
            amount = power;
        }
    }
    TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD_BASIC_LAND);
    if (controller.searchLibrary(target, source, game)) {
        controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl)

Example 3 with FilterLandPermanent

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

the class JolraelEmpressOfBeastsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        FilterPermanent filter = new FilterLandPermanent();
        filter.add(new ControllerIdPredicate(targetPlayer.getId()));
        game.addEffect(new BecomesCreatureAllEffect(new CreatureToken(3, 3), "lands", filter, Duration.EndOfTurn, false), source);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) BecomesCreatureAllEffect(mage.abilities.effects.common.continuous.BecomesCreatureAllEffect) CreatureToken(mage.game.permanent.token.custom.CreatureToken)

Example 4 with FilterLandPermanent

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

the class DefendersForestCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    for (CombatGroup group : game.getCombat().getGroups()) {
        if (group.getAttackers().contains(sourceAbility.getSourceId())) {
            UUID defenderId = group.getDefenderId();
            if (group.isDefenderIsPlaneswalker()) {
                Permanent permanent = game.getPermanent(defenderId);
                if (permanent != null) {
                    defenderId = permanent.getControllerId();
                }
            }
            FilterLandPermanent filter = new FilterLandPermanent("forest");
            filter.add(SubType.FOREST.getPredicate());
            return game.getBattlefield().countAll(filter, defenderId, game);
        }
    }
    return 0;
}
Also used : FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup)

Example 5 with FilterLandPermanent

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

the class SasayasEssenceManaEffect method getNetMana.

@Override
public List<Mana> getNetMana(Game game, Ability source) {
    List<Mana> netMana = new ArrayList<>();
    Player controller = game.getPlayer(source.getControllerId());
    Mana producedMana = (Mana) this.getValue("mana");
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && producedMana != 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) {
            if (producedMana.getBlack() > 0) {
                netMana.add(Mana.BlackMana(count));
            }
            if (producedMana.getRed() > 0) {
                netMana.add(Mana.RedMana(count));
            }
            if (producedMana.getBlue() > 0) {
                netMana.add(Mana.BlueMana(count));
            }
            if (producedMana.getGreen() > 0) {
                netMana.add(Mana.GreenMana(count));
            }
            if (producedMana.getWhite() > 0) {
                netMana.add(Mana.WhiteMana(count));
            }
            if (producedMana.getColorless() > 0) {
                netMana.add(Mana.ColorlessMana(count));
            }
        }
    }
    return netMana;
}
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) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ArrayList(java.util.ArrayList)

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