From cc1be73101abe20c61e25206875b279145883109 Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Sat, 16 Dec 2023 12:06:44 +0000 Subject: Feature: Add Vermin Tracker (#804) Add Vermin Tracker #804 --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../java/at/hannibal2/skyhanni/config/Storage.java | 6 +- .../hannibal2/skyhanni/config/commands/Commands.kt | 5 + .../rift/area/westvillage/VerminTrackerConfig.java | 25 +++ .../rift/area/westvillage/WestVillageConfig.java | 5 + .../features/rift/area/westvillage/KloonHacking.kt | 171 --------------------- .../rift/area/westvillage/KloonTerminal.kt | 14 -- .../rift/area/westvillage/VerminTracker.kt | 149 ++++++++++++++++++ .../rift/area/westvillage/kloon/KloonHacking.kt | 171 +++++++++++++++++++++ .../rift/area/westvillage/kloon/KloonTerminal.kt | 14 ++ 10 files changed, 377 insertions(+), 187 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/rift/area/westvillage/VerminTrackerConfig.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonHacking.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonTerminal.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonHacking.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonTerminal.kt (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 7bcf31f72..d6c6b62e1 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -288,7 +288,8 @@ import at.hannibal2.skyhanni.features.rift.area.mirrorverse.RiftLavaMazeParkour import at.hannibal2.skyhanni.features.rift.area.mirrorverse.RiftUpsideDownParkour import at.hannibal2.skyhanni.features.rift.area.mirrorverse.TubulatorParkour import at.hannibal2.skyhanni.features.rift.area.stillgorechateau.RiftBloodEffigies -import at.hannibal2.skyhanni.features.rift.area.westvillage.KloonHacking +import at.hannibal2.skyhanni.features.rift.area.westvillage.VerminTracker +import at.hannibal2.skyhanni.features.rift.area.westvillage.kloon.KloonHacking import at.hannibal2.skyhanni.features.rift.area.wyldwoods.RiftLarva import at.hannibal2.skyhanni.features.rift.area.wyldwoods.RiftOdonata import at.hannibal2.skyhanni.features.rift.area.wyldwoods.ShyCruxWarnings @@ -682,6 +683,7 @@ class SkyHanniMod { loadModule(JyrreTimer()) loadModule(NewYearCakeReminder()) loadModule(HighlightInquisitors()) + loadModule(VerminTracker) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index 4a9c94fb5..e17646663 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -19,7 +19,8 @@ import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward; import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker; import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker; import at.hannibal2.skyhanni.features.misc.visualwords.VisualWord; -import at.hannibal2.skyhanni.features.rift.area.westvillage.KloonTerminal; +import at.hannibal2.skyhanni.features.rift.area.westvillage.VerminTracker; +import at.hannibal2.skyhanni.features.rift.area.westvillage.kloon.KloonTerminal; import at.hannibal2.skyhanni.features.slayer.SlayerProfitTracker; import at.hannibal2.skyhanni.utils.LorenzVec; import at.hannibal2.skyhanni.utils.NEUInternalName; @@ -358,6 +359,9 @@ public class Storage { @Expose public List completedKloonTerminals = new ArrayList<>(); + @Expose + public VerminTracker.Data verminTracker = new VerminTracker.Data(); + } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 3dba2e047..8f4d96483 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -41,6 +41,7 @@ import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager import at.hannibal2.skyhanni.features.misc.massconfiguration.DefaultConfigFeatures import at.hannibal2.skyhanni.features.misc.visualwords.VisualWordGui +import at.hannibal2.skyhanni.features.rift.area.westvillage.VerminTracker import at.hannibal2.skyhanni.features.slayer.SlayerProfitTracker import at.hannibal2.skyhanni.test.PacketTest import at.hannibal2.skyhanni.test.SkyHanniConfigSearchResetCommand @@ -203,6 +204,10 @@ object Commands { "shmouselock", "Lock/Unlock the mouse so it will no longer rotate the player (for farming)" ) { LockMouseLook.toggleLock() } + registerCommand( + "shresetvermintracker", + "Resets the Vermin Tracker" + ) { VerminTracker.resetCommand(it) } } private fun usersBugFix() { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/rift/area/westvillage/VerminTrackerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/rift/area/westvillage/VerminTrackerConfig.java new file mode 100644 index 000000000..1ada3d883 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/rift/area/westvillage/VerminTrackerConfig.java @@ -0,0 +1,25 @@ +package at.hannibal2.skyhanni.config.features.rift.area.westvillage; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +public class VerminTrackerConfig { + @Expose + @ConfigOption(name = "Show Counter", desc = "Count all §aSilverfish§7, §aSpiders, §7and §aFlies §7vacuumed.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Hide Chat", desc = "Hide the chat message when vacuuming a vermin.") + @ConfigEditorBoolean + @FeatureToggle + public boolean hideChat = false; + + @Expose + public Position pos = new Position(16, -232, false, true); +} + diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/rift/area/westvillage/WestVillageConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/rift/area/westvillage/WestVillageConfig.java index 273080489..478bc4cc9 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/rift/area/westvillage/WestVillageConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/rift/area/westvillage/WestVillageConfig.java @@ -10,4 +10,9 @@ public class WestVillageConfig { @Accordion @Expose public KloonHackingConfig hacking = new KloonHackingConfig(); + + @ConfigOption(name = "Vermin Tracker", desc = "infested") + @Accordion + @Expose + public VerminTrackerConfig verminTracker = new VerminTrackerConfig(); } diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonHacking.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonHacking.kt deleted file mode 100644 index 41c52b3f5..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonHacking.kt +++ /dev/null @@ -1,171 +0,0 @@ -package at.hannibal2.skyhanni.features.rift.area.westvillage - -import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.data.ProfileStorageData -import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.InventoryCloseEvent -import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.events.LorenzToolTipEvent -import at.hannibal2.skyhanni.features.rift.RiftAPI -import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.RenderUtils.highlight -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import io.github.moulberry.notenoughupdates.events.SlotClickEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class KloonHacking { - private val config get() = RiftAPI.config.area.westVillage.hacking - - // TODO USE SH-REPO - val pattern = "You've set the color of this terminal to (?.*)!".toPattern() - - private var wearingHelmet = false - private var inTerminalInventory = false - private var inColourInventory = false - private val correctButtons = mutableListOf() - private var nearestTerminal: KloonTerminal? = null - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (!RiftAPI.inRift()) return - if (event.repeatSeconds(1)) { - checkHelmet() - } - } - - private fun checkHelmet() { - wearingHelmet = InventoryUtils.getHelmet()?.getInternalName()?.equals("RETRO_ENCABULATING_VISOR") ?: false - } - - @SubscribeEvent - fun onInventoryOpen(event: InventoryFullyOpenedEvent) { - inTerminalInventory = false - inColourInventory = false - nearestTerminal = null - if (!RiftAPI.inRift()) return - if (!config.solver) return - if (event.inventoryName == "Hacking" || event.inventoryName == "Hacking (As seen on CSI)") { - inTerminalInventory = true - correctButtons.clear() - for ((slot, stack) in event.inventoryItems) { - if (slot in 2..6) { - correctButtons.add(stack.displayName.removeColor()) - } - } - } - if (event.inventoryName == "Hacked Terminal Color Picker") { - inColourInventory = true - } - } - - @SubscribeEvent - fun onInventoryClose(event: InventoryCloseEvent) { - inTerminalInventory = false - inColourInventory = false - } - - @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!RiftAPI.inRift()) return - if (inTerminalInventory) { - if (!config.solver) return - var i = 0 - for (slot in InventoryUtils.getItemsInOpenChest()) { - if (slot.slotIndex == 11 + 10 * i) { - val correctButton = slot.stack!!.displayName.removeColor() == correctButtons[i] - slot highlight if (correctButton) LorenzColor.GREEN else LorenzColor.RED - continue - } - if (slot.slotIndex > i * 9 + 8 && slot.slotIndex < i * 9 + 18 && slot.stack!!.displayName.removeColor() == correctButtons[i]) { - slot highlight LorenzColor.YELLOW - } - if (slot.slotIndex == i * 9 + 17) { - i += 1 - } - } - } - if (inColourInventory) { - if (!config.colour) return - val targetColour = nearestTerminal ?: getNearestTerminal() - for (slot in InventoryUtils.getItemsInOpenChest()) { - if (slot.stack.getLore().any { it.contains(targetColour?.name ?: "") }) { - slot highlight LorenzColor.GREEN - } - } - } - } - - @SubscribeEvent(priority = EventPriority.HIGH) - fun onSlotClick(event: SlotClickEvent) { - if (!inTerminalInventory || !RiftAPI.inRift()) return - event.usePickblockInstead() - } - - @SubscribeEvent - fun onRenderWorld(event: LorenzRenderWorldEvent) { - if (!RiftAPI.inRift()) return - if (!config.waypoints) return - if (!wearingHelmet) return - val storage = ProfileStorageData.profileSpecific?.rift ?: return - for (terminal in KloonTerminal.entries) { - if (terminal !in storage.completedKloonTerminals) { - event.drawWaypointFilled(terminal.location, LorenzColor.DARK_RED.toColor(), true, true) - } - } - } - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - if (!RiftAPI.inRift()) return - if (!wearingHelmet) return - pattern.matchMatcher(event.message.removeColor()) { - val storage = ProfileStorageData.profileSpecific?.rift ?: return - val colour = group("colour") - val completedTerminal = KloonTerminal.entries.firstOrNull { it.name == colour } ?: return - if (completedTerminal != nearestTerminal) return - storage.completedKloonTerminals.add(completedTerminal) - } - } - - @SubscribeEvent - fun onTooltip(event: LorenzToolTipEvent) { - if (!RiftAPI.inRift()) return - if (!inTerminalInventory) return - if (!config.solver) return - - val neededTooltips = listOf(0, 2, 3, 4, 5, 6, 8, 9, 26, 27, 44, 45) - if (event.slot.slotIndex !in neededTooltips) { - event.toolTip.clear() - } - } - - private fun getNearestTerminal(): KloonTerminal? { - var closestTerminal: KloonTerminal? = null - var closestDistance = 8.0 - - for (terminal in KloonTerminal.entries) { - val distance = terminal.location.distanceToPlayer() - if (distance < closestDistance) { - closestTerminal = terminal - closestDistance = distance - } - } - nearestTerminal = closestTerminal - return closestTerminal - } - - @SubscribeEvent - fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(9, "rift.area.westVillageConfig", "rift.area.westVillage") - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonTerminal.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonTerminal.kt deleted file mode 100644 index b5434d330..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonTerminal.kt +++ /dev/null @@ -1,14 +0,0 @@ -package at.hannibal2.skyhanni.features.rift.area.westvillage - -import at.hannibal2.skyhanni.utils.LorenzVec - -enum class KloonTerminal(val location: LorenzVec) { - RED(LorenzVec(-69.0, 65.0, -63.0)), - ORANGE(LorenzVec(-44.0, 71.0, -62.0)), - YELLOW(LorenzVec(-39.0, 71.0, -95.0)), - GREEN(LorenzVec(-62.0, 71.0, -83.0)), - AQUA(LorenzVec(-33.0, 70.0, -134.5)), - BLUE(LorenzVec(-66.5, 72.0, -119.0)), - PURPLE(LorenzVec(-89.0, 73.0, -115.0)), - PINK(LorenzVec(-110.0, 73.0, -107.0)) -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt new file mode 100644 index 000000000..4bb2120b4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt @@ -0,0 +1,149 @@ +package at.hannibal2.skyhanni.features.rift.area.westvillage + +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.rift.RiftAPI +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker +import at.hannibal2.skyhanni.utils.tracker.TrackerData +import com.google.gson.annotations.Expose +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +object VerminTracker { + private val silverfishPattern by RepoPattern.pattern( + "rift.area.westvillage.vermintracker.silverfish", + ".*§eYou vacuumed a §.*Silverfish.*" + ) + private val spiderPattern by RepoPattern.pattern( + "rift.area.westvillage.vermintracker.spider", + ".*§eYou vacuumed a §.*Spider.*" + ) + private val flyPattern by RepoPattern.pattern( + "rift.area.westvillage.vermintracker.fly", + ".*§eYou vacuumed a §.*Fly.*" + ) + private val verminBinPattern by RepoPattern.pattern( + "rift.area.westvillage.vermintracker.binline", + "§fVermin Bin: §\\w(?\\d+) (?\\w+)" + ) + private val verminBagPattern by RepoPattern.pattern( + "rift.area.westvillage.vermintracker.bagline", + "§fVacuum Bag: §\\w(?\\d+) (?\\w+)" + ) + + private val config get() = RiftAPI.config.area.westVillage.verminTracker + + private val tracker = SkyHanniTracker("Vermin Tracker", { Data() }, { it.rift.verminTracker }) + { drawDisplay(it) } + + class Data : TrackerData() { + override fun reset() { + count.clear() + } + + @Expose + var count: MutableMap = mutableMapOf() + } + + enum class VerminType(val vermin: String, val pattern: Pattern) { + SILVERFISH("§aSilverfish", silverfishPattern), + SPIDER("§aSpiders", spiderPattern), + FLY("§aFlies", flyPattern), + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + VerminType.entries.forEach { verminType -> + if (verminType.pattern.matches(event.message)) { + addVermin(verminType) + if (config.hideChat) { + event.blockedReason = "vermin_vacuumed" + } + } + } + } + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + if (!RiftAPI.inRift() || event.inventoryName != "Vermin Bin") return + + val bin = event.inventoryItems[13]?.getLore() ?: return + val bag = InventoryUtils.getItemsInOwnInventory() + .firstOrNull { it.getInternalName() == "TURBOMAX_VACUUM".asInternalName() } + ?.getLore() ?: emptyList() + + val binCounts = countVermin(bin, verminBinPattern) + VerminType.entries.forEach { setVermin(it, binCounts[it] ?: 0) } + + if (bag.isEmpty()) return + + val bagCounts = countVermin(bag, verminBagPattern) + VerminType.entries.forEach { addVermin(it, bagCounts[it] ?: 0) } + } + + private fun countVermin(lore: List, pattern: Pattern): MutableMap { + val verminCounts = mutableMapOf( + VerminType.SILVERFISH to 0, + VerminType.SPIDER to 0, + VerminType.FLY to 0 + ) + for (line in lore) { + pattern.matchMatcher(line) { + val vermin = group("vermin")?.lowercase() ?: continue + val verminCount = group("count")?.toInt() ?: continue + val verminType = getVerminType(vermin) + verminCounts[verminType] = verminCount + } + } + return verminCounts + } + + private fun getVerminType(vermin: String): VerminType { + return when (vermin) { + "silverfish", "silverfishes" -> VerminType.SILVERFISH + "spider", "spiders" -> VerminType.SPIDER + "fly", "flies" -> VerminType.FLY + else -> VerminType.SILVERFISH + } + } + + private fun addVermin(vermin: VerminType, count: Int = 1) { + tracker.modify { it.count.addOrPut(vermin, count) } + } + + private fun setVermin(vermin: VerminType, count: Int) { + tracker.modify { it.count[vermin] = count } + } + + private fun drawDisplay(data: Data): List> = buildList { + addAsSingletonList("§7Vermin Tracker:") + data.count.entries.sortedByDescending { it.value }.forEach { (vermin, amount) -> + val verminName = vermin.vermin + addAsSingletonList(" §7- §e${amount.addSeparators()} $verminName") + } + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent) { + if (!isEnabled()) return + + tracker.renderDisplay(config.pos) + } + + fun resetCommand(args: Array) { + tracker.resetCommand(args, "shresetvermintracker") + } + + private fun isEnabled() = RiftAPI.inRift() && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonHacking.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonHacking.kt new file mode 100644 index 000000000..eb24782c6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonHacking.kt @@ -0,0 +1,171 @@ +package at.hannibal2.skyhanni.features.rift.area.westvillage.kloon + +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.features.rift.RiftAPI +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class KloonHacking { + private val config get() = RiftAPI.config.area.westVillage.hacking + + // TODO USE SH-REPO + val pattern = "You've set the color of this terminal to (?.*)!".toPattern() + + private var wearingHelmet = false + private var inTerminalInventory = false + private var inColourInventory = false + private val correctButtons = mutableListOf() + private var nearestTerminal: KloonTerminal? = null + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!RiftAPI.inRift()) return + if (event.repeatSeconds(1)) { + checkHelmet() + } + } + + private fun checkHelmet() { + wearingHelmet = InventoryUtils.getHelmet()?.getInternalName()?.equals("RETRO_ENCABULATING_VISOR") ?: false + } + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + inTerminalInventory = false + inColourInventory = false + nearestTerminal = null + if (!RiftAPI.inRift()) return + if (!config.solver) return + if (event.inventoryName == "Hacking" || event.inventoryName == "Hacking (As seen on CSI)") { + inTerminalInventory = true + correctButtons.clear() + for ((slot, stack) in event.inventoryItems) { + if (slot in 2..6) { + correctButtons.add(stack.displayName.removeColor()) + } + } + } + if (event.inventoryName == "Hacked Terminal Color Picker") { + inColourInventory = true + } + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + inTerminalInventory = false + inColourInventory = false + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!RiftAPI.inRift()) return + if (inTerminalInventory) { + if (!config.solver) return + var i = 0 + for (slot in InventoryUtils.getItemsInOpenChest()) { + if (slot.slotIndex == 11 + 10 * i) { + val correctButton = slot.stack!!.displayName.removeColor() == correctButtons[i] + slot highlight if (correctButton) LorenzColor.GREEN else LorenzColor.RED + continue + } + if (slot.slotIndex > i * 9 + 8 && slot.slotIndex < i * 9 + 18 && slot.stack!!.displayName.removeColor() == correctButtons[i]) { + slot highlight LorenzColor.YELLOW + } + if (slot.slotIndex == i * 9 + 17) { + i += 1 + } + } + } + if (inColourInventory) { + if (!config.colour) return + val targetColour = nearestTerminal ?: getNearestTerminal() + for (slot in InventoryUtils.getItemsInOpenChest()) { + if (slot.stack.getLore().any { it.contains(targetColour?.name ?: "") }) { + slot highlight LorenzColor.GREEN + } + } + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onSlotClick(event: SlotClickEvent) { + if (!inTerminalInventory || !RiftAPI.inRift()) return + event.usePickblockInstead() + } + + @SubscribeEvent + fun onRenderWorld(event: LorenzRenderWorldEvent) { + if (!RiftAPI.inRift()) return + if (!config.waypoints) return + if (!wearingHelmet) return + val storage = ProfileStorageData.profileSpecific?.rift ?: return + for (terminal in KloonTerminal.entries) { + if (terminal !in storage.completedKloonTerminals) { + event.drawWaypointFilled(terminal.location, LorenzColor.DARK_RED.toColor(), true, true) + } + } + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!RiftAPI.inRift()) return + if (!wearingHelmet) return + pattern.matchMatcher(event.message.removeColor()) { + val storage = ProfileStorageData.profileSpecific?.rift ?: return + val colour = group("colour") + val completedTerminal = KloonTerminal.entries.firstOrNull { it.name == colour } ?: return + if (completedTerminal != nearestTerminal) return + storage.completedKloonTerminals.add(completedTerminal) + } + } + + @SubscribeEvent + fun onTooltip(event: LorenzToolTipEvent) { + if (!RiftAPI.inRift()) return + if (!inTerminalInventory) return + if (!config.solver) return + + val neededTooltips = listOf(0, 2, 3, 4, 5, 6, 8, 9, 26, 27, 44, 45) + if (event.slot.slotIndex !in neededTooltips) { + event.toolTip.clear() + } + } + + private fun getNearestTerminal(): KloonTerminal? { + var closestTerminal: KloonTerminal? = null + var closestDistance = 8.0 + + for (terminal in KloonTerminal.entries) { + val distance = terminal.location.distanceToPlayer() + if (distance < closestDistance) { + closestTerminal = terminal + closestDistance = distance + } + } + nearestTerminal = closestTerminal + return closestTerminal + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(9, "rift.area.westVillageConfig", "rift.area.westVillage") + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonTerminal.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonTerminal.kt new file mode 100644 index 000000000..201bfca77 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonTerminal.kt @@ -0,0 +1,14 @@ +package at.hannibal2.skyhanni.features.rift.area.westvillage.kloon + +import at.hannibal2.skyhanni.utils.LorenzVec + +enum class KloonTerminal(val location: LorenzVec) { + RED(LorenzVec(-69.0, 65.0, -63.0)), + ORANGE(LorenzVec(-44.0, 71.0, -62.0)), + YELLOW(LorenzVec(-39.0, 71.0, -95.0)), + GREEN(LorenzVec(-62.0, 71.0, -83.0)), + AQUA(LorenzVec(-33.0, 70.0, -134.5)), + BLUE(LorenzVec(-66.5, 72.0, -119.0)), + PURPLE(LorenzVec(-89.0, 73.0, -115.0)), + PINK(LorenzVec(-110.0, 73.0, -107.0)) +} -- cgit