diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2023-06-09 23:09:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 23:09:43 +0200 |
commit | 40703a977119cd83f6975d873728e756e46e0cc7 (patch) | |
tree | 3df00cff2d2ec519709b3e411ed21f1134ade250 /src/main | |
parent | c6dbecb3e1bd1edd795fd18ee9e6628f7c702e47 (diff) | |
download | skyhanni-40703a977119cd83f6975d873728e756e46e0cc7.tar.gz skyhanni-40703a977119cd83f6975d873728e756e46e0cc7.tar.bz2 skyhanni-40703a977119cd83f6975d873728e756e46e0cc7.zip |
Sack Display Price Changes (#217)
Co-authored-by: HiZe_ <superhize@hotmail.com>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt | 328 |
2 files changed, 182 insertions, 148 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java index 0a357a8f3..d61db3cfd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java @@ -181,7 +181,7 @@ public class Inventory { @Expose @ConfigOption(name = "Show Price From", desc = "Show price from Bazaar or NPC.") @ConfigEditorDropdown(values = {"Bazaar", "NPC"}) - public int priceFrom = 1; + public int priceFrom = 0; @Expose @ConfigOption(name = "Show in Runes Sack", desc = "Show contained items inside a runes sack.") 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 619f231b2..0bd5dbc98 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt @@ -5,11 +5,13 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -28,6 +30,7 @@ class SackDisplay { var isRuneSack = false var isGemstoneSack = false var isTrophySack = false + var sackRarity = TrophyRarity.NONE } private val config get() = SkyHanniMod.feature.inventory.sackDisplay @@ -36,47 +39,126 @@ class SackDisplay { private val runeItem = mutableMapOf<String, Rune>() private val gemstoneItem = mutableMapOf<String, Gemstone>() private val sackPattern = "^(.* Sack|Enchanted .* Sack)$".toPattern() + private val stackList = mutableMapOf<Int, ItemStack>() private val gemstoneMap = mapOf( - "Jade Gemstones" to "ROUGH_JADE_GEM", - "Amber Gemstones" to "ROUGH_AMBER_GEM", - "Topaz Gemstones" to "ROUGH_TOPAZ_GEM", - "Sapphire Gemstones" to "ROUGH_SAPPHIRE_GEM", - "Amethyst Gemstones" to "ROUGH_AMETHYST_GEM", - "Jasper Gemstones" to "ROUGH_JASPER_GEM", - "Ruby Gemstones" to "ROUGH_RUBY_GEM", - "Opal Gemstones" to "ROUGH_OPAL_GEM" + "Jade Gemstones" to "ROUGH_JADE_GEM", + "Amber Gemstones" to "ROUGH_AMBER_GEM", + "Topaz Gemstones" to "ROUGH_TOPAZ_GEM", + "Sapphire Gemstones" to "ROUGH_SAPPHIRE_GEM", + "Amethyst Gemstones" to "ROUGH_AMETHYST_GEM", + "Jasper Gemstones" to "ROUGH_JASPER_GEM", + "Ruby Gemstones" to "ROUGH_RUBY_GEM", + "Opal Gemstones" to "ROUGH_OPAL_GEM" ) private val numPattern = - "(?:(?:§[0-9a-f](?<level>I{1,3})§7:)?|(?:§7Stored:)?) (?<color>§[0-9a-f])(?<stored>\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?)§7/(?<total>\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?)".toPattern() + "(?:(?:§[0-9a-f](?<level>I{1,3})§7:)?|(?:§7Stored:)?) (?<color>§[0-9a-f])(?<stored>\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?)§7/(?<total>\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?)".toPattern() private val gemstonePattern = - " §[0-9a-f](?<gemrarity>[A-z]*): §[0-9a-f](?<stored>\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?)(?: §[0-9a-f]\\(\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?\\))?".toPattern() + " §[0-9a-f](?<gemrarity>[A-z]*): §[0-9a-f](?<stored>\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?)(?: §[0-9a-f]\\(\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?\\))?".toPattern() @SubscribeEvent fun onBackgroundDraw(event: GuiRenderEvent.ChestBackgroundRenderEvent) { if (inInventory) { config.position.renderStringsAndItems( - display, - extraSpace = config.extraSpace, - itemScale = 1.3, - posLabel = "Sacks Items" + display, + extraSpace = config.extraSpace, + itemScale = 1.3, + posLabel = "Sacks Items" ) } } - private fun updateDisplay() { + private fun update() { display = drawDisplay() } - private fun update() { - updateDisplay() + private fun init() { + for ((_, stack) in stackList) { + val name = stack.name ?: continue + val lore = stack.getLore() + val gem = Gemstone() + val rune = Rune() + val item = Item() + loop@ for (line in lore) { + if (isGemstoneSack) { + gemstonePattern.matchMatcher(line) { + val rarity = group("gemrarity") + val stored = group("stored") + gem.internalName = gemstoneMap[name.removeColor()].toString() + if (gemstoneMap.containsKey(name.removeColor())) { + val internalName = + "${rarity.uppercase()}_${name.uppercase().split(" ")[0].removeColor()}_GEM" + + when (rarity) { + "Rough" -> { + gem.rough = stored + gem.roughPrice = calculatePrice(internalName, stored) + } + + "Flawed" -> { + gem.flawed = stored + gem.flawedPrice = calculatePrice(internalName, stored) + } + + "Fine" -> { + gem.fine = stored + gem.finePrice = calculatePrice(internalName, stored) + } + + "Flawless" -> { + gem.flawless = stored + gem.flawlessPrice = calculatePrice(internalName, stored) + } + } + gemstoneItem[name] = gem + } + } + } else { + numPattern.matchMatcher(line) { + val stored = group("stored") + val total = group("total") + val internalName = stack.getInternalName() + item.internalName = internalName + item.colorCode = group("color") + item.stored = stored + item.total = total + if (isTrophySack) { + val trophyName = name.removeColor().uppercase().replace(" ", "_").replace("-", "_") + item.price = calculatePrice("MAGMA_FISH", Trophy.valueOf(trophyName).convert(sackRarity, stored)) + } else { + item.price = if (calculatePrice(internalName, stored) < 0) 0 else calculatePrice(internalName, stored) + } + if (isRuneSack) { + val level = group("level") + rune.stack = stack + if (level == "I") { + rune.lvl1 = stored + continue@loop + } + if (level == "II") { + rune.lvl2 = stored + continue@loop + } + if (level == "III") { + rune.lvl3 = stored + } + runeItem.put(name, rune) + } else { + sackItem.put(name, item) + } + } + } + } + } } private fun drawDisplay(): List<List<Any>> { val newDisplay = mutableListOf<List<Any>>() var totalPrice = 0 var rendered = 0 + init() + if (sackItem.isNotEmpty()) { val sortedPairs: MutableMap<String, Item> = when (config.sortingType) { 0 -> sackItem.toList().sortedByDescending { it.second.stored.formatNumber() }.toMap().toMutableMap() @@ -92,7 +174,8 @@ class SackDisplay { } } - newDisplay.addAsSingletonList("§7Items in Sacks: §o(Rendering ${if (config.itemToShow > sortedPairs.size) sortedPairs.size else config.itemToShow} of ${sortedPairs.size} items)") + val amountShowing = if (config.itemToShow > sortedPairs.size) sortedPairs.size else config.itemToShow + newDisplay.addAsSingletonList("§7Items in Sacks: §o(Rendering $amountShowing of ${sortedPairs.size} items)") for ((itemName, item) in sortedPairs) { val (internalName, colorCode, stored, total, price) = item totalPrice += price @@ -111,12 +194,14 @@ class SackDisplay { else add("${itemName.replace("§k", "")}: ") - add(when (config.numberFormat) { - 0 -> "$colorCode${stored}§7/§b${total}" - 1 -> "$colorCode${NumberUtil.format(stored.formatNumber())}§7/§b${total}" - 2 -> "$colorCode${stored}§7/§b${total.formatNumber().toInt().addSeparators()}" - else -> "$colorCode${stored}§7/§b${total}" - }) + add( + when (config.numberFormat) { + 0 -> "$colorCode${stored}§7/§b${total}" + 1 -> "$colorCode${NumberUtil.format(stored.formatNumber())}§7/§b${total}" + 2 -> "$colorCode${stored}§7/§b${total.formatNumber().toInt().addSeparators()}" + else -> "$colorCode${stored}§7/§b${total}" + } + ) if (colorCode == "§a") add(" §c§l(Full!)") @@ -126,31 +211,27 @@ class SackDisplay { rendered++ } - newDisplay.add(buildList { - add("§eSort by: §6Stored ") - add(Renderable.optionalLink("§7[§bDESC§7] ", { - config.sortingType = 0 - update() - }) { !NEUItems.neuHasFocus() }) - add(Renderable.optionalLink("§7[§bASC§7] ", { - config.sortingType = 1 - update() - }) { !NEUItems.neuHasFocus() }) - - if (config.showPrice) { - add("§6Price ") - add(Renderable.optionalLink("§7[§bDESC§7] ", { - config.sortingType = 2 - update() - }) { !NEUItems.neuHasFocus() }) - add(Renderable.optionalLink("§7[§bASC§7]", { - config.sortingType = 3 + val name = SortType.values()[config.sortingType].longName + newDisplay.addAsSingletonList("§7Sorted By: §c$name") + + newDisplay.addSelector(" ", SortType.values(), + getName = { type -> type.shortName }, + isCurrent = { it.ordinal == config.sortingType }, + onChange = { + config.sortingType = it.ordinal update() - }) { !NEUItems.neuHasFocus() }) - } - }) - if (config.showPrice) - newDisplay.addAsSingletonList("§eTotal price: §6${format(totalPrice)}") + }) + + if (config.showPrice) { + newDisplay.addAsSingletonList("§cTotal price: §6${format(totalPrice)}") + newDisplay.addSelector(" ", PriceFrom.values(), + getName = { type -> type.displayName }, + isCurrent = { it.ordinal == config.priceFrom }, + onChange = { + config.priceFrom = it.ordinal + update() + }) + } } if (runeItem.isNotEmpty()) { @@ -202,6 +283,7 @@ class SackDisplay { runeItem.clear() gemstoneItem.clear() sackItem.clear() + stackList.clear() } @SubscribeEvent @@ -215,114 +297,38 @@ class SackDisplay { isRuneSack = inventoryName == "Runes Sack" isGemstoneSack = inventoryName == "Gemstones Sack" isTrophySack = inventoryName.contains("Trophy Fishing Sack") - val sackRarity = if (inventoryName.startsWith("Bronze")) TrophyRarity.BRONZE else if (inventoryName.startsWith("Silver")) TrophyRarity.SILVER else TrophyRarity.NONE + sackRarity = inventoryName.getTrophyRarity() inInventory = true - for ((_, stack) in stacks) { - val name = stack.name ?: continue - val lore = stack.getLore() - val gem = Gemstone() - val rune = Rune() - val item = Item() - loop@ for (line in lore) { - if (isGemstoneSack) { - gemstonePattern.matchMatcher(line) { - val rarity = group("gemrarity") - val stored = group("stored") - gem.internalName = gemstoneMap[name.removeColor()].toString() - if (gemstoneMap.containsKey(name.removeColor())) { - val internalName = - "${rarity.uppercase()}_${name.uppercase().split(" ")[0].removeColor()}_GEM" - - when (rarity) { - "Rough" -> { - gem.rough = stored - gem.roughPrice = calculatePrice(internalName, stored) - } - - "Flawed" -> { - gem.flawed = stored - gem.flawedPrice = calculatePrice(internalName, stored) - } - - "Fine" -> { - gem.fine = stored - gem.finePrice = calculatePrice(internalName, stored) - } - - "Flawless" -> { - gem.flawless = stored - gem.flawlessPrice = calculatePrice(internalName, stored) - } - } - gemstoneItem[name] = gem - } - } - } else { - numPattern.matchMatcher(line) { - val stored = group("stored") - val total = group("total") - val internalName = stack.getInternalName() - item.internalName = internalName - item.colorCode = group("color") - item.stored = stored - item.total = total - if (isTrophySack) { - val trophyName = name.removeColor().uppercase().replace(" ", "_").replace("-", "_") - item.price = calculatePrice("MAGMA_FISH", Trophy.valueOf(trophyName).convert(sackRarity, stored)) - } else - item.price = calculatePrice(internalName, stored) - - if (isRuneSack) { - val level = group("level") - rune.stack = stack - if (level == "I") { - rune.lvl1 = stored - continue@loop - } - if (level == "II") { - rune.lvl2 = stored - continue@loop - } - if (level == "III") { - rune.lvl3 = stored - } - runeItem.put(name, rune) - } else { - sackItem.put(name, item) - } - } - } - } - } + stackList.putAll(stacks) update() } data class Gemstone( - var internalName: String = "", - var rough: String = "0", - var flawed: String = "0", - var fine: String = "0", - var flawless: String = "0", - var roughPrice: Int = 0, - var flawedPrice: Int = 0, - var finePrice: Int = 0, - var flawlessPrice: Int = 0, + var internalName: String = "", + var rough: String = "0", + var flawed: String = "0", + var fine: String = "0", + var flawless: String = "0", + var roughPrice: Int = 0, + var flawedPrice: Int = 0, + var finePrice: Int = 0, + var flawlessPrice: Int = 0, ) data class Rune( - var stack: ItemStack? = null, - var lvl1: String = "0", - var lvl2: String = "0", - var lvl3: String = "0", + var stack: ItemStack? = null, + var lvl1: String = "0", + var lvl2: String = "0", + var lvl3: String = "0", ) data class Item( - var internalName: String = "", - var colorCode: String = "", - var stored: String = "0", - var total: String = "0", - var price: Int = 0, + var internalName: String = "", + var colorCode: String = "", + var stored: String = "0", + var total: String = "0", + var price: Int = 0, ) enum class Trophy(private val bronzeValue: Int, private val silverValue: Int) { @@ -349,13 +355,13 @@ class SackDisplay { return when (rarity) { TrophyRarity.BRONZE -> (this.bronzeValue * stored.formatNumber().toInt()).toString() TrophyRarity.SILVER -> (this.silverValue * stored.formatNumber().toInt()).toString() - else -> "0" + TrophyRarity.NONE -> "0" } } } enum class TrophyRarity { - NONE, BRONZE, SILVER + BRONZE, SILVER, NONE } private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled @@ -363,7 +369,11 @@ class SackDisplay { private fun calculatePrice(internalName: String, stored: String) = when (config.priceFrom) { 0 -> { - (NEUItems.getPrice(internalName, true) * stored.formatNumber()).toInt() + (NEUItems.getPrice(internalName, true) * stored.formatNumber()).toInt().let { + if (it < 0) + 0 + else it + } } 1 -> try { @@ -375,4 +385,28 @@ class SackDisplay { else -> 0 } + + enum class SortType(val shortName: String, val longName: String) { + STORED_DESC("Stored D", "Stored Descending"), + STORED_ASC("Stored A", "Stored Ascending"), + PRICE_DESC("Price D", "Price Descending"), + PRICE_ASC("Price A", "Price Ascending"), + ; + } + + enum class PriceFrom(val displayName: String) { + NPC("Npc Price"), + BAZAAR("Bazaar Price"), + ; + } + + private fun String.getTrophyRarity(): TrophyRarity { + return if (this.startsWith("Bronze")) + TrophyRarity.BRONZE + else + if (this.startsWith("Silver")) + TrophyRarity.SILVER + else + TrophyRarity.NONE + } } |