rely on stringification instead of state reports

This commit is contained in:
2025-01-17 23:04:38 +09:00
parent 80ccb92815
commit 9345c7af04
9 changed files with 123 additions and 73 deletions
+27 -25
View File
@@ -79,21 +79,12 @@ export default class Entity {
])
}
adjustWaypoint(waypoint, direction) {
return SATX.clamp(
waypoint.clone().add(direction.clone().multiplyScalar(this.radius)),
this.game?.width,
this.game?.height,
this.radius,
)
}
attackAction(cursor) {
this.moveAction(cursor, true)
}
castAction(slot, cursor, halt = false) {
const ability = this.abilities[slot]
const ability = this.ability(slot)
if (ability == null) { return }
if (this.casting != null) {
@@ -143,6 +134,21 @@ export default class Entity {
// --- Actions above --- //
ability(slot) {
if (this.abilities[slot] != null) {
return this.game?.abilities.find((it) => it.id == this.abilities[slot])
}
}
adjustWaypoint(waypoint, direction) {
return SATX.clamp(
waypoint.clone().add(direction.clone().multiplyScalar(this.radius)),
this.game?.width,
this.game?.height,
this.radius,
)
}
collidables() {
const entityColliders = (this.game?.entities ?? []).filter((e) => e.id != this.id).map((e) => e.collider())
const terrainColliders = (this.game?.terrains ?? []).map((t) => t.colliders()).flat()
@@ -200,12 +206,6 @@ export default class Entity {
this.dead = false
}
state() {
return {
...this,
}
}
teleport(cursor) {
this.position = cursor.clone()
this.fixPosition()
@@ -264,16 +264,18 @@ export default class Entity {
if (this.#attacking) {
const cursor = this.#dest ?? this.position
const basicAttack = this.abilities[0]
const target = this.closestTargetTo(cursor, basicAttack.range)
if (target != null && this.distanceTo(target.position) < basicAttack.range) {
const cooldown = this.game?.secToTick(basicAttack.cooldown) ?? 0
const lastCast = this.cooldowns[basicAttack.id]
const timestamp = this.game?.currentTick ?? 0
if (lastCast != null && lastCast + cooldown > timestamp) { return false }
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 cooldown = this.game?.secToTick(basicAttack.cooldown) ?? 0
const lastCast = this.cooldowns[basicAttack.id]
const timestamp = this.game?.currentTick ?? 0
if (lastCast != null && lastCast + cooldown > timestamp) { return false }
this.castAction(0, cursor, false)
return true
this.castAction(0, cursor, false)
return true
}
}
}