Truncate paths when possible

This commit is contained in:
ceikry 2023-04-23 09:32:20 -05:00
parent 4c22977a7d
commit f7b627d1ab
2 changed files with 17 additions and 6 deletions

View file

@ -97,14 +97,18 @@ internal constructor() : Pathfinder() {
}
}
override fun find(start: Location?, moverSize: Int, end: Location?, sizeX: Int, sizeY: Int, rotation: Int, type: Int, walkingFlag: Int, near: Boolean, clipMaskSupplier: ClipMaskSupplier?): Path {
override fun find(start: Location?, moverSize: Int, dest: Location?, sizeX: Int, sizeY: Int, rotation: Int, type: Int, walkingFlag: Int, near: Boolean, clipMaskSupplier: ClipMaskSupplier?): Path {
reset()
assert(start != null && end != null)
var vec = Vector.betweenLocs(end!!, start!!)
assert(start != null && dest != null)
var vec = Vector.betweenLocs(start!!, dest!!)
var mag = kotlin.math.floor(vec.magnitude())
var end = dest!!
if (mag > ServerConstants.MAX_PATHFIND_DISTANCE) {
try {
throw Exception("Pathfinding distance exceeds server max! -> " + mag.toString() + " {" + start + "->" + end + "}")
if (mag < 50.0) { //truncate the path if it's realistically long
vec = vec.normalized() * (ServerConstants.MAX_PATHFIND_DISTANCE - 1)
end = start!!.transform(vec)
} else throw Exception("Pathfinding distance exceeds server max! -> " + mag.toString() + " {" + start + "->" + end + "}")
} catch (e: Exception) {
e.printStackTrace()
}

View file

@ -55,6 +55,7 @@ import core.net.packet.`in`.Packet
import core.net.packet.`in`.RunScript
import core.tools.Log
import core.worker.ManagementEvents
import core.api.utils.Vector
import java.io.PrintWriter
import java.io.StringWriter
import java.lang.Math.min
@ -452,8 +453,14 @@ object PacketProcessor {
//there's more data in this packet, we're just not using it
}
val loc = Location.create(x,y,player.location.z)
var canWalk = !player.locks.isMovementLocked && player.location.withinDistance(loc, ServerConstants.MAX_PATHFIND_DISTANCE)
var loc = Location.create(x,y,player.location.z)
var canWalk = !player.locks.isMovementLocked
val vec = Vector.betweenLocs(player.location, loc)
if (vec.magnitude() > ServerConstants.MAX_PATHFIND_DISTANCE) {
val newVec = vec.normalized() * (ServerConstants.MAX_PATHFIND_DISTANCE - 1)
loc = player.location.transform(newVec)
}
if (canWalk && player.interfaceManager.isOpened && !player.interfaceManager.opened.definition.isWalkable)
canWalk = canWalk && player.interfaceManager.close()