Refactored components of the ScriptAPI to more efficiently utilize pathfinding
Implemented a global limit on pathfinding distance (server.max_pathfind_dist) Pathfinding limit is enforced at the packet level as well as elsewhere (ContentAPI, etc)
This commit is contained in:
@@ -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,15 +453,22 @@ object PacketProcessor {
|
||||
//there's more data in this packet, we're just not using it
|
||||
}
|
||||
|
||||
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()
|
||||
if (canWalk && player.interfaceManager.hasChatbox() && !player.interfaceManager.chatbox.definition.isWalkable)
|
||||
player.interfaceManager.closeChatbox()
|
||||
|
||||
if (!canWalk || !player.dialogueInterpreter.close()) {
|
||||
player.debug("[WALK ACTION]-- NO HANDLE: PLAYER LOCKED OR INTERFACES SAY NO")
|
||||
player.debug("[WALK ACTION]-- Action canceled. Either player is locked, interfaces can't close, or distance is beyond server pathfinding limit.")
|
||||
return sendClearMinimap(player)
|
||||
}
|
||||
|
||||
@@ -474,7 +482,7 @@ object PacketProcessor {
|
||||
player.faceLocation(null)
|
||||
player.scripts.reset()
|
||||
|
||||
player.pulseManager.run(object : MovementPulse(player, Location.create(x,y,player.location.z), isRunning) {
|
||||
player.pulseManager.run(object : MovementPulse(player, loc, isRunning) {
|
||||
override fun pulse(): Boolean {
|
||||
if (isRunning)
|
||||
player.walkingQueue.isRunning = false
|
||||
@@ -798,4 +806,4 @@ object PacketProcessor {
|
||||
}
|
||||
|
||||
const val BASE_CHAT_CUTOFF = 81
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user