fixed bug with too early state transition after playing a powercard
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import pp.mdga.client.ClientGameLogic;
|
import pp.mdga.client.ClientGameLogic;
|
||||||
import pp.mdga.client.ClientState;
|
import pp.mdga.client.ClientState;
|
||||||
import pp.mdga.client.gamestate.TurnState;
|
import pp.mdga.client.gamestate.TurnState;
|
||||||
|
import pp.mdga.game.BonusCard;
|
||||||
import pp.mdga.message.client.AnimationEndMessage;
|
import pp.mdga.message.client.AnimationEndMessage;
|
||||||
import pp.mdga.message.server.PlayCardMessage;
|
import pp.mdga.message.server.PlayCardMessage;
|
||||||
import pp.mdga.notification.PlayCardNotification;
|
import pp.mdga.notification.PlayCardNotification;
|
||||||
@@ -12,6 +13,7 @@ public class PlayPowerCardState extends TurnStates {
|
|||||||
private final TurnState parent;
|
private final TurnState parent;
|
||||||
|
|
||||||
private PlayCardMessage playCardMessage;
|
private PlayCardMessage playCardMessage;
|
||||||
|
private int animationCounter = 0;
|
||||||
|
|
||||||
public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
|
public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
|
||||||
super(parent, logic);
|
super(parent, logic);
|
||||||
@@ -20,7 +22,11 @@ public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
animationCounter++;
|
||||||
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor() , playCardMessage.getCard().getCard()));
|
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor() , playCardMessage.getCard().getCard()));
|
||||||
|
if(!playCardMessage.getCard().getCard().equals(BonusCard.TURBO)){
|
||||||
|
animationCounter++;
|
||||||
|
}
|
||||||
handlePowerCard(playCardMessage);
|
handlePowerCard(playCardMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +41,10 @@ public void setPlayCard(PlayCardMessage playCardMessage) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectAnimationEnd(){
|
public void selectAnimationEnd(){
|
||||||
logic.send(new AnimationEndMessage());
|
animationCounter--;
|
||||||
parent.setState(parent.getRollDice());
|
if(animationCounter == 0){
|
||||||
|
logic.send(new AnimationEndMessage());
|
||||||
|
parent.setState(parent.getRollDice());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class FirstRollState extends RollDiceAutomatonState {
|
|||||||
private static final System.Logger LOGGER = System.getLogger(FirstRollState.class.getName());
|
private static final System.Logger LOGGER = System.getLogger(FirstRollState.class.getName());
|
||||||
private List<Piece> moveablePieces;
|
private List<Piece> moveablePieces;
|
||||||
private int roll;
|
private int roll;
|
||||||
|
private boolean isDied = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a server state of the specified game logic.
|
* Constructs a server state of the specified game logic.
|
||||||
@@ -37,6 +38,7 @@ public FirstRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
|
|||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
|
LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
|
||||||
roll = 0;
|
roll = 0;
|
||||||
|
isDied = false;
|
||||||
moveablePieces = new ArrayList<>();
|
moveablePieces = new ArrayList<>();
|
||||||
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
|
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
|
||||||
if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
|
if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
|
||||||
@@ -62,14 +64,16 @@ public void received(RequestDieMessage msg, int from) {
|
|||||||
roll = this.logic.getGame().getDie().shuffle();
|
roll = this.logic.getGame().getDie().shuffle();
|
||||||
this.logic.getGame().setDiceEyes(roll);
|
this.logic.getGame().setDiceEyes(roll);
|
||||||
this.logic.getServerSender().broadcast(new DieMessage(roll));
|
this.logic.getServerSender().broadcast(new DieMessage(roll));
|
||||||
|
isDied = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(AnimationEndMessage msg, int from) {
|
public void received(AnimationEndMessage msg, int from) {
|
||||||
if (from != this.logic.getGame().getActivePlayerId()) {
|
if (from != this.logic.getGame().getActivePlayerId()) {
|
||||||
return;
|
LOGGER.log(System.Logger.Level.INFO, "Received AnimationEndMessage from wrong player.");
|
||||||
}
|
} else if (!isDied){
|
||||||
if (!moveablePieces.isEmpty()) {
|
LOGGER.log(System.Logger.Level.INFO, "Received AnimationEndMessage without the active player rolling a die.");
|
||||||
|
} else if (!moveablePieces.isEmpty()) {
|
||||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage());
|
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage());
|
||||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user