Began work on weapon armor and player handlers.
This commit is contained in:
commit
43174bc73f
22 changed files with 823 additions and 0 deletions
|
|
@ -0,0 +1,55 @@
|
|||
package net.halfheart.ventricleengine;
|
||||
import org.json.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WeaponsHandler {
|
||||
private static Weapon constructWeapon(String weaponName) {
|
||||
String filename = "/weapons.json";
|
||||
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
||||
String jsonText = new BufferedReader(
|
||||
new InputStreamReader(Objects.requireNonNull(inputStream), StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
JSONArray jsonArray = new JSONArray(jsonText);
|
||||
|
||||
JSONObject wantedItem = null;
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject item = jsonArray.getJSONObject(i);
|
||||
if (item.opt("name").toString().equals(weaponName)) {
|
||||
wantedItem = item;
|
||||
}
|
||||
}
|
||||
assert wantedItem != null;
|
||||
String name = wantedItem.opt("name").toString();
|
||||
if (name.equals("Fists")) {
|
||||
switch ()
|
||||
}
|
||||
String description = wantedItem.opt("desc").toString();
|
||||
String dmgType = wantedItem.opt("type").toString();
|
||||
String ammoType = wantedItem.opt("ammo").toString();
|
||||
short damage = (short) wantedItem.opt("dmg");
|
||||
short cost = (short) wantedItem.opt("cost");
|
||||
byte weight = (byte) wantedItem.opt("weight");
|
||||
return new Weapon(name, description, dmgType, ammoType, damage, cost, weight);
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static Weapon FISTS = constructWeapon("Fists");
|
||||
public static Weapon COMBATKNIFE = constructWeapon("Combat Knife");
|
||||
public static Weapon RIPPER = constructWeapon("Ripper");
|
||||
public static Weapon CHAINSAW = constructWeapon("Chainsaw");
|
||||
public static Weapon BASEBALLBAT = constructWeapon("Baseball Bat");
|
||||
public static Weapon POWERFIST = constructWeapon("Power Fist");
|
||||
public static Weapon SUPERSLEDGE = constructWeapon("Super Sledge");
|
||||
public static Weapon PISTOL10MM = constructWeapon("10mm Pistol");
|
||||
public static Weapon HUNTINGRIFLE = constructWeapon("Hunting Rifle");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue