-
Notifications
You must be signed in to change notification settings - Fork 471
feat: secrets per run #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| +1 −1 | types/src/main/kotlin/gg/skytils/hypixel/types/skyblock/dungeon.kt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import gg.skytils.skytilsmod.Skytils.Companion.failPrefix | |
| import gg.skytils.skytilsmod.Skytils.Companion.mc | ||
| import gg.skytils.skytilsmod.core.API | ||
| import gg.skytils.skytilsmod.utils.* | ||
| import gg.skytils.skytilsmod.utils.NumberUtil.roundToPrecision | ||
| import gg.skytils.skytilsmod.utils.NumberUtil.toRoman | ||
| import gg.skytils.skytilsmod.utils.SkillUtils.level | ||
| import kotlinx.coroutines.launch | ||
|
|
@@ -104,6 +105,12 @@ object PartyFinderStats { | |
| val name = playerResponse.formattedName | ||
|
|
||
| val secrets = playerResponse.achievements.getOrDefault("skyblock_treasure_hunter", 0) | ||
| val comps = cataData.tier_completions.values | ||
| val masterComps = masterCataData?.tier_completions?.values ?: emptyList() | ||
| val runs = comps.sum() - (cataData.tier_completions["total"] ?: 0.0) + | ||
| masterComps.sum() - (masterCataData?.tier_completions?.get("total") ?: 0.0) | ||
|
Comment on lines
+108
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of logic for calculating To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, could we extract this calculation into a shared utility function? This function could potentially reside in a relevant utility class (e.g., This would also centralize the fix for the potential division by zero issue. |
||
| val secretsPerRun = ((profileData.dungeons?.secrets ?: 0.0) / runs).roundToPrecision(2) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the It's important to handle the case where val dungeonSecrets = profileData.dungeons?.secrets ?: 0.0
val secretsPerRun = if (runs > 0.0) {
(dungeonSecrets / runs).roundToPrecision(2)
} else {
0.0 // Default to 0.0 secrets/run if there are no runs
} |
||
|
|
||
| val component = UMessage("&2&m--------------------------------\n").append( | ||
| "$name §8» §dCata §9${ | ||
| NumberUtil.nf.format(cataLevel) | ||
|
|
@@ -240,6 +247,7 @@ object PartyFinderStats { | |
| UTextComponent("§5Miscellanous: §7(Hover)\n\n").setHoverText( | ||
| """ | ||
| #§aTotal Secrets Found: §l§e${NumberUtil.nf.format(secrets)} | ||
| #§aSecrets Per Run: §l§e${NumberUtil.nf.format(secretsPerRun)} | ||
| #§aBlood Mobs Killed: §l§e${NumberUtil.nf.format(bloodMobsKilled)} | ||
| #§dMagical Power: §l§e$magicalPower | ||
| """.trimMargin("#") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a potential for division by zero here if
runsis equal to0.0. Ifrunsis0.0andprofileData.dungeons?.secretsis greater than0, the division(profileData.dungeons?.secrets ?: 0.0) / runswould result inInfinity. TheroundToPrecision(2)method then convertsInfinityto a very large finite number, which would be misleading when formatted and displayed to the user. IfprofileData.dungeons?.secretsis0.0andrunsis0.0, the result isNaN, whichroundToPrecision(2)converts to0.0(which is acceptable in this specific sub-case).How about explicitly checking if
runsis greater than zero before performing the division to prevent this and ensure a more accurate representation (e.g., 0 secrets/run if there are no runs)?