mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-10-18 08:02:56 -04:00
Fixed some weird behavior with combat movement
This commit is contained in:
@@ -59,6 +59,7 @@ class NpcCombatMode(obj: AIObject) : NpcMode(obj) {
|
||||
private val targets = CopyOnWriteArraySet<CreatureObject>()
|
||||
private val iteration = AtomicLong(0)
|
||||
private val npcRunSpeed = PswgDatabase.config.getDouble(this, "npcRunSpeed", 9.0)
|
||||
private var isMoving = false
|
||||
|
||||
private val primaryTarget: CreatureObject? // Don't attack if they're already dead
|
||||
get() = targets.stream()
|
||||
@@ -135,7 +136,7 @@ class NpcCombatMode(obj: AIObject) : NpcMode(obj) {
|
||||
val actionRange = attackRange / 2
|
||||
val lineOfSight = obj.isLineOfSight(target)
|
||||
|
||||
if (ai.walkSpeed > 0 && (targetDistance > actionRange || !lineOfSight)) {
|
||||
if (ai.walkSpeed > 0 && (targetDistance > attackRange || !lineOfSight)) {
|
||||
val targetLocation = target.location
|
||||
val targetHeading = target.location.yaw + ThreadLocalRandom.current().nextDouble(-75.0, 75.0)
|
||||
val targetRange = actionRange / 2
|
||||
@@ -143,6 +144,12 @@ class NpcCombatMode(obj: AIObject) : NpcMode(obj) {
|
||||
val moveZ = targetLocation.z + cos(Math.toRadians(targetHeading)) * targetRange
|
||||
val moveHeading = targetLocation.getHeadingTo(Point3D(moveX, targetLocation.y, moveZ)) + 180
|
||||
StartNpcMovementIntent(obj, target.effectiveParent, Location.builder(targetLocation).setX(moveX).setZ(moveZ).setHeading(moveHeading).build(), npcRunSpeed).broadcast()
|
||||
isMoving = true
|
||||
} else {
|
||||
if (ai.walkSpeed > 0 && isMoving) {
|
||||
StopNpcMovementIntent(obj).broadcast()
|
||||
isMoving = false
|
||||
}
|
||||
}
|
||||
|
||||
if (lineOfSight && iteration.get() % 4 == 0L) {
|
||||
|
||||
Reference in New Issue
Block a user