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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations