From e0f3a5e3f5e1c0361d3f96ede45d7fe069d072d6 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Fri, 14 Jun 2024 20:54:21 -0400 Subject: Fix: Compact Hoppity Chat for Purchased Rabbits (#2100) --- .../event/hoppity/HoppityEggsCompactChat.kt | 24 +++++++++++++++++++--- .../features/event/hoppity/HoppityEggsManager.kt | 9 ++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt index a0a42c767..9420676d5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt @@ -23,6 +23,7 @@ object HoppityEggsCompactChat { private var newRabbit = false private var lastChatMeal: HoppityEggType? = null private var lastDuplicateAmount: Long? = null + private var rabbitBought = false private val config get() = ChocolateFactoryAPI.config fun compactChat(event: LorenzChatEvent, lastDuplicateAmount: Long? = null) { @@ -58,21 +59,23 @@ object HoppityEggsCompactChat { this.lastProfit = "" this.lastChatMeal = null this.lastDuplicateAmount = null + this.rabbitBought = false } private fun createCompactMessage(): String { val mealName = lastChatMeal?.coloredName ?: "" + val mealNameFormatted = if (rabbitBought) "§aBought Rabbit" else "$mealName Egg" return if (duplicate) { - val format = lastDuplicateAmount?.let { it.shortFormat() } ?: "?" + val format = lastDuplicateAmount?.shortFormat() ?: "?" val timeFormatted = lastDuplicateAmount?.let { ChocolateFactoryAPI.timeUntilNeed(it).format(maxUnits = 2) } ?: "?" val timeStr = if (config.showDuplicateTime) ", §a+§b$timeFormatted§7" else "" - "$mealName Egg! §7Duplicate $lastName §7(§6+$format Chocolate§7$timeStr)" + "$mealNameFormatted! §7Duplicate $lastName §7(§6+$format Chocolate§7$timeStr)" } else if (newRabbit) { - "$mealName Egg! §d§lNEW $lastName §7(${lastProfit}§7)" + "$mealNameFormatted! §d§lNEW $lastName §7(${lastProfit}§7)" } else "?" } @@ -83,11 +86,26 @@ object HoppityEggsCompactChat { compactChat(event) } + HoppityEggsManager.eggBoughtPattern.matchMatcher(event.message) { + rabbitBought = true + compactChat(event) + } + HoppityEggsManager.rabbitFoundPattern.matchMatcher(event.message) { + // The only case where "You found ..." will come in with more than 1 message, + // or empty for hoppityEggChat, is where the rabbit was purchased from hoppity + // in this case, we want to reset variables to a clean state during this capture, + // as the important capture for the purchased message is the final message in + // the chain; "You found [rabbit]" -> "Dupe/New Rabbit" -> "You bought [rabbit]" + if (hoppityEggChat.isEmpty() || hoppityEggChat.size > 1) { + resetCompactData() + } + lastName = group("name") lastRarity = group("rarity") compactChat(event) } + HoppityEggsManager.newRabbitFound.matchMatcher(event.message) { val chocolate = groupOrNull("chocolate") val perSecond = group("perSecond") diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt index 800167460..0640bfff2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt @@ -44,6 +44,15 @@ object HoppityEggsManager { "§d§lHOPPITY'S HUNT §r§dYou found a §r§.Chocolate (?\\w+) Egg §r§d(?.*)§r§d!" ) + /** + * REGEX-TEST: §aYou bought §r§9Casanova §r§afor §r§6970,000 Coins§r§a! + * REGEX-TEST: §aYou bought §r§fHeidie §r§afor §r§6194,000 Coins§r§a! + */ + val eggBoughtPattern by ChocolateFactoryAPI.patternGroup.pattern( + "egg.bought", + "§aYou bought §r§.(?.*?) §r§afor §r§6((\\d|,)*) Coins§r§a!" + ) + /** * REGEX-TEST: §D§LHOPPITY'S HUNT §7You found §fArnie §7(§F§LCOMMON§7)! * REGEX-TEST: §D§LHOPPITY'S HUNT §7You found §aPenelope §7(§A§LUNCOMMON§7)! -- cgit