aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java
diff options
context:
space:
mode:
authorkr45732 <52721908+kr45732@users.noreply.github.com>2022-08-11 07:03:39 -0400
committerGitHub <noreply@github.com>2022-08-11 21:03:39 +1000
commitfde462b796ed7fbb22fdf7cf04c032389f3e8629 (patch)
treeb6791c22df64efdd477a223bd50a84a27a5de953 /src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java
parentba69e034794b7a5dc8d950ab4ba2d12370aa509f (diff)
downloadnotenoughupdates-fde462b796ed7fbb22fdf7cf04c032389f3e8629.tar.gz
notenoughupdates-fde462b796ed7fbb22fdf7cf04c032389f3e8629.tar.bz2
notenoughupdates-fde462b796ed7fbb22fdf7cf04c032389f3e8629.zip
PV Refactoring (#212)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java351
1 files changed, 177 insertions, 174 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java
index 4ee1f208..96412db6 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java
@@ -26,6 +26,13 @@ import com.google.gson.JsonPrimitive;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.Utils;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
@@ -35,15 +42,8 @@ import net.minecraft.util.EnumChatFormatting;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
public class PlayerStats {
+
public static final String HEALTH = "health";
public static final String DEFENCE = "defence";
public static final String STRENGTH = "strength";
@@ -58,7 +58,7 @@ public class PlayerStats {
public static final String MINING_FORTUNE = "mining_fortune";
public static final String MINING_SPEED = "mining_speed";
- public static final String[] defaultStatNames = new String[]{
+ public static final String[] defaultStatNames = new String[] {
"health",
"defence",
"strength",
@@ -73,9 +73,9 @@ public class PlayerStats {
"ferocity",
"ability_damage",
"mining_fortune",
- "mining_speed"
+ "mining_speed",
};
- public static final String[] defaultStatNamesPretty = new String[]{
+ public static final String[] defaultStatNamesPretty = new String[] {
EnumChatFormatting.RED + "\u2764 Health",
EnumChatFormatting.GREEN + "\u2748 Defence",
EnumChatFormatting.RED + "\u2741 Strength",
@@ -90,83 +90,23 @@ public class PlayerStats {
EnumChatFormatting.RED + "\u2AFD Ferocity",
EnumChatFormatting.RED + "\u2739 Ability Damage",
EnumChatFormatting.GOLD + "\u2618 Mining Fortune",
- EnumChatFormatting.GOLD + "\u2E15 Mining Speed"
+ EnumChatFormatting.GOLD + "\u2E15 Mining Speed",
};
-
- public static class Stats {
- JsonObject statsJson = new JsonObject();
-
- /*public float health;
- public float defence;
- public float strength;
- public float speed;
- public float crit_chance;
- public float crit_damage;
- public float bonus_attack_speed;
- public float intelligence;
- public float sea_creature_chance;
- public float magic_find;
- public float pet_luck;*/
-
- public Stats(Stats... statses) {
- for (Stats stats : statses) {
- add(stats);
- }
- }
-
- /*@Override
- public String toString() {
- return String.format("{health=%s,defence=%s,strength=%s,speed=%s,crit_chance=%s,crit_damage=%s," +
- "bonus_attack_speed=%s,intelligence=%s,sea_creature_chance=%s,magic_find=%s,pet_luck=%s}",
- stats.get("health"), defence, strength, speed, crit_chance, crit_damage, bonus_attack_speed, intelligence,
- sea_creature_chance, magic_find, pet_luck
- );
- }*/
-
- public float get(String statName) {
- if (statsJson.has(statName)) {
- return statsJson.get(statName).getAsFloat();
- } else {
- return 0;
- }
- }
-
- public Stats add(Stats stats) {
- for (Map.Entry<String, JsonElement> statEntry : stats.statsJson.entrySet()) {
- if (statEntry.getValue().isJsonPrimitive() && ((JsonPrimitive) statEntry.getValue()).isNumber()) {
- if (!statsJson.has(statEntry.getKey())) {
- statsJson.add(statEntry.getKey(), statEntry.getValue());
- } else {
- JsonPrimitive e = statsJson.get(statEntry.getKey()).getAsJsonPrimitive();
- float statNum = e.getAsFloat() + statEntry.getValue().getAsFloat();
- statsJson.add(statEntry.getKey(), new JsonPrimitive(statNum));
- }
- }
- }
- return this;
- }
-
- public void scale(String statName, float scale) {
- if (statsJson.has(statName)) {
- statsJson.add(statName, new JsonPrimitive(statsJson.get(statName).getAsFloat() * scale));
- }
- }
-
- public void scaleAll(float scale) {
- for (Map.Entry<String, JsonElement> statEntry : statsJson.entrySet()) {
- statsJson.add(statEntry.getKey(), new JsonPrimitive(statEntry.getValue().getAsFloat() * scale));
- }
+ private static final HashMap<String, Pattern> STAT_PATTERN_MAP = new HashMap<String, Pattern>() {
+ {
+ put(HEALTH, Pattern.compile("^Health: ((?:\\+|-)[0-9]+)"));
+ put(DEFENCE, Pattern.compile("^Defense: ((?:\\+|-)[0-9]+)"));
+ put(STRENGTH, Pattern.compile("^Strength: ((?:\\+|-)[0-9]+)"));
+ put(SPEED, Pattern.compile("^Speed: ((?:\\+|-)[0-9]+)"));
+ put(CRIT_CHANCE, Pattern.compile("^Crit Chance: ((?:\\+|-)[0-9]+)"));
+ put(CRIT_DAMAGE, Pattern.compile("^Crit Damage: ((?:\\+|-)[0-9]+)"));
+ put(BONUS_ATTACK_SPEED, Pattern.compile("^Bonus Attack Speed: ((?:\\+|-)[0-9]+)"));
+ put(INTELLIGENCE, Pattern.compile("^Intelligence: ((?:\\+|-)[0-9]+)"));
+ put(SEA_CREATURE_CHANCE, Pattern.compile("^Sea Creature Chance: ((?:\\+|-)[0-9]+)"));
+ put("ferocity", Pattern.compile("^Ferocity: ((?:\\+|-)[0-9]+)"));
+ put("ability_damage", Pattern.compile("^Ability Damage: ((?:\\+|-)[0-9]+)"));
}
-
- public void addStat(String statName, float amount) {
- if (!statsJson.has(statName)) {
- statsJson.add(statName, new JsonPrimitive(amount));
- } else {
- JsonPrimitive e = statsJson.get(statName).getAsJsonPrimitive();
- statsJson.add(statName, new JsonPrimitive(e.getAsFloat() + amount));
- }
- }
- }
+ };
public static Stats getBaseStats() {
JsonObject misc = Constants.MISC;
@@ -193,29 +133,26 @@ public class PlayerStats {
return bonus;
}
- private static Stats getSkillBonus(JsonObject skillInfo) {
+ private static Stats getSkillBonus(Map<String, ProfileViewer.Level> skyblockInfo) {
JsonObject bonuses = Constants.BONUSES;
if (bonuses == null) return null;
Stats skillBonus = new Stats();
- for (Map.Entry<String, JsonElement> entry : skillInfo.entrySet()) {
- if (entry.getKey().startsWith("level_")) {
- String skill = entry.getKey().substring("level_".length());
- JsonElement element = Utils.getElement(bonuses, "bonus_stats." + skill);
- if (element != null && element.isJsonObject()) {
- JsonObject skillStatMap = element.getAsJsonObject();
-
- Stats currentBonus = new Stats();
- for (int i = 1; i <= entry.getValue().getAsFloat(); i++) {
- if (skillStatMap.has("" + i)) {
- currentBonus = new Stats();
- for (Map.Entry<String, JsonElement> entry2 : skillStatMap.get("" + i).getAsJsonObject().entrySet()) {
- currentBonus.addStat(entry2.getKey(), entry2.getValue().getAsFloat());
- }
+ for (Map.Entry<String, ProfileViewer.Level> entry : skyblockInfo.entrySet()) {
+ JsonElement element = Utils.getElement(bonuses, "bonus_stats." + entry.getKey());
+ if (element != null && element.isJsonObject()) {
+ JsonObject skillStatMap = element.getAsJsonObject();
+
+ Stats currentBonus = new Stats();
+ for (int i = 1; i <= entry.getValue().level; i++) {
+ if (skillStatMap.has("" + i)) {
+ currentBonus = new Stats();
+ for (Map.Entry<String, JsonElement> entry2 : skillStatMap.get("" + i).getAsJsonObject().entrySet()) {
+ currentBonus.addStat(entry2.getKey(), entry2.getValue().getAsFloat());
}
- skillBonus.add(currentBonus);
}
+ skillBonus.add(currentBonus);
}
}
}
@@ -261,8 +198,7 @@ public class PlayerStats {
}
private static float harpBonus(JsonObject profile) {
- String talk_to_melody =
- Utils.getElementAsString(Utils.getElement(profile, "objectives.talk_to_melody.status"), "INCOMPLETE");
+ String talk_to_melody = Utils.getElementAsString(Utils.getElement(profile, "objectives.talk_to_melody.status"), "INCOMPLETE");
if (talk_to_melody.equalsIgnoreCase("COMPLETE")) {
return 26;
} else {
@@ -270,29 +206,24 @@ public class PlayerStats {
}
}
- private static float hotmFortune(JsonObject profile, JsonObject skillInfo) {
- int miningLevelFortune =
- (int) (4 * (float) Math.floor(Utils.getElementAsFloat(Utils.getElement(skillInfo, "level_skill_mining"), 0)));
- int miningFortuneStat =
- ((Utils.getElementAsInt(Utils.getElement(profile, "mining_core.nodes.mining_fortune"), 0)) * 5);
- int miningFortune2Stat =
- ((Utils.getElementAsInt(Utils.getElement(profile, "mining_core.nodes.mining_fortune_2"), 0)) * 5);
+ private static float hotmFortune(JsonObject profile, Map<String, ProfileViewer.Level> skyblockInfo) {
+ int miningLevelFortune = (int) (4 * (float) Math.floor(skyblockInfo.get("mining").level));
+ int miningFortuneStat = ((Utils.getElementAsInt(Utils.getElement(profile, "mining_core.nodes.mining_fortune"), 0)) * 5);
+ int miningFortune2Stat = ((Utils.getElementAsInt(Utils.getElement(profile, "mining_core.nodes.mining_fortune_2"), 0)) * 5);
return miningFortuneStat + miningFortune2Stat + miningLevelFortune;
}
private static float hotmSpeed(JsonObject profile) {
- int miningSpeedStat =
- ((Utils.getElementAsInt(Utils.getElement(profile, "mining_core.nodes.mining_speed"), 0)) * 20);
- int miningSpeed2Stat =
- ((Utils.getElementAsInt(Utils.getElement(profile, "mining_core.nodes.mining_speed_2"), 0)) * 40);
+ int miningSpeedStat = ((Utils.getElementAsInt(Utils.getElement(profile, "mining_core.nodes.mining_speed"), 0)) * 20);
+ int miningSpeed2Stat = ((Utils.getElementAsInt(Utils.getElement(profile, "mining_core.nodes.mining_speed_2"), 0)) * 40);
return miningSpeedStat + miningSpeed2Stat;
}
- public static Stats getPassiveBonuses(JsonObject skillInfo, JsonObject profile) {
+ public static Stats getPassiveBonuses(Map<String, ProfileViewer.Level> skyblockInfo, JsonObject profile) {
Stats passiveBonuses = new Stats();
Stats fairyBonus = getFairyBonus((int) Utils.getElementAsFloat(Utils.getElement(profile, "fairy_exchanges"), 0));
- Stats skillBonus = getSkillBonus(skillInfo);
+ Stats skillBonus = getSkillBonus(skyblockInfo);
Stats petBonus = getTamingBonus(profile);
if (skillBonus == null || petBonus == null) {
@@ -307,10 +238,10 @@ public class PlayerStats {
return passiveBonuses;
}
- public static Stats getHOTMBonuses(JsonObject skillInfo, JsonObject profile) {
+ public static Stats getHOTMBonuses(Map<String, ProfileViewer.Level> skyblockInfo, JsonObject profile) {
Stats hotmBonuses = new Stats();
- hotmBonuses.addStat(MINING_FORTUNE, hotmFortune(profile, skillInfo));
+ hotmBonuses.addStat(MINING_FORTUNE, hotmFortune(profile, skyblockInfo));
hotmBonuses.addStat(MINING_SPEED, hotmSpeed(profile));
return hotmBonuses;
@@ -347,7 +278,7 @@ public class PlayerStats {
Stats stats,
JsonObject inventoryInfo,
JsonObject collectionInfo,
- JsonObject skillInfo,
+ Map<String, ProfileViewer.Level> skyblockInfo,
JsonObject profile
) {
JsonArray armor = Utils.getElement(inventoryInfo, "inv_armor").getAsJsonArray();
@@ -361,12 +292,13 @@ public class PlayerStats {
case "LAPIS_ARMOR_":
bonuses.addStat(HEALTH, 60);
break;
- case "EMERALD_ARMOR_": {
- int bonus = (int) Math.floor(Utils.getElementAsFloat(Utils.getElement(collectionInfo, "EMERALD"), 0) / 3000);
- bonuses.addStat(HEALTH, bonus);
- bonuses.addStat(DEFENCE, bonus);
- }
- break;
+ case "EMERALD_ARMOR_":
+ {
+ int bonus = (int) Math.floor(Utils.getElementAsFloat(Utils.getElement(collectionInfo, "EMERALD"), 0) / 3000);
+ bonuses.addStat(HEALTH, bonus);
+ bonuses.addStat(DEFENCE, bonus);
+ }
+ break;
case "FAIRY_":
bonuses.addStat(HEALTH, Utils.getElementAsFloat(Utils.getElement(profile, "fairy_souls_collected"), 0));
break;
@@ -380,10 +312,7 @@ public class PlayerStats {
bonuses.addStat(HEALTH, 50 * Math.round(stats.get(CRIT_DAMAGE)));
break;
case "ANGLER_":
- bonuses.addStat(
- HEALTH,
- 10 * (float) Math.floor(Utils.getElementAsFloat(Utils.getElement(skillInfo, "level_skill_fishing"), 0))
- );
+ bonuses.addStat(HEALTH, 10 * (float) Math.floor(skyblockInfo.get("fishing").level));
bonuses.addStat(SEA_CREATURE_CHANCE, 4);
break;
case "ARMOR_OF_MAGMA_":
@@ -424,20 +353,6 @@ public class PlayerStats {
return bonuses;
}
- private static final HashMap<String, Pattern> STAT_PATTERN_MAP = new HashMap<String, Pattern>() {{
- put(HEALTH, Pattern.compile("^Health: ((?:\\+|-)[0-9]+)"));
- put(DEFENCE, Pattern.compile("^Defense: ((?:\\+|-)[0-9]+)"));
- put(STRENGTH, Pattern.compile("^Strength: ((?:\\+|-)[0-9]+)"));
- put(SPEED, Pattern.compile("^Speed: ((?:\\+|-)[0-9]+)"));
- put(CRIT_CHANCE, Pattern.compile("^Crit Chance: ((?:\\+|-)[0-9]+)"));
- put(CRIT_DAMAGE, Pattern.compile("^Crit Damage: ((?:\\+|-)[0-9]+)"));
- put(BONUS_ATTACK_SPEED, Pattern.compile("^Bonus Attack Speed: ((?:\\+|-)[0-9]+)"));
- put(INTELLIGENCE, Pattern.compile("^Intelligence: ((?:\\+|-)[0-9]+)"));
- put(SEA_CREATURE_CHANCE, Pattern.compile("^Sea Creature Chance: ((?:\\+|-)[0-9]+)"));
- put("ferocity", Pattern.compile("^Ferocity: ((?:\\+|-)[0-9]+)"));
- put("ability_damage", Pattern.compile("^Ability Damage: ((?:\\+|-)[0-9]+)"));
- }};
-
private static Stats getStatForItem(String internalname, JsonObject item, JsonArray lore) {
Stats stats = new Stats();
for (int i = 0; i < lore.size(); i++) {
@@ -501,8 +416,7 @@ public class PlayerStats {
if (itemBonuses.containsKey(internalname)) {
continue;
}
- if (!talismanOnly ||
- Utils.checkItemType(item.get("lore").getAsJsonArray(), true, "ACCESSORY", "HATCCESSORY") >= 0) {
+ if (!talismanOnly || Utils.checkItemType(item.get("lore").getAsJsonArray(), true, "ACCESSORY", "HATCCESSORY") >= 0) {
Stats itemBonus = getStatForItem(internalname, item, item.get("lore").getAsJsonArray());
itemBonuses.put(internalname, itemBonus);
@@ -534,13 +448,21 @@ public class PlayerStats {
JsonObject petnums = Constants.PETNUMS;
if (petsJson == null || petnums == null) return new Stats();
- if (petsInfo != null && petsInfo.has("active_pet") && petsInfo.get("active_pet") != null &&
- petsInfo.get("active_pet").isJsonObject()) {
+ if (
+ petsInfo != null &&
+ petsInfo.has("active_pet") &&
+ petsInfo.get("active_pet") != null &&
+ petsInfo.get("active_pet").isJsonObject()
+ ) {
JsonObject pet = petsInfo.get("active_pet").getAsJsonObject();
- if (pet.has("type") && pet.get("type") != null &&
- pet.has("tier") && pet.get("tier") != null &&
- pet.has("exp") && pet.get("exp") != null) {
-
+ if (
+ pet.has("type") &&
+ pet.get("type") != null &&
+ pet.has("tier") &&
+ pet.get("tier") != null &&
+ pet.has("exp") &&
+ pet.get("exp") != null
+ ) {
String petname = pet.get("type").getAsString();
String tier = pet.get("tier").getAsString();
String heldItem = Utils.getElementAsString(pet.get("heldItem"), null);
@@ -553,8 +475,11 @@ public class PlayerStats {
float exp = pet.get("exp").getAsFloat();
if (tierNum == null) return new Stats();
- if (pet.has("heldItem") && !pet.get("heldItem").isJsonNull() &&
- pet.get("heldItem").getAsString().equals("PET_ITEM_TIER_BOOST")) {
+ if (
+ pet.has("heldItem") &&
+ !pet.get("heldItem").isJsonNull() &&
+ pet.get("heldItem").getAsString().equals("PET_ITEM_TIER_BOOST")
+ ) {
tierNum = "" + (Integer.parseInt(tierNum) + 1);
}
@@ -602,18 +527,15 @@ public class PlayerStats {
String key = entryBoost.getKey().toLowerCase();
try {
stats.addStat(key, entryBoost.getValue());
- } catch (Exception ignored) {
- }
+ } catch (Exception ignored) {}
}
-
}
if (petStatBootsMult != null) {
for (Map.Entry<String, Float> entryBoost : petStatBootsMult.entrySet()) {
String key = entryBoost.getKey().toLowerCase();
try {
stats.scale(key, entryBoost.getValue());
- } catch (Exception ignored) {
- }
+ } catch (Exception ignored) {}
}
}
}
@@ -670,25 +592,30 @@ public class PlayerStats {
}
for (Map.Entry<String, JsonElement> statEntry : stats.statsJson.entrySet()) {
- if (statEntry.getKey().equals(CRIT_DAMAGE) ||
+ if (
+ statEntry.getKey().equals(CRIT_DAMAGE) ||
statEntry.getKey().equals(INTELLIGENCE) ||
- statEntry.getKey().equals(BONUS_ATTACK_SPEED)) continue;
+ statEntry.getKey().equals(BONUS_ATTACK_SPEED)
+ ) continue;
stats.statsJson.add(statEntry.getKey(), new JsonPrimitive(Math.max(0, statEntry.getValue().getAsFloat())));
}
}
public static Stats getStats(
- JsonObject skillInfo, JsonObject inventoryInfo, JsonObject collectionInfo,
- JsonObject petsInfo, JsonObject profile
+ Map<String, ProfileViewer.Level> skyblockInfo,
+ JsonObject inventoryInfo,
+ JsonObject collectionInfo,
+ JsonObject petsInfo,
+ JsonObject profile
) {
- if (skillInfo == null || inventoryInfo == null || collectionInfo == null || profile == null) return null;
+ if (skyblockInfo == null || inventoryInfo == null || collectionInfo == null || profile == null) return null;
JsonArray armor = Utils.getElement(inventoryInfo, "inv_armor").getAsJsonArray();
JsonArray inventory = Utils.getElement(inventoryInfo, "inv_contents").getAsJsonArray();
JsonArray talisman_bag = Utils.getElement(inventoryInfo, "talisman_bag").getAsJsonArray();
- Stats passiveBonuses = getPassiveBonuses(skillInfo, profile);
- Stats hotmBonuses = getHOTMBonuses(skillInfo, profile);
+ Stats passiveBonuses = getPassiveBonuses(skyblockInfo, profile);
+ Stats hotmBonuses = getHOTMBonuses(skyblockInfo, profile);
Stats armorBonuses = getItemBonuses(false, armor);
Stats talismanBonuses = getItemBonuses(true, inventory, talisman_bag);
@@ -706,7 +633,7 @@ public class PlayerStats {
stats = stats.add(passiveBonuses).add(armorBonuses).add(talismanBonuses).add(petBonus).add(hotmBonuses);
- stats.add(getSetBonuses(stats, inventoryInfo, collectionInfo, skillInfo, profile));
+ stats.add(getSetBonuses(stats, inventoryInfo, collectionInfo, skyblockInfo, profile));
stats.scaleAll(getStatMult(inventoryInfo));
@@ -723,8 +650,7 @@ public class PlayerStats {
* @see io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer.Profile#getInventoryInfo(String)
*/
public static int getMagicalPower(JsonObject inventoryInfo) {
- if (inventoryInfo == null || !inventoryInfo.has("talisman_bag") ||
- !inventoryInfo.get("talisman_bag").isJsonArray()) {
+ if (inventoryInfo == null || !inventoryInfo.has("talisman_bag") || !inventoryInfo.get("talisman_bag").isJsonArray()) {
return -1;
}
JsonArray accessories = inventoryInfo.get("talisman_bag").getAsJsonArray();
@@ -784,7 +710,6 @@ public class PlayerStats {
powderAmount += 22;
break;
}
-
}
return powderAmount;
}
@@ -799,13 +724,91 @@ public class PlayerStats {
public static @Nullable String getSelectedMagicalPower(JsonObject profileInfo) {
String abs = "accessory_bag_storage";
- if (profileInfo == null
- || !profileInfo.has(abs)
- || !profileInfo.get(abs).isJsonObject()
- || !profileInfo.get(abs).getAsJsonObject().has("selected_power")) {
+ if (
+ profileInfo == null ||
+ !profileInfo.has(abs) ||
+ !profileInfo.get(abs).isJsonObject() ||
+ !profileInfo.get(abs).getAsJsonObject().has("selected_power")
+ ) {
return null;
}
String selectedPower = profileInfo.get(abs).getAsJsonObject().get("selected_power").getAsString();
return selectedPower.substring(0, 1).toUpperCase() + selectedPower.substring(1);
}
+
+ public static class Stats {
+
+ JsonObject statsJson = new JsonObject();
+
+ /*public float health;
+ public float defence;
+ public float strength;
+ public float speed;
+ public float crit_chance;
+ public float crit_damage;
+ public float bonus_attack_speed;
+ public float intelligence;
+ public float sea_creature_chance;
+ public float magic_find;
+ public float pet_luck;*/
+
+ public Stats(Stats... statses) {
+ for (Stats stats : statses) {
+ add(stats);
+ }
+ }
+
+ /*@Override
+ public String toString() {
+ return String.format("{health=%s,defence=%s,strength=%s,speed=%s,crit_chance=%s,crit_damage=%s," +
+ "bonus_attack_speed=%s,intelligence=%s,sea_creature_chance=%s,magic_find=%s,pet_luck=%s}",
+ stats.get("health"), defence, strength, speed, crit_chance, crit_damage, bonus_attack_speed, intelligence,
+ sea_creature_chance, magic_find, pet_luck
+ );
+ }*/
+
+ public float get(String statName) {
+ if (statsJson.has(statName)) {
+ return statsJson.get(statName).getAsFloat();
+ } else {
+ return 0;
+ }
+ }
+
+ public Stats add(Stats stats) {
+ for (Map.Entry<String, JsonElement> statEntry : stats.statsJson.entrySet()) {
+ if (statEntry.getValue().isJsonPrimitive() && ((JsonPrimitive) statEntry.getValue()).isNumber()) {
+ if (!statsJson.has(statEntry.getKey())) {
+ statsJson.add(statEntry.getKey(), statEntry.getValue());
+ } else {
+ JsonPrimitive e = statsJson.get(statEntry.getKey()).getAsJsonPrimitive();
+ float statNum = e.getAsFloat() + statEntry.getValue().getAsFloat();
+ statsJson.add(statEntry.getKey(), new JsonPrimitive(statNum));
+ }
+ }
+ }
+ return this;
+ }
+
+ public void scale(String statName, float scale) {
+ if (statsJson.has(statName)) {
+ statsJson.add(statName, new JsonPrimitive(statsJson.get(statName).getAsFloat() * scale));
+ }
+ }
+
+ public void scaleAll(float scale) {
+ for (Map.Entry<String, JsonElement> statEntry : statsJson.entrySet()) {
+ statsJson.add(statEntry.getKey(), new JsonPrimitive(statEntry.getValue().getAsFloat() * scale));
+ }
+ }
+
+ public void addStat(String statName, float amount) {
+ if (!statsJson.has(statName)) {
+ statsJson.add(statName, new JsonPrimitive(amount));
+ } else {
+ JsonPrimitive e = statsJson.get(statName).getAsJsonPrimitive();
+ statsJson.add(statName, new JsonPrimitive(e.getAsFloat() + amount));
+ }
+ }
+ }
}