Search in sources :

Example 11 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class PlayersAttackedThisTurnWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.BEGINNING_PHASE_PRE) {
        playersAttackedThisTurn.clear();
        opponentsAttackedThisTurn.clear();
    }
    if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
        // players
        PlayerList playersAttacked = playersAttackedThisTurn.get(event.getPlayerId());
        if (playersAttacked == null) {
            playersAttacked = new PlayerList();
        }
        UUID playerDefender = game.getCombat().getDefendingPlayerId(event.getSourceId(), game);
        if (playerDefender != null && !playersAttacked.contains(playerDefender)) {
            playersAttacked.add(playerDefender);
        }
        playersAttackedThisTurn.putIfAbsent(event.getPlayerId(), playersAttacked);
        // opponents
        PlayerList opponentsAttacked = opponentsAttackedThisTurn.get(event.getPlayerId());
        if (opponentsAttacked == null) {
            opponentsAttacked = new PlayerList();
        }
        UUID opponentDefender = game.getCombat().getDefendingPlayerId(event.getSourceId(), game);
        if (opponentDefender != null && game.getOpponents(event.getPlayerId()).contains(opponentDefender) && !opponentsAttacked.contains(opponentDefender)) {
            opponentsAttacked.add(opponentDefender);
        }
        opponentsAttackedThisTurn.putIfAbsent(event.getPlayerId(), opponentsAttacked);
    }
}
Also used : PlayerList(mage.players.PlayerList) UUID(java.util.UUID)

Example 12 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class MysticBarrierReplacementEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (game.getPlayers().size() > 2) {
        Player controller = game.getPlayer(source.getControllerId());
        if (controller == null) {
            return false;
        }
        if (!game.getState().getPlayersInRange(controller.getId(), game).contains(event.getPlayerId())) {
            return false;
        }
        String allowedDirection = (String) game.getState().getValue(source.getSourceId() + "_modeChoice");
        if (allowedDirection == null) {
            return false;
        }
        Player defender = game.getPlayer(event.getTargetId());
        if (defender == null) {
            Permanent planeswalker = game.getPermanent(event.getTargetId());
            if (planeswalker != null) {
                defender = game.getPlayer(planeswalker.getControllerId());
            }
        }
        if (defender == null) {
            return false;
        }
        PlayerList playerList = game.getState().getPlayerList(event.getPlayerId());
        if (allowedDirection.equals(MysticBarrier.ALLOW_ATTACKING_LEFT) && !playerList.getNext().equals(defender.getId())) {
            // the defender is not the player to the left
            Player attacker = game.getPlayer(event.getPlayerId());
            if (attacker != null) {
                game.informPlayer(attacker, "You can only attack to the left!");
            }
            return true;
        }
        if (allowedDirection.equals(MysticBarrier.ALLOW_ATTACKING_RIGHT) && !playerList.getPrevious().equals(defender.getId())) {
            // the defender is not the player to the right
            Player attacker = game.getPlayer(event.getPlayerId());
            if (attacker != null) {
                game.informPlayer(attacker, "You can only attack to the right!");
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) PlayerList(mage.players.PlayerList)

Example 13 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class OrderOfSuccessionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<UUID, UUID> playerCreature = new HashMap<>(2);
        Choice choice = new ChoiceLeftOrRight();
        if (!controller.choose(Outcome.Neutral, choice, game)) {
            return false;
        }
        boolean left = choice.getChoice().equals("Left");
        PlayerList playerList = game.getState().getPlayerList().copy();
        // set playerlist to controller
        while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
            playerList.getNext();
        }
        Player currentPlayer = game.getPlayer(playerList.get());
        Player nextPlayer;
        UUID firstNextPlayer = null;
        while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer) && controller.canRespond()) {
            nextPlayer = game.getPlayer(playerList.get());
            if (nextPlayer == null) {
                return false;
            }
            // save first next player to check for iteration stop
            if (firstNextPlayer == null) {
                firstNextPlayer = nextPlayer.getId();
            }
            if (!nextPlayer.canRespond()) {
                continue;
            }
            // if player is in range they choose a creature to control
            if (currentPlayer != null && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent("creature controlled by " + nextPlayer.getLogName());
                filter.add(new ControllerIdPredicate(nextPlayer.getId()));
                Target target = new TargetCreaturePermanent(filter);
                target.setNotTarget(true);
                if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game)) {
                    if (currentPlayer.chooseTarget(outcome, target, source, game)) {
                        playerCreature.put(currentPlayer.getId(), target.getFirstTarget());
                    }
                }
            }
            currentPlayer = nextPlayer;
        }
        // change control of targets
        for (Map.Entry<UUID, UUID> entry : playerCreature.entrySet()) {
            Player player = game.getPlayer(entry.getKey());
            if (player != null) {
                Permanent creature = game.getPermanent(entry.getValue());
                if (creature != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, player.getId());
                    effect.setTargetPointer(new FixedTarget(creature.getId(), game));
                    game.addEffect(effect, source);
                    game.informPlayers(new StringBuilder(player.getLogName()).append(" gains control of ").append(creature.getName()).toString());
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) HashMap(java.util.HashMap) PlayerList(mage.players.PlayerList) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ChoiceLeftOrRight(mage.choices.ChoiceLeftOrRight) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class WildfireDevilsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    PlayerList players = game.getState().getPlayersInRange(controller.getId(), game);
    if (players == null) {
        return false;
    }
    Player randomPlayer = game.getPlayer(players.get(RandomUtil.nextInt(players.size())));
    if (randomPlayer == null) {
        return false;
    }
    game.informPlayers("The chosen random player is " + randomPlayer.getLogName());
    if (randomPlayer.getGraveyard().getCards(game).stream().noneMatch(card1 -> card1.isInstantOrSorcery(game))) {
        return false;
    }
    TargetCardInGraveyard targetCard = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
    targetCard.setNotTarget(true);
    if (!randomPlayer.choose(Outcome.Discard, randomPlayer.getGraveyard(), targetCard, game)) {
        return false;
    }
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return false;
    }
    randomPlayer.moveCards(card, Zone.EXILED, source, game);
    if (game.getState().getZone(card.getId()) != Zone.EXILED) {
        return false;
    }
    Card copiedCard = game.copyCard(card, source, controller.getId());
    if (copiedCard == null) {
        return false;
    }
    randomPlayer.moveCards(copiedCard, Zone.EXILED, source, game);
    if (!controller.chooseUse(outcome, "Cast the copy of the exiled card?", source, game)) {
        return false;
    }
    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
    Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
    return cardWasCast;
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ApprovingObject(mage.ApprovingObject) PlayerList(mage.players.PlayerList) Card(mage.cards.Card)

Example 15 with PlayerList

use of mage.players.PlayerList in project mage by magefree.

the class XorLessLifeCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean conditionApplies = false;
    switch(this.type) {
        case AN_OPPONENT:
            for (UUID opponentUUID : game.getOpponents(source.getControllerId())) {
                conditionApplies |= game.getPlayer(opponentUUID).isInGame() && game.getPlayer(opponentUUID).getLife() <= amount;
            }
            break;
        case CONTROLLER:
            conditionApplies = game.getPlayer(source.getControllerId()).getLife() <= amount;
            break;
        case TARGET_OPPONENT:
            // TODO: Implement this.
            break;
        case EACH_PLAYER:
            int maxLife = 0;
            PlayerList playerList = game.getState().getPlayersInRange(source.getControllerId(), game);
            for (UUID pid : playerList) {
                Player p = game.getPlayer(pid);
                if (p != null && p.isInGame()) {
                    if (maxLife < p.getLife()) {
                        maxLife = p.getLife();
                    }
                }
            }
            conditionApplies = maxLife <= amount;
            break;
    }
    return conditionApplies;
}
Also used : Player(mage.players.Player) PlayerList(mage.players.PlayerList) UUID(java.util.UUID)

Aggregations

PlayerList (mage.players.PlayerList)33 Player (mage.players.Player)30 UUID (java.util.UUID)13 Permanent (mage.game.permanent.Permanent)13 Target (mage.target.Target)9 Card (mage.cards.Card)6 FilterCard (mage.filter.FilterCard)5 FilterPermanent (mage.filter.FilterPermanent)5 ContinuousEffect (mage.abilities.effects.ContinuousEffect)4 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)4 TargetCard (mage.target.TargetCard)4 ArrayList (java.util.ArrayList)3 MageObject (mage.MageObject)3 Effect (mage.abilities.effects.Effect)3 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)3 Choice (mage.choices.Choice)3 TargetPermanent (mage.target.TargetPermanent)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 Serializable (java.io.Serializable)2 java.util (java.util)2