mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-21 09:02:07 -07:00
Truncate paths when possible
This commit is contained in:
parent
4c22977a7d
commit
f7b627d1ab
2 changed files with 17 additions and 6 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue