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

2
.idea/misc.xml generated
View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="ms-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

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

View file

@ -0,0 +1,11 @@
[
{
"food": {
"name": "Stimpak",
"stat": "hp",
"mod": "+",
"value": "20",
"duration": 0
}
}
]

View file

@ -6,12 +6,246 @@
"resistances": {
"bash": 0,
"slash": 0,
"balistic": 0,
"ballistic": 0,
"laser": 0,
"plasma": 0
},
"unit": "dr",
"weight": 0,
"cost": -1
},
{
"name": "Leather Armor",
"desc": "A set of leather armor, good protection from laser weapons.",
"type": "armor",
"resistances": {
"ballistic": 2,
"slash": 2,
"laser": 5,
"plasma": 3},
"unit": "dr",
"cost": 5,
"weight": 5
},
{"name": "Sturdy Leather Armor",
"desc": "A set of combat armor, better protection from laser and plasma weapons.",
"type": "armor",
"resistances": {
"ballistic": 5,
"slash": 5,
"laser": 10,
"plasma": 10
},
"unit": "dr",
"cost": 5,
"weight": 5
},
{"name": "Raider Armor",
"desc": "A set of raider armor, good protection from ballistic damage.",
"type": "armor",
"resistances": {
"ballistic": 5,
"slash": 3,
"laser": 2,
"plasma": 2
},
"unit": "dr",
"cost": 5,
"weight": 5
},
{"name": "Metal Armor" ,
"desc": "A set of raider armor, better protection from ballistic and slash damage.",
"type": "armor",
"resistances": {
"ballistic": 10,
"slash": 10,
"laser": 5,
"plasma": 5
},
"unit": "dr",
"cost": 5,
"weight": 5
},
{"name": "Combat Armor",
"desc": "A set of combat armor, better protection from all damage types.",
"type": "armor",
"resistances": {
"ballistic": 10,
"slash": 10,
"laser": 10,
"plasma": 10
},
"unit": "dr",
"cost": 5,
"weight": 5
},
{"name": "Centurion Armor",
"desc": "A set of Centurion armor, great protection from ballistic damage.",
"type": "armor",
"resistances": {
"ballistic": 10,
"slash": 10,
"laser": 10,
"plasma": 10
},
"unit": "dr",
"cost": 25,
"weight": 25
},
{"name": "NCR Ranger Armor" ,
"desc": "A set of NCR Ranger armor, great protection from laser and plasma weapons",
"type": "armor",
"resistances": {
"ballistic": 10,
"slash": 10,
"laser": 10,
"plasma": 10
},
"unit": "dr",
"cost": 30,
"weight": 30
},
{"name": "T-45 Power Armor",
"desc": "A set of T-45 Power Armor, protects against all damage types.",
"type": "parmor",
"resistances": {
"ballistic": 15,
"slash": 15,
"laser": 15,
"plasma": 15
},
"unit": "dt",
"cost": 5,
"weight": 5
},
{"name": "T-60 Power Armor",
"desc": "A set of T-60 Power Armor, good protection from all damage types.",
"type": "parmor",
"resistances": {
"ballistic": 25,
"slash": 25,
"laser": 25,
"plasma": 25
},
"unit": "dt",
"cost": 5,
"weight": 5}
,
{"name": "T-65 Power Armor",
"desc": "A set of T-60 Power Armor, great protection from all damage types.",
"type": "parmor",
"resistances": {
"ballistic": 35,
"slash": 35,
"laser": 35,
"plasma": 35
},
"unit": "dt",
"cost": 5,
"weight": 5
},
{"name": "X-01 Power Armor",
"desc": "X-01 Power Armor, good protection from energy damage.",
"type": "parmor",
"resistances": {
"ballistic": 10,
"slash": 10,
"laser": 30,
"plasma": 30
},
"unit": "dt",
"cost": 5,
"weight": 5
},
{"name": "APA MkI Power Armor",
"desc": "APA MkI Power Armor, great protection from energy damage.",
"type": "parmor",
"resistances": {
"ballistic": 20,
"slash": 20,
"laser": 40,
"plasma": 40
},
"unit": "dt",
"cost": 5,
"weight": 5
},
{"name": "APA MkII Power Armor",
"desc": "APA MkII Power Armor, excellent protection from energy damage.",
"type": "parmor",
"resistances": {
"ballistic": 30,
"slash": 30,
"laser": 50,
"plasma": 50
},
"unit": "dt",
"cost": 5,
"weight": 5
},
{"name": "Raider Power Armor",
"desc": "Raider Power Armor, good protection from ballistic damage.",
"type": "parmor",
"resistances": {
"ballistic": 30,
"slash": 30,
"laser": 10,
"plasma": 10
},
"unit": "dt",
"cost": 5,
"weight": 5
},
{"name": "Ultracite Power Armor",
"desc": "Ultracite Power Armor, great protection from ballistic damage.",
"type": "parmor",
"resistances": {
"ballistic": 40,
"slash": 40,
"laser": 20,
"plasma": 20
},
"unit": "dt",
"cost": 5,
"weight": 5
},
{"name": "T-51 Power Armor",
"desc": "T-51 Power Armor, excellent protection from ballistic damage.",
"type": "parmor",
"resistances": {
"ballistic": 50,
"slash": 50,
"laser": 30,
"plasma": 30
},
"unit": "dt",
"cost": 5,
"weight": 5
},
{"name": "Enclave Uniform",
"desc": "Enclave uniform, standard issue",
"type": "armor",
"resistances": {
"ballistic": 0,
"slash": 0,
"laser": 0,
"plasma": 0
},
"unit": "dr",
"cost": 20,
"weight": 20
},
{"name": "Excavator Power Armor",
"desc": "Excavator Power Armor, +25% Chance to find extra loot",
"type": "parmor",
"resistances": {
"ballistic": 5,
"slash": 5,
"laser": 5,
"plasma": 5
},
"unit": "dt",
"cost": 5,
"weight": 5
}
]

View file

@ -0,0 +1,10 @@
[
{
"name": "Food",
"desc": "Yummy :).",
"weight": 0,
"cost": 0,
"consumable": true,
"aidModifier": "food"
}
]

View file

@ -73,7 +73,7 @@
},
{
"name": "Hunting Rifle",
"desc": "A hunting rifle, does 15 balistic damage",
"desc": "A hunting rifle, does 15 ballistic damage",
"type": "ballistic",
"ammo": "308",
"dmg": 10,