From 63bfc5557def364a277233b19fc265c30e798131 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 25 Jul 2022 19:40:23 +0200 Subject: [PATCH] Updated player manager. --- .../nl/andrewl/aos2_server/PlayerManager.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java b/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java index a9c3d15..83d0892 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java @@ -3,7 +3,12 @@ package nl.andrewl.aos2_server; import nl.andrewl.aos2_server.model.ServerPlayer; import nl.andrewl.aos_core.Net; import nl.andrewl.aos_core.model.Team; +import nl.andrewl.aos_core.model.item.BlockItemStack; +import nl.andrewl.aos_core.model.item.Gun; +import nl.andrewl.aos_core.model.item.GunItemStack; +import nl.andrewl.aos_core.model.item.ItemStack; import nl.andrewl.aos_core.net.client.ClientHealthMessage; +import nl.andrewl.aos_core.net.client.ItemStackMessage; import nl.andrewl.aos_core.net.client.PlayerJoinMessage; import nl.andrewl.aos_core.net.client.PlayerLeaveMessage; import nl.andrewl.aos_core.net.connect.DatagramInit; @@ -136,7 +141,19 @@ public class PlayerManager { player.setPosition(getBestSpawnPoint(player)); player.setVelocity(new Vector3f(0)); player.setHealth(1); - getHandler(player.getId()).sendDatagramPacket(new ClientHealthMessage(player.getHealth())); + var handler = getHandler(player.getId()); + for (int i = 0; i < player.getInventory().getItemStacks().size(); i++) { + ItemStack stack = player.getInventory().getItemStacks().get(i); + if (stack instanceof GunItemStack g) { + Gun gun = (Gun) g.getType(); + g.setBulletCount(gun.getMaxBulletCount()); + g.setClipCount(gun.getMaxClipCount()); + } else if (stack instanceof BlockItemStack b) { + b.setAmount(50); + } + handler.sendTcpMessage(new ItemStackMessage(i, stack)); + } + handler.sendDatagramPacket(new ClientHealthMessage(player.getHealth())); broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis())); // TODO: Team points or something. }