exclude dead entities from auto-attack target selection

This commit is contained in:
2025-01-23 11:17:16 +09:00
parent 15e72a9e10
commit 55e5e8117c
5 changed files with 58 additions and 85 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ export default class Ability {
const entities = projectile.game?.entities ?? []
const pos = projectile.position
projectile.despawn()
const nearbyDeadTeammates = entities.filter((it) => it.dead && it.team == team)
const nearbyDeadTeammates = entities.filter((it) => it.dead && it.team == team && it.distanceTo(pos) <= ability.radius)
const closestDeadTeammate = nearbyDeadTeammates.reduce((e1, e2) => (e1?.distanceTo(pos) ?? Infinity) < e2.distanceTo(pos) ? e1 : e2, null)
if (closestDeadTeammate != null) {
closestDeadTeammate.revive(closestDeadTeammate.maxHealth / 4)
+2 -2
View File
@@ -300,8 +300,8 @@ export default class Entity {
const entities = this.game?.entities
if (entities == null) { return }
const targetsInRange = targetAllies
? entities.filter((it) => this.team == it.team && it.distanceTo(cursor) <= range + this.radius + it.radius)
: entities.filter((it) => this.team != it.team && it.distanceTo(cursor) <= range + this.radius + it.radius)
? entities.filter((it) => !it.dead && this.team == it.team && it.distanceTo(cursor) <= range + this.radius + it.radius)
: entities.filter((it) => !it.dead && this.team != it.team && it.distanceTo(cursor) <= range + this.radius + it.radius)
if (targetsInRange.length < 1) { return }
+1 -1
View File
@@ -41,7 +41,7 @@ export default class Game {
if (options.action == 'attack') { entity.attackAction(new Vector2(options.x, options.y)) }
if (options.action == 'cast') { entity.castAction(options.slot, new Vector2(options.x, options.y)) }
if (options.action == 'halt') { entity.haltAction(), delay }
if (options.action == 'halt') { entity.haltAction() }
if (options.action == 'stop') { entity.stopAction() }
if (options.action == 'move') { entity.moveAction(new Vector2(options.x, options.y)) }
}