Refactoring and comments.
This commit is contained in:
parent
7f821d7723
commit
05a97e072a
18 changed files with 333 additions and 277 deletions
7
.idea/dictionaries/project.xml
generated
Normal file
7
.idea/dictionaries/project.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="project">
|
||||||
|
<words>
|
||||||
|
<w>Stimpak</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
47
src/main/java/net/halfheart/lonesomeroad/ID.java
Normal file
47
src/main/java/net/halfheart/lonesomeroad/ID.java
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
package net.halfheart.lonesomeroad;
|
||||||
|
|
||||||
|
import net.halfheart.ventricleengine.objects.*;
|
||||||
|
import net.halfheart.ventricleengine.WeaponsHandler;
|
||||||
|
import net.halfheart.ventricleengine.ArmorsHandler;
|
||||||
|
import net.halfheart.ventricleengine.AidModifierHandler;
|
||||||
|
import net.halfheart.ventricleengine.ItemsHandler;
|
||||||
|
import net.halfheart.ventricleengine.PlayerHandler;
|
||||||
|
|
||||||
|
|
||||||
|
public record ID() {
|
||||||
|
public static Weapon FISTS = WeaponsHandler.constructWeapon("Fists");
|
||||||
|
public static Weapon COMBATKNIFE = WeaponsHandler.constructWeapon("Combat Knife");
|
||||||
|
public static Weapon RIPPER = WeaponsHandler.constructWeapon("Ripper");
|
||||||
|
public static Weapon CHAINSAW = WeaponsHandler.constructWeapon("Chainsaw");
|
||||||
|
public static Weapon BASEBALLBAT = WeaponsHandler.constructWeapon("Baseball Bat");
|
||||||
|
public static Weapon POWERFIST = WeaponsHandler.constructWeapon("Power Fist");
|
||||||
|
public static Weapon SUPERSLEDGE = WeaponsHandler.constructWeapon("Super Sledge");
|
||||||
|
public static Weapon PISTOL10MM = WeaponsHandler.constructWeapon("10mm Pistol");
|
||||||
|
public static Weapon HUNTINGRIFLE = WeaponsHandler.constructWeapon("Hunting Rifle");
|
||||||
|
|
||||||
|
public static Armor NOTHING = ArmorsHandler.constructArmor("Nothing");
|
||||||
|
public static Armor LEATHERARMOR = ArmorsHandler.constructArmor("Leather Armor");
|
||||||
|
public static Armor STURDYLEATHERARMOR = ArmorsHandler.constructArmor("Sturdy Leather Armor");
|
||||||
|
public static Armor RAIDERARMOR = ArmorsHandler.constructArmor("Raider Armor");
|
||||||
|
public static Armor METALARMOR = ArmorsHandler.constructArmor("Metal Armor");
|
||||||
|
public static Armor COMBATARMOR = ArmorsHandler.constructArmor("Combat Armor");
|
||||||
|
public static Armor CENTURIONARMOR = ArmorsHandler.constructArmor("Centurion Armor");
|
||||||
|
public static Armor NCRRANGERARMOR = ArmorsHandler.constructArmor("NCR Ranger Armor");
|
||||||
|
public static Armor T45POWERARMOR = ArmorsHandler.constructArmor("T-45 Power Armor");
|
||||||
|
public static Armor T60POWERARMOR = ArmorsHandler.constructArmor("T-60 Power Armor");
|
||||||
|
public static Armor T65POWERARMOR = ArmorsHandler.constructArmor("T-65 Power Armor");
|
||||||
|
public static Armor X01POWERARMOR = ArmorsHandler.constructArmor("X-01 Power Armor");
|
||||||
|
public static Armor APAMKIORPOWERARMOR = ArmorsHandler.constructArmor("APA MkI Power Armor");
|
||||||
|
public static Armor APAMKIIPOWERARMOR = ArmorsHandler.constructArmor("APA MkII Power Armor");
|
||||||
|
public static Armor RAIDERPOWERARMOR = ArmorsHandler.constructArmor("Raider Power Armor");
|
||||||
|
public static Armor ULTRACITEPOWERARMOR = ArmorsHandler.constructArmor("Ultracite Power Armor");
|
||||||
|
public static Armor T51POWERARMOR = ArmorsHandler.constructArmor("T-51 Power Armor");
|
||||||
|
public static Armor ENCLAVEUNIFORM = ArmorsHandler.constructArmor("Enclave Uniform");
|
||||||
|
public static Armor EXCAVATORPOWERARMOR = ArmorsHandler.constructArmor("Excavator Power Armor");
|
||||||
|
|
||||||
|
public static Player PLAYER = PlayerHandler.constructPlayer("none");
|
||||||
|
|
||||||
|
public static Item STIMPAK = ItemsHandler.constructItem("Stimpak");
|
||||||
|
|
||||||
|
public static AidModifier STIMPAK_M = AidModifierHandler.constructAidModifier("Stimpak");
|
||||||
|
}
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package net.halfheart.ventricleengine;
|
package net.halfheart.ventricleengine;
|
||||||
|
import net.halfheart.ventricleengine.objects.AidModifier;
|
||||||
|
import net.halfheart.lonesomeroad.ID;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -12,7 +12,8 @@ import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class AidModifierHandler {
|
public class AidModifierHandler {
|
||||||
private static AidModifier constructAidModifier(String aidModifierName) {
|
// Creates AidModifier object by parsing JSON
|
||||||
|
public static AidModifier constructAidModifier(String aidModifierName) {
|
||||||
String filename = "/aid_modifiers.json";
|
String filename = "/aid_modifiers.json";
|
||||||
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
||||||
String jsonText = new BufferedReader(
|
String jsonText = new BufferedReader(
|
||||||
|
|
@ -34,22 +35,35 @@ public class AidModifierHandler {
|
||||||
String stat = wantedItem.opt("stat").toString();
|
String stat = wantedItem.opt("stat").toString();
|
||||||
String mod = wantedItem.opt("mod").toString();
|
String mod = wantedItem.opt("mod").toString();
|
||||||
short value = (short) wantedItem.opt("value");
|
short value = (short) wantedItem.opt("value");
|
||||||
int duration = (int) wantedItem.opt("duration");
|
return new AidModifier(name, stat, mod, value);
|
||||||
return new AidModifier(name, stat, mod, value, duration);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Applies requested aid modifier to player
|
||||||
public static void applyAid(AidModifier modifier) {
|
public static void applyAid(AidModifier modifier) {
|
||||||
if (modifier.stat.equals("hp")) {
|
if (modifier.stat.equals("hp")) {
|
||||||
char action = modifier.mod.charAt(0);
|
char action = modifier.mod.charAt(0);
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case '+' -> PlayerHandler.PLAYER.hp = (short) (PlayerHandler.PLAYER.hp + modifier.value);
|
case '+' -> ID.PLAYER.hp = (short) (ID.PLAYER.hp + modifier.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AidModifier STIMPAK = constructAidModifier("Stimpak");
|
// Removes requested aid modifier from player
|
||||||
|
public static void removeAid(AidModifier modifier) {
|
||||||
|
if (modifier.name.equals("Stimpak")) {
|
||||||
|
System.out.println("Invalid Operation: Tried to remove Stimpak modifier from player");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns aidModifier from String of name
|
||||||
|
public static AidModifier findAid(String aidModifierName) {
|
||||||
|
return switch (aidModifierName) {
|
||||||
|
case "Stimpak" -> ID.STIMPAK_M;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
package net.halfheart.ventricleengine;
|
package net.halfheart.ventricleengine;
|
||||||
|
import net.halfheart.ventricleengine.objects.Armor;
|
||||||
|
import net.halfheart.lonesomeroad.ID;
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
|
@ -12,7 +14,8 @@ import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ArmorsHandler {
|
public class ArmorsHandler {
|
||||||
private static Armor constructArmor(String armorName) {
|
// Creates Armor object by parsing JSON
|
||||||
|
public static Armor constructArmor(String armorName) {
|
||||||
String filename = "/armors.json";
|
String filename = "/armors.json";
|
||||||
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
||||||
String jsonText = new BufferedReader(
|
String jsonText = new BufferedReader(
|
||||||
|
|
@ -49,48 +52,29 @@ public class ArmorsHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns Armor from String of name
|
||||||
public static Armor findArmor(String armorName) {
|
public static Armor findArmor(String armorName) {
|
||||||
return switch (armorName) {
|
return switch (armorName) {
|
||||||
case "Nothing" -> NOTHING;
|
case "Nothing" -> ID.NOTHING;
|
||||||
case "Leather Armor" -> LEATHERARMOR;
|
case "Leather Armor" -> ID.LEATHERARMOR;
|
||||||
case "Sturdy Leather Armor" -> STURDYLEATHERARMOR;
|
case "Sturdy Leather Armor" -> ID.STURDYLEATHERARMOR;
|
||||||
case "Raider Armor" -> RAIDERARMOR;
|
case "Raider Armor" -> ID.RAIDERARMOR;
|
||||||
case "Metal Armor" -> METALARMOR;
|
case "Metal Armor" -> ID.METALARMOR;
|
||||||
case "Combat Armor" -> COMBATARMOR;
|
case "Combat Armor" -> ID.COMBATARMOR;
|
||||||
case "Centurion Armor" -> CENTURIONARMOR;
|
case "Centurion Armor" -> ID.CENTURIONARMOR;
|
||||||
case "NCR Ranger Armor" -> NCRRANGERARMOR;
|
case "NCR Ranger Armor" -> ID.NCRRANGERARMOR;
|
||||||
case "T-45 Power Armor" -> T45POWERARMOR;
|
case "T-45 Power Armor" -> ID.T45POWERARMOR;
|
||||||
case "T-60 Power Armor" -> T60POWERARMOR;
|
case "T-60 Power Armor" -> ID.T60POWERARMOR;
|
||||||
case "T-65 Power Armor" -> T65POWERARMOR;
|
case "T-65 Power Armor" -> ID.T65POWERARMOR;
|
||||||
case "X-01 Power Armor" -> X01POWERARMOR;
|
case "X-01 Power Armor" -> ID.X01POWERARMOR;
|
||||||
case "APA MkI Power Armor" -> APAMKIORPOWERARMOR;
|
case "APA MkI Power Armor" -> ID.APAMKIORPOWERARMOR;
|
||||||
case "APA MkII Power Armor" -> APAMKIIPOWERARMOR;
|
case "APA MkII Power Armor" -> ID.APAMKIIPOWERARMOR;
|
||||||
case "Raider Power Armor" -> RAIDERPOWERARMOR;
|
case "Raider Power Armor" -> ID.RAIDERPOWERARMOR;
|
||||||
case "Ultracite Power Armor" -> ULTRACITEPOWERARMOR;
|
case "Ultracite Power Armor" -> ID.ULTRACITEPOWERARMOR;
|
||||||
case "T-51 Power Armor" -> T51POWERARMOR;
|
case "T-51 Power Armor" -> ID.T51POWERARMOR;
|
||||||
case "Enclave Uniform" -> ENCLAVEUNIFORM;
|
case "Enclave Uniform" -> ID.ENCLAVEUNIFORM;
|
||||||
case "Excavator Power Armor" -> EXCAVATORPOWERARMOR;
|
case "Excavator Power Armor" -> ID.EXCAVATORPOWERARMOR;
|
||||||
default -> null;
|
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");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
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;
|
|
||||||
this.aidModifier = aidModifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package net.halfheart.ventricleengine;
|
package net.halfheart.ventricleengine;
|
||||||
|
|
||||||
|
import net.halfheart.lonesomeroad.ID;
|
||||||
|
import net.halfheart.ventricleengine.objects.Item;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
|
@ -11,10 +13,9 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.halfheart.ventricleengine.AidModifierHandler.STIMPAK;
|
|
||||||
|
|
||||||
public class ItemsHandler {
|
public class ItemsHandler {
|
||||||
private static Item constructItem(String weaponName) {
|
// Creates Item by parsing JSON
|
||||||
|
public static Item constructItem(String itemName) {
|
||||||
String filename = "/items.json";
|
String filename = "/items.json";
|
||||||
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
||||||
String jsonText = new BufferedReader(
|
String jsonText = new BufferedReader(
|
||||||
|
|
@ -27,7 +28,7 @@ public class ItemsHandler {
|
||||||
JSONObject wantedItem = null;
|
JSONObject wantedItem = null;
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject item = jsonArray.getJSONObject(i);
|
JSONObject item = jsonArray.getJSONObject(i);
|
||||||
if (item.opt("name").toString().equals(weaponName)) {
|
if (item.opt("name").toString().equals(itemName)) {
|
||||||
wantedItem = item;
|
wantedItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,12 +45,11 @@ public class ItemsHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns Item from String of name
|
||||||
public static Item findItem(String itemName) {
|
public static Item findItem(String itemName) {
|
||||||
return switch (itemName) {
|
return switch (itemName) {
|
||||||
case "Stimpak" -> STIMPAK;
|
case "Stimpak" -> ID.STIMPAK;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item STIMPAK = constructItem("Stimpak");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
package net.halfheart.ventricleengine;
|
|
||||||
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;
|
|
||||||
List<Armor> armors;
|
|
||||||
List<Item> items;
|
|
||||||
|
|
||||||
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,
|
|
||||||
List<Weapon> weapons,
|
|
||||||
List<Armor> armors,
|
|
||||||
List<Item> items
|
|
||||||
)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
this.weapons = weapons;
|
|
||||||
this.armors = armors;
|
|
||||||
this.items = items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,10 +6,13 @@ import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.halfheart.ventricleengine.objects.*;
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
|
||||||
public class PlayerHandler {
|
public class PlayerHandler {
|
||||||
private static Player constructPlayer(String savePath) {
|
// Creates Player object by parsing JSON
|
||||||
|
public static Player constructPlayer(String savePath) {
|
||||||
|
// "none" Used for creating a blank Player for character creation
|
||||||
if (savePath.equals("none")) {
|
if (savePath.equals("none")) {
|
||||||
String name = "No Player Loaded!";
|
String name = "No Player Loaded!";
|
||||||
byte strength = 0;
|
byte strength = 0;
|
||||||
|
|
@ -25,13 +28,13 @@ public class PlayerHandler {
|
||||||
short hp = 0;
|
short hp = 0;
|
||||||
short food = 0;
|
short food = 0;
|
||||||
boolean isRadiated = false;
|
boolean isRadiated = false;
|
||||||
byte radSeverity = 0;
|
|
||||||
byte radPoints = 0;
|
byte radPoints = 0;
|
||||||
int xp = 0;
|
int xp = 0;
|
||||||
short level = 0;
|
short level = 0;
|
||||||
List<Weapon> weaponList = new ArrayList<>();
|
List<Weapon> weaponList = new ArrayList<>();
|
||||||
List<Armor> armorList = new ArrayList<>();
|
List<Armor> armorList = new ArrayList<>();
|
||||||
List<Item> itemList = new ArrayList<>();
|
List<Item> itemList = new ArrayList<>();
|
||||||
|
List<AidModifier> aidList = new ArrayList<>();
|
||||||
|
|
||||||
return new Player(
|
return new Player(
|
||||||
name,
|
name,
|
||||||
|
|
@ -48,13 +51,13 @@ public class PlayerHandler {
|
||||||
hp,
|
hp,
|
||||||
food,
|
food,
|
||||||
isRadiated,
|
isRadiated,
|
||||||
radSeverity,
|
|
||||||
radPoints,
|
radPoints,
|
||||||
xp,
|
xp,
|
||||||
level,
|
level,
|
||||||
weaponList,
|
weaponList,
|
||||||
armorList,
|
armorList,
|
||||||
itemList
|
itemList,
|
||||||
|
aidList
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|
@ -75,7 +78,6 @@ public class PlayerHandler {
|
||||||
short hp = (short) saveData.opt("hp");
|
short hp = (short) saveData.opt("hp");
|
||||||
short food = (short) saveData.opt("food");
|
short food = (short) saveData.opt("food");
|
||||||
boolean isRadiated = (boolean) saveData.opt("isRadiated");
|
boolean isRadiated = (boolean) saveData.opt("isRadiated");
|
||||||
byte radSeverity = (byte) saveData.opt("radSeverity");
|
|
||||||
byte radPoints = (byte) saveData.opt("radPoints");
|
byte radPoints = (byte) saveData.opt("radPoints");
|
||||||
int xp = (int) saveData.opt("xp");
|
int xp = (int) saveData.opt("xp");
|
||||||
short level = (short) saveData.opt("level");
|
short level = (short) saveData.opt("level");
|
||||||
|
|
@ -83,6 +85,7 @@ public class PlayerHandler {
|
||||||
JSONObject weapons = saveData.getJSONObject("weapons");
|
JSONObject weapons = saveData.getJSONObject("weapons");
|
||||||
JSONObject armors = saveData.getJSONObject("armors");
|
JSONObject armors = saveData.getJSONObject("armors");
|
||||||
JSONObject items = saveData.getJSONObject("items");
|
JSONObject items = saveData.getJSONObject("items");
|
||||||
|
JSONObject aidModifiers = saveData.getJSONObject("aidModifiers");
|
||||||
|
|
||||||
List<Weapon> weaponList = new ArrayList<>();
|
List<Weapon> weaponList = new ArrayList<>();
|
||||||
for (String key : weapons.keySet()) {
|
for (String key : weapons.keySet()) {
|
||||||
|
|
@ -96,6 +99,10 @@ public class PlayerHandler {
|
||||||
for (String key : items.keySet()) {
|
for (String key : items.keySet()) {
|
||||||
itemList.add(ItemsHandler.findItem(items.opt(key).toString()));
|
itemList.add(ItemsHandler.findItem(items.opt(key).toString()));
|
||||||
}
|
}
|
||||||
|
List<AidModifier> aidModifierList = new ArrayList<>();
|
||||||
|
for (String key : aidModifiers.keySet()) {
|
||||||
|
aidModifierList.add(AidModifierHandler.findAid(items.opt(key).toString()));
|
||||||
|
}
|
||||||
|
|
||||||
return new Player(
|
return new Player(
|
||||||
name,
|
name,
|
||||||
|
|
@ -112,13 +119,13 @@ public class PlayerHandler {
|
||||||
hp,
|
hp,
|
||||||
food,
|
food,
|
||||||
isRadiated,
|
isRadiated,
|
||||||
radSeverity,
|
|
||||||
radPoints,
|
radPoints,
|
||||||
xp,
|
xp,
|
||||||
level,
|
level,
|
||||||
weaponList,
|
weaponList,
|
||||||
armorList,
|
armorList,
|
||||||
itemList
|
itemList,
|
||||||
|
aidModifierList
|
||||||
);
|
);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("Save file not found at path: "+savePath);
|
System.out.println("Save file not found at path: "+savePath);
|
||||||
|
|
@ -128,6 +135,4 @@ public class PlayerHandler {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Player PLAYER = constructPlayer("none");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
package net.halfheart.ventricleengine;
|
package net.halfheart.ventricleengine;
|
||||||
|
import net.halfheart.lonesomeroad.ID;
|
||||||
|
import net.halfheart.ventricleengine.objects.Weapon;
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
|
@ -10,7 +12,8 @@ import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class WeaponsHandler {
|
public class WeaponsHandler {
|
||||||
private static Weapon constructWeapon(String weaponName) {
|
// Creates Weapon object by parsing JSON
|
||||||
|
public static Weapon constructWeapon(String weaponName) {
|
||||||
String filename = "/weapons.json";
|
String filename = "/weapons.json";
|
||||||
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
try (InputStream inputStream = WeaponsHandler.class.getResourceAsStream(filename)) {
|
||||||
String jsonText = new BufferedReader(
|
String jsonText = new BufferedReader(
|
||||||
|
|
@ -41,40 +44,33 @@ public class WeaponsHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finds Weapon from String of name
|
||||||
public static Weapon findWeapon(String weaponName) {
|
public static Weapon findWeapon(String weaponName) {
|
||||||
return switch (weaponName) {
|
return switch (weaponName) {
|
||||||
case "Fists" -> FISTS;
|
case "Fists" -> ID.FISTS;
|
||||||
case "Combat Knife" -> COMBATKNIFE;
|
case "Combat Knife" -> ID.COMBATKNIFE;
|
||||||
case "Ripper" -> RIPPER;
|
case "Ripper" -> ID.RIPPER;
|
||||||
case "Chainsaw" -> CHAINSAW;
|
case "Chainsaw" -> ID.CHAINSAW;
|
||||||
case "Baseball Bat" -> BASEBALLBAT;
|
case "Baseball Bat" -> ID.BASEBALLBAT;
|
||||||
case "Power Fist" -> POWERFIST;
|
case "Power Fist" -> ID.POWERFIST;
|
||||||
case "Super Sledge" -> SUPERSLEDGE;
|
case "Super Sledge" -> ID.SUPERSLEDGE;
|
||||||
case "10mm Pistol" -> PISTOL10MM;
|
case "10mm Pistol" -> ID.PISTOL10MM;
|
||||||
case "Hunting Rifle" -> HUNTINGRIFLE;
|
case "Hunting Rifle" -> ID.HUNTINGRIFLE;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fistCalc() {
|
public static void fistCalc() {
|
||||||
switch (PlayerHandler.PLAYER.strength){
|
switch (ID.PLAYER.strength){
|
||||||
case 0 -> {
|
case 0 -> {
|
||||||
FISTS.description = FISTS.description+"please don't.";
|
ID.FISTS.description = ID.FISTS.description+"please don't.";
|
||||||
FISTS.damage = -2;
|
ID.FISTS.damage = -2;
|
||||||
}
|
}
|
||||||
case (1|2|3|4) -> FISTS.description = FISTS.description+"a last resort.";
|
case (1|2|3|4) -> ID.FISTS.description = ID.FISTS.description+"a last resort.";
|
||||||
case (5|6|7|8) -> FISTS.description = FISTS.description+"use cautiously.";
|
case (5|6|7|8) -> ID.FISTS.description = ID.FISTS.description+"use cautiously.";
|
||||||
case (9|10) -> FISTS.description = FISTS.description+"a formidable weapon.";
|
case (9|10) -> ID.FISTS.description = ID.FISTS.description+"a formidable weapon.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package net.halfheart.ventricleengine.objects;
|
||||||
|
|
||||||
|
|
||||||
|
// AidModifiers are used to break down the JSON data into Java-readable components.
|
||||||
|
public class AidModifier {
|
||||||
|
public String name; // Name of the effect, seen in game
|
||||||
|
public String stat; // Stat that the modifier affects
|
||||||
|
public String mod; // Operation that the modifier is doing to the stat (e.g. * for multiplying)
|
||||||
|
public short value; // Value that the operation uses (e.g. 25 for +25 hp)
|
||||||
|
|
||||||
|
public AidModifier(String name, String stat, String mod, short value) {
|
||||||
|
this.name = name;
|
||||||
|
this.stat = stat;
|
||||||
|
this.mod = mod;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package net.halfheart.ventricleengine.objects;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
// Armor is used to represent each armor as a Java object with values
|
||||||
|
public class Armor {
|
||||||
|
public String name; // Name of the armor, seen in game
|
||||||
|
public String description; // Description seen in pip-boy
|
||||||
|
public String type; // Armor type, either skin, uarmor, armor, or parmor
|
||||||
|
public List<Byte> resistances; // A list of resistance byte values for each damage type
|
||||||
|
public String resUnit; // Unit the resistances use, either dt or dr for damage threshold and damage resistance
|
||||||
|
public short cost; // Buy/Sell price
|
||||||
|
public byte weight; // Weight of item in inventory
|
||||||
|
|
||||||
|
public Armor(
|
||||||
|
String name,
|
||||||
|
String description,
|
||||||
|
String type,
|
||||||
|
List<Byte> resistances,
|
||||||
|
String resUnit,
|
||||||
|
short cost,
|
||||||
|
byte weight
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.type = type;
|
||||||
|
this.resistances = resistances;
|
||||||
|
this.resUnit = resUnit;
|
||||||
|
this.cost = cost;
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package net.halfheart.ventricleengine.objects;
|
||||||
|
|
||||||
|
// Item is used to represent each armor as a Java object with values
|
||||||
|
public class Item {
|
||||||
|
public String name; // Name of item, seen in game
|
||||||
|
public String description; // Description seen in pip-boy
|
||||||
|
public byte weight; // Weight of item in inventory
|
||||||
|
public short cost; // Buy/Sell value of item
|
||||||
|
public boolean consumable; // Whether the item can be consumed
|
||||||
|
public String aidModifier; // Aid modifier that the item applies when consumed
|
||||||
|
|
||||||
|
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;
|
||||||
|
this.aidModifier = aidModifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
package net.halfheart.ventricleengine.objects;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
// Player is used to represent the save data values as a Java object
|
||||||
|
public class Player {
|
||||||
|
public String name; // Name of player
|
||||||
|
// Next 7 lines: S.P.E.C.I.A.L. values of player
|
||||||
|
public byte strength;
|
||||||
|
public byte perception;
|
||||||
|
public byte endurance;
|
||||||
|
public byte charisma;
|
||||||
|
public byte intelligence;
|
||||||
|
public byte agility;
|
||||||
|
public byte luck;
|
||||||
|
|
||||||
|
public short caps; // Caps the player has, used for vendors
|
||||||
|
public short pwMoney; // Pre-War Money the player has, used in Enclave vendors
|
||||||
|
|
||||||
|
public short hpCap; // Player health point cap
|
||||||
|
public short hp; // Current player health
|
||||||
|
|
||||||
|
public short food; // Food the player has, eaten each walk cycle
|
||||||
|
|
||||||
|
public boolean isRadiated; // Whether the player is irradiated
|
||||||
|
// TODO: Decide function of radPoints
|
||||||
|
public byte radPoints; // Rad points player has
|
||||||
|
|
||||||
|
public int xp; // Current player xp
|
||||||
|
public short level; // Current level of player
|
||||||
|
|
||||||
|
public List<Weapon> weapons; // Weapons that the player has in inventory
|
||||||
|
public List<Armor> armors; // Armors that the player has in inventory
|
||||||
|
public List<Item> items; // Items that the player has in inventory
|
||||||
|
public List<AidModifier> aidModifiers; // Modifiers currently affecting player
|
||||||
|
|
||||||
|
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 radPoints,
|
||||||
|
int xp,
|
||||||
|
short level,
|
||||||
|
List<Weapon> weapons,
|
||||||
|
List<Armor> armors,
|
||||||
|
List<Item> items,
|
||||||
|
List<AidModifier> aidModifiers
|
||||||
|
)
|
||||||
|
{
|
||||||
|
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.radPoints = radPoints;
|
||||||
|
this.xp = xp;
|
||||||
|
this.level = level;
|
||||||
|
this.weapons = weapons;
|
||||||
|
this.armors = armors;
|
||||||
|
this.items = items;
|
||||||
|
this.aidModifiers = aidModifiers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package net.halfheart.ventricleengine.objects;
|
||||||
|
|
||||||
|
// Weapon is used to represent each weapon as a Java object with values
|
||||||
|
public class Weapon {
|
||||||
|
public String name; // Name of weapon, seen in game
|
||||||
|
public String description; // Description of weapon, seen in pip-boy
|
||||||
|
public String dmgType; // Type of damage the weapon deals. Laser, Bash, Slash. etc.
|
||||||
|
public String ammoType; // Ammo the weapon uses. "none" for melee weapons
|
||||||
|
public short damage; // Damage the weapon deals
|
||||||
|
public short cost; // Buy/Sell value of weapon
|
||||||
|
public byte weight; // Weight of weapon in inventory
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"food": {
|
"Stimpak": {
|
||||||
"name": "Stimpak",
|
"name": "Stimpak",
|
||||||
"stat": "hp",
|
"stat": "hp",
|
||||||
"mod": "+",
|
"mod": "+",
|
||||||
"value": "20",
|
"value": "20"
|
||||||
"duration": 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue