Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Base Stats #3197

Merged
merged 12 commits into from
Jan 11, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public class DebugConfig {
@ConfigEditorBoolean
public boolean showNpcPrice = false;

@Expose
@ConfigOption(name = "Show Base Values", desc = "Show item base values in item lore.")
@ConfigEditorBoolean
public boolean showBaseValues = false;

@Expose
@ConfigOption(name = "Show Craft Price", desc = "Show craft price in item lore.")
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ data class SkyblockItemData(
@Expose val id: String?,
@Expose @SerializedName("npc_sell_price") val npcPrice: Double?,
@Expose @SerializedName("motes_sell_price") val motesPrice: Double?,
@Expose @SerializedName("stats") val stats: Map<String, Int>?,
hannibal002 marked this conversation as resolved.
Show resolved Hide resolved
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object BazaarApi {

private var loadedNpcPriceData = false

val holder = BazaarDataHolder()
val holder = HypixelItemAPI()
var inBazaarInventory = false
private var currentSearchedItem = ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import at.hannibal2.skyhanni.data.jsonobjects.other.SkyblockItemsDataJson
import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.APIUtils
import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.json.fromJson
import kotlinx.coroutines.launch

class BazaarDataHolder {
class HypixelItemAPI {

companion object {

Expand All @@ -27,11 +28,14 @@ class BazaarDataHolder {
val itemsData = ConfigManager.gson.fromJson<SkyblockItemsDataJson>(apiResponse)

val motesPrice = mutableMapOf<NEUInternalName, Double>()
val allStats = mutableMapOf<NEUInternalName, Map<String, Int>>()
for (item in itemsData.items) {
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() } }
}
ItemUtils.itemBaseStats = allStats
RiftAPI.motesPrice = motesPrice
} catch (e: Throwable) {
ErrorManager.logErrorWithData(
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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
Expand Down Expand Up @@ -452,6 +453,22 @@ object SkyHanniDebugsAndTests {
event.toolTip.add("§7NPC price: ${npcPrice.addSeparators()}")
}

@SubscribeEvent
fun onShowBaseStats(event: LorenzToolTipEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!debugConfig.showBaseValues) return
val internalName = event.itemStack.getInternalNameOrNull() ?: return

val stats = internalName.getBaseStats()
if (stats.isEmpty()) return

event.toolTip.add("§7Base stats:")
for ((name, value) in stats) {

event.toolTip.add("§7$name: $value")
}
}

@SubscribeEvent
fun onShowCraftPrice(event: LorenzToolTipEvent) {
if (!LorenzUtils.inSkyBlock) return
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.getBazaarData
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarDataHolder
import at.hannibal2.skyhanni.features.inventory.bazaar.HypixelItemAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getRecipePrice
Expand Down Expand Up @@ -92,7 +92,7 @@ object ItemPriceUtils {
if (this == NEUInternalName.WISP_POTION) {
return 20_000.0
}
return BazaarDataHolder.getNpcPrice(this)
return HypixelItemAPI.getNpcPrice(this)
}

fun debugItemPrice(args: Array<String>) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ 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 val missingRepoItems = mutableSetOf<String>()
private var lastRepoWarning = SimpleTimeMark.farPast()

fun NEUInternalName.getBaseStats(): Map<String, Int> = itemBaseStats[this].orEmpty()

@HandleEvent
fun onConfigLoad(event: ConfigLoadEvent) {
ConditionalUtils.onToggle(SkyHanniMod.feature.misc.replaceRomanNumerals) {
Expand Down
Loading