Skip to content

Commit

Permalink
moved command, fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Oct 15, 2024
1 parent c189a23 commit a79f5be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import at.hannibal2.skyhanni.config.ConfigGuiManager
import at.hannibal2.skyhanni.data.ChatManager
import at.hannibal2.skyhanni.data.GardenCropMilestonesCommunityFix
import at.hannibal2.skyhanni.data.PartyAPI
import at.hannibal2.skyhanni.data.PetAPI
import at.hannibal2.skyhanni.data.SackAPI
import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.data.TitleManager
Expand Down Expand Up @@ -785,11 +784,6 @@ object Commands {
category = CommandCategory.DEVELOPER_TEST
callback { SkyBlockIslandTest.onCommand(it) }
}
event.register("shcalcpetxp") {
description = "Gets the pet xp from a given level and rarity."
category = CommandCategory.DEVELOPER_TEST
callback { PetAPI.testLevelToXP(it) }
}
}

private fun internalCommands(event: CommandRegistrationEvent) {
Expand Down
39 changes: 26 additions & 13 deletions src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.jsonobjects.repo.NEUPetsJson
import at.hannibal2.skyhanni.data.model.TabWidget
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
Expand All @@ -22,6 +25,7 @@ import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatDoubleOrNull
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.chat.Text.hover
Expand Down Expand Up @@ -267,7 +271,7 @@ object PetAPI {
val rarity = LorenzRarity.getByColorCode(group("rarity")[0]) ?: LorenzRarity.ULTIMATE

val newPet = PetData(
petNametoInternalName(petName, rarity),
petNameToInternalName(petName, rarity),
petName,
rarity,
petItem,
Expand Down Expand Up @@ -299,8 +303,8 @@ object PetAPI {
xpWidgetPattern.matchMatcher(line) {
if (group("max") != null) return null

val overflow = group("overflow")?.replace(",", "")?.toDoubleOrNull() ?: 0.0
val currentXP = group("currentXP")?.replace(",", "")?.toDoubleOrNull() ?: 0.0
val overflow = group("overflow")?.formatDoubleOrNull() ?: 0.0
val currentXP = group("currentXP")?.formatDoubleOrNull() ?: 0.0

return overflow + currentXP
}
Expand Down Expand Up @@ -350,7 +354,7 @@ object PetAPI {
val fakePetLine = "§r§7[Lvl $level] §r${rarity.chatColorCode}$petName${if (hasSkin) "§r${group("skin")}" else ""}"

val newPet = PetData(
petNametoInternalName(petName, rarity),
petNameToInternalName(petName, rarity),
petName,
rarity,
petItem,
Expand All @@ -373,7 +377,7 @@ object PetAPI {
}

@SubscribeEvent
fun onOpenInventory(event: InventoryFullyOpenedEvent) {
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!isPetMenu(event.inventoryName)) {
inPetMenu = false
return
Expand All @@ -388,12 +392,12 @@ object PetAPI {
}

@SubscribeEvent
fun onCloseInventory(event: InventoryCloseEvent) {
fun onInventoryClose(event: InventoryCloseEvent) {
inPetMenu = false
}

@SubscribeEvent
fun onItemClick(event: GuiContainerEvent.SlotClickEvent) {
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
if (!inPetMenu) return
if (event.clickTypeEnum != GuiContainerEvent.ClickType.NORMAL) return
val category = event.item?.getItemCategoryOrNull() ?: return
Expand Down Expand Up @@ -463,7 +467,7 @@ object PetAPI {
}

return PetData(
petNametoInternalName(name, rarity),
petNameToInternalName(name, rarity),
name,
rarity,
NEUInternalName.NONE,
Expand All @@ -474,7 +478,16 @@ object PetAPI {
)
}

fun testLevelToXP(input: Array<String>) {
@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shcalcpetxp") {
description = "Gets the pet xp from a given level and rarity."
category = CommandCategory.DEVELOPER_TEST
callback { testLevelToXP(it) }
}
}

private fun testLevelToXP(input: Array<String>) {
if (input.size >= 3) {
val level = input[0].toIntOrNull()
val rarity = LorenzRarity.getByName(input[1])
Expand All @@ -492,7 +505,7 @@ object PetAPI {
}
private fun levelToXP(level: Int, rarity: LorenzRarity, petName: String = ""): Double? {
val newPetName = petNametoFakeInternalName(petName)
val newPetName = petNameToFakeInternalName(petName)
val petObject = xpLevelingCustom?.getAsJsonObject(newPetName)
val rarityOffset = getRarityOffset(rarity, petObject?.getAsJsonObject("rarity_offset")) ?: return null
Expand Down Expand Up @@ -576,15 +589,15 @@ object PetAPI {
}
}
private fun petNametoFakeInternalName(petName: String): String {
private fun petNameToFakeInternalName(petName: String): String {
return when (petName.uppercase()) {
"T-REX" -> "TYRANNOSAURUS"
else -> petName.uppercase().replace(" ", "_")
}
}
private fun petNametoInternalName(petName: String, rarity: LorenzRarity): NEUInternalName {
return "${petNametoFakeInternalName(petName)};${rarity.id}".asInternalName()
private fun petNameToInternalName(petName: String, rarity: LorenzRarity): NEUInternalName {
return "${petNameToFakeInternalName(petName)};${rarity.id}".asInternalName()
}
fun PetData?.arePetsEqual(pet2: PetData?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.data.PetData

/**
* This event fires when a pet change occurs and on joining SkyBlock for the first time in a session.
* This event fires when a pet change occurs and when joining SkyBlock for the first time in a session.
* The XP value in the PetData might not be accurate.
*
* @property oldPet The previous pet before the change.
Expand Down

0 comments on commit a79f5be

Please sign in to comment.