diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
8 files changed, 334 insertions, 293 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/hoppity/EggFoundEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/hoppity/EggFoundEvent.kt new file mode 100644 index 000000000..2cd81811f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/hoppity/EggFoundEvent.kt @@ -0,0 +1,10 @@ +package at.hannibal2.skyhanni.events.hoppity + +import at.hannibal2.skyhanni.api.event.SkyHanniEvent +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType + +class EggFoundEvent( + val type: HoppityEggType, + val slotIndex: Int?, + val note: String?, +) : SkyHanniEvent() 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<String>() + 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) } /** @@ -60,6 +65,14 @@ object HoppityAPI { ) /** + * 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(?<amount>[\\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<String>() @@ -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,37 +39,13 @@ 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 (?<meal>\\w+) Egg §r§d(?<note>.*)§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(?<meal>.*) §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(?<meal>[\\w ]+) Rabbit §r§din the Chocolate Factory§r§d!", - ) - - val eggFoundPatterns: List<Pattern> = 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 = {} } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt index bd1fc8717..ccb6712c0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt @@ -57,7 +57,7 @@ object ChocolateFactoryBarnManager { } ChocolateAmount.addToAll(amount) HoppityEggsCompactChat.compactChat(event, lastDuplicateAmount = amount) - HoppityAPI.attemptFire(event, lastDuplicateAmount = amount) + HoppityAPI.attemptFireRabbitFound(lastDuplicateAmount = amount) } rabbitCrashedPattern.matchMatcher(event.message) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryStrayTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryStrayTracker.kt index 5c964c639..805d2c861 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryStrayTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryStrayTracker.kt @@ -1,24 +1,29 @@ package at.hannibal2.skyhanni.features.inventory.chocolatefactory -import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.api.event.HandleEvent +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.events.hoppity.EggFoundEvent import at.hannibal2.skyhanni.features.event.hoppity.HoppityAPI +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType import at.hannibal2.skyhanni.features.event.hoppity.HoppityEventSummary import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut +import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc import at.hannibal2.skyhanni.utils.DelayedRun 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.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzRarity +import at.hannibal2.skyhanni.utils.LorenzRarity.LEGENDARY import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.removeResets import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -26,8 +31,10 @@ import at.hannibal2.skyhanni.utils.renderables.Searchable import at.hannibal2.skyhanni.utils.renderables.toSearchable import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker import at.hannibal2.skyhanni.utils.tracker.TrackerData +import com.google.gson.JsonElement +import com.google.gson.JsonObject import com.google.gson.annotations.Expose -import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraft.inventory.Slot import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @@ -43,14 +50,14 @@ object ChocolateFactoryStrayTracker { * REGEX-TEST: §6§lGolden Rabbit §d§lCAUGHT! * REGEX-TEST: §fAudi §d§lCAUGHT! */ - private val strayCaughtPattern by ChocolateFactoryAPI.patternGroup.pattern( + val strayCaughtPattern by ChocolateFactoryAPI.patternGroup.pattern( "stray.caught", - "^§[a-f0-9].* §d§lCAUGHT!", + "^(?:§.)*(?<name>.*) §d§lCAUGHT!", ) /** * REGEX-TEST: §7You caught a stray §fMandy §7and §7gained §6+283,574 Chocolate§7! - * REGEX-TEST: §7You caught a stray §aSven §7and gained §7§6+397,004 Chocolate§7!' + * REGEX-TEST: §7You caught a stray §aSven §7and gained §7§6+397,004 Chocolate§7! */ private val strayLorePattern by ChocolateFactoryAPI.patternGroup.pattern( "stray.loreinfo", @@ -101,14 +108,6 @@ object ChocolateFactoryStrayTracker { "§7You caught a stray (?<color>§.)Fish the Rabbit§7! §7You have already found (?:§.)?Fish the (?:§.)?Rabbit§7, so you received §6(?<amount>[\\d,]*) (?:§6)?Chocolate§7!", ) - private val rarityFormatMap = mapOf( - "common" to "§f", - "uncommon" to "§a", - "rare" to "§9", - "epic" to "§5", - "legendary" to "§6", - ) - private val tracker = SkyHanniTracker("Stray Tracker", { Data() }, { it.chocolateFactory.strayTracker }) { drawDisplay(it) } @@ -120,10 +119,10 @@ object ChocolateFactoryStrayTracker { } @Expose - var straysCaught: MutableMap<String, Int> = mutableMapOf() + var straysCaught: MutableMap<LorenzRarity, Int> = mutableMapOf() @Expose - var straysExtraChocMs: MutableMap<String, Long> = mutableMapOf() + var straysExtraChocMs: MutableMap<LorenzRarity, Long> = mutableMapOf() @Expose var goldenTypesCaught: MutableMap<String, Int> = mutableMapOf() @@ -134,15 +133,12 @@ object ChocolateFactoryStrayTracker { return notEmptyLines.joinToString(" ") } - private fun incrementRarity(rarity: String, chocAmount: Long = 0) { + private fun incrementRarity(rarity: LorenzRarity, chocAmount: Long = 0) { tracker.modify { it.straysCaught.addOrPut(rarity, 1) } val extraTime = ChocolateFactoryAPI.timeUntilNeed(chocAmount + 1) tracker.modify { it.straysExtraChocMs.addOrPut(rarity, extraTime.inWholeMilliseconds) } - if (HoppityAPI.isHoppityEvent()) { - LorenzRarity.getByName(rarity)?.let { - HoppityEventSummary.addStrayCaught(it, chocAmount) - } - } + if (!HoppityAPI.isHoppityEvent()) return + HoppityEventSummary.addStrayCaught(rarity, chocAmount) } private fun incrementGoldenType(typeCaught: String, amount: Int = 1) { @@ -159,108 +155,100 @@ object ChocolateFactoryStrayTracker { tips = listOf("§a+§b${formattedExtraTime} §afrom strays§7"), ).toSearchable(), ) - rarityFormatMap.keys.forEach { rarity -> + HoppityAPI.hoppityRarities.forEach { rarity -> extractHoverableOfRarity(rarity, data)?.let { add(it) } } } - private fun extractHoverableOfRarity(rarity: String, data: Data): Searchable? { + private fun extractHoverableOfRarity(rarity: LorenzRarity, data: Data): Searchable? { val caughtOfRarity = data.straysCaught[rarity] val caughtString = caughtOfRarity?.toString() ?: return null val rarityExtraChocMs = data.straysExtraChocMs[rarity]?.milliseconds val extraChocFormat = rarityExtraChocMs?.format() ?: "" - val colorCode = rarityFormatMap[rarity] ?: "" - val lineHeader = "$colorCode${rarity.substring(0, 1).uppercase()}${rarity.substring(1)}§7: §r$colorCode" + val colorCode = rarity.chatColorCode + val lineHeader = "$colorCode${rarity.toString().lowercase().replaceFirstChar { it.uppercase() }}§7: §r$colorCode" val lineFormat = "${lineHeader}${caughtString}" val renderable = rarityExtraChocMs?.let { - val tip = - "§a+§b$extraChocFormat §afrom $colorCode$rarity strays§7${if (rarity == "legendary") extractGoldenTypesCaught(data) else ""}" + var tip = "§a+§b$extraChocFormat §afrom $colorCode${rarity.toString().lowercase()} strays§7" + if (rarity == LEGENDARY) tip += extractGoldenTypesCaught(data) Renderable.hoverTips(Renderable.string(lineFormat), tips = tip.split("\n")) } ?: Renderable.string(lineFormat) - return renderable.toSearchable(rarity) + return renderable.toSearchable(rarity.toString()) + } + + private val goldenTypesMap: Map<String, (Int, MutableList<String>) -> Unit> by lazy { + mapOf( + "sidedish" to { count, list -> list.add("§b$count §6Side ${StringUtils.pluralize(count, "Dish", "Dishes")}") }, + "jackpot" to { count, list -> list.add("§b$count §6Chocolate ${StringUtils.pluralize(count, "Jackpot")}") }, + "mountain" to { count, list -> list.add("§b$count §6Chocolate ${StringUtils.pluralize(count, "Mountain")}") }, + "dorado" to { count, list -> list.add("§b$count §6El Dorado ${StringUtils.pluralize(count, "Sighting")}") }, + "stampede" to { count, list -> list.add("§b$count §6${StringUtils.pluralize(count, "Stampede")}") }, + "goldenclick" to { count, list -> list.add("§b$count §6Golden ${StringUtils.pluralize(count, "Click")}") } + ) } private fun extractGoldenTypesCaught(data: Data): String { val goldenList = mutableListOf<String>() - data.goldenTypesCaught["sidedish"]?.let { - goldenList.add("§b$it §6Side Dish" + if (it > 1) "es" else "") + data.goldenTypesCaught.sortedDesc().forEach { (key, count) -> goldenTypesMap[key]?.invoke(count, goldenList) } + return if (goldenList.isEmpty()) "" else ("\n" + goldenList.joinToString("\n")) + } + + fun handleStrayClicked(slot: Slot) { + if (!isEnabled() || claimedStraysSlots.contains(slot.slotNumber)) return + + claimedStraysSlots.add(slot.slotIndex) + val loreLine = formLoreToSingleLine(slot.stack.getLore()) + + // "Base" strays - Common -> Epic, raw choc only reward. + strayLorePattern.matchMatcher(loreLine) { + //Pretty sure base strays max at Epic, but... + val rarity = HoppityAPI.rarityByRabbit(group("rabbit")) ?: return@matchMatcher + incrementRarity(rarity, group("amount").formatLong()) } - data.goldenTypesCaught["jackpot"]?.let { - goldenList.add("§b$it §6Chocolate Jackpot" + if (it > 1) "s" else "") + + // Fish the Rabbit + fishTheRabbitPattern.matchMatcher(loreLine) { + //Also fairly sure that Fish maxes out at Rare, but... + val rarity = HoppityAPI.rarityByRabbit(group("color")) ?: return@matchMatcher + incrementRarity(rarity, group("amount").formatLong()) } - data.goldenTypesCaught["mountain"]?.let { - goldenList.add("§b$it §6Chocolate Mountain" + if (it > 1) "s" else "") + + // Golden Strays, Jackpot and Mountain, raw choc only reward. + goldenStrayJackpotMountainPattern.matchMatcher(loreLine) { + val amount = group("amount").formatLong().also { am -> incrementRarity(LEGENDARY, am) } + val multiplier = amount / ChocolateFactoryAPI.chocolatePerSecond + when (multiplier) { + in 479.0..481.0 -> incrementGoldenType("jackpot") + in 1499.0..1501.0 -> incrementGoldenType("mountain") + } } - data.goldenTypesCaught["dorado"]?.let { - goldenList.add((if (it >= 3) "§a" else "§b") + "$it§7/§a3 §6El Dorado §7Sighting" + if (it > 1) "s" else "") + + // Golden Strays, "Golden Click" + goldenStrayClick.matchMatcher(loreLine) { + incrementGoldenType("goldenclick") } - data.goldenTypesCaught["stampede"]?.let { - goldenList.add("§b$it §6Stampede" + if (it > 1) "s" else "") + + // Golden Strays, hoard/stampede + strayHoardPattern.matchMatcher(loreLine.removeResets()) { + incrementGoldenType("stampede") } - data.goldenTypesCaught["goldenclick"]?.let { - goldenList.add("§b$it §6Golden Click" + if (it > 1) "s" else "") + + // El Dorado - all catches + strayDoradoPattern.matchMatcher(loreLine) { + groupOrNull("amount")?.let { amount -> + incrementRarity(LEGENDARY, amount.formatLong()) + } + incrementGoldenType("dorado") } - return if (goldenList.size == 0) "" else ("\n" + goldenList.joinToString("\n")) } @SubscribeEvent fun onTick(event: SecondPassedEvent) { if (!isEnabled()) return InventoryUtils.getItemsInOpenChest().filter { - !claimedStraysSlots.contains(it.slotIndex) - }.forEach { - strayCaughtPattern.matchMatcher(it.stack.name) { - if (it.stack.getLore().isEmpty()) return - claimedStraysSlots.add(it.slotIndex) - val loreLine = formLoreToSingleLine(it.stack.getLore()) - - // "Base" strays - Common -> Epic, raw choc only reward. - strayLorePattern.matchMatcher(loreLine) { - //Pretty sure base strays max at Epic, but... - val rarity = rarityFormatMap.entries.find { e -> e.value == group("rabbit").substring(0, 2) }?.key ?: "common" - incrementRarity(rarity, group("amount").formatLong()) - } - - // Fish the Rabbit - fishTheRabbitPattern.matchMatcher(loreLine) { - //Also fairly sure that Fish maxes out at Rare, but... - val rarity = rarityFormatMap.entries.find { e -> e.value == group("color").substring(0, 2) }?.key ?: "common" - incrementRarity(rarity, group("amount").formatLong()) - } - - // Golden Strays, Jackpot and Mountain, raw choc only reward. - goldenStrayJackpotMountainPattern.matchMatcher(loreLine) { - val amount = group("amount").formatLong().also { am -> incrementRarity("legendary", am) } - val multiplier = amount / ChocolateFactoryAPI.chocolatePerSecond - when (multiplier) { - in 479.0..481.0 -> incrementGoldenType("jackpot") - in 1499.0..1501.0 -> incrementGoldenType("mountain") - } - } - - // Golden Strays, "Golden Click" - goldenStrayClick.matchMatcher(loreLine) { - incrementGoldenType("goldenclick") - } - - // Golden Strays, hoard/stampede - strayHoardPattern.matchMatcher(loreLine.removeResets()) { - incrementGoldenType("stampede") - } - - // El Dorado - all catches - strayDoradoPattern.matchMatcher(loreLine) { - groupOrNull("amount")?.let { amount -> - incrementRarity("legendary", amount.formatLong()) - } - incrementGoldenType("dorado") - } - } - } - InventoryUtils.getItemsInOpenChest().filter { claimedStraysSlots.contains(it.slotIndex) }.forEach { if (!strayCaughtPattern.matches(it.stack.name)) { @@ -269,27 +257,17 @@ object ChocolateFactoryStrayTracker { } } - @SubscribeEvent(priority = EventPriority.HIGH) - fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { - val index = event.slot?.slotIndex ?: return - if (index == -999) return - if (claimedStraysSlots.contains(index)) 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) - if (!nameText.equals("§6§lGolden Rabbit §8- §aSide Dish")) return - - HoppityAPI.fireSideDishMessage() - if (!isEnabled()) return - - claimedStraysSlots.add(index) - incrementGoldenType("sidedish") - incrementRarity("legendary", 0) - DelayedRun.runDelayed(1.seconds) { - claimedStraysSlots.remove(claimedStraysSlots.indexOf(index)) + @HandleEvent + fun onEggFound(event: EggFoundEvent) { + if (!isEnabled() || event.type != HoppityEggType.SIDE_DISH) return + event.slotIndex?.let { + claimedStraysSlots.add(it) + DelayedRun.runDelayed(1.seconds) { + claimedStraysSlots.remove(claimedStraysSlots.indexOf(it)) + } } + incrementRarity(LEGENDARY, 0) + incrementGoldenType("sidedish") } @SubscribeEvent @@ -304,6 +282,32 @@ object ChocolateFactoryStrayTracker { tracker.firstUpdate() } + private fun <T> migrateJsonStringKeyToRarityKey(jElement: JsonElement, enumClass: Class<T>): JsonElement { + if (!jElement.isJsonObject) return jElement + val newElement = JsonObject() + + for ((key, value) in jElement.asJsonObject.entrySet()) { + val enum = try { + enumClass.javaClass.enumConstants.first { it.name.equals(key, ignoreCase = true) } + } catch (e: IllegalArgumentException) { + continue + } + value?.asInt?.let { newElement.addProperty(enum.toString(), it) } + } + + return newElement + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.transform(58, "chocolateFactory.strayTracker.straysCaught") { element -> + migrateJsonStringKeyToRarityKey(element, LorenzRarity::class.java) + } + event.transform(58, "chocolateFactory.strayTracker.straysExtraChocMs") { element -> + migrateJsonStringKeyToRarityKey(element, LorenzRarity::class.java) + } + } + fun resetCommand() { tracker.resetCommand() } |