From f270213bb7b5bc065e91f0d4d905311fb9ab398c Mon Sep 17 00:00:00 2001 From: "Jamin W. Collins" Date: Thu, 15 Mar 2018 09:19:17 -0600 Subject: [PATCH] Improve can't win/lose effects for multiplayer Fixes: core-developers/forge#170 Signed-off-by: Jamin W. Collins --- .../src/main/java/forge/game/GameAction.java | 22 +++++++++++++++++-- .../main/java/forge/game/player/Player.java | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index 0cd254fe430..4055250ddfa 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -1206,6 +1206,7 @@ public class GameAction { public void checkGameOverCondition() { // award loses as SBE List losers = null; + FCollectionView allPlayers = game.getPlayers(); for (Player p : allPlayers) { if (p.checkLoseCondition()) { // this will set appropriate outcomes @@ -1219,14 +1220,14 @@ public class GameAction { GameEndReason reason = null; // Has anyone won by spelleffect? - for (Player p : game.getPlayers()) { + for (Player p : allPlayers) { if (!p.hasWon()) { continue; } // then the rest have lost! reason = GameEndReason.WinsGameSpellEffect; - for (Player pl : game.getPlayers()) { + for (Player pl : allPlayers) { if (pl.equals(p)) { continue; } @@ -1243,6 +1244,23 @@ public class GameAction { break; } + // loop through all the non-losing players that can't win + // see if all of their opponents are in that "about to lose" collection + if (losers != null) { + for (Player p : allPlayers) { + if (losers.contains(p)) { + continue; + } + if (p.cantWin()) { + if (losers.containsAll(p.getOpponents())) { + // what to do here?!?!?! + System.err.println(p.toString() + " is about to win, but can't!"); + } + } + + } + } + // need a separate loop here, otherwise ConcurrentModificationException is raised if (losers != null) { for (Player p : losers) { diff --git a/forge-game/src/main/java/forge/game/player/Player.java b/forge-game/src/main/java/forge/game/player/Player.java index c05bd569f7d..e919719ef5f 100644 --- a/forge-game/src/main/java/forge/game/player/Player.java +++ b/forge-game/src/main/java/forge/game/player/Player.java @@ -1825,7 +1825,7 @@ public class Player extends GameEntity implements Comparable { if (getOutcome() != null && getOutcome().lossState == GameLossReason.Conceded) { return false; } - return (hasKeyword("You can't lose the game.") || Iterables.any(getOpponents(), PlayerPredicates.CANT_WIN)); + return hasKeyword("You can't lose the game."); } public final boolean cantLoseForZeroOrLessLife() {