aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-08-11 13:59:52 +0200
committerGitHub <noreply@github.com>2024-08-11 13:59:52 +0200
commit091b939ea277d22da7fe46eba7d2834af71463e0 (patch)
tree48c694f5dc76fdf917a1b063bcb8f840e0b3eb45 /src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
parent9b462cf711085dd0ac56131ded2e09ff2609bc45 (diff)
downloadskyhanni-091b939ea277d22da7fe46eba7d2834af71463e0.tar.gz
skyhanni-091b939ea277d22da7fe46eba7d2834af71463e0.tar.bz2
skyhanni-091b939ea277d22da7fe46eba7d2834af71463e0.zip
Backend: ItemPriceUtils (#2290)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt68
1 files changed, 64 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
index e604c29ff..b03b47168 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
@@ -1,18 +1,78 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.getBazaarData
+import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarDataHolder
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
-import at.hannibal2.skyhanni.utils.NEUItems.getLowestBinOrNull
-import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
-import at.hannibal2.skyhanni.utils.NEUItems.getPrice
-import at.hannibal2.skyhanni.utils.NEUItems.getRawCraftCostOrNull
+import at.hannibal2.skyhanni.utils.NEUItems.getRecipes
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import io.github.moulberry.notenoughupdates.recipes.NeuRecipe
object ItemPriceUtils {
+ fun NEUInternalName.getPrice(
+ priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
+ pastRecipes: List<NeuRecipe> = emptyList(),
+ ) = getPriceOrNull(priceSource, pastRecipes) ?: -1.0
+
+ fun NEUInternalName.getPriceOrNull(
+ priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
+ pastRecipes: List<NeuRecipe> = emptyList(),
+ ): Double? {
+ when (this) {
+ NEUInternalName.JASPER_CRYSTAL -> return 0.0
+ NEUInternalName.RUBY_CRYSTAL -> return 0.0
+ NEUInternalName.SKYBLOCK_COIN -> return 1.0
+ NEUInternalName.WISP_POTION -> return 20_000.0
+ }
+
+ if (priceSource != ItemPriceSource.NPC_SELL) {
+ getBazaarData()?.let {
+ return if (priceSource == ItemPriceSource.BAZAAR_INSTANT_BUY) it.sellOfferPrice else it.instantBuyPrice
+ }
+
+ getLowestBinOrNull()?.let {
+ return it
+ }
+
+ if (equals("JACK_O_LANTERN")) {
+ return "PUMPKIN".asInternalName().getPrice(priceSource) + 1
+ }
+ }
+ if (equals("GOLDEN_CARROT")) {
+ // 6.8 for some players
+ return 7.0 // NPC price
+ }
+
+ return getNpcPriceOrNull() ?: getRawCraftCostOrNull(pastRecipes)
+ }
+
+ private fun NEUInternalName.getLowestBinOrNull(): Double? {
+ val result = NEUItems.manager.auctionManager.getLowestBin(asString())
+ if (result == -1L) return null
+ return result.toDouble()
+ }
+
+ // If NEU fails to calculate the craft costs, we calculate it ourself.
+ fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<NeuRecipe> = emptyList()): Double? =
+ NEUItems.manager.auctionManager.getCraftCost(asString())?.craftCost ?: run {
+ getRecipes(this).filter { it !in pastRecipes }
+ .map { ItemUtils.getRecipePrice(it, pastRecipes + it) }
+ .filter { it >= 0 }
+ .minOrNull()
+ }
+
+ fun NEUInternalName.getNpcPrice(): Double = getNpcPriceOrNull() ?: -1.0
+
+ fun NEUInternalName.getNpcPriceOrNull(): Double? {
+ if (this == NEUInternalName.WISP_POTION) {
+ return 20_000.0
+ }
+ return BazaarDataHolder.getNpcPrice(this)
+ }
+
fun debugItemPrice(args: Array<String>) {
val internalName = getItemOrFromHand(args)
if (internalName == null) {