From de86e01a3a5aa9463b26a9571d62b82b721219b6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 11 Jan 2025 01:32:47 +0100 Subject: [PATCH] using and verifying SkyblockStat --- .../inventory/bazaar/HypixelItemAPI.kt | 6 +-- .../skyhanni/test/SkyHanniDebugsAndTests.kt | 4 +- .../at/hannibal2/skyhanni/utils/ItemUtils.kt | 40 ++++++++++++++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/HypixelItemAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/HypixelItemAPI.kt index e176f0338611..01cb3fa6aa2d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/HypixelItemAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/HypixelItemAPI.kt @@ -33,14 +33,14 @@ class HypixelItemAPI { val neuItemId = NEUItems.transHypixelNameToInternalName(item.id ?: continue) item.npcPrice?.let { list[neuItemId] = it } item.motesPrice?.let { motesPrice[neuItemId] = it } - item.stats?.let { stats -> allStats[neuItemId] = stats.mapKeys { it.key.lowercase() } } + item.stats?.let { stats -> allStats[neuItemId] = stats } } - ItemUtils.itemBaseStats = allStats + ItemUtils.updateBaseStats(allStats) RiftAPI.motesPrice = motesPrice } catch (e: Throwable) { ErrorManager.logErrorWithData( e, "Error getting npc sell prices", - "hypixelApiResponse" to apiResponse + "hypixelApiResponse" to apiResponse, ) } return list diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt index 588da6aa1621..1db07ec81034 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt @@ -29,11 +29,11 @@ import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemPriceUtils.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPriceOrNull import at.hannibal2.skyhanni.utils.ItemPriceUtils.getRawCraftCostOrNull -import at.hannibal2.skyhanni.utils.ItemUtils.getBaseStats import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull +import at.hannibal2.skyhanni.utils.ItemUtils.getRawBaseStats import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LocationUtils @@ -459,7 +459,7 @@ object SkyHanniDebugsAndTests { if (!debugConfig.showBaseValues) return val internalName = event.itemStack.getInternalNameOrNull() ?: return - val stats = internalName.getBaseStats() + val stats = internalName.getRawBaseStats() if (stats.isEmpty()) return event.toolTip.add("ยง7Base stats:") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 1b21a19756e1..440565e9b2dd 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.data.NotificationManager import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.data.SkyHanniNotification +import at.hannibal2.skyhanni.data.model.SkyblockStat import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.features.misc.ReplaceRomanNumerals @@ -45,12 +46,46 @@ import kotlin.time.Duration.Companion.seconds object ItemUtils { private val itemNameCache = mutableMapOf() // internal name -> item name - var itemBaseStats = mapOf>() + private var itemBaseStats = mapOf>() + private var itemBaseStatsRaw = mapOf>() private val missingRepoItems = mutableSetOf() private var lastRepoWarning = SimpleTimeMark.farPast() - fun NEUInternalName.getBaseStats(): Map = itemBaseStats[this].orEmpty() + fun updateBaseStats(rawStats: Map>) { + verifyStats(rawStats) + itemBaseStatsRaw = rawStats + } + + private fun verifyStats(allRawStats: Map>) { + val allItems = mutableMapOf>() + val unknownStats = mutableMapOf() + for ((internalName, rawStats) in allRawStats) { + val stats = mutableMapOf() + for ((rawStat, value) in rawStats) { + val stat = SkyblockStat.getValueOrNull(rawStat) + if (stat == null) { + unknownStats["`$rawStat`"] = "on '$internalName'" + } else { + stats[stat] = value + } + } + allItems[internalName] = stats + } + if (unknownStats.isNotEmpty()) { + val name = StringUtils.pluralize(unknownStats.size, "stat", withNumber = true) + ErrorManager.logErrorStateWithData( + "Found unknown skyblock stats on items, please report this in disocrd", + "found $name via Hypixel Item API that are not in enum SkyblockStat", + // TODO logErrorStateWithData should accept a map of extra data directly + extraData = unknownStats.map { it.key to it.value }.toTypedArray(), + ) + } + itemBaseStats = allItems + } + + fun NEUInternalName.getBaseStats(): Map = itemBaseStats[this].orEmpty() + fun NEUInternalName.getRawBaseStats(): Map = itemBaseStatsRaw[this].orEmpty() @HandleEvent fun onConfigLoad(event: ConfigLoadEvent) { @@ -241,6 +276,7 @@ object ItemUtils { // Overload to avoid spread operators fun createItemStack(item: Item, displayName: String, loreArray: Array, amount: Int = 1, damage: Int = 0): ItemStack = createItemStack(item, displayName, loreArray.toList(), amount, damage) + // Taken from NEU fun createItemStack(item: Item, displayName: String, lore: List, amount: Int = 1, damage: Int = 0): ItemStack { val stack = ItemStack(item, amount, damage)