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,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;
}
}