From e350ade0d86955ce1a865f4286cd208d54693777 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 12 Sep 2024 02:33:44 +0200 Subject: Improvement: Stars in Estimated Item Value (#2492) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../hannibal2/skyhanni/utils/EssenceItemUtils.kt | 136 +++++++++++++++++++++ .../skyhanni/utils/SkyBlockItemModifierUtils.kt | 4 +- 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/EssenceItemUtils.kt (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EssenceItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EssenceItemUtils.kt new file mode 100644 index 000000000..fbb106d08 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/EssenceItemUtils.kt @@ -0,0 +1,136 @@ +package at.hannibal2.skyhanni.utils + +import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.data.jsonobjects.repo.neu.NeuEssenceCostJson +import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object EssenceItemUtils { + var itemPrices = mapOf>() + + @SubscribeEvent + fun onNeuRepoReload(event: NeuRepositoryReloadEvent) { + val unformattedData = event.getConstant>("essencecosts", NeuEssenceCostJson.TYPE) + + ConfigManager.gson.toJson(unformattedData).let { + ChatUtils.debug("saved to clipboard!") + OSUtils.copyToClipboard(it) + } + this.itemPrices = reformatData(unformattedData) + + println("result: ${itemPrices.size}") + } + + fun NEUInternalName.getEssencePrices(): Map? = itemPrices[this] + + private fun reformatData(unformattedData: Map): MutableMap> { + val itemPrices = mutableMapOf>() + for ((name, data) in unformattedData) { + + val essencePrices = loadEssencePrices(data) + val extraItems = data.extraItems ?: emptyMap() + val (coinPrices, iemPrices) = loadCoinAndItemPrices(extraItems) + + val upgradePrices = mutableMapOf() + for ((tier, essencePrice) in essencePrices) { + val coinPrice = coinPrices[tier] + val itemPrice = iemPrices[tier] ?: emptyMap() + upgradePrices[tier] = EssenceUpgradePrice(essencePrice, coinPrice, itemPrice) + } + + val internalName = name.asInternalName() + itemPrices[internalName] = upgradePrices + } + return itemPrices + } + + private fun loadCoinAndItemPrices( + extraItems: Map>, + ): Pair, MutableMap>> { + + val collectCoinPrices = mutableMapOf() + val collectItemPrices = mutableMapOf>() + + for ((tier, rawItems) in extraItems.mapKeys { it.key.toInt() }) { + val itemPrices = mutableMapOf() + + for ((itemName, amount) in rawItems.map { split(it) }) { + if (itemName == NEUInternalName.SKYBLOCK_COIN) { + collectCoinPrices[tier] = amount + } else { + itemPrices[itemName] = amount.toInt() + } + } + + collectItemPrices[tier] = itemPrices + } + return Pair(collectCoinPrices, collectItemPrices) + } + + private fun split(string: String): Pair = string.split(":").let { it[0].asInternalName() to it[1].toLong() } + + private fun loadEssencePrices(data: NeuEssenceCostJson): MutableMap { + val map = mutableMapOf() + val essenceType = data.essenceType + data.essenceFor1?.let { map[1] = EssencePrice(it, essenceType) } + data.essenceFor2?.let { map[2] = EssencePrice(it, essenceType) } + data.essenceFor3?.let { map[3] = EssencePrice(it, essenceType) } + data.essenceFor4?.let { map[4] = EssencePrice(it, essenceType) } + data.essenceFor5?.let { map[5] = EssencePrice(it, essenceType) } + data.essenceFor6?.let { map[6] = EssencePrice(it, essenceType) } + data.essenceFor7?.let { map[7] = EssencePrice(it, essenceType) } + data.essenceFor8?.let { map[8] = EssencePrice(it, essenceType) } + data.essenceFor9?.let { map[9] = EssencePrice(it, essenceType) } + data.essenceFor10?.let { map[10] = EssencePrice(it, essenceType) } + data.essenceFor11?.let { map[11] = EssencePrice(it, essenceType) } + data.essenceFor12?.let { map[12] = EssencePrice(it, essenceType) } + data.essenceFor13?.let { map[13] = EssencePrice(it, essenceType) } + data.essenceFor14?.let { map[14] = EssencePrice(it, essenceType) } + data.essenceFor15?.let { map[15] = EssencePrice(it, essenceType) } + return map + } + + data class EssenceUpgradePrice( + val essencePrice: EssencePrice, + val coinPrice: Long?, + val itemPrice: Map, + ) { + + operator fun plus(other: EssenceUpgradePrice): EssenceUpgradePrice { + if (other.essencePrice.essenceType != essencePrice.essenceType) ErrorManager.skyHanniError( + "Trying to add non compatible EssenceUpgradePrices!", + "essencePrice.essenceType" to essencePrice.essenceType, + "other.essencePrice.essenceType" to other.essencePrice.essenceType, + ) + + val coinPrice = coinPrice ?: 0L + val otherCoinPrice = other.coinPrice ?: 0L + + val map = itemPrice.toMutableMap() + for (entry in other.itemPrice) { + map.addOrPut(entry.key, entry.value) + } + + return EssenceUpgradePrice(essencePrice + other.essencePrice, coinPrice + otherCoinPrice, map) + } + } + + data class EssencePrice(val essenceAmount: Int, val essenceType: String) { + + operator fun plus(other: EssencePrice): EssencePrice { + if (other.essenceType != essenceType) ErrorManager.skyHanniError( + "Trying to add non compatible essence prices!", + "essenceType" to essenceType, + "other.essenceType" to other.essenceType, + ) + + return EssencePrice(essenceAmount + other.essenceAmount, essenceType) + } + } + +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index c9e193329..4d0cf4468 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -46,9 +46,11 @@ object SkyBlockItemModifierUtils { fun ItemStack.getManaDisintegrators() = getAttributeInt("mana_disintegrator_count") fun ItemStack.getDungeonStarCount() = if (isDungeonItem()) { - getAttributeInt("upgrade_level") ?: getAttributeInt("dungeon_item_level") + getStarCount() ?: getAttributeInt("dungeon_item_level") } else null + fun ItemStack.getStarCount() = getAttributeInt("upgrade_level") + private fun ItemStack.isDungeonItem() = getLore().any { it.contains("DUNGEON ") } fun ItemStack.getPetExp() = getPetInfo()?.get("exp")?.asDouble -- cgit