Began work on weapon armor and player handlers.

This commit is contained in:
Raktbastr 2026-05-15 16:18:51 -05:00
commit 43174bc73f
22 changed files with 823 additions and 0 deletions

View file

@ -0,0 +1,9 @@
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() {
}
}

View file

@ -0,0 +1,32 @@
package net.halfheart.ventricleengine;
import java.util.List;
public class Armor {
String name;
String description;
String resType;
List<byte[]> resistances;
String resUnit;
short cost;
byte weight;
public Armor(
String name,
String description,
String resType,
List<byte[]> resistances,
String resUnit,
short cost,
byte weight
)
{
this.name = name;
this.description = description;
this.resType = resType;
this.resistances = resistances;
this.resUnit = resUnit;
this.cost = cost;
this.weight = weight;
}
}

View file

@ -0,0 +1,46 @@
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 ArmorsHandler {
private static Armor constructArmor(String weaponName) {
String filename = "/armors.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;
}
}

View file

@ -0,0 +1,21 @@
package net.halfheart.ventricleengine;
public class Item {
byte weight;
short cost;
boolean consumable;
String aidModifier;
public Item(
byte weight,
short cost,
boolean consumable,
String aidModifier
){
this.weight = weight;
this.cost = cost;
this.consumable = consumable;
this.aidModifier = aidModifier;
}
}

View file

@ -0,0 +1,74 @@
package net.halfheart.ventricleengine;
import java.util.ArrayList;
import java.util.List;
public class Player {
String name;
byte strength;
byte perception;
byte endurance;
byte charisma;
byte intelligence;
byte agility;
byte luck;
short caps;
short pwMoney;
short hpCap;
short hp;
short food;
boolean isRadiated;
byte radSeverity;
byte radPoints;
int xp;
short level;
List<Weapon> weapons = new ArrayList<>();
List<Armor> armors = new ArrayList<>();
List<Item> items = new ArrayList<>();
public Player(
String name,
byte strength,
byte perception,
byte endurance,
byte charisma,
byte intelligence,
byte agility,
byte luck,
short caps,
short pwMoney,
short hpCap,
short hp,
short food,
boolean isRadiated,
byte radSeverity,
byte radPoints,
int xp,
short level
)
{
this.name = name;
this.strength = strength;
this.perception = perception;
this.endurance = endurance;
this.charisma = charisma;
this.intelligence = intelligence;
this.agility = agility;
this.luck = luck;
this.caps = caps;
this.pwMoney = pwMoney;
this.hpCap = hpCap;
this.hp = hp;
this.food = food;
this.isRadiated = isRadiated;
this.radSeverity = radSeverity;
this.radPoints = radPoints;
this.xp = xp;
this.level = level;
}
}

View file

@ -0,0 +1,21 @@
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 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);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -0,0 +1,30 @@
package net.halfheart.ventricleengine;
public class Weapon {
String name;
String description;
String dmgType;
String ammoType;
short damage;
short cost;
byte weight;
public Weapon(
String name,
String description,
String dmgType,
String ammoType,
short damage,
short cost,
byte weight
)
{
this.name = name;
this.description = description;
this.dmgType = dmgType;
this.ammoType = ammoType;
this.damage = damage;
this.cost = cost;
this.weight = weight;
}
}

View file

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