From 289ce50552ac1fc14f1a570c7966f213410101f9 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Thu, 28 Jul 2022 11:44:45 +0200 Subject: [PATCH] Added some simple chat commands. --- .../aos2_client/render/gui/GuiRenderer.java | 2 +- .../ClientCommunicationHandler.java | 7 +++++++ .../nl/andrewl/aos2_server/PlayerManager.java | 2 ++ .../aos2_server/ProjectileManager.java | 2 ++ .../aos2_server/model/ServerPlayer.java | 19 +++++++++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java b/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java index bdf9fec..b0d6c84 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java +++ b/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java @@ -343,7 +343,7 @@ public class GuiRenderer { nvgFillColor(vgId, GuiUtils.rgba(0.7f, 0, 0, 1, colorA)); nvgText(vgId, 5, y, msg.message()); } else if (msg.author().equals("_PRIVATE")) { - nvgFillColor(vgId, GuiUtils.rgba(0.3f, 0.3f, 0.3f, 1, colorA)); + nvgFillColor(vgId, GuiUtils.rgba(0.6f, 0.6f, 0.6f, 1, colorA)); nvgText(vgId, 5, y, msg.message()); } else { nvgFillColor(vgId, GuiUtils.rgba(1, 1, 1, 1, colorA)); diff --git a/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java b/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java index f554afa..bac002c 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java +++ b/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java @@ -91,6 +91,13 @@ public class ClientCommunicationHandler { server.getPlayerManager().getHandler(teamPlayer).sendTcpMessage(chat); } } + } else if (chatWrittenMessage.message().equalsIgnoreCase("/kd")) { + int k = player.getKillCount(); + int d = player.getDeathCount(); + float kd = d <= 0 ? 0 : (float) k / (float) d; + sendTcpMessage(ChatMessage.privateMessage("Your kill/death ratio is %.2f.".formatted(kd))); + } else if (chatWrittenMessage.message().equalsIgnoreCase("/kill")) { + server.getPlayerManager().playerKilled(player, null); } else { server.getPlayerManager().broadcastTcpMessage(new ChatMessage( System.currentTimeMillis(), 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 1f9f1c6..33f23d8 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java @@ -169,11 +169,13 @@ public class PlayerManager { Vector3f deathPosition = new Vector3f(player.getPosition()); player.setPosition(getBestSpawnPoint(player)); player.setVelocity(new Vector3f(0)); + player.incrementDeathCount(); resupply(player); broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis())); broadcastUdpMessage(new SoundMessage("death", 1, deathPosition)); String deathMessage; if (killedBy != null) { + killedBy.incrementKillCount(); deathMessage = player.getUsername() + " was killed by " + killedBy.getUsername() + "."; } else { deathMessage = player.getUsername() + " died."; diff --git a/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java b/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java index 5c96a28..e1e0242 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java @@ -184,6 +184,8 @@ public class ProjectileManager { float damage = gun.getBaseDamage(); if (playerHitType == 1) damage *= 2; hitPlayer.setHealth(hitPlayer.getHealth() - damage); + Vector3f impactAcceleration = new Vector3f(projectile.getVelocity()).normalize().mul(3); + hitPlayer.getVelocity().add(impactAcceleration); int soundVariant = ThreadLocalRandom.current().nextInt(1, 4); server.getPlayerManager().broadcastUdpMessage(new SoundMessage("hurt_" + soundVariant, 1, hitPlayer.getPosition(), hitPlayer.getVelocity())); if (hitPlayer.getHealth() == 0) { diff --git a/server/src/main/java/nl/andrewl/aos2_server/model/ServerPlayer.java b/server/src/main/java/nl/andrewl/aos2_server/model/ServerPlayer.java index 708a67d..f3ed0ad 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/model/ServerPlayer.java +++ b/server/src/main/java/nl/andrewl/aos2_server/model/ServerPlayer.java @@ -28,6 +28,9 @@ public class ServerPlayer extends Player { */ private float health; + private int deathCount; + private int killCount; + public ServerPlayer(int id, String username) { super(id, username); this.inventory = new Inventory(new ArrayList<>(), 0); @@ -57,6 +60,22 @@ public class ServerPlayer extends Player { this.health = health; } + public int getDeathCount() { + return deathCount; + } + + public void incrementDeathCount() { + deathCount++; + } + + public int getKillCount() { + return killCount; + } + + public void incrementKillCount() { + killCount++; + } + /** * Helper method to build an update message for this player, to be sent to * various clients.