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

Fix: Item Value Estimation Coloring #3061

Closed
Closed
4 changes: 3 additions & 1 deletion .idea/dictionaries/default_user.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.data.jsonobjects.repo

import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

Expand All @@ -11,4 +12,18 @@ data class ItemsJson(
@Expose @SerializedName("lava_fishing_rods") val lavaFishingRods: List<NEUInternalName>,
@Expose @SerializedName("water_fishing_rods") val waterFishingRods: List<NEUInternalName>,
@Expose @SerializedName("book_bundle_amount") val bookBundleAmount: Map<String, Int>,
@Expose @SerializedName("value_calculation_data") val valueCalculationData: ItemValueCalculationDataJson,
)

data class ItemValueCalculationDataJson(
@Expose @SerializedName("always_active_enchants") val alwaysActiveEnchants: Map<String, AlwaysActiveEnchantJson>,
@Expose @SerializedName("only_tier_one_prices") val onlyTierOnePrices: List<String>,
@Expose @SerializedName("only_tier_five_prices") val onlyTierFivePrices: List<String>,
)

data class AlwaysActiveEnchantJson(
@Expose val level: Int,
@Expose val items: List<String>,
) {
val internalNames = items.map { it.toInternalName() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameFullyRarityAware
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addButton
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
Expand Down Expand Up @@ -121,12 +121,12 @@ object ChestValue {
if (total < config.hideBelow) continue
val textAmount = " §7x${amount.addSeparators()}:"
val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(textAmount)
val name = "${stack.itemName.reduceStringLength((config.nameLength - width), ' ')} $textAmount"
val name = "${stack.itemNameFullyRarityAware.reduceStringLength((config.nameLength - width), ' ')} $textAmount"
val price = "§6${(total).formatPrice()}"
val text = if (config.alignedDisplay)
"$name $price"
else
"${stack.itemName} §7x$amount: §6${total.formatPrice()}"
"${stack.itemNameFullyRarityAware} §7x$amount: §6${total.formatPrice()}"
newDisplay.add(
buildList {
val renderable = Renderable.hoverTips(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.features.misc.EstimatedItemValueConfig
import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemValueCalculationDataJson
import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemsJson
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
Expand Down Expand Up @@ -49,6 +50,9 @@ object EstimatedItemValue {
var bookBundleAmount = mapOf<String, Int>()
private var currentlyShowing = false

lateinit var itemValueCalculationData: ItemValueCalculationDataJson
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be null, not lateinit. starting with a outdated repo will cause ugly errors instead of clean repo errors

private set

fun isCurrentlyShowing() = currentlyShowing && Minecraft.getMinecraft().currentScreen != null

@HandleEvent
Expand All @@ -61,6 +65,7 @@ object EstimatedItemValue {
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<ItemsJson>("Items")
bookBundleAmount = data.bookBundleAmount
itemValueCalculationData = data.valueCalculationData
}

@HandleEvent(onlyOnSkyblock = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.misc.items

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.ReforgeAPI
import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager
import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI
import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI.getKuudraTier
import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI.isKuudraArmor
Expand All @@ -23,6 +24,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.getReadableNBTDump
import at.hannibal2.skyhanni.utils.ItemUtils.isRune
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameBaseRarityAware
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzRarity
Expand Down Expand Up @@ -120,18 +122,16 @@ object EstimatedItemValueCalculator {
::addEnchantments,
)

val farmingForDummies = "FARMING_FOR_DUMMIES".toInternalName()
val etherwarpConduit = "ETHERWARP_CONDUIT".toInternalName()
val etherwarpMerger = "ETHERWARP_MERGER".toInternalName()
val fumingPotatoBook = "FUMING_POTATO_BOOK".toInternalName()
val hotPotatoBook = "HOT_POTATO_BOOK".toInternalName()
val silex = "SIL_EX".toInternalName()
val transmissionTuner = "TRANSMISSION_TUNER".toInternalName()
val manaDisintegrator = "MANA_DISINTEGRATOR".toInternalName()
private val farmingForDummies = "FARMING_FOR_DUMMIES".toInternalName()
private val etherwarpConduit = "ETHERWARP_CONDUIT".toInternalName()
private val etherwarpMerger = "ETHERWARP_MERGER".toInternalName()
private val fumingPotatoBook = "FUMING_POTATO_BOOK".toInternalName()
private val hotPotatoBook = "HOT_POTATO_BOOK".toInternalName()
private val silex = "SIL_EX".toInternalName()
private val transmissionTuner = "TRANSMISSION_TUNER".toInternalName()
private val manaDisintegrator = "MANA_DISINTEGRATOR".toInternalName()

val kuudraUpgradeTiers = listOf("HOT_", "BURNING_", "FIERY_", "INFERNAL_")

fun getTotalPrice(stack: ItemStack): Double = EstimatedItemValueCalculator.calculate(stack, mutableListOf()).first
fun getTotalPrice(stack: ItemStack): Double = calculate(stack, mutableListOf()).first

fun calculate(stack: ItemStack, list: MutableList<String>): Pair<Double, Double> {
val basePrice = addBaseItem(stack, list)
Expand Down Expand Up @@ -700,7 +700,7 @@ object EstimatedItemValueCalculator {
}
}

val name = internalName.itemName
val name = stack.itemNameBaseRarityAware
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont want to show the recomb color here, and since the reforge name is also not part of the clean item name, i dont see why this line change is necessary

if (internalName.startsWith("ENCHANTED_BOOK_BUNDLE_")) {
list.add("§7Base item: $name")
return 0.0
Expand All @@ -710,52 +710,25 @@ object EstimatedItemValueCalculator {
return price
}

// TODO repo
private val hasAlwaysScavenger = listOf(
"CRYPT_DREADLORD_SWORD".toInternalName(),
"ZOMBIE_SOLDIER_CUTLASS".toInternalName(),
"CONJURING_SWORD".toInternalName(),
"EARTH_SHARD".toInternalName(),
"ZOMBIE_KNIGHT_SWORD".toInternalName(),
"SILENT_DEATH".toInternalName(),
"ZOMBIE_COMMANDER_WHIP".toInternalName(),
"ICE_SPRAY_WAND".toInternalName(),
)

private val hasAlwaysReplenish = listOf(
"ADVANCED_GARDENING_HOE".toInternalName(),
"ADVANCED_GARDENING_AXE".toInternalName(),
)

private fun addEnchantments(stack: ItemStack, list: MutableList<String>): Double {
val enchantments = stack.getEnchantments() ?: return 0.0

var totalPrice = 0.0
val map = mutableMapOf<String, Double>()

// todo use repo
val tieredEnchants = listOf("compact", "cultivating", "champion", "expertise", "hecatomb", "toxophilite")

@Suppress("PropertyWrapping")
val onlyTierOnePrices = listOf("ultimate_chimera", "ultimate_fatal_tempo", "smoldering", "ultimate_flash", "divine_gift")
val onlyTierFivePrices = listOf("ferocious_mana", "hardened_mana", "mana_vampire", "strong_mana")

val internalName = stack.getInternalName()
for ((rawName, rawLevel) in enchantments) {
// efficiency 1-5 is cheap, 6-10 is handled by silex
if (rawName == "efficiency") continue

if (rawName == "scavenger" && rawLevel == 5 && internalName in hasAlwaysScavenger) {
continue
}

if (rawName == "replenish" && rawLevel == 1 && internalName in hasAlwaysReplenish) {
continue
val isAlwaysActive = EstimatedItemValue.itemValueCalculationData.alwaysActiveEnchants.entries.any {
it.key == rawName && it.value.level == rawLevel && it.value.internalNames.contains(internalName)
}
if (isAlwaysActive) continue

var level = rawLevel
var multiplier = 1
if (rawName in onlyTierOnePrices) {
if (rawName in EstimatedItemValue.itemValueCalculationData.onlyTierOnePrices) {

when (rawLevel) {
2 -> multiplier = 2
Expand All @@ -765,7 +738,7 @@ object EstimatedItemValueCalculator {
}
level = 1
}
if (rawName in onlyTierFivePrices) {
if (rawName in EstimatedItemValue.itemValueCalculationData.onlyTierFivePrices) {
when (rawLevel) {
6 -> multiplier = 2
7 -> multiplier = 4
Expand All @@ -780,7 +753,7 @@ object EstimatedItemValueCalculator {
if (internalName.startsWith("ENCHANTED_BOOK_BUNDLE_")) {
multiplier = EstimatedItemValue.bookBundleAmount.getOrDefault(rawName, 5)
}
if (rawName in tieredEnchants) level = 1
if (rawName in DiscordRPCManager.stackingEnchants.keys) level = 1

val enchantmentName = "$rawName;$level".uppercase().toInternalName()
val itemStack = enchantmentName.getItemStackOrNull() ?: continue
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.ItemPriceUtils.getPrice
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
Expand Down Expand Up @@ -344,6 +345,11 @@ object ItemUtils {
return data.itemCategory
}

fun ItemStack.getItemBaseRarityOrNull(): LorenzRarity? {
val rarity = getItemRarityOrNull() ?: return null
return if (isRecombobulated(this)) LorenzRarity.entries.firstOrNull { it.id == rarity.id - 1 } else rarity
}

fun ItemStack.getItemRarityOrNull(): LorenzRarity? {
val data = cachedData
if (itemRarityLastCheck(data)) {
Expand Down Expand Up @@ -460,6 +466,28 @@ object ItemUtils {
return getInternalNameOrNull()?.itemName ?: "<null>"
}

/**
* Returns the item name with its base color, i.e. before recombobulation
*/
val ItemStack.itemNameBaseRarityAware: String
get() {
return getRarityName(getItemBaseRarityOrNull())
}

/**
* Returns the item name with its full color, i.e. after recombobulation
*/
val ItemStack.itemNameFullyRarityAware: String
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between this and the display name?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the purpose is to remove the reforge name, maybe its better to have the function be called nameWithoutReforge instead?

get() {
return getRarityName(getItemRarityOrNull())
}

private fun ItemStack.getRarityName(rarity: LorenzRarity?): String =
if (rarity == null) itemName
else if (itemName.startsWith("§")) {
itemName.replaceFirst(Regex("§[0-9a-f]"), rarity.color.getChatColor())
} else itemName

fun ItemStack.getAttributeFromShard(): Pair<String, Int>? {
if (getInternalName().asString() != "ATTRIBUTE_SHARD") return null
val attributes = getAttributes() ?: return null
Expand Down
Loading