fix melee attacks

This commit is contained in:
2025-01-17 23:40:33 +09:00
parent 9345c7af04
commit 8e95bc141c
4 changed files with 25 additions and 14 deletions
+6 -4
View File
@@ -107,7 +107,7 @@ export default class Entity {
return false
}
this.casting = { ability, cursor, timestamp }
this.casting = { ability, cursor, timestamp } // TODO: use ID only for ability
return true
}
@@ -118,7 +118,9 @@ export default class Entity {
moveAction(cursor, attack = false) {
if (this.casting != null && this.casting.ability.moveCancelable) {
this.casting = null
if (!attack && !(this.casting != null && this.casting.ability.id == this.abilities[0])) {
this.casting = null
}
}
this.#attacking = attack
@@ -266,8 +268,8 @@ export default class Entity {
const cursor = this.#dest ?? this.position
const basicAttack = this.ability(0)
if (basicAttack != null) {
const target = this.closestTargetTo(cursor, basicAttack.range)
if (target != null && this.distanceTo(target.position) < basicAttack.range) {
const target = this.closestTargetTo(cursor, 500)
if (target != null && this.distanceTo(target.position) < basicAttack.range + this.radius + target.radius) {
const cooldown = this.game?.secToTick(basicAttack.cooldown) ?? 0
const lastCast = this.cooldowns[basicAttack.id]
const timestamp = this.game?.currentTick ?? 0