diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-08-16 11:17:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-16 11:17:02 +0200 |
commit | 24cbfa2faaa6cef709d42f75c3d1d51f3368e8b2 (patch) | |
tree | ae3d5f0b82def7214a3d51c0737183357878b671 /src | |
parent | 571d0ed6eca959a18032509844d5237df6a9e601 (diff) | |
download | skyhanni-24cbfa2faaa6cef709d42f75c3d1d51f3368e8b2.tar.gz skyhanni-24cbfa2faaa6cef709d42f75c3d1d51f3368e8b2.tar.bz2 skyhanni-24cbfa2faaa6cef709d42f75c3d1d51f3368e8b2.zip |
Fix: Item Trackers NPC Price (#2352)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
3 files changed, 20 insertions, 15 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt index b03b47168..57ff972e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt @@ -3,6 +3,7 @@ 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.getRecipePrice import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull @@ -46,7 +47,7 @@ object ItemPriceUtils { return 7.0 // NPC price } - return getNpcPriceOrNull() ?: getRawCraftCostOrNull(pastRecipes) + return getNpcPriceOrNull() ?: getRawCraftCostOrNull(priceSource, pastRecipes) } private fun NEUInternalName.getLowestBinOrNull(): Double? { @@ -55,14 +56,15 @@ object ItemPriceUtils { 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() - } + // We can not use NEU craft cost, since we want to respect the price source choice + // NEUItems.manager.auctionManager.getCraftCost(asString())?.craftCost + fun NEUInternalName.getRawCraftCostOrNull( + priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY, + pastRecipes: List<NeuRecipe> = emptyList(), + ): Double? = getRecipes(this).filter { it !in pastRecipes } + .map { it.getRecipePrice(priceSource, pastRecipes + it) } + .filter { it >= 0 } + .minOrNull() fun NEUInternalName.getNpcPrice(): Double = getNpcPriceOrNull() ?: -1.0 diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index cd55107db..59a718d6c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -5,9 +5,9 @@ import at.hannibal2.skyhanni.events.DebugDataCollectEvent 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.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull -import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches @@ -418,10 +418,12 @@ object ItemUtils { return neededItems } - fun getRecipePrice(recipe: NeuRecipe, pastRecipes: List<NeuRecipe> = emptyList()): Double = - neededItems(recipe).map { - it.key.getPrice(pastRecipes = pastRecipes) * it.value - }.sum() + fun NeuRecipe.getRecipePrice( + priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY, + pastRecipes: List<NeuRecipe> = emptyList(), + ): Double = neededItems(this).map { + it.key.getPrice(priceSource, pastRecipes) * it.value + }.sum() @SubscribeEvent fun onDebugDataCollect(event: DebugDataCollectEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index b7cf23eeb..296439939 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -185,7 +185,8 @@ object NEUItems { ): Double? = this.getPriceOrNullNew(priceSource, pastRecipes) @Deprecated("Moved to ItemPriceUtils", ReplaceWith("")) - fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<NeuRecipe> = emptyList()): Double? = getRawCraftCostOrNullNew(pastRecipes) + fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<NeuRecipe> = emptyList()): Double? = + getRawCraftCostOrNullNew(ItemPriceSource.BAZAAR_INSTANT_BUY, pastRecipes) fun NEUInternalName.getItemStackOrNull(): ItemStack? = ItemResolutionQuery(manager) .withKnownInternalName(asString()) |