diff --git a/src/main/java/de/towerdefence/server/game/GameSession.java b/src/main/java/de/towerdefence/server/game/GameSession.java
index a31e6ad..bcc7cfe 100644
--- a/src/main/java/de/towerdefence/server/game/GameSession.java
+++ b/src/main/java/de/towerdefence/server/game/GameSession.java
@@ -118,11 +118,11 @@ public class GameSession {
return changedEnemies;
}
- public void placeTower(Tower tower, int x, int y) throws InvalidPlacementException {
- if (x < 0 || y < 0 || x + 1 > MAP_SIZE.x || y + 1 > MAP_SIZE.y) {
+ public void placeTower(Tower tower, Vector2i pos) throws InvalidPlacementException {
+ if (pos.x < 0 || pos.y < 0 || pos.x + 1 > MAP_SIZE.x || pos.y + 1 > MAP_SIZE.y) {
throw new InvalidPlacementException(InvalidPlacementReason.OUT_OF_BOUNDS);
}
- if (towers[x][y] != null) {
+ if (towers[pos.x][pos.y] != null) {
throw new InvalidPlacementException(InvalidPlacementReason.LOCATION_USED);
}
if (money < Tower.COST) {
@@ -133,9 +133,8 @@ public class GameSession {
money -= Tower.COST;
moneyCallback.call(player, money);
- tower.x = x;
- tower.y = y;
- towers[x][y] = tower;
+ tower.pos = pos;
+ towers[pos.x][pos.y] = tower;
}
public void addMoney(int amount) {
diff --git a/src/main/java/de/towerdefence/server/game/Tower.java b/src/main/java/de/towerdefence/server/game/Tower.java
index a4a9f64..4c30055 100644
--- a/src/main/java/de/towerdefence/server/game/Tower.java
+++ b/src/main/java/de/towerdefence/server/game/Tower.java
@@ -1,12 +1,13 @@
package de.towerdefence.server.game;
+import org.joml.Vector2i;
+
import lombok.Getter;
@Getter
public class Tower {
public static final int COST = 20;
- protected int x;
- protected int y;
+ protected Vector2i pos;
public Tower() {
}
diff --git a/src/main/java/de/towerdefence/server/game/pathfinding/PathNode.java b/src/main/java/de/towerdefence/server/game/pathfinding/PathNode.java
index 76893c0..f7e951d 100644
--- a/src/main/java/de/towerdefence/server/game/pathfinding/PathNode.java
+++ b/src/main/java/de/towerdefence/server/game/pathfinding/PathNode.java
@@ -6,7 +6,7 @@ import lombok.AllArgsConstructor;
@AllArgsConstructor
final class PathNode {
- protected final Vector2i pos;
- protected final long cost; // This is the cost to this Node
- protected final long estimate; // This is the estimated remaining cost to the Target
+ final Vector2i pos;
+ final long cost; // This is the cost to this Node
+ final long estimate; // This is the estimated remaining cost to the Target
}
diff --git a/src/main/java/de/towerdefence/server/match/MatchService.java b/src/main/java/de/towerdefence/server/match/MatchService.java
index 63729e7..ba28895 100644
--- a/src/main/java/de/towerdefence/server/match/MatchService.java
+++ b/src/main/java/de/towerdefence/server/match/MatchService.java
@@ -5,6 +5,8 @@ import de.towerdefence.server.game.callbacks.PlayerMoneyCallback;
import de.towerdefence.server.game.exeptions.InvalidPlacementException;
import de.towerdefence.server.game.exeptions.InvalidPlacementReason;
import de.towerdefence.server.player.Player;
+
+import org.joml.Vector2i;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -51,7 +53,7 @@ public class MatchService {
if (opponent.isEmpty()) {
throw new NotInMatchException();
}
- playerSession.get().placeTower(new Tower(), x, y);
+ playerSession.get().placeTower(new Tower(), new Vector2i(x, y));
return opponent.get();
}
diff --git a/src/main/java/de/towerdefence/server/server/channels/match/MatchWebsocketHandler.java b/src/main/java/de/towerdefence/server/server/channels/match/MatchWebsocketHandler.java
index 866b332..9a559ba 100644
--- a/src/main/java/de/towerdefence/server/server/channels/match/MatchWebsocketHandler.java
+++ b/src/main/java/de/towerdefence/server/server/channels/match/MatchWebsocketHandler.java
@@ -17,6 +17,7 @@ import de.towerdefence.server.match.MatchService;
import de.towerdefence.server.match.NotInMatchException;
import de.towerdefence.server.player.Player;
import de.towerdefence.server.server.JsonWebsocketHandler;
+import de.towerdefence.server.server.channels.match.enemy.EnemyUpdateMessage;
import de.towerdefence.server.server.channels.match.hitpoints.PlayerHitpointsMessage;
import de.towerdefence.server.server.channels.match.money.PlayerMoneyMessage;
import de.towerdefence.server.server.channels.match.placing.GamePlayerMap;
@@ -45,7 +46,7 @@ public class MatchWebsocketHandler extends JsonWebsocketHandler {
sessionPlayers.get(session),
this::onPlayerMoneyChanged,
this::onPlayerHitpointsChanged,
- this::onEnemiesChanged
+ this::onEnemiesChanged
);
}
@@ -73,7 +74,11 @@ public class MatchWebsocketHandler extends JsonWebsocketHandler {
}
private void onEnemiesChanged(Player player, Enemy[] newEnemies, Enemy[] changedEnemies) {
-
+ WebSocketSession session = playerSessions.get(player);
+ try {
+ new EnemyUpdateMessage(newEnemies, changedEnemies).send(session);
+ }catch(IOException ignored){
+ }
}
@Override
diff --git a/src/main/java/de/towerdefence/server/server/channels/match/enemy/EnemyUpdateMessage.java b/src/main/java/de/towerdefence/server/server/channels/match/enemy/EnemyUpdateMessage.java
index c83c359..909e4f7 100644
--- a/src/main/java/de/towerdefence/server/server/channels/match/enemy/EnemyUpdateMessage.java
+++ b/src/main/java/de/towerdefence/server/server/channels/match/enemy/EnemyUpdateMessage.java
@@ -12,8 +12,6 @@ import lombok.AllArgsConstructor;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collector;
-import java.util.stream.Collectors;
@AllArgsConstructor
public class EnemyUpdateMessage extends JsonMessage {
@@ -34,8 +32,8 @@ public class EnemyUpdateMessage extends JsonMessage {
.map((Enemy enemy) -> {
ObjectNode o = factory.objectNode();
o.set("id", factory.numberNode(enemy.getId()));
- o.set("x", factory.numberNode(enemy.getX()));
- o.set("y", factory.numberNode(enemy.getY()));
+ o.set("x", factory.numberNode(enemy.getPos().x));
+ o.set("y", factory.numberNode(enemy.getPos().y));
return o;
})
.map(JsonNode.class::cast)
@@ -46,8 +44,8 @@ public class EnemyUpdateMessage extends JsonMessage {
.map((Enemy enemy) -> {
ObjectNode o = factory.objectNode();
o.set("id", factory.numberNode(enemy.getId()));
- o.set("x", factory.numberNode(enemy.getX()));
- o.set("y", factory.numberNode(enemy.getY()));
+ o.set("x", factory.numberNode(enemy.getPos().x));
+ o.set("y", factory.numberNode(enemy.getPos().y));
return o;
})
.map(JsonNode.class::cast)
diff --git a/src/main/resources/spotbugs-exclude.xml b/src/main/resources/spotbugs-exclude.xml
index d737fbf..d3a00dc 100644
--- a/src/main/resources/spotbugs-exclude.xml
+++ b/src/main/resources/spotbugs-exclude.xml
@@ -25,4 +25,10 @@
+
+
+
+
+
+