Commit bf2ccd74 authored by Hans Mackowiak's avatar Hans Mackowiak

Merge branch 'extraTurnPlayer' into 'master'

ExtraTurn in PlayerView

See merge request core-developers/forge!1073
parents e7ec230b da7659d8
......@@ -219,7 +219,7 @@ public class CombatUtil {
}
break;
case "CARDNAME can't attack during extra turns.":
if (game.getPhaseHandler().getPlayerTurn().isPlayingExtraTurn()) {
if (game.getPhaseHandler().getPlayerTurn().isExtraTurn()) {
return false;
}
break;
......
......@@ -799,7 +799,12 @@ public class PhaseHandler implements java.io.Serializable {
private Player getNextActivePlayer() {
ExtraTurn extraTurn = !extraTurns.isEmpty() ? extraTurns.pop() : null;
Player nextPlayer = extraTurn != null ? extraTurn.getPlayer() : game.getNextPlayerAfter(playerTurn);
// update ExtraTurn Count for all players
for (final Player p : game.getPlayers()) {
p.setExtraTurnCount(getExtraTurnForPlayer(p));
}
if (extraTurn != null) {
// The bottom of the extra turn stack is the normal turn
nextPlayer.setExtraTurn(!extraTurns.isEmpty());
......@@ -868,12 +873,31 @@ public class PhaseHandler implements java.io.Serializable {
}
public final ExtraTurn addExtraTurn(final Player player) {
Player previous = null;
// use a stack to handle extra turns, make sure the bottom of the stack
// restores original turn order
if (extraTurns.isEmpty()) {
extraTurns.push(new ExtraTurn(game.getNextPlayerAfter(playerTurn)));
} else {
previous = extraTurns.peek().getPlayer();
}
return extraTurns.push(new ExtraTurn(player));
ExtraTurn result = extraTurns.push(new ExtraTurn(player));
// update Extra Turn for all players
for (final Player p : game.getPlayers()) {
p.setExtraTurnCount(getExtraTurnForPlayer(p));
}
// get all players where the view should be updated
List<Player> toUpdate = Lists.newArrayList(player);
if (previous != null) {
toUpdate.add(previous);
}
// fireEvent to update the Details
game.fireEvent(new GameEventPlayerStatsChanged(toUpdate));
return result;
}
public final void addExtraPhase(final PhaseType afterPhase, final PhaseType extraPhase) {
......@@ -1128,4 +1152,25 @@ public class PhaseHandler implements java.io.Serializable {
public void setCombat(Combat combat) {
this.combat = combat;
}
/**
* returns the continuous extra turn count
* @param PLayer p
* @return int
*/
public int getExtraTurnForPlayer(final Player p) {
if (this.extraTurns.isEmpty() || this.extraTurns.size() < 2) {
return 0;
}
int count = 0;
// skip the first element
for (final ExtraTurn et : extraTurns.subList(1, extraTurns.size())) {
if (!et.getPlayer().equals(p)) {
break;
}
count += 1;
}
return count;
}
}
......@@ -144,7 +144,6 @@ public class Player extends GameEntity implements Comparable<Player> {
private Map<Card, Integer> commanderCast = Maps.newHashMap();
private final Game game;
private boolean triedToDrawFromEmptyLibrary = false;
private boolean isPlayingExtraTrun = false;
private CardCollection lostOwnership = new CardCollection();
private CardCollection gainedOwnership = new CardCollection();
private int numManaConversion = 0;
......@@ -2673,11 +2672,18 @@ public class Player extends GameEntity implements Comparable<Player> {
return result;
}
public boolean isPlayingExtraTurn() {
return isPlayingExtraTrun;
public boolean isExtraTurn() {
return view.getIsExtraTurn();
}
public void setExtraTurn(boolean b) {
isPlayingExtraTrun = b;
view.setIsExtraTurn(b);
}
public int getExtraTurnCount() {
return view.getExtraTurnCount();
}
public void setExtraTurnCount(final int val) {
view.setExtraTurnCount(val);
}
public void initVariantsZones(RegisteredPlayer registeredPlayer) {
......
......@@ -189,6 +189,22 @@ public class PlayerView extends GameEntityView {
set(TrackableProperty.Counters, p.getCounters());
}
public boolean getIsExtraTurn() {
return get(TrackableProperty.IsExtraTurn);
}
public void setIsExtraTurn(final boolean val) {
set(TrackableProperty.IsExtraTurn, val);
}
public int getExtraTurnCount() {
return get(TrackableProperty.ExtraTurnCount);
}
public void setExtraTurnCount(final int val) {
set(TrackableProperty.ExtraTurnCount, val);
}
public int getMaxHandSize() {
return get(TrackableProperty.MaxHandSize);
}
......@@ -422,6 +438,11 @@ public class PlayerView extends GameEntityView {
details.add(TextUtil.concatNoSpace("Cards in hand: ", TextUtil.addSuffix(String.valueOf(getHandSize()),"/"), getMaxHandString()));
details.add(TextUtil.concatWithSpace("Cards drawn this turn:", String.valueOf(getNumDrawnThisTurn())));
details.add(TextUtil.concatWithSpace("Damage prevention:", String.valueOf(getPreventNextDamage())));
if (getIsExtraTurn()) {
details.add("Extra Turn: Yes");
}
details.add(TextUtil.concatWithSpace("Extra Turn Count:", String.valueOf(getExtraTurnCount())));
final String keywords = Lang.joinHomogenous(getDisplayableKeywords());
if (!keywords.isEmpty()) {
details.add(keywords);
......
......@@ -113,6 +113,8 @@ public enum TrackableProperty {
Hand(TrackableTypes.CardViewCollectionType, FreezeMode.IgnoresFreeze),
Library(TrackableTypes.CardViewCollectionType, FreezeMode.IgnoresFreeze),
Mana(TrackableTypes.ManaMapType, FreezeMode.IgnoresFreeze),
IsExtraTurn(TrackableTypes.BooleanType),
ExtraTurnCount(TrackableTypes.IntegerType),
//SpellAbility
HostCard(TrackableTypes.CardViewType),
......
......@@ -412,6 +412,8 @@ public final class CMatchUI
if (vHand != null) {
vHand.getLayoutControl().updateHand();
}
// update Cards in Hand
vField.updateDetails();
}
if (updateAnte) {
cAntes.update();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment