diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-03-14 12:18:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-14 12:18:43 +0100 |
commit | 578069c68c0dc648bcc9e5fa6a2d445da7fc8e9c (patch) | |
tree | 512fd0dbfe9e411d7df0133d58190b7f4c2e9a74 /src/main/java/at/hannibal2/skyhanni | |
parent | 020f9b5758870d806754051f1e87ec276b0a8521 (diff) | |
download | skyhanni-578069c68c0dc648bcc9e5fa6a2d445da7fc8e9c.tar.gz skyhanni-578069c68c0dc648bcc9e5fa6a2d445da7fc8e9c.tar.bz2 skyhanni-578069c68c0dc648bcc9e5fa6a2d445da7fc8e9c.zip |
Feature: AH estimated item value comparison (#339)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
8 files changed, 202 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index e6e27dc97..b1dbd73e0 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -253,6 +253,7 @@ import at.hannibal2.skyhanni.features.minion.InfernoMinionFeatures import at.hannibal2.skyhanni.features.minion.MinionCollectLogic import at.hannibal2.skyhanni.features.minion.MinionFeatures import at.hannibal2.skyhanni.features.minion.MinionXp +import at.hannibal2.skyhanni.features.misc.AuctionHousePriceComparison import at.hannibal2.skyhanni.features.misc.BetterSignEditing import at.hannibal2.skyhanni.features.misc.BetterWikiFromMenus import at.hannibal2.skyhanni.features.misc.BrewingStandOverlay @@ -506,7 +507,7 @@ class SkyHanniMod { // features loadModule(BazaarOrderHelper()) - loadModule(AuctionsHighlighter()) + loadModule(AuctionsHighlighter) loadModule(ChatFilter()) loadModule(PlayerChatModifier()) loadModule(DungeonChatFilter()) @@ -733,6 +734,7 @@ class SkyHanniMod { loadModule(EnderNodeTracker) loadModule(CompactBestiaryChatMessage()) loadModule(WatchdogHider()) + loadModule(AuctionHousePriceComparison()) loadModule(AccountUpgradeReminder()) loadModule(PetExpTooltip()) loadModule(Translator()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/AuctionHousePriceComparisonConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/AuctionHousePriceComparisonConfig.java new file mode 100644 index 000000000..3ff502632 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/AuctionHousePriceComparisonConfig.java @@ -0,0 +1,41 @@ +package at.hannibal2.skyhanni.config.features.inventory; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.utils.LorenzColor; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorColour; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +public class AuctionHousePriceComparisonConfig { + + @Expose + @ConfigOption( + name = "Show Price Comparison", + desc = "Highlight auctions based on the difference between their estimated value and the value they are listed for. §eCan " + + "be very inaccurate." + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = false; + + @Expose + @ConfigOption(name = "Good Colour", desc = "What colour to highlight good value items with.") + @ConfigEditorColour + public String good = LorenzColor.GREEN.toConfigColour(); + + @Expose + @ConfigOption(name = "Very Good Colour", desc = "What colour to highlight very good value items with.") + @ConfigEditorColour + public String veryGood = "0:255:0:139:0"; + + @Expose + @ConfigOption(name = "Bad Colour", desc = "What colour to highlight bad items with.") + @ConfigEditorColour + public String bad = LorenzColor.YELLOW.toConfigColour(); + + @Expose + @ConfigOption(name = "Very Bad Colour", desc = "What colour to highlight very bad items with.") + @ConfigEditorColour + public String veryBad = "0:255:225:43:30"; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java index e82ca2827..874fde7d7 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java @@ -75,6 +75,11 @@ public class InventoryConfig { public AuctionHouseConfig auctions = new AuctionHouseConfig(); @Expose + @ConfigOption(name = "Auctions Price Comparison", desc = "") + @Accordion + public AuctionHousePriceComparisonConfig auctionsPriceComparison = new AuctionHousePriceComparisonConfig(); + + @Expose @ConfigOption( name = "Item Number", desc = "Showing the item number as a stack size for these items." diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt index 9a8055139..0f454b54d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/AuctionsHighlighter.kt @@ -18,14 +18,19 @@ import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -class AuctionsHighlighter { +object AuctionsHighlighter { private val config get() = SkyHanniMod.feature.inventory.auctions - private val buyItNowPattern by RepoPattern.pattern( - "auctions.highlight.buyitnow", + private val patternGroup = RepoPattern.group("auctions.highlight") + val buyItNowPattern by patternGroup.pattern( + "buyitnow", "§7Buy it now: §6(?<coins>.*) coins" ) + val auctionPattern by patternGroup.pattern( + "auction", + "§7(?:Starting bid|Top bid): §6(?<coins>.*) coins" + ) @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/AuctionHousePriceComparison.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/AuctionHousePriceComparison.kt new file mode 100644 index 000000000..187641835 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/AuctionHousePriceComparison.kt @@ -0,0 +1,139 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.features.inventory.AuctionsHighlighter +import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValueCalculator +import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color + +class AuctionHousePriceComparison { + + private val config get() = SkyHanniMod.feature.inventory.auctionsPriceComparison + + private var slotPriceMap = mapOf<Int, Long>() + private var bestPrice = 0L + private var worstPrice = 0L + private var inInventory = false + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + inInventory = false + if (!event.inventoryName.startsWith("Auctions")) return + inInventory = true + + bestPrice = 0L + worstPrice = 0L + + val map = mutableMapOf<Int, Long>() + + for ((slot, stack) in event.inventoryItems) { + for (line in stack.getLore()) { + AuctionsHighlighter.buyItNowPattern.matchMatcher(line) { + map.add(stack, group("coins").formatLong(), slot) + } + AuctionsHighlighter.auctionPattern.matchMatcher(line) { + map.add(stack, group("coins").formatLong(), slot) + } + } + } + this.slotPriceMap = map + } + + private fun MutableMap<Int, Long>.add(stack: ItemStack, binPrice: Long, slot: Int) { + val (totalPrice, basePrice) = EstimatedItemValueCalculator.calculate(stack, mutableListOf()) + if (totalPrice == basePrice) return + val estimatedPrice = totalPrice.toLong() + + val diff = estimatedPrice - binPrice + this[slot] = diff + if (diff >= 0) { + if (diff > bestPrice) { + bestPrice = diff + } + } else { + if (diff < worstPrice) { + worstPrice = diff + } + } + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!isEnabled()) return + + val good = config.good.toChromaColor() + val veryGood = config.veryGood.toChromaColor() + + val bad = config.bad.toChromaColor() + val veryBad = config.veryBad.toChromaColor() + + + for (slot in InventoryUtils.getItemsInOpenChest()) { + val diff = slotPriceMap[slot.slotIndex] ?: continue + if (diff == 0L) { + slot highlight good + continue + } + val isGood = diff >= 0 + val percentage = if (isGood) { + diff.toDouble() / bestPrice + } else { + -diff.toDouble() / -worstPrice + } + val color = if (isGood) { + getColorInBetween(good, veryGood, percentage) + } else { + getColorInBetween(bad, veryBad, percentage) + } + slot highlight color + } + } + + @SubscribeEvent + fun onTooltip(event: LorenzToolTipEvent) { + if (!isEnabled()) return + + val diff = slotPriceMap[event.slot.slotIndex] ?: return + + event.toolTip.add("") + if (diff >= 0) { + event.toolTip.add("§aThis item is §6${diff.addSeparators()} coins §acheaper") + event.toolTip.add("§athan the estimated item value!") + } else { + event.toolTip.add("§cThis item is §6${(-diff).addSeparators()} coins §cmore") + event.toolTip.add("§cexpensive than the estimated item value!") + } + } + + private fun getColorInBetween(color1: Color, color2: Color, percentage: Double): Color { + val r1 = color1.red + val g1 = color1.green + val b1 = color1.blue + + val r2 = color2.red + val g2 = color2.green + val b2 = color2.blue + + val newRed = (lerp(percentage, r1, r2)).toInt().coerceIn(0, 255) + val newGreen = (lerp(percentage, g1, g2)).toInt().coerceIn(0, 255) + val newBlue = (lerp(percentage, b1, b2)).toInt().coerceIn(0, 255) + + return Color(newRed, newGreen, newBlue) + } + + private fun lerp(delta: Double, start: Int, end: Int) = start + delta * (end - start) + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && inInventory +} 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 87e582545..6b90adba6 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 @@ -546,6 +546,7 @@ object EstimatedItemValueCalculator { var totalPrice = 0.0 val map = mutableMapOf<String, Double>() + //todo use repo val tieredEnchants = listOf("compact", "cultivating", "champion", "expertise", "hecatomb") val onlyTierOnePrices = listOf("ultimate_chimera", "ultimate_fatal_tempo", "smoldering", "ultimate_flash", "divine_gift") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 196103e2d..d4c9b87a4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -395,6 +395,9 @@ object ItemUtils { if (this == NEUInternalName.NONE) { error("NEUInternalName.NONE has no name!") } + if (NEUItems.ignoreItemsFilter.match(this.asString())) { + return "§cBugged Item" + } val itemStack = getItemStackOrNull() val name = itemStack?.name ?: error("Could not find item name for $this") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzColor.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzColor.kt index fdac1a4a8..717acf98d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzColor.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzColor.kt @@ -38,6 +38,8 @@ enum class LorenzColor(private val chatColorCode: Char, private val color: Color override fun toString(): String = coloredLabel + fun toConfigColour(): String = "0:255:${color.red}:${color.green}:${color.blue}" + companion object { fun EnumDyeColor.toLorenzColor() = when (this) { |