From 67dd38b9d76eab01f0359b6c9d627618111be07f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:19:40 +0200 Subject: Improvement + Fix: Custom CF Reminder (#2334) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../ChocolateFactoryCustomReminder.kt | 61 ++++++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt index 1f7de017c..109db545c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt @@ -11,14 +11,20 @@ import at.hannibal2.skyhanni.utils.HypixelCommands 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.NumberUtil.formatLong +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat +import at.hannibal2.skyhanni.utils.RegexUtils.matchAll +import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.TimeUtils.minutes import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule @@ -43,11 +49,36 @@ object ChocolateFactoryCustomReminder { private var lastUpgradeWarning = SimpleTimeMark.farPast() + private val patternGroup = RepoPattern.group("inventory.chocolate.factory") + + /** + * REGEX-TEST: §cRequires 400B all-time Chocolate! + */ + private val milestoneCostLorePattern by patternGroup.pattern( + "milestone.cost", + "§cRequires (?.*) all-time Chocolate!", + ) + + /** + * REGEX-TEST: §cYou don't have enough Chocolate! + */ + private val chatMessagePattern by patternGroup.list( + "chat.hide", + "§cYou don't have enough Chocolate!", + "§cYou don't have the required items!", + "§cYou must collect (.*) all-time Chocolate!", + ) + @SubscribeEvent fun onChat(event: SystemMessageEvent) { if (!isEnabled()) return + if (!ChocolateFactoryAPI.inChocolateFactory) return if (configReminder.hideChat) { - if (event.message == "§cYou don't have enough Chocolate!") { + + if (chatMessagePattern.matches(event.message)) { + //§cYou don't have the required items! + //§cYou must collect 300B all-time Chocolate! +// if (event.message == "§cYou don't have enough Chocolate!") { event.blockedReason = "custom_reminder" } } @@ -64,17 +95,37 @@ object ChocolateFactoryCustomReminder { if (!isEnabled()) return val item = event.item ?: return if (event.clickedButton != 0) return - // TODO add support for prestige and for Chocolate Milestone - val cost = ChocolateFactoryAPI.getChocolateBuyCost(item.getLore()) ?: return + val (cost, name) = getCostAndName(item) ?: return val duration = ChocolateAmount.CURRENT.timeUntilGoal(cost) - val nextLevelName = ChocolateFactoryAPI.getNextLevelName(item) ?: return // the user has enough chocolate, and just bought something if (duration.isNegative()) { reset() return } - setReminder(cost, nextLevelName) + setReminder(cost, name) + } + + // TODO add support for prestige + private fun getCostAndName(item: ItemStack): Pair? { + val list = item.getLore() + val cost = ChocolateFactoryAPI.getChocolateBuyCost(list) + if (cost == null) { + milestoneCostLorePattern.matchAll(list) { + // math needed to get from "time until current chocolate" to "time until all time chocolate" + val amount = group("amount").formatLong() + val allTime = ChocolateAmount.ALL_TIME.chocolate() + val missingAllTime = amount - allTime + val current = ChocolateAmount.CURRENT.chocolate() + val missing = missingAllTime + current + + return missing to "§6${amount.shortFormat()} Chocolate Milestone" + } + return null + } + + val nextLevelName = ChocolateFactoryAPI.getNextLevelName(item) ?: item.name + return cost to nextLevelName } @SubscribeEvent -- cgit