From ad7c6dfc824bb7d2b1405ec5f7c0a017612bbf2f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:45:09 +0200 Subject: Fix: price source inconsistencies (bz sell/buy and npc price) (#2221) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../config/features/garden/SkyMartConfig.java | 22 ++------------ .../features/garden/composter/ComposterConfig.java | 33 ++------------------- .../features/inventory/SackDisplayConfig.java | 33 ++------------------- .../features/misc/EstimatedItemValueConfig.java | 5 ++-- .../config/features/misc/TrackerConfig.java | 34 ++-------------------- .../java/at/hannibal2/skyhanni/data/SackAPI.kt | 25 +++++----------- .../at/hannibal2/skyhanni/data/TrackerManager.kt | 10 ------- .../skyhanni/features/fame/CityProjectFeatures.kt | 2 +- .../features/garden/composter/ComposterOverlay.kt | 7 +---- .../garden/inventory/SkyMartCopperPrice.kt | 4 +-- .../skyhanni/features/inventory/SackDisplay.kt | 17 +++-------- .../features/misc/items/EstimatedItemValue.kt | 2 +- .../misc/items/EstimatedItemValueCalculator.kt | 4 +-- .../java/at/hannibal2/skyhanni/test/PriceSource.kt | 8 ----- .../at/hannibal2/skyhanni/utils/ItemPriceSource.kt | 10 +++++++ .../java/at/hannibal2/skyhanni/utils/NEUItems.kt | 27 ++++++++++------- .../skyhanni/utils/tracker/SkyHanniItemTracker.kt | 9 +++--- .../skyhanni/utils/tracker/SkyHanniTracker.kt | 12 ++------ 18 files changed, 65 insertions(+), 199 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/test/PriceSource.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/ItemPriceSource.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/SkyMartConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/SkyMartConfig.java index b477d2329..d2a9428c7 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/SkyMartConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/SkyMartConfig.java @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.config.features.garden; import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.utils.ItemPriceSource; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; @@ -26,24 +27,7 @@ public class SkyMartConfig { public Position copperPricePos = new Position(211, 132, false, true); @Expose - @ConfigOption(name = "Overlay Price", desc = "Toggle for Bazaar 'sell order' vs 'instant sell' price in copper price overlay.") + @ConfigOption(name = "Change Price Source", desc = "Change what price to use: Bazaar (Sell Offer or Buy Order) or NPC.") @ConfigEditorDropdown - public OverlayPriceTypeEntry overlayPriceType = OverlayPriceTypeEntry.INSTANT_SELL; - - public enum OverlayPriceTypeEntry { - INSTANT_SELL("Instant Sell"), - SELL_ORDER("Sell Order"), - ; - private final String str; - - - OverlayPriceTypeEntry(String str) { - this.str = str; - } - - @Override - public String toString() { - return str; - } - } + public ItemPriceSource priceSource = ItemPriceSource.BAZAAR_INSTANT_SELL; } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java index 5f22aa62b..9712573fb 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/composter/ComposterConfig.java @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.config.features.garden.composter; import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.HasLegacyId; import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.utils.ItemPriceSource; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.Accordion; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; @@ -21,37 +22,9 @@ public class ComposterConfig { public boolean overlay = true; @Expose - @ConfigOption(name = "Overlay Price", desc = "Toggle for Bazaar 'buy order' vs 'instant buy' price in composter overlay.") + @ConfigOption(name = "Change Price Source", desc = "Change what price to use: Bazaar (Sell Offer or Buy Order) or NPC.") @ConfigEditorDropdown - public OverlayPriceTypeEntry overlayPriceType = OverlayPriceTypeEntry.INSTANT_BUY; - - public enum OverlayPriceTypeEntry implements HasLegacyId { - INSTANT_BUY("Instant Buy", 0), - BUY_ORDER("Buy Order", 1), - ; - private final String str; - private final int legacyId; - - OverlayPriceTypeEntry(String str, int legacyId) { - this.str = str; - this.legacyId = legacyId; - } - - // Constructor if new enum elements are added post-migration - OverlayPriceTypeEntry(String str) { - this(str, -1); - } - - @Override - public int getLegacyId() { - return legacyId; - } - - @Override - public String toString() { - return str; - } - } + public ItemPriceSource priceSource = ItemPriceSource.BAZAAR_INSTANT_BUY; @Expose @ConfigOption(name = "Retrieve From", desc = "Change where to retrieve the materials from in the composter overlay: Bazaar or Sacks.") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/SackDisplayConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/SackDisplayConfig.java index 0b4fc9998..88a6405fc 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/SackDisplayConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/SackDisplayConfig.java @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.config.features.inventory; import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.HasLegacyId; import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.utils.ItemPriceSource; import at.hannibal2.skyhanni.utils.RenderUtils; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; @@ -170,37 +171,9 @@ public class SackDisplayConfig { } @Expose - @ConfigOption(name = "Show Price From", desc = "Show price from Bazaar or NPC.") + @ConfigOption(name = "Change Price Source", desc = "Change what price to use: Bazaar (Sell Offer or Buy Order) or NPC.") @ConfigEditorDropdown - public PriceFrom priceFrom = PriceFrom.BAZAAR; - - public enum PriceFrom implements HasLegacyId { - BAZAAR("Bazaar", 0), - NPC("NPC", 1); - - private final String str; - private final int legacyId; - - PriceFrom(String str, int legacyId) { - this.str = str; - this.legacyId = legacyId; - } - - // Constructor if new enum elements are added post-migration - PriceFrom(String str) { - this(str, -1); - } - - @Override - public int getLegacyId() { - return legacyId; - } - - @Override - public String toString() { - return str; - } - } + public ItemPriceSource priceSource = ItemPriceSource.BAZAAR_INSTANT_BUY; @Expose @ConfigLink(owner = SackDisplayConfig.class, field = "enabled") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/EstimatedItemValueConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/EstimatedItemValueConfig.java index 10d97ebfd..096370308 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/EstimatedItemValueConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/EstimatedItemValueConfig.java @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.config.features.misc; import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.utils.ItemPriceSource; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; @@ -65,9 +66,9 @@ public class EstimatedItemValueConfig { public Property ignoreRunes = Property.of(false); @Expose - @ConfigOption(name = "Bazaar Price Source", desc = "Use Instant Buy or Buy Order.") + @ConfigOption(name = "Change Price Source", desc = "Change what price to use: Bazaar (Sell Offer or Buy Order) or NPC.") @ConfigEditorDropdown - public Property bazaarPriceSource = Property.of(BazaarPriceSource.BUY_ORDER); + public Property priceSource = Property.of(ItemPriceSource.BAZAAR_INSTANT_SELL); public enum BazaarPriceSource { INSTANT_BUY("Instant Buy"), diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/TrackerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/TrackerConfig.java index 5896dd38c..dcad728fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/TrackerConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/TrackerConfig.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features.misc; import at.hannibal2.skyhanni.config.FeatureToggle; -import at.hannibal2.skyhanni.config.HasLegacyId; +import at.hannibal2.skyhanni.utils.ItemPriceSource; import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.Accordion; @@ -19,37 +19,9 @@ public class TrackerConfig { public boolean hideInEstimatedItemValue = true; @Expose - @ConfigOption(name = "Show Price From", desc = "Show price from Bazaar or NPC.") + @ConfigOption(name = "Change Price Source", desc = "Change what price to use: Bazaar (Sell Offer or Buy Order) or NPC.") @ConfigEditorDropdown - public PriceFromEntry priceFrom = PriceFromEntry.SELL_OFFER; - - public enum PriceFromEntry implements HasLegacyId { - INSTANT_SELL("Instant Sell", 0), - SELL_OFFER("Sell Offer", 1), - NPC("NPC", 2); - private final String str; - private final int legacyId; - - PriceFromEntry(String str, int legacyId) { - this.str = str; - this.legacyId = legacyId; - } - - // Constructor if new enum elements are added post-migration - PriceFromEntry(String str) { - this(str, -1); - } - - @Override - public int getLegacyId() { - return legacyId; - } - - @Override - public String toString() { - return str; - } - } + public ItemPriceSource priceSource = ItemPriceSource.BAZAAR_INSTANT_BUY; @Expose @ConfigOption(name = "Default Display Mode", desc = "Change the display mode that gets shown on default.") diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt index b5d31185a..e392699cd 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigFileType -import at.hannibal2.skyhanni.config.features.inventory.SackDisplayConfig.PriceFrom import at.hannibal2.skyhanni.data.jsonobjects.repo.neu.NeuSacksJson import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent @@ -22,7 +21,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName -import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal @@ -49,15 +47,15 @@ object SackAPI { private val patternGroup = RepoPattern.group("data.sacks") private val sackPattern by patternGroup.pattern( "sack", - "^(.* Sack|Enchanted .* Sack)\$" + "^(.* Sack|Enchanted .* Sack)\$", ) private val numPattern by patternGroup.pattern( "number", - "(?:(?:§[0-9a-f](?I{1,3})§7:)?|(?:§7Stored:)?) (?§[0-9a-f])(?[0-9.,kKmMbB]+)§7/(?\\d+(?:[0-9.,]+)?[kKmMbB]?)" + "(?:(?:§[0-9a-f](?I{1,3})§7:)?|(?:§7Stored:)?) (?§[0-9a-f])(?[0-9.,kKmMbB]+)§7/(?\\d+(?:[0-9.,]+)?[kKmMbB]?)", ) private val gemstonePattern by patternGroup.pattern( "gemstone", - " §[0-9a-f](?[A-z]*): §[0-9a-f](?\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?)(?: §[0-9a-f]\\(\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?\\))?" + " §[0-9a-f](?[A-z]*): §[0-9a-f](?\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?)(?: §[0-9a-f]\\(\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?\\))?", ) private var isRuneSack = false @@ -114,21 +112,14 @@ object SackAPI { SackDisplay.update(isNewInventory) } - private fun String.getTrophyRarity(): TrophyRarity? { - return if (this.startsWith("Bronze")) - TrophyRarity.BRONZE - else - if (this.startsWith("Silver")) - TrophyRarity.SILVER - else null + private fun String.getTrophyRarity(): TrophyRarity? = when { + this.startsWith("Bronze") -> TrophyRarity.BRONZE + this.startsWith("Silver") -> TrophyRarity.SILVER + else -> null } private fun NEUInternalName.sackPrice(stored: Int): Long { - return when (sackDisplayConfig.priceFrom) { - PriceFrom.BAZAAR -> (getPrice() * stored).toLong().coerceAtLeast(0) - PriceFrom.NPC -> (getNpcPriceOrNull() ?: 0.0).toLong() * stored - else -> 0L - } + return getPrice(sackDisplayConfig.priceSource).toLong() * stored } fun getSacksData(savingSacks: Boolean) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt b/src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt index ab5f9cc78..71b60d76e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt @@ -1,13 +1,10 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.config.features.misc.TrackerConfig.PriceFromEntry import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ConditionalUtils -import at.hannibal2.skyhanni.utils.ConfigUtils import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -39,11 +36,4 @@ object TrackerManager { hasChanged = false } } - - @SubscribeEvent - fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.transform(17, "misc.tracker.priceFrom") { element -> - ConfigUtils.migrateIntToEnum(element, PriceFromEntry::class.java) - } - } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt index f4f4fbac4..445714402 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt @@ -170,7 +170,7 @@ object CityProjectFeatures { ) { inInventory && !NEUItems.neuHasFocus() } ) - val price = internalName.getPrice(false) * amount + val price = internalName.getPrice() * amount val format = price.shortFormat() list.add(" §7(§6$format§7)") add(list) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt index 303fd7464..8ed772ea3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.features.garden.composter import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.garden.composter.ComposterConfig -import at.hannibal2.skyhanni.config.features.garden.composter.ComposterConfig.OverlayPriceTypeEntry import at.hannibal2.skyhanni.config.features.garden.composter.ComposterConfig.RetrieveFromEntry import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacksOrNull import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson @@ -535,8 +534,7 @@ object ComposterOverlay { } private fun getPrice(internalName: NEUInternalName): Double { - val useSellPrice = config.overlayPriceType == ComposterConfig.OverlayPriceTypeEntry.BUY_ORDER - val price = internalName.getPrice(useSellPrice) + val price = internalName.getPrice(config.priceSource) if (internalName.equals("BIOFUEL") && price > 20_000) return 20_000.0 return price @@ -622,9 +620,6 @@ object ComposterOverlay { event.move(3, "garden.composterOverlayOrganicMatterPos", "garden.composters.overlayOrganicMatterPos") event.move(3, "garden.composterOverlayFuelExtrasPos", "garden.composters.overlayFuelExtrasPos") event.move(3, "garden.composterRoundDown", "garden.composters.roundDown") - event.transform(15, "garden.composters.overlayPriceType") { element -> - ConfigUtils.migrateIntToEnum(element, OverlayPriceTypeEntry::class.java) - } event.transform(15, "garden.composters.retrieveFrom") { element -> ConfigUtils.migrateIntToEnum(element, RetrieveFromEntry::class.java) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt index b2575c88d..5ef150907 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt @@ -1,7 +1,6 @@ package at.hannibal2.skyhanni.features.garden.inventory import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.config.features.garden.SkyMartConfig import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent @@ -56,8 +55,7 @@ object SkyMartCopperPrice { } ?: continue val internalName = item.getInternalName() - val useSellPrice = config.overlayPriceType == SkyMartConfig.OverlayPriceTypeEntry.SELL_ORDER - val itemPrice = internalName.getPriceOrNull(useSellPrice) ?: continue + val itemPrice = internalName.getPriceOrNull(config.priceSource) ?: continue val profit = itemPrice - (otherItemsPrice ?: 0.0) val factor = profit / copper diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt index 81e277fd6..55be1b08f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.features.inventory import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.config.features.inventory.SackDisplayConfig import at.hannibal2.skyhanni.config.features.inventory.SackDisplayConfig.NumberFormatEntry import at.hannibal2.skyhanni.config.features.inventory.SackDisplayConfig.PriceFormatEntry import at.hannibal2.skyhanni.config.features.inventory.SackDisplayConfig.SortingTypeEntry @@ -17,6 +16,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addSelector import at.hannibal2.skyhanni.utils.CollectionUtils.addString import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemPriceSource import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils @@ -206,11 +206,11 @@ object SackDisplay { ) if (config.showPrice) { - list.addSelector(" ", + list.addSelector(" ", 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 = SackDisplayConfig.PriceFrom.entries[it.ordinal] // todo avoid ordinal + config.priceSource = ItemPriceSource.entries[it.ordinal] // todo avoid ordinal update(false) }) list.addButton( @@ -300,12 +300,6 @@ object SackDisplay { ; } - enum class PriceFrom(val displayName: String) { - BAZAAR("Bazaar Price"), - NPC("NPC Price"), - ; - } - enum class PriceFormat(val displayName: String) { FORMATED("Formatted"), UNFORMATED("Unformatted"), @@ -327,9 +321,6 @@ object SackDisplay { event.transform(15, "inventory.sackDisplay.priceFormat") { element -> ConfigUtils.migrateIntToEnum(element, PriceFormatEntry::class.java) } - event.transform(15, "inventory.sackDisplay.priceFrom") { element -> - ConfigUtils.migrateIntToEnum(element, SackDisplayConfig.PriceFrom::class.java) - } event.transform(15, "inventory.sackDisplay.sortingType") { element -> ConfigUtils.migrateIntToEnum(element, SortingTypeEntry::class.java) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt index 21b86b6cf..e55916f95 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt @@ -123,7 +123,7 @@ object EstimatedItemValue { ignoreHelmetSkins, ignoreArmorDyes, ignoreRunes, - bazaarPriceSource, + priceSource, useAttributeComposite, ) { cache.clear() 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 bfc42659f..ad00298c3 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 @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.features.misc.items import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.api.ReforgeAPI -import at.hannibal2.skyhanni.config.features.misc.EstimatedItemValueConfig import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName @@ -760,7 +759,6 @@ object EstimatedItemValueCalculator { private fun NEUInternalName.getPrice(): Double = getPriceOrNull() ?: -1.0 private fun NEUInternalName.getPriceOrNull(): Double? { - val useSellPrice = config.bazaarPriceSource.get() == EstimatedItemValueConfig.BazaarPriceSource.BUY_ORDER - return getPriceOrNull(useSellPrice) + return getPriceOrNull(config.priceSource.get()) } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/PriceSource.kt b/src/main/java/at/hannibal2/skyhanni/test/PriceSource.kt deleted file mode 100644 index 45da414ee..000000000 --- a/src/main/java/at/hannibal2/skyhanni/test/PriceSource.kt +++ /dev/null @@ -1,8 +0,0 @@ -package at.hannibal2.skyhanni.test - -enum class PriceSource(val displayName: String) { - BAZAAR_INSTANT_SELL("Instant Sell"), - BAZAAR_SELL_OFFER("Sell Offer"), - NPC("NPC Price"), - ; -} 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 = emptyList()) = - getPriceOrNull(useSellPrice, pastRecipes) ?: -1.0 + fun NEUInternalName.getPrice( + priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY, + pastRecipes: List = 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 = emptyList()): Double? { + fun NEUInternalName.getPriceOrNull( + priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY, + pastRecipes: List = 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( fun addPriceFromButton(lists: MutableList>) { if (isInventoryOpen()) { - lists.addSelector( + lists.addSelector( "", 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( 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 -- cgit