|
|
|
@ -19,7 +19,7 @@ import net.runelite.api.coords.LocalPoint
|
|
|
|
|
import net.runelite.api.CollisionDataFlag
|
|
|
|
|
import net.runelite.api.Tile
|
|
|
|
|
|
|
|
|
|
import kotlin.math.abs
|
|
|
|
|
import kotlin.math.min
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draws an overlay based on the Old School RuneScape pathfinding
|
|
|
|
@ -35,19 +35,19 @@ typealias CollisionFlags = Int
|
|
|
|
|
|
|
|
|
|
fun buildPath(
|
|
|
|
|
backEdges: Map<ScenePoint, ScenePoint>,
|
|
|
|
|
_current: ScenePoint
|
|
|
|
|
): Sequence<ScenePoint> {
|
|
|
|
|
var current = _current
|
|
|
|
|
end: ScenePoint
|
|
|
|
|
): List<ScenePoint> {
|
|
|
|
|
val list = mutableListOf<ScenePoint>()
|
|
|
|
|
var current: ScenePoint? = end
|
|
|
|
|
while (current != null) {
|
|
|
|
|
list.add(current)
|
|
|
|
|
|
|
|
|
|
current = backEdges.get(current)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return generateSequence({
|
|
|
|
|
val ret = current
|
|
|
|
|
current = when (val next = backEdges.get(current)) {
|
|
|
|
|
null -> return@generateSequence null
|
|
|
|
|
else -> next
|
|
|
|
|
}
|
|
|
|
|
list.reverse()
|
|
|
|
|
|
|
|
|
|
return@generateSequence ret
|
|
|
|
|
})
|
|
|
|
|
return list
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun findPath(
|
|
|
|
@ -55,7 +55,7 @@ fun findPath(
|
|
|
|
|
to: ScenePoint,
|
|
|
|
|
collisionFlags: Array<IntArray>,
|
|
|
|
|
tiles: Array<Array<Tile?>>,
|
|
|
|
|
): Sequence<ScenePoint>? {
|
|
|
|
|
): List<ScenePoint>? {
|
|
|
|
|
|
|
|
|
|
// A basic breadth-first search, taking into account OSRS movement
|
|
|
|
|
// rules
|
|
|
|
@ -270,6 +270,52 @@ fun neighbors(
|
|
|
|
|
).filter({ n -> n != null }).map({ n -> n!! })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun checkpointTiles(tiles: List<ScenePoint>): Set<ScenePoint> {
|
|
|
|
|
when (tiles.size) {
|
|
|
|
|
0 -> return emptySet()
|
|
|
|
|
1 -> return setOf(tiles[0])
|
|
|
|
|
2 -> {
|
|
|
|
|
return setOf(tiles[0], tiles[1])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val delta = { a: ScenePoint, b: ScenePoint ->
|
|
|
|
|
Pair(a.getX() - b.getX(), a.getY() - b.getY())
|
|
|
|
|
}
|
|
|
|
|
val checkpoints = mutableSetOf<ScenePoint>()
|
|
|
|
|
var idx = 0
|
|
|
|
|
var currentDelta = Pair(0, 0)
|
|
|
|
|
while (idx < tiles.size) {
|
|
|
|
|
val a = tiles[idx - 1]
|
|
|
|
|
val b = tiles[idx]
|
|
|
|
|
val d = delta(a, b)
|
|
|
|
|
|
|
|
|
|
if (!d.equals(currentDelta)) {
|
|
|
|
|
checkpoints.add(a)
|
|
|
|
|
currentDelta = d
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
idx += 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return checkpoints
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun runningPath(tiles: List<ScenePoint>): List<ScenePoint> {
|
|
|
|
|
val list = mutableListOf<ScenePoint>()
|
|
|
|
|
|
|
|
|
|
var current: Int = 0
|
|
|
|
|
while (current < tiles.size) {
|
|
|
|
|
list.add(tiles[current])
|
|
|
|
|
current += 2
|
|
|
|
|
}
|
|
|
|
|
if ((tiles.size > 1) && ((tiles.size % 2) == 0)) {
|
|
|
|
|
list.add(tiles.last())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Overlay
|
|
|
|
|
@Inject constructor(
|
|
|
|
|
val client: Client,
|
|
|
|
@ -316,7 +362,7 @@ class Overlay
|
|
|
|
|
hoveredTile,
|
|
|
|
|
collisionFlags,
|
|
|
|
|
tiles,
|
|
|
|
|
)?.toList()
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
@ -336,7 +382,7 @@ class Overlay
|
|
|
|
|
destinationTile,
|
|
|
|
|
collisionFlags,
|
|
|
|
|
tiles,
|
|
|
|
|
)?.toList()
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
@ -357,12 +403,21 @@ class Overlay
|
|
|
|
|
false -> null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doPaint(
|
|
|
|
|
gfx,
|
|
|
|
|
destinationPathTiles,
|
|
|
|
|
hoveredPathTiles,
|
|
|
|
|
overlappingTiles,
|
|
|
|
|
)
|
|
|
|
|
if (this.isRunning()) {
|
|
|
|
|
doPaint(
|
|
|
|
|
gfx,
|
|
|
|
|
destinationPathTiles?.let({ runningPath(it) }),
|
|
|
|
|
hoveredPathTiles?.let({ runningPath(it) }),
|
|
|
|
|
overlappingTiles,
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
doPaint(
|
|
|
|
|
gfx,
|
|
|
|
|
destinationPathTiles,
|
|
|
|
|
hoveredPathTiles,
|
|
|
|
|
overlappingTiles,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
@ -440,9 +495,16 @@ class Overlay
|
|
|
|
|
borderColor: Color,
|
|
|
|
|
borderWidth: Double,
|
|
|
|
|
) {
|
|
|
|
|
var local = LocalPoint.fromScene(tile.getX(), tile.getY())
|
|
|
|
|
var poly = Perspective.getCanvasTilePoly(client, local)
|
|
|
|
|
val local = LocalPoint.fromScene(tile.getX(), tile.getY())
|
|
|
|
|
val poly = Perspective.getCanvasTilePoly(client, local)
|
|
|
|
|
|
|
|
|
|
OverlayUtil.renderPolygon(gfx, poly, borderColor, Color(0, 0, 0, 0), BasicStroke(borderWidth.toFloat()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun isRunning(): Boolean {
|
|
|
|
|
val willRun = client.getVarpValue(173) == 1
|
|
|
|
|
// TODO: handle ctrl-clicks
|
|
|
|
|
|
|
|
|
|
return willRun
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|