Merge remote-tracking branch 'origin/dev/server_h' into development
This commit is contained in:
		@@ -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
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -80,6 +80,7 @@ public void received(ServerStartGameMessage msg) {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        logic.getGame().setBoard(msg.getBoard());
 | 
			
		||||
        System.out.println(logic.getGame().getPlayerById(logic.getOwnPlayerId()).toString());
 | 
			
		||||
        logic.addNotification(new GameNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor()));
 | 
			
		||||
        for (var player : logic.getGame().getPlayers().values()) {
 | 
			
		||||
            List<UUID> pieces = new ArrayList<>();
 | 
			
		||||
@@ -94,6 +95,7 @@ public void received(ServerStartGameMessage msg) {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerJoinedMessage msg) {
 | 
			
		||||
        if (msg.getPlayer().getName().equals(logic.getOwnPlayerName())) {
 | 
			
		||||
            System.out.println(msg.getId());
 | 
			
		||||
            logic.setOwnPlayerId(msg.getId());
 | 
			
		||||
        }
 | 
			
		||||
        if (msg.isHost() && msg.getId() == logic.getOwnPlayerId()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 | 
			
		||||
@@ -61,8 +58,8 @@ public void setState(DetermineStartPlayerStates state) {
 | 
			
		||||
        if(this.state != null){
 | 
			
		||||
            this.state.exit();
 | 
			
		||||
        }
 | 
			
		||||
        state.enter();
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.state.enter();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -63,7 +63,7 @@ public void received(ActivePlayerMessage msg) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg) {
 | 
			
		||||
        Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
 | 
			
		||||
        Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
 | 
			
		||||
        if (msg.isHomeMove()) {
 | 
			
		||||
            logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
            logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -67,7 +67,7 @@ public void received(ActivePlayerMessage msg) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg) {
 | 
			
		||||
        Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
 | 
			
		||||
        Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
 | 
			
		||||
        if (msg.isHomeMove()) {
 | 
			
		||||
            logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
            logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,6 @@ public DetermineStartPlayerState getParent(){
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        for(Map.Entry<Integer, Player> entry : logic.getGame().getPlayers().entrySet()){
 | 
			
		||||
            //logic.addNotification(new WaitMoveNotification(entry.getValue().getPieces()[0].getUuid()));
 | 
			
		||||
            logic.addNotification(new MovePieceNotification(entry.getValue().getPieces()[0].getUuid(), entry.getValue().getStartNodeIndex(), true));
 | 
			
		||||
            logic.getGame().getBoard().getInfield()[entry.getValue().getStartNodeIndex()].setOccupant(entry.getValue().getPieces()[0]);
 | 
			
		||||
            animationCounter++;
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,8 @@
 | 
			
		||||
 | 
			
		||||
public class RollRankingDiceState extends DetermineStartPlayerStates {
 | 
			
		||||
 | 
			
		||||
    private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
 | 
			
		||||
 | 
			
		||||
    private final DetermineStartPlayerState parent;
 | 
			
		||||
 | 
			
		||||
    public RollRankingDiceState(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
@@ -19,11 +21,13 @@ public RollRankingDiceState(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Entering RollRankingDiceState");
 | 
			
		||||
        logic.addNotification(new DiceNowNotification());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Exiting RollRankingDiceState");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,8 @@
 | 
			
		||||
 | 
			
		||||
public class WaitRankingState extends DetermineStartPlayerStates {
 | 
			
		||||
 | 
			
		||||
    private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
 | 
			
		||||
 | 
			
		||||
    private final DetermineStartPlayerState parent;
 | 
			
		||||
    private boolean canChange = false;
 | 
			
		||||
 | 
			
		||||
@@ -27,11 +29,12 @@ private void changeToIntro(){
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Entering WaitRankingState");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Exiting WaitRankingState");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -47,6 +47,7 @@ public void received(DieMessage msg){
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectAnimationEnd(){
 | 
			
		||||
        logic.send(new AnimationEndMessage());
 | 
			
		||||
        parent.setState(parent.getChoosePiece());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,8 @@
 | 
			
		||||
 | 
			
		||||
public class NoPieceState extends ChoosePieceStates {
 | 
			
		||||
 | 
			
		||||
    private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
 | 
			
		||||
 | 
			
		||||
    private final ChoosePieceState parent;
 | 
			
		||||
 | 
			
		||||
    public NoPieceState(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
@@ -25,7 +27,7 @@ public NoPieceState(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Entering NoPieceState");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -35,14 +37,16 @@ public void exit() {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(SelectPieceMessage msg) {
 | 
			
		||||
        parent.setState(parent.getSelectPiece());
 | 
			
		||||
        ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new));
 | 
			
		||||
        ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new));
 | 
			
		||||
        parent.getSelectPiece().setPossiblePieces(pieces);
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Received " + msg.getPieces().size() + " pieces");
 | 
			
		||||
        logic.addNotification(new SelectableMoveNotification(pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new)), msg.getTargetIndex(), msg.getIsHomeMove()));
 | 
			
		||||
        parent.setState(parent.getSelectPiece());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(WaitPieceMessage msg){
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Received WaitPieceMessage");
 | 
			
		||||
        logic.addNotification(new WaitMoveNotification(msg.getPieceID()));
 | 
			
		||||
        parent.setState(parent.getWaitingPiece());
 | 
			
		||||
    }
 | 
			
		||||
@@ -56,6 +60,8 @@ public void received(StartPieceMessage msg){
 | 
			
		||||
        listPiece.add(piece.getUuid());
 | 
			
		||||
        listIndex.add(msg.getTargetIndex());
 | 
			
		||||
        homeMove.add(false);
 | 
			
		||||
        parent.getStartPiece().setMoveablePiece(piece);
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Received start piece " + listPiece.get(0));
 | 
			
		||||
        logic.addNotification(new SelectableMoveNotification(listPiece, listIndex, homeMove));
 | 
			
		||||
        parent.setState(parent.getStartPiece());
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,7 @@ public void selectPiece(Piece piece) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg) {
 | 
			
		||||
        Piece piece = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
 | 
			
		||||
        Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
 | 
			
		||||
        if (msg.isHomeMove()) {
 | 
			
		||||
            logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
            logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,8 @@
 | 
			
		||||
 | 
			
		||||
public class StartPieceState extends ChoosePieceStates {
 | 
			
		||||
 | 
			
		||||
    private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
 | 
			
		||||
 | 
			
		||||
    private final ChoosePieceState parent;
 | 
			
		||||
    private Piece moveablePiece;
 | 
			
		||||
 | 
			
		||||
@@ -27,7 +29,11 @@ public void enter() {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        moveablePiece = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMoveablePiece(Piece moveablePiece) {
 | 
			
		||||
        this.moveablePiece = moveablePiece;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ public void selectPiece(Piece piece){
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg){
 | 
			
		||||
        Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
 | 
			
		||||
        Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
 | 
			
		||||
        pieceToMove.setState(PieceState.ACTIVE);
 | 
			
		||||
        parent.getParent().setState(parent.getParent().getMovePiece());
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,7 @@ public class Game {
 | 
			
		||||
    /**
 | 
			
		||||
     * The dice modifier.
 | 
			
		||||
     */
 | 
			
		||||
    private int diceModifier;
 | 
			
		||||
    private int diceModifier = 1;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The number of eyes on the dice.
 | 
			
		||||
 
 | 
			
		||||
@@ -49,6 +49,25 @@ public void setOccupant(Piece occupant) {
 | 
			
		||||
        this.occupant = occupant;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method handles the event when a new occupant is moved to the node,
 | 
			
		||||
     * it then returns the old occupant.
 | 
			
		||||
     *
 | 
			
		||||
     * @param newOccupant the new occupant of the node
 | 
			
		||||
     * @return the old occupant of the node
 | 
			
		||||
     */
 | 
			
		||||
    public Piece moveOccupant(Piece newOccupant) {
 | 
			
		||||
        if (occupant == null) {
 | 
			
		||||
            setOccupant(newOccupant);
 | 
			
		||||
            return null;
 | 
			
		||||
        } else {
 | 
			
		||||
            occupant.setShield(ShieldState.NONE);
 | 
			
		||||
            occupant.setState(PieceState.WAITING);
 | 
			
		||||
            setOccupant(newOccupant);
 | 
			
		||||
            return occupant;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is used to clear the node of its occupant
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -152,6 +152,57 @@ public PowerCard getPowerCardByType(BonusCard bonusCard) {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Piece getWaitingPiece(){
 | 
			
		||||
        for (Piece piece : this.waitingArea) {
 | 
			
		||||
            if (piece != null){
 | 
			
		||||
                return piece;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method returns a boolean based on if the Player has a piece in its waiting area
 | 
			
		||||
     *
 | 
			
		||||
     * @return the boolean if the waiting area contains a piece
 | 
			
		||||
     */
 | 
			
		||||
    public boolean hasPieceInWaitingArea(){
 | 
			
		||||
        for (Piece piece : this.waitingArea) {
 | 
			
		||||
            if (piece != null){
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getHomeIndexOfPiece(Piece piece) {
 | 
			
		||||
        for (int i = 0; i < Resources.MAX_PIECES; i++) {
 | 
			
		||||
            if (this.homeNodes[i].getOccupant().equals(piece)) {
 | 
			
		||||
                return i;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean pieceInsideOfHome(Piece piece) {
 | 
			
		||||
        for (Node node : this.homeNodes) {
 | 
			
		||||
            if (node.getOccupant().equals(piece)) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isHomeFinished(Piece piece) {
 | 
			
		||||
        for (int i = getHomeIndexOfPiece(piece); i < Resources.MAX_PIECES; i++) {
 | 
			
		||||
            if (!this.homeNodes[i].isOccupied()) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method returns the give name of the Player
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package pp.mdga.message.client;
 | 
			
		||||
 | 
			
		||||
import com.jme3.network.serializing.Serializable;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
@@ -12,22 +13,22 @@ public class RequestMoveMessage extends ClientMessage {
 | 
			
		||||
    /**
 | 
			
		||||
     * The identifier for the piece.
 | 
			
		||||
     */
 | 
			
		||||
    private final UUID pieceIdentifier;
 | 
			
		||||
    private final Piece piece;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructor for RequestMove
 | 
			
		||||
     *
 | 
			
		||||
     * @param pieceIdentifier the piece identifier
 | 
			
		||||
     * @param piece the piece
 | 
			
		||||
     */
 | 
			
		||||
    public RequestMoveMessage(UUID pieceIdentifier) {
 | 
			
		||||
        this.pieceIdentifier = pieceIdentifier;
 | 
			
		||||
    public RequestMoveMessage(Piece piece) {
 | 
			
		||||
        this.piece = piece;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Default constructor for serialization purposes.
 | 
			
		||||
     */
 | 
			
		||||
    private RequestMoveMessage() {
 | 
			
		||||
        pieceIdentifier = null;
 | 
			
		||||
        piece = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -35,8 +36,8 @@ private RequestMoveMessage() {
 | 
			
		||||
     *
 | 
			
		||||
     * @return the piece identifier
 | 
			
		||||
     */
 | 
			
		||||
    public UUID getPieceIdentifier() {
 | 
			
		||||
        return pieceIdentifier;
 | 
			
		||||
    public Piece getPiece() {
 | 
			
		||||
        return piece;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -46,7 +47,8 @@ public UUID getPieceIdentifier() {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "RequestMove{pieceIdentifier = " + pieceIdentifier + '}';
 | 
			
		||||
        assert piece != null;
 | 
			
		||||
        return "RequestMove{pieceIdentifier = " + piece.toString() + '}';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package pp.mdga.message.server;
 | 
			
		||||
 | 
			
		||||
import com.jme3.network.serializing.Serializable;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
@@ -12,7 +13,7 @@ public class MoveMessage extends ServerMessage {
 | 
			
		||||
    /**
 | 
			
		||||
     * The identifier of the piece that should be moved.
 | 
			
		||||
     */
 | 
			
		||||
    private final UUID pieceUUID;
 | 
			
		||||
    private final Piece piece;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The index of the target node;
 | 
			
		||||
@@ -27,11 +28,13 @@ public class MoveMessage extends ServerMessage {
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a new MoveMessage instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @param identifier the identifier of the piece that should be moved
 | 
			
		||||
     * @param piece the identifier of the piece that should be moved
 | 
			
		||||
     * @param isHomeMove boolean flag declaring home move or not
 | 
			
		||||
     * @param targetIndex the targetIndex
 | 
			
		||||
     */
 | 
			
		||||
    public MoveMessage(UUID identifier, boolean isHomeMove, int targetIndex) {
 | 
			
		||||
    public MoveMessage(Piece piece, boolean isHomeMove, int targetIndex) {
 | 
			
		||||
        super();
 | 
			
		||||
        this.pieceUUID = identifier;
 | 
			
		||||
        this.piece = piece;
 | 
			
		||||
        this.isHomeMove = isHomeMove;
 | 
			
		||||
        this.targetIndex = targetIndex;
 | 
			
		||||
    }
 | 
			
		||||
@@ -41,7 +44,7 @@ public MoveMessage(UUID identifier, boolean isHomeMove, int targetIndex) {
 | 
			
		||||
     */
 | 
			
		||||
    private MoveMessage() {
 | 
			
		||||
        super();
 | 
			
		||||
        pieceUUID = null;
 | 
			
		||||
        piece = null;
 | 
			
		||||
        targetIndex = 0;
 | 
			
		||||
        isHomeMove = false;
 | 
			
		||||
    }
 | 
			
		||||
@@ -51,8 +54,8 @@ private MoveMessage() {
 | 
			
		||||
     *
 | 
			
		||||
     * @return the identifier of the piece that should be moved
 | 
			
		||||
     */
 | 
			
		||||
    public UUID getIdentifier() {
 | 
			
		||||
        return pieceUUID;
 | 
			
		||||
    public Piece getPiece() {
 | 
			
		||||
        return piece;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -90,6 +93,6 @@ public void accept(ServerInterpreter interpreter) {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "MoveMessage{" + "pieceUUID=" + pieceUUID + ", targetIndex=" + targetIndex + ", isHomeMove=" + isHomeMove + '}';
 | 
			
		||||
        return "MoveMessage{" + "pieceUUID=" + piece.getUuid() + ", targetIndex=" + targetIndex + ", isHomeMove=" + isHomeMove + '}';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@
 | 
			
		||||
import com.jme3.network.serializing.Serializable;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A message sent by the server to the active player to select a piece to move.
 | 
			
		||||
@@ -13,7 +13,7 @@ public class SelectPieceMessage extends ServerMessage {
 | 
			
		||||
    /**
 | 
			
		||||
     * The list of pieces
 | 
			
		||||
     */
 | 
			
		||||
    private final List<UUID> pieces;
 | 
			
		||||
    private final List<Piece> pieces;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The list of booleans of isHomeMove of the pieces
 | 
			
		||||
@@ -32,7 +32,7 @@ public class SelectPieceMessage extends ServerMessage {
 | 
			
		||||
     * @param isHomeMove  the List of booleans of isHomeMove of the pieces
 | 
			
		||||
     * @param targetIndex the List of indexes of target nodes of the pieces
 | 
			
		||||
     */
 | 
			
		||||
    public SelectPieceMessage(List<UUID> pieces, List<Boolean> isHomeMove, List<Integer> targetIndex) {
 | 
			
		||||
    public SelectPieceMessage(List<Piece> pieces, List<Boolean> isHomeMove, List<Integer> targetIndex) {
 | 
			
		||||
        super();
 | 
			
		||||
        this.pieces = pieces;
 | 
			
		||||
        this.isHomeMove = isHomeMove;
 | 
			
		||||
@@ -54,7 +54,7 @@ public SelectPieceMessage() {
 | 
			
		||||
     *
 | 
			
		||||
     * @return the pieces
 | 
			
		||||
     */
 | 
			
		||||
    public List<UUID> getPieces() {
 | 
			
		||||
    public List<Piece> getPieces() {
 | 
			
		||||
        return pieces;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,6 @@
 | 
			
		||||
package pp.mdga.server.automaton;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.AnimationEndMessage;
 | 
			
		||||
import pp.mdga.message.client.DisconnectedMessage;
 | 
			
		||||
import pp.mdga.message.client.LeaveGameMessage;
 | 
			
		||||
import pp.mdga.message.client.RequestDieMessage;
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.message.server.CeremonyMessage;
 | 
			
		||||
import pp.mdga.message.server.PauseGameMessage;
 | 
			
		||||
import pp.mdga.server.automaton.game.AnimationState;
 | 
			
		||||
@@ -88,6 +85,15 @@ public void received(LeaveGameMessage msg, int from) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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.
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,6 @@ public void received(AnimationEndMessage msg, int from) {
 | 
			
		||||
        this.messageReceived.add(from);
 | 
			
		||||
        if (this.messageReceived.size() == this.logic.getGame().getPlayers().size()) {
 | 
			
		||||
            this.gameAutomaton.setCurrentState(this.gameAutomaton.getTurnState());
 | 
			
		||||
            this.gameAutomaton.getTurnState().setCurrentState(this.gameAutomaton.getTurnState().getPowerCardState());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -79,9 +79,6 @@ else if (maximumRoll < entry.getValue()) {
 | 
			
		||||
                    this.playersHaveToRoll.clear();
 | 
			
		||||
                    this.playersHaveToRoll.add(entry.getKey());
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    this.logic.getServerSender().send(entry.getKey(), new EndOfTurnMessage());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            for (int id: this.playersHaveToRoll) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,7 @@
 | 
			
		||||
package pp.mdga.server.automaton.game;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.NoPowerCardMessage;
 | 
			
		||||
import pp.mdga.message.client.RequestDieMessage;
 | 
			
		||||
import pp.mdga.message.client.RequestMoveMessage;
 | 
			
		||||
import pp.mdga.message.client.SelectedPiecesMessage;
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.GameState;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
 | 
			
		||||
@@ -111,6 +108,15 @@ public void received(RequestMoveMessage msg, int from) {
 | 
			
		||||
        this.currentState.received(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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.
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -34,17 +34,17 @@ public ChoosePieceState(TurnState turnAutomaton, ServerGameLogic logic) {
 | 
			
		||||
        this.waitingPieceState = new WaitingPieceState(this, logic);
 | 
			
		||||
        this.startPieceState = new StartPieceState(this, logic);
 | 
			
		||||
        this.selectPieceState = new SelectPieceState(this, logic);
 | 
			
		||||
        this.setCurrentState(this.noPieceState);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited ChoosePieceState state.");
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered ChoosePieceState state.");
 | 
			
		||||
        this.setCurrentState(this.noPieceState);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered ChoosePieceState state.");
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited ChoosePieceState state.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,24 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.AnimationEndMessage;
 | 
			
		||||
import pp.mdga.message.server.ActivePlayerMessage;
 | 
			
		||||
import pp.mdga.message.server.DiceNowMessage;
 | 
			
		||||
import pp.mdga.message.server.EndOfTurnMessage;
 | 
			
		||||
import pp.mdga.message.server.SpectatorMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.TurnState;
 | 
			
		||||
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
public class MovePieceState extends TurnAutomatonState {
 | 
			
		||||
    /**
 | 
			
		||||
     * Create LobbyState constants.
 | 
			
		||||
     */
 | 
			
		||||
    private static final System.Logger LOGGER = System.getLogger(MovePieceState.class.getName());
 | 
			
		||||
    private Set<Player> finishedAnimations = new HashSet<>();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a server state of the specified game logic.
 | 
			
		||||
@@ -24,8 +35,34 @@ public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered MovePieceState state.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setActivePlayer(Color color) {
 | 
			
		||||
        if (!logic.getGame().getPlayerByColor(color.next()).isFinished()) {
 | 
			
		||||
            logic.getGame().setActiveColor(logic.getGame().getActiveColor().next());
 | 
			
		||||
            logic.getServerSender().broadcast(new ActivePlayerMessage(color.next()));
 | 
			
		||||
        } else {
 | 
			
		||||
            setActivePlayer(color.next());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(AnimationEndMessage msg, int from){
 | 
			
		||||
        finishedAnimations.add(logic.getGame().getPlayerById(from));
 | 
			
		||||
        if (finishedAnimations.size() == logic.getGame().getPlayers().size()) {
 | 
			
		||||
            if (logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).isFinished()){
 | 
			
		||||
                logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new SpectatorMessage());
 | 
			
		||||
                setActivePlayer(logic.getGame().getActiveColor());
 | 
			
		||||
            } else if (logic.getGame().getDiceEyes() == 6){
 | 
			
		||||
                logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new DiceNowMessage());
 | 
			
		||||
            } else {
 | 
			
		||||
                logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new EndOfTurnMessage());
 | 
			
		||||
                setActivePlayer(logic.getGame().getActiveColor());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        finishedAnimations.clear();
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited MovePieceState state.");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,8 @@
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
@@ -51,12 +53,12 @@ public PowerCardState(TurnState turnAutomaton, ServerGameLogic logic) {
 | 
			
		||||
        this.shieldCardState = new ShieldCardState(this, logic);
 | 
			
		||||
        this.swapCardState = new SwapCardState(this, logic);
 | 
			
		||||
        this.turboCardState = new TurboCardState(this, logic);
 | 
			
		||||
        this.setCurrentState(this.choosePowerCardState);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited PowerCardState state.");
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Enter PowerCardState state.");
 | 
			
		||||
        this.setCurrentState(this.choosePowerCardState);
 | 
			
		||||
        this.visitor = new ServerCardVisitor(this.logic);
 | 
			
		||||
        for (PowerCard card : this.turnAutomaton.getPlayer().getHandCards()) {
 | 
			
		||||
            card.accept(this.visitor);
 | 
			
		||||
@@ -73,7 +75,12 @@ public void enter() {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered PowerCardState state.");
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exit PowerCardState state.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(NoPowerCardMessage msg, int form){
 | 
			
		||||
        currentState.received(msg, form);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -86,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.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.AnimationEndMessage;
 | 
			
		||||
import pp.mdga.message.client.RequestDieMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.TurnState;
 | 
			
		||||
@@ -33,12 +34,12 @@ public RollDiceState(TurnState turnAutomaton, ServerGameLogic logic) {
 | 
			
		||||
        this.firstRollState = new FirstRollState(this, logic);
 | 
			
		||||
        this.secondRollState = new SecondRollState(this, logic);
 | 
			
		||||
        this.thirdRollState = new ThirdRollState(this, logic);
 | 
			
		||||
        this.setCurrentState(this.firstRollState);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered RollDiceState state.");
 | 
			
		||||
        this.setCurrentState(this.firstRollState);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -58,6 +59,11 @@ public void received(RequestDieMessage msg, int from) {
 | 
			
		||||
        this.currentState.received(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(AnimationEndMessage msg, int from){
 | 
			
		||||
        this.currentState.received(msg, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method will be used to return currentState attribute of RollDiceState class.
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn.choosepiece;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.*;
 | 
			
		||||
import pp.mdga.message.client.AnimationEndMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.ServerState;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
 | 
			
		||||
@@ -20,4 +22,76 @@ public ChoosePieceAutomatonState(ChoosePieceState choosePieceAutomaton, ServerGa
 | 
			
		||||
        super(logic);
 | 
			
		||||
        this.choosePieceAutomaton = choosePieceAutomaton;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected boolean canMove(Piece piece){
 | 
			
		||||
        int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
 | 
			
		||||
        if (piece.getState().equals(PieceState.HOME)){
 | 
			
		||||
            return canHomeMove(piece, steps);
 | 
			
		||||
        } else {
 | 
			
		||||
            int homeMoves = getHomeMoves(piece, steps);
 | 
			
		||||
            if (homeMoves > 0){
 | 
			
		||||
                return canHomeMove(piece, homeMoves);
 | 
			
		||||
            } else {
 | 
			
		||||
                return canInfieldMove(piece, steps);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
   protected int getHomeMoves(Piece piece, int steps){
 | 
			
		||||
        int pieceIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
 | 
			
		||||
        Color color = piece.getColor();
 | 
			
		||||
        int startIndex = logic.getGame().getPlayerByColor(color).getStartNodeIndex();
 | 
			
		||||
        int moveIndex = pieceIndex + steps;
 | 
			
		||||
        if (moveIndex > logic.getGame().getBoard().getInfield().length){
 | 
			
		||||
            if (startIndex > pieceIndex){
 | 
			
		||||
                return steps - (startIndex - pieceIndex -1);
 | 
			
		||||
            }
 | 
			
		||||
            moveIndex %= logic.getGame().getBoard().getInfield().length;
 | 
			
		||||
            if (moveIndex >= startIndex){
 | 
			
		||||
                return moveIndex - startIndex + 1;
 | 
			
		||||
            }
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        if (pieceIndex < startIndex && startIndex <= moveIndex){
 | 
			
		||||
            return moveIndex - startIndex + 1;
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean canInfieldMove(Piece piece, int steps){
 | 
			
		||||
        int pieceIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
 | 
			
		||||
        int moveIndex = (pieceIndex + steps) % logic.getGame().getBoard().getInfield().length;
 | 
			
		||||
        Piece occupant = logic.getGame().getBoard().getInfield()[moveIndex].getOccupant();
 | 
			
		||||
        if (occupant != null){
 | 
			
		||||
            return occupant.getColor() != piece.getColor();
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean canHomeMove(Piece piece, int moveIndex){
 | 
			
		||||
        Color color = piece.getColor();
 | 
			
		||||
        Player player = logic.getGame().getPlayerByColor(color);
 | 
			
		||||
        Node[] homeNodes = player.getHomeNodes();
 | 
			
		||||
        int index;
 | 
			
		||||
        if (player.pieceInsideOfHome(piece)){
 | 
			
		||||
            index = player.getHomeIndexOfPiece(piece);
 | 
			
		||||
        } else {
 | 
			
		||||
            index = 0;
 | 
			
		||||
        }
 | 
			
		||||
        if  (index + moveIndex >= homeNodes.length){
 | 
			
		||||
            return false;
 | 
			
		||||
        } else {
 | 
			
		||||
            for (int i = index; i <= index + moveIndex; i++){
 | 
			
		||||
                if(homeNodes[i].isOccupied()){
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected int calculateTargetIndex(Piece piece){
 | 
			
		||||
        int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
 | 
			
		||||
        return (logic.getGame().getBoard().getInfieldIndexOfPiece(piece) + steps) % logic.getGame().getBoard().getInfield().length;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,13 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn.choosepiece;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.Resources;
 | 
			
		||||
import pp.mdga.game.*;
 | 
			
		||||
import pp.mdga.message.client.AnimationEndMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class NoPieceState extends ChoosePieceAutomatonState {
 | 
			
		||||
    /**
 | 
			
		||||
     * Create FirstRollState constants.
 | 
			
		||||
@@ -19,12 +24,57 @@ public NoPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic
 | 
			
		||||
        super(choosePieceAutomaton, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void initialize(){
 | 
			
		||||
        Player activePlayer = logic.getGame().getPlayerByColor(logic.getGame().getActiveColor());
 | 
			
		||||
        if(logic.getGame().getDiceModifier() == 0){
 | 
			
		||||
            if (logic.getGame().getDiceEyes() == 6) {
 | 
			
		||||
                if (activePlayer.hasPieceInWaitingArea()){
 | 
			
		||||
                    if (!logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].isOccupied(activePlayer.getColor())){
 | 
			
		||||
                       this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getWaitingPieceState());
 | 
			
		||||
                    }
 | 
			
		||||
                    this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
 | 
			
		||||
                }
 | 
			
		||||
                this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
 | 
			
		||||
            }
 | 
			
		||||
        } else if (activePlayer.hasPieceInWaitingArea()) {
 | 
			
		||||
            if (!logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].isOccupied(activePlayer.getColor())){
 | 
			
		||||
                if (logic.getGame().getDiceEyes() == 6) {
 | 
			
		||||
                    this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getWaitingPieceState());
 | 
			
		||||
                } else {
 | 
			
		||||
                    checkSelectPiece(activePlayer);
 | 
			
		||||
                }
 | 
			
		||||
            } else if (canMove(logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].getOccupant())){
 | 
			
		||||
                this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getStartPieceState());
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            checkSelectPiece(activePlayer);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void checkSelectPiece(Player activePlayer){
 | 
			
		||||
        ArrayList<Piece> moveablePieces = new ArrayList<>();
 | 
			
		||||
        for (Piece piece : activePlayer.getPieces()){
 | 
			
		||||
            if (piece.getState().equals(PieceState.ACTIVE) || piece.getState().equals(PieceState.HOME)){
 | 
			
		||||
                moveablePieces.add(piece);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        moveablePieces.removeIf(piece -> !canMove(piece));
 | 
			
		||||
        if (moveablePieces.isEmpty()) {
 | 
			
		||||
            this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
 | 
			
		||||
        } else {
 | 
			
		||||
            this.choosePieceAutomaton.getSelectPieceState().setMoveablePieces(moveablePieces);
 | 
			
		||||
            this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getSelectPieceState());
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method will be used whenever this state will be entered.
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered NoPieceState state.");
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Entered NoPieceState state.");
 | 
			
		||||
        initialize();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,8 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn.choosepiece;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.message.server.ActivePlayerMessage;
 | 
			
		||||
import pp.mdga.message.server.EndOfTurnMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
 | 
			
		||||
 | 
			
		||||
@@ -19,12 +22,23 @@ public NoTurnState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic)
 | 
			
		||||
        super(choosePieceAutomaton, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setActivePlayer(Color color) {
 | 
			
		||||
        if (!logic.getGame().getPlayerByColor(color.next()).isFinished()) {
 | 
			
		||||
            logic.getGame().setActiveColor(logic.getGame().getActiveColor().next());
 | 
			
		||||
            logic.getServerSender().broadcast(new ActivePlayerMessage(color.next()));
 | 
			
		||||
        } else {
 | 
			
		||||
            setActivePlayer(color.next());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method will be used whenever this state will be entered.
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered NoTurnState state.");
 | 
			
		||||
        logic.getServerSender().send(logic.getGame().getActivePlayerId(), new EndOfTurnMessage());
 | 
			
		||||
        setActivePlayer(logic.getGame().getActiveColor());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,26 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn.choosepiece;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.PieceState;
 | 
			
		||||
import pp.mdga.game.ShieldState;
 | 
			
		||||
import pp.mdga.message.client.RequestMoveMessage;
 | 
			
		||||
import pp.mdga.message.server.MoveMessage;
 | 
			
		||||
import pp.mdga.message.server.SelectPieceMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class SelectPieceState extends ChoosePieceAutomatonState {
 | 
			
		||||
    /**
 | 
			
		||||
     * Create FirstRollState constants.
 | 
			
		||||
     */
 | 
			
		||||
    private static final System.Logger LOGGER = System.getLogger(SelectPieceState.class.getName());
 | 
			
		||||
 | 
			
		||||
    private ArrayList<Piece> moveablePieces = new ArrayList<>();
 | 
			
		||||
    private final ArrayList<Boolean> isHomeMove = new ArrayList<>();
 | 
			
		||||
    private final ArrayList<Integer> targetIndex = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a server state of the specified game logic.
 | 
			
		||||
     *
 | 
			
		||||
@@ -19,12 +31,51 @@ public SelectPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic l
 | 
			
		||||
        super(choosePieceAutomaton, logic);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMoveablePieces(ArrayList<Piece> moveablePieces) {
 | 
			
		||||
        this.moveablePieces = moveablePieces;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method will be used whenever this state will be entered.
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered SelectPieceState state.");
 | 
			
		||||
        int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
 | 
			
		||||
        for (Piece piece : moveablePieces) {
 | 
			
		||||
            int homeMoves =  getHomeMoves(piece, steps);
 | 
			
		||||
            if (homeMoves > 0) {
 | 
			
		||||
                isHomeMove.add(true);
 | 
			
		||||
                targetIndex.add(homeMoves);
 | 
			
		||||
            } else {
 | 
			
		||||
                isHomeMove.add(false);
 | 
			
		||||
                targetIndex.add(calculateTargetIndex(piece));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        logic.getServerSender().send(logic.getGame().getActivePlayerId(), new SelectPieceMessage(moveablePieces, isHomeMove, targetIndex));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestMoveMessage msg, int from){
 | 
			
		||||
        if (moveablePieces.contains(msg.getPiece())) {
 | 
			
		||||
            int indexOfPiece = moveablePieces.indexOf(msg.getPiece());
 | 
			
		||||
            if (isHomeMove.get(indexOfPiece)) {
 | 
			
		||||
                logic.getGame().getPlayerByColor(msg.getPiece().getColor()).setPieceInHome(targetIndex.get(indexOfPiece), logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()));
 | 
			
		||||
                if (logic.getGame().getPlayerByColor(msg.getPiece().getColor()).isHomeFinished(logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()))) {
 | 
			
		||||
                    logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()).setState(PieceState.HOMEFINISHED);
 | 
			
		||||
                } else {
 | 
			
		||||
                    logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()).setState(PieceState.HOME);
 | 
			
		||||
                }
 | 
			
		||||
                logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()).setShield(ShieldState.NONE);
 | 
			
		||||
            } else {
 | 
			
		||||
                Piece occ = logic.getGame().getBoard().getInfield()[targetIndex.get(indexOfPiece)].moveOccupant(moveablePieces.get(indexOfPiece));
 | 
			
		||||
                if (occ != null) {
 | 
			
		||||
                    logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            logic.getServerSender().broadcast(new MoveMessage(moveablePieces.get(indexOfPiece), isHomeMove.get(indexOfPiece), targetIndex.get(indexOfPiece)));
 | 
			
		||||
            this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -33,5 +84,8 @@ public void enter() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited SelectPieceState state.");
 | 
			
		||||
        moveablePieces.clear();
 | 
			
		||||
        isHomeMove.clear();
 | 
			
		||||
        targetIndex.clear();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,9 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn.choosepiece;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.message.client.RequestMoveMessage;
 | 
			
		||||
import pp.mdga.message.server.MoveMessage;
 | 
			
		||||
import pp.mdga.message.server.StartPieceMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
 | 
			
		||||
 | 
			
		||||
@@ -9,6 +13,8 @@ public class StartPieceState extends ChoosePieceAutomatonState {
 | 
			
		||||
     */
 | 
			
		||||
    private static final System.Logger LOGGER = System.getLogger(StartPieceState.class.getName());
 | 
			
		||||
 | 
			
		||||
    private Piece piece;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a server state of the specified game logic.
 | 
			
		||||
     *
 | 
			
		||||
@@ -25,6 +31,20 @@ public StartPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic lo
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited StartPieceState state.");
 | 
			
		||||
        piece = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].getOccupant();
 | 
			
		||||
        logic.getServerSender().send(logic.getGame().getActivePlayerId(), new StartPieceMessage(piece.getUuid(), calculateTargetIndex(piece)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestMoveMessage msg, int from){
 | 
			
		||||
        if (piece.equals(msg.getPiece())) {
 | 
			
		||||
            Piece occ = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(piece.getColor()).getStartNodeIndex()].getOccupant();
 | 
			
		||||
            if (occ != null){
 | 
			
		||||
                logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
 | 
			
		||||
            }
 | 
			
		||||
            logic.getServerSender().broadcast(new MoveMessage(piece, false, calculateTargetIndex(piece)));
 | 
			
		||||
            this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -33,5 +53,6 @@ public void enter() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered StartPieceState state.");
 | 
			
		||||
        piece = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,11 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn.choosepiece;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.PieceState;
 | 
			
		||||
import pp.mdga.game.ShieldState;
 | 
			
		||||
import pp.mdga.message.client.RequestMoveMessage;
 | 
			
		||||
import pp.mdga.message.server.MoveMessage;
 | 
			
		||||
import pp.mdga.message.server.WaitPieceMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.rolldice.FirstRollState;
 | 
			
		||||
@@ -9,6 +15,7 @@ public class WaitingPieceState extends ChoosePieceAutomatonState {
 | 
			
		||||
     * Create FirstRollState constants.
 | 
			
		||||
     */
 | 
			
		||||
    private static final System.Logger LOGGER = System.getLogger(WaitingPieceState.class.getName());
 | 
			
		||||
    private Piece piece;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a server state of the specified game logic.
 | 
			
		||||
@@ -26,6 +33,21 @@ public WaitingPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered WaitingPieceState state.");
 | 
			
		||||
        this.piece = logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getWaitingPiece();
 | 
			
		||||
        logic.getServerSender().send(logic.getGame().getActivePlayerId(), new WaitPieceMessage(this.piece.getUuid()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestMoveMessage msg, int from){
 | 
			
		||||
        if (msg.getPiece().equals(this.piece)) {
 | 
			
		||||
            piece.setState(PieceState.ACTIVE);
 | 
			
		||||
            Piece thrownOcc = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].moveOccupant(this.piece);
 | 
			
		||||
            if (thrownOcc != null) {
 | 
			
		||||
                logic.getGame().getPlayerByColor(thrownOcc.getColor()).addWaitingPiece(thrownOcc);
 | 
			
		||||
            }
 | 
			
		||||
            logic.getServerSender().broadcast(new MoveMessage(this.piece, false, logic.getGame().getPlayerById(logic.getGame().getActivePlayerId()).getStartNodeIndex()));
 | 
			
		||||
            this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -34,5 +56,6 @@ public void enter() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited WaitingPieceState state.");
 | 
			
		||||
        piece = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,13 +4,18 @@
 | 
			
		||||
import pp.mdga.game.card.ShieldCard;
 | 
			
		||||
import pp.mdga.game.card.SwapCard;
 | 
			
		||||
import pp.mdga.game.card.TurboCard;
 | 
			
		||||
import pp.mdga.message.client.NoPowerCardMessage;
 | 
			
		||||
import pp.mdga.message.client.SelectCardMessage;
 | 
			
		||||
import pp.mdga.message.server.DiceNowMessage;
 | 
			
		||||
import pp.mdga.message.server.IncorrectRequestMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
 | 
			
		||||
import pp.mdga.visitor.Visitor;
 | 
			
		||||
 | 
			
		||||
public class ChoosePowerCardState extends PowerCardAutomatonState implements Visitor {
 | 
			
		||||
 | 
			
		||||
    private static final System.Logger LOGGER = System.getLogger(ChoosePowerCardState.class.getName());
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a server state of the specified game logic.
 | 
			
		||||
     *
 | 
			
		||||
@@ -26,7 +31,7 @@ public ChoosePowerCardState(PowerCardState powerCardAutomaton, ServerGameLogic l
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Entered ChoosePowerCard state.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -47,6 +52,12 @@ public void received(SelectCardMessage msg, int from) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(NoPowerCardMessage msg, int from) {
 | 
			
		||||
        this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getRollDiceState());
 | 
			
		||||
        logic.getServerSender().send(from, new DiceNowMessage());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method will be used to change the state of the power card automaton depending on the given card parameter.
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -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()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -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()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,8 +3,10 @@
 | 
			
		||||
import pp.mdga.Resources;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.PieceState;
 | 
			
		||||
import pp.mdga.message.client.AnimationEndMessage;
 | 
			
		||||
import pp.mdga.message.client.RequestDieMessage;
 | 
			
		||||
import pp.mdga.message.server.DiceAgainMessage;
 | 
			
		||||
import pp.mdga.message.server.DiceNowMessage;
 | 
			
		||||
import pp.mdga.message.server.DieMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
 | 
			
		||||
@@ -17,6 +19,8 @@ public class FirstRollState extends RollDiceAutomatonState {
 | 
			
		||||
     * Create FirstRollState constants.
 | 
			
		||||
     */
 | 
			
		||||
    private static final System.Logger LOGGER = System.getLogger(FirstRollState.class.getName());
 | 
			
		||||
    private List<Piece> moveablePieces;
 | 
			
		||||
    private int roll;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a server state of the specified game logic.
 | 
			
		||||
@@ -30,12 +34,19 @@ public FirstRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered FirstRollState state.");
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
 | 
			
		||||
        roll = 0;
 | 
			
		||||
        moveablePieces = new ArrayList<>();
 | 
			
		||||
        for (Piece piece : this.rollDiceAutomaton.getTurnAutomaton().getPlayer().getPieces()) {
 | 
			
		||||
            if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
 | 
			
		||||
                moveablePieces.add(piece);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited FirstRollState state.");
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Exited FirstRollState state.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -47,25 +58,19 @@ public void exit() {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestDieMessage msg, int from) {
 | 
			
		||||
        List<Piece> moveablePieces = new ArrayList<>();
 | 
			
		||||
        for (Piece piece : this.rollDiceAutomaton.getTurnAutomaton().getPlayer().getPieces()) {
 | 
			
		||||
            if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
 | 
			
		||||
                moveablePieces.add(piece);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int roll = this.logic.getGame().getDie().shuffle();
 | 
			
		||||
        roll = this.logic.getGame().getDie().shuffle();
 | 
			
		||||
        this.logic.getGame().setDiceEyes(roll);
 | 
			
		||||
        this.logic.getServerSender().broadcast(new DieMessage(roll));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(AnimationEndMessage msg, int from) {
 | 
			
		||||
        if (!moveablePieces.isEmpty()) {
 | 
			
		||||
            this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
 | 
			
		||||
            this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
 | 
			
		||||
        } else {
 | 
			
		||||
            if (roll == Resources.MAX_EYES) {
 | 
			
		||||
                this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
 | 
			
		||||
                this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
 | 
			
		||||
            } else {
 | 
			
		||||
                this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceAgainMessage());
 | 
			
		||||
                this.rollDiceAutomaton.setCurrentState(this.rollDiceAutomaton.getSecondRollState());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.RequestDieMessage;
 | 
			
		||||
import pp.mdga.message.server.DiceAgainMessage;
 | 
			
		||||
import pp.mdga.message.server.DiceNowMessage;
 | 
			
		||||
import pp.mdga.message.server.DieMessage;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
 | 
			
		||||
@@ -24,6 +25,7 @@ public SecondRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage());
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered SecondRollState state.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -42,11 +44,10 @@ public void exit() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestDieMessage msg, int from) {
 | 
			
		||||
        int roll = this.logic.getGame().getDie().shuffle();
 | 
			
		||||
        this.logic.getServerSender().broadcast(new DieMessage(roll));
 | 
			
		||||
        if (roll == 6) {
 | 
			
		||||
            this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
 | 
			
		||||
            this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
 | 
			
		||||
        } else {
 | 
			
		||||
            this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceAgainMessage());
 | 
			
		||||
            this.rollDiceAutomaton.setCurrentState(this.rollDiceAutomaton.getThirdRollState());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,7 @@
 | 
			
		||||
package pp.mdga.server.automaton.game.turn.rolldice;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.message.client.RequestDieMessage;
 | 
			
		||||
import pp.mdga.message.server.ActivePlayerMessage;
 | 
			
		||||
import pp.mdga.message.server.CeremonyMessage;
 | 
			
		||||
import pp.mdga.message.server.DieMessage;
 | 
			
		||||
import pp.mdga.message.server.NoTurnMessage;
 | 
			
		||||
import pp.mdga.message.server.SpectatorMessage;
 | 
			
		||||
import pp.mdga.message.server.*;
 | 
			
		||||
import pp.mdga.server.ServerGameLogic;
 | 
			
		||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
 | 
			
		||||
 | 
			
		||||
@@ -27,6 +23,7 @@ public ThirdRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage());
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Exited ThirdRollState state.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -45,8 +42,8 @@ public void exit() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RequestDieMessage msg, int from) {
 | 
			
		||||
        int roll = this.logic.getGame().getDie().shuffle();
 | 
			
		||||
        this.logic.getServerSender().broadcast(new DieMessage(roll));
 | 
			
		||||
        if (roll == 6) {
 | 
			
		||||
            this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
 | 
			
		||||
            this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
 | 
			
		||||
        } else {
 | 
			
		||||
            this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new NoTurnMessage());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user