diff --git a/client/src/main/java/nl/andrewl/aos2_client/control/InputHandler.java b/client/src/main/java/nl/andrewl/aos2_client/control/InputHandler.java index b4a22d2..5a89ba5 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/control/InputHandler.java +++ b/client/src/main/java/nl/andrewl/aos2_client/control/InputHandler.java @@ -31,6 +31,7 @@ public class InputHandler { if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) selectedInventoryIndex = 0; if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS) selectedInventoryIndex = 1; if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) selectedInventoryIndex = 2; + if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS) selectedInventoryIndex = 3; ClientInputState currentInputState = new ClientInputState( comm.getClientId(), diff --git a/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java b/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java index d8fb897..f079eaf 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java +++ b/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java @@ -66,6 +66,7 @@ public class SoundManager { load("footsteps_4", "sound/m_footsteps_4.wav"); load("shot_m1-garand_1", "sound/m_shot_m1-garand_1.wav"); load("shot_ak-47_1", "sound/m_shot_ak-47_1.wav"); + load("shot_winchester_1", "sound/m_shot_winchester_1.wav"); load("bullet_impact_1", "sound/m_bullet_impact_1.wav"); load("bullet_impact_2", "sound/m_bullet_impact_2.wav"); load("bullet_impact_3", "sound/m_bullet_impact_3.wav"); diff --git a/core/src/main/java/nl/andrewl/aos_core/model/item/ItemTypes.java b/core/src/main/java/nl/andrewl/aos_core/model/item/ItemTypes.java index b8e2080..8e0989f 100644 --- a/core/src/main/java/nl/andrewl/aos_core/model/item/ItemTypes.java +++ b/core/src/main/java/nl/andrewl/aos_core/model/item/ItemTypes.java @@ -2,6 +2,7 @@ package nl.andrewl.aos_core.model.item; import nl.andrewl.aos_core.model.item.gun.Ak47; import nl.andrewl.aos_core.model.item.gun.Rifle; +import nl.andrewl.aos_core.model.item.gun.Winchester; import java.util.HashMap; import java.util.Map; @@ -16,11 +17,13 @@ public final class ItemTypes { public static final BlockItem BLOCK = new BlockItem(1); public static final Rifle RIFLE = new Rifle(2); public static final Ak47 AK_47 = new Ak47(3); + public static final Winchester WINCHESTER = new Winchester(4); static { registerType(BLOCK); registerType(RIFLE); registerType(AK_47); + registerType(WINCHESTER); } public static void registerType(Item type) { diff --git a/core/src/main/java/nl/andrewl/aos_core/model/item/gun/Winchester.java b/core/src/main/java/nl/andrewl/aos_core/model/item/gun/Winchester.java new file mode 100644 index 0000000..7ea306b --- /dev/null +++ b/core/src/main/java/nl/andrewl/aos_core/model/item/gun/Winchester.java @@ -0,0 +1,21 @@ +package nl.andrewl.aos_core.model.item.gun; + +import nl.andrewl.aos_core.model.item.Gun; + +public class Winchester extends Gun { + public Winchester(int id) { + super( + id, + "Winchester", + 10, + 6, + 4, + 0.85f, + 0.75f, + 2.5f, + 0.3f, + 60f, + false + ); + } +} 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 5033bec..a0205bd 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java @@ -34,33 +34,39 @@ public class ProjectileManager { this.removalQueue = new LinkedList<>(); } - public void spawnBullet(ServerPlayer player, Gun gun) { - int id = nextProjectileId++; - if (nextProjectileId == Integer.MAX_VALUE) nextProjectileId = 1; + public void spawnBullets(ServerPlayer player, Gun gun) { Random rand = ThreadLocalRandom.current(); - Vector3f pos = new Vector3f(); - Matrix4f bulletTransform = new Matrix4f() - .translate(player.getEyePosition()) - .rotate(player.getOrientation().x + (float) Math.PI, Directions.UPf) - .translate(-0.35f, -0.4f, 0.35f); - bulletTransform.transformPosition(pos); + Vector3f direction = new Vector3f(); + Matrix4f bulletTransform = new Matrix4f(); - Vector3f direction = new Vector3f(player.getViewVector()).normalize(); - float accuracy = gun.getAccuracy(); - accuracy -= server.getConfig().actions.movementAccuracyDecreaseFactor * player.getVelocity().length(); - float perturbationFactor = (1 - accuracy) / 8; - direction.x += rand.nextGaussian(0, perturbationFactor); - direction.y += rand.nextGaussian(0, perturbationFactor); - direction.z += rand.nextGaussian(0, perturbationFactor); + for (int i = 0; i < gun.getBulletsPerRound(); i++) { + int id = nextProjectileId++; + if (nextProjectileId == Integer.MAX_VALUE) nextProjectileId = 1; - Vector3f vel = new Vector3f(direction).normalize() - .mul(200 * MOVEMENT_FACTOR) - .add(player.getVelocity()); + pos.set(0); + bulletTransform.identity() + .translate(player.getEyePosition()) + .rotate(player.getOrientation().x + (float) Math.PI, Directions.UPf) + .translate(-0.35f, -0.4f, 0.35f); + bulletTransform.transformPosition(pos); - ServerProjectile bullet = new ServerProjectile(id, pos, vel, Projectile.Type.BULLET, player); - projectiles.put(bullet.getId(), bullet); - server.getPlayerManager().broadcastUdpMessage(bullet.toMessage(false)); + direction.set(player.getViewVector()).normalize(); + float accuracy = gun.getAccuracy(); + accuracy -= server.getConfig().actions.movementAccuracyDecreaseFactor * player.getVelocity().length(); + float perturbationFactor = (1 - accuracy) / 8; + direction.x += rand.nextGaussian(0, perturbationFactor); + direction.y += rand.nextGaussian(0, perturbationFactor); + direction.z += rand.nextGaussian(0, perturbationFactor); + + Vector3f vel = new Vector3f(direction).normalize() + .mul(200 * MOVEMENT_FACTOR) + .add(player.getVelocity()); + + ServerProjectile bullet = new ServerProjectile(id, new Vector3f(pos), vel, Projectile.Type.BULLET, player); + projectiles.put(bullet.getId(), bullet); + server.getPlayerManager().broadcastUdpMessage(bullet.toMessage(false)); + } } public void tick(float dt) { diff --git a/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java b/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java index 6849c83..35cd9db 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java @@ -9,6 +9,7 @@ import nl.andrewl.aos_core.model.item.GunItemStack; import nl.andrewl.aos_core.model.item.ItemStack; import nl.andrewl.aos_core.model.item.gun.Ak47; import nl.andrewl.aos_core.model.item.gun.Rifle; +import nl.andrewl.aos_core.model.item.gun.Winchester; import nl.andrewl.aos_core.model.world.World; import nl.andrewl.aos_core.net.client.ClientInputState; import nl.andrewl.aos_core.net.client.InventorySelectedStackMessage; @@ -111,7 +112,7 @@ public class PlayerActionManager { now - gunLastShotAt > gun.getShotCooldownTime() * 1000 && (gun.isAutomatic() || !gunNeedsReCock) ) { - server.getProjectileManager().spawnBullet(player, gun); + server.getProjectileManager().spawnBullets(player, gun); g.setBulletCount(g.getBulletCount() - 1); gunLastShotAt = now; if (!gun.isAutomatic()) { @@ -123,6 +124,8 @@ public class PlayerActionManager { shotSound = "shot_m1-garand_1"; } else if (gun instanceof Ak47) { shotSound = "shot_ak-47_1"; + } else if (gun instanceof Winchester) { + shotSound = "shot_winchester_1"; } server.getPlayerManager().broadcastUdpMessage(new SoundMessage(shotSound, 1, player.getPosition(), player.getVelocity())); } 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 2182618..d6296dc 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 @@ -6,6 +6,7 @@ import nl.andrewl.aos_core.model.item.BlockItemStack; import nl.andrewl.aos_core.model.item.GunItemStack; import nl.andrewl.aos_core.model.item.Inventory; import nl.andrewl.aos_core.model.item.ItemTypes; +import nl.andrewl.aos_core.model.item.gun.Winchester; import nl.andrewl.aos_core.net.client.PlayerUpdateMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,8 +35,9 @@ public class ServerPlayer extends Player { this.health = 1f; this.actionManager = new PlayerActionManager(this); inventory.getItemStacks().add(new GunItemStack(ItemTypes.RIFLE)); - inventory.getItemStacks().add(new BlockItemStack(ItemTypes.BLOCK, 50, (byte) 1)); inventory.getItemStacks().add(new GunItemStack(ItemTypes.AK_47)); + inventory.getItemStacks().add(new GunItemStack(ItemTypes.WINCHESTER)); + inventory.getItemStacks().add(new BlockItemStack(ItemTypes.BLOCK, 50, (byte) 1)); } public PlayerActionManager getActionManager() {