From 196c1d5780f90386dc2b53282c1a3a1b6345a781 Mon Sep 17 00:00:00 2001 From: ILike2WatchMemes Date: Sat, 7 Sep 2024 21:20:17 +0200 Subject: Feature: Experiment Rewards compacting (#2209) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../skyhanni/config/features/chat/ChatConfig.java | 6 ++ .../features/chat/CompactExperimentRewards.kt | 103 +++++++++++++++++++++ .../features/inventory/SuperpairsClicksAlert.kt | 2 +- 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/chat/CompactExperimentRewards.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index 6a1d129a2..53f7aac94 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -89,6 +89,12 @@ public class ChatConfig { @FeatureToggle public boolean compactBestiaryMessage = true; + @Expose + @ConfigOption(name = "Compact Enchanting Rewards", desc = "Compact the rewards gained from Add-ons and Experiments in Experimentation Table, only showing additional information when hovering.") + @ConfigEditorBoolean + @FeatureToggle + public boolean compactExperimentationTable = false; + @Expose @ConfigOption(name = "Arachne Hider", desc = "Hide chat messages about the Arachne Fight while outside of §eArachne's Sanctuary§7.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactExperimentRewards.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactExperimentRewards.kt new file mode 100644 index 000000000..d1c2d2c46 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactExperimentRewards.kt @@ -0,0 +1,103 @@ +package at.hannibal2.skyhanni.features.chat + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds + +@SkyHanniModule +object CompactExperimentRewards { + + private val config get() = SkyHanniMod.feature.chat + + private var gainedRewards = mutableListOf() + private var lastTimeTableOpened = SimpleTimeMark.farPast() + private var currentMessage = "" + + private val patternGroup = RepoPattern.group("chat.experiments.compact") + + /** + * REGEX-TEST: Superpairs (Metaphysical) + * REGEX-TEST: Superpairs Rewards + */ + private val experimentInventoriesPattern by patternGroup.pattern( + "inventories", + "(?:Superpairs|Chronomatron|Ultrasequencer) (?:\\(.+\\)|➜ Stakes|Rewards)|Experimentation Table", + ) + + /** + * REGEX-TEST: §eYou claimed the §r§dUltrasequencer §r§erewards! + * REGEX-TEST: §eYou claimed the §r§cUltrasequencer §r§erewards! + */ + private val claimMessagePattern by patternGroup.pattern( + "message", + "(?§eYou claimed the §r§.\\S+ §r§erewards!)", + ) + + /** + * REGEX-TEST: §8 +§r§3600k Enchanting Exp + * REGEX-TEST: §r§8+§r§3132k Enchanting Exp + * REGEX-TEST: §r§8+§r§aThunderlord V + * REGEX-TEST: §r§8+§r§3143k Enchanting Exp + * REGEX-TEST: §r§8+§r§aGrand Experience Bottle + * REGEX-TEST: §r§8+§r§aCaster V + */ + private val experimentsDropPattern by patternGroup.pattern( + "drop", + "^(?:§8 \\+| §r§8\\+)(?.*)\$", + ) + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + if (isEnabled() && experimentInventoriesPattern.matches(InventoryUtils.openInventoryName())) { + lastTimeTableOpened = SimpleTimeMark.now() + } + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!isEnabled() || lastTimeTableOpened.passedSince() >= 3.seconds || event.blockedReason != "") return + + val message = event.message + claimMessagePattern.matchMatcher(message) { + currentMessage = group("message") + event.blockedReason = "COMPACT_REWARDS" + return + } + experimentsDropPattern.matchMatcher(message) { + val reward = group("reward") + + gainedRewards.add(reward) + event.blockedReason = "COMPACT_REWARDS" + + DelayedRun.runDelayed(100.milliseconds) { + sendMessage(reward) + } + } + } + + private fun sendMessage(reward: String?) { + if (gainedRewards.last() != reward || currentMessage == "") return + + val expList = mutableListOf().apply { + gainedRewards.forEach { add("§8+$it") } + } + + ChatUtils.hoverableChat(currentMessage, expList, null, false) + gainedRewards.clear() + currentMessage = "" + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.compactExperimentationTable +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperpairsClicksAlert.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperpairsClicksAlert.kt index 5c5011c85..8e3c12679 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperpairsClicksAlert.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperpairsClicksAlert.kt @@ -19,7 +19,7 @@ object SuperpairsClicksAlert { private var roundsNeeded = -1 private val roundsNeededRegex = Regex("""(?:Chain|Series) of (\d+):""") private val currentRoundRegex = Regex("""Round: (\d+)""") - private val targetInventoryNames = arrayOf("Chronomatron", "Ultrasequencer") + private val targetInventoryNames = arrayOf("Chronomatron", "c") @SubscribeEvent fun onInventoryOpen(event: InventoryOpenEvent) { -- cgit