mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Add ability to reverse turn order.
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -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/GameCommand.java svneol=native#text/plain
|
||||||
forge-game/src/main/java/forge/ImageKeys.java -text
|
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/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/Game.java -text
|
||||||
forge-game/src/main/java/forge/game/GameAction.java svneol=native#text/plain
|
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
|
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/RestartGameEffect.java -text
|
||||||
forge-game/src/main/java/forge/game/ability/effects/RevealEffect.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/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/RollPlanarDiceEffect.java -text
|
||||||
forge-game/src/main/java/forge/game/ability/effects/RunSVarAbilityEffect.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
|
forge-game/src/main/java/forge/game/ability/effects/SacrificeAllEffect.java -text
|
||||||
|
|||||||
80
forge-game/src/main/java/forge/game/Direction.java
Normal file
80
forge-game/src/main/java/forge/game/Direction.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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<Direction> 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<Direction> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,8 @@ public class Game {
|
|||||||
|
|
||||||
private final Zone stackZone = new Zone(ZoneType.Stack, this);
|
private final Zone stackZone = new Zone(ZoneType.Stack, this);
|
||||||
|
|
||||||
|
private Direction turnOrder = Direction.getDefaultDirection();
|
||||||
|
|
||||||
private long timestamp = 0;
|
private long timestamp = 0;
|
||||||
public final GameAction action;
|
public final GameAction action;
|
||||||
private final Match match;
|
private final Match match;
|
||||||
@@ -288,6 +290,19 @@ public class Game {
|
|||||||
return list;
|
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.
|
* Create and return the next timestamp.
|
||||||
*
|
*
|
||||||
@@ -498,20 +513,25 @@ public class Game {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int shift = this.getTurnOrder().getShift();
|
||||||
|
final int totalNumPlayers = allPlayers.size();
|
||||||
if (-1 == iPlayer) { // if playerTurn has just lost
|
if (-1 == iPlayer) { // if playerTurn has just lost
|
||||||
int iAlive;
|
int iAlive;
|
||||||
iPlayer = allPlayers.indexOf(playerTurn);
|
iPlayer = allPlayers.indexOf(playerTurn);
|
||||||
do {
|
do {
|
||||||
iPlayer = (iPlayer + 1) % allPlayers.size();
|
iPlayer = (iPlayer + shift) % totalNumPlayers;
|
||||||
|
if (iPlayer < 0) {
|
||||||
|
iPlayer += totalNumPlayers;
|
||||||
|
}
|
||||||
iAlive = roIngamePlayers.indexOf(allPlayers.get(iPlayer));
|
iAlive = roIngamePlayers.indexOf(allPlayers.get(iPlayer));
|
||||||
} while (iAlive < 0);
|
} while (iAlive < 0);
|
||||||
iPlayer = iAlive;
|
iPlayer = iAlive;
|
||||||
}
|
}
|
||||||
else { // for the case noone has died
|
else { // for the case noone has died
|
||||||
if (iPlayer == roIngamePlayers.size() - 1) {
|
iPlayer = (iPlayer + shift) % totalNumPlayers;
|
||||||
iPlayer = -1;
|
if (iPlayer < 0) {
|
||||||
|
iPlayer += totalNumPlayers;
|
||||||
}
|
}
|
||||||
iPlayer++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return roIngamePlayers.get(iPlayer);
|
return roIngamePlayers.get(iPlayer);
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ public enum ApiType {
|
|||||||
RestartGame (RestartGameEffect.class),
|
RestartGame (RestartGameEffect.class),
|
||||||
Reveal (RevealEffect.class),
|
Reveal (RevealEffect.class),
|
||||||
RevealHand (RevealHandEffect.class),
|
RevealHand (RevealHandEffect.class),
|
||||||
|
ReverseTurnOrder (ReverseTurnOrderEffect.class),
|
||||||
RollPlanarDice (RollPlanarDiceEffect.class),
|
RollPlanarDice (RollPlanarDiceEffect.class),
|
||||||
RunSVarAbility (RunSVarAbilityEffect.class),
|
RunSVarAbility (RunSVarAbilityEffect.class),
|
||||||
Sacrifice (SacrificeEffect.class),
|
Sacrifice (SacrificeEffect.class),
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user