From bc1a28285226db06109b0d39ec4242db1edb8a6d Mon Sep 17 00:00:00 2001 From: NetheriteMiner <88792142+NetheriteMiner@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:24:21 -0500 Subject: Max Items Bazaar with current Purse. #876 --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 + .../config/features/inventory/InventoryConfig.java | 10 +++ .../java/at/hannibal2/skyhanni/data/PurseAPI.kt | 2 + .../skyhanni/features/inventory/MaxPurseItems.kt | 99 ++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/MaxPurseItems.kt (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 7e3cebd29..4037f11ff 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -216,6 +216,7 @@ import at.hannibal2.skyhanni.features.inventory.HideNotClickableItems import at.hannibal2.skyhanni.features.inventory.HighlightBonzoMasks import at.hannibal2.skyhanni.features.inventory.ItemDisplayOverlayFeatures import at.hannibal2.skyhanni.features.inventory.ItemStars +import at.hannibal2.skyhanni.features.inventory.MaxPurseItems import at.hannibal2.skyhanni.features.inventory.PowerStoneGuideFeatures import at.hannibal2.skyhanni.features.inventory.QuickCraftFeatures import at.hannibal2.skyhanni.features.inventory.QuiverNotification @@ -754,6 +755,7 @@ class SkyHanniMod { loadModule(SkillProgress) loadModule(SkillTooltip()) loadModule(QuiverNotification) + loadModule(MaxPurseItems()) init() 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 84ebfd9ca..6c905889f 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 @@ -2,6 +2,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.config.features.inventory.helper.HelperConfig; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.Accordion; @@ -199,6 +200,15 @@ public class InventoryConfig { @FeatureToggle public boolean shiftClickForEquipment = false; + @Expose + @ConfigOption(name = "Max Items With Purse", desc = "Calculates the maximum amount of items that can be purchased from the Bazaar for the amount of coins in your purse.") + @ConfigEditorBoolean + @FeatureToggle + public boolean maxPurseItems = false; + + @Expose + public Position purseItemsPos = new Position(346, 90, true, false); + @Expose @ConfigOption(name = "Shift Click NPC sell", desc = "Makes normal clicks to shift clicks in npc inventory for selling.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt index a9c18c60c..90ea15627 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt @@ -76,4 +76,6 @@ object PurseAPI { return PurseChangeCause.LOSE_UNKNOWN } } + + fun getPurse(): Double = currentPurse } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/MaxPurseItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/MaxPurseItems.kt new file mode 100644 index 000000000..f3ca86a34 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/MaxPurseItems.kt @@ -0,0 +1,99 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.PurseAPI +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.features.bazaar.BazaarApi +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.formatDouble +import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraft.client.Minecraft +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class MaxPurseItems { + + private val patternGroup = RepoPattern.group("inventory.maxpurse") + private val orderPattern by patternGroup.pattern( + "order", + ".*§6(?[\\d.,]+) coins §7each.*" + ) + private val instantPattern by patternGroup.pattern( + "instant", + ".*Price per unit: §6(?[\\d.,]+) coins.*" + ) + private val createOrderPattern by patternGroup.pattern( + "createorder", + "§aCreate Buy Order" + ) + private val createInstantPattern by patternGroup.pattern( + "createinstant", + "§aBuy Instantly" + ) + + private var buyOrderPrice: Double? = null + private var instantBuyPrice: Double? = null + private val config get() = SkyHanniMod.feature.inventory + + private fun getPrices() { + for (item in Minecraft.getMinecraft().thePlayer.openContainer.inventory) { + val name = item?.displayName ?: continue + createOrderPattern.matchMatcher(name) { + for (info in item.getLore()) { + orderPattern.matchMatcher(info) { + // +0.1 because I expect people to use the gold nugget option + buyOrderPrice = group("coins").formatDouble()?.let { it + 0.1 } ?: 0.0 + // If we get to this point, we have the instant price because instant is earlier in the list of items + // So we can return + return + } + } + } + createInstantPattern.matchMatcher(name) { + for (info in item.getLore()) { + instantPattern.matchMatcher(info) { + instantBuyPrice = group("coins").formatDouble() ?: 0.0 + } + } + } + } + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (!isEnabled()) return + if (!BazaarApi.inBazaarInventory) return + // I would use BazaarAPI for price info, but as soon as NEU's data goes out of date, it will be wrong + if (BazaarApi.currentlyOpenedProduct == null) { + buyOrderPrice = null + instantBuyPrice = null + return + } + if (buyOrderPrice == null && instantBuyPrice == null) { + getPrices() + } + + val currentPurse = PurseAPI.getPurse() + val buyOrders = buyOrderPrice?.let { + (currentPurse / it).toInt() + } ?: 0 + val buyInstant = instantBuyPrice?.let { + (currentPurse / it).toInt() + } ?: 0 + + config.purseItemsPos.renderStrings( + listOf( + "§eWith your current purse, you can buy order", + "§e${buyOrders.addSeparators()}x of this item with your purse (at top order +0.1)", + "§eOr ${buyInstant.addSeparators()}x with instant buy at the bazaar" + ), posLabel = "Max Items With Purse" + ) + } + + fun isEnabled(): Boolean { + return LorenzUtils.inSkyBlock && config.maxPurseItems + } +} -- cgit