From a267da2c57fdc765a540540505db8c9c6ed66231 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:44:00 -0400 Subject: Fixes & Improvements: Hoppity Rework (#2488) --- .../skyhanni/features/event/hoppity/HoppityAPI.kt | 141 +++++++++++---------- .../features/event/hoppity/HoppityEggLocator.kt | 11 +- .../features/event/hoppity/HoppityEggType.kt | 4 +- .../event/hoppity/HoppityEggsCompactChat.kt | 138 ++++++++++++-------- .../features/event/hoppity/HoppityEggsManager.kt | 91 ++++++------- 5 files changed, 206 insertions(+), 179 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/event') diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityAPI.kt index 5c63fe3a8..6c42f8a17 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityAPI.kt @@ -3,50 +3,55 @@ package at.hannibal2.skyhanni.features.event.hoppity import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.events.hoppity.EggFoundEvent import at.hannibal2.skyhanni.events.hoppity.RabbitFoundEvent +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager.eggFoundPattern import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager.getEggType +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.SIDE_DISH +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.CHOCOLATE_SHOP_MILESTONE +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.CHOCOLATE_FACTORY_MILESTONE import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI +import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStrayTracker import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzRarity import at.hannibal2.skyhanni.utils.LorenzRarity.DIVINE +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getMinecraftId import at.hannibal2.skyhanni.utils.SkyblockSeason -import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule object HoppityAPI { - private var hoppityEggChat = mutableListOf() + private var messageCount = 0 private var duplicate = false private var lastRarity = "" private var lastName = "" private var newRabbit = false - private var lastChatMeal: HoppityEggType? = null + private var lastMeal: HoppityEggType? = null private var lastDuplicateAmount: Long? = null - private var rabbitBought = false val hoppityRarities by lazy { LorenzRarity.entries.filter { it <= DIVINE } } - private fun resetChatData() { - this.hoppityEggChat = mutableListOf() + private fun resetRabbitData() { + this.messageCount = 0 this.duplicate = false this.newRabbit = false this.lastRarity = "" this.lastName = "" - this.lastChatMeal = null + this.lastMeal = null this.lastDuplicateAmount = null - this.rabbitBought = false } fun isHoppityEvent() = (SkyblockSeason.currentSeason == SkyblockSeason.SPRING || SkyHanniMod.feature.dev.debug.alwaysHoppitys) - fun rarityByRabbit(rabbit: String): LorenzRarity? = hoppityRarities.firstOrNull { it.chatColorCode == rabbit.substring(0, 2) } /** @@ -59,6 +64,14 @@ object HoppityAPI { "(?:§.)*?(?\\d{1,2})[a-z]{2} Chocolate Milestone", ) + /** + * REGEX-TEST: §6§lGolden Rabbit §8- §aSide Dish + */ + private val sideDishNamePattern by ChocolateFactoryAPI.patternGroup.pattern( + "rabbit.sidedish", + "(?:§.)*?Golden Rabbit (?:§.)?- (?:§.)?Side Dish" + ) + /** * REGEX-TEST: §7Reach §6300B Chocolate §7all-time to * REGEX-TEST: §7Reach §61k Chocolate §7all-time to unlock @@ -77,99 +90,99 @@ object HoppityAPI { "§7Spend §6(?[\\d.MBk]*) Chocolate §7in.*", ) - fun fireSideDishMessage() { - LorenzChatEvent( - "§d§lHOPPITY'S HUNT §r§dYou found a §r§6§lSide Dish §r§6Egg §r§din the Chocolate Factory§r§d!", - ChatComponentText(""), - ).postAndCatch() + @SubscribeEvent(priority = EventPriority.HIGH) + fun onTick(event: SecondPassedEvent) { + if (!ChocolateFactoryAPI.inChocolateFactory) return + InventoryUtils.getItemsInOpenChest().filter { + it.stack.hasDisplayName() && + it.stack.getMinecraftId().toString() == "minecraft:skull" && + it.stack.getLore().isNotEmpty() + }.forEach { + ChocolateFactoryStrayTracker.strayCaughtPattern.matchMatcher(it.stack.displayName) { + ChocolateFactoryStrayTracker.handleStrayClicked(it) + when(groupOrNull("name") ?: return@matchMatcher) { + "Fish the Rabbit" -> EggFoundEvent(HoppityEggType.STRAY, it.slotNumber, null).post() + "El Dorado" -> EggFoundEvent(HoppityEggType.STRAY, it.slotNumber, null).post() + else -> return@matchMatcher + } + } + } } @SubscribeEvent(priority = EventPriority.HIGH) fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { - val index = event.slot?.slotIndex ?: return - if (index == -999) return + val index = event.slot?.slotIndex?.takeIf { it != -999 } ?: return val clickedStack = InventoryUtils.getItemsInOpenChest() .find { it.slotNumber == event.slot.slotNumber && it.hasStack } ?.stack ?: return val nameText = (if (clickedStack.hasDisplayName()) clickedStack.displayName else clickedStack.itemName) + sideDishNamePattern.matchMatcher(nameText) { + EggFoundEvent(SIDE_DISH, index, null).post() + lastMeal = SIDE_DISH + attemptFireRabbitFound() + } milestoneNamePattern.matchMatcher(nameText) { - val itemLore = clickedStack.getLore() - if (!itemLore.any { it == "§eClick to claim!" }) return - - // Will never match both all time and shop patterns together - allTimeLorePattern.firstMatcher(clickedStack.getLore()) { - LorenzChatEvent( - "§d§lHOPPITY'S HUNT §r§dYou claimed a §r§6§lChocolate Milestone Rabbit §r§din the Chocolate Factory§r§d!", - ChatComponentText(""), - ).postAndCatch() - } - - shopLorePattern.firstMatcher(clickedStack.getLore()) { - LorenzChatEvent( - "§d§lHOPPITY'S HUNT §r§dYou claimed a §r§6§lShop Milestone Rabbit §r§din the Chocolate Factory§r§d!", - ChatComponentText(""), - ).postAndCatch() + clickedStack.getLore().let { + if (!it.any { line -> line == "§eClick to claim!" }) return + allTimeLorePattern.firstMatcher(it) { + EggFoundEvent(CHOCOLATE_FACTORY_MILESTONE, index, null).post() + lastMeal = CHOCOLATE_FACTORY_MILESTONE + attemptFireRabbitFound() + } + shopLorePattern.firstMatcher(it) { + EggFoundEvent(CHOCOLATE_SHOP_MILESTONE, index, null).post() + lastMeal = CHOCOLATE_SHOP_MILESTONE + attemptFireRabbitFound() + } } } } - // Dumbed down version of the Compact Chat for Hoppity's, - // with the additional native context of side dishes - fun handleChat(event: LorenzChatEvent) { - HoppityEggsManager.eggFoundPatterns.forEach { - it.matchMatcher(event.message) { - resetChatData() - lastChatMeal = getEggType(event) - attemptFire(event) - } + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyBlock) return + eggFoundPattern.matchMatcher(event.message) { + resetRabbitData() + lastMeal = getEggType(event) + lastMeal?.let { EggFoundEvent(it, null, groupOrNull("note")).post() } + attemptFireRabbitFound() } HoppityEggsManager.eggBoughtPattern.matchMatcher(event.message) { if (group("rabbitname").equals(lastName)) { - rabbitBought = true - lastChatMeal = HoppityEggType.BOUGHT - attemptFire(event) + lastMeal = HoppityEggType.BOUGHT + EggFoundEvent(HoppityEggType.BOUGHT, null, null).post() + attemptFireRabbitFound() } } HoppityEggsManager.rabbitFoundPattern.matchMatcher(event.message) { - // The only cases where "You found ..." will come in with more than 1 message, - // or empty for hoppityEggChat, is where the rabbit was purchased from hoppity, - // In the case of buying, 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)) { - resetChatData() - } - lastName = group("name") lastRarity = group("rarity") - attemptFire(event) + attemptFireRabbitFound() } HoppityEggsManager.newRabbitFound.matchMatcher(event.message) { newRabbit = true groupOrNull("other")?.let { - attemptFire(event) + attemptFireRabbitFound() return } - attemptFire(event) + attemptFireRabbitFound() } } - fun attemptFire(event: LorenzChatEvent, lastDuplicateAmount: Long? = null) { + fun attemptFireRabbitFound(lastDuplicateAmount: Long? = null) { lastDuplicateAmount?.let { this.lastDuplicateAmount = it - } - hoppityEggChat.add(event.message) - if (lastDuplicateAmount != null) { this.duplicate = true } - val lastChatMeal = lastChatMeal ?: return - if (hoppityEggChat.size == 3) { - RabbitFoundEvent(lastChatMeal, duplicate, lastName, lastDuplicateAmount ?: 0).post() - } + messageCount++ + val lastChatMeal = lastMeal ?: return + if (messageCount != 3) return + RabbitFoundEvent(lastChatMeal, duplicate, lastName, lastDuplicateAmount ?: 0).post() + resetRabbitData() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocator.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocator.kt index 0d5bfefa8..8e9e68e16 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocator.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.event.hoppity +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.data.ClickType import at.hannibal2.skyhanni.data.IslandGraphs import at.hannibal2.skyhanni.events.DebugDataCollectEvent @@ -8,6 +9,7 @@ import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.ReceiveParticleEvent +import at.hannibal2.skyhanni.events.hoppity.EggFoundEvent import at.hannibal2.skyhanni.features.fame.ReminderUtils import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -59,6 +61,11 @@ object HoppityEggLocator { var currentEggType: HoppityEggType? = null var currentEggNote: String? = null + @HandleEvent + fun onEggFound(event: EggFoundEvent) { + if (event.type.isResetting) resetData() + } + @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { resetData() @@ -168,10 +175,6 @@ object HoppityEggLocator { private fun shouldShowAllEggs() = config.showAllWaypoints && !locatorInHotbar && HoppityEggType.eggsRemaining() - fun eggFound() { - resetData() - } - @SubscribeEvent fun onReceiveParticle(event: ReceiveParticleEvent) { if (!isEnabled()) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggType.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggType.kt index 23e00cf88..5371816e1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggType.kt @@ -17,7 +17,8 @@ enum class HoppityEggType( SIDE_DISH("Side Dish", "§6§l", -1), BOUGHT("Bought", "§a", -1), CHOCOLATE_SHOP_MILESTONE("Shop Milestone", "§6", -1), - CHOCOLATE_FACTORY_MILESTONE("Chocolate Milestone", "§6", -1) + CHOCOLATE_FACTORY_MILESTONE("Chocolate Milestone", "§6", -1), + STRAY("Stray Rabbit", "§a", -1) ; fun timeUntil(): Duration { @@ -39,6 +40,7 @@ enum class HoppityEggType( } fun isClaimed() = claimed + val isResetting get() = resettingEntries.contains(this) val formattedName get() = "${if (isClaimed()) "§7§m" else mealColor}$mealName:$mealColor" val coloredName get() = "$mealColor$mealName" 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 6bc1c8dfc..abbdff1f0 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 @@ -1,25 +1,34 @@ package at.hannibal2.skyhanni.features.event.hoppity +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.features.event.hoppity.HoppityEggsConfig import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.hoppity.EggFoundEvent +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.BOUGHT import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.CHOCOLATE_FACTORY_MILESTONE import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.CHOCOLATE_SHOP_MILESTONE import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.SIDE_DISH -import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager.eggFoundPatterns +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.STRAY +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager.eggFoundPattern import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager.getEggType import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow import at.hannibal2.skyhanni.utils.TimeUtils.format +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds typealias RarityType = HoppityEggsConfig.CompactRarityTypes +@SkyHanniModule object HoppityEggsCompactChat { private var hoppityEggChat = mutableListOf() @@ -30,31 +39,32 @@ 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 + private val eventConfig get() = SkyHanniMod.feature.event.hoppityEggs - fun compactChat(event: LorenzChatEvent, lastDuplicateAmount: Long? = null) { + fun compactChat(event: LorenzChatEvent? = null, lastDuplicateAmount: Long? = null) { + if (!HoppityEggsManager.config.compactChat) return lastDuplicateAmount?.let { this.lastDuplicateAmount = it - } - if (!HoppityEggsManager.config.compactChat) return - event.blockedReason = "compact_hoppity" - hoppityEggChat.add(event.message) - if (lastDuplicateAmount != null) { this.duplicate = true } - if (hoppityEggChat.size == 3) { - DelayedRun.runDelayed(200.milliseconds) { - sendCompact() - } + event?.let { + it.blockedReason = "compact_hoppity" + hoppityEggChat.add(it.message) } + if (hoppityEggChat.size == 3) sendCompact() } private fun sendCompact() { - if (hoppityEggChat.isNotEmpty()) { + if (lastChatMeal.let { HoppityEggType.resettingEntries.contains(it) } && eventConfig.sharedWaypoints) { + DelayedRun.runDelayed(5.milliseconds) { + clickableCompact(HoppityEggsManager.getAndDisposeWaypointOnclick()) + resetCompactData() + } + } else { ChatUtils.hoverableChat(createCompactMessage(), hover = hoppityEggChat, prefix = false) + resetCompactData() } - resetCompactData() } private fun resetCompactData() { @@ -66,15 +76,16 @@ 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 if (lastChatMeal == SIDE_DISH) "§6§lSide Dish §r§6Egg" - else if (lastChatMeal == CHOCOLATE_SHOP_MILESTONE || lastChatMeal == CHOCOLATE_FACTORY_MILESTONE) "§6§lMilestone Rabbit" - else "$mealName Egg" + val mealNameFormat = when (lastChatMeal) { + BOUGHT -> "§aBought Rabbit" + SIDE_DISH -> "§6§lSide Dish §r§6Egg" + CHOCOLATE_SHOP_MILESTONE, CHOCOLATE_FACTORY_MILESTONE -> "§6§lMilestone Rabbit" + STRAY -> "§aStray Rabbit" + else -> "${lastChatMeal?.coloredName ?: ""} Egg" + } val rarityConfig = HoppityEggsManager.config.rarityInCompact return if (duplicate) { @@ -85,39 +96,72 @@ object HoppityEggsCompactChat { val showDupeRarity = rarityConfig.let { it == RarityType.BOTH || it == RarityType.DUPE } val timeStr = if (config.showDuplicateTime) ", §a+§b$timeFormatted§7" else "" - "$mealNameFormatted! §7Duplicate ${if (showDupeRarity) "$lastRarity " else ""}$lastName §7(§6+$format Chocolate§7$timeStr)" + "$mealNameFormat! §7Duplicate ${if (showDupeRarity) "$lastRarity " else ""}$lastName §7(§6+$format Chocolate§7$timeStr)" } else if (newRabbit) { val showNewRarity = rarityConfig.let { it == RarityType.BOTH || it == RarityType.NEW } - "$mealNameFormatted! §d§lNEW ${if (showNewRarity) "$lastRarity " else ""}$lastName §7(${lastProfit}§7)" + "$mealNameFormat! §d§lNEW ${if (showNewRarity) "$lastRarity " else ""}$lastName §7(${lastProfit}§7)" } else "?" } - fun handleChat(event: LorenzChatEvent) { - eggFoundPatterns.forEach { - it.matchMatcher(event.message) { - resetCompactData() - lastChatMeal = getEggType(event) - compactChat(event) - } + private fun clickableCompact(onClick: () -> Unit) { + val hover = hoppityEggChat.joinToString("\n") + " \n§eClick here to share the location of this chocolate egg with the server!" + hoppityEggChat.clear() + ChatUtils.clickableChat( + createCompactMessage(), + hover = hover, + onClick = onClick, + expireAt = 30.seconds.fromNow(), + oneTimeClick = true, + prefix = false, + ) + } + + @HandleEvent + fun onEggFound(event: EggFoundEvent) { + if (!HoppityEggsManager.config.compactChat || HoppityEggType.resettingEntries.contains(event.type) || event.type == BOUGHT) return + lastChatMeal = event.type + hoppityEggChat.add( + when (event.type) { + SIDE_DISH -> + "§d§lHOPPITY'S HUNT §r§dYou found a §r§6§lSide Dish §r§6Egg §r§din the Chocolate Factory§r§d!" + + CHOCOLATE_FACTORY_MILESTONE -> + "§d§lHOPPITY'S HUNT §r§dYou claimed a §r§6§lChocolate Milestone Rabbit §r§din the Chocolate Factory§r§d!" + + CHOCOLATE_SHOP_MILESTONE -> + "§d§lHOPPITY'S HUNT §r§dYou claimed a §r§6§lShop Milestone Rabbit §r§din the Chocolate Factory§r§d!" + + STRAY -> { + "§d§lHOPPITY'S HUNT §r§dYou found a §r§aStray Rabbit§r§d!".also { + // If it was an El Dorado dupe stray, we don't want hanging data + DelayedRun.runDelayed(300.milliseconds) { resetCompactData() } + } + } + + else -> + "§d§lHOPPITY'S HUNT §r§7Unknown Egg Type?" + }, + ) + if (hoppityEggChat.size == 3) sendCompact() + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyBlock) return + eggFoundPattern.matchMatcher(event.message) { + resetCompactData() + lastChatMeal = getEggType(event) + compactChat(event) } HoppityEggsManager.eggBoughtPattern.matchMatcher(event.message) { if (group("rabbitname").equals(lastName)) { - rabbitBought = true + lastChatMeal = BOUGHT compactChat(event) } } HoppityEggsManager.rabbitFoundPattern.matchMatcher(event.message) { - // The only cases where "You found ..." will come in with more than 1 message, - // or empty for hoppityEggChat, is where the rabbit was purchased from hoppity, - // In the case of buying, 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) @@ -138,20 +182,4 @@ object HoppityEggsCompactChat { compactChat(event) } } - - fun clickableCompact(onClick: () -> Unit): Boolean = if (hoppityEggChat.isNotEmpty() && !rabbitBought && lastChatMeal != null && - HoppityEggType.resettingEntries.contains(lastChatMeal) - ) { - val hover = hoppityEggChat.joinToString("\n") + " \n§eClick here to share the location of this chocolate egg with the server!" - hoppityEggChat.clear() - ChatUtils.clickableChat( - createCompactMessage(), - hover = hover, - onClick = onClick, - expireAt = 30.seconds.fromNow(), - oneTimeClick = true, - prefix = false, - ) - true - } else false } 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 bec966128..75b65fdc4 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 @@ -1,10 +1,13 @@ package at.hannibal2.skyhanni.features.event.hoppity import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.events.hoppity.EggFoundEvent +import at.hannibal2.skyhanni.events.hoppity.RabbitFoundEvent import at.hannibal2.skyhanni.features.fame.ReminderUtils import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -21,11 +24,9 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.now import at.hannibal2.skyhanni.utils.SkyBlockTime import at.hannibal2.skyhanni.utils.SoundUtils -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils.format import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Matcher -import java.util.regex.Pattern import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -38,36 +39,12 @@ object HoppityEggsManager { * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou found a §r§9Chocolate Lunch Egg §r§don a ledge next to the stairs up§r§d! * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou found a §r§aChocolate Dinner Egg §r§dbehind Emissary Sisko§r§d! * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou found a §r§9Chocolate Lunch Egg §r§dnear the Diamond Essence Shop§r§d! - * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou found a §r§6§lSide Dish §r§6Egg §r§din the Chocolate Factory§r§d! */ - private val eggFoundPattern by ChocolateFactoryAPI.patternGroup.pattern( + val eggFoundPattern by ChocolateFactoryAPI.patternGroup.pattern( "egg.found", "§d§lHOPPITY'S HUNT §r§dYou found a §r§.Chocolate (?\\w+) Egg §r§d(?.*)§r§d!", ) - /** - * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou found a §r§6§lSide Dish §r§6Egg §r§din the Chocolate Factory§r§d! - */ - private val sideDishEggFoundPattern by ChocolateFactoryAPI.patternGroup.pattern( - "sidedish.found", - "§d§lHOPPITY'S HUNT §r§dYou found a §r§6§l(?.*) §r§6Egg §r§din the Chocolate Factory§r§d!", - ) - - /** - * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou claimed a §r§6§lShop Milestone Rabbit §r§din the Chocolate Factory§r§d! - * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou claimed a §r§6§lChocolate Milestone Rabbit §r§din the Chocolate Factory§r§d! - */ - private val milestoneRabbitFoundPattern by ChocolateFactoryAPI.patternGroup.pattern( - "milestone.claimed", - "§d§lHOPPITY'S HUNT §r§dYou claimed a §r§6§l(?[\\w ]+) Rabbit §r§din the Chocolate Factory§r§d!", - ) - - val eggFoundPatterns: List = listOf( - eggFoundPattern, - sideDishEggFoundPattern, - milestoneRabbitFoundPattern, - ) - /** * 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! @@ -126,12 +103,28 @@ object HoppityEggsManager { private var warningActive = false private var lastWarnTime = SimpleTimeMark.farPast() + private var latestWaypointOnclick: () -> Unit = {} + @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { lastMeal = null lastNote = null } + @HandleEvent + fun onEggFound(event: EggFoundEvent) { + if (!HoppityAPI.isHoppityEvent() || !event.type.isResetting) return + HoppityEggLocations.saveNearestEgg() + event.type.markClaimed() + lastMeal = event.type + lastNote = event.note + } + + @HandleEvent + fun onRabbitFound(event: RabbitFoundEvent) { + HoppityCollectionStats.incrementRabbit(event.rabbitName) + } + @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!LorenzUtils.inSkyBlock) return @@ -147,22 +140,8 @@ object HoppityEggsManager { return } - HoppityEggsCompactChat.handleChat(event) - HoppityAPI.handleChat(event) - if (!HoppityAPI.isHoppityEvent()) return - eggFoundPattern.matchMatcher(event.message) { - HoppityEggLocations.saveNearestEgg() - HoppityEggLocator.eggFound() - val meal = getEggType(event) - val note = group("note").removeColor() - meal.markClaimed() - lastMeal = meal - lastNote = note - return - } - noEggsLeftPattern.matchMatcher(event.message) { HoppityEggType.allFound() @@ -188,10 +167,6 @@ object HoppityEggsManager { getEggType(event).markSpawned() return } - - rabbitFoundPattern.matchMatcher(event.message) { - HoppityCollectionStats.incrementRabbit(group("name")) - } } internal fun Matcher.getEggType(event: LorenzChatEvent): HoppityEggType = @@ -202,6 +177,12 @@ object HoppityEggsManager { ) } + fun getAndDisposeWaypointOnclick(): () -> Unit { + val onClick = latestWaypointOnclick + latestWaypointOnclick = {} + return onClick + } + fun shareWaypointPrompt() { if (!config.sharedWaypoints) return val meal = lastMeal ?: return @@ -211,16 +192,16 @@ object HoppityEggsManager { val currentLocation = LocationUtils.playerLocation() DelayedRun.runNextTick { - val onClick = { HoppityEggsShared.shareNearbyEggLocation(currentLocation, meal, note) } - if (!HoppityEggsCompactChat.clickableCompact(onClick)) { - ChatUtils.clickableChat( - "Click here to share the location of this chocolate egg with the server!", - onClick = onClick, - "§eClick to share!", - expireAt = 30.seconds.fromNow(), - oneTimeClick = true, - ) - } + latestWaypointOnclick = { HoppityEggsShared.shareNearbyEggLocation(currentLocation, meal, note) } + if (config.compactChat) return@runNextTick + ChatUtils.clickableChat( + "Click here to share the location of this chocolate egg with the server!", + onClick = latestWaypointOnclick, + "§eClick to share!", + expireAt = 30.seconds.fromNow(), + oneTimeClick = true, + ) + latestWaypointOnclick = {} } } -- cgit