fixed bugs in MoveMessage
This commit is contained in:
		@@ -61,6 +61,8 @@ public void update() {
 | 
			
		||||
                    case NONE:
 | 
			
		||||
                        throw new RuntimeException("no notification expected: " + n.getClass().getName());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                delay = 0;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -51,7 +51,8 @@ protected void controlUpdate(float tpf) {
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                // Stop rolling when angular velocity is close to zero
 | 
			
		||||
                if (angularVelocity.lengthSquared() < 3f) {
 | 
			
		||||
//                if (angularVelocity.lengthSquared() < 3f) {
 | 
			
		||||
                if(true){
 | 
			
		||||
                    slerp = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -65,7 +66,8 @@ protected void controlUpdate(float tpf) {
 | 
			
		||||
                spatial.setLocalRotation(interpolated);
 | 
			
		||||
 | 
			
		||||
                // Stop rolling once duration is complete
 | 
			
		||||
                if (timeElapsed >= 1.0f) {
 | 
			
		||||
//                if (timeElapsed >= 1.0f) {
 | 
			
		||||
                if(true){
 | 
			
		||||
                    isRolling = false;
 | 
			
		||||
                    slerp = false;
 | 
			
		||||
                    actionAfter.run();
 | 
			
		||||
 
 | 
			
		||||
@@ -152,7 +152,6 @@ public void received(RankingResponseMessage msg){
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(SelectPieceMessage msg){
 | 
			
		||||
        System.out.println("SelectPieceMessage received in GameState");
 | 
			
		||||
        state.received(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -70,7 +70,6 @@ public void selectAnimationEnd(){
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(SelectPieceMessage msg){
 | 
			
		||||
        System.out.println("SelectPieceMessage received in TurnState");
 | 
			
		||||
        state.received(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,6 @@ public void selectPiece(Piece piece){
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(SelectPieceMessage msg){
 | 
			
		||||
        System.out.println("SelectPieceMessage received in ChoosePieceState");
 | 
			
		||||
        currentState.received(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,12 +26,11 @@ public SelectPieceState(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        possiblePieces = new ArrayList<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
 | 
			
		||||
        possiblePieces = new ArrayList<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
 | 
			
		||||
import pp.mdga.game.Node;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.message.client.RequestMoveMessage;
 | 
			
		||||
import pp.mdga.message.client.SelectedPiecesMessage;
 | 
			
		||||
@@ -49,17 +50,21 @@ public void selectPiece(Piece piece){
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg){
 | 
			
		||||
        Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
 | 
			
		||||
        int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
 | 
			
		||||
        LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i);
 | 
			
		||||
        int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
 | 
			
		||||
        int targetIndex = msg.getTargetIndex();
 | 
			
		||||
        Node targetNode = logic.getGame().getBoard().getInfield()[targetIndex];
 | 
			
		||||
        //clear old Node
 | 
			
		||||
        logic.getGame().getBoard().getInfield()[oldIndex].clearOccupant();
 | 
			
		||||
 | 
			
		||||
        Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
 | 
			
		||||
        //get Occupant
 | 
			
		||||
        Piece occ = targetNode.getOccupant();
 | 
			
		||||
        if (occ != null){
 | 
			
		||||
            logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
 | 
			
		||||
            logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), i, msg.getTargetIndex()));
 | 
			
		||||
        logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(msg.getPiece());
 | 
			
		||||
        targetNode.setOccupant(msg.getPiece());
 | 
			
		||||
        logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), oldIndex, targetIndex));
 | 
			
		||||
 | 
			
		||||
        parent.getParent().setState(parent.getParent().getMovePiece());
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -63,28 +63,33 @@ public void received(RequestMoveMessage msg, int from){
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int indexOfPiece = moveablePieces.indexOf(msg.getPiece());
 | 
			
		||||
        logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(moveablePieces.get(indexOfPiece))].clearOccupant();
 | 
			
		||||
        if (isHomeMove.get(indexOfPiece)) {
 | 
			
		||||
            logic.getGame().getPlayerByColor(msg.getPiece().getColor()).setPieceInHome(targetIndex.get(indexOfPiece), logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()));
 | 
			
		||||
        Piece movePiece = moveablePieces.get(indexOfPiece);
 | 
			
		||||
        boolean homeMove = isHomeMove.get(indexOfPiece);
 | 
			
		||||
        int targIdx = targetIndex.get(indexOfPiece);
 | 
			
		||||
 | 
			
		||||
        Node oldNode = logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(movePiece)];
 | 
			
		||||
        oldNode.clearOccupant();
 | 
			
		||||
        if (homeMove) {
 | 
			
		||||
            //setPieceInHome
 | 
			
		||||
            logic.getGame().getPlayerByColor(msg.getPiece().getColor()).setPieceInHome(targIdx, movePiece);
 | 
			
		||||
 | 
			
		||||
            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);
 | 
			
		||||
                movePiece.setState(PieceState.HOMEFINISHED);
 | 
			
		||||
            }
 | 
			
		||||
            logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()).setShield(ShieldState.NONE);
 | 
			
		||||
            else {
 | 
			
		||||
                movePiece.setState(PieceState.HOME);
 | 
			
		||||
            }
 | 
			
		||||
            movePiece.setShield(ShieldState.NONE);
 | 
			
		||||
        } else {
 | 
			
		||||
            Node targetNode = logic.getGame().getBoard().getInfield()[targetIndex.get(indexOfPiece)];
 | 
			
		||||
            Node targetNode = logic.getGame().getBoard().getInfield()[targIdx];
 | 
			
		||||
            Piece occ = targetNode.getOccupant();
 | 
			
		||||
//                Piece occ = logic.getGame().getBoard().getInfield()[targetIndex.get(indexOfPiece)].moveOccupant(moveablePieces.get(indexOfPiece));
 | 
			
		||||
            if (occ != null) {
 | 
			
		||||
                logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            targetNode.setOccupant(msg.getPiece());
 | 
			
		||||
        }
 | 
			
		||||
        logic.getServerSender().broadcast(new MoveMessage(moveablePieces.get(indexOfPiece), isHomeMove.get(indexOfPiece), targetIndex.get(indexOfPiece)));
 | 
			
		||||
        logic.getServerSender().broadcast(new MoveMessage(movePiece, homeMove, targIdx));
 | 
			
		||||
        this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user