added Ceremony integration

This commit is contained in:
Hanno Fleischer
2024-12-10 19:29:06 +01:00
parent 997b31eba2
commit 9f1dafece2
13 changed files with 230 additions and 31 deletions

View File

@@ -257,33 +257,4 @@ public void selectNext(){
public void selectResume(){
LOGGER.log(Level.DEBUG, "Resume not allowed");
}
/**
* This method is used to create a CeremonyNotification
*
* @return the created CeremonyNotification
*/
protected CeremonyNotification createCeremonyNotification(){
CeremonyNotification notification = new CeremonyNotification();
for (var player : logic.getGame().getPlayers().entrySet()){
notification.getColors().add(player.getValue().getColor());
notification.getNames().add(player.getValue().getName());
notification.getSixes().add(player.getValue().getPlayerStatistic().getDiced6());
notification.getBonusNodes().add(player.getValue().getPlayerStatistic().getActivatedBonusNodes());
notification.getPiecesLost().add(player.getValue().getPlayerStatistic().getPiecesBeingThrown());
notification.getPiecesThrown().add(player.getValue().getPlayerStatistic().getPiecesThrown());
notification.getNodesMoved().add(player.getValue().getPlayerStatistic().getTraveledNodes());
notification.getBonusCardsPlayed().add(player.getValue().getPlayerStatistic().getCardsPlayed());
}
notification.getNames().add("GAME OVERALL");
notification.getNodesMoved().add(logic.getGame().getGameStatistics().getTraveledNodes());
notification.getSixes().add(logic.getGame().getGameStatistics().getDiced6());
notification.getPiecesThrown().add(logic.getGame().getGameStatistics().getPiecesThrown());
notification.getPiecesLost().add(logic.getGame().getGameStatistics().getPiecesBeingThrown());
notification.getBonusNodes().add(logic.getGame().getGameStatistics().getActivatedBonusNodes());
notification.getBonusCardsPlayed().add(logic.getGame().getGameStatistics().getCardsPlayed());
return notification;
}
}

View File

@@ -10,6 +10,7 @@
import pp.mdga.message.client.LeaveGameMessage;
import pp.mdga.message.server.*;
import pp.mdga.notification.AcquireCardNotification;
import pp.mdga.notification.CeremonyNotification;
import pp.mdga.notification.DrawCardNotification;
import pp.mdga.notification.InterruptNotification;
import pp.mdga.notification.StartDialogNotification;
@@ -208,7 +209,16 @@ public void received(MoveMessage msg){
*/
@Override
public void received(CeremonyMessage msg){
logic.addNotification(createCeremonyNotification());
CeremonyNotification notification = new CeremonyNotification();
notification.setColors(msg.getColors());
notification.setNames(msg.getNames());
notification.setBonusNodes(msg.getBonusNodes());
notification.setSixes(msg.getSixes());
notification.setBonusCardsPlayed(msg.getBonusCardsPlayed());
notification.setPiecesLost(msg.getPiecesLost());
notification.setPiecesThrown(msg.getPiecesThrown());
notification.setNodesMoved(msg.getNodesMoved());
logic.addNotification(notification);
logic.setState(logic.getCeremony());
}

View File

@@ -80,6 +80,8 @@ public class Game {
private boolean turboFlag = false;
private Map<Integer, Player> playerRanking = new HashMap<>();
/**
* This constructor creates a new Game object.
*/
@@ -504,4 +506,12 @@ public void setDiceEyes(int diceEyes) {
public void setDiceModifier(int diceModifier) {
this.diceModifier = diceModifier;
}
public Map<Integer, Player> getPlayerRanking() {
return playerRanking;
}
public void setPlayerRanking(Map<Integer, Player> playerRanking) {
this.playerRanking = playerRanking;
}
}

View File

@@ -1,17 +1,149 @@
package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.Color;
import java.util.ArrayList;
/**
* A message sent by the server to indicate the beginning of the ceremony.
*/
@Serializable
public class CeremonyMessage extends ServerMessage {
private ArrayList<Color> colors;
private ArrayList<String> names;
private ArrayList<Integer> piecesThrown;
private ArrayList<Integer> piecesLost;
private ArrayList<Integer> bonusCardsPlayed;
private ArrayList<Integer> sixes;
private ArrayList<Integer> nodesMoved;
private ArrayList<Integer> bonusNodes;
/**
* Constructs a new Ceremony instance.
*/
public CeremonyMessage() {
super();
colors = new ArrayList<>();
names = new ArrayList<>();
piecesThrown = new ArrayList<>();
piecesLost = new ArrayList<>();
bonusCardsPlayed = new ArrayList<>();
sixes = new ArrayList<>();
nodesMoved = new ArrayList<>();
bonusNodes = new ArrayList<>();
}
/**
* @return the list of colors
*/
public ArrayList<Color> getColors() {
return colors;
}
/**
* @param colors the list of colors to set
*/
public void setColors(ArrayList<Color> colors) {
this.colors = colors;
}
/**
* @return the list of player names
*/
public ArrayList<String> getNames() {
return names;
}
/**
* @param names the list of player names to set
*/
public void setNames(ArrayList<String> names) {
this.names = names;
}
/**
* @return the list of pieces thrown
*/
public ArrayList<Integer> getPiecesThrown() {
return piecesThrown;
}
/**
* @param piecesThrown the list of pieces thrown to set
*/
public void setPiecesThrown(ArrayList<Integer> piecesThrown) {
this.piecesThrown = piecesThrown;
}
/**
* @return the list of pieces lost
*/
public ArrayList<Integer> getPiecesLost() {
return piecesLost;
}
/**
* @param piecesLost the list of pieces lost to set
*/
public void setPiecesLost(ArrayList<Integer> piecesLost) {
this.piecesLost = piecesLost;
}
/**
* @return the list of bonus cards played
*/
public ArrayList<Integer> getBonusCardsPlayed() {
return bonusCardsPlayed;
}
/**
* @param bonusCardsPlayed the list of bonus cards played to set
*/
public void setBonusCardsPlayed(ArrayList<Integer> bonusCardsPlayed) {
this.bonusCardsPlayed = bonusCardsPlayed;
}
/**
* @return the list of sixes rolled
*/
public ArrayList<Integer> getSixes() {
return sixes;
}
/**
* @param sixes the list of sixes rolled to set
*/
public void setSixes(ArrayList<Integer> sixes) {
this.sixes = sixes;
}
/**
* @return the list of nodes moved
*/
public ArrayList<Integer> getNodesMoved() {
return nodesMoved;
}
/**
* @param nodesMoved the list of nodes moved to set
*/
public void setNodesMoved(ArrayList<Integer> nodesMoved) {
this.nodesMoved = nodesMoved;
}
/**
* @return the list of bonus nodes
*/
public ArrayList<Integer> getBonusNodes() {
return bonusNodes;
}
/**
* @param bonusNodes the list of bonus nodes to set
*/
public void setBonusNodes(ArrayList<Integer> bonusNodes) {
this.bonusNodes = bonusNodes;
}
/**

View File

@@ -1,5 +1,8 @@
package pp.mdga.server.automaton;
import pp.mdga.game.Color;
import pp.mdga.message.server.CeremonyMessage;
import pp.mdga.notification.CeremonyNotification;
import pp.mdga.server.ServerGameLogic;
/**
@@ -20,12 +23,43 @@ public CeremonyState(ServerGameLogic logic) {
super(logic);
}
/**
* This method is used to create a CeremonyNotification
*
* @return the created CeremonyNotification
*/
private CeremonyMessage createCeremonyMessage(){
CeremonyMessage message = new CeremonyMessage();
for (var player : logic.getGame().getPlayerRanking().entrySet()){
message.getColors().add(player.getValue().getColor());
message.getNames().add(player.getValue().getName());
message.getSixes().add(player.getValue().getPlayerStatistic().getDiced6());
message.getBonusNodes().add(player.getValue().getPlayerStatistic().getActivatedBonusNodes());
message.getPiecesLost().add(player.getValue().getPlayerStatistic().getPiecesBeingThrown());
message.getPiecesThrown().add(player.getValue().getPlayerStatistic().getPiecesThrown());
message.getNodesMoved().add(player.getValue().getPlayerStatistic().getTraveledNodes());
message.getBonusCardsPlayed().add(player.getValue().getPlayerStatistic().getCardsPlayed());
}
message.getNames().add("GAME OVERALL");
message.getColors().add(Color.NONE);
message.getNodesMoved().add(logic.getGame().getGameStatistics().getTraveledNodes());
message.getSixes().add(logic.getGame().getGameStatistics().getDiced6());
message.getPiecesThrown().add(logic.getGame().getGameStatistics().getPiecesThrown());
message.getPiecesLost().add(logic.getGame().getGameStatistics().getPiecesBeingThrown());
message.getBonusNodes().add(logic.getGame().getGameStatistics().getActivatedBonusNodes());
message.getBonusCardsPlayed().add(logic.getGame().getGameStatistics().getCardsPlayed());
return message;
}
/**
* This method will be used whenever this state will be entered.
*/
@Override
public void enter() {
LOGGER.log(System.Logger.Level.DEBUG, "Entered CeremonyState state.");
logic.getServerSender().broadcast(createCeremonyMessage());
}
/**

View File

@@ -4,6 +4,7 @@
import pp.mdga.game.Player;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.ActivePlayerMessage;
import pp.mdga.message.server.CeremonyMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.EndOfTurnMessage;
import pp.mdga.message.server.SpectatorMessage;
@@ -46,8 +47,14 @@ 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.getGame().getPlayerRanking().put(logic.getGame().getPlayerRanking().size(), logic.getGame().getActivePlayer());
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new SpectatorMessage());
setActivePlayer(logic.getGame().getActiveColor());
if (logic.getGame().getPlayerRanking().size() == logic.getGame().getPlayers().size() - 1){
logic.getGame().getPlayerRanking().put(logic.getGame().getPlayerRanking().size(), logic.getGame().getActivePlayer());
logic.setCurrentState(logic.getCeremonyState());
return;
}
this.turnAutomaton.getGameAutomaton().setCurrentState(this.turnAutomaton.getGameAutomaton().getTurnState());
} else if (logic.getGame().getDiceEyes() == 6){
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new DiceNowMessage());

View File

@@ -49,6 +49,8 @@ public void exit() {
*/
@Override
public void received(AnimationEndMessage msg, int from) {
logic.getGame().getActivePlayer().getPlayerStatistic().increaseCardsPlayed();
logic.getGame().getGameStatistics().increaseCardsPlayed();
this.messageReceived.add(from);
if (this.messageReceived.size() == this.logic.getGame().getPlayers().size()) {
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage());

View File

@@ -63,10 +63,11 @@ public void received(RequestMoveMessage msg, int from) {
if (!moveablePieces.contains(msg.getPiece())) {
throw new RuntimeException("invalid Piece");
}
int indexOfPiece = moveablePieces.indexOf(msg.getPiece());
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
Piece piece = moveablePieces.get(indexOfPiece);
logic.getGame().getActivePlayer().getPlayerStatistic().increaseTraveledNodes(calculateTargetIndex(piece));
logic.getGame().getGameStatistics().increaseTraveledNodes(calculateTargetIndex(piece));
if (canPieceMoveInHome(piece, steps)) {
if (piece.getState().equals(PieceState.HOME)) {
//gets the oldNode
@@ -115,6 +116,10 @@ public void received(RequestMoveMessage msg, int from) {
Piece occ = targetNode.getOccupant();
if (occ != null) {
logic.getGame().getActivePlayer().getPlayerStatistic().increasePiecesThrown();
logic.getGame().getGameStatistics().increasePiecesThrown();
logic.getGame().getPlayerByColor(occ.getColor()).getPlayerStatistic().increasePiecesBeingThrown();
logic.getGame().getGameStatistics().increasePiecesBeingThrown();
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
}
@@ -135,6 +140,8 @@ public void received(RequestMoveMessage msg, int from) {
logic.getServerSender().broadcast(new MoveMessage(piece, homeMove, targIdx));
if (targetNode.isBonus()) {
logic.getGame().getActivePlayer().getPlayerStatistic().increaseActivatedBonusNodes();
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
for (Player p : logic.getGame().getPlayersAsList()) {
if (p.getColor() == logic.getGame().getActiveColor()) {
PowerCard cardToDraw = logic.getGame().draw();

View File

@@ -46,6 +46,8 @@ public void received(RequestMoveMessage msg, int from) {
if (piece.equals(msg.getPiece())) {
int targetIndex = calculateTargetIndex(piece);
Node targetNode = logic.getGame().getBoard().getInfield()[targetIndex];
logic.getGame().getActivePlayer().getPlayerStatistic().increaseTraveledNodes(calculateTargetIndex(piece));
logic.getGame().getGameStatistics().increaseTraveledNodes(calculateTargetIndex(piece));
//send MoveMessage
logic.getServerSender().broadcast(new MoveMessage(piece, false, targetIndex));
@@ -55,6 +57,10 @@ public void received(RequestMoveMessage msg, int from) {
Piece occ = targetNode.getOccupant();
if (occ != null) {
logic.getGame().getActivePlayer().getPlayerStatistic().increasePiecesThrown();
logic.getGame().getGameStatistics().increasePiecesThrown();
logic.getGame().getPlayerByColor(occ.getColor()).getPlayerStatistic().increasePiecesBeingThrown();
logic.getGame().getGameStatistics().increasePiecesBeingThrown();
//move occ to waiting
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
}
@@ -62,6 +68,8 @@ public void received(RequestMoveMessage msg, int from) {
targetNode.setOccupant(piece);
if (targetNode.isBonus()) {
logic.getGame().getActivePlayer().getPlayerStatistic().increaseActivatedBonusNodes();
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
for (Player p : logic.getGame().getPlayersAsList()) {
if (p.getColor() == logic.getGame().getActiveColor()) {
PowerCard cardToDraw = logic.getGame().draw();

View File

@@ -44,6 +44,10 @@ public void received(RequestMoveMessage msg, int from){
piece.setState(PieceState.ACTIVE);
Piece thrownOcc = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].getOccupant();
if (thrownOcc != null) {
logic.getGame().getActivePlayer().getPlayerStatistic().increasePiecesThrown();
logic.getGame().getGameStatistics().increasePiecesThrown();
logic.getGame().getPlayerByColor(thrownOcc.getColor()).getPlayerStatistic().increasePiecesBeingThrown();
logic.getGame().getGameStatistics().increasePiecesBeingThrown();
logic.getGame().getPlayerByColor(thrownOcc.getColor()).addWaitingPiece(thrownOcc);
}
logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].setOccupant(this.piece);

View File

@@ -63,6 +63,10 @@ public void exit() {
public void received(RequestDieMessage msg, int from) {
roll = this.logic.getGame().getDie().shuffle();
this.logic.getGame().setDiceEyes(roll);
if (roll == Resources.MAX_EYES) {
logic.getGame().getActivePlayer().getPlayerStatistic().increaseDiced6();
logic.getGame().getGameStatistics().increaseDiced6();
}
this.logic.getServerSender().broadcast(new DieMessage(roll));
isDied = true;
}

View File

@@ -1,5 +1,6 @@
package pp.mdga.server.automaton.game.turn.rolldice;
import pp.mdga.Resources;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.ChoosePieceStateMessage;
@@ -47,6 +48,10 @@ public void exit() {
public void received(RequestDieMessage msg, int from) {
int roll = this.logic.getGame().getDie().shuffle();
this.logic.getGame().setDiceEyes(roll);
if (roll == Resources.MAX_EYES) {
logic.getGame().getActivePlayer().getPlayerStatistic().increaseDiced6();
logic.getGame().getGameStatistics().increaseDiced6();
}
this.logic.getServerSender().broadcast(new DieMessage(roll));
}

View File

@@ -1,5 +1,6 @@
package pp.mdga.server.automaton.game.turn.rolldice;
import pp.mdga.Resources;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.*;
@@ -44,6 +45,10 @@ public void exit() {
public void received(RequestDieMessage msg, int from) {
int roll = this.logic.getGame().getDie().shuffle();
this.logic.getGame().setDiceEyes(roll);
if (roll == Resources.MAX_EYES) {
logic.getGame().getActivePlayer().getPlayerStatistic().increaseDiced6();
logic.getGame().getGameStatistics().increaseDiced6();
}
this.logic.getServerSender().broadcast(new DieMessage(roll));
}