diff --git a/client/src/main/java/nl/andrewlalis/aos_client/launcher/servers/PublicServerListModel.java b/client/src/main/java/nl/andrewlalis/aos_client/launcher/servers/PublicServerListModel.java index 76eea6a..6e2b26a 100644 --- a/client/src/main/java/nl/andrewlalis/aos_client/launcher/servers/PublicServerListModel.java +++ b/client/src/main/java/nl/andrewlalis/aos_client/launcher/servers/PublicServerListModel.java @@ -105,22 +105,7 @@ public class PublicServerListModel extends AbstractListModel { this.currentOrderDir = json.get("orderDirection").asText(); this.currentPageItems.clear(); for (Iterator it = json.get("contents").elements(); it.hasNext();) { - JsonNode node = it.next(); - Image icon = null; - JsonNode iconNode = node.get("icon"); - if (iconNode != null && iconNode.getNodeType() == JsonNodeType.STRING) { - icon = ImageIO.read(new ByteArrayInputStream(Base64.getUrlDecoder().decode(iconNode.textValue()))); - } - PublicServerInfo info = new PublicServerInfo( - node.get("name").asText(), - node.get("address").asText(), - node.get("description").asText(), - node.get("location").asText(), - icon, - node.get("maxPlayers").asInt(), - node.get("currentPlayers").asInt() - ); - this.currentPageItems.add(info); + this.addServerInfoFromJson(it.next()); } this.fireContentsChanged(this, 0, this.getSize()); } catch (IOException e) { @@ -155,6 +140,24 @@ public class PublicServerListModel extends AbstractListModel { return this.currentPageItems.get(index); } + public void addServerInfoFromJson(JsonNode node) throws IOException { + Image icon = null; + JsonNode iconNode = node.get("icon"); + if (iconNode != null && iconNode.getNodeType() == JsonNodeType.STRING) { + icon = ImageIO.read(new ByteArrayInputStream(Base64.getUrlDecoder().decode(iconNode.textValue()))); + } + PublicServerInfo info = new PublicServerInfo( + node.get("name").asText(), + node.get("address").asText(), + node.get("description").asText(), + node.get("location").asText(), + icon, + node.get("maxPlayers").asInt(), + node.get("currentPlayers").asInt() + ); + this.currentPageItems.add(info); + } + public void dispose() { this.executorService.shutdown(); } diff --git a/client/src/main/resources/nl/andrewlalis/aos_client/sound/machine_gun-shot1.wav b/client/src/main/resources/nl/andrewlalis/aos_client/sound/machine_gun-shot1.wav new file mode 100644 index 0000000..4479717 Binary files /dev/null and b/client/src/main/resources/nl/andrewlalis/aos_client/sound/machine_gun-shot1.wav differ diff --git a/client/src/main/resources/nl/andrewlalis/aos_client/sound/machine_gun-shot2.wav b/client/src/main/resources/nl/andrewlalis/aos_client/sound/machine_gun-shot2.wav new file mode 100644 index 0000000..374231b Binary files /dev/null and b/client/src/main/resources/nl/andrewlalis/aos_client/sound/machine_gun-shot2.wav differ diff --git a/core/src/main/java/nl/andrewlalis/aos_core/model/tools/GunCategory.java b/core/src/main/java/nl/andrewlalis/aos_core/model/tools/GunCategory.java index 815259d..c50ebef 100644 --- a/core/src/main/java/nl/andrewlalis/aos_core/model/tools/GunCategory.java +++ b/core/src/main/java/nl/andrewlalis/aos_core/model/tools/GunCategory.java @@ -3,7 +3,8 @@ package nl.andrewlalis.aos_core.model.tools; public enum GunCategory { SHOTGUN(0), SMG(1), - RIFLE(2); + RIFLE(2), + MACHINE(3); private final byte code; diff --git a/core/src/main/java/nl/andrewlalis/aos_core/model/tools/GunType.java b/core/src/main/java/nl/andrewlalis/aos_core/model/tools/GunType.java index 82e1141..27cae1e 100644 --- a/core/src/main/java/nl/andrewlalis/aos_core/model/tools/GunType.java +++ b/core/src/main/java/nl/andrewlalis/aos_core/model/tools/GunType.java @@ -52,8 +52,12 @@ public class GunType implements Serializable { * How much damage the bullet does for a direct hit. */ private final float baseDamage; + /** + * How fast the gun pushes the player backwards when shot (in m/s). + */ + private final float recoil; - public GunType(String name, GunCategory category, String color, int maxClipCount, int clipSize, int bulletsPerRound, float accuracy, float shotCooldownTime, float reloadTime, float bulletSpeed, float baseDamage) { + public GunType(String name, GunCategory category, String color, int maxClipCount, int clipSize, int bulletsPerRound, float accuracy, float shotCooldownTime, float reloadTime, float bulletSpeed, float baseDamage, float recoil) { this.name = name; this.category = category; this.color = color; @@ -65,6 +69,7 @@ public class GunType implements Serializable { this.reloadTime = reloadTime; this.bulletSpeed = bulletSpeed; this.baseDamage = baseDamage; + this.recoil = recoil; } public String getName() { @@ -110,4 +115,8 @@ public class GunType implements Serializable { public float getBaseDamage() { return baseDamage; } + + public float getRecoil() { + return recoil; + } } diff --git a/core/src/main/java/nl/andrewlalis/aos_core/net/data/SoundType.java b/core/src/main/java/nl/andrewlalis/aos_core/net/data/SoundType.java index a936299..57a4780 100644 --- a/core/src/main/java/nl/andrewlalis/aos_core/net/data/SoundType.java +++ b/core/src/main/java/nl/andrewlalis/aos_core/net/data/SoundType.java @@ -8,26 +8,26 @@ import java.util.Map; * efficient transmission to clients. */ public enum SoundType { - SHOT_SMG(0, "ak47shot1.wav", 25), - SHOT_RIFLE(1, "m1garand-shot1.wav", 25), - SHOT_SHOTGUN(2, "shotgun-shot1.wav", 25), - RELOAD(3, "reload.wav", 10), - CHAT(4, "chat.wav", 5), - DEATH(5, "death.wav", 5), - BULLET_IMPACT_1(6, "bullet_impact_1.wav", 10), - BULLET_IMPACT_2(7, "bullet_impact_2.wav", 10), - BULLET_IMPACT_3(8, "bullet_impact_3.wav", 10), - BULLET_IMPACT_4(9, "bullet_impact_4.wav", 10), - BULLET_IMPACT_5(10, "bullet_impact_5.wav", 10); + SHOT_SMG(0, "ak47shot1.wav"), + SHOT_RIFLE(1, "m1garand-shot1.wav"), + SHOT_SHOTGUN(2, "shotgun-shot1.wav"), + SHOT_MACHINE_GUN_1(11, "machine_gun-shot1.wav"), + SHOT_MACHINE_GUN_2(12, "machine_gun-shot2.wav"), + RELOAD(3, "reload.wav"), + CHAT(4, "chat.wav"), + DEATH(5, "death.wav"), + BULLET_IMPACT_1(6, "bullet_impact_1.wav"), + BULLET_IMPACT_2(7, "bullet_impact_2.wav"), + BULLET_IMPACT_3(8, "bullet_impact_3.wav"), + BULLET_IMPACT_4(9, "bullet_impact_4.wav"), + BULLET_IMPACT_5(10, "bullet_impact_5.wav"); private final byte code; private final String soundName; - private final int clipBufferCount; - SoundType(int code, String soundName, int clipBufferCount) { + SoundType(int code, String soundName) { this.code = (byte) code; this.soundName = soundName; - this.clipBufferCount = clipBufferCount; } public byte getCode() { @@ -38,10 +38,6 @@ public enum SoundType { return soundName; } - public int getClipBufferCount() { - return clipBufferCount; - } - private static final Map typeIndex = new HashMap<>(); static { for (var val : values()) { diff --git a/server/src/main/java/nl/andrewlalis/aos_server/Server.java b/server/src/main/java/nl/andrewlalis/aos_server/Server.java index 30690a9..6d45b73 100644 --- a/server/src/main/java/nl/andrewlalis/aos_server/Server.java +++ b/server/src/main/java/nl/andrewlalis/aos_server/Server.java @@ -71,7 +71,8 @@ public class Server { gs.getShotCooldownTime(), gs.getReloadTime(), gs.getBulletSpeed(), - gs.getBaseDamage() + gs.getBaseDamage(), + gs.getRecoil() )); } diff --git a/server/src/main/java/nl/andrewlalis/aos_server/WorldUpdater.java b/server/src/main/java/nl/andrewlalis/aos_server/WorldUpdater.java index 87ee570..dce84cf 100644 --- a/server/src/main/java/nl/andrewlalis/aos_server/WorldUpdater.java +++ b/server/src/main/java/nl/andrewlalis/aos_server/WorldUpdater.java @@ -195,9 +195,12 @@ public class WorldUpdater extends Thread { soundType = SoundType.SHOT_RIFLE; } else if (p.getGun().getType().getCategory() == GunCategory.SHOTGUN) { soundType = SoundType.SHOT_SHOTGUN; + } else if (p.getGun().getType().getCategory() == GunCategory.MACHINE) { + soundType = ThreadLocalRandom.current().nextFloat() < 0.8f ? SoundType.SHOT_MACHINE_GUN_1 : SoundType.SHOT_MACHINE_GUN_2; } this.worldUpdate.addSound(new Sound(p.getPosition(), 1.0f, soundType)); p.useWeapon(); + p.setVelocity(p.getVelocity().add(p.getOrientation().mul(-1 * p.getGun().getType().getRecoil()))); } if (p.getState().isReloading() && !p.isReloading() && p.getGun().canReload()) { p.startReloading(); diff --git a/server/src/main/java/nl/andrewlalis/aos_server/settings/GunSettings.java b/server/src/main/java/nl/andrewlalis/aos_server/settings/GunSettings.java index ad7b85f..561111b 100644 --- a/server/src/main/java/nl/andrewlalis/aos_server/settings/GunSettings.java +++ b/server/src/main/java/nl/andrewlalis/aos_server/settings/GunSettings.java @@ -12,6 +12,7 @@ public class GunSettings { private float reloadTime; private float bulletSpeed; private float baseDamage; + private float recoil; public String getName() { return name; @@ -56,4 +57,8 @@ public class GunSettings { public float getBaseDamage() { return baseDamage; } + + public float getRecoil() { + return recoil; + } } diff --git a/server/src/main/resources/default_settings.yaml b/server/src/main/resources/default_settings.yaml index d1a5ba9..2cb42a8 100644 --- a/server/src/main/resources/default_settings.yaml +++ b/server/src/main/resources/default_settings.yaml @@ -72,20 +72,47 @@ team-settings: # The list of available guns are defined in this list. gun-settings: - - name: AK-47 + - name: AK-47 # The name of the gun. + category: SMG # The category of gun. This affects sounds base functionality. + color: "#2e2b26" # The color of the gun in the player's hand. + max-clip-count: 4 # The maximum number of clips which a player can hold for this gun. + clip-size: 30 # The number of rounds in each clip. + bullets-per-round: 1 # The number of bullets spawned for each round fired. + accuracy: 0.10 # The accuracy of the gun, or rather deviation. Increase this to decrease accuracy. + shot-cooldown-time: 0.05 # How many seconds to wait after shooting before you can shoot again. + reload-time: 1.2 # How many seconds to wait while reloading. + bullet-speed: 90 # How fast the bullets from this gun fly, in meters per second. + base-damage: 40 # The amount of damage that bullets from this gun do, assuming a direct hit. + recoil: 3 # How much the player is pushed back after each shot, in meters per second. + + - name: Nerf Blaster category: SMG - color: "#2e2b26" - max-clip-count: 4 - clip-size: 30 + color: "#ffc619" + max-clip-count: 5 + clip-size: 16 + bullets-per-round: 1 + accuracy: 0.20 + shot-cooldown-time: 0.25 + reload-time: 1.0 + bullet-speed: 40 + base-damage: 1 + recoil: 0.25 + + - name: Nerf Infiniblaster + category: MACHINE + color: "#b52bff" + max-clip-count: 3 + clip-size: 500 bullets-per-round: 1 accuracy: 0.10 - shot-cooldown-time: 0.05 - reload-time: 1.2 - bullet-speed: 90 - base-damage: 40 + shot-cooldown-time: 0.04 + reload-time: 3 + bullet-speed: 60 + base-damage: 1 + recoil: 0.25 - name: M-249 - category: SMG + category: MACHINE color: "#001942" max-clip-count: 3 clip-size: 100 @@ -95,6 +122,7 @@ gun-settings: reload-time: 3.5 bullet-speed: 80 base-damage: 35 + recoil: 2 - name: M1 Garand category: RIFLE @@ -107,15 +135,17 @@ gun-settings: reload-time: 0.75 bullet-speed: 150 base-damage: 100 + recoil: 20 - name: Winchester category: SHOTGUN color: "#1a1205" max-clip-count: 8 clip-size: 6 - bullets-per-round: 3 + bullets-per-round: 5 accuracy: 0.15 shot-cooldown-time: 0.5 reload-time: 2.0 bullet-speed: 75 - base-damage: 80 \ No newline at end of file + base-damage: 80 + recoil: 40 \ No newline at end of file