Search in sources :

Example 16 with FilterLandPermanent

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

the class OreskosExplorerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    int controllerLands = game.getBattlefield().countAll(new FilterLandPermanent(), controller.getId(), game);
    int landsToSearch = 0;
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        if (!playerId.equals(controller.getId())) {
            if (controllerLands < game.getBattlefield().countAll(new FilterLandPermanent(), playerId, game)) {
                landsToSearch++;
            }
        }
    }
    if (landsToSearch > 0) {
        FilterLandCard filterPlains = new FilterLandCard("up to " + landsToSearch + " Plains cards");
        filterPlains.add(SubType.PLAINS.getPredicate());
        TargetCardInLibrary target = new TargetCardInLibrary(0, landsToSearch, filterPlains);
        if (controller.searchLibrary(target, source, game, controller.getId())) {
            Cards cards = new CardsImpl(target.getTargets());
            controller.revealCards(sourceObject.getIdName(), cards, game);
            controller.moveCards(cards.getCards(game), Zone.HAND, source, game);
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandCard(mage.filter.common.FilterLandCard) MageObject(mage.MageObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 17 with FilterLandPermanent

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

the class PowerSinkCounterUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        Player controller = game.getPlayer(source.getControllerId());
        MageObject sourceObject = game.getObject(source.getSourceId());
        if (player != null && controller != null && sourceObject != null) {
            int amount = source.getManaCostsToPay().getX();
            if (amount > 0) {
                Cost cost = ManaUtil.createManaCost(amount, true);
                if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " to prevent?", source, game)) {
                    if (cost.pay(source, game, source, player.getId(), false)) {
                        game.informPlayers(sourceObject.getName() + ": additional cost was paid");
                        return true;
                    }
                }
                game.informPlayers(sourceObject.getName() + ": additional cost wasn't paid - countering " + spell.getName());
                // Counter target spell unless its controller pays {X}
                game.getStack().counter(source.getFirstTarget(), source, game);
                // that player taps all lands with mana abilities they control...
                List<Permanent> lands = game.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), player.getId(), game);
                for (Permanent land : lands) {
                    Abilities<Ability> landAbilities = land.getAbilities();
                    for (Ability ability : landAbilities) {
                        if (ability instanceof ActivatedManaAbilityImpl) {
                            land.tap(source, game);
                            break;
                        }
                    }
                }
                // ...and empties their mana pool
                player.getManaPool().emptyPool(game);
            }
            return true;
        }
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) Cost(mage.abilities.costs.Cost)

Example 18 with FilterLandPermanent

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

the class KeldonFirebombersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Permanent> landsToSacrifice = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            int amount = game.getBattlefield().getAllActivePermanents(filter, playerId, game).size() - 3;
            if (amount > 0) {
                FilterLandPermanent playerFilter = filter.copy();
                playerFilter.add(new ControllerIdPredicate(playerId));
                Target target = new TargetLandPermanent(amount, amount, playerFilter, true);
                player.choose(outcome.Sacrifice, target, source.getSourceId(), game);
                for (UUID landId : target.getTargets()) {
                    Permanent land = game.getPermanent(landId);
                    if (land != null) {
                        landsToSacrifice.add(land);
                    }
                }
            }
        }
    }
    for (Permanent land : landsToSacrifice) {
        land.sacrifice(source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ArrayList(java.util.ArrayList) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID)

Example 19 with FilterLandPermanent

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

the class SurveyorsScopeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int numberOfLands = 0;
        int ownLands = game.getBattlefield().countAll(new FilterLandPermanent(), controller.getId(), game);
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (!playerId.equals(controller.getId())) {
                if (game.getBattlefield().countAll(new FilterLandPermanent(), playerId, game) > ownLands + 1) {
                    numberOfLands++;
                }
            }
        }
        game.informPlayers("Surveyor's Scope: X = " + numberOfLands);
        // 10/17/2013 	If no players control at least two more lands than you when the ability resolves, you'll still search and shuffle your library.
        return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(0, numberOfLands, StaticFilters.FILTER_CARD_BASIC_LAND)).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 20 with FilterLandPermanent

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

the class ThoughtsOfRuinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int amount = controller.getHand().size();
        if (amount > 0) {
            List<Permanent> permanentsToSacrifice = new ArrayList<>();
            // select all lands to sacrifice
            for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    int lands = game.getState().getBattlefield().countAll(filter, playerId, game);
                    if (amount >= lands) {
                        permanentsToSacrifice.addAll(game.getState().getBattlefield().getAllActivePermanents(filter, playerId, game));
                    } else {
                        FilterLandPermanent playerFilter = filter.copy();
                        playerFilter.add(new ControllerIdPredicate(playerId));
                        Target target = new TargetLandPermanent(amount, amount, playerFilter, true);
                        player.choose(outcome, target, source.getSourceId(), game);
                        for (UUID landId : target.getTargets()) {
                            Permanent permanent = game.getPermanent(landId);
                            if (permanent != null) {
                                permanentsToSacrifice.add(permanent);
                            }
                        }
                    }
                }
            }
            // sacrifice all lands
            for (Permanent permanent : permanentsToSacrifice) {
                permanent.sacrifice(source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ArrayList(java.util.ArrayList) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID)

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