This commit is contained in:
Cedric Beck
2024-12-09 01:43:25 +01:00
19 changed files with 113 additions and 4 deletions

View File

@@ -66,6 +66,8 @@ public class MdgaApp extends SimpleApplication {
private ServerConnection networkConnection;
public static final int DEBUG_MULTIPLIER = 0;
public MdgaApp() {
networkConnection = new NetworkSupport(this);
this.clientGameLogic = new ClientGameLogic(networkConnection);

View File

@@ -7,6 +7,7 @@
import pp.mdga.client.view.CeremonyView;
import pp.mdga.client.view.GameView;
import pp.mdga.client.view.LobbyView;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Color;
import pp.mdga.notification.*;
@@ -171,6 +172,12 @@ private void handleGame(Notification notification) {
} else if (notification instanceof NoShieldNotification n) {
boardHandler.unshieldPiece(n.getPieceId());
} else if (notification instanceof PlayCardNotification n) {
if(n.getCard() == BonusCard.TURBO) {
guiHandler.turbo();
app.getModelSynchronize().animationEnd();
return;
}
if(n.getColor() == ownColor) guiHandler.playCardOwn(n.getCard());
else guiHandler.playCardEnemy(n.getColor(), n.getCard());
} else if (notification instanceof PlayerInGameNotification n) {
@@ -203,7 +210,7 @@ private void handleGame(Notification notification) {
boardHandler.swapPieceAnim(n.getFirstPiece(), n.getSecondPiece());
guiHandler.swap();
} else if (notification instanceof WaitMoveNotification) {
//TODO ???
//nothing
} else if (notification instanceof SelectableMoveNotification n) {
boardHandler.outlineMove(n.getPieces(), n.getMoveIndices(), n.getHomeMoves());
modelSynchronizer.setSwap(false);
@@ -214,7 +221,7 @@ private void handleGame(Notification notification) {
boardHandler.outlineShield(n.getPieces());
modelSynchronizer.setSwap(false);
} else if (notification instanceof TurboActiveNotification){
guiHandler.turbo();
//nothing
} else if (notification instanceof FinishNotification n){
guiHandler.finish(n.getColorFinished());
} else {

View File

@@ -153,6 +153,7 @@ private void initializeSerializables() {
Serializer.registerClass(ShieldCard.class);
Serializer.registerClass(HiddenCard.class);
Serializer.registerClass(ChoosePieceStateMessage.class);
Serializer.registerClass(DrawCardMessage.class);
Serializer.registerClass(Color.class, new EnumSerializer());
Serializer.registerClass(PieceState.class, new EnumSerializer());

View File

@@ -21,6 +21,9 @@ public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException
public void writeObject(ByteBuffer buffer, Object object) throws IOException
{
UUID uuid = (UUID) object;
buffer.put(uuid.toString().getBytes());
if(uuid != null) {
buffer.put(uuid.toString().getBytes());
}
}
}

View File

@@ -424,6 +424,14 @@ public void received(ChoosePieceStateMessage choosePieceStateMessage) {
state.received(choosePieceStateMessage);
}
/**
* @param drawCardMessage
*/
@Override
public void received(DrawCardMessage drawCardMessage) {
state.received(drawCardMessage);
}
/**
* This method calls the method received of the state
*

View File

@@ -100,6 +100,11 @@ public void received(ChoosePieceStateMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
}
@Override
public void received(DrawCardMessage msg){
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());
}
@Override
public void received(MoveMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());

View File

@@ -286,6 +286,11 @@ public void received(ChoosePieceStateMessage msg){
state.received(msg);
}
@Override
public void received(DrawCardMessage msg){
state.received(msg);
}
/**
* This method returns the current state
*

View File

@@ -31,6 +31,13 @@ public void received(CeremonyMessage msg) {
logic.setState(logic.getCeremony());
}
@Override
public void received(DrawCardMessage msg){
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), msg.getCard().getCard()));
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseActivatedBonusNodes();
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
}
@Override
public void received(DieMessage msg) {
//logic.getGame().setDiceEyes(msg.getDiceEye());

View File

@@ -143,6 +143,11 @@ public void received(ChoosePieceStateMessage msg){
state.received(msg);
}
@Override
public void received(DrawCardMessage msg){
state.received(msg);
}
public ChoosePieceState getChoosePiece() {
return choosePieceState;
}

View File

@@ -67,6 +67,13 @@ public void received(ActivePlayerMessage msg) {
}
}
@Override
public void received(DrawCardMessage msg){
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), msg.getCard().getCard()));
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseActivatedBonusNodes();
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
}
@Override
public void received(MoveMessage msg) {
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());

View File

@@ -6,6 +6,7 @@
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.ChoosePieceStateMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.DieMessage;
import pp.mdga.message.server.NoTurnMessage;
import pp.mdga.notification.DiceNowNotification;
@@ -59,4 +60,9 @@ public void received(ChoosePieceStateMessage msg){
public void received(NoTurnMessage msg){
parent.getParent().setState(parent.getParent().getWaiting());
}
@Override
public void received(DiceNowMessage msg){
logic.addNotification(new DiceNowNotification());
}
}

View File

@@ -13,4 +13,9 @@ public class BonusNode extends Node {
BonusNode() {
super(null);
}
@Override
public boolean isBonus() {
return true;
}
}

View File

@@ -49,6 +49,10 @@ public void setOccupant(Piece occupant) {
this.occupant = occupant;
}
public boolean isBonus(){
return false;
}
/**
* This method handles the event when a new occupant is moved to the node,
* it then returns the old occupant.

View File

@@ -0,0 +1,34 @@
package pp.mdga.message.server;
import com.jme3.network.serializing.Serializable;
import pp.mdga.game.card.PowerCard;
@Serializable
public class DrawCardMessage extends ServerMessage{
private final PowerCard card;
public DrawCardMessage(PowerCard card){
super();
this.card = card;
}
private DrawCardMessage(){
super();
card = null;
}
/**
* Accepts a visitor to process this message.
*
* @param interpreter the visitor to process this message
*/
@Override
public void accept(ServerInterpreter interpreter) {
interpreter.received(this);
}
public PowerCard getCard(){
return card;
}
}

View File

@@ -223,4 +223,6 @@ public interface ServerInterpreter {
void received(IncorrectRequestMessage msg);
void received(ChoosePieceStateMessage choosePieceStateMessage);
void received(DrawCardMessage drawCardMessage);
}

View File

@@ -3,6 +3,7 @@
import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
import pp.mdga.game.ShieldState;
import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.IncorrectRequestMessage;
import pp.mdga.message.server.PlayCardMessage;
@@ -56,6 +57,8 @@ public void received(SelectedPiecesMessage msg, int from) {
}
}
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), new ArrayList<>(), this.logic.getGame().getDiceModifier()));
this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).removeHandCard(this.powerCardAutomaton.getSelectedCard());
this.logic.getGame().getDiscardPile().add(this.powerCardAutomaton.getSelectedCard());
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
}
else {

View File

@@ -78,6 +78,9 @@ public void received(SelectedPiecesMessage msg, int from) {
logic.getServerSender().broadcast(new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), msg.getPieces(), 1));
this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).removeHandCard(this.powerCardAutomaton.getSelectedCard());
this.logic.getGame().getDiscardPile().add(this.powerCardAutomaton.getSelectedCard());
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
}
} else {

View File

@@ -26,6 +26,8 @@ public void enter() {
this.logic.getGame().getDie().modify();
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.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).removeHandCard(this.powerCardAutomaton.getSelectedCard());
this.logic.getGame().getDiscardPile().add(this.powerCardAutomaton.getSelectedCard());
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
}

View File

@@ -38,7 +38,7 @@ public void enter() {
LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
roll = 0;
moveablePieces = new ArrayList<>();
for (Piece piece : this.rollDiceAutomaton.getTurnAutomaton().getPlayer().getPieces()) {
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
moveablePieces.add(piece);
}