Fix lobby in serverAutomaton and adjust TskUpdateMessage

This commit is contained in:
Felix Koppe
2024-12-02 11:48:54 +01:00
parent 206cad2f79
commit bb1b721e77
9 changed files with 351 additions and 81 deletions

View File

@@ -239,6 +239,10 @@ public void selectTsk(Color color){
state.selectTSK(color);
}
public void deselectTSK(Color color){
state.deselectTSK(color);
}
public void selectDice(){
state.selectDice();
}

View File

@@ -101,9 +101,13 @@ public void received(LobbyPlayerJoinedMessage msg){
@Override
public void received(UpdateTSKMessage msg){
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
if(msg.isTaken()) {
logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), parent.getOwnPlayerId()== msg.getId()));
} else {
logic.addNotification(new TskUnselectNotification(logic.getGame().getPlayers().get(msg.getId()).getColor()));
}
logic.getGame().getPlayers().get(msg.getId()).setColor(msg.getColor());
logic.addNotification(new TskSelectNotification(msg.getColor(), logic.getGame().getPlayers().get(msg.getId()).getName(), parent.getOwnPlayerId()== msg.getId()));
}
@Override

View File

@@ -18,23 +18,26 @@ public class UpdateTSKMessage extends ServerMessage {
*/
private final Color color;
private final boolean isTaken;
/**
* Constructs a new UpdateTSK instance with the specified id and color.
*
* @param id the name associated with the update
* @param color the color associated with the update
*/
public UpdateTSKMessage(int id, Color color) {
public UpdateTSKMessage(int id, Color color, boolean isTaken) {
super();
this.id = id;
this.color = color;
this.isTaken = isTaken;
}
/**
* Default constructor for serialization purposes.
*/
private UpdateTSKMessage() {
this(0, null);
this(0, null, false);
}
/**
@@ -84,4 +87,8 @@ public String toString() {
public String getInfoTextKey() {
return "";
}
public boolean isTaken() {
return isTaken;
}
}

View File

@@ -7,6 +7,7 @@
import pp.mdga.message.server.*;
import pp.mdga.server.ServerGameLogic;
import java.lang.foreign.StructLayout;
import java.util.Map;
/**
@@ -84,8 +85,13 @@ public void received(SelectTSKMessage msg, int from) {
return;
}
}
if(this.logic.getGame().getPlayerById(from).getColor() != Color.NONE) {
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, this.logic.getGame().getPlayerById(from).getColor(), false));
}
this.logic.getGame().getPlayerById(from).setColor(msg.getColor());
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, msg.getColor()));
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, msg.getColor(), true));
}
/**
@@ -98,7 +104,7 @@ public void received(SelectTSKMessage msg, int from) {
@Override
public void received(DeselectTSKMessage msg, int from) {
this.logic.getGame().getPlayerById(from).setColor(Color.NONE);
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, Color.NONE));
this.logic.getServerSender().broadcast(new UpdateTSKMessage(from, Color.NONE, false));
}
/**