Skip to content

Commit

Permalink
Fix: Carnival Area (#2843)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
hannibal002 and hannibal002 authored Oct 28, 2024
1 parent 2a8e5cf commit 55ed913
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import at.hannibal2.skyhanni.api.event.SkyHanniEvent

// Detect area changes by looking at the scoreboard.
class ScoreboardAreaChangeEvent(val area: String, val previousArea: String?) : SkyHanniEvent()
class GraphAreaChangeEvent(val area: String, val previousArea: String?) : SkyHanniEvent()
class GraphAreaChangeEvent(val area: String, val previousArea: String?, val onlyInternal: Boolean) : SkyHanniEvent()
21 changes: 13 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/features/misc/IslandAreas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object IslandAreas {
display = null
targetNode = null
hasMoved = true
updateArea("no_area")
updateArea("no_area", onlyInternal = true)
}

fun nodeMoved() {
Expand Down Expand Up @@ -162,24 +162,26 @@ object IslandAreas {
val distance = difference.roundTo(0).toInt()
val text = "$coloredName§7: §e$distance$suffix"

val isConfigVisible = node.getAreaTag(useConfig = true) != null
if (!foundCurrentArea) {
foundCurrentArea = true

val inAnArea = name != "no_area"
val inAnArea = name != "no_area" && isConfigVisible
if (config.pathfinder.includeCurrentArea.get()) {
if (inAnArea) {
addSearchString("§eCurrent area: $coloredName")
} else {
addSearchString("§7Not in an area.")
}
}
updateArea(name)
updateArea(name, onlyInternal = !isConfigVisible)

addSearchString("§eAreas nearby:")
continue
}

if (name == "no_area") continue
if (!isConfigVisible) continue
foundAreas++

add(
Expand Down Expand Up @@ -221,18 +223,20 @@ object IslandAreas {
}
}

private fun updateArea(name: String) {
private fun updateArea(name: String, onlyInternal: Boolean) {
if (name != currentAreaName) {
val oldArea = currentAreaName
currentAreaName = name
GraphAreaChangeEvent(name, oldArea).post()
GraphAreaChangeEvent(name, oldArea, onlyInternal).post()
}
}

@HandleEvent
fun onAreaChange(event: GraphAreaChangeEvent) {
val name = event.area
val inAnArea = name != "no_area"
// when this is a small area and small areas are disabled via config
if (event.onlyInternal) return
if (inAnArea && config.enterTitle) {
LorenzUtils.sendTitle("§aEntered $name!", 3.seconds)
}
Expand All @@ -247,7 +251,8 @@ object IslandAreas {
if (name == currentAreaName) continue
if (name == "no_area") continue
val position = node.position
val color = node.getAreaTag()?.color?.getChatColor().orEmpty()
val areaTag = node.getAreaTag(useConfig = true) ?: continue
val color = areaTag.color.getChatColor()
if (!position.canBeSeen(40.0)) return
event.drawDynamicText(position, color + name, 1.5)
}
Expand All @@ -269,8 +274,8 @@ object IslandAreas {
private val allAreas = listOf(GraphNodeTag.AREA, GraphNodeTag.SMALL_AREA)
private val onlyLargeAreas = listOf(GraphNodeTag.AREA)

fun GraphNode.getAreaTag(ignoreConfig: Boolean = false): GraphNodeTag? = tags.firstOrNull {
it in (if (config.includeSmallAreas || ignoreConfig) allAreas else onlyLargeAreas)
fun GraphNode.getAreaTag(useConfig: Boolean = false): GraphNodeTag? = tags.firstOrNull {
it in (if (config.includeSmallAreas || !useConfig) allAreas else onlyLargeAreas)
}

private fun setTarget(node: GraphNode) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/test/DebugCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.repo.RepoManager
import at.hannibal2.skyhanni.data.repo.RepoManager.Companion.hasDefaultSettings
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.features.misc.IslandAreas
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
Expand Down Expand Up @@ -127,7 +128,9 @@ object DebugCommand {
event.addIrrelevant {
add("on Hypixel SkyBlock")
add("skyBlockIsland: ${LorenzUtils.skyBlockIsland}")
add("skyBlockArea: '${LorenzUtils.skyBlockArea}'")
add("skyBlockArea:")
add(" scoreboard: '${LorenzUtils.skyBlockArea}'")
add(" graph network: '${IslandAreas.currentAreaName}'")
add("isOnAlphaServer: '${LorenzUtils.isOnAlphaServer}'")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object GraphEditorBugFinder {

val nearestArea = mutableMapOf<GraphNode, GraphNode>()
for (node in nodes) {
val pathToNearestArea = GraphUtils.findFastestPath(node) { it.getAreaTag(ignoreConfig = true) != null }?.first
val pathToNearestArea = GraphUtils.findFastestPath(node) { it.getAreaTag() != null }?.first
if (pathToNearestArea == null) {
continue
}
Expand All @@ -56,7 +56,7 @@ object GraphEditorBugFinder {
for (neighbour in node.neighbours.keys) {
val neighbouringAreaNode = nearestArea[neighbour]?.name ?: continue
if (neighbouringAreaNode == areaNode) continue
if ((null == node.getAreaTag(ignoreConfig = true))) {
if ((null == node.getAreaTag())) {
bugs++
errorsInWorld[node] = "§cConflicting areas $areaNode and $neighbouringAreaNode"
}
Expand Down

0 comments on commit 55ed913

Please sign in to comment.