Added logic to avoid collisions with non-normal players, and removed some old print statement.

This commit is contained in:
Andrew Lalis 2022-08-01 16:56:22 +02:00
parent 935cbd1393
commit 3dcf503338
3 changed files with 9 additions and 4 deletions

View File

@ -168,7 +168,6 @@ public class CommunicationHandler {
OtherPlayer player = new OtherPlayer(in.readInt(), in.readString()); OtherPlayer player = new OtherPlayer(in.readInt(), in.readString());
int teamId = in.readInt(); int teamId = in.readInt();
if (teamId != -1) player.setTeam(client.getTeams().get(teamId)); if (teamId != -1) player.setTeam(client.getTeams().get(teamId));
System.out.println(teamId);
player.getPosition().set(in.readFloat(), in.readFloat(), in.readFloat()); player.getPosition().set(in.readFloat(), in.readFloat(), in.readFloat());
player.getVelocity().set(in.readFloat(), in.readFloat(), in.readFloat()); player.getVelocity().set(in.readFloat(), in.readFloat(), in.readFloat());
player.getOrientation().set(in.readFloat(), in.readFloat()); player.getOrientation().set(in.readFloat(), in.readFloat());

View File

@ -5,6 +5,7 @@ import nl.andrewl.aos2_server.model.ServerPlayer;
import nl.andrewl.aos2_server.model.ServerProjectile; import nl.andrewl.aos2_server.model.ServerProjectile;
import nl.andrewl.aos_core.Directions; import nl.andrewl.aos_core.Directions;
import nl.andrewl.aos_core.model.Player; 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.Projectile;
import nl.andrewl.aos_core.model.item.Gun; import nl.andrewl.aos_core.model.item.Gun;
import nl.andrewl.aos_core.model.world.Hit; import nl.andrewl.aos_core.model.world.Hit;
@ -111,13 +112,17 @@ public class ProjectileManager {
ServerPlayer hitPlayer = null; ServerPlayer hitPlayer = null;
int playerHitType = -1; int playerHitType = -1;
for (ServerPlayer player : server.getPlayerManager().getPlayers()) { for (ServerPlayer player : server.getPlayerManager().getPlayers()) {
// Don't allow players to shoot themselves. // First, skip any players that can't be hit by bullets.
if (projectile.getPlayer() != null && projectile.getPlayer().equals(player)) continue;
// Don't check for collisions with team players, if friendly fire is disabled.
if ( 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 && !server.getConfig().actions.friendlyFire &&
projectile.getPlayer() != null && projectile.getPlayer().getTeam() != null && projectile.getPlayer() != null && projectile.getPlayer().getTeam() != null &&
projectile.getPlayer().getTeam().equals(player.getTeam()) projectile.getPlayer().getTeam().equals(player.getTeam())
)
) continue; ) continue;
Vector3f headPos = player.getEyePosition(); Vector3f headPos = player.getEyePosition();

View File

@ -21,6 +21,7 @@ public class PlayerModeCommand implements PlayerCommand {
server.getPlayerManager().setMode(player, mode); server.getPlayerManager().setMode(player, mode);
handler.sendTcpMessage(new ClientInventoryMessage(player.getInventory())); handler.sendTcpMessage(new ClientInventoryMessage(player.getInventory()));
server.getPlayerManager().broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis())); server.getPlayerManager().broadcastUdpMessage(player.getUpdateMessage(System.currentTimeMillis()));
handler.sendTcpMessage(ChatMessage.privateMessage("Your mode has been updated to " + mode.name() + "."));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
handler.sendTcpMessage(ChatMessage.privateMessage("Invalid mode. Should be NORMAL, CREATIVE, or SPECTATOR.")); handler.sendTcpMessage(ChatMessage.privateMessage("Invalid mode. Should be NORMAL, CREATIVE, or SPECTATOR."));
} }