Search in sources :

Example 16 with FilterControlledLandPermanent

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

the class CantPlayLandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    game.getState().getPlayersInRange(source.getControllerId(), game).forEach((playerId) -> {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            int lands = game.getBattlefield().countAll(new FilterControlledLandPermanent(), playerId, game);
            TargetLandPermanent target = new TargetLandPermanent(Integer.min(5, lands));
            target.setNotTarget(true);
            target.setRequired(true);
            player.chooseTarget(outcome.Benefit, target, source, game);
            game.getBattlefield().getAllActivePermanents(new FilterControlledLandPermanent(), playerId, game).stream().filter((land) -> (!target.getTargets().contains(land.getId()))).forEachOrdered((land) -> {
                land.sacrifice(source, game);
            });
        }
    });
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Zone(mage.constants.Zone) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Outcome(mage.constants.Outcome) PermanentsOnTheBattlefieldCondition(mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) TargetLandPermanent(mage.target.common.TargetLandPermanent) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Duration(mage.constants.Duration) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) ComparisonType(mage.constants.ComparisonType) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) ConditionalContinuousRuleModifyingEffect(mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect) ContinuousRuleModifyingEffectImpl(mage.abilities.effects.ContinuousRuleModifyingEffectImpl) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 17 with FilterControlledLandPermanent

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

the class BendOrBreakEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Map of players and their piles
        Map<UUID, List<List<Permanent>>> playerPermanents = new LinkedHashMap<>();
        PlayerList playerList = game.getState().getPlayerList().copy();
        while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
            playerList.getNext();
        }
        Player currentPlayer = game.getPlayer(playerList.get());
        Player nextPlayer;
        UUID firstNextPlayer = null;
        while (!getNextPlayerInDirection(true, playerList).equals(firstNextPlayer) && controller.canRespond()) {
            nextPlayer = game.getPlayer(playerList.get());
            if (nextPlayer == null) {
                return false;
            }
            if (firstNextPlayer == null) {
                firstNextPlayer = nextPlayer.getId();
            }
            if (!nextPlayer.canRespond()) {
                continue;
            }
            // Each player separates all nontoken lands they control into two piles
            if (currentPlayer != null && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                List<Permanent> firstPile = new ArrayList<>();
                List<Permanent> secondPile = new ArrayList<>();
                FilterControlledLandPermanent filter = new FilterControlledLandPermanent("lands you control to assign to the first pile (lands not chosen will be assigned to the second pile)");
                TargetPermanent target = new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true);
                if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game)) {
                    // TODO: add support for AI (50/50), need AI hints mechanic here
                    currentPlayer.chooseTarget(Outcome.Neutral, target, source, game);
                    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, currentPlayer.getId(), game)) {
                        if (target.getTargets().contains(permanent.getId())) {
                            firstPile.add(permanent);
                        } else {
                            secondPile.add(permanent);
                        }
                    }
                    StringBuilder sb = new StringBuilder("First pile of ").append(currentPlayer.getLogName()).append(": ");
                    sb.append(firstPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
                    game.informPlayers(sb.toString());
                    sb = new StringBuilder("Second pile of ").append(currentPlayer.getLogName()).append(": ");
                    sb.append(secondPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
                    game.informPlayers(sb.toString());
                }
                List<List<Permanent>> playerPiles = new ArrayList<>();
                playerPiles.add(firstPile);
                playerPiles.add(secondPile);
                playerPermanents.put(currentPlayer.getId(), playerPiles);
            }
            currentPlayer = nextPlayer;
        }
        // For each player, one of their piles is chosen by one of their opponents of their choice
        for (Map.Entry<UUID, List<List<Permanent>>> playerPiles : playerPermanents.entrySet()) {
            Player player = game.getPlayer(playerPiles.getKey());
            if (player != null) {
                FilterPlayer filter = new FilterPlayer("opponent");
                List<PlayerIdPredicate> opponentPredicates = new ArrayList<>();
                for (UUID opponentId : game.getOpponents(player.getId())) {
                    opponentPredicates.add(new PlayerIdPredicate(opponentId));
                }
                filter.add(Predicates.or(opponentPredicates));
                Target target = new TargetPlayer(1, 1, true, filter);
                target.setTargetController(player.getId());
                target.setAbilityController(source.getControllerId());
                if (player.chooseTarget(outcome, target, source, game)) {
                    Player chosenOpponent = game.getPlayer(target.getFirstTarget());
                    if (chosenOpponent != null) {
                        List<Permanent> firstPile = playerPiles.getValue().get(0);
                        List<Permanent> secondPile = playerPiles.getValue().get(1);
                        game.informPlayers(player.getLogName() + " chose " + chosenOpponent.getLogName() + " to choose their pile");
                        if (chosenOpponent.choosePile(outcome, "Piles of " + player.getName(), firstPile, secondPile, game)) {
                            List<List<Permanent>> lists = playerPiles.getValue();
                            lists.clear();
                            lists.add(firstPile);
                            lists.add(secondPile);
                            game.informPlayers(player.getLogName() + " will have their first pile destroyed");
                        } else {
                            List<List<Permanent>> lists = playerPiles.getValue();
                            lists.clear();
                            lists.add(secondPile);
                            lists.add(firstPile);
                            game.informPlayers(player.getLogName() + " will have their second pile destroyed");
                        }
                    }
                }
            }
        }
        // Destroy all lands in the chosen piles. Tap all lands in the other piles
        for (Map.Entry<UUID, List<List<Permanent>>> playerPiles : playerPermanents.entrySet()) {
            Player player = game.getPlayer(playerPiles.getKey());
            if (player != null) {
                List<Permanent> pileToSac = playerPiles.getValue().get(0);
                List<Permanent> pileToTap = playerPiles.getValue().get(1);
                for (Permanent permanent : pileToSac) {
                    if (permanent != null) {
                        permanent.destroy(source, game, false);
                    }
                }
                for (Permanent permanent : pileToTap) {
                    if (permanent != null) {
                        permanent.tap(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) TargetPermanent(mage.target.TargetPermanent) PlayerList(mage.players.PlayerList) FilterPlayer(mage.filter.FilterPlayer) TargetPlayer(mage.target.TargetPlayer) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Target(mage.target.Target) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) PlayerList(mage.players.PlayerList) TargetPermanent(mage.target.TargetPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 18 with FilterControlledLandPermanent

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

the class ArgothianWurmEffect 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 19 with FilterControlledLandPermanent

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

the class ChainOfSilenceEffect 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;
    }
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
        ContinuousEffect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn);
        game.addEffect(effect, source);
        Player player = game.getPlayer(permanent.getControllerId());
        TargetControlledPermanent target = new TargetControlledPermanent(0, 1, new FilterControlledLandPermanent("a land to sacrifice (to be able to copy " + sourceObject.getName() + ')'), true);
        if (player != null && player.chooseTarget(Outcome.Sacrifice, target, source, game)) {
            Permanent land = game.getPermanent(target.getFirstTarget());
            if (land != null && land.sacrifice(source, game)) {
                if (player.chooseUse(outcome, "Copy the spell?", source, game)) {
                    Spell spell = game.getStack().getSpell(source.getSourceId());
                    if (spell != null) {
                        spell.createCopyOnStack(game, source, player.getId(), true);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PreventDamageByTargetEffect(mage.abilities.effects.common.PreventDamageByTargetEffect) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Spell(mage.game.stack.Spell)

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