mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 08:39:17 +00:00
Optimise Mob.walkTo for paths that require no verification
This commit is contained in:
@@ -2,7 +2,10 @@ package org.apollo.plugin.entity.walkto
|
|||||||
|
|
||||||
import org.apollo.game.model.Direction
|
import org.apollo.game.model.Direction
|
||||||
import org.apollo.game.model.Position
|
import org.apollo.game.model.Position
|
||||||
import org.apollo.game.model.entity.*
|
import org.apollo.game.model.entity.Entity
|
||||||
|
import org.apollo.game.model.entity.Mob
|
||||||
|
import org.apollo.game.model.entity.Npc
|
||||||
|
import org.apollo.game.model.entity.Player
|
||||||
import org.apollo.game.model.entity.obj.GameObject
|
import org.apollo.game.model.entity.obj.GameObject
|
||||||
import org.apollo.game.model.entity.path.SimplePathfindingAlgorithm
|
import org.apollo.game.model.entity.path.SimplePathfindingAlgorithm
|
||||||
|
|
||||||
@@ -41,7 +44,7 @@ fun Mob.walkBehind(target: Mob) {
|
|||||||
walkTo(target, target.lastDirection.opposite())
|
walkTo(target, target.lastDirection.opposite())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Mob.walkTo(target: Position, positionPredicate: (Position) -> Boolean = { true }) {
|
fun Mob.walkTo(target: Position, positionPredicate: ((Position) -> Boolean)? = null) {
|
||||||
if (position == target) {
|
if (position == target) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -49,11 +52,15 @@ fun Mob.walkTo(target: Position, positionPredicate: (Position) -> Boolean = { tr
|
|||||||
val pathfinder = SimplePathfindingAlgorithm(world.collisionManager)
|
val pathfinder = SimplePathfindingAlgorithm(world.collisionManager)
|
||||||
val path = pathfinder.find(position, target)
|
val path = pathfinder.find(position, target)
|
||||||
|
|
||||||
for (step in path) {
|
if (positionPredicate == null) {
|
||||||
if (!positionPredicate.invoke(step)) {
|
path.forEach(walkingQueue::addStep)
|
||||||
return
|
} else {
|
||||||
}
|
for (step in path) {
|
||||||
|
if (!positionPredicate.invoke(step)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
walkingQueue.addStep(step)
|
walkingQueue.addStep(step)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user