- Added Order of Succession

This commit is contained in:
swordshine
2014-06-08 11:01:14 +00:00
parent 876e9260fe
commit 8ccdcf93c8
14 changed files with 175 additions and 12 deletions

View File

@@ -529,13 +529,25 @@ public class Game {
* {@code null} if there are no players in the game.
*/
public Player getNextPlayerAfter(final Player playerTurn) {
return getNextPlayerAfter(playerTurn, this.turnOrder);
}
/**
* Get the player whose turn it is after a given player's turn, taking turn
* order into account.
* @param playerTurn a {@link Player}, or {@code null}.
* @param turnOrder a {@link Direction}
* @return A {@link Player}, whose turn comes after the current player, or
* {@code null} if there are no players in the game.
*/
public Player getNextPlayerAfter(final Player playerTurn, final Direction turnOrder) {
int iPlayer = roIngamePlayers.indexOf(playerTurn);
if (roIngamePlayers.isEmpty()) {
return null;
}
final int shift = this.getTurnOrder().getShift();
final int shift = turnOrder.getShift();
final int totalNumPlayers = allPlayers.size();
if (-1 == iPlayer) { // if playerTurn has just lost
int iAlive;

View File

@@ -30,6 +30,7 @@ public enum ApiType {
Charm (CharmEffect.class),
ChooseCard (ChooseCardEffect.class),
ChooseColor (ChooseColorEffect.class),
ChooseDirection (ChooseDirectionEffect.class),
ChooseNumber (ChooseNumberEffect.class),
ChoosePlayer (ChoosePlayerEffect.class),
ChooseSource (ChooseSourceEffect.class),

View File

@@ -0,0 +1,35 @@
package forge.game.ability.effects;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
import forge.game.Direction;
import forge.game.Game;
import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card;
import forge.game.player.Player;
import forge.game.player.PlayerController.BinaryChoiceType;
import forge.game.spellability.SpellAbility;
public class ChooseDirectionEffect 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();
final List<Player> left = new ArrayList<Player>(game.getPlayers());
// TODO: We'd better set up turn order UI here
final String info = "Left (clockwise): " + left + "\r\nRight (anticlockwise):" + Lists.reverse(left);
sa.getActivatingPlayer().getController().notifyOfValue(sa, source, info);
boolean chosen = sa.getActivatingPlayer().getController().chooseBinary(sa,
"Choose a direction", BinaryChoiceType.LeftOrRight);
source.setChosenDirection(chosen ? Direction.Left : Direction.Right);
}
}

View File

@@ -117,8 +117,8 @@ public class RepeatEachEffect extends SpellAbilityEffect {
}
if (recordChoice) {
boolean random = sa.hasParam("Random");
Map<Player, List<Card>> recordMap = new HashMap<Player, List<Card>>();
if (sa.hasParam("ChoosePlayer")) {
Map<Player, List<Card>> recordMap = new HashMap<Player, List<Card>>();
for (Card card : repeatCards) {
Player p;
if (random) {
@@ -132,14 +132,40 @@ public class RepeatEachEffect extends SpellAbilityEffect {
recordMap.put(p, Lists.newArrayList(card));
}
}
for (Entry<Player, List<Card>> entry : recordMap.entrySet()) {
// Remember the player and imprint the cards
source.addRemembered(entry.getKey());
source.getImprinted().addAll(entry.getValue());
AbilityUtils.resolve(repeat);
source.removeRemembered(entry.getKey());
source.getImprinted().removeAll(entry.getValue());
}
} else if (sa.hasParam("ChooseCard")) {
List<Card> list = CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield),
sa.getParam("ChooseCard"), source.getController(), source);
String filterController = sa.getParam("FilterControlledBy");
// default: Starting with you and proceeding in the chosen direction
Player p = sa.getActivatingPlayer();
do {
List<Card> valid = new ArrayList<Card>(list);
if ("NextPlayerInChosenDirection".equals(filterController)) {
valid = CardLists.filterControlledBy(valid,
game.getNextPlayerAfter(p, source.getChosenDirection()));
}
Card card = p.getController().chooseSingleEntityForEffect(valid, sa, "Choose a card");
if (recordMap.containsKey(p)) {
recordMap.get(p).add(0, card);
} else {
recordMap.put(p, Lists.newArrayList(card));
}
if (source.getChosenDirection() != null) {
p = game.getNextPlayerAfter(p, source.getChosenDirection());
} else {
p = game.getNextPlayerAfter(p);
}
} while (!p.equals(sa.getActivatingPlayer()));
}
for (Entry<Player, List<Card>> entry : recordMap.entrySet()) {
// Remember the player and imprint the cards
source.addRemembered(entry.getKey());
source.getImprinted().addAll(entry.getValue());
AbilityUtils.resolve(repeat);
source.removeRemembered(entry.getKey());
source.getImprinted().removeAll(entry.getValue());
}
}
}

View File

@@ -207,6 +207,7 @@ public class Card extends GameEntity implements Comparable<Card> {
private int chosenNumber;
private Player chosenPlayer;
private List<Card> chosenCard = new ArrayList<Card>();
private Direction chosenDirection = null;
private Card cloneOrigin = null;
private final List<Card> clones = new ArrayList<Card>();
@@ -1725,6 +1726,14 @@ public class Card extends GameEntity implements Comparable<Card> {
this.chosenCard = c;
}
public Direction getChosenDirection() {
return chosenDirection;
}
public void setChosenDirection(Direction chosenDirection) {
this.chosenDirection = chosenDirection;
}
// used for cards like Meddling Mage...
/**
* <p>
@@ -1898,6 +1907,12 @@ public class Card extends GameEntity implements Comparable<Card> {
sb.append("]\r\n");
}
if (this.chosenDirection != null) {
sb.append("\r\n[Chosen direction: ");
sb.append(this.getChosenDirection());
sb.append("]\r\n");
}
if (this.hauntedBy.size() != 0) {
sb.append("Haunted by: ");
for (final Card c : this.hauntedBy) {
@@ -5476,7 +5491,7 @@ public class Card extends GameEntity implements Comparable<Card> {
if (o instanceof Player) {
if (!p.equals(o)) {
return false;
}
}
}
}
}
@@ -5485,7 +5500,7 @@ public class Card extends GameEntity implements Comparable<Card> {
if (o instanceof Player) {
if (!p.equals(o)) {
return false;
}
}
}
}
} else if (property.startsWith("nonRememberedPlayerCtrl")) {

View File

@@ -65,6 +65,7 @@ public abstract class PlayerController {
OddsOrEvens,
UntapOrLeaveTapped,
UntapTimeVault,
LeftOrRight,
}
protected final Game game;