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.ClientState;
|
||||
import pp.mdga.client.gamestate.TurnState;
|
||||
import pp.mdga.game.BonusCard;
|
||||
import pp.mdga.message.client.AnimationEndMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.notification.PlayCardNotification;
|
||||
@@ -12,6 +13,7 @@ public class PlayPowerCardState extends TurnStates {
|
||||
private final TurnState parent;
|
||||
|
||||
private PlayCardMessage playCardMessage;
|
||||
private int animationCounter = 0;
|
||||
|
||||
public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
@@ -20,7 +22,11 @@ public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
animationCounter++;
|
||||
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor() , playCardMessage.getCard().getCard()));
|
||||
if(!playCardMessage.getCard().getCard().equals(BonusCard.TURBO)){
|
||||
animationCounter++;
|
||||
}
|
||||
handlePowerCard(playCardMessage);
|
||||
}
|
||||
|
||||
@@ -35,7 +41,10 @@ public void setPlayCard(PlayCardMessage playCardMessage) {
|
||||
|
||||
@Override
|
||||
public void selectAnimationEnd(){
|
||||
logic.send(new AnimationEndMessage());
|
||||
parent.setState(parent.getRollDice());
|
||||
animationCounter--;
|
||||
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 List<Piece> moveablePieces;
|
||||
private int roll;
|
||||
private boolean isDied = false;
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
@@ -37,6 +38,7 @@ public FirstRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
|
||||
public void enter() {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
|
||||
roll = 0;
|
||||
isDied = false;
|
||||
moveablePieces = new ArrayList<>();
|
||||
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
|
||||
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();
|
||||
this.logic.getGame().setDiceEyes(roll);
|
||||
this.logic.getServerSender().broadcast(new DieMessage(roll));
|
||||
isDied = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(AnimationEndMessage msg, int from) {
|
||||
if (from != this.logic.getGame().getActivePlayerId()) {
|
||||
return;
|
||||
}
|
||||
if (!moveablePieces.isEmpty()) {
|
||||
LOGGER.log(System.Logger.Level.INFO, "Received AnimationEndMessage from wrong player.");
|
||||
} else if (!isDied){
|
||||
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.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user