diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/diana/DianaConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/event/diana/DianaConfig.kt index 8142f1c9c54f..f4424f6d44f9 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/diana/DianaConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/diana/DianaConfig.kt @@ -2,13 +2,11 @@ package at.hannibal2.skyhanni.config.features.event.diana import at.hannibal2.skyhanni.config.FeatureToggle import at.hannibal2.skyhanni.config.core.config.Position -import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper import com.google.gson.annotations.Expose import io.github.notenoughupdates.moulconfig.ChromaColour import io.github.notenoughupdates.moulconfig.annotations.Accordion import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorColour -import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider import io.github.notenoughupdates.moulconfig.annotations.ConfigLink @@ -150,10 +148,12 @@ class DianaConfig { @ConfigLink(owner = DianaConfig::class, field = "burrowNearestWarp") val warpGuiPosition: Position = Position(327, 125, scale = 2.6f) - @Expose - @ConfigOption(name = "Ignored Warps", desc = "Warps listed here will not be suggested.") - @ConfigEditorDraggableList - val ignoredWarpsList: MutableList = mutableListOf(BurrowWarpHelper.WarpPoint.TAYLOR) + + // TODO add a way to ignore warps, maybe with ; list via name +// @Expose +// @ConfigOption(name = "Ignored Warps", desc = "Warps listed here will not be suggested.") +// @ConfigEditorDraggableList +// val ignoredWarps: MutableList = mutableListOf() @Expose @ConfigOption( diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt index fd89400f63c8..5921a3e5e504 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt @@ -28,6 +28,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.GraphUtils import at.hannibal2.skyhanni.utils.GraphUtils.distanceSqToPlayer +import at.hannibal2.skyhanni.utils.GraphUtils.distanceToNode import at.hannibal2.skyhanni.utils.GraphUtils.distanceToPlayer import at.hannibal2.skyhanni.utils.GraphUtils.playerPosition import at.hannibal2.skyhanni.utils.LorenzColor @@ -139,10 +140,14 @@ object IslandGraphs { private var cachedNearbyNodes = listOf() private var lastCacheUpdate = SimpleTimeMark.farPast() + // TODO create class for those things private var currentTarget: LorenzVec? = null private var currentTargetNode: GraphNode? = null private var navigationLabel = "" private var lastDisplayedDistance = 0.0 + private var warpIsBetter = false + private var bestWarpPoint: GraphNode? = null + private var distanceToBestWarp = 0.0 private var totalDistance = 0.0 private var pathColor = Color.WHITE private var allowRerouting = false @@ -467,6 +472,9 @@ object IslandGraphs { goal = null pathRenderer = null currentTargetNode = null + warpIsBetter = false + bestWarpPoint = null + distanceToBestWarp = 0.0 navigationLabel = "" totalDistance = 0.0 lastDisplayedDistance = 0.0 @@ -518,6 +526,7 @@ object IslandGraphs { require(label.isNotEmpty()) { "Label cannot be empty." } resetNavigation() allowRerouting = false + currentTargetNode = getGraph().getNearestNode(location) initNavigation(location, label, color, onFound, onManualCancel, condition) } @@ -552,6 +561,7 @@ object IslandGraphs { private fun updateNavigationProgress() { if (navigationLabel == "") return + checkForWarps() val distance = (pathRenderer?.remainingDistance ?: return).roundTo(1) if (distance == lastDisplayedDistance) return @@ -568,6 +578,39 @@ object IslandGraphs { NavigationFeedback.sendPathFindMessage(component) } + private fun checkForWarps() { + val graph = getGraph() + val targetNode = currentTargetNode ?: error("currentTargetNode is null") + + val warp = bestWarpPoint ?: run { + val possibleWarps = graph.filterByActive { it.hasTag(GraphNodeTag.WARP) } + val warp = possibleWarps.minByOrNull { targetNode.distanceToNode(it) } ?: run { + warpIsBetter = false + bestWarpPoint = null + return + } + println("found nearest node: ${warp.name}") + bestWarpPoint = warp + distanceToBestWarp = warp.distanceToNode(targetNode) + warp + } + val command = warp.name ?: error("warp node without name") + val genericMargin = 20 + val newWarpIsBetter = distanceToBestWarp + genericMargin < lastDisplayedDistance + if (newWarpIsBetter != warpIsBetter) { + warpIsBetter = newWarpIsBetter + if (newWarpIsBetter) { + println("warp is better!") + ChatUtils.clickableChat( + "click to run $command", + onClick = { + ChatUtils.sendMessageToServer(command) + }, + ) + } + } + } + fun cancelClick() { stopNavigation() onManualCancel() @@ -576,7 +619,9 @@ object IslandGraphs { @HandleEvent fun onRenderWorld(event: SkyHanniRenderWorldEvent) { if (currentIslandGraph == null) return - pathRenderer?.render(event) + if (!warpIsBetter) { + pathRenderer?.render(event) + } } fun isActive(testTarget: LorenzVec, testLabel: String): Boolean = testTarget == currentTarget && testLabel == navigationLabel diff --git a/src/main/java/at/hannibal2/skyhanni/data/model/graph/GraphNodeTag.kt b/src/main/java/at/hannibal2/skyhanni/data/model/graph/GraphNodeTag.kt index 76595436287f..ac527930d2b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/model/graph/GraphNodeTag.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/model/graph/GraphNodeTag.kt @@ -21,7 +21,16 @@ enum class GraphNodeTag( POI("poi", LorenzColor.WHITE, "Point of Interest", "A relevant spot or a landmark on the map.", onlySkyblock = null), // LAUNCH_PAD("launch", LorenzColor.WHITE, "Launch Pad", "Slime blocks sending you to another server."), - TELEPORT("teleport", LorenzColor.BLUE, "Teleport", "A spot from/to teleport.", onlySkyblock = null), + + // TODO delete once no graph data contains this anymore + // deprecated, dont use anymore + TELEPORT("teleport", LorenzColor.BLUE, "Teleport", "A spot from/to teleport. Deprecated, split up to warp, jump pad, and teleport pad", onlySkyblock = null), + // teleports from any island to this location on this island + WARP("warp", LorenzColor.BLUE, "Warp", "A warp command target.", onlySkyblock = null), + // stand there, jumps to another island, name is the other island + JUMP_PAD("jump_pad", LorenzColor.BLUE, "Jump Pad", "jump pad or portal to another island.", onlySkyblock = null), + // teleports around on the same island. + TELEPORT_PAD("teleport_pad", LorenzColor.BLUE, "Teleport Pad", "Teleport pad inside the same island.", onlySkyblock = null), // on multiple islands ROMEO("romeo", LorenzColor.WHITE, "Romeo & Juliette Quest", "Spots related to the Romeo and Juliette/Ring of Love quest line."), diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt index 3aa2064c9f51..5e9763371994 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt @@ -1,269 +1,269 @@ -package at.hannibal2.skyhanni.features.event.diana - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.api.event.HandleEvent -import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.config.commands.CommandCategory -import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent -import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.data.jsonobjects.repo.WarpLocationData -import at.hannibal2.skyhanni.data.jsonobjects.repo.WarpsJson -import at.hannibal2.skyhanni.events.DebugDataCollectEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.events.chat.SkyHanniChatEvent -import at.hannibal2.skyhanni.events.minecraft.KeyPressEvent -import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.test.command.ErrorManager -import at.hannibal2.skyhanni.utils.ChatUtils -import at.hannibal2.skyhanni.utils.DelayedRun -import at.hannibal2.skyhanni.utils.HypixelCommands -import at.hannibal2.skyhanni.utils.KeyboardManager -import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.NumberUtil.roundTo -import at.hannibal2.skyhanni.utils.RenderUtils -import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable -import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.collection.CollectionUtils.sorted -import at.hannibal2.skyhanni.utils.renderables.Renderable -import at.hannibal2.skyhanni.utils.renderables.primitives.text -import com.google.gson.JsonArray -import net.minecraft.client.Minecraft -import org.lwjgl.glfw.GLFW -import kotlin.time.Duration -import kotlin.time.Duration.Companion.milliseconds -import kotlin.time.Duration.Companion.seconds - -@SkyHanniModule -object BurrowWarpHelper { - - private val config get() = SkyHanniMod.feature.event.diana - - var currentWarp: WarpPoint? = null - - private var lastWarpTime = SimpleTimeMark.farPast() - private var lastWarp: WarpPoint? = null - - private var cannotWarpUntil: SimpleTimeMark = SimpleTimeMark.farPast() - private var warpQueued = false - - fun blockWarp(duration: Duration) { - val until = SimpleTimeMark.now().plus(duration) - if (until.minus(cannotWarpUntil) > 0.milliseconds) { - cannotWarpUntil = until - } - } - - @HandleEvent(GuiRenderEvent::class, onlyOnIsland = IslandType.HUB) - fun onRenderOverlay() { - if (!config.burrowNearestWarp) return - if (!DianaApi.isDoingDiana()) return - val warp = currentWarp ?: return - if (GriffinBurrowHelper.mobAlive) return - - val text = "§bWarp to " + warp.displayName - val keybindSuffix = if (config.keyBindWarp != GLFW.GLFW_KEY_UNKNOWN) { - val keyName = KeyboardManager.getKeyName(config.keyBindWarp) - " §7(§ePress $keyName§7)" - } else "" - - val warpText = Renderable.text(text + keybindSuffix, horizontalAlign = RenderUtils.HorizontalAlignment.CENTER) - - config.warpGuiPosition.renderRenderable(warpText, posLabel = "Diana Nearest Warp") - } - - @HandleEvent - fun onKeyPress(event: KeyPressEvent) { - if (event.keyCode != config.keyBindWarp) return - if (warpQueued) return - - if (cannotWarpUntil.isInFuture()) { - GriffinBurrowHelper.addDebug("delaying warp for ${cannotWarpUntil.timeUntil()}") - warpQueued = true - DelayedRun.runDelayed(cannotWarpUntil.timeUntil(), { warp() }) - } else warp() - } - - private fun warp() { - warpQueued = false - if (!DianaApi.isDoingDiana()) return - if (!config.burrowNearestWarp) return - if (Minecraft.getInstance().screen != null) return - val warp = currentWarp ?: return - if (lastWarpTime.passedSince() < 1.seconds) return - - GriffinBurrowHelper.addDebug("warping to $warp count of bezierFitter ${PreciseGuessBurrow.getBezierFitterCount()}") - lastWarpTime = SimpleTimeMark.now() - HypixelCommands.warp(warp.name) - lastWarp = currentWarp - } - - @HandleEvent(onlyOnSkyblock = true) - fun onChat(event: SkyHanniChatEvent.Allow) { - if (event.message != "§cYou haven't unlocked this fast travel destination!") return - if (lastWarpTime.passedSince() > 1.seconds) return - lastWarp?.let { - it.unlocked = false - ChatUtils.chat("Detected not having access to warp point §b${it.displayName}§e!") - ChatUtils.chat("Use §c/shresetburrowwarps §eonce you have activated this travel scroll.") - ChatUtils.chatAndOpenConfig( - "Click Here to permanently ignore this warp.", - SkyHanniMod.feature.event.diana::ignoredWarpsList, - ) - lastWarp = null - currentWarp = null - } - } - - @HandleEvent - fun onWorldChange() { - lastWarp = null - currentWarp = null - } - - @HandleEvent - fun onDebug(event: DebugDataCollectEvent) { - event.title("Diana Burrow Nearest Warp") - - if (!DianaApi.isDoingDiana()) { - event.addIrrelevant("not doing diana") - return - } - if (!config.burrowNearestWarp) { - event.addIrrelevant("disabled in config") - return - } - val target = GriffinBurrowHelper.targetLocation - if (target == null) { - event.addIrrelevant("targetLocation is null") - return - } - - val list = mutableListOf() - shouldUseWarps(target, list) - event.addData(list) - } - - fun shouldUseWarps(target: LorenzVec, debug: MutableList? = null) { - debug?.add("target: ${target.printWithAccuracy(1)}") - val playerLocation = LocationUtils.playerLocation() - debug?.add("playerLocation: ${playerLocation.printWithAccuracy(1)}") - val warpPoint = getNearestWarpPoint(target) ?: run { - debug?.add("no nearest warp point found (everything disabled/not unlocked with tp scrolls)") - return - } - debug?.add("warpPoint: ${warpPoint.displayName}") - - val playerDistance = playerLocation.distance(target) - debug?.add("playerDistance: ${playerDistance.roundTo(1)}") - val warpDistance = warpPoint.distance(target) - debug?.add("warpDistance: ${warpDistance.roundTo(1)}") - val difference = playerDistance - warpDistance - debug?.add("difference: ${difference.roundTo(1)}") - val setWarpPoint = difference > config.warpDistanceDifference - debug?.add("setWarpPoint: $setWarpPoint") - currentWarp = if (setWarpPoint) warpPoint else null - } - - private fun getNearestWarpPoint(location: LorenzVec): WarpPoint? = - WarpPoint.entries.filter { it.unlocked && !it.ignored() }.map { it to it.distance(location) } - .sorted().firstOrNull()?.first - - @HandleEvent - fun onCommandRegistration(event: CommandRegistrationEvent) { - event.registerBrigadier("shresetburrowwarps") { - description = "Manually resetting disabled diana burrow warp points" - category = CommandCategory.USERS_RESET - simpleCallback { - WarpPoint.entries.forEach { point -> point.unlocked = true } - ChatUtils.chat("Reset disabled burrow warps.") - } - } - } - - @HandleEvent - fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(119, "event.diana.inquisitorSharing", "event.diana.rareMobsSharing") { - val sharing = it.asJsonObject - val focus = sharing.remove("focusInquisitor") - sharing.add("focus", focus) - it - } - event.move(119, "event.diana.highlightInquisitors", "event.diana.highlightRareMobs") - - event.transform(119, "event.diana") { element -> - val oldWarps = element.asJsonObject.getAsJsonObject("ignoredWarps") - val newWarps = JsonArray() - - if (oldWarps.getAsJsonPrimitive("crypt")?.asBoolean == true) { - newWarps.add("CRYPT") - } - if (oldWarps.getAsJsonPrimitive("wizard")?.asBoolean == true) { - newWarps.add("WIZARD") - } - if (oldWarps.getAsJsonPrimitive("stonks")?.asBoolean == true) { - newWarps.add("STONKS") - } - newWarps.add("TAYLOR") - element.asJsonObject.add("ignoredWarpsList", newWarps) - element - } - } - - var warpLocationData: Map? = null - - @HandleEvent - fun onRepoReload(event: RepositoryReloadEvent) { - val constant = event.getConstant("Warps") - warpLocationData = constant.warpLocation - } - - enum class WarpPoint( - var unlocked: Boolean = true, - ) { - HUB, - CASTLE, - CRYPT, - DA, - MUSEUM, - WIZARD, - STONKS, - TAYLOR, - ; - - val displayName: String get() { - val locationData = warpLocationData ?: ErrorManager.skyHanniError("repo invalid for diana warp") - for (entry in locationData) { - if (entry.key.equals(this.name, true)) { - return entry.value.displayName - } - } - ErrorManager.skyHanniError("repo invalid for diana warp") - } - - val location: LorenzVec get() { - val locationData = warpLocationData ?: ErrorManager.skyHanniError("repo invalid for diana warp") - for (entry in locationData) { - if (entry.key.equals(this.name, true)) { - return LorenzVec(entry.value.x, entry.value.y, entry.value.z) - } - } - ErrorManager.skyHanniError("repo invalid for diana warp") - } - - private val extraBlocks: Int get() { - val locationData = warpLocationData ?: ErrorManager.skyHanniError("repo invalid for diana warp") - for (entry in locationData) { - if (entry.key.equals(this.name, true)) { - return entry.value.extraDianaWarpBlocks - } - } - ErrorManager.skyHanniError("repo invalid for diana warp") - } - - fun distance(other: LorenzVec): Double = other.distance(location) + extraBlocks - - fun ignored(): Boolean = config.ignoredWarpsList.contains(this) - } -} +// package at.hannibal2.skyhanni.features.event.diana +// +// import at.hannibal2.skyhanni.SkyHanniMod +// import at.hannibal2.skyhanni.api.event.HandleEvent +// import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +// import at.hannibal2.skyhanni.config.commands.CommandCategory +// import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent +// import at.hannibal2.skyhanni.data.IslandType +// import at.hannibal2.skyhanni.data.jsonobjects.repo.WarpLocationData +// import at.hannibal2.skyhanni.data.jsonobjects.repo.WarpsJson +// import at.hannibal2.skyhanni.events.DebugDataCollectEvent +// import at.hannibal2.skyhanni.events.GuiRenderEvent +// import at.hannibal2.skyhanni.events.RepositoryReloadEvent +// import at.hannibal2.skyhanni.events.chat.SkyHanniChatEvent +// import at.hannibal2.skyhanni.events.minecraft.KeyPressEvent +// import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +// import at.hannibal2.skyhanni.test.command.ErrorManager +// import at.hannibal2.skyhanni.utils.ChatUtils +// import at.hannibal2.skyhanni.utils.DelayedRun +// import at.hannibal2.skyhanni.utils.HypixelCommands +// import at.hannibal2.skyhanni.utils.KeyboardManager +// import at.hannibal2.skyhanni.utils.LocationUtils +// import at.hannibal2.skyhanni.utils.LorenzVec +// import at.hannibal2.skyhanni.utils.NumberUtil.roundTo +// import at.hannibal2.skyhanni.utils.RenderUtils +// import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable +// import at.hannibal2.skyhanni.utils.SimpleTimeMark +// import at.hannibal2.skyhanni.utils.collection.CollectionUtils.sorted +// import at.hannibal2.skyhanni.utils.renderables.Renderable +// import at.hannibal2.skyhanni.utils.renderables.primitives.text +// import com.google.gson.JsonArray +// import net.minecraft.client.Minecraft +// import org.lwjgl.glfw.GLFW +// import kotlin.time.Duration +// import kotlin.time.Duration.Companion.milliseconds +// import kotlin.time.Duration.Companion.seconds +// +// @SkyHanniModule +// object BurrowWarpHelper { +// +// private val config get() = SkyHanniMod.feature.event.diana +// +// var currentWarp: WarpPoint? = null +// +// private var lastWarpTime = SimpleTimeMark.farPast() +// private var lastWarp: WarpPoint? = null +// +// private var cannotWarpUntil: SimpleTimeMark = SimpleTimeMark.farPast() +// private var warpQueued = false +// +// fun blockWarp(duration: Duration) { +// val until = SimpleTimeMark.now().plus(duration) +// if (until.minus(cannotWarpUntil) > 0.milliseconds) { +// cannotWarpUntil = until +// } +// } +// +// @HandleEvent(GuiRenderEvent::class, onlyOnIsland = IslandType.HUB) +// fun onRenderOverlay() { +// if (!config.burrowNearestWarp) return +// if (!DianaApi.isDoingDiana()) return +// val warp = currentWarp ?: return +// if (GriffinBurrowHelper.mobAlive) return +// +// val text = "§bWarp to " + warp.displayName +// val keybindSuffix = if (config.keyBindWarp != GLFW.GLFW_KEY_UNKNOWN) { +// val keyName = KeyboardManager.getKeyName(config.keyBindWarp) +// " §7(§ePress $keyName§7)" +// } else "" +// +// val warpText = Renderable.text(text + keybindSuffix, horizontalAlign = RenderUtils.HorizontalAlignment.CENTER) +// +// config.warpGuiPosition.renderRenderable(warpText, posLabel = "Diana Nearest Warp") +// } +// +// @HandleEvent +// fun onKeyPress(event: KeyPressEvent) { +// if (event.keyCode != config.keyBindWarp) return +// if (warpQueued) return +// +// if (cannotWarpUntil.isInFuture()) { +// GriffinBurrowHelper.addDebug("delaying warp for ${cannotWarpUntil.timeUntil()}") +// warpQueued = true +// DelayedRun.runDelayed(cannotWarpUntil.timeUntil(), { warp() }) +// } else warp() +// } +// +// private fun warp() { +// warpQueued = false +// if (!DianaApi.isDoingDiana()) return +// if (!config.burrowNearestWarp) return +// if (Minecraft.getInstance().screen != null) return +// val warp = currentWarp ?: return +// if (lastWarpTime.passedSince() < 1.seconds) return +// +// GriffinBurrowHelper.addDebug("warping to $warp count of bezierFitter ${PreciseGuessBurrow.getBezierFitterCount()}") +// lastWarpTime = SimpleTimeMark.now() +// HypixelCommands.warp(warp.name) +// lastWarp = currentWarp +// } +// +// @HandleEvent(onlyOnSkyblock = true) +// fun onChat(event: SkyHanniChatEvent.Allow) { +// if (event.message != "§cYou haven't unlocked this fast travel destination!") return +// if (lastWarpTime.passedSince() > 1.seconds) return +// lastWarp?.let { +// it.unlocked = false +// ChatUtils.chat("Detected not having access to warp point §b${it.displayName}§e!") +// ChatUtils.chat("Use §c/shresetburrowwarps §eonce you have activated this travel scroll.") +// ChatUtils.chatAndOpenConfig( +// "Click Here to permanently ignore this warp.", +// SkyHanniMod.feature.event.diana::ignoredWarpsList, +// ) +// lastWarp = null +// currentWarp = null +// } +// } +// +// @HandleEvent +// fun onWorldChange() { +// lastWarp = null +// currentWarp = null +// } +// +// @HandleEvent +// fun onDebug(event: DebugDataCollectEvent) { +// event.title("Diana Burrow Nearest Warp") +// +// if (!DianaApi.isDoingDiana()) { +// event.addIrrelevant("not doing diana") +// return +// } +// if (!config.burrowNearestWarp) { +// event.addIrrelevant("disabled in config") +// return +// } +// val target = GriffinBurrowHelper.targetLocation +// if (target == null) { +// event.addIrrelevant("targetLocation is null") +// return +// } +// +// val list = mutableListOf() +// shouldUseWarps(target, list) +// event.addData(list) +// } +// +// fun shouldUseWarps(target: LorenzVec, debug: MutableList? = null) { +// debug?.add("target: ${target.printWithAccuracy(1)}") +// val playerLocation = LocationUtils.playerLocation() +// debug?.add("playerLocation: ${playerLocation.printWithAccuracy(1)}") +// val warpPoint = getNearestWarpPoint(target) ?: run { +// debug?.add("no nearest warp point found (everything disabled/not unlocked with tp scrolls)") +// return +// } +// debug?.add("warpPoint: ${warpPoint.displayName}") +// +// val playerDistance = playerLocation.distance(target) +// debug?.add("playerDistance: ${playerDistance.roundTo(1)}") +// val warpDistance = warpPoint.distance(target) +// debug?.add("warpDistance: ${warpDistance.roundTo(1)}") +// val difference = playerDistance - warpDistance +// debug?.add("difference: ${difference.roundTo(1)}") +// val setWarpPoint = difference > config.warpDistanceDifference +// debug?.add("setWarpPoint: $setWarpPoint") +// currentWarp = if (setWarpPoint) warpPoint else null +// } +// +// private fun getNearestWarpPoint(location: LorenzVec): WarpPoint? = +// WarpPoint.entries.filter { it.unlocked && !it.ignored() }.map { it to it.distance(location) } +// .sorted().firstOrNull()?.first +// +// @HandleEvent +// fun onCommandRegistration(event: CommandRegistrationEvent) { +// event.registerBrigadier("shresetburrowwarps") { +// description = "Manually resetting disabled diana burrow warp points" +// category = CommandCategory.USERS_RESET +// simpleCallback { +// WarpPoint.entries.forEach { point -> point.unlocked = true } +// ChatUtils.chat("Reset disabled burrow warps.") +// } +// } +// } +// +// @HandleEvent +// fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { +// event.move(119, "event.diana.inquisitorSharing", "event.diana.rareMobsSharing") { +// val sharing = it.asJsonObject +// val focus = sharing.remove("focusInquisitor") +// sharing.add("focus", focus) +// it +// } +// event.move(119, "event.diana.highlightInquisitors", "event.diana.highlightRareMobs") +// +// event.transform(119, "event.diana") { element -> +// val oldWarps = element.asJsonObject.getAsJsonObject("ignoredWarps") +// val newWarps = JsonArray() +// +// if (oldWarps.getAsJsonPrimitive("crypt")?.asBoolean == true) { +// newWarps.add("CRYPT") +// } +// if (oldWarps.getAsJsonPrimitive("wizard")?.asBoolean == true) { +// newWarps.add("WIZARD") +// } +// if (oldWarps.getAsJsonPrimitive("stonks")?.asBoolean == true) { +// newWarps.add("STONKS") +// } +// newWarps.add("TAYLOR") +// element.asJsonObject.add("ignoredWarpsList", newWarps) +// element +// } +// } +// +// var warpLocationData: Map? = null +// +// @HandleEvent +// fun onRepoReload(event: RepositoryReloadEvent) { +// val constant = event.getConstant("Warps") +// warpLocationData = constant.warpLocation +// } +// +// enum class WarpPoint( +// var unlocked: Boolean = true, +// ) { +// HUB, +// CASTLE, +// CRYPT, +// DA, +// MUSEUM, +// WIZARD, +// STONKS, +// TAYLOR, +// ; +// +// val displayName: String get() { +// val locationData = warpLocationData ?: ErrorManager.skyHanniError("repo invalid for diana warp") +// for (entry in locationData) { +// if (entry.key.equals(this.name, true)) { +// return entry.value.displayName +// } +// } +// ErrorManager.skyHanniError("repo invalid for diana warp") +// } +// +// val location: LorenzVec get() { +// val locationData = warpLocationData ?: ErrorManager.skyHanniError("repo invalid for diana warp") +// for (entry in locationData) { +// if (entry.key.equals(this.name, true)) { +// return LorenzVec(entry.value.x, entry.value.y, entry.value.z) +// } +// } +// ErrorManager.skyHanniError("repo invalid for diana warp") +// } +// +// private val extraBlocks: Int get() { +// val locationData = warpLocationData ?: ErrorManager.skyHanniError("repo invalid for diana warp") +// for (entry in locationData) { +// if (entry.key.equals(this.name, true)) { +// return entry.value.extraDianaWarpBlocks +// } +// } +// ErrorManager.skyHanniError("repo invalid for diana warp") +// } +// +// fun distance(other: LorenzVec): Double = other.distance(location) + extraBlocks +// +// fun ignored(): Boolean = config.ignoredWarpsList.contains(this) +// } +// } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt index 92677cb785f9..e68b5acc5158 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent import at.hannibal2.skyhanni.config.commands.brigadier.BrigadierArguments import at.hannibal2.skyhanni.data.ElectionCandidate import at.hannibal2.skyhanni.data.EntityMovementData +import at.hannibal2.skyhanni.data.IslandGraphs import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.title.TitleManager import at.hannibal2.skyhanni.events.BlockClickEvent @@ -222,15 +223,19 @@ object GriffinBurrowHelper { val newLocation = calculateNewTarget() if (targetLocation != newLocation) { targetLocation = newLocation - // TODO: add island graphs here some day when the hub is fully added in the graph -// newLocation?.let { -// IslandGraphs.find(it) -// } - } - - if (config.burrowNearestWarp) { - targetLocation?.let { - BurrowWarpHelper.shouldUseWarps(it) + newLocation?.let { + IslandGraphs.pathFind(it.add(y = 2), "Diana Target") { + isEnabled() && targetLocation == it + } + } + } else { + newLocation?.let { + val addTwo = it.add(y = 2) + if (IslandGraphs.isActive(addTwo, "Diana Target")) { + IslandGraphs.pathFind(addTwo, "Diana Target") { + isEnabled() && targetLocation == it + } + } } } @@ -242,8 +247,6 @@ object GriffinBurrowHelper { if (!toDelete.isEmpty()) update() } - // TODO add option to only focus on last guess - highly requested method that is less optimal for money per hour. users choice - // TODO pathfind alg / check closest to any warp point private fun calculateNewTarget(): LorenzVec? { val locations = mutableListOf() @@ -257,8 +260,7 @@ object GriffinBurrowHelper { allGuesses.forEach { locations.add(it.getCurrent()) } locations.addAll(RareMobWaypointShare.waypoints.values.map { it.location }) } - val newLocation = locations.minByOrNull { it.distanceToPlayer() } - return newLocation + return locations.minByOrNull { it.distanceToPlayer() } } fun showUseSpadeTitle() { @@ -398,7 +400,6 @@ object GriffinBurrowHelper { GriffinBurrowParticleFinder.reset() mobAlive = false - BurrowWarpHelper.currentWarp = null if (isEnabled()) { update() } @@ -452,25 +453,16 @@ object GriffinBurrowHelper { renderRareMobs(event, playerLocation) } - val currentWarp = BurrowWarpHelper.currentWarp if (config.lineToNext) { - var color: ChromaColour? - val renderLocation = if (currentWarp != null) { - color = LorenzColor.AQUA.toChromaColor() - currentWarp.location - } else { - color = if (shouldFocusOnRareMob) LorenzColor.LIGHT_PURPLE.toChromaColor() else LorenzColor.WHITE.toChromaColor() - targetLocation?.blockCenter() ?: return - } + var color = if (shouldFocusOnRareMob) LorenzColor.LIGHT_PURPLE.toChromaColor() else LorenzColor.WHITE.toChromaColor() + val renderLocation = targetLocation?.blockCenter() ?: return val targetType = getGuess(targetLocation)?.burrowType val lineWidth = if (targetType != null && targetType != BurrowType.UNKNOWN) { color = targetType.color 3 } else 2 - if (currentWarp == null) { - event.drawLineToCrosshair(renderLocation, color, lineWidth, false) - } + event.drawLineToCrosshair(renderLocation, color, lineWidth, false) } if (RareMobWaypointShare.waypoints.isNotEmpty() && config.rareMobsSharing.focus) { @@ -484,7 +476,7 @@ object GriffinBurrowHelper { val location = target.getCurrent() val distance = location.distance(playerLocation) val text = when (target.burrowType) { - BurrowType.UNKNOWN -> "${if (currentWarp != null) "§b" else "§f"}Guess" + BurrowType.UNKNOWN -> "${"§f"}Guess" else -> target.burrowType.text } @@ -534,7 +526,7 @@ object GriffinBurrowHelper { if (burrowType == BurrowType.UNKNOWN) { if (!config.guess) return else { - val textColor = if (BurrowWarpHelper.currentWarp != null && targetLocation == location) "§b" else "§f" + val textColor = "§f" text = "${textColor}Guess" if (distance > 5) { val formattedDistance = distance.toInt().addSeparators() diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/PreciseGuessBurrow.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/PreciseGuessBurrow.kt index 1599e6b20150..a3618ded2874 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/PreciseGuessBurrow.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/PreciseGuessBurrow.kt @@ -56,7 +56,8 @@ object PreciseGuessBurrow { if (bezierFitter.count() < 6) { val duration = (6 - bezierFitter.count()) * 100 - BurrowWarpHelper.blockWarp(duration.milliseconds) + // why did we block it here? should be generic now +// BurrowWarpHelper.blockWarp(duration.milliseconds) } val guessPosition = guessBurrowLocation() ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/test/graph/GraphEditorBugFinder.kt b/src/main/java/at/hannibal2/skyhanni/test/graph/GraphEditorBugFinder.kt index 07a82f1802a9..fc033f6cb4ff 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/graph/GraphEditorBugFinder.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/graph/GraphEditorBugFinder.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.data.IslandGraphs import at.hannibal2.skyhanni.data.IslandGraphs.pathFind import at.hannibal2.skyhanni.data.model.graph.Graph import at.hannibal2.skyhanni.data.model.graph.GraphNode +import at.hannibal2.skyhanni.data.model.graph.GraphNodeTag import at.hannibal2.skyhanni.events.minecraft.SkyHanniRenderWorldEvent import at.hannibal2.skyhanni.features.misc.pathfind.IslandAreaBackend.getAreaTag import at.hannibal2.skyhanni.features.misc.pathfind.NavigationHelper @@ -34,6 +35,7 @@ object GraphEditorBugFinder { checkConflictingTags(graph, errorsInWorld) checkConflictingAreas(graph, errorsInWorld) checkMissingData(graph, errorsInWorld) + checkDeprecatedTags(graph, errorsInWorld) this.errorsInWorld = errorsInWorld errorsInWorld.keys.minByOrNull { @@ -41,6 +43,23 @@ object GraphEditorBugFinder { }?.pathFind("Graph Editor Bug", Color.RED, condition = { isEnabled() }) } + private fun checkDeprecatedTags( + graph: Graph, + errorsInWorld: MutableMap, + ) { + for (node in graph) { + if (node.hasTag(GraphNodeTag.TELEPORT)) { + errorsInWorld[node] = "deprecated teleport node" + } + + if (node.hasTag(GraphNodeTag.WARP)) { + if (node.name?.startsWith("/") == false) { + errorsInWorld[node] = "invalid warp name" + } + } + } + } + private fun checkMissingData(graph: Graph, errorsInWorld: MutableMap) { for (node in graph) { val nameNull = node.name.isNullOrBlank() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GraphUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GraphUtils.kt index 6814f96c2820..6b0c173b8c79 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/GraphUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/GraphUtils.kt @@ -177,6 +177,7 @@ object GraphUtils { fun GenericNode.distanceToPlayer(): Double = position.distance(playerPosition) fun GenericNode.distanceSqToPlayer(): Double = position.distanceSq(playerPosition) fun distanceSqToPlayer(location: LorenzVec) = location.distanceSq(playerPosition) + fun GraphNode.distanceToNode(other: GraphNode): Double = findShortestDistance(this, other) interface GenericNode { val position: LorenzVec