Skip to content

Commit

Permalink
Improvement: Estimated Item Value Mithril Infusion (#2990)
Browse files Browse the repository at this point in the history
Co-authored-by: Empa <itsempa@users.noreply.github.com>
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 25, 2024
1 parent d4510fa commit ffc6d1d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.data.jsonobjects.repo.neu
import at.hannibal2.skyhanni.data.model.SkyblockStatList
import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalNames
import at.hannibal2.skyhanni.utils.NEUItems
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
Expand Down Expand Up @@ -52,7 +52,7 @@ data class NeuReforgeJson(
is Map<*, *> -> {
val type = "SPECIAL_ITEMS"
val map = any as? Map<String, List<String>> ?: return type to emptyList()
val internalNames = map["internalName"]?.map { it.toInternalName() }.orEmpty()
val internalNames = map["internalName"]?.toInternalNames().orEmpty()
val itemType = map["itemid"]?.map {
NEUItems.getInternalNamesForItemId(Item.getByNameOrId(it) ?: return@map emptyList())
}?.flatten().orEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getGemstones
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHelmetSkin
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHotPotatoCount
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getManaDisintegrators
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getMithrilInfusion
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getPolarvoidBookCount
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getPowerScroll
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getReforgeName
Expand All @@ -70,7 +71,7 @@ import io.github.notenoughupdates.moulconfig.observer.Property
import net.minecraft.item.ItemStack
import java.util.Locale

// TODO split into smaler sub classes
// TODO split into smaller sub classes
@Suppress("LargeClass")
object EstimatedItemValueCalculator {

Expand All @@ -94,6 +95,7 @@ object EstimatedItemValueCalculator {
::addStatsBook,
::addEnrichment,
::addDivanPowderCoating,
::addMithrilInfusion,

// counted
::addStars, // crimson, dungeon
Expand All @@ -120,23 +122,33 @@ 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()

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

fun getTotalPrice(stack: ItemStack): Double = EstimatedItemValueCalculator.calculate(stack, mutableListOf()).first
private val FARMING_FOR_DUMMIES = "FARMING_FOR_DUMMIES".toInternalName()
private val ETHERWARP_CONDUIT = "ETHERWARP_CONDUIT".toInternalName()
private val ETHERWARP_MERGER = "ETHERWARP_MERGER".toInternalName()
private val FUMING_POTATO_BOOK = "FUMING_POTATO_BOOK".toInternalName()
private val HOT_POTATO_BOOK = "HOT_POTATO_BOOK".toInternalName()
private val SILEX = "SIL_EX".toInternalName()
private val TRANSMISSION_TUNER = "TRANSMISSION_TUNER".toInternalName()
private val MANA_DISINTEGRATOR = "MANA_DISINTEGRATOR".toInternalName()
private val RECOMBOBULATOR_3000 = "RECOMBOBULATOR_3000".toInternalName()
private val JALAPENO_BOOK = "JALAPENO_BOOK".toInternalName()
private val WOOD_SINGULARITY = "WOOD_SINGULARITY".toInternalName()
private val DIVAN_POWDER_COATING = "DIVAN_POWDER_COATING".toInternalName()
private val ART_OF_WAR = "THE_ART_OF_WAR".toInternalName()
private val BOOK_OF_STATS = "BOOK_OF_STATS".toInternalName()
private val ART_OF_PEACE = "THE_ART_OF_PEACE".toInternalName()
private val POLARVOID_BOOK = "POLARVOID_BOOK".toInternalName()
private val POCKET_SACK_IN_A_SACK = "POCKET_SACK_IN_A_SACK".toInternalName()
private val BOOKWORM_BOOK = "BOOKWORM_BOOK".toInternalName()
private val STONK_PICKAXE = "STONK_PICKAXE".toInternalName()
private val MITHRIL_INFUSION = "MITHRIL_INFUSION".toInternalName()

fun getTotalPrice(stack: ItemStack): Double = 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) }
return Pair(totalPrice, basePrice)
return totalPrice to basePrice
}

private fun addAttributeCost(stack: ItemStack, list: MutableList<String>): Double {
Expand Down Expand Up @@ -281,55 +293,62 @@ object EstimatedItemValueCalculator {
private fun addRecombobulator(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.isRecombobulated()) return 0.0

val price = "RECOMBOBULATOR_3000".toInternalName().getPrice()
val price = RECOMBOBULATOR_3000.getPrice()
list.add("§7Recombobulated: §a§l✔ §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addJalapenoBook(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.hasJalapenoBook()) return 0.0

val price = "JALAPENO_BOOK".toInternalName().getPrice()
val price = JALAPENO_BOOK.getPrice()
list.add("§7Jalapeno Book: §a§l✔ §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addEtherwarp(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.hasEtherwarp()) return 0.0

val price = etherwarpConduit.getPrice() + etherwarpMerger.getPrice()
val price = ETHERWARP_CONDUIT.getPrice() + ETHERWARP_MERGER.getPrice()
list.add("§7Etherwarp: §a§l✔ §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addWoodSingularity(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.hasWoodSingularity()) return 0.0

val price = "WOOD_SINGULARITY".toInternalName().getPrice()
val price = WOOD_SINGULARITY.getPrice()
list.add("§7Wood Singularity: §a§l✔ §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addDivanPowderCoating(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.hasDivanPowderCoating()) return 0.0

val price = "DIVAN_POWDER_COATING".toInternalName().getPrice()
val price = DIVAN_POWDER_COATING.getPrice()
list.add("§7Divan Powder Coating: §a§l✔ §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addMithrilInfusion(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.getMithrilInfusion()) return 0.0
val price = MITHRIL_INFUSION.getPrice()
list.add("§7Mithril Infusion: §a§l✔ §7(§6${price.shortFormat()}§7)")
return price
}

private fun addArtOfWar(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.hasArtOfWar()) return 0.0

val price = "THE_ART_OF_WAR".toInternalName().getPrice()
val price = ART_OF_WAR.getPrice()
list.add("§7The Art of War: §a§l✔ §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addStatsBook(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.hasBookOfStats()) return 0.0

val price = "BOOK_OF_STATS".toInternalName().getPrice()
val price = BOOK_OF_STATS.getPrice()
list.add("§7Book of Stats: §a§l✔ §7(§6" + price.shortFormat() + "§7)")
return price
}
Expand All @@ -338,7 +357,7 @@ object EstimatedItemValueCalculator {
private fun addArtOfPeace(stack: ItemStack, list: MutableList<String>): Double {
if (!stack.hasArtOfPeace()) return 0.0

val price = "THE_ART_OF_PEACE".toInternalName().getPrice()
val price = ART_OF_PEACE.getPrice()
list.add("§7The Art Of Peace: §a§l✔ §7(§6" + price.shortFormat() + "§7)")
return price
}
Expand All @@ -358,12 +377,12 @@ object EstimatedItemValueCalculator {

var totalPrice = 0.0

val hpbPrice = hotPotatoBook.getPrice() * hpb
val hpbPrice = HOT_POTATO_BOOK.getPrice() * hpb
list.add("§7HPB's: §e$hpb§7/§e10 §7(§6" + hpbPrice.shortFormat() + "§7)")
totalPrice += hpbPrice

if (fuming > 0) {
val fumingPrice = fumingPotatoBook.getPrice() * fuming
val fumingPrice = FUMING_POTATO_BOOK.getPrice() * fuming
list.add("§7Fuming: §e$fuming§7/§e5 §7(§6" + fumingPrice.shortFormat() + "§7)")
totalPrice += fumingPrice
}
Expand All @@ -374,34 +393,31 @@ object EstimatedItemValueCalculator {
private fun addFarmingForDummies(stack: ItemStack, list: MutableList<String>): Double {
val count = stack.getFarmingForDummiesCount() ?: return 0.0

val price = farmingForDummies.getPrice() * count
val price = FARMING_FOR_DUMMIES.getPrice() * count
list.add("§7Farming for Dummies: §e$count§7/§e5 §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addPolarvoidBook(stack: ItemStack, list: MutableList<String>): Double {
val count = stack.getPolarvoidBookCount() ?: return 0.0

val polarvoidBook = "POLARVOID_BOOK".toInternalName()
val price = polarvoidBook.getPrice() * count
val price = POLARVOID_BOOK.getPrice() * count
list.add("§7Polarvoid: §e$count§7/§e5 §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addPocketSackInASack(stack: ItemStack, list: MutableList<String>): Double {
val count = stack.getAppliedPocketSackInASack() ?: return 0.0

val pocketSackInASack = "POCKET_SACK_IN_A_SACK".toInternalName()
val price = pocketSackInASack.getPrice() * count
val price = POCKET_SACK_IN_A_SACK.getPrice() * count
list.add("§7Pocket Sack-in-a-Sack: §e$count§7/§e3 §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addBookwormBook(stack: ItemStack, list: MutableList<String>): Double {
val count = stack.getBookwormBookCount() ?: return 0.0

val bookwormBook = "BOOKWORM_BOOK".toInternalName()
val price = bookwormBook.getPrice() * count
val price = BOOKWORM_BOOK.getPrice() * count
list.add("§7Bookworm's Favorite Book: §e$count§7/§e5 §7(§6" + price.shortFormat() + "§7)")
return price
}
Expand All @@ -410,25 +426,25 @@ object EstimatedItemValueCalculator {
val tier = stack.getSilexCount() ?: return 0.0

val internalName = stack.getInternalName()
val maxTier = if (internalName == "STONK_PICKAXE".toInternalName()) 4 else 5
val maxTier = if (internalName == STONK_PICKAXE) 4 else 5

val price = silex.getPrice() * tier
val price = SILEX.getPrice() * tier
list.add("§7Silex: §e$tier§7/§e$maxTier §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addTransmissionTuners(stack: ItemStack, list: MutableList<String>): Double {
val count = stack.getTransmissionTunerCount() ?: return 0.0

val price = transmissionTuner.getPrice() * count
val price = TRANSMISSION_TUNER.getPrice() * count
list.add("§7Transmission Tuners: §e$count§7/§e4 §7(§6" + price.shortFormat() + "§7)")
return price
}

private fun addManaDisintegrators(stack: ItemStack, list: MutableList<String>): Double {
val count = stack.getManaDisintegrators() ?: return 0.0

val price = manaDisintegrator.getPrice() * count
val price = MANA_DISINTEGRATOR.getPrice() * count
list.add("§7Mana Disintegrators: §e$count§7/§e10 §7(§6" + price.shortFormat() + "§7)")
return price
}
Expand Down Expand Up @@ -718,7 +734,7 @@ object EstimatedItemValueCalculator {

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

private fun addEnchantments(stack: ItemStack, list: MutableList<String>): Double {
Expand Down Expand Up @@ -775,7 +791,7 @@ object EstimatedItemValueCalculator {
}
if (rawName in tieredEnchants) level = 1

val enchantmentName = "$rawName;$level".uppercase().toInternalName()
val enchantmentName = "$rawName;$level".toInternalName()
val singlePrice = enchantmentName.getPriceOrNull(config.priceSource.get()) ?: continue

var name = enchantmentName.itemName
Expand Down Expand Up @@ -915,7 +931,7 @@ object EstimatedItemValueCalculator {
return "§b$name $second Shard"
}

fun Pair<String, Int>.getAttributePrice(): Double? = EstimatedItemValueCalculator.getPriceOrCompositePriceForAttribute(
fun Pair<String, Int>.getAttributePrice(): Double? = getPriceOrCompositePriceForAttribute(
"ATTRIBUTE_SHARD+ATTRIBUTE_$first",
second,
)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class NEUInternalName private constructor(private val internalName: String) {
internalNameMap.getOrPut(it) { NEUInternalName(it) }
}

fun Set<String>.toInternalNames(): Set<NEUInternalName> = mapTo(mutableSetOf()) { it.toInternalName() }
fun List<String>.toInternalNames(): List<NEUInternalName> = mapTo(mutableListOf()) { it.toInternalName() }

private val itemNameCache = mutableMapOf<String, NEUInternalName?>()

fun fromItemNameOrNull(itemName: String): NEUInternalName? = itemNameCache.getOrPut(itemName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ object SkyBlockItemModifierUtils {
it - 5 - getBaseSilexCount()
}?.takeIf { it > 0 }

fun ItemStack.getMithrilInfusion(): Boolean = getAttributeByte("mithril_infusion") == 1.toByte()

private fun ItemStack.getBaseSilexCount() = when (getInternalName().asString()) {
"STONK_PICKAXE" -> 1
"PROMISING_SPADE" -> 5
Expand Down

0 comments on commit ffc6d1d

Please sign in to comment.