From fe51024f9a230f6408e69bd73293c71412bf9c0e Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:49:05 +1100 Subject: Fix: Trapper area waypoints not working (#1186) --- .../features/misc/trevor/CurrentMobArea.kt | 14 ------ .../features/misc/trevor/TrapperMobArea.kt | 14 ++++++ .../features/misc/trevor/TrevorFeatures.kt | 57 +++++++++++++++------- .../skyhanni/features/misc/trevor/TrevorMob.kt | 10 ++++ .../skyhanni/features/misc/trevor/TrevorMobs.kt | 10 ---- .../skyhanni/features/misc/trevor/TrevorSolver.kt | 19 ++++---- 6 files changed, 72 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/trevor/CurrentMobArea.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrapperMobArea.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorMob.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorMobs.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/CurrentMobArea.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/CurrentMobArea.kt deleted file mode 100644 index f8a7f7c4c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/CurrentMobArea.kt +++ /dev/null @@ -1,14 +0,0 @@ -package at.hannibal2.skyhanni.features.misc.trevor - -import at.hannibal2.skyhanni.utils.LorenzVec - -enum class CurrentMobArea(val location: String, val coordinates: LorenzVec) { - OASIS("Oasis", LorenzVec(126.0, 77.0, -456.0)), - GORGE("Mushroom Gorge", LorenzVec(300.0, 80.0, -509.0)), - OVERGROWN("Overgrown Mushroom Cave", LorenzVec(242.0, 60.0, -389.0)), - SETTLEMENT("Desert Settlement", LorenzVec(184.0, 86.0, -384.0)), - GLOWING("Glowing Mushroom Cave", LorenzVec(199.0, 50.0, -512.0)), - MOUNTAIN("Desert Mountain", LorenzVec(255.0, 148.0, -518.0)), - FOUND(" ", LorenzVec(0.0, 0.0, 0.0)), - NONE(" ", LorenzVec(0.0, 0.0, 0.0)), -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrapperMobArea.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrapperMobArea.kt new file mode 100644 index 000000000..753920ed1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrapperMobArea.kt @@ -0,0 +1,14 @@ +package at.hannibal2.skyhanni.features.misc.trevor + +import at.hannibal2.skyhanni.utils.LorenzVec + +enum class TrapperMobArea(val location: String, val coordinates: LorenzVec) { + OASIS("Oasis", LorenzVec(126.0, 77.0, -456.0)), + GORGE("Mushroom Gorge", LorenzVec(300.0, 80.0, -509.0)), + OVERGROWN("Overgrown Mushroom Cave", LorenzVec(242.0, 60.0, -389.0)), + SETTLEMENT("Desert Settlement", LorenzVec(184.0, 86.0, -384.0)), + GLOWING("Glowing Mushroom Cave", LorenzVec(199.0, 50.0, -512.0)), + MOUNTAIN("Desert Mountain", LorenzVec(255.0, 148.0, -518.0)), + FOUND(" ", LorenzVec(0.0, 0.0, 0.0)), + NONE(" ", LorenzVec(0.0, 0.0, 0.0)), +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt index 45a8c2f89..7fe10ae5d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt @@ -31,6 +31,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.findMatcher import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData @@ -65,7 +66,23 @@ object TrevorFeatures { ) private val locationPattern by patternGroup.pattern( "zone", - "Zone: (?.*)" + "Location: (?.*)" + ) + private val mobDiedPattern by patternGroup.pattern( + "mob.died", + "§aReturn to the Trapper soon to get a new animal to hunt!" + ) + private val startDialoguePattern by patternGroup.pattern( + "start.dialogue", + "[NPC] Trevor: You will have 10 minutes to find the mob from when you accept the task." + ) + private val outOfTimePattern by patternGroup.pattern( + "outoftime", + "You ran out of time and the animal disappeared!" + ) + private val clickOptionPattern by patternGroup.pattern( + "clickoption", + "Click an option: §r§a§l\\[YES]§r§7 - §r§c§l\\[NO]" ) private var timeUntilNextReady = 0 @@ -107,14 +124,14 @@ object TrevorFeatures { val formattedMessage = event.message.removeColor() - if (event.message == "§aReturn to the Trapper soon to get a new animal to hunt!") { + mobDiedPattern.matchMatcher(event.message) { TrevorSolver.resetLocation() if (config.trapperMobDiedMessage) { LorenzUtils.sendTitle("§2Mob Died ", 5.seconds) SoundUtils.playBeepSound() } trapperReady = true - TrevorSolver.mobLocation = CurrentMobArea.NONE + TrevorSolver.mobLocation = TrapperMobArea.NONE if (timeUntilNextReady <= 0) { currentStatus = TrapperStatus.READY currentLabel = "§2Ready" @@ -122,7 +139,7 @@ object TrevorFeatures { currentStatus = TrapperStatus.WAITING currentLabel = if (timeUntilNextReady == 1) "§31 second left" else "§3$timeUntilNextReady seconds left" } - TrevorSolver.mobLocation = CurrentMobArea.NONE + TrevorSolver.mobLocation = TrapperMobArea.NONE } trapperPattern.matchMatcher(formattedMessage) { @@ -147,15 +164,15 @@ object TrevorFeatures { TrevorSolver.averageHeight = LocationUtils.playerLocation().y } - if (formattedMessage == "[NPC] Trevor: You will have 10 minutes to find the mob from when you accept the task.") { + startDialoguePattern.matchMatcher(formattedMessage) { teleportBlock = SimpleTimeMark.now() } + outOfTimePattern.matchMatcher(formattedMessage) { + resetTrapper() + } - if (event.message.contains("§r§7Click an option: §r§a§l[YES]§r§7 - §r§c§l[NO]")) { - - val siblings = event.chatComponent.siblings - - for (sibling in siblings) { + clickOptionPattern.findMatcher(event.message) { + event.chatComponent.siblings.forEach { sibling -> if (sibling.chatStyle.chatClickEvent != null && sibling.chatStyle.chatClickEvent.value.contains("YES")) { lastChatPromptTime = SimpleTimeMark.now() lastChatPrompt = sibling.chatStyle.chatClickEvent.value.drop(1) @@ -207,18 +224,18 @@ object TrevorFeatures { active = true } - CurrentMobArea.entries.firstOrNull { it.location == formattedLine }?.let { + TrapperMobArea.entries.firstOrNull { it.location == formattedLine }?.let { TrevorSolver.mobLocation = it found = true } locationPattern.matchMatcher(formattedLine) { val zone = group("zone") - TrevorSolver.mobLocation = CurrentMobArea.entries.firstOrNull { it.location == zone } - ?: CurrentMobArea.NONE + TrevorSolver.mobLocation = TrapperMobArea.entries.firstOrNull { it.location == zone } + ?: TrapperMobArea.NONE found = true } } - if (!found) TrevorSolver.mobLocation = CurrentMobArea.NONE + if (!found) TrevorSolver.mobLocation = TrapperMobArea.NONE if (!active) { trapperReady = true } else { @@ -247,11 +264,11 @@ object TrevorFeatures { if (config.trapperSolver) { var location = TrevorSolver.mobLocation.coordinates - if (TrevorSolver.mobLocation == CurrentMobArea.NONE) return + if (TrevorSolver.mobLocation == TrapperMobArea.NONE) return if (TrevorSolver.averageHeight != 0.0) { location = LorenzVec(location.x, TrevorSolver.averageHeight, location.z) } - if (TrevorSolver.mobLocation == CurrentMobArea.FOUND) { + if (TrevorSolver.mobLocation == TrapperMobArea.FOUND) { val displayName = if (TrevorSolver.currentMob == null) "Mob Location" else { TrevorSolver.currentMob!!.mobName } @@ -300,8 +317,7 @@ object TrevorFeatures { } } - @SubscribeEvent - fun onWorldChange(event: LorenzWorldChangeEvent) { + private fun resetTrapper() { TrevorSolver.resetLocation() currentStatus = TrapperStatus.READY currentLabel = "§2Ready" @@ -309,6 +325,11 @@ object TrevorFeatures { inBetweenQuests = false } + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + resetTrapper() + } + enum class TrapperStatus(baseColor: LorenzColor) { READY(LorenzColor.DARK_GREEN), WAITING(LorenzColor.DARK_AQUA), diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorMob.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorMob.kt new file mode 100644 index 000000000..b8a89fe2f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorMob.kt @@ -0,0 +1,10 @@ +package at.hannibal2.skyhanni.features.misc.trevor + +enum class TrevorMob(val mobName: String, val renderDistance: Double) { + COW("Cow", 68.0), + HORSE("Horse", 90.0), + SHEEP("Sheep", 68.0), + PIG("Pig", 68.0), + RABBIT("Rabbit", 43.0), + CHICKEN("Chicken", 33.0), +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorMobs.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorMobs.kt deleted file mode 100644 index d04f6f285..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorMobs.kt +++ /dev/null @@ -1,10 +0,0 @@ -package at.hannibal2.skyhanni.features.misc.trevor - -enum class TrevorMobs(val mobName: String, val renderDistance: Double) { - COW("Cow", 68.0), - HORSE("Horse", 90.0), - SHEEP("Sheep", 68.0), - PIG("Pig", 68.0), - RABBIT("Rabbit", 43.0), - CHICKEN("Chicken", 33.0), -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorSolver.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorSolver.kt index d73b79db4..36f7d595b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorSolver.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorSolver.kt @@ -16,14 +16,14 @@ import kotlin.time.Duration.Companion.seconds object TrevorSolver { - private val animalHealths = intArrayOf(100, 200, 500, 1000, 2000, 5000, 10000, 30000) + private val animalHealths = setOf(100, 200, 500, 1000, 2000, 5000, 10000, 30000) - var currentMob: TrevorMobs? = null + var currentMob: TrevorMob? = null private var maxHeight: Double = 0.0 private var minHeight: Double = 0.0 private var foundID = -1 var mobCoordinates = LorenzVec(0.0, 0.0, 0.0) - var mobLocation = CurrentMobArea.NONE + var mobLocation = TrapperMobArea.NONE var averageHeight = (minHeight + maxHeight) / 2 fun findMobHeight(height: Int, above: Boolean) { @@ -53,18 +53,18 @@ object TrevorSolver { if (entity is EntityOtherPlayerMP) continue val name = entity.name val entityHealth = if (entity is EntityLivingBase) entity.baseMaxHealth.derpy() else 0 - currentMob = TrevorMobs.entries.firstOrNull { it.mobName.contains(name) } + currentMob = TrevorMob.entries.firstOrNull { it.mobName.contains(name) } if (animalHealths.any { it == entityHealth } && currentMob != null) { if (foundID == entity.entityId) { val dist = entity.position.toLorenzVec().distanceToPlayer() - if ((currentMob == TrevorMobs.RABBIT || currentMob == TrevorMobs.SHEEP) && mobLocation == CurrentMobArea.OASIS) { - println("This is unfortunate") - } else canSee = entity.canBeSeen() && dist < currentMob!!.renderDistance + if ((currentMob == TrevorMob.RABBIT || currentMob == TrevorMob.SHEEP) && mobLocation == TrapperMobArea.OASIS) return + + canSee = entity.canBeSeen() && dist < currentMob!!.renderDistance if (canSee) { - if (mobLocation != CurrentMobArea.FOUND) { + if (mobLocation != TrapperMobArea.FOUND) { LorenzUtils.sendTitle("§2Saw ${currentMob!!.mobName}!", 3.seconds) } - mobLocation = CurrentMobArea.FOUND + mobLocation = TrapperMobArea.FOUND mobCoordinates = entity.position.toLorenzVec() } } else { @@ -74,7 +74,6 @@ object TrevorSolver { } } if (foundID != -1) { - println("Cannot find mob anymore") mobCoordinates = LorenzVec(0.0, 0.0, 0.0) foundID = -1 } -- cgit