diff --git a/.gitattributes b/.gitattributes
index 9a6615df295..376e6bc6bcd 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -259,6 +259,7 @@ forge-game/pom.xml -text
forge-game/src/main/java/forge/GameCommand.java svneol=native#text/plain
forge-game/src/main/java/forge/ImageKeys.java -text
forge-game/src/main/java/forge/game/CardTraitBase.java -text
+forge-game/src/main/java/forge/game/Direction.java -text
forge-game/src/main/java/forge/game/Game.java -text
forge-game/src/main/java/forge/game/GameAction.java svneol=native#text/plain
forge-game/src/main/java/forge/game/GameActionUtil.java svneol=native#text/plain
@@ -387,6 +388,7 @@ forge-game/src/main/java/forge/game/ability/effects/RepeatEffect.java -text
forge-game/src/main/java/forge/game/ability/effects/RestartGameEffect.java -text
forge-game/src/main/java/forge/game/ability/effects/RevealEffect.java -text
forge-game/src/main/java/forge/game/ability/effects/RevealHandEffect.java -text
+forge-game/src/main/java/forge/game/ability/effects/ReverseTurnOrderEffect.java -text
forge-game/src/main/java/forge/game/ability/effects/RollPlanarDiceEffect.java -text
forge-game/src/main/java/forge/game/ability/effects/RunSVarAbilityEffect.java -text
forge-game/src/main/java/forge/game/ability/effects/SacrificeAllEffect.java -text
diff --git a/forge-game/src/main/java/forge/game/Direction.java b/forge-game/src/main/java/forge/game/Direction.java
new file mode 100644
index 00000000000..1e08482a107
--- /dev/null
+++ b/forge-game/src/main/java/forge/game/Direction.java
@@ -0,0 +1,80 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Forge Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.game;
+
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Represents a direction (left or right).
+ */
+public enum Direction {
+ Left,
+ Right;
+
+ private static final String LEFT = "Left";
+ private static final String RIGHT = "Right";
+ /** Immutable list of all directions (in order, Left and Right). */
+ private static final List listOfDirections =
+ ImmutableList.of(getDefaultDirection(), getDefaultDirection().getOtherDirection());
+
+ /** @return The default direction. */
+ public static final Direction getDefaultDirection() { return Left; }
+
+ /** @return Immutable list of all directions (in order, Left and Right). */
+ public static List getListOfDirections() { return listOfDirections; }
+
+ /**
+ * Get the index by which the turn order is shifted, given this Direction.
+ * @return 1 or -1.
+ */
+ public int getShift() {
+ if (this.equals(getDefaultDirection())) {
+ return 1;
+ }
+ return -1;
+ }
+
+ /**
+ * Give the other Direction.
+ * @return Right if this is Left, and vice versa.
+ */
+ public Direction getOtherDirection() {
+ switch (this) {
+ case Left:
+ return Direction.Right;
+ case Right:
+ return Direction.Left;
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ switch(this) {
+ case Left:
+ return LEFT;
+ case Right:
+ return RIGHT;
+ }
+ return null;
+ }
+}
diff --git a/forge-game/src/main/java/forge/game/Game.java b/forge-game/src/main/java/forge/game/Game.java
index cb1af37b0aa..ea5bf615bdb 100644
--- a/forge-game/src/main/java/forge/game/Game.java
+++ b/forge-game/src/main/java/forge/game/Game.java
@@ -85,6 +85,8 @@ public class Game {
private final GameLog gameLog = new GameLog();
private final Zone stackZone = new Zone(ZoneType.Stack, this);
+
+ private Direction turnOrder = Direction.getDefaultDirection();
private long timestamp = 0;
public final GameAction action;
@@ -287,6 +289,19 @@ public class Game {
});
return list;
}
+
+ /**
+ * Get the turn order.
+ * @return the Direction in which the turn order of this Game currently
+ * proceeds.
+ */
+ public final Direction getTurnOrder() {
+ return this.turnOrder;
+ }
+
+ public final void reverseTurnOrder() {
+ this.turnOrder = this.turnOrder.getOtherDirection();
+ }
/**
* Create and return the next timestamp.
@@ -498,20 +513,25 @@ public class Game {
return null;
}
+ final int shift = this.getTurnOrder().getShift();
+ final int totalNumPlayers = allPlayers.size();
if (-1 == iPlayer) { // if playerTurn has just lost
int iAlive;
iPlayer = allPlayers.indexOf(playerTurn);
do {
- iPlayer = (iPlayer + 1) % allPlayers.size();
+ iPlayer = (iPlayer + shift) % totalNumPlayers;
+ if (iPlayer < 0) {
+ iPlayer += totalNumPlayers;
+ }
iAlive = roIngamePlayers.indexOf(allPlayers.get(iPlayer));
} while (iAlive < 0);
iPlayer = iAlive;
}
else { // for the case noone has died
- if (iPlayer == roIngamePlayers.size() - 1) {
- iPlayer = -1;
- }
- iPlayer++;
+ iPlayer = (iPlayer + shift) % totalNumPlayers;
+ if (iPlayer < 0) {
+ iPlayer += totalNumPlayers;
+ }
}
return roIngamePlayers.get(iPlayer);
diff --git a/forge-game/src/main/java/forge/game/ability/ApiType.java b/forge-game/src/main/java/forge/game/ability/ApiType.java
index f8aa5c7e967..75aec52ff79 100644
--- a/forge-game/src/main/java/forge/game/ability/ApiType.java
+++ b/forge-game/src/main/java/forge/game/ability/ApiType.java
@@ -109,6 +109,7 @@ public enum ApiType {
RestartGame (RestartGameEffect.class),
Reveal (RevealEffect.class),
RevealHand (RevealHandEffect.class),
+ ReverseTurnOrder (ReverseTurnOrderEffect.class),
RollPlanarDice (RollPlanarDiceEffect.class),
RunSVarAbility (RunSVarAbilityEffect.class),
Sacrifice (SacrificeEffect.class),
diff --git a/forge-game/src/main/java/forge/game/ability/effects/ReverseTurnOrderEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ReverseTurnOrderEffect.java
new file mode 100644
index 00000000000..fd06cecd4ae
--- /dev/null
+++ b/forge-game/src/main/java/forge/game/ability/effects/ReverseTurnOrderEffect.java
@@ -0,0 +1,20 @@
+package forge.game.ability.effects;
+
+import forge.game.Game;
+import forge.game.ability.SpellAbilityEffect;
+import forge.game.card.Card;
+import forge.game.spellability.SpellAbility;
+
+public class ReverseTurnOrderEffect extends SpellAbilityEffect {
+
+ /* (non-Javadoc)
+ * @see forge.card.abilityfactory.SpellEffect#resolve(java.util.Map, forge.card.spellability.SpellAbility)
+ */
+ @Override
+ public void resolve(final SpellAbility sa) {
+ final Card source = sa.getHostCard();
+ final Game game = source.getGame();
+ game.reverseTurnOrder();
+ }
+
+}