From 21f92de676710c0c39d37056dada80af8266a9ba Mon Sep 17 00:00:00 2001 From: raaaaaven <168305416+raaaaaven@users.noreply.github.com> Date: Wed, 29 May 2024 21:44:20 +0100 Subject: Feature: Added ULTRA RARE Book Notification. (#1738) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: raven Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../skyhanni/config/ConfigUpdaterMigrator.kt | 2 +- .../features/inventory/helper/HelperConfig.java | 20 ++++ .../skyhanni/config/features/misc/MiscConfig.java | 6 -- .../features/inventory/SuperpairsClicksAlert.kt | 68 ++++++++++++++ .../features/inventory/UltraRareBookAlert.kt | 102 +++++++++++++++++++++ .../features/misc/SuperpairsClicksAlert.kt | 62 ------------- 7 files changed, 194 insertions(+), 70 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/SuperpairsClicksAlert.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/SuperpairsClicksAlert.kt (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index c8a4c04dc..0374024e0 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -275,6 +275,8 @@ import at.hannibal2.skyhanni.features.inventory.ShiftClickNPCSell import at.hannibal2.skyhanni.features.inventory.SkyblockGuideHighlightFeature import at.hannibal2.skyhanni.features.inventory.StatsTuning import at.hannibal2.skyhanni.features.inventory.SuperCraftFeatures +import at.hannibal2.skyhanni.features.inventory.SuperpairsClicksAlert +import at.hannibal2.skyhanni.features.inventory.UltraRareBookAlert import at.hannibal2.skyhanni.features.inventory.auctionhouse.AuctionHouseCopyUnderbidPrice import at.hannibal2.skyhanni.features.inventory.auctionhouse.AuctionHouseOpenPriceWebsite import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi @@ -362,7 +364,6 @@ import at.hannibal2.skyhanni.features.misc.ReplaceRomanNumerals import at.hannibal2.skyhanni.features.misc.RestorePieceOfWizardPortalLore import at.hannibal2.skyhanni.features.misc.ServerRestartTitle import at.hannibal2.skyhanni.features.misc.SkyBlockKickDuration -import at.hannibal2.skyhanni.features.misc.SuperpairsClicksAlert import at.hannibal2.skyhanni.features.misc.TabWidgetSettings import at.hannibal2.skyhanni.features.misc.TimeFeatures import at.hannibal2.skyhanni.features.misc.TpsCounter @@ -888,6 +889,7 @@ class SkyHanniMod { loadModule(Translator()) loadModule(CosmeticFollowingLine()) loadModule(SuperpairsClicksAlert()) + loadModule(UltraRareBookAlert) loadModule(PowderTracker) loadModule(ModifyVisualWords) loadModule(TabListReader) diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index fadaec07f..b44153e79 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 45 + const val CONFIG_VERSION = 46 fun JsonElement.at(chain: List, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java index 0960c46b5..e117004a4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java @@ -51,4 +51,24 @@ public class HelperConfig { @ConfigOption(name = "Tia Relay Abiphone Network Maintenance", desc = "") @Accordion public TiaRelayConfig tiaRelay = new TiaRelayConfig(); + + @Expose + @ConfigOption(name = "Enchanting", desc = "") + @Accordion + public EnchantingConfig enchanting = new EnchantingConfig(); + + public static class EnchantingConfig { + @Expose + @ConfigOption(name = "Superpairs Clicks Alert", desc = "Display an alert when you reach the maximum clicks gained from Chronomatron or Ultrasequencer.") + @ConfigEditorBoolean + @FeatureToggle + public boolean superpairsClicksAlert = false; + + @Expose + @ConfigOption(name = "ULTRA-RARE Book Alert", desc = "Sends a chat message, title and sound when you find an ULTRA-RARE book.") + @ConfigEditorBoolean + @FeatureToggle + public boolean ultraRareBookAlert = false; + } + } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java index 6e4fe4f12..1921d64b3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java @@ -198,12 +198,6 @@ public class MiscConfig { @FeatureToggle public boolean accountUpgradeReminder = true; - @Expose - @ConfigOption(name = "Superpairs Clicks Alert", desc = "Display an alert when you reach the maximum clicks gained from Chronomatron or Ultrasequencer.") - @ConfigEditorBoolean - @FeatureToggle - public boolean superpairsClicksAlert = false; - @Expose @ConfigOption(name = "NEU Heavy Pearls", desc = "Fixing NEU Heavy Pearl detection.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperpairsClicksAlert.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperpairsClicksAlert.kt new file mode 100644 index 000000000..e9c8a717b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperpairsClicksAlert.kt @@ -0,0 +1,68 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class SuperpairsClicksAlert { + + private val config get() = SkyHanniMod.feature.inventory.helper.enchanting + + private var roundsNeeded = -1 + private val roundsNeededRegex = Regex("""(?:Chain|Series) of (\d+):""") + private val currentRoundRegex = Regex("""Round: (\d+)""") + private val targetInventoryNames = arrayOf("Chronomatron", "Ultrasequencer") + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + if (!config.superpairsClicksAlert) return + if (!targetInventoryNames.any { event.inventoryName.contains(it) }) return + + // player may have drank Metaphysical Serum which reduces clicks needed by up to 3, so need to parse it + for (i in 24 downTo 20) { + val lore = event.inventoryItems[i]?.getLore() ?: continue + if (lore.any { it.contains("Practice mode has no rewards") }) { + roundsNeeded = -1 + break + } + if (lore.any { it.contains("Enchanting level too low!") || it.contains("Not enough experience!") }) continue + val match = lore.asReversed().firstNotNullOfOrNull { roundsNeededRegex.find(it.removeColor()) } ?: continue + roundsNeeded = match.groups[1]!!.value.toInt() + break + } + } + + @SubscribeEvent + fun onInventoryUpdated(event: InventoryUpdatedEvent) { + if (!config.superpairsClicksAlert) return + if (roundsNeeded == -1) return + if (!targetInventoryNames.any { event.inventoryName.contains(it) }) return + + if ( // checks if we have succeeded in either minigame + (event.inventoryName.contains("Chronomatron") + && ((event.inventoryItems[4]?.displayName?.removeColor() + ?.let { currentRoundRegex.find(it) } + ?.groups?.get(1)?.value?.toInt() ?: -1) > roundsNeeded)) + + || (event.inventoryName.contains("Ultrasequencer") + && event.inventoryItems.entries + .filter { it.key < 45 } + .any { it.value.stackSize > roundsNeeded }) + ) { + SoundUtils.playBeepSound() + ChatUtils.chat("You have reached the maximum possible clicks!") + roundsNeeded = -1 + } + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(46, "misc.superpairsClicksAlert", "inventory.helper.enchanting.superpairsClicksAlert") + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt new file mode 100644 index 000000000..1d6af4e89 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt @@ -0,0 +1,102 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +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.RenderUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SoundUtils.createSound +import at.hannibal2.skyhanni.utils.SoundUtils.playSound +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiContainer +import net.minecraft.client.renderer.GlStateManager +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color +import kotlin.time.Duration.Companion.seconds + +object UltraRareBookAlert { + + private val config get() = SkyHanniMod.feature.inventory.helper.enchanting + private val dragonSound by lazy { createSound("mob.enderdragon.growl", 1f) } + + private val patternGroup = RepoPattern.group("data.enchanting") + private val superpairsGui by patternGroup.pattern( + "inventory.experimentstable.gui", + "Superpairs.*" + ) + private val ultraRarePattern by patternGroup.pattern( + "inventory.experimentstable.ultrarare", + "§d§kXX§5 ULTRA-RARE BOOK! §d§kXX" + ) + private val bookPattern by patternGroup.pattern( + "inventory.experimentstable.book", + "§9(?.*)" + ) + + private var enchantsFound = false + + private var lastNotificationTime = SimpleTimeMark.farPast() + + private fun notification(enchantsName: String) { + lastNotificationTime = SimpleTimeMark.now() + dragonSound.playSound() + ChatUtils.chat("You have uncovered a §d§kXX§5 ULTRA-RARE BOOK! §d§kXX§e! You found: §9$enchantsName") + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.ultraRareBookAlert) return + if (!superpairsGui.matches(InventoryUtils.openInventoryName())) return + if (lastNotificationTime.passedSince() > 5.seconds) return + val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return + + GlStateManager.pushMatrix() + GlStateManager.translate(0f, -150f, 500f) + + Renderable.drawInsideRoundedRect( + Renderable.string("§d§kXX§5 ULTRA-RARE BOOK! §d§kXX", 1.5), + Color(Color.DARK_GRAY.withAlpha(0), true), + horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, + verticalAlign = RenderUtils.VerticalAlignment.CENTER, + ).renderXYAligned(0, 125, gui.width, gui.height) + + GlStateManager.translate(0f, 150f, -500f) + GlStateManager.popMatrix() + } + + @SubscribeEvent + fun onInventoryUpdated(event: InventoryUpdatedEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.ultraRareBookAlert) return + if (enchantsFound) return + if (!superpairsGui.matches(event.inventoryName)) return + + for (lore in event.inventoryItems.map { it.value.getLore() }) { + val firstLine = lore.firstOrNull() ?: continue + if (!ultraRarePattern.matches(firstLine)) continue + val bookNameLine = lore.getOrNull(2) ?: continue + bookPattern.matchMatcher(bookNameLine) { + val enchantsName = group("enchant") + notification(enchantsName) + enchantsFound = true + } + } + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + enchantsFound = false + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/SuperpairsClicksAlert.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/SuperpairsClicksAlert.kt deleted file mode 100644 index b09a1dbff..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/SuperpairsClicksAlert.kt +++ /dev/null @@ -1,62 +0,0 @@ -package at.hannibal2.skyhanni.features.misc - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.InventoryOpenEvent -import at.hannibal2.skyhanni.events.InventoryUpdatedEvent -import at.hannibal2.skyhanni.utils.ChatUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.SoundUtils -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class SuperpairsClicksAlert { - - private val config get() = SkyHanniMod.feature.misc - - private var roundsNeeded = -1 - private val roundsNeededRegex = Regex("""(?:Chain|Series) of (\d+):""") - private val currentRoundRegex = Regex("""Round: (\d+)""") - private val targetInventoryNames = arrayOf("Chronomatron", "Ultrasequencer") - - @SubscribeEvent - fun onInventoryOpen(event: InventoryOpenEvent) { - if (!config.superpairsClicksAlert) return - if (!targetInventoryNames.any { event.inventoryName.contains(it) }) return - - // player may have drank Metaphysical Serum which reduces clicks needed by up to 3, so need to parse it - for (i in 24 downTo 20) { - val lore = event.inventoryItems[i]?.getLore() ?: continue - if (lore.any { it.contains("Practice mode has no rewards") }) { - roundsNeeded = -1 - break - } - if (lore.any { it.contains("Enchanting level too low!") || it.contains("Not enough experience!") }) continue - val match = lore.asReversed().firstNotNullOfOrNull { roundsNeededRegex.find(it.removeColor()) } ?: continue - roundsNeeded = match.groups[1]!!.value.toInt() - break - } - } - - @SubscribeEvent - fun onInventoryUpdated(event: InventoryUpdatedEvent) { - if (!config.superpairsClicksAlert) return - if (roundsNeeded == -1) return - if (!targetInventoryNames.any { event.inventoryName.contains(it) }) return - - if ( // checks if we have succeeded in either minigame - (event.inventoryName.contains("Chronomatron") - && ((event.inventoryItems[4]?.displayName?.removeColor() - ?.let { currentRoundRegex.find(it) } - ?.groups?.get(1)?.value?.toInt() ?: -1) > roundsNeeded)) - - || (event.inventoryName.contains("Ultrasequencer") - && event.inventoryItems.entries - .filter { it.key < 45 } - .any { it.value.stackSize > roundsNeeded }) - ) { - SoundUtils.playBeepSound() - ChatUtils.chat("You have reached the maximum possible clicks!") - roundsNeeded = -1 - } - } -} -- cgit