Search in sources :

Example 11 with FilterControlledLandPermanent

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

the class GlobalRuinDestroyLandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Set<UUID> lands = new HashSet<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            for (SubType landName : Arrays.stream(SubType.values()).filter(p -> p.getSubTypeSet() == SubTypeSet.BasicLandType).collect(Collectors.toSet())) {
                FilterControlledLandPermanent filter = new FilterControlledLandPermanent(landName + " you control");
                filter.add(landName.getPredicate());
                Target target = new TargetControlledPermanent(1, 1, filter, true);
                if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                    player.chooseTarget(outcome, target, source, game);
                    lands.add(target.getFirstTarget());
                }
            }
        }
    }
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_LAND, game)) {
        if (!lands.contains(permanent.getId())) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Target(mage.target.Target) Arrays(java.util.Arrays) StaticFilters(mage.filter.StaticFilters) SubTypeSet(mage.constants.SubTypeSet) Set(java.util.Set) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) SubType(mage.constants.SubType) Collectors(java.util.stream.Collectors) Player(mage.players.Player) HashSet(java.util.HashSet) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Ability(mage.abilities.Ability) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) SubType(mage.constants.SubType) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) UUID(java.util.UUID) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) HashSet(java.util.HashSet)

Example 12 with FilterControlledLandPermanent

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

the class ShivanWumpusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        boolean costPaid = false;
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent()));
            Player player = game.getPlayer(playerId);
            if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
                costPaid = true;
            }
        }
        if (costPaid) {
            super.apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 13 with FilterControlledLandPermanent

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

the class JalumGrifterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getTargets().get(0).getFirstTarget());
    if (controller != null && opponent != null) {
        List<Card> shellGamePile = new ArrayList<>();
        Card sourceCard = game.getCard(source.getSourceId());
        if (sourceCard != null) {
            sourceCard = sourceCard.copy();
            sourceCard.setFaceDown(true, game);
            shellGamePile.add(sourceCard);
            game.informPlayers(controller.getLogName() + " turns " + sourceCard.getLogName() + " face down");
        }
        Target target = new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent(), true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
                controller.chooseTarget(outcome, target, source, game);
            }
        }
        for (UUID cardId : target.getTargets()) {
            Card card = game.getCard(cardId);
            if (card != null) {
                card = card.copy();
                card.setFaceDown(true, game);
                shellGamePile.add(card);
                game.informPlayers(controller.getLogName() + " turns " + card.getLogName() + " face down");
            }
        }
        if (shellGamePile.isEmpty()) {
            return true;
        }
        Collections.shuffle(shellGamePile);
        game.informPlayers(controller.getLogName() + " shuffles the face-down pile");
        TargetCard targetCard = new TargetCard(Zone.HAND, new FilterCard());
        CardsImpl cards = new CardsImpl();
        cards.addAll(shellGamePile);
        if (opponent.choose(Outcome.Sacrifice, cards, targetCard, game)) {
            Card card = game.getCard(targetCard.getFirstTarget());
            if (card != null) {
                card.setFaceDown(false, game);
                game.informPlayers(opponent.getLogName() + " reveals " + card.getLogName());
                if (card.getId().equals(sourceCard.getId())) {
                    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
                    if (sourcePermanent != null) {
                        sourcePermanent.sacrifice(source, game);
                    }
                } else {
                    Permanent permanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
                    if (permanent != null) {
                        permanent.destroy(source, game, false);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 14 with FilterControlledLandPermanent

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

the class CantBlockUnlessControllerControlsMoreLandsEffect method canAttack.

@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
    if (defenderId == null) {
        return true;
    }
    UUID defendingPlayerId;
    Player defender = game.getPlayer(defenderId);
    if (defender == null) {
        Permanent permanent = game.getPermanent(defenderId);
        if (permanent != null) {
            defendingPlayerId = permanent.getControllerId();
        } else {
            return false;
        }
    } else {
        defendingPlayerId = defenderId;
    }
    if (defendingPlayerId != null) {
        return game.getBattlefield().countAll(new FilterControlledLandPermanent(), source.getControllerId(), game) > game.getBattlefield().countAll(new FilterControlledLandPermanent(), defendingPlayerId, game);
    } else {
        return true;
    }
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) UUID(java.util.UUID) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 15 with FilterControlledLandPermanent

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

the class SweepEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        FilterPermanent filter = new FilterControlledLandPermanent("any number of " + sweepSubtype + "s you control");
        filter.add(sweepSubtype.getPredicate());
        Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
        if (controller.chooseTarget(outcome, target, source, game)) {
            game.getState().setValue(CardUtil.getCardZoneString("sweep", source.getSourceId(), game), target.getTargets().size());
            controller.moveCards(new CardsImpl(target.getTargets()), Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) CardsImpl(mage.cards.CardsImpl)

Aggregations

FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)19 Player (mage.players.Player)19 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)14 Permanent (mage.game.permanent.Permanent)13 UUID (java.util.UUID)11 Target (mage.target.Target)7 OneShotEffect (mage.abilities.effects.OneShotEffect)4 Cost (mage.abilities.costs.Cost)3 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)3 CardsImpl (mage.cards.CardsImpl)3 TargetPermanent (mage.target.TargetPermanent)3 ArrayList (java.util.ArrayList)2 MageObject (mage.MageObject)2 Ability (mage.abilities.Ability)2 Effect (mage.abilities.effects.Effect)2 Card (mage.cards.Card)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 CardType (mage.constants.CardType)2 Outcome (mage.constants.Outcome)2