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(