diff options
Diffstat (limited to 'src/main/java/at')
4 files changed, 64 insertions, 25 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt index c6daa20eb..3efa9a8e5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt @@ -3,14 +3,13 @@ package at.hannibal2.skyhanni.features.inventory import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValueCalculator import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName import at.hannibal2.skyhanni.utils.InventoryUtils.getUpperItems -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst import at.hannibal2.skyhanni.utils.RenderUtils.highlight @@ -57,10 +56,9 @@ object AuctionsHighlighter { if (config.highlightAuctionsUnderbid) { lore.matchFirst(buyItNowPattern) { val coins = group("coins").formatLong() - stack.getInternalNameOrNull()?.getPriceOrNull()?.let { - if (coins > it) { - slot highlight LorenzColor.GOLD - } + val totalPrice = EstimatedItemValueCalculator.getTotalPrice(stack) + if (coins > totalPrice) { + slot highlight LorenzColor.GOLD } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt index 9395b90e1..5825436b8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt @@ -184,8 +184,7 @@ object ChestValue { val internalName = stack.getInternalNameOrNull() ?: continue if (internalName.getItemStackOrNull() == null) continue val list = mutableListOf<String>() - val pair = EstimatedItemValueCalculator.calculate(stack, list) - var (total, _) = pair + var total = EstimatedItemValueCalculator.calculate(stack, list).first val key = "$internalName+$total" if (stack.item == Items.enchanted_book) total /= 2 diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt index 8602eece8..c18408a0f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt @@ -54,6 +54,9 @@ import java.util.Locale object EstimatedItemValueCalculator { private val config get() = SkyHanniMod.feature.inventory.estimatedItemValues + + private val kuudraSets = listOf("AURORA", "CRIMSON", "TERROR", "HOLLOW", "FERVOR") + private val additionalCostFunctions = listOf( ::addAttributeCost, ::addReforgeStone, @@ -92,6 +95,8 @@ object EstimatedItemValueCalculator { ::addEnchantments ) + fun getTotalPrice(stack: ItemStack): Double = EstimatedItemValueCalculator.calculate(stack, mutableListOf()).first + fun calculate(stack: ItemStack, list: MutableList<String>): Pair<Double, Double> { val basePrice = addBaseItem(stack, list) val totalPrice = additionalCostFunctions.fold(basePrice) { total, function -> total + function(stack, list) } @@ -101,13 +106,10 @@ object EstimatedItemValueCalculator { private fun addAttributeCost(stack: ItemStack, list: MutableList<String>): Double { val attributes = stack.getAttributes() ?: return 0.0 var internalName = stack.getInternalName().asString().removePrefix("VANQUISHED_") - val kuudraSets = listOf("AURORA", "CRIMSON", "TERROR", "HOLLOW") var genericName = internalName if (kuudraSets.any { internalName.contains(it) } && listOf("CHESTPLATE", "LEGGINGS", "HELMET", "BOOTS").any { internalName.endsWith(it) }) { - for (prefix in listOf("HOT_", "BURNING_", "FIERY_", "INFERNAL_")) { - internalName = internalName.removePrefix(prefix) - } + internalName = removeCrimsonArmorPrefix(internalName) genericName = kuudraSets.fold(internalName) { acc, part -> acc.replace(part, "GENERIC_KUUDRA") } } if (internalName == "ATTRIBUTE_SHARD" && attributes.size == 1) { @@ -128,28 +130,67 @@ object EstimatedItemValueCalculator { if (attributes.size != 2) return 0.0 val basePrice = internalName.asInternalName().getPriceOrNull() ?: 0.0 var subTotal = 0.0 - val combo = ("$internalName+ATTRIBUTE_${attributes[0].first}+ATTRIBUTE_${attributes[1].first}").asInternalName() - val comboPrice = combo.getPriceOrNull() - if (comboPrice != null && comboPrice > basePrice) { - list.add("§7Attribute Combo: (§6${NumberUtil.format(comboPrice)}§7)") - subTotal += comboPrice - basePrice + val combo = ("$internalName+ATTRIBUTE_${attributes[0].first}+ATTRIBUTE_${attributes[1].first}") + var comboPrice = combo.asInternalName().getPriceOrNull() + + if (comboPrice != null) { + val useless = isUselessAttribute(combo) + val color = if (comboPrice > basePrice && !useless) "§6" else "§7" + list.add("§7Attribute Combo: ($color${NumberUtil.format(comboPrice)}§7)") + if (!useless) { + subTotal += addAttributePrice(comboPrice, basePrice) + } } else { list.add("§7Attributes:") } for (attr in attributes) { + val attributeName = "$genericName+ATTRIBUTE_${attr.first}" val price = - getPriceOrCompositePriceForAttribute("$genericName+ATTRIBUTE_${attr.first}", attr.second) + getPriceOrCompositePriceForAttribute(attributeName, attr.second) + var priceColor = "§7" + val useless = isUselessAttribute(attributeName) + var nameColor = if (!useless) "§9" else "§7" if (price != null) { - subTotal += price + if (price > basePrice && !useless) { + subTotal += addAttributePrice(price, basePrice) + priceColor = "§6" + } + } val displayName = attr.first.fixMending() list.add( - " §9${ + " $nameColor${ displayName.allLettersFirstUppercase() - } ${attr.second}§7: §6${if (price != null) NumberUtil.format(price) else "Unknown"}" + } ${attr.second}§7: $priceColor${if (price != null) NumberUtil.format(price) else "Unknown"}" ) } - return subTotal + // Adding 0.1 so that we always show the estimated item value overlay + return subTotal + 0.1 + } + + private fun removeCrimsonArmorPrefix(original: String): String { + var internalName = original + for (prefix in listOf("HOT_", "BURNING_", "FIERY_", "INFERNAL_")) { + internalName = internalName.removePrefix(prefix) + } + return internalName + } + + private fun addAttributePrice(attributePrice: Double, basePrice: Double): Double = + if (attributePrice > basePrice) { + attributePrice - basePrice + } else { + 0.0 + } + + private fun isUselessAttribute(internalName: String): Boolean { + if (internalName.contains("RESISTANCE")) return true + if (internalName.contains("SPEED")) return true + if (internalName.contains("EXPERIENCE")) return true + if (internalName.contains("FORTITUDE")) return true + if (internalName.contains("ENDER")) return true + + return false } private fun String.fixMending() = if (this == "MENDING") "VITALITY" else this @@ -489,7 +530,7 @@ object EstimatedItemValueCalculator { } private fun addBaseItem(stack: ItemStack, list: MutableList<String>): Double { - val internalName = stack.getInternalName() + val internalName = removeCrimsonArmorPrefix(stack.getInternalName().asString()).asInternalName() var price = internalName.getPrice() if (price == -1.0) { price = 0.0 diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt index ea50b4c85..5e536ad01 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedWardrobePrice.kt @@ -39,7 +39,8 @@ object EstimatedWardrobePrice { var totalPrice = 0.0 for (item in items) { - val price = EstimatedItemValueCalculator.calculate(item, mutableListOf()).first + + val price = EstimatedItemValueCalculator.getTotalPrice(item) totalPrice += price toolTip.add(index++, " §7- ${item.name}: §6${NumberUtil.format(price)}") @@ -57,7 +58,7 @@ object EstimatedWardrobePrice { for ((slot, item) in event.inventoryItems) { item.getInternalNameOrNull() ?: continue - val price = EstimatedItemValueCalculator.calculate(item, mutableListOf()).first + val price = EstimatedItemValueCalculator.getTotalPrice(item) if (price == 0.0) continue val id = slot % 9 val list = map.getOrPut(id) { mutableListOf() } |