# Conflicts:
#	Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java
#	Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/ChoosePieceAutomatonState.java
#	Projekte/mdga/model/src/main/java/pp/mdga/server/automaton/game/turn/choosepiece/SelectPieceState.java
This commit is contained in:
Benjamin Feyer
2024-12-09 04:50:01 +01:00
56 changed files with 468 additions and 101 deletions

View File

@@ -11,6 +11,7 @@ public enum Asset {
cir, cir,
heer, heer,
jet, jet,
jet_noGear("Models/jet/jet_noGear.j3o", "Models/jet/jet_diff.png"),
lw, lw,
marine, marine,
node_home_blue("Models/node_home/node_home.j3o", "Models/node_home/node_home_blue_diff.png"), node_home_blue("Models/node_home/node_home.j3o", "Models/node_home/node_home_blue_diff.png"),

View File

@@ -250,12 +250,13 @@ private void hoverPiece() {
PieceControl control = checkPiece(); PieceControl control = checkPiece();
if (control != null) { if (control != null) {
if (control != hoverPiece) { if (control != hoverPiece) {
pieceOff(); pieceOff(gameView);
hoverPiece = control; hoverPiece = control;
hoverPiece.hover(); // hoverPiece.hover();
gameView.getBoardHandler().pieceHoverOn(hoverPiece);
} }
} else { } else {
pieceOff(); pieceOff(gameView);
} }
} }
} }
@@ -305,8 +306,11 @@ private CardControl checkCard(GameView gameView) {
/** /**
* Disables the hover effect on the currently hovered piece, if any. * Disables the hover effect on the currently hovered piece, if any.
*/ */
private void pieceOff() { private void pieceOff(GameView gameView) {
if (hoverPiece != null) hoverPiece.hoverOff(); if (hoverPiece != null) {
gameView.getBoardHandler().pieceHoverOff(hoverPiece);
// hoverPiece.hoverOff();
}
hoverPiece = null; hoverPiece = null;
} }

View File

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

View File

@@ -23,8 +23,12 @@ public class ModelSynchronizer {
} }
public void animationEnd() { public void animationEnd() {
if(app.getNotificationSynchronizer().waitForAnimation) {
app.getNotificationSynchronizer().waitForAnimation = false;
} else {
app.getGameLogic().selectAnimationEnd(); app.getGameLogic().selectAnimationEnd();
} }
}
public void select(UUID a, UUID b){ public void select(UUID a, UUID b){
if(swap) selectSwap(a,b); if(swap) selectSwap(a,b);
@@ -79,6 +83,8 @@ public void confirm() {
GameView gameView = (GameView) app.getView(); GameView gameView = (GameView) app.getView();
gameView.getGuiHandler().hideText();
if(a != null && b != null) { if(a != null && b != null) {
app.getGameLogic().selectPiece(a); app.getGameLogic().selectPiece(a);
app.getGameLogic().selectPiece(b); app.getGameLogic().selectPiece(b);

View File

@@ -7,10 +7,13 @@
import pp.mdga.client.view.CeremonyView; import pp.mdga.client.view.CeremonyView;
import pp.mdga.client.view.GameView; import pp.mdga.client.view.GameView;
import pp.mdga.client.view.LobbyView; import pp.mdga.client.view.LobbyView;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Color; import pp.mdga.game.Color;
import pp.mdga.notification.*; import pp.mdga.notification.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
public class NotificationSynchronizer { public class NotificationSynchronizer {
private final MdgaApp app; private final MdgaApp app;
@@ -22,12 +25,18 @@ public class NotificationSynchronizer {
private static final float STANDARD_DELAY = 2.5f; private static final float STANDARD_DELAY = 2.5f;
public boolean waitForAnimation = false;
NotificationSynchronizer(MdgaApp app) { NotificationSynchronizer(MdgaApp app) {
this.app = app; this.app = app;
} }
public void update() { public void update() {
while (timer.getTimeInSeconds() >= delay) { while (timer.getTimeInSeconds() >= delay) {
if(waitForAnimation) {
return;
}
Notification n = app.getGameLogic().getNotification(); Notification n = app.getGameLogic().getNotification();
if(n == null) { if(n == null) {
@@ -62,10 +71,12 @@ public void update() {
throw new RuntimeException("no notification expected: " + n.getClass().getName()); throw new RuntimeException("no notification expected: " + n.getClass().getName());
} }
if(0 == MdgaApp.DEBUG_MULTIPLIER) {
delay = 0; delay = 0;
} }
} }
} }
}
private void handleMain(Notification notification) { private void handleMain(Notification notification) {
if (notification instanceof LobbyDialogNotification) { if (notification instanceof LobbyDialogNotification) {
@@ -144,9 +155,11 @@ private void handleGame(Notification notification) {
guiHandler.showDice(); guiHandler.showDice();
} else if (notification instanceof DrawCardNotification n) { } else if (notification instanceof DrawCardNotification n) {
guiHandler.drawCard(n.getColor()); guiHandler.drawCard(n.getColor());
delay = STANDARD_DELAY;
} else if (notification instanceof HomeMoveNotification home) { } else if (notification instanceof HomeMoveNotification home) {
boardHandler.movePieceHomeAnim(home.getPieceId(), home.getHomeIndex()); boardHandler.movePieceHomeAnim(home.getPieceId(), home.getHomeIndex());
guiHandler.hideText(); guiHandler.hideText();
app.getGameLogic().selectAnimationEnd();
} else if (notification instanceof InterruptNotification notification1) { } else if (notification instanceof InterruptNotification notification1) {
gameView.enterInterrupt(notification1.getColor()); gameView.enterInterrupt(notification1.getColor());
} else if (notification instanceof MovePieceNotification n) { } else if (notification instanceof MovePieceNotification n) {
@@ -161,11 +174,27 @@ private void handleGame(Notification notification) {
guiHandler.hideText(); guiHandler.hideText();
} else if (notification instanceof ThrowPieceNotification n) { } else if (notification instanceof ThrowPieceNotification n) {
boardHandler.throwPiece(n.getPieceId(), n.getThrowColor()); boardHandler.throwPiece(n.getPieceId(), n.getThrowColor());
} else if (notification instanceof NoShieldNotification n) { waitForAnimation = true;
boardHandler.unshieldPiece(n.getPieceId()); } else if (notification instanceof RemoveShieldNotification n) {
boardHandler.unshieldPiece(n.getPieceUuid());
} else if (notification instanceof PlayCardNotification n) { } else if (notification instanceof PlayCardNotification n) {
if(n.getCard() == BonusCard.TURBO) {
app.getAcousticHandler().playSound(MdgaSound.TURBO);
guiHandler.turbo();
} else if(n.getCard() == BonusCard.SHIELD) {
app.getAcousticHandler().playSound(MdgaSound.SHIELD);
} else if(n.getCard() == BonusCard.SWAP) {
app.getAcousticHandler().playSound(MdgaSound.SWAP);
}
if(n.getColor() == ownColor) guiHandler.playCardOwn(n.getCard()); if(n.getColor() == ownColor) guiHandler.playCardOwn(n.getCard());
else guiHandler.playCardEnemy(n.getColor(), n.getCard()); else guiHandler.playCardEnemy(n.getColor(), n.getCard());
new Timer().schedule(new TimerTask() {
@Override
public void run() {
app.getModelSynchronize().animationEnd();
}
}, 2200 * MdgaApp.DEBUG_MULTIPLIER);
} else if (notification instanceof PlayerInGameNotification n) { } else if (notification instanceof PlayerInGameNotification n) {
boardHandler.addPlayer(n.getColor(),n.getPiecesList()); boardHandler.addPlayer(n.getColor(),n.getPiecesList());
guiHandler.addPlayer(n.getColor(),n.getName()); guiHandler.addPlayer(n.getColor(),n.getName());
@@ -175,13 +204,13 @@ private void handleGame(Notification notification) {
gameView.getGuiHandler().hideText(); gameView.getGuiHandler().hideText();
if(n.getColor() == ownColor){ if(n.getColor() == ownColor){
guiHandler.rollDice(n.getEyes(), n.isTurbo() ? n.getMultiplier() : -1); guiHandler.rollDice(n.getEyes(), n.isTurbo() ? n.getMultiplier() : -1);
waitForAnimation = true;
} }
else { else {
boardHandler.hideDice(); boardHandler.hideDice();
if (n.isTurbo()) guiHandler.showRolledDiceMult(n.getEyes(), n.getMultiplier(), n.getColor()); if (n.isTurbo()) guiHandler.showRolledDiceMult(n.getEyes(), n.getMultiplier(), n.getColor());
else guiHandler.showRolledDice(n.getEyes(), n.getColor()); else guiHandler.showRolledDice(n.getEyes(), n.getColor());
} }
delay = 7;
} else if (notification instanceof SelectableCardsNotification n) { } else if (notification instanceof SelectableCardsNotification n) {
guiHandler.setSelectableCards(n.getCards()); guiHandler.setSelectableCards(n.getCards());
gameView.showNoPower(); gameView.showNoPower();
@@ -196,7 +225,7 @@ private void handleGame(Notification notification) {
boardHandler.swapPieceAnim(n.getFirstPiece(), n.getSecondPiece()); boardHandler.swapPieceAnim(n.getFirstPiece(), n.getSecondPiece());
guiHandler.swap(); guiHandler.swap();
} else if (notification instanceof WaitMoveNotification) { } else if (notification instanceof WaitMoveNotification) {
//TODO ??? //nothing
} else if (notification instanceof SelectableMoveNotification n) { } else if (notification instanceof SelectableMoveNotification n) {
boardHandler.outlineMove(n.getPieces(), n.getMoveIndices(), n.getHomeMoves()); boardHandler.outlineMove(n.getPieces(), n.getMoveIndices(), n.getHomeMoves());
modelSynchronizer.setSwap(false); modelSynchronizer.setSwap(false);
@@ -207,7 +236,7 @@ private void handleGame(Notification notification) {
boardHandler.outlineShield(n.getPieces()); boardHandler.outlineShield(n.getPieces());
modelSynchronizer.setSwap(false); modelSynchronizer.setSwap(false);
} else if (notification instanceof TurboActiveNotification){ } else if (notification instanceof TurboActiveNotification){
guiHandler.turbo(); //nothing
} else if (notification instanceof FinishNotification n){ } else if (notification instanceof FinishNotification n){
guiHandler.finish(n.getColorFinished()); guiHandler.finish(n.getColorFinished());
} else { } else {

View File

@@ -147,6 +147,16 @@ public void playSound(MdgaSound sound) {
case TANK_EXPLOSION: case TANK_EXPLOSION:
assets.add(new SoundAssetDelayVolume(SoundAsset.EXPLOSION_1, 1.0f, 0f)); assets.add(new SoundAssetDelayVolume(SoundAsset.EXPLOSION_1, 1.0f, 0f));
break; break;
case SHIELD:
assets.add(new SoundAssetDelayVolume(SoundAsset.SHIELD, 1.0f, 0f));
break;
case TURBO:
assets.add(new SoundAssetDelayVolume(SoundAsset.SPEED, 1.0f, 0.1f));
assets.add(new SoundAssetDelayVolume(SoundAsset.SPEED, 1.0f, 1.3f));
break;
case SWAP:
assets.add(new SoundAssetDelayVolume(SoundAsset.SWAP, 1.0f, 0f));
break;
default: default:
break; break;
} }

View File

@@ -40,5 +40,8 @@ public enum MdgaSound {
MATRIX, MATRIX,
TURRET_ROTATE, TURRET_ROTATE,
TANK_SHOOT, TANK_SHOOT,
TANK_EXPLOSION TANK_EXPLOSION,
SHIELD,
TURBO,
SWAP,
} }

View File

@@ -39,7 +39,10 @@ enum SoundAsset {
MATRIX("matrix.wav"), MATRIX("matrix.wav"),
CONNECTED("connected.wav"), CONNECTED("connected.wav"),
TURRET_ROTATE("turret_rotate.ogg"), TURRET_ROTATE("turret_rotate.ogg"),
TANK_SHOOT("tank_shoot.ogg") TANK_SHOOT("tank_shoot.ogg"),
SHIELD("shield.ogg"),
SPEED("speed.ogg"),
SWAP("swap.ogg"),
; ;

View File

@@ -76,13 +76,13 @@ public void start() {
* Spawns the jet model at the designated spawn point, applying material, scaling, and rotation. * Spawns the jet model at the designated spawn point, applying material, scaling, and rotation.
*/ */
private void spawnJet() { private void spawnJet() {
jetModel = app.getAssetManager().loadModel(Asset.jet.getModelPath()); jetModel = app.getAssetManager().loadModel(Asset.jet_noGear.getModelPath());
jetModel.setLocalTranslation(spawnPoint); jetModel.setLocalTranslation(spawnPoint);
jetModel.scale(Asset.jet.getSize()); jetModel.scale(Asset.jet_noGear.getSize());
jetModel.rotate(FastMath.HALF_PI, 0, 0); jetModel.rotate(FastMath.HALF_PI, 0, 0);
jetModel.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); jetModel.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(Asset.jet.getDiffPath())); mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(Asset.jet_noGear.getDiffPath()));
jetModel.setMaterial(mat); jetModel.setMaterial(mat);
rootNode.attachChild(jetModel); rootNode.attachChild(jetModel);

View File

@@ -529,7 +529,6 @@ private void throwPiece(UUID uuid){
* @param uuid the UUID of the piece to shield * @param uuid the UUID of the piece to shield
*/ */
public void shieldPiece(UUID uuid){ public void shieldPiece(UUID uuid){
pieces.get(uuid).activateShield(); pieces.get(uuid).activateShield();
} }
@@ -670,6 +669,7 @@ public void pieceSelect(PieceControl pieceSelected) {
if(selectableOwnPieces.contains(pieceSelected)){ if(selectableOwnPieces.contains(pieceSelected)){
for(PieceControl p : selectableOwnPieces) { for(PieceControl p : selectableOwnPieces) {
p.unSelect(); p.unSelect();
if(selectedPieceNodeMap.get(p) != null) selectedPieceNodeMap.get(p).unSelect();
} }
if (!isSelected) { if (!isSelected) {
pieceSelected.select(); pieceSelected.select();
@@ -678,7 +678,7 @@ public void pieceSelect(PieceControl pieceSelected) {
} }
else { else {
pieceSelected.unSelect(); pieceSelected.unSelect();
if(selectedPieceNodeMap.get(pieceSelected) != null) selectedPieceNodeMap.get(pieceSelected).highlight(); if(selectedPieceNodeMap.get(pieceSelected) != null) selectedPieceNodeMap.get(pieceSelected).unSelect();
selectedOwnPiece = null; selectedOwnPiece = null;
} }
} }
@@ -700,6 +700,16 @@ else if(selectableEnemyPieces.contains(pieceSelected)) {
app.getModelSynchronize().select(getKeyByValue(pieces, selectedOwnPiece), getKeyByValue(pieces, selectedEnemyPiece)); app.getModelSynchronize().select(getKeyByValue(pieces, selectedOwnPiece), getKeyByValue(pieces, selectedEnemyPiece));
} }
public void pieceHoverOn(PieceControl hoverPiece){
hoverPiece.hover();
if(selectedPieceNodeMap.get(hoverPiece) != null) selectedPieceNodeMap.get(hoverPiece).hover();
}
public void pieceHoverOff(PieceControl hoverPiece){
hoverPiece.hoverOff();
if(selectedPieceNodeMap.get(hoverPiece) != null) selectedPieceNodeMap.get(hoverPiece).hoverOff();
}
/** /**
* Clears all highlighted, selectable, and selected pieces and nodes. * Clears all highlighted, selectable, and selected pieces and nodes.
*/ */

View File

@@ -17,7 +17,11 @@ public class NodeControl extends OutlineControl {
private static final ColorRGBA OUTLINE_HIGHLIGHT_COLOR = ColorRGBA.White; private static final ColorRGBA OUTLINE_HIGHLIGHT_COLOR = ColorRGBA.White;
private static final int OUTLINE_HIGHLIGHT_WIDTH = 6; private static final int OUTLINE_HIGHLIGHT_WIDTH = 6;
private static final ColorRGBA OUTLINE_SELECT_COLOR = ColorRGBA.Cyan; private static final ColorRGBA OUTLINE_SELECT_COLOR = ColorRGBA.Cyan;
private static final int OUTLINE_SELECT_WIDTH = 6; private static final int OUTLINE_SELECT_WIDTH = 8;
private static final ColorRGBA OUTLINE_HOVER_COLOR = ColorRGBA.Yellow;
private static final int OUTLINE_HOVER_WIDTH = 6;
private boolean select = false;
private boolean highlight = false;
/** /**
* Constructs a {@link NodeControl} with the specified application and post processor. * Constructs a {@link NodeControl} with the specified application and post processor.
@@ -40,15 +44,34 @@ public Vector3f getLocation(){
return this.getSpatial().getLocalTranslation(); return this.getSpatial().getLocalTranslation();
} }
/**
* Highlights the node by applying an outline effect.
* The outline color and width are predefined as white and 6, respectively.
*/
public void highlight(){ public void highlight(){
highlight = true;
super.outline(OUTLINE_HIGHLIGHT_COLOR, OUTLINE_HIGHLIGHT_WIDTH); super.outline(OUTLINE_HIGHLIGHT_COLOR, OUTLINE_HIGHLIGHT_WIDTH);
} }
public void unHighlight(){
highlight = false;
deOutline();
}
public void select(){ public void select(){
select = true;
super.outline(OUTLINE_SELECT_COLOR, OUTLINE_SELECT_WIDTH); super.outline(OUTLINE_SELECT_COLOR, OUTLINE_SELECT_WIDTH);
} }
public void unSelect(){
select = false;
if(highlight) highlight();
else deOutline();
}
public void hover(){
super.outline(OUTLINE_HOVER_COLOR, OUTLINE_HOVER_WIDTH);
}
public void hoverOff(){
if(select) select();
else if(highlight) highlight();
else deOutline();
}
} }

View File

@@ -113,6 +113,7 @@ public Vector3f getLocation(){
protected void controlUpdate(float delta) { protected void controlUpdate(float delta) {
if(shieldRing != null){ if(shieldRing != null){
shieldRing.rotate(0, 0, delta * SHIELD_SPEED); shieldRing.rotate(0, 0, delta * SHIELD_SPEED);
shieldRing.setLocalTranslation(spatial.getLocalTranslation().add(new Vector3f(0,0,SHIELD_Z)));
} }
} }

View File

@@ -33,6 +33,7 @@ public class CardLayerHandler {
private final Set<CardControl> selectableCards = new HashSet<>(); private final Set<CardControl> selectableCards = new HashSet<>();
private BonusCard cardSelect = null; private BonusCard cardSelect = null;
private boolean show = false;
public CardLayerHandler(MdgaApp app, Texture2D backTexture) { public CardLayerHandler(MdgaApp app, Texture2D backTexture) {
this.app = app; this.app = app;
@@ -64,11 +65,14 @@ public void rollDice(int rollNum, Runnable actionAfter) {
} }
public void showDice() { public void showDice() {
if(show) return;
show = true;
cardLayer.addSpatial(diceControl.getSpatial()); cardLayer.addSpatial(diceControl.getSpatial());
diceControl.spin(); diceControl.spin();
} }
public void hideDice() { public void hideDice() {
show = false;
diceControl.hide(); diceControl.hide();
} }

View File

@@ -11,6 +11,7 @@
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl; import com.jme3.scene.control.AbstractControl;
import pp.mdga.client.Asset; import pp.mdga.client.Asset;
import pp.mdga.client.MdgaApp;
import java.util.Random; import java.util.Random;
@@ -51,8 +52,7 @@ protected void controlUpdate(float tpf) {
); );
// Stop rolling when angular velocity is close to zero // Stop rolling when angular velocity is close to zero
// if (angularVelocity.lengthSquared() < 3f) { if (angularVelocity.lengthSquared() <= 3f || MdgaApp.DEBUG_MULTIPLIER == 0) {
if(true){
slerp = true; slerp = true;
} }
} }
@@ -66,8 +66,7 @@ protected void controlUpdate(float tpf) {
spatial.setLocalRotation(interpolated); spatial.setLocalRotation(interpolated);
// Stop rolling once duration is complete // Stop rolling once duration is complete
// if (timeElapsed >= 1.0f) { if (timeElapsed >= 1.0f * MdgaApp.DEBUG_MULTIPLIER) {
if(true){
isRolling = false; isRolling = false;
slerp = false; slerp = false;
actionAfter.run(); actionAfter.run();

View File

@@ -52,6 +52,7 @@ public void rollDice(int rollNum, int mult) {
else actionTextHandler.ownDiceMult(rollNum, mult); else actionTextHandler.ownDiceMult(rollNum, mult);
hideDice(); hideDice();
app.getModelSynchronize().animationEnd(); app.getModelSynchronize().animationEnd();
app.getModelSynchronize().animationEnd();
}); });
} }

View File

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

View File

@@ -14,13 +14,22 @@ public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException
byte[] uuid = new byte[36]; byte[] uuid = new byte[36];
data.get(uuid); data.get(uuid);
if(uuid.equals(new UUID(1, 1))) {
return null;
} else {
return (T) UUID.fromString(new String(uuid)); return (T) UUID.fromString(new String(uuid));
} }
}
@Override @Override
public void writeObject(ByteBuffer buffer, Object object) throws IOException public void writeObject(ByteBuffer buffer, Object object) throws IOException
{ {
UUID uuid = (UUID) object; UUID uuid = (UUID) object;
if(uuid != null) {
buffer.put(uuid.toString().getBytes()); buffer.put(uuid.toString().getBytes());
} else {
buffer.put(new UUID(1, 1).toString().getBytes());
}
} }
} }

View File

@@ -424,6 +424,14 @@ public void received(ChoosePieceStateMessage choosePieceStateMessage) {
state.received(choosePieceStateMessage); state.received(choosePieceStateMessage);
} }
/**
* @param drawCardMessage
*/
@Override
public void received(DrawCardMessage drawCardMessage) {
state.received(drawCardMessage);
}
/** /**
* This method calls the method received of the state * 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()); 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 @Override
public void received(MoveMessage msg) { public void received(MoveMessage msg) {
LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString()); LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg.toString());

View File

@@ -3,8 +3,14 @@
import pp.mdga.client.gamestate.*; import pp.mdga.client.gamestate.*;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.card.HiddenCard;
import pp.mdga.game.card.ShieldCard;
import pp.mdga.game.card.SwapCard;
import pp.mdga.game.card.TurboCard;
import pp.mdga.message.client.LeaveGameMessage; import pp.mdga.message.client.LeaveGameMessage;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.notification.AcquireCardNotification;
import pp.mdga.notification.DrawCardNotification;
import pp.mdga.notification.InterruptNotification; import pp.mdga.notification.InterruptNotification;
import pp.mdga.notification.StartDialogNotification; import pp.mdga.notification.StartDialogNotification;
@@ -286,6 +292,21 @@ public void received(ChoosePieceStateMessage msg){
state.received(msg); state.received(msg);
} }
@Override
public void received(DrawCardMessage msg){
if(msg.getCard() instanceof HiddenCard){
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), BonusCard.HIDDEN));
} else if(msg.getCard() instanceof TurboCard) {
logic.addNotification(new AcquireCardNotification(BonusCard.TURBO));
} else if(msg.getCard() instanceof ShieldCard) {
logic.addNotification(new AcquireCardNotification(BonusCard.SHIELD));
} else if(msg.getCard() instanceof SwapCard) {
logic.addNotification(new AcquireCardNotification(BonusCard.SWAP));
} else {
throw new RuntimeException();
}
}
/** /**
* This method returns the current state * This method returns the current state
* *

View File

@@ -2,7 +2,9 @@
import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState; import pp.mdga.client.ClientState;
import pp.mdga.game.Board;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import pp.mdga.game.Node;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.PieceState; import pp.mdga.game.PieceState;
import pp.mdga.game.ShieldState; import pp.mdga.game.ShieldState;
@@ -12,6 +14,7 @@
import pp.mdga.notification.SwapPieceNotification; import pp.mdga.notification.SwapPieceNotification;
import pp.mdga.notification.ThrowPieceNotification; import pp.mdga.notification.ThrowPieceNotification;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public abstract class GameStates extends ClientState { public abstract class GameStates extends ClientState {
@@ -24,17 +27,12 @@ public GameStates(ClientState parent, ClientGameLogic logic) {
protected void handlePowerCard(PlayCardMessage msg) { protected void handlePowerCard(PlayCardMessage msg) {
if (msg.getCard().getCard().equals(BonusCard.TURBO)) { if (msg.getCard().getCard().equals(BonusCard.TURBO)) {
logic.getGame().setTurboFlag(true);
logic.getGame().setDiceModifier(msg.getDiceModifier()); logic.getGame().setDiceModifier(msg.getDiceModifier());
} else if (msg.getCard().getCard().equals(BonusCard.SHIELD)) { } else if (msg.getCard().getCard().equals(BonusCard.SHIELD)) {
handleShield(msg.getPieces().get(0).getUuid()); handleShield(msg.getPieces().get(0).getUuid());
} else { } else {
Piece ownPiece = logic.getGame().getPieceThroughUUID(msg.getPieces().get(0).getUuid()); swapPieces(msg.getPieces().get(0), msg.getPieces().get(1));
Piece enemyPiece = logic.getGame().getPieceThroughUUID(msg.getPieces().get(1).getUuid());
LOGGER.log(System.Logger.Level.INFO, "Swapping");
int ownIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(ownPiece);
logic.addNotification(new SwapPieceNotification(ownPiece.getUuid(), enemyPiece.getUuid()));
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece);
logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece);
} }
logic.getGame().getDiscardPile().add(msg.getCard()); logic.getGame().getDiscardPile().add(msg.getCard());
} }
@@ -57,4 +55,17 @@ private void handleShield(UUID uuid) {
logic.addNotification(new ShieldActiveNotification(uuid)); logic.addNotification(new ShieldActiveNotification(uuid));
} }
} }
private void swapPieces(Piece messageOwn, Piece messageEnemy) {
//swap Pieces in Model
Board board = logic.getGame().getBoard();
Piece modelOwn = logic.getGame().getPieceThroughUUID(messageOwn.getUuid());
Piece modelEnemy = logic.getGame().getPieceThroughUUID(messageEnemy.getUuid());
Node ownNode = board.getInfield()[board.getInfieldIndexOfPiece(modelOwn)];
Node enemyNode = board.getInfield()[board.getInfieldIndexOfPiece(modelEnemy)];
ownNode.setOccupant(modelEnemy);
enemyNode.setOccupant(modelOwn);
logic.addNotification(new SwapPieceNotification(modelOwn.getUuid(), modelEnemy.getUuid()));
}
} }

View File

@@ -31,6 +31,13 @@ public void received(CeremonyMessage msg) {
logic.setState(logic.getCeremony()); 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 @Override
public void received(DieMessage msg) { public void received(DieMessage msg) {
//logic.getGame().setDiceEyes(msg.getDiceEye()); //logic.getGame().setDiceEyes(msg.getDiceEye());
@@ -87,6 +94,7 @@ public void received(MoveMessage msg) {
//set new node //set new node
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece); logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
} }
logic.getGame().setTurboFlag(false);
parent.setState(parent.getAnimation()); parent.setState(parent.getAnimation());
} }
} }

View File

@@ -11,7 +11,15 @@
import pp.mdga.client.gamestate.turnstate.TurnStates; import pp.mdga.client.gamestate.turnstate.TurnStates;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.ShieldState;
import pp.mdga.game.card.HiddenCard;
import pp.mdga.game.card.ShieldCard;
import pp.mdga.game.card.SwapCard;
import pp.mdga.game.card.TurboCard;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.notification.RemoveShieldNotification;
import pp.mdga.notification.AcquireCardNotification;
import pp.mdga.notification.DrawCardNotification;
public class TurnState extends GameStates { public class TurnState extends GameStates {
@@ -23,6 +31,7 @@ public class TurnState extends GameStates {
private final PlayPowerCardState playPowerCardState = new PlayPowerCardState(this, logic); private final PlayPowerCardState playPowerCardState = new PlayPowerCardState(this, logic);
private final PowerCardState powerCardState = new PowerCardState(this, logic); private final PowerCardState powerCardState = new PowerCardState(this, logic);
private final RollDiceState rollDiceState = new RollDiceState(this, logic); private final RollDiceState rollDiceState = new RollDiceState(this, logic);
private boolean canChangeTurbo = false;
public TurnState(ClientState parent, ClientGameLogic logic) { public TurnState(ClientState parent, ClientGameLogic logic) {
super(parent, logic); super(parent, logic);
@@ -31,6 +40,13 @@ public TurnState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
for (Piece piece : logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPieces()) {
if (piece.isShielded() || piece.isSuppressed()){
piece.setShield(ShieldState.NONE);
logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
}
}
logic.getGame().setTurboFlag(false);
this.setState(this.powerCardState); this.setState(this.powerCardState);
} }
@@ -143,6 +159,11 @@ public void received(ChoosePieceStateMessage msg){
state.received(msg); state.received(msg);
} }
@Override
public void received(DrawCardMessage msg){
}
public ChoosePieceState getChoosePiece() { public ChoosePieceState getChoosePiece() {
return choosePieceState; return choosePieceState;
} }
@@ -170,4 +191,12 @@ public GameState getParent(){
public TurnStates getState(){ public TurnStates getState(){
return state; return state;
} }
public boolean isCanChangeTurbo() {
return canChangeTurbo;
}
public void setCanChangeTurbo(boolean canChangeTurbo) {
this.canChangeTurbo = canChangeTurbo;
}
} }

View File

@@ -42,7 +42,16 @@ public void received(DiceNowMessage msg) {
@Override @Override
public void received(DieMessage msg) { public void received(DieMessage msg) {
logic.getGame().setDiceEyes(msg.getDiceEye()); logic.getGame().setDiceEyes(msg.getDiceEye());
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes())); if(logic.getGame().getTurboFlag()){
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye(), logic.getGame().getDiceModifier()));
}
else {
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye()));
}
// logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes()));
//stats
if (msg.getDiceEye() == 6) { if (msg.getDiceEye() == 6) {
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6(); logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();
logic.getGame().getGameStatistics().increaseDiced6(); logic.getGame().getGameStatistics().increaseDiced6();
@@ -67,6 +76,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 @Override
public void received(MoveMessage msg) { public void received(MoveMessage msg) {
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()); Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
@@ -95,6 +111,7 @@ public void received(MoveMessage msg) {
//set new node //set new node
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece); logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
} }
logic.getGame().setTurboFlag(false);
parent.setState(parent.getAnimation()); parent.setState(parent.getAnimation());
} }
} }

View File

@@ -6,6 +6,7 @@
import pp.mdga.message.client.AnimationEndMessage; import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.client.RequestDieMessage; import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.ChoosePieceStateMessage; import pp.mdga.message.server.ChoosePieceStateMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.DieMessage; import pp.mdga.message.server.DieMessage;
import pp.mdga.message.server.NoTurnMessage; import pp.mdga.message.server.NoTurnMessage;
import pp.mdga.notification.DiceNowNotification; import pp.mdga.notification.DiceNowNotification;
@@ -42,7 +43,14 @@ public void selectDice(){
@Override @Override
public void received(DieMessage msg){ public void received(DieMessage msg){
logic.getGame().setDiceEyes(msg.getDiceEye()); logic.getGame().setDiceEyes(msg.getDiceEye());
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye(),false));
if(logic.getGame().getTurboFlag()){
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye(), logic.getGame().getDiceModifier()));
}
else {
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye()));
}
} }
@Override @Override
@@ -59,4 +67,9 @@ public void received(ChoosePieceStateMessage msg){
public void received(NoTurnMessage msg){ public void received(NoTurnMessage msg){
parent.getParent().setState(parent.getParent().getWaiting()); parent.getParent().setState(parent.getParent().getWaiting());
} }
@Override
public void received(DiceNowMessage msg){
logic.addNotification(new DiceNowNotification());
}
} }

View File

@@ -41,8 +41,9 @@ public void received(SelectPieceMessage msg) {
//TODO //TODO
ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new)); ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new));
parent.getSelectPiece().setPossiblePieces(pieces); parent.getSelectPiece().setPossiblePieces(pieces);
ArrayList<UUID> listPiece = pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new));
LOGGER.log(System.Logger.Level.INFO, "Received " + msg.getPieces().size() + " pieces"); LOGGER.log(System.Logger.Level.INFO, "Received " + msg.getPieces().size() + " pieces");
logic.addNotification(new SelectableMoveNotification(pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new)), msg.getTargetIndex(), msg.getIsHomeMove())); logic.addNotification(new SelectableMoveNotification(listPiece, msg.getTargetIndex(), msg.getIsHomeMove()));
parent.setState(parent.getSelectPiece()); parent.setState(parent.getSelectPiece());
} }
@@ -71,6 +72,7 @@ public void received(StartPieceMessage msg){
@Override @Override
public void received(NoTurnMessage msg){ public void received(NoTurnMessage msg){
logic.getGame().setTurboFlag(false);
parent.getParent().getParent().setState(parent.getParent().getParent().getWaiting()); parent.getParent().getParent().setState(parent.getParent().getParent().getWaiting());
} }
} }

View File

@@ -71,7 +71,7 @@ public void received(MoveMessage msg) {
//set new node //set new node
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece); logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
} }
logic.getGame().setTurboFlag(false);
parent.getParent().setState(parent.getParent().getMovePiece()); parent.getParent().setState(parent.getParent().getMovePiece());
} }
} }

View File

@@ -65,7 +65,7 @@ public void received(MoveMessage msg){
targetNode.setOccupant(msg.getPiece()); targetNode.setOccupant(msg.getPiece());
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), oldIndex, targetIndex)); logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), oldIndex, targetIndex));
logic.getGame().setTurboFlag(false);
parent.getParent().setState(parent.getParent().getMovePiece()); parent.getParent().setState(parent.getParent().getMovePiece());
} }
} }

View File

@@ -49,7 +49,7 @@ public void received(MoveMessage msg){
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex(), true)); logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex(), true));
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(msg.getPiece()); logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(msg.getPiece());
logic.getGame().setTurboFlag(false);
pieceToMove.setState(PieceState.ACTIVE); pieceToMove.setState(PieceState.ACTIVE);
parent.getParent().setState(parent.getParent().getMovePiece()); parent.getParent().setState(parent.getParent().getMovePiece());
} }

View File

@@ -4,6 +4,7 @@
import pp.mdga.client.ClientState; import pp.mdga.client.ClientState;
import pp.mdga.client.gamestate.turnstate.PowerCardState; import pp.mdga.client.gamestate.turnstate.PowerCardState;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece;
import pp.mdga.game.card.*; import pp.mdga.game.card.*;
import pp.mdga.message.client.NoPowerCardMessage; import pp.mdga.message.client.NoPowerCardMessage;
import pp.mdga.message.client.SelectCardMessage; import pp.mdga.message.client.SelectCardMessage;
@@ -12,6 +13,7 @@
import pp.mdga.message.server.PossibleCardsMessage; import pp.mdga.message.server.PossibleCardsMessage;
import pp.mdga.message.server.PossiblePieceMessage; import pp.mdga.message.server.PossiblePieceMessage;
import pp.mdga.notification.SelectableCardsNotification; import pp.mdga.notification.SelectableCardsNotification;
import pp.mdga.notification.SelectableShieldNotification;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -85,7 +87,9 @@ public void selectCard(BonusCard card){
@Override @Override
public void received(PlayCardMessage msg){ public void received(PlayCardMessage msg){
if(msg.getCard().getCard().equals(BonusCard.TURBO)){ if(msg.getCard().getCard().equals(BonusCard.TURBO)){
logic.getGame().setDiceModifier(msg.getDiceModifier());
parent.getParent().getPlayPowerCard().setPlayCard(msg); parent.getParent().getPlayPowerCard().setPlayCard(msg);
logic.getGame().setTurboFlag(true);
parent.getParent().setState(parent.getParent().getPlayPowerCard()); parent.getParent().setState(parent.getParent().getPlayPowerCard());
} }
} }
@@ -108,6 +112,7 @@ public void received(PossiblePieceMessage msg){
if (msg.getEnemyPossiblePieces().isEmpty()){ if (msg.getEnemyPossiblePieces().isEmpty()){
parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new))); parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new)));
parent.setState(parent.getShield()); parent.setState(parent.getShield());
logic.addNotification(new SelectableShieldNotification(msg.getOwnPossiblePieces().stream().map(Piece::getUuid).toList()));
} else { } else {
System.out.println("Should enter Swap State"); System.out.println("Should enter Swap State");
parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new))); parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new)));

View File

@@ -5,10 +5,12 @@
import pp.mdga.client.gamestate.turnstate.PowerCardState; import pp.mdga.client.gamestate.turnstate.PowerCardState;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.message.client.RequestPlayCardMessage; import pp.mdga.message.client.RequestPlayCardMessage;
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.PlayCardMessage; import pp.mdga.message.server.PlayCardMessage;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class ShieldState extends PowerCardStates { public class ShieldState extends PowerCardStates {
@@ -40,7 +42,10 @@ public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
public void selectPiece(Piece piece) { public void selectPiece(Piece piece) {
if (possiblePieces.contains(piece)) { if (possiblePieces.contains(piece)) {
logic.send(RequestPlayCardMessage.requestPlayShield(piece.getUuid())); // logic.send(RequestPlayCardMessage.requestPlayShield(piece.getUuid()));
ArrayList<Piece> temp = new ArrayList<>();
temp.add(piece);
logic.send(new SelectedPiecesMessage(temp));
} else { } else {
LOGGER.log(Level.DEBUG, "Invalid piece selected"); LOGGER.log(Level.DEBUG, "Invalid piece selected");
} }

View File

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

View File

@@ -78,6 +78,8 @@ public class Game {
*/ */
private int diceEyes; private int diceEyes;
private boolean turboFlag = false;
/** /**
* This constructor creates a new Game object. * This constructor creates a new Game object.
*/ */
@@ -85,7 +87,7 @@ public Game() {
gameStatistics = new Statistic(); gameStatistics = new Statistic();
initializeDrawPile(); initializeDrawPile();
board = new Board(); board = new Board();
die = new Die(5,5,5,5,5,5,5,5,5,1,1,6,2,4,6,5,5,5,5,5); die = new Die(2,5,6,3,6);
} }
/** /**
@@ -309,6 +311,14 @@ public boolean isHost() {
return this.host != -1; return this.host != -1;
} }
public void setTurboFlag(boolean flag) {
this.turboFlag = flag;
}
public boolean getTurboFlag() {
return this.turboFlag;
}
/** /**
* This method returns the players. * This method returns the players.
* *

View File

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

View File

@@ -114,6 +114,8 @@ public void removeHandCard(PowerCard card) {
* @param piece as the piece which should be added to the waitingArea attribute of Player class as a Piece object. * @param piece as the piece which should be added to the waitingArea attribute of Player class as a Piece object.
*/ */
public void addWaitingPiece(Piece piece) { public void addWaitingPiece(Piece piece) {
piece.setState(PieceState.WAITING);
for (int i = 0; i < Resources.MAX_PIECES; i++) { for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (this.waitingArea[i] == null) { if (this.waitingArea[i] == null) {
this.waitingArea[i] = piece; this.waitingArea[i] = piece;

View File

@@ -41,9 +41,9 @@ public RequestPlayCardMessage(BonusCard card, UUID ownPieceIdentifier, UUID enem
* Default constructor for serialization purposes. * Default constructor for serialization purposes.
*/ */
private RequestPlayCardMessage() { private RequestPlayCardMessage() {
card = null; card = BonusCard.HIDDEN;
ownPieceIdentifier = null; ownPieceIdentifier = UUID.randomUUID();
enemyPieceIdentifier = null; enemyPieceIdentifier = UUID.randomUUID();
} }
/** /**

View File

@@ -0,0 +1,39 @@
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;
}
@Override
public String toString() {
return "DrawCardMessage{" + "PowerCard=" + card +'}';
}
}

View File

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

View File

@@ -1,29 +0,0 @@
package pp.mdga.notification;
import java.util.UUID;
/**
* Notification that a piece has no shield.
*/
public class NoShieldNotification extends Notification{
/**
* The id of the piece that has no shield.
*/
private final UUID pieceId;
/**
* Constructor.
* @param pieceId the id of the piece that has no shield.
*/
public NoShieldNotification(UUID pieceId) {
this.pieceId = pieceId;
}
/**
* Get the id of the piece that has no shield.
* @return the id of the piece that has no shield.
*/
public UUID getPieceId() {
return pieceId;
}
}

View File

@@ -0,0 +1,15 @@
package pp.mdga.notification;
import java.util.UUID;
public class RemoveShieldNotification extends Notification {
private final UUID pieceUuid;
public RemoveShieldNotification(UUID pieceUuid) {
this.pieceUuid = pieceUuid;
}
public UUID getPieceUuid() {
return pieceUuid;
}
}

View File

@@ -13,6 +13,7 @@ public class RollDiceNotification extends Notification{
private int multiplier; private int multiplier;
private boolean isRanking; private boolean isRanking;
//normal
/** /**
* Constructor. * Constructor.
* @param color the color of the player that rolled the die. * @param color the color of the player that rolled the die.
@@ -26,6 +27,7 @@ public RollDiceNotification(Color color, int eyes) {
this.isRanking = false; this.isRanking = false;
} }
//ranking
public RollDiceNotification(Color color, int eyes, boolean isRanking) { public RollDiceNotification(Color color, int eyes, boolean isRanking) {
this.color = color; this.color = color;
this.eyes = eyes; this.eyes = eyes;
@@ -34,10 +36,11 @@ public RollDiceNotification(Color color, int eyes, boolean isRanking) {
this.isRanking = isRanking; this.isRanking = isRanking;
} }
public RollDiceNotification(Color color, int eyes, boolean turbo, int multiplier) { //turbo
public RollDiceNotification(Color color, int eyes, int multiplier) {
this.color = color; this.color = color;
this.eyes = eyes; this.eyes = eyes;
this.turbo = turbo; this.turbo = true;
this.multiplier = multiplier; this.multiplier = multiplier;
this.isRanking = false; this.isRanking = false;
} }

View File

@@ -1,6 +1,8 @@
package pp.mdga.server.automaton.game; package pp.mdga.server.automaton.game;
import pp.mdga.game.Piece;
import pp.mdga.game.Player; import pp.mdga.game.Player;
import pp.mdga.game.ShieldState;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.GameState; import pp.mdga.server.automaton.GameState;
@@ -52,6 +54,9 @@ public TurnState(GameState gameAutomaton, ServerGameLogic logic) {
public void enter() { public void enter() {
LOGGER.log(Level.INFO, "Entered TurnState state."); LOGGER.log(Level.INFO, "Entered TurnState state.");
this.player = this.logic.getGame().getPlayerById(this.logic.getGame().getActivePlayerId()); this.player = this.logic.getGame().getPlayerById(this.logic.getGame().getActivePlayerId());
for (Piece piece : this.player.getPieces()) {
piece.setShield(ShieldState.NONE);
}
this.setCurrentState(this.powerCardState); this.setCurrentState(this.powerCardState);
} }

View File

@@ -32,7 +32,6 @@ public PlayPowerCardState(TurnState turnAutomaton, ServerGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
LOGGER.log(System.Logger.Level.DEBUG, "Entered PlayPowerCardState state."); LOGGER.log(System.Logger.Level.DEBUG, "Entered PlayPowerCardState state.");
} }

View File

@@ -22,6 +22,7 @@ public class RollDiceState extends TurnAutomatonState {
private final FirstRollState firstRollState; private final FirstRollState firstRollState;
private final SecondRollState secondRollState; private final SecondRollState secondRollState;
private final ThirdRollState thirdRollState; private final ThirdRollState thirdRollState;
private boolean resetModifier = true;
/** /**
* Constructs a server state of the specified game logic. * Constructs a server state of the specified game logic.
@@ -39,12 +40,16 @@ public RollDiceState(TurnState turnAutomaton, ServerGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
LOGGER.log(System.Logger.Level.DEBUG, "Entered RollDiceState state."); LOGGER.log(System.Logger.Level.DEBUG, "Entered RollDiceState state.");
if (resetModifier){
logic.getGame().setDiceModifier(1);
}
this.setCurrentState(this.firstRollState); this.setCurrentState(this.firstRollState);
} }
@Override @Override
public void exit() { public void exit() {
LOGGER.log(System.Logger.Level.DEBUG, "Exited RollDiceState state."); LOGGER.log(System.Logger.Level.DEBUG, "Exited RollDiceState state.");
resetModifier = true;
} }
/** /**
@@ -73,6 +78,10 @@ public RollDiceAutomatonState getCurrentState() {
return this.currentState; return this.currentState;
} }
public void setResetModifier(boolean resetModifier) {
this.resetModifier = resetModifier;
}
/** /**
* This method will be used to return firstRollState attribute of RollDiceState class. * This method will be used to return firstRollState attribute of RollDiceState class.
* *

View File

@@ -1,6 +1,5 @@
package pp.mdga.server.automaton.game.turn.choosepiece; package pp.mdga.server.automaton.game.turn.choosepiece;
import com.jme3.util.SortUtil;
import pp.mdga.game.*; import pp.mdga.game.*;
import pp.mdga.message.client.AnimationEndMessage; import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
@@ -72,6 +71,9 @@ private boolean canInfieldMove(Piece piece, int steps) {
int moveIndex = (pieceIndex + steps) % logic.getGame().getBoard().getInfield().length; int moveIndex = (pieceIndex + steps) % logic.getGame().getBoard().getInfield().length;
Piece occupant = logic.getGame().getBoard().getInfield()[moveIndex].getOccupant(); Piece occupant = logic.getGame().getBoard().getInfield()[moveIndex].getOccupant();
if (occupant != null){ if (occupant != null){
if (occupant.isShielded()){
return false;
}
return occupant.getColor() != piece.getColor(); return occupant.getColor() != piece.getColor();
} }
return true; return true;

View File

@@ -1,7 +1,9 @@
package pp.mdga.server.automaton.game.turn.choosepiece; package pp.mdga.server.automaton.game.turn.choosepiece;
import pp.mdga.game.*; import pp.mdga.game.*;
import pp.mdga.game.card.HiddenCard;
import pp.mdga.message.client.RequestMoveMessage; import pp.mdga.message.client.RequestMoveMessage;
import pp.mdga.message.server.DrawCardMessage;
import pp.mdga.message.server.MoveMessage; import pp.mdga.message.server.MoveMessage;
import pp.mdga.message.server.SelectPieceMessage; import pp.mdga.message.server.SelectPieceMessage;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
@@ -165,6 +167,17 @@ public void received(RequestMoveMessage msg, int from){
movePiece.setShield(ShieldState.NONE); movePiece.setShield(ShieldState.NONE);
} else { } else {
Node targetNode = logic.getGame().getBoard().getInfield()[targIdx]; Node targetNode = logic.getGame().getBoard().getInfield()[targIdx];
//TODO durch merge auskommentiert
if(targetNode.isBonus()) {
for (Player p : logic.getGame().getPlayersAsList()) {
if(p.getColor() == logic.getGame().getActiveColor()) {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(logic.getGame().draw()));
} else {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
}
}
}
Piece occ = targetNode.getOccupant(); Piece occ = targetNode.getOccupant();
if (occ != null) { if (occ != null) {
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ); logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);

View File

@@ -2,7 +2,10 @@
import pp.mdga.game.Node; import pp.mdga.game.Node;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.Player;
import pp.mdga.game.card.HiddenCard;
import pp.mdga.message.client.RequestMoveMessage; import pp.mdga.message.client.RequestMoveMessage;
import pp.mdga.message.server.DrawCardMessage;
import pp.mdga.message.server.MoveMessage; import pp.mdga.message.server.MoveMessage;
import pp.mdga.message.server.StartPieceMessage; import pp.mdga.message.server.StartPieceMessage;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
@@ -42,6 +45,17 @@ public void received(RequestMoveMessage msg, int from){
if (piece.equals(msg.getPiece())) { if (piece.equals(msg.getPiece())) {
int targetIndex = calculateTargetIndex(piece); int targetIndex = calculateTargetIndex(piece);
Node targetNode = logic.getGame().getBoard().getInfield()[targetIndex]; Node targetNode = logic.getGame().getBoard().getInfield()[targetIndex];
if(targetNode.isBonus()) {
for (Player p : logic.getGame().getPlayersAsList()) {
if(p.getColor() == logic.getGame().getActiveColor()) {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(logic.getGame().draw()));
} else {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
}
}
}
//send MoveMessage //send MoveMessage
logic.getServerSender().broadcast(new MoveMessage(piece, false, targetIndex)); logic.getServerSender().broadcast(new MoveMessage(piece, false, targetIndex));

View File

@@ -3,6 +3,7 @@
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.PieceState; import pp.mdga.game.PieceState;
import pp.mdga.game.ShieldState; import pp.mdga.game.ShieldState;
import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.SelectedPiecesMessage; import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.IncorrectRequestMessage; import pp.mdga.message.server.IncorrectRequestMessage;
import pp.mdga.message.server.PlayCardMessage; import pp.mdga.message.server.PlayCardMessage;
@@ -55,7 +56,11 @@ public void received(SelectedPiecesMessage msg, int from) {
piece.setShield(ShieldState.ACTIVE); piece.setShield(ShieldState.ACTIVE);
} }
} }
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), new ArrayList<>(), this.logic.getGame().getDiceModifier())); ArrayList<Piece> temp = new ArrayList<>();
temp.add(msg.getPieces().get(0));
this.logic.getServerSender().broadcast(new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), temp, 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()); this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
} }
else { else {

View File

@@ -1,6 +1,10 @@
package pp.mdga.server.automaton.game.turn.powercard; package pp.mdga.server.automaton.game.turn.powercard;
import pp.mdga.game.Board;
import pp.mdga.game.Color;
import pp.mdga.game.Node;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.card.SwapCard;
import pp.mdga.message.client.SelectedPiecesMessage; import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.IncorrectRequestMessage; import pp.mdga.message.server.IncorrectRequestMessage;
import pp.mdga.message.server.PlayCardMessage; import pp.mdga.message.server.PlayCardMessage;
@@ -9,6 +13,7 @@
import pp.mdga.server.automaton.game.turn.PowerCardState; import pp.mdga.server.automaton.game.turn.PowerCardState;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class SwapCardState extends PowerCardAutomatonState { public class SwapCardState extends PowerCardAutomatonState {
@@ -51,20 +56,30 @@ public void exit() {
@Override @Override
public void received(SelectedPiecesMessage msg, int from) { public void received(SelectedPiecesMessage msg, int from) {
if (msg.getPieces().size() == 2) { if (msg.getPieces().size() == 2) {
Piece first = msg.getPieces().get(0); Piece selOwn = msg.getPieces().get(0);
Piece second = msg.getPieces().get(1); Piece selEnemy = msg.getPieces().get(1);
if ((this.powerCardAutomaton.getVisitor().getSwapOwnPieces().contains(first) List<Piece> ownPieces = this.powerCardAutomaton.getVisitor().getSwapOwnPieces();
&& this.powerCardAutomaton.getVisitor().getSwapOtherPieces().contains(second)) List<Piece> enemyPieces = this.powerCardAutomaton.getVisitor().getSwapOtherPieces();
|| (this.powerCardAutomaton.getVisitor().getSwapOwnPieces().contains(second)
&& this.powerCardAutomaton.getVisitor().getSwapOtherPieces().contains(first))) {
this.powerCardAutomaton.addSelectedPiece(first);
this.powerCardAutomaton.addSelectedPiece(second);
ArrayList<Piece> temp = new ArrayList<>(); //if selOwn and selEnemy is in wrong order
temp.add(first); if(ownPieces.contains(selEnemy) && enemyPieces.contains(selOwn)){
temp.add(second); Piece temp = selEnemy;
selEnemy = selOwn;
selOwn = temp;
}
logic.getServerSender().broadcast(new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), temp, 1)); if (ownPieces.contains(selOwn) && enemyPieces.contains(selEnemy)) {
this.powerCardAutomaton.addSelectedPiece(selOwn);
this.powerCardAutomaton.addSelectedPiece(selEnemy);
if(!(powerCardAutomaton.getSelectedCard() instanceof SwapCard)) throw new RuntimeException("getSelectedCard is not swapCard");
swapPieces(selOwn, selEnemy);
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()); this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
} }
@@ -72,4 +87,16 @@ public void received(SelectedPiecesMessage msg, int from) {
this.logic.getServerSender().send(from, new IncorrectRequestMessage(4)); this.logic.getServerSender().send(from, new IncorrectRequestMessage(4));
} }
} }
private void swapPieces(Piece messageOwn, Piece messageEnemy) {
//swap Pieces in Model
Board board = logic.getGame().getBoard();
Piece modelOwn = logic.getGame().getPieceThroughUUID(messageOwn.getUuid());
Piece modelEnemy = logic.getGame().getPieceThroughUUID(messageEnemy.getUuid());
Node ownNode = board.getInfield()[board.getInfieldIndexOfPiece(modelOwn)];
Node enemyNode = board.getInfield()[board.getInfieldIndexOfPiece(modelEnemy)];
ownNode.setOccupant(modelEnemy);
enemyNode.setOccupant(modelOwn);
}
} }

View File

@@ -25,7 +25,10 @@ public TurboCardState(PowerCardState powerCardAutomaton, ServerGameLogic logic)
public void enter() { public void enter() {
this.logic.getGame().getDie().modify(); this.logic.getGame().getDie().modify();
this.logic.getGame().setDiceModifier(this.logic.getGame().getDie().getDieModifier()); 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.getServerSender().broadcast(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().getRollDiceState().setResetModifier(false);
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState()); 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."); LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
roll = 0; roll = 0;
moveablePieces = new ArrayList<>(); 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) { if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
moveablePieces.add(piece); moveablePieces.add(piece);
} }
@@ -66,6 +66,9 @@ public void received(RequestDieMessage msg, int from) {
@Override @Override
public void received(AnimationEndMessage msg, int from) { public void received(AnimationEndMessage msg, int from) {
if (from != this.logic.getGame().getActivePlayerId()) {
return;
}
if (!moveablePieces.isEmpty()) { if (!moveablePieces.isEmpty()) {
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage()); this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage());
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState()); this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());

View File

@@ -52,6 +52,9 @@ public void received(RequestDieMessage msg, int from) {
@Override @Override
public void received(AnimationEndMessage msg, int from) { public void received(AnimationEndMessage msg, int from) {
if (from != this.logic.getGame().getActivePlayerId()) {
return;
}
if (this.logic.getGame().getDiceEyes() == 6) { if (this.logic.getGame().getDiceEyes() == 6) {
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage()); this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage());
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState()); this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());

View File

@@ -49,6 +49,9 @@ public void received(RequestDieMessage msg, int from) {
@Override @Override
public void received(AnimationEndMessage msg, int from) { public void received(AnimationEndMessage msg, int from) {
if (from != this.logic.getGame().getActivePlayerId()) {
return;
}
if (this.logic.getGame().getDiceEyes() == 6) { if (this.logic.getGame().getDiceEyes() == 6) {
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage()); this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage());
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState()); this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());