Skip to content

Commit

Permalink
using and verifying SkyblockStat
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed Jan 11, 2025
1 parent 8ca5c90 commit de86e01
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:")
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,12 +46,46 @@ import kotlin.time.Duration.Companion.seconds
object ItemUtils {

private val itemNameCache = mutableMapOf<NEUInternalName, String>() // internal name -> item name
var itemBaseStats = mapOf<NEUInternalName, Map<String, Int>>()
private var itemBaseStats = mapOf<NEUInternalName, Map<SkyblockStat, Int>>()
private var itemBaseStatsRaw = mapOf<NEUInternalName, Map<String, Int>>()

private val missingRepoItems = mutableSetOf<String>()
private var lastRepoWarning = SimpleTimeMark.farPast()

fun NEUInternalName.getBaseStats(): Map<String, Int> = itemBaseStats[this].orEmpty()
fun updateBaseStats(rawStats: Map<NEUInternalName, Map<String, Int>>) {
verifyStats(rawStats)
itemBaseStatsRaw = rawStats
}

private fun verifyStats(allRawStats: Map<NEUInternalName, Map<String, Int>>) {
val allItems = mutableMapOf<NEUInternalName, Map<SkyblockStat, Int>>()
val unknownStats = mutableMapOf<String, String>()
for ((internalName, rawStats) in allRawStats) {
val stats = mutableMapOf<SkyblockStat, Int>()
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<SkyblockStat, Int> = itemBaseStats[this].orEmpty()
fun NEUInternalName.getRawBaseStats(): Map<String, Int> = itemBaseStatsRaw[this].orEmpty()

@HandleEvent
fun onConfigLoad(event: ConfigLoadEvent) {
Expand Down Expand Up @@ -241,6 +276,7 @@ object ItemUtils {
// Overload to avoid spread operators
fun createItemStack(item: Item, displayName: String, loreArray: Array<String>, 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<String>, amount: Int = 1, damage: Int = 0): ItemStack {
val stack = ItemStack(item, amount, damage)
Expand Down

0 comments on commit de86e01

Please sign in to comment.