diff options
author | Lulonaut <lulonaut@lulonaut.tech> | 2023-09-27 13:10:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-27 21:10:16 +1000 |
commit | c41f5adb3977d8d60944c548fa2b456587256f5f (patch) | |
tree | 9ee5bdc131d12251327369757322c0d062ad306d | |
parent | 4cc84e3fd1b67e1e7f5b7c744e08dfee915708b1 (diff) | |
download | NotEnoughUpdates-c41f5adb3977d8d60944c548fa2b456587256f5f.tar.gz NotEnoughUpdates-c41f5adb3977d8d60944c548fa2b456587256f5f.tar.bz2 NotEnoughUpdates-c41f5adb3977d8d60944c548fa2b456587256f5f.zip |
Fix skyblock level calculations in PV (#828)
4 files changed, 44 insertions, 32 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java index 3bfac529..3184fba6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java @@ -950,8 +950,13 @@ public class SkyblockProfiles { return levelingInfo = out; } - public int getBestiaryLevel() { - return BestiaryData.calculateTotalBestiaryLevel(BestiaryData.parseBestiaryData(getProfileJson())); + /** + * Get the Skyblock XP provided by the bestiary progress for this profile + * + * @return skyblock xp + */ + public int getBestiaryXp() { + return BestiaryData.calculateBestiarySkyblockXp(getProfileJson()); } public JsonObject getPetsInfo() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.kt b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.kt index ff2d2288..51083622 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.kt +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.kt @@ -23,6 +23,7 @@ import com.google.gson.JsonObject import io.github.moulberry.notenoughupdates.util.Constants import io.github.moulberry.notenoughupdates.util.ItemUtils import io.github.moulberry.notenoughupdates.util.Utils +import kotlin.math.min object BestiaryData { private val categoriesToParse = listOf( @@ -51,12 +52,33 @@ object BestiaryData { * @see BestiaryPage.parseBestiaryData */ @JvmStatic - fun calculateTotalBestiaryLevel(computedCategories: List<Category>): Int { - var level = 0.0 + fun calculateTotalBestiaryTiers(computedCategories: List<Category>): Int { + var tiers = 0.0 computedCategories.forEach { - level += countTotalLevels(it) + tiers += countTotalLevels(it) } - return level.toInt() - 1 + return tiers.toInt() + } + + /** + * Calculate the skyblock xp awarded for the given bestiary progress + */ + @JvmStatic + fun calculateBestiarySkyblockXp(profileInfo: JsonObject): Int { + val totalTiers = calculateTotalBestiaryTiers(parseBestiaryData(profileInfo)) + var skyblockXp = 0 + + val slayingTask = Constants.SBLEVELS.getAsJsonObject("slaying_task") ?: return 0 + val xpPerTier = (slayingTask.get("bestiary_family_xp") ?: return 0).asInt + val xpPerMilestone = slayingTask.get("bestiary_milestone_xp").asInt + val maxXp = slayingTask.get("bestiary_progress").asInt + + skyblockXp += totalTiers * xpPerTier + + val milestones = (totalTiers / 100) + skyblockXp += milestones * xpPerMilestone + + return min(skyblockXp, maxXp) } private fun countTotalLevels(category: Category): Int { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.kt b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.kt index ea5a576b..896a8fb5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.kt +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.kt @@ -21,7 +21,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.bestiary import io.github.moulberry.notenoughupdates.core.util.StringUtils import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewerPage -import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData.calculateTotalBestiaryLevel +import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData.calculateTotalBestiaryTiers import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData.hasMigrated import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData.parseBestiaryData import io.github.moulberry.notenoughupdates.util.Constants @@ -61,7 +61,7 @@ class BestiaryPage(instance: GuiProfileViewer?) : GuiProfileViewerPage(instance) private var lastSelectedCategory = "" private var selectedSubCategory = "" private var tooltipToDisplay: MutableList<String> = mutableListOf() - private var bestiaryLevel = 0 + private var bestiaryLevel = 0.0 private var computedCategories: MutableList<Category> = mutableListOf() private val bestiaryTexture = ResourceLocation("notenoughupdates:pv_bestiary_tab.png") @@ -90,7 +90,7 @@ class BestiaryPage(instance: GuiProfileViewer?) : GuiProfileViewerPage(instance) // Do the initial parsing only once if (computedCategories.isEmpty()) { computedCategories = parseBestiaryData(profileInfo) - bestiaryLevel = calculateTotalBestiaryLevel(computedCategories) + bestiaryLevel = calculateTotalBestiaryTiers(computedCategories).toDouble() } val bestiarySize = computedCategories.size val bestiaryXSize = (350f / (bestiarySize - 1 + 0.0000001f)).toInt() @@ -150,7 +150,7 @@ class BestiaryPage(instance: GuiProfileViewer?) : GuiProfileViewerPage(instance) val color = Color(128, 128, 128, 255) Utils.renderAlignedString( EnumChatFormatting.RED.toString() + "Milestone: ", - "${EnumChatFormatting.GRAY}${(bestiaryLevel / 10) - 1}", + "${EnumChatFormatting.GRAY}${(bestiaryLevel / 10)}", (guiLeft + 280).toFloat(), (guiTop + 50).toFloat(), 110 diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java index a8301bb6..9bf5395e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java @@ -161,10 +161,7 @@ public class SlayingTaskLevel extends GuiTaskLevel { if (kuudraBossCollection >= 5000) bossCollectionXp += 30; } - int sbXpBestiary = 0; - int bestiaryTiers = GuiProfileViewer.getSelectedProfile().getBestiaryLevel(); - sbXpBestiary += bestiaryTiers; - sbXpBestiary = sbXpBestiary + (sbXpBestiary / 10) * 2; + int sbXpBestiary = GuiProfileViewer.getSelectedProfile().getBestiaryXp(); int mythologicalKillsXp = 0; if (object.has("stats")) { @@ -179,13 +176,7 @@ public class SlayingTaskLevel extends GuiTaskLevel { int sbXpFromDragonKills = 0; JsonObject slayDragonsXp = slayingTask.getAsJsonObject("slay_dragons_xp"); for (Map.Entry<String, JsonElement> stringJsonElementEntry : slayDragonsXp.entrySet()) { - String key = stringJsonElementEntry.getKey(); - int value = stringJsonElementEntry.getValue().getAsInt(); - // kills_superior_dragon_100 - float element = Utils.getElementAsFloat(Utils.getElement(object, "bestiary.kills_" + key + "_100"), 0); - if (element > 0) { - sbXpFromDragonKills += value; - } + sbXpFromDragonKills += stringJsonElementEntry.getValue().getAsInt(); } // slayer kills @@ -215,21 +206,15 @@ public class SlayingTaskLevel extends GuiTaskLevel { // arachne JsonArray defeatArachneXp = slayingTask.get("defeat_arachne_xp").getAsJsonArray(); int sbXpGainedArachne = 0; - - JsonElement tier1 = Utils.getElement(object, "bestiary.kills_arachne_300"); - if (tier1 != null) { - sbXpGainedArachne += defeatArachneXp.get(0).getAsInt(); - } - - JsonElement tier2 = Utils.getElement(object, "bestiary.kills_arachne_500"); - if (tier2 != null) { - sbXpGainedArachne += defeatArachneXp.get(1).getAsInt(); + for (JsonElement jsonElement : defeatArachneXp) { + sbXpGainedArachne += jsonElement.getAsInt(); } List<String> lore = new ArrayList<>(); int slayerLevelUpMax = slayingTask.get("slayer_level_up").getAsInt(); int bossCollectionsMax = slayingTask.get("boss_collections").getAsInt(); + int bestiaryXpMax = slayingTask.get("bestiary_progress").getAsInt(); int slayDragonsMax = slayingTask.get("slay_dragons").getAsInt(); int defeatSlayersMax = slayingTask.get("defeat_slayers").getAsInt(); int defeatKuudraMax = slayingTask.get("defeat_kuudra").getAsInt(); @@ -237,7 +222,7 @@ public class SlayingTaskLevel extends GuiTaskLevel { lore.add(levelPage.buildLore("Slayer Level Up", sbXpGainedSlayer, slayerLevelUpMax, false)); lore.add(levelPage.buildLore("Boss Collections", bossCollectionXp, bossCollectionsMax, false)); - lore.add(levelPage.buildLore("Bestiary Progress", sbXpBestiary, 0, true)); + lore.add(levelPage.buildLore("Bestiary Progress", sbXpBestiary, bestiaryXpMax, false)); lore.add(levelPage.buildLore("Mythological Kills", mythologicalKillsXp, mythologicalKillsMax, false)); lore.add(levelPage.buildLore("Slay Dragons", sbXpFromDragonKills, slayDragonsMax, false)); lore.add(levelPage.buildLore("Defeat Slayers", sbXpFromSlayerDefeat, defeatSlayersMax, false)); @@ -247,7 +232,7 @@ public class SlayingTaskLevel extends GuiTaskLevel { int slayingTaskMax = levelPage.getConstant().getAsJsonObject("category_xp").get("slaying_task").getAsInt(); int totalXp = sbXpGainedSlayer + bossCollectionXp + mythologicalKillsXp + - sbXpFromDragonKills + sbXpFromSlayerDefeat + sbXpDefeatKuudra + sbXpGainedArachne; + sbXpFromDragonKills + sbXpFromSlayerDefeat + sbXpDefeatKuudra + sbXpGainedArachne + sbXpBestiary; levelPage.renderLevelBar( "Slaying Task", new ItemStack(Items.golden_sword), |