From bee7395f3ec5fdcd097bd69c12feb95dfc69d0f1 Mon Sep 17 00:00:00 2001 From: dam <27978131-real_damighty@users.noreply.gitlab.com> Date: Wed, 6 May 2026 20:08:13 +0300 Subject: [PATCH] Smaller performance improvements --- .../entity/combat/CombatMovementIntents.kt | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Server/src/main/core/game/node/entity/combat/CombatMovementIntents.kt b/Server/src/main/core/game/node/entity/combat/CombatMovementIntents.kt index bd6fd3690..2a8caded8 100644 --- a/Server/src/main/core/game/node/entity/combat/CombatMovementIntents.kt +++ b/Server/src/main/core/game/node/entity/combat/CombatMovementIntents.kt @@ -175,16 +175,16 @@ object CombatMovementIntents { reservedTiles.addAll(occupiedTiles(attacker, attacker.location)) return } - - val candidates = movementDestinationsFor(attacker, target, targetLocation) - val standingOnCandidate = candidates.any { it.location == attacker.location } - if (standingOnCandidate && canAttackFrom(attacker, target, attacker.location, targetLocation)) { + if (canAttackFrom(attacker, target, attacker.location, targetLocation)) { attacker.walkingQueue.reset() attacker.face(target) projectedLocations[attacker] = attacker.location reservedTiles.addAll(occupiedTiles(attacker, attacker.location)) return } + + val candidates = movementDestinationsFor(attacker, target, targetLocation) + val standingOnCandidate = candidates.any { it.location == attacker.location } val projectedAttackerLocation = CombatMovementPlanner.predictTargetLocations(attacker).lastOrNull() if (projectedAttackerLocation != null && canAttackFrom(attacker, target, projectedAttackerLocation, targetLocation)) { attacker.face(target) @@ -348,12 +348,23 @@ object CombatMovementIntents { } } } - return tiles.filter { hasProjectileLineOfSight(it, attacker.size(), target, targetLocation) }.sortedWith( + tiles.sortWith( compareBy { it.getDistance(attacker.location) } .thenBy { it.getDistance(closestOccupiedTile(target, targetLocation, it)) } .thenBy { it.x } .thenBy { it.y } - ).take(MAX_RANGED_APPROACH_CANDIDATES) + ) + val attackTiles = ArrayList(minOf(MAX_RANGED_APPROACH_CANDIDATES, tiles.size)) + for (tile in tiles) { + if (!hasProjectileLineOfSight(tile, attacker.size(), target, targetLocation)) { + continue + } + attackTiles.add(tile) + if (attackTiles.size >= MAX_RANGED_APPROACH_CANDIDATES) { + break + } + } + return attackTiles } private fun canAttackFromMelee(