Skip to content

Commit

Permalink
Add Hoppity rank in pv (#1191)
Browse files Browse the repository at this point in the history
Co-authored-by: jani270 <[email protected]>
Co-authored-by: SeRaid <[email protected]>
Co-authored-by: Phoebe <[email protected]>
Co-authored-by: nopo <[email protected]>
Co-authored-by: NopoTheGamer <[email protected]>
  • Loading branch information
6 people authored May 31, 2024
1 parent 7227b4d commit c20969c
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,6 @@ public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
int guiTop = GuiProfileViewer.getGuiTop();
super.mouseClicked(mouseX, mouseY, mouseButton);

// Dimensions: X: guiLeft + xStart + xOffset * 3, Y: guiTop + yStartBottom + 77, Width: 80, Height: 12
if (mouseX >= GuiProfileViewer.getGuiLeft() + 22 + 103 * 3 &&
mouseX <= GuiProfileViewer.getGuiLeft() + 22 + 103 * 3 + 80 &&
mouseY >= GuiProfileViewer.getGuiTop() + 105 + 77 && mouseY <= GuiProfileViewer.getGuiTop() + 105 + 77 + 12) {
getInstance().killDeathSearchTextField.mouseClicked(mouseX, mouseY, mouseButton);
getInstance().playerNameTextField.otherComponentClick();
return true;
}

getInstance().killDeathSearchTextField.otherComponentClick();

int i = ProfileViewerUtils.onSlotToChangePage(mouseX, mouseY, guiLeft, guiTop);
switch (i) {
case 1:
Expand All @@ -151,6 +140,21 @@ public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
break;
}

if (onHoppityPage) {
return hoppityPage.mouseClicked(mouseX, mouseY, mouseButton);
}

// Dimensions: X: guiLeft + xStart + xOffset * 3, Y: guiTop + yStartBottom + 77, Width: 80, Height: 12
if (mouseX >= GuiProfileViewer.getGuiLeft() + 22 + 103 * 3 &&
mouseX <= GuiProfileViewer.getGuiLeft() + 22 + 103 * 3 + 80 &&
mouseY >= GuiProfileViewer.getGuiTop() + 105 + 77 && mouseY <= GuiProfileViewer.getGuiTop() + 105 + 77 + 12) {
getInstance().killDeathSearchTextField.mouseClicked(mouseX, mouseY, mouseButton);
getInstance().playerNameTextField.otherComponentClick();
return true;
}

getInstance().killDeathSearchTextField.otherComponentClick();

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c20969c

Please sign in to comment.