aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/io')
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityLeaderboardRank.kt114
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityPage.kt65
2 files changed, 167 insertions, 12 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityLeaderboardRank.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityLeaderboardRank.kt
new file mode 100644
index 00000000..f85691be
--- /dev/null
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityLeaderboardRank.kt
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2024 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.miscfeatures.profileviewer
+
+import com.google.gson.JsonObject
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates
+import io.github.moulberry.notenoughupdates.core.util.StringUtils
+import io.github.moulberry.notenoughupdates.util.Utils
+import io.github.moulberry.notenoughupdates.util.getIntOrValue
+import io.github.moulberry.notenoughupdates.util.kotlin.Coroutines
+
+object HoppityLeaderboardRank {
+
+ private val manager get() = NotEnoughUpdates.INSTANCE.manager
+
+ private var leaderboardRank = -1
+ private var currentRankStatus = HoppityLeaderboardRankStatus.LOADING
+ private var currentlyLoading = false
+
+ fun getRank(): String = StringUtils.formatNumber(leaderboardRank)
+
+ fun getRankInfo() = currentRankStatus.getDisplayString()
+ fun getAdditionalInfo() = currentRankStatus.getAdditionalInfoString()
+
+ fun resetData() {
+ leaderboardRank = -1
+ currentRankStatus = HoppityLeaderboardRankStatus.LOADING
+ currentlyLoading = false
+ }
+
+ fun openWebsite() {
+ if (currentRankStatus == HoppityLeaderboardRankStatus.LOADING) return
+ Utils.openUrl("https://elitebot.dev/leaderboard/chocolate")
+ Utils.playPressSound()
+ }
+
+ fun loadData(uuid: String?, profileId: String?) {
+ if (uuid == null || profileId == null) {
+ processResult(-1, true)
+ return
+ }
+ if (currentlyLoading) return
+ currentlyLoading = true
+ Coroutines.launchCoroutine {
+
+ manager.apiUtils.request()
+ .url("https://api.elitebot.dev/leaderboard/rank/chocolate/$uuid/$profileId")
+ .requestJson()
+ .whenComplete { json: JsonObject?, error: Throwable? ->
+ if (error != null || json == null) {
+ processResult(-1, true, uuid)
+ } else {
+ val rank = json.getIntOrValue("rank", -1)
+ processResult(rank)
+ }
+ }
+ }
+ }
+
+ private fun processResult(rank: Int, errored: Boolean = false, uuid: String? = null) {
+ if (!currentlyLoading) return
+ if (errored) {
+ currentRankStatus = HoppityLeaderboardRankStatus.ERROR
+ if (uuid != null) {
+ addToElite(uuid)
+ }
+ } else if (rank == -1) {
+ currentRankStatus = HoppityLeaderboardRankStatus.TOO_LOW
+ } else {
+ leaderboardRank = rank
+ currentRankStatus = HoppityLeaderboardRankStatus.FOUND
+ }
+ currentlyLoading = false
+ }
+
+ private fun addToElite(uuid: String) {
+ // errors when player has never been loaded on elitebot before, load their whole profile to add them to it
+ manager.apiUtils.request()
+ .url("https://api.elitebot.dev/account/$uuid")
+ .requestJson()
+ }
+}
+
+enum class HoppityLeaderboardRankStatus(private val display: () -> String, private val additionalInfo: () -> String) {
+ LOADING({ "Loading..." }, { "§eStill loading data." }),
+ TOO_LOW({ "Too Low" }, { "§eLeaderboard only has top 5,000 players." }),
+ FOUND(
+ { HoppityLeaderboardRank.getRank() },
+ { "§7#§b${HoppityLeaderboardRank.getRank()} §7on the Elitebot chocolate leaderboard." }
+ ),
+
+ ERROR({ "Error" }, { "§cError while fetching leaderboard rank, try again later." }),
+ ;
+
+ fun getDisplayString() = display()
+ fun getAdditionalInfoString() = additionalInfo()
+}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityPage.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityPage.kt
index d26c6fde..052ac8ac 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityPage.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/profileviewer/HoppityPage.kt
@@ -164,7 +164,12 @@ class HoppityPage(pvInstance: GuiProfileViewer) : GuiProfileViewerPage(pvInstanc
Utils.renderAlignedString(
"§eUntil Prestige:",
if (chocolateForNextPrestige() != 0L) {
- "§f${StringUtils.shortNumberFormat(chocolateForNextPrestige().toDouble() - prestigeChocolate.toDouble())}"
+ val amount = chocolateForNextPrestige().toDouble() - prestigeChocolate.toDouble()
+ if (amount < 0) {
+ "§f0"
+ } else {
+ "§f${StringUtils.shortNumberFormat(amount)}"
+ }
} else {
"§f§lMax"
},
@@ -265,7 +270,21 @@ class HoppityPage(pvInstance: GuiProfileViewer) : GuiProfileViewerPage(pvInstanc
listOf("§7Chocolate Spent: §6${StringUtils.formatNumber(chocolateSpent)}")
)
- //178
+ drawAlignedStringWithHover(
+ "§eLeaderboard Rank:",
+ "§f${HoppityLeaderboardRank.getRankInfo()}",
+ guiLeft + 160,
+ guiTop + 178,
+ 110,
+ mouseX,
+ mouseY,
+ listOf(
+ HoppityLeaderboardRank.getAdditionalInfo(),
+ "",
+ "Data provided by the Elitebot API.",
+ "§eClick to view on the Elitebot website."
+ )
+ )
rabbitFamilyInfo.displayInfo(31, 32, mouseX, mouseY)
rabbitFamilyInfo2.displayInfo(42, 66, mouseX, mouseY)
@@ -281,6 +300,18 @@ class HoppityPage(pvInstance: GuiProfileViewer) : GuiProfileViewerPage(pvInstanc
}
}
+ override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int): Boolean {
+
+ if (mouseButton == 0) {
+ if (mouseX in (guiLeft + 160)..(guiLeft + 270) && mouseY in (guiTop + 178)..(guiTop + 190)) {
+ HoppityLeaderboardRank.openWebsite()
+ }
+ }
+
+ return false
+ }
+
+
private fun drawAlignedStringWithHover(
first: String,
second: String,
@@ -522,19 +553,28 @@ class HoppityPage(pvInstance: GuiProfileViewer) : GuiProfileViewerPage(pvInstanc
if (data.profile?.cookie_buff_active == true) {
baseMultiplier = 1.25
}
- val activePet = selectedProfile?.petsInfo?.get("active_pet")?.asJsonObject
-
- if (activePet != null && activePet.get("type").asString == "RABBIT" && activePet.get("tier").asString == "MYTHIC") {
- val petLevel = PetLeveling.getPetLevelingForPet("RABBIT", PetInfoOverlay.Rarity.MYTHIC)
- .getPetLevel(activePet.get("exp").asDouble).currentLevel
-
- //calculation is 0.01 + 0.0004 per pet level
- baseMultiplier += 0.01 + (petLevel * 0.0004)
+ val activePetInfo = selectedProfile?.petsInfo?.get("active_pet")
+ if (activePetInfo != null && !activePetInfo.isJsonNull) {
+ activePetInfo.asJsonObject?.let { pet ->
+ if (pet.get("type").asString == "RABBIT" && pet.get("tier").asString == "MYTHIC") {
+ val petLevel = PetLeveling.getPetLevelingForPet("RABBIT", PetInfoOverlay.Rarity.MYTHIC)
+ .getPetLevel(pet.get("exp").asDouble).currentLevel
+
+ //calculation is 0.01 + 0.0004 per pet level
+ baseMultiplier += 0.01 + (petLevel * 0.0004)
+ }
+ }
}
rabbitToRarity.clear()
RabbitCollectionRarity.resetData()
+ val profileId = selectedProfile?.outerProfileJson?.get("profile_id")?.asString?.replace("-", "")
+ val uuid = GuiProfileViewer.getProfile()?.uuid
+
+ HoppityLeaderboardRank.resetData()
+ HoppityLeaderboardRank.loadData(uuid, profileId)
+
val hoppityData = hoppityJson.getAsJsonObject("hoppity") ?: return
val rabbitRarities = hoppityData.getAsJsonObject("rarities") ?: return
val specialRabbits = hoppityData.getAsJsonObject("special") ?: return
@@ -576,7 +616,6 @@ class HoppityPage(pvInstance: GuiProfileViewer) : GuiProfileViewerPage(pvInstanc
}
for (mythic in foundMythicRabbits) {
- //TODO check if these names are correct when hypixel adds them to the api
if (mythic == "sigma") {
RabbitCollectionRarity.MYTHIC.chocolatePerSecond += 5 * foundMythicRabbits.size
}
@@ -599,6 +638,7 @@ class HoppityPage(pvInstance: GuiProfileViewer) : GuiProfileViewerPage(pvInstanc
totalRabbit.maximum = RabbitCollectionRarity.values().sumOf { it.maximum }
rabbitFamilyInfo.clear()
+ rabbitFamilyInfo2.clear()
factoryModifiersInfo.clear()
otherModifiersInfo.clear()
@@ -751,7 +791,8 @@ class HoppityPage(pvInstance: GuiProfileViewer) : GuiProfileViewerPage(pvInstanc
multiplier = baseMultiplier + prestigeMultiplier + coachMultiplier + rabbitMultiplier
val rabbitChocolate = RabbitCollectionRarity.TOTAL.chocolatePerSecond
- val employeeChocolate = rabbitFamilyInfo.sumOf { it.extraCps * it.level } + rabbitFamilyInfo2.sumOf { it.extraCps * it.level }
+ val employeeChocolate =
+ rabbitFamilyInfo.sumOf { it.extraCps * it.level } + rabbitFamilyInfo2.sumOf { it.extraCps * it.level }
rawChocolatePerSecond = rabbitChocolate + employeeChocolate + talismanChocolate
chocolatePerSecond = rawChocolatePerSecond * multiplier