Finished handlers

This commit is contained in:
Raktbastr 2026-05-15 16:18:51 -05:00
parent 43174bc73f
commit 7f821d7723
16 changed files with 621 additions and 42 deletions

View file

@ -2,14 +2,17 @@ package net.halfheart.ventricleengine;
import org.json.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class ArmorsHandler {
private static Armor constructArmor(String weaponName) {
private static Armor constructArmor(String armorName) {
String filename = "/armors.json";
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
String jsonText = new BufferedReader(
@ -22,25 +25,72 @@ public class ArmorsHandler {
JSONObject wantedItem = null;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject item = jsonArray.getJSONObject(i);
if (item.opt("name").toString().equals(weaponName)) {
if (item.opt("name").toString().equals(armorName)) {
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) {
JSONObject resistances = wantedItem.getJSONObject("resistances");
}
return null;
String name = wantedItem.opt("name").toString();
String description = wantedItem.opt("desc").toString();
String armorType = wantedItem.opt("type").toString();
String resUnit = wantedItem.opt("unit").toString();
List<Byte> resList = new ArrayList<>();
for (String key : resistances.keySet()) {
byte res = (byte) resistances.opt(key);
resList.add(res);
}
byte weight = (byte) wantedItem.opt("weight");
short cost = (short) wantedItem.opt("cost");
return new Armor(name, description, armorType, resList, resUnit, cost, weight);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Armor findArmor(String armorName) {
return switch (armorName) {
case "Nothing" -> NOTHING;
case "Leather Armor" -> LEATHERARMOR;
case "Sturdy Leather Armor" -> STURDYLEATHERARMOR;
case "Raider Armor" -> RAIDERARMOR;
case "Metal Armor" -> METALARMOR;
case "Combat Armor" -> COMBATARMOR;
case "Centurion Armor" -> CENTURIONARMOR;
case "NCR Ranger Armor" -> NCRRANGERARMOR;
case "T-45 Power Armor" -> T45POWERARMOR;
case "T-60 Power Armor" -> T60POWERARMOR;
case "T-65 Power Armor" -> T65POWERARMOR;
case "X-01 Power Armor" -> X01POWERARMOR;
case "APA MkI Power Armor" -> APAMKIORPOWERARMOR;
case "APA MkII Power Armor" -> APAMKIIPOWERARMOR;
case "Raider Power Armor" -> RAIDERPOWERARMOR;
case "Ultracite Power Armor" -> ULTRACITEPOWERARMOR;
case "T-51 Power Armor" -> T51POWERARMOR;
case "Enclave Uniform" -> ENCLAVEUNIFORM;
case "Excavator Power Armor" -> EXCAVATORPOWERARMOR;
default -> null;
};
}
public static Armor NOTHING = constructArmor("Nothing");
public static Armor LEATHERARMOR = constructArmor("Leather Armor");
public static Armor STURDYLEATHERARMOR = constructArmor("Sturdy Leather Armor");
public static Armor RAIDERARMOR = constructArmor("Raider Armor");
public static Armor METALARMOR = constructArmor("Metal Armor");
public static Armor COMBATARMOR = constructArmor("Combat Armor");
public static Armor CENTURIONARMOR = constructArmor("Centurion Armor");
public static Armor NCRRANGERARMOR = constructArmor("NCR Ranger Armor");
public static Armor T45POWERARMOR = constructArmor("T-45 Power Armor");
public static Armor T60POWERARMOR = constructArmor("T-60 Power Armor");
public static Armor T65POWERARMOR = constructArmor("T-65 Power Armor");
public static Armor X01POWERARMOR = constructArmor("X-01 Power Armor");
public static Armor APAMKIORPOWERARMOR = constructArmor("APA MkI Power Armor");
public static Armor APAMKIIPOWERARMOR = constructArmor("APA MkII Power Armor");
public static Armor RAIDERPOWERARMOR = constructArmor("Raider Power Armor");
public static Armor ULTRACITEPOWERARMOR = constructArmor("Ultracite Power Armor");
public static Armor T51POWERARMOR = constructArmor("T-51 Power Armor");
public static Armor ENCLAVEUNIFORM = constructArmor("Enclave Uniform");
public static Armor EXCAVATORPOWERARMOR = constructArmor("Excavator Power Armor");
}