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

@ -1,9 +1,7 @@
package net.halfheart;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
static void main() {
public static void main(String[] args) {
}
}

View file

@ -0,0 +1,18 @@
package net.halfheart.ventricleengine;
public class AidModifier {
String name;
String stat;
String mod;
short value;
int duration;
public AidModifier(String name, String stat, String mod, short value, int duration) {
this.name = name;
this.stat = stat;
this.mod = mod;
this.value = value;
this.duration = duration;
}
}

View file

@ -0,0 +1,55 @@
package net.halfheart.ventricleengine;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.stream.Collectors;
public class AidModifierHandler {
private static AidModifier constructAidModifier(String aidModifierName) {
String filename = "/aid_modifiers.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(aidModifierName)) {
wantedItem = item;
}
}
assert wantedItem != null;
String name = wantedItem.opt("name").toString();
String stat = wantedItem.opt("stat").toString();
String mod = wantedItem.opt("mod").toString();
short value = (short) wantedItem.opt("value");
int duration = (int) wantedItem.opt("duration");
return new AidModifier(name, stat, mod, value, duration);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void applyAid(AidModifier modifier) {
if (modifier.stat.equals("hp")) {
char action = modifier.mod.charAt(0);
switch (action) {
case '+' -> PlayerHandler.PLAYER.hp = (short) (PlayerHandler.PLAYER.hp + modifier.value);
}
}
}
public static AidModifier STIMPAK = constructAidModifier("Stimpak");
}

View file

@ -6,7 +6,7 @@ public class Armor {
String name;
String description;
String resType;
List<byte[]> resistances;
List<Byte> resistances;
String resUnit;
short cost;
byte weight;
@ -15,7 +15,7 @@ public class Armor {
String name,
String description,
String resType,
List<byte[]> resistances,
List<Byte> resistances,
String resUnit,
short cost,
byte weight

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");
}

View file

@ -1,17 +1,23 @@
package net.halfheart.ventricleengine;
public class Item {
String name;
String description;
byte weight;
short cost;
boolean consumable;
String aidModifier;
public Item(
String name,
String description,
byte weight,
short cost,
boolean consumable,
String aidModifier
){
this.name = name;
this.description = description;
this.weight = weight;
this.cost = cost;
this.consumable = consumable;

View file

@ -0,0 +1,55 @@
package net.halfheart.ventricleengine;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.stream.Collectors;
import static net.halfheart.ventricleengine.AidModifierHandler.STIMPAK;
public class ItemsHandler {
private static Item constructItem(String weaponName) {
String filename = "/items.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();
String description = wantedItem.opt("desc").toString();
byte weight = (byte) wantedItem.opt("weight");
short cost = (short) wantedItem.opt("cost");
boolean consumable = (boolean) wantedItem.opt("consumable");
String aidModifier = wantedItem.opt("aidModifier").toString();
return new Item(name, description, weight, cost, consumable, aidModifier);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Item findItem(String itemName) {
return switch (itemName) {
case "Stimpak" -> STIMPAK;
default -> null;
};
}
public static Item STIMPAK = constructItem("Stimpak");
}

View file

@ -1,5 +1,4 @@
package net.halfheart.ventricleengine;
import java.util.ArrayList;
import java.util.List;
public class Player {
@ -27,9 +26,9 @@ public class Player {
int xp;
short level;
List<Weapon> weapons = new ArrayList<>();
List<Armor> armors = new ArrayList<>();
List<Item> items = new ArrayList<>();
List<Weapon> weapons;
List<Armor> armors;
List<Item> items;
public Player(
String name,
@ -49,7 +48,10 @@ public class Player {
byte radSeverity,
byte radPoints,
int xp,
short level
short level,
List<Weapon> weapons,
List<Armor> armors,
List<Item> items
)
{
this.name = name;
@ -70,5 +72,8 @@ public class Player {
this.radPoints = radPoints;
this.xp = xp;
this.level = level;
this.weapons = weapons;
this.armors = armors;
this.items = items;
}
}

View file

@ -1,21 +1,133 @@
package net.halfheart.ventricleengine;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import org.json.*;
public class PlayerHandler {
private static Player constructPlayer(String savePath) {
try {
String content = new String(Files.readAllBytes(Paths.get(savePath)));
JSONObject jsonObject = new JSONObject(content);
if (savePath.equals("none")) {
String name = "No Player Loaded!";
byte strength = 0;
byte perception = 0;
byte endurance = 0;
byte charisma = 0;
byte intelligence = 0;
byte agility = 0;
byte luck = 0;
short caps = 0;
short pwMoney = 0;
short hpCap = 0;
short hp = 0;
short food = 0;
boolean isRadiated = false;
byte radSeverity = 0;
byte radPoints = 0;
int xp = 0;
short level = 0;
List<Weapon> weaponList = new ArrayList<>();
List<Armor> armorList = new ArrayList<>();
List<Item> itemList = new ArrayList<>();
} catch (IOException e) {
throw new RuntimeException(e);
return new Player(
name,
strength,
perception,
endurance,
charisma,
intelligence,
agility,
luck,
caps,
pwMoney,
hpCap,
hp,
food,
isRadiated,
radSeverity,
radPoints,
xp,
level,
weaponList,
armorList,
itemList
);
} else {
try {
String content = new String(Files.readAllBytes(Paths.get(savePath)));
JSONObject saveData = new JSONObject(content);
String name = saveData.opt("name").toString();
byte strength = (byte) saveData.opt("strength");
byte perception = (byte) saveData.opt("perception");
byte endurance = (byte) saveData.opt("endurance");
byte charisma = (byte) saveData.opt("charisma");
byte intelligence = (byte) saveData.opt("intelligence");
byte agility = (byte) saveData.opt("agility");
byte luck = (byte) saveData.opt("luck");
short caps = (short) saveData.opt("caps");
short pwMoney = (short) saveData.opt("pwMoney");
short hpCap = (short) saveData.opt("hpCap");
short hp = (short) saveData.opt("hp");
short food = (short) saveData.opt("food");
boolean isRadiated = (boolean) saveData.opt("isRadiated");
byte radSeverity = (byte) saveData.opt("radSeverity");
byte radPoints = (byte) saveData.opt("radPoints");
int xp = (int) saveData.opt("xp");
short level = (short) saveData.opt("level");
JSONObject weapons = saveData.getJSONObject("weapons");
JSONObject armors = saveData.getJSONObject("armors");
JSONObject items = saveData.getJSONObject("items");
List<Weapon> weaponList = new ArrayList<>();
for (String key : weapons.keySet()) {
weaponList.add(WeaponsHandler.findWeapon(weapons.opt(key).toString()));
}
List<Armor> armorList = new ArrayList<>();
for (String key : armors.keySet()) {
armorList.add(ArmorsHandler.findArmor(armors.opt(key).toString()));
}
List<Item> itemList = new ArrayList<>();
for (String key : items.keySet()) {
itemList.add(ItemsHandler.findItem(items.opt(key).toString()));
}
return new Player(
name,
strength,
perception,
endurance,
charisma,
intelligence,
agility,
luck,
caps,
pwMoney,
hpCap,
hp,
food,
isRadiated,
radSeverity,
radPoints,
xp,
level,
weaponList,
armorList,
itemList
);
} catch (FileNotFoundException e) {
System.out.println("Save file not found at path: "+savePath);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return null;
}
public static Player PLAYER = constructPlayer("none");
}

View file

@ -2,6 +2,7 @@ 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;
@ -28,9 +29,6 @@ public class WeaponsHandler {
}
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();
@ -38,11 +36,38 @@ public class WeaponsHandler {
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) {
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
public static Weapon findWeapon(String weaponName) {
return switch (weaponName) {
case "Fists" -> FISTS;
case "Combat Knife" -> COMBATKNIFE;
case "Ripper" -> RIPPER;
case "Chainsaw" -> CHAINSAW;
case "Baseball Bat" -> BASEBALLBAT;
case "Power Fist" -> POWERFIST;
case "Super Sledge" -> SUPERSLEDGE;
case "10mm Pistol" -> PISTOL10MM;
case "Hunting Rifle" -> HUNTINGRIFLE;
default -> null;
};
}
public static void fistCalc() {
switch (PlayerHandler.PLAYER.strength){
case 0 -> {
FISTS.description = FISTS.description+"please don't.";
FISTS.damage = -2;
}
case (1|2|3|4) -> FISTS.description = FISTS.description+"a last resort.";
case (5|6|7|8) -> FISTS.description = FISTS.description+"use cautiously.";
case (9|10) -> FISTS.description = FISTS.description+"a formidable weapon.";
}
}
public static Weapon FISTS = constructWeapon("Fists");
public static Weapon COMBATKNIFE = constructWeapon("Combat Knife");
public static Weapon RIPPER = constructWeapon("Ripper");