adjusted stattransition methods to work correctly

This commit is contained in:
Hanno Fleischer
2024-12-08 03:08:47 +01:00
parent 8c22d935a9
commit 8b27ccce22
12 changed files with 57 additions and 18 deletions

View File

@@ -275,6 +275,11 @@ public void received(ActivePlayerMessage msg){
state.received(msg);
}
@Override
public void received(PossiblePieceMessage msg){
state.received(msg);
}
/**
* This method returns the current state
*

View File

@@ -8,10 +8,7 @@
import pp.mdga.client.gamestate.determinestartplayerstate.RollRankingDiceState;
import pp.mdga.client.gamestate.determinestartplayerstate.WaitRankingState;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.ActivePlayerMessage;
import pp.mdga.message.server.DieMessage;
import pp.mdga.message.server.RankingResponseMessage;
import pp.mdga.message.server.RankingRollAgainMessage;
import pp.mdga.message.server.*;
public class DetermineStartPlayerState extends GameStates {
@@ -80,6 +77,11 @@ public void received(DieMessage msg){
state.received(msg);
}
@Override
public void received(DiceNowMessage msg){
state.received(msg);
}
@Override
public void received(RankingRollAgainMessage msg){
state.received(msg);

View File

@@ -132,6 +132,11 @@ public void received(DieMessage msg){
state.received(msg);
}
@Override
public void received(PossiblePieceMessage msg){
state.received(msg);
}
public ChoosePieceState getChoosePiece() {
return choosePieceState;
}

View File

@@ -106,11 +106,12 @@ public void received(DiceNowMessage msg){
@Override
public void received(PossiblePieceMessage msg){
if (msg.getEnemyPossiblePieces().isEmpty()){
parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new)));
parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new)));
parent.setState(parent.getShield());
} else {
parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new)));
parent.getSwap().setPossibleEnemyPieces(msg.getEnemyPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new)));
System.out.println("Should enter Swap State");
parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new)));
parent.getSwap().setPossibleEnemyPieces(msg.getEnemyPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new)));
parent.setState(parent.getSwap());
}
}

View File

@@ -5,6 +5,7 @@
import pp.mdga.client.gamestate.turnstate.PowerCardState;
import pp.mdga.game.Piece;
import pp.mdga.message.client.RequestPlayCardMessage;
import pp.mdga.message.client.SelectCardMessage;
import pp.mdga.message.server.PlayCardMessage;
import pp.mdga.notification.SelectableSwapNotification;
@@ -13,6 +14,8 @@
public class SwapState extends PowerCardStates {
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
private final PowerCardState parent;
private ArrayList<Piece> possibleOwnPieces;
@@ -29,6 +32,7 @@ public SwapState(ClientState parent, ClientGameLogic logic) {
@Override
public void enter() {
LOGGER.log(System.Logger.Level.INFO, "Entering SwapState");
ArrayList<UUID> ownPieces = new ArrayList<>(possibleOwnPieces.stream().map(Piece::getUuid).toList());
ArrayList<UUID> enemyPieces = new ArrayList<>(possibleEnemyPieces.stream().map(Piece::getUuid).toList());
logic.addNotification(new SelectableSwapNotification(ownPieces, enemyPieces));
@@ -36,6 +40,7 @@ public void enter() {
@Override
public void exit() {
LOGGER.log(System.Logger.Level.INFO, "Exiting SwapState");
possibleOwnPieces = null;
possibleEnemyPieces = null;
}

View File

@@ -1,7 +1,9 @@
package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Piece;
import java.io.PipedOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -14,12 +16,12 @@ public class PossiblePieceMessage extends ServerMessage {
/**
* The list of possible own pieces
*/
private final List<UUID> possibleOwnPieces;
private final List<Piece> possibleOwnPieces;
/**
* The list of possible enemy pieces
*/
private final List<UUID> possibleEnemyPieces;
private final List<Piece> possibleEnemyPieces;
/**
* Constructor for PossiblePiece
@@ -37,7 +39,7 @@ public PossiblePieceMessage() {
* @param possibleEnemyPieces the list of possible enemy pieces
* @return the swapped possible pieces
*/
public static PossiblePieceMessage swapPossiblePieces(ArrayList<UUID> possibleOwnPieces, ArrayList<UUID> possibleEnemyPieces) {
public static PossiblePieceMessage swapPossiblePieces(List<Piece> possibleOwnPieces, List<Piece> possibleEnemyPieces) {
PossiblePieceMessage possiblePieceMessage = new PossiblePieceMessage();
possiblePieceMessage.possibleOwnPieces.addAll(possibleOwnPieces);
possiblePieceMessage.possibleEnemyPieces.addAll(possibleEnemyPieces);
@@ -50,7 +52,7 @@ public static PossiblePieceMessage swapPossiblePieces(ArrayList<UUID> possibleOw
* @param possibleOwnPieces the list of possible own pieces
* @return the possible pieces for the shield
*/
public static PossiblePieceMessage shieldPossiblePieces(ArrayList<UUID> possibleOwnPieces) {
public static PossiblePieceMessage shieldPossiblePieces(List<Piece> possibleOwnPieces) {
PossiblePieceMessage possiblePieceMessage = new PossiblePieceMessage();
possiblePieceMessage.possibleOwnPieces.addAll(possibleOwnPieces);
return possiblePieceMessage;
@@ -61,7 +63,7 @@ public static PossiblePieceMessage shieldPossiblePieces(ArrayList<UUID> possible
*
* @param piece the piece to add
*/
public void addOwnPossiblePiece(UUID piece) {
public void addOwnPossiblePiece(Piece piece) {
this.possibleOwnPieces.add(piece);
}
@@ -70,7 +72,7 @@ public void addOwnPossiblePiece(UUID piece) {
*
* @param piece the piece to add
*/
public void addEnemyPossiblePiece(UUID piece) {
public void addEnemyPossiblePiece(Piece piece) {
this.possibleEnemyPieces.add(piece);
}
@@ -79,7 +81,7 @@ public void addEnemyPossiblePiece(UUID piece) {
*
* @return the list of possible pieces
*/
public List<UUID> getOwnPossiblePieces() {
public List<Piece> getOwnPossiblePieces() {
return possibleOwnPieces;
}
@@ -88,7 +90,7 @@ public List<UUID> getOwnPossiblePieces() {
*
* @return the list of possible enemy pieces
*/
public List<UUID> getEnemyPossiblePieces() {
public List<Piece> getEnemyPossiblePieces() {
return possibleEnemyPieces;
}

View File

@@ -90,6 +90,10 @@ public void received(NoPowerCardMessage msg, int from){
this.currentState.received(msg, from);
}
public void received(SelectCardMessage msg, int from){
currentState.received(msg, from);
}
/**
* This method will be called whenever the server received a RequestDieMessage message.
* It will also get the client id of the player who send this message.

View File

@@ -113,6 +113,10 @@ public void received(AnimationEndMessage msg, int from) {
this.currentState.received(msg, from);
}
public void received(SelectCardMessage msg, int from){
currentState.received(msg, from);
}
/**
* This method will be used to return currentState attribute of TurnState class.
*

View File

@@ -3,6 +3,7 @@
import pp.mdga.game.Piece;
import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.NoPowerCardMessage;
import pp.mdga.message.client.SelectCardMessage;
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.PossibleCardsMessage;
@@ -92,6 +93,10 @@ public void addSelectedPiece(Piece piece) {
this.selectedPieces.add(piece);
}
public void received(SelectCardMessage msg, int from){
currentState.received(msg, from);
}
/**
* This method will be called whenever the server received an SelectedPiecesMessage message.
* It will also get the client id of the player who send this message.

View File

@@ -6,6 +6,7 @@
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.IncorrectRequestMessage;
import pp.mdga.message.server.PlayCardMessage;
import pp.mdga.message.server.PossiblePieceMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.turn.PowerCardState;
@@ -27,7 +28,7 @@ public ShieldCardState(PowerCardState powerCardAutomaton, ServerGameLogic logic)
*/
@Override
public void enter() {
logic.getServerSender().send(logic.getGame().getActivePlayerId(), PossiblePieceMessage.shieldPossiblePieces(this.powerCardAutomaton.getVisitor().getShieldPieces()));
}
/**

View File

@@ -3,10 +3,14 @@
import pp.mdga.game.Piece;
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.IncorrectRequestMessage;
import pp.mdga.message.server.PossiblePieceMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.game.turn.PowerCardState;
public class SwapCardState extends PowerCardAutomatonState {
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
/**
* Constructs a server state of the specified game logic.
*
@@ -22,7 +26,8 @@ public SwapCardState(PowerCardState powerCardAutomaton, ServerGameLogic logic) {
*/
@Override
public void enter() {
LOGGER.log(System.Logger.Level.INFO, "Entered SwapCardState");
logic.getServerSender().send(logic.getGame().getActivePlayerId(), PossiblePieceMessage.swapPossiblePieces(this.powerCardAutomaton.getVisitor().getSwapOwnPieces(), this.powerCardAutomaton.getVisitor().getSwapOtherPieces()));
}
/**

View File

@@ -24,7 +24,7 @@ public TurboCardState(PowerCardState powerCardAutomaton, ServerGameLogic logic)
@Override
public void enter() {
this.logic.getGame().getDie().modify();
this.logic.getGame().setDiceModifier(this.logic.getGame().getDiceModifier());
this.logic.getGame().setDiceModifier(this.logic.getGame().getDie().getDieModifier());
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), new ArrayList<>(), this.logic.getGame().getDiceModifier()));
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
}