Added recoil.

This commit is contained in:
Andrew Lalis 2021-07-07 17:56:57 +02:00
parent 4481f1c028
commit 0e926d628a
10 changed files with 96 additions and 48 deletions

View File

@ -105,22 +105,7 @@ public class PublicServerListModel extends AbstractListModel<PublicServerInfo> {
this.currentOrderDir = json.get("orderDirection").asText(); this.currentOrderDir = json.get("orderDirection").asText();
this.currentPageItems.clear(); this.currentPageItems.clear();
for (Iterator<JsonNode> it = json.get("contents").elements(); it.hasNext();) { for (Iterator<JsonNode> it = json.get("contents").elements(); it.hasNext();) {
JsonNode node = it.next(); this.addServerInfoFromJson(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.fireContentsChanged(this, 0, this.getSize()); this.fireContentsChanged(this, 0, this.getSize());
} catch (IOException e) { } catch (IOException e) {
@ -155,6 +140,24 @@ public class PublicServerListModel extends AbstractListModel<PublicServerInfo> {
return this.currentPageItems.get(index); 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() { public void dispose() {
this.executorService.shutdown(); this.executorService.shutdown();
} }

View File

@ -3,7 +3,8 @@ package nl.andrewlalis.aos_core.model.tools;
public enum GunCategory { public enum GunCategory {
SHOTGUN(0), SHOTGUN(0),
SMG(1), SMG(1),
RIFLE(2); RIFLE(2),
MACHINE(3);
private final byte code; private final byte code;

View File

@ -52,8 +52,12 @@ public class GunType implements Serializable {
* How much damage the bullet does for a direct hit. * How much damage the bullet does for a direct hit.
*/ */
private final float baseDamage; 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.name = name;
this.category = category; this.category = category;
this.color = color; this.color = color;
@ -65,6 +69,7 @@ public class GunType implements Serializable {
this.reloadTime = reloadTime; this.reloadTime = reloadTime;
this.bulletSpeed = bulletSpeed; this.bulletSpeed = bulletSpeed;
this.baseDamage = baseDamage; this.baseDamage = baseDamage;
this.recoil = recoil;
} }
public String getName() { public String getName() {
@ -110,4 +115,8 @@ public class GunType implements Serializable {
public float getBaseDamage() { public float getBaseDamage() {
return baseDamage; return baseDamage;
} }
public float getRecoil() {
return recoil;
}
} }

View File

@ -8,26 +8,26 @@ import java.util.Map;
* efficient transmission to clients. * efficient transmission to clients.
*/ */
public enum SoundType { public enum SoundType {
SHOT_SMG(0, "ak47shot1.wav", 25), SHOT_SMG(0, "ak47shot1.wav"),
SHOT_RIFLE(1, "m1garand-shot1.wav", 25), SHOT_RIFLE(1, "m1garand-shot1.wav"),
SHOT_SHOTGUN(2, "shotgun-shot1.wav", 25), SHOT_SHOTGUN(2, "shotgun-shot1.wav"),
RELOAD(3, "reload.wav", 10), SHOT_MACHINE_GUN_1(11, "machine_gun-shot1.wav"),
CHAT(4, "chat.wav", 5), SHOT_MACHINE_GUN_2(12, "machine_gun-shot2.wav"),
DEATH(5, "death.wav", 5), RELOAD(3, "reload.wav"),
BULLET_IMPACT_1(6, "bullet_impact_1.wav", 10), CHAT(4, "chat.wav"),
BULLET_IMPACT_2(7, "bullet_impact_2.wav", 10), DEATH(5, "death.wav"),
BULLET_IMPACT_3(8, "bullet_impact_3.wav", 10), BULLET_IMPACT_1(6, "bullet_impact_1.wav"),
BULLET_IMPACT_4(9, "bullet_impact_4.wav", 10), BULLET_IMPACT_2(7, "bullet_impact_2.wav"),
BULLET_IMPACT_5(10, "bullet_impact_5.wav", 10); 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 byte code;
private final String soundName; 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.code = (byte) code;
this.soundName = soundName; this.soundName = soundName;
this.clipBufferCount = clipBufferCount;
} }
public byte getCode() { public byte getCode() {
@ -38,10 +38,6 @@ public enum SoundType {
return soundName; return soundName;
} }
public int getClipBufferCount() {
return clipBufferCount;
}
private static final Map<Byte, SoundType> typeIndex = new HashMap<>(); private static final Map<Byte, SoundType> typeIndex = new HashMap<>();
static { static {
for (var val : values()) { for (var val : values()) {

View File

@ -71,7 +71,8 @@ public class Server {
gs.getShotCooldownTime(), gs.getShotCooldownTime(),
gs.getReloadTime(), gs.getReloadTime(),
gs.getBulletSpeed(), gs.getBulletSpeed(),
gs.getBaseDamage() gs.getBaseDamage(),
gs.getRecoil()
)); ));
} }

View File

@ -195,9 +195,12 @@ public class WorldUpdater extends Thread {
soundType = SoundType.SHOT_RIFLE; soundType = SoundType.SHOT_RIFLE;
} else if (p.getGun().getType().getCategory() == GunCategory.SHOTGUN) { } else if (p.getGun().getType().getCategory() == GunCategory.SHOTGUN) {
soundType = SoundType.SHOT_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)); this.worldUpdate.addSound(new Sound(p.getPosition(), 1.0f, soundType));
p.useWeapon(); p.useWeapon();
p.setVelocity(p.getVelocity().add(p.getOrientation().mul(-1 * p.getGun().getType().getRecoil())));
} }
if (p.getState().isReloading() && !p.isReloading() && p.getGun().canReload()) { if (p.getState().isReloading() && !p.isReloading() && p.getGun().canReload()) {
p.startReloading(); p.startReloading();

View File

@ -12,6 +12,7 @@ public class GunSettings {
private float reloadTime; private float reloadTime;
private float bulletSpeed; private float bulletSpeed;
private float baseDamage; private float baseDamage;
private float recoil;
public String getName() { public String getName() {
return name; return name;
@ -56,4 +57,8 @@ public class GunSettings {
public float getBaseDamage() { public float getBaseDamage() {
return baseDamage; return baseDamage;
} }
public float getRecoil() {
return recoil;
}
} }

View File

@ -72,20 +72,47 @@ team-settings:
# The list of available guns are defined in this list. # The list of available guns are defined in this list.
gun-settings: 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 category: SMG
color: "#2e2b26" color: "#ffc619"
max-clip-count: 4 max-clip-count: 5
clip-size: 30 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 bullets-per-round: 1
accuracy: 0.10 accuracy: 0.10
shot-cooldown-time: 0.05 shot-cooldown-time: 0.04
reload-time: 1.2 reload-time: 3
bullet-speed: 90 bullet-speed: 60
base-damage: 40 base-damage: 1
recoil: 0.25
- name: M-249 - name: M-249
category: SMG category: MACHINE
color: "#001942" color: "#001942"
max-clip-count: 3 max-clip-count: 3
clip-size: 100 clip-size: 100
@ -95,6 +122,7 @@ gun-settings:
reload-time: 3.5 reload-time: 3.5
bullet-speed: 80 bullet-speed: 80
base-damage: 35 base-damage: 35
recoil: 2
- name: M1 Garand - name: M1 Garand
category: RIFLE category: RIFLE
@ -107,15 +135,17 @@ gun-settings:
reload-time: 0.75 reload-time: 0.75
bullet-speed: 150 bullet-speed: 150
base-damage: 100 base-damage: 100
recoil: 20
- name: Winchester - name: Winchester
category: SHOTGUN category: SHOTGUN
color: "#1a1205" color: "#1a1205"
max-clip-count: 8 max-clip-count: 8
clip-size: 6 clip-size: 6
bullets-per-round: 3 bullets-per-round: 5
accuracy: 0.15 accuracy: 0.15
shot-cooldown-time: 0.5 shot-cooldown-time: 0.5
reload-time: 2.0 reload-time: 2.0
bullet-speed: 75 bullet-speed: 75
base-damage: 80 base-damage: 80
recoil: 40