diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-07-15 16:45:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-15 16:45:09 +0200 |
commit | ad7c6dfc824bb7d2b1405ec5f7c0a017612bbf2f (patch) | |
tree | 4a9786dd9c2578d0063ccd179200f04b612d7e35 /src/main/java/at/hannibal2/skyhanni/utils | |
parent | a716e5d26a6ae6c79300c298c221382fb73e21a8 (diff) | |
download | skyhanni-ad7c6dfc824bb7d2b1405ec5f7c0a017612bbf2f.tar.gz skyhanni-ad7c6dfc824bb7d2b1405ec5f7c0a017612bbf2f.tar.bz2 skyhanni-ad7c6dfc824bb7d2b1405ec5f7c0a017612bbf2f.zip |
Fix: price source inconsistencies (bz sell/buy and npc price) (#2221)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
4 files changed, 33 insertions, 25 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceSource.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceSource.kt new file mode 100644 index 000000000..13049a596 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceSource.kt @@ -0,0 +1,10 @@ +package at.hannibal2.skyhanni.utils + +enum class ItemPriceSource(val displayName: String) { + BAZAAR_INSTANT_BUY("Instant Buy/Sell Offer"), // Sell Offer + BAZAAR_INSTANT_SELL("Instant Sell/Buy Order"), // Buy Order + NPC_SELL("NPC Sell"), + ; + + override fun toString(): String = displayName +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 3fc54009e..563fefb30 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -160,8 +160,10 @@ object NEUItems { fun getInternalNameOrNull(nbt: NBTTagCompound): NEUInternalName? = ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName()?.asInternalName() - fun NEUInternalName.getPrice(useSellPrice: Boolean = false, pastRecipes: List<NeuRecipe> = emptyList()) = - getPriceOrNull(useSellPrice, pastRecipes) ?: -1.0 + fun NEUInternalName.getPrice( + priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY, + pastRecipes: List<NeuRecipe> = emptyList(), + ) = getPriceOrNull(priceSource, pastRecipes) ?: -1.0 fun NEUInternalName.getNpcPrice() = getNpcPriceOrNull() ?: -1.0 @@ -175,20 +177,25 @@ object NEUItems { fun transHypixelNameToInternalName(hypixelId: String): NEUInternalName = manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId).asInternalName() - fun NEUInternalName.getPriceOrNull(useSellPrice: Boolean = false, pastRecipes: List<NeuRecipe> = emptyList()): Double? { + fun NEUInternalName.getPriceOrNull( + priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY, + pastRecipes: List<NeuRecipe> = emptyList(), + ): Double? { if (this == NEUInternalName.WISP_POTION) { return 20_000.0 } - getBazaarData()?.let { - return if (useSellPrice) it.sellOfferPrice else it.instantBuyPrice - } + if (priceSource != ItemPriceSource.NPC_SELL) { + getBazaarData()?.let { + return if (priceSource == ItemPriceSource.BAZAAR_INSTANT_BUY) it.sellOfferPrice else it.instantBuyPrice + } - val result = manager.auctionManager.getLowestBin(asString()) - if (result != -1L) return result.toDouble() + val result = manager.auctionManager.getLowestBin(asString()) + if (result != -1L) return result.toDouble() - if (equals("JACK_O_LANTERN")) { - return "PUMPKIN".asInternalName().getPrice(useSellPrice) + 1 + if (equals("JACK_O_LANTERN")) { + return "PUMPKIN".asInternalName().getPrice(priceSource) + 1 + } } if (equals("GOLDEN_CARROT")) { // 6.8 for some players diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt index 21f115746..241d0a1e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt @@ -1,13 +1,12 @@ package at.hannibal2.skyhanni.utils.tracker import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.features.misc.TrackerConfig.PriceFromEntry import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage import at.hannibal2.skyhanni.data.SlayerAPI -import at.hannibal2.skyhanni.test.PriceSource import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc +import at.hannibal2.skyhanni.utils.ItemPriceSource import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils @@ -55,12 +54,12 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( fun addPriceFromButton(lists: MutableList<List<Any>>) { if (isInventoryOpen()) { - lists.addSelector<PriceSource>( + lists.addSelector<ItemPriceSource>( "", getName = { type -> type.displayName }, - isCurrent = { it.ordinal == config.priceFrom.ordinal }, // todo avoid ordinal + isCurrent = { it.ordinal == config.priceSource.ordinal }, // todo avoid ordinal onChange = { - config.priceFrom = PriceFromEntry.entries[it.ordinal] // todo avoid ordinal + config.priceSource = ItemPriceSource.entries[it.ordinal] // todo avoid ordinal update() } ) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt index 9d4d5ea38..00431049f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt @@ -2,18 +2,15 @@ package at.hannibal2.skyhanni.utils.tracker import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.core.config.Position -import at.hannibal2.skyhanni.config.features.misc.TrackerConfig.PriceFromEntry import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.data.TrackerManager -import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.getBazaarData import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValue import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull -import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull +import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -40,12 +37,7 @@ open class SkyHanniTracker<Data : TrackerData>( val config get() = SkyHanniMod.feature.misc.tracker private val storedTrackers get() = SkyHanniMod.feature.storage.trackerDisplayModes - fun getPricePer(name: NEUInternalName) = when (config.priceFrom) { - PriceFromEntry.INSTANT_SELL -> name.getBazaarData()?.instantBuyPrice ?: name.getPriceOrNull() ?: 0.0 - PriceFromEntry.SELL_OFFER -> name.getBazaarData()?.sellOfferPrice ?: name.getPriceOrNull() ?: 0.0 - - else -> name.getNpcPriceOrNull() ?: 0.0 - } + fun getPricePer(name: NEUInternalName) = name.getPrice(config.priceSource) } fun isInventoryOpen() = inventoryOpen |