Search in sources :

Example 6 with PlayerIdPredicate

use of mage.filter.predicate.other.PlayerIdPredicate in project mage by magefree.

the class PreventAllDamageToAllEffect method createFilter.

private static FilterPermanentOrPlayer createFilter(FilterPermanent filterPermanent, FilterPlayer filterPlayer) {
    String mes1 = filterPermanent != null ? filterPermanent.getMessage() : "";
    String mes2 = filterPlayer != null ? filterPlayer.getMessage() : "";
    String message;
    if (!mes1.isEmpty() && !mes2.isEmpty()) {
        message = mes1 + " and " + mes2;
    } else {
        message = mes1 + mes2;
    }
    FilterPermanent filter1 = filterPermanent;
    if (filter1 == null) {
        filter1 = new FilterPermanent();
        // disable filter
        filter1.add(new PermanentIdPredicate(UUID.randomUUID()));
    }
    FilterPlayer filter2 = filterPlayer;
    if (filter2 == null) {
        filter2 = new FilterPlayer();
        // disable filter
        filter2.add(new PlayerIdPredicate(UUID.randomUUID()));
    }
    return new FilterPermanentOrPlayer(message, filter1, filter2);
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterPermanentOrPlayer(mage.filter.common.FilterPermanentOrPlayer) FilterPermanent(mage.filter.FilterPermanent) FilterPlayer(mage.filter.FilterPlayer) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate)

Example 7 with PlayerIdPredicate

use of mage.filter.predicate.other.PlayerIdPredicate 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 8 with PlayerIdPredicate

use of mage.filter.predicate.other.PlayerIdPredicate in project mage by magefree.

the class BurningCinderFuryOfCrimsonChaosFireWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player tappingPlayer = game.getPlayer(firstControllerId);
    Permanent permanentToControl = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (tappingPlayer != null && permanentToControl != null) {
        // Create opponent filter list manually because otherwise opponent check prevents controller of this to be valid
        FilterPlayer filter = new FilterPlayer("opponent to control " + permanentToControl.getIdName());
        List<PlayerIdPredicate> opponentPredicates = new ArrayList<>();
        for (UUID opponentId : game.getOpponents(firstControllerId)) {
            opponentPredicates.add(new PlayerIdPredicate(opponentId));
        }
        filter.add(Predicates.or(opponentPredicates));
        Target target = new TargetPlayer(1, 1, true, filter);
        target.setTargetController(firstControllerId);
        target.setAbilityController(source.getControllerId());
        if (tappingPlayer.chooseTarget(outcome, target, source, game)) {
            Player chosenOpponent = game.getPlayer(target.getFirstTarget());
            if (chosenOpponent != null) {
                game.informPlayers(tappingPlayer.getLogName() + " chose " + chosenOpponent.getLogName() + " to gain control of " + permanentToControl.getLogName() + " at the beginning of the next end step");
                ContinuousEffect effect = new BurningCinderFuryOfCrimsonChaosFireCreatureGainControlEffect(Duration.Custom, chosenOpponent.getId());
                effect.setTargetPointer(new FixedTarget(permanentToControl.getId(), game));
                game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) Permanent(mage.game.permanent.Permanent) FilterPlayer(mage.filter.FilterPlayer) TargetPlayer(mage.target.TargetPlayer) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Aggregations

PlayerIdPredicate (mage.filter.predicate.other.PlayerIdPredicate)8 Player (mage.players.Player)7 FilterPlayer (mage.filter.FilterPlayer)6 Permanent (mage.game.permanent.Permanent)6 TargetPlayer (mage.target.TargetPlayer)4 FixedTarget (mage.target.targetpointer.FixedTarget)4 UUID (java.util.UUID)3 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 Card (mage.cards.Card)2 FilterPlayerOrPlaneswalker (mage.filter.common.FilterPlayerOrPlaneswalker)2 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)2 Target (mage.target.Target)2 TargetPlayerOrPlaneswalker (mage.target.common.TargetPlayerOrPlaneswalker)2 HashSet (java.util.HashSet)1 Ability (mage.abilities.Ability)1 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)1 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)1 ConditionalInterveningIfTriggeredAbility (mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility)1 Effect (mage.abilities.effects.Effect)1