fix auto-attack targeting

This commit is contained in:
2025-01-13 11:45:26 +09:00
parent 49a4d3e924
commit 03bbea4862
8 changed files with 32 additions and 134 deletions
+14 -19
View File
@@ -27,6 +27,7 @@ export default class Entity {
#dest = null
#game = null
#logic = null
#move = false
#path = []
#position = new Vector2()
#scheduledPathfinding = null
@@ -87,7 +88,7 @@ export default class Entity {
this.moveAction(x, y, true)
}
castAction(slot, x, y, clearDestination = true) {
castAction(slot, x, y, halt = true) {
const ability = this.abilities[slot]
if (this.casting != null) {
@@ -99,8 +100,8 @@ export default class Entity {
return false
}
if (clearDestination) {
this.#dest = null
if (halt) {
this.#move = false
}
const cursor = new Vector2(x, y)
@@ -117,21 +118,22 @@ export default class Entity {
}
haltAction() {
this.#dest = null
this.#move = false
}
moveAction(x, y, attack = false) {
this.#attack = attack
if (this.casting != null && (!this.#attack || this.casting.ability.id != this.abilities[0].id)) {
this.casting = null
}
this.#attack = attack
this.#move = true
this.#dest = SATX.fixCollisions(new Vector2(x, y), this.collidables(), this.radius, this.game?.width, this.game?.height)
}
stopAction() {
this.casting = null
this.#dest = null
this.#move = true
this.#attack = false
}
@@ -160,14 +162,6 @@ export default class Entity {
return entityColliders.concat(terrainColliders)
}
// DEPRECATED: hulls were a failed concept for position fixing
collidableHulls() {
const entityColliders = (this.game?.entities ?? []).filter((e) => e.id != this.id).map((e) => e.collider)
const terrainColliders = (this.game?.terrains ?? []).map((t) => t.hull)
return entityColliders.concat(terrainColliders)
}
cooldown(id) {
this.cooldowns[id] = this.game?.currentTick ?? 0
}
@@ -207,7 +201,7 @@ export default class Entity {
this.fixPosition()
}
takeStep(distanceTraveled = 0) {
move(distanceTraveled = 0) {
if (this.casting != null) { return false }
if (this.#attack && this.game?.entities.some((e) => e.team != this.team && e.position.clone().sub(this.position).length() < this.abilities[0].range)) {
@@ -221,8 +215,8 @@ export default class Entity {
return true
}
if (this.#dest == null) { return false }
if (!this.#move || this.#dest == null) { return false }
const collidables = this.collidables()
const fixedDest = SATX.clamp(SATX.fixCollisions(this.#dest, collidables, this.radius), this.game?.width, this.game?.height, this.radius)
const tunnel = SATX.entityTunnel(this.#position.x, this.#position.y, fixedDest.x, fixedDest.y, this.radius)
@@ -268,10 +262,11 @@ export default class Entity {
if (this.position.equals(destination)) {
this.#path = this.#path.slice(1)
if (this.#path.length > 0) {
this.takeStep(distance)
this.move(distance)
}
else {
this.#dest = null
this.#move = false
}
}
}
@@ -279,7 +274,7 @@ export default class Entity {
update() {
this.cast()
this.takeStep()
this.move()
this.fixPosition()
if (this.#logic != null) {
this.#logic()