From 3dcf503338573c1ce580c08177bfcfbcd546e5ce Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Mon, 1 Aug 2022 16:56:22 +0200 Subject: [PATCH] Added logic to avoid collisions with non-normal players, and removed some old print statement. --- .../nl/andrewl/aos2_client/CommunicationHandler.java | 1 - .../nl/andrewl/aos2_server/ProjectileManager.java | 11 ++++++++--- .../cli/ingame/commands/PlayerModeCommand.java | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/nl/andrewl/aos2_client/CommunicationHandler.java b/client/src/main/java/nl/andrewl/aos2_client/CommunicationHandler.java index c092704..1b6e832 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/CommunicationHandler.java +++ b/client/src/main/java/nl/andrewl/aos2_client/CommunicationHandler.java @@ -168,7 +168,6 @@ public class CommunicationHandler { OtherPlayer player = new OtherPlayer(in.readInt(), in.readString()); int teamId = in.readInt(); if (teamId != -1) player.setTeam(client.getTeams().get(teamId)); - System.out.println(teamId); player.getPosition().set(in.readFloat(), in.readFloat(), in.readFloat()); player.getVelocity().set(in.readFloat(), in.readFloat(), in.readFloat()); player.getOrientation().set(in.readFloat(), in.readFloat()); 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 6b59bf5..b23873b 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java @@ -5,6 +5,7 @@ import nl.andrewl.aos2_server.model.ServerPlayer; import nl.andrewl.aos2_server.model.ServerProjectile; import nl.andrewl.aos_core.Directions; import nl.andrewl.aos_core.model.Player; +import nl.andrewl.aos_core.model.PlayerMode; import nl.andrewl.aos_core.model.Projectile; import nl.andrewl.aos_core.model.item.Gun; import nl.andrewl.aos_core.model.world.Hit; @@ -111,13 +112,17 @@ public class ProjectileManager { ServerPlayer hitPlayer = null; int playerHitType = -1; for (ServerPlayer player : server.getPlayerManager().getPlayers()) { - // Don't allow players to shoot themselves. - if (projectile.getPlayer() != null && projectile.getPlayer().equals(player)) continue; - // Don't check for collisions with team players, if friendly fire is disabled. + // First, skip any players that can't be hit by bullets. if ( + // Only normal players can be hit. + player.getMode() != PlayerMode.NORMAL || + // Don't allow players to shoot themselves. + (projectile.getPlayer() != null && projectile.getPlayer().equals(player)) || + (// If friendly fire is disabled, don't allow it! !server.getConfig().actions.friendlyFire && projectile.getPlayer() != null && projectile.getPlayer().getTeam() != null && projectile.getPlayer().getTeam().equals(player.getTeam()) + ) ) continue; Vector3f headPos = player.getEyePosition(); diff --git a/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/commands/PlayerModeCommand.java b/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/commands/PlayerModeCommand.java index 141bc2f..0aa84cd 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/commands/PlayerModeCommand.java +++ b/server/src/main/java/nl/andrewl/aos2_server/cli/ingame/commands/PlayerModeCommand.java @@ -21,6 +21,7 @@ public class PlayerModeCommand implements PlayerCommand { server.getPlayerManager().setMode(player, mode); handler.sendTcpMessage(new ClientInventoryMessage(player.getInventory())); server.getPlayerManager().broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis())); + handler.sendTcpMessage(ChatMessage.privateMessage("Your mode has been updated to " + mode.name() + ".")); } catch (IllegalArgumentException e) { handler.sendTcpMessage(ChatMessage.privateMessage("Invalid mode. Should be NORMAL, CREATIVE, or SPECTATOR.")); }