fixed bug when moving pieces from waiting to infield for non active players
This commit is contained in:
@@ -4,11 +4,9 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.GameState;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.message.server.*;
|
||||
import pp.mdga.notification.ActivePlayerNotification;
|
||||
import pp.mdga.notification.HomeMoveNotification;
|
||||
import pp.mdga.notification.MovePieceNotification;
|
||||
import pp.mdga.notification.PlayCardNotification;
|
||||
import pp.mdga.notification.*;
|
||||
|
||||
public class SpectatorState extends GameStates {
|
||||
|
||||
@@ -62,24 +60,32 @@ public void received(ActivePlayerMessage msg) {
|
||||
|
||||
@Override
|
||||
public void received(MoveMessage msg) {
|
||||
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
Piece piece = 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();
|
||||
logic.getGame().getPlayerByColor(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove);
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||
} else {
|
||||
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) {
|
||||
throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant());
|
||||
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown();
|
||||
logic.getGame().getGameStatistics().increasePiecesThrown();
|
||||
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
|
||||
if (occ != null) {
|
||||
//TODO: MoveThrowNotification
|
||||
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
|
||||
//set occ to waiting
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
}
|
||||
if (logic.getGame().getPlayerByColor(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)) {
|
||||
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true));
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove);
|
||||
if(msg.getPiece().getState().equals(PieceState.WAITING)){
|
||||
logic.addNotification(new MovePieceNotification(piece.getUuid(), msg.getTargetIndex(), true));
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).removeWaitingPiece(piece);
|
||||
piece.setState(PieceState.ACTIVE);
|
||||
} else {
|
||||
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove);
|
||||
logic.addNotification(new MovePieceNotification(piece.getUuid(), oldIndex, msg.getTargetIndex()));
|
||||
//clear old node
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
}
|
||||
//set new node
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
|
||||
}
|
||||
parent.setState(parent.getAnimation());
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ public void received(ActivePlayerMessage msg) {
|
||||
@Override
|
||||
public void received(MoveMessage msg) {
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
//logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
if (msg.isHomeMove()) {
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
@@ -79,16 +78,21 @@ public void received(MoveMessage msg) {
|
||||
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
|
||||
//logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
|
||||
if (occ != null) {
|
||||
//TODO: MoveThrowNotification
|
||||
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
|
||||
//set occ to waiting
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
}
|
||||
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), oldIndex, msg.getTargetIndex()));
|
||||
//clear old node
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
if(msg.getPiece().getState().equals(PieceState.WAITING)){
|
||||
logic.addNotification(new MovePieceNotification(piece.getUuid(), msg.getTargetIndex(), true));
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).removeWaitingPiece(piece);
|
||||
piece.setState(PieceState.ACTIVE);
|
||||
} else {
|
||||
logic.addNotification(new MovePieceNotification(piece.getUuid(), oldIndex, msg.getTargetIndex()));
|
||||
//clear old node
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
}
|
||||
//set new node
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user