collapse Effect into Ability

This commit is contained in:
2025-01-12 13:58:35 +09:00
parent d9849f770b
commit d9d62d7070
4 changed files with 124 additions and 101 deletions
+22 -11
View File
@@ -11,10 +11,10 @@ export default class Entity {
health = 1 // TODO: health can go into negatives and can go over maxHealth
maxHealth = 1
abilities = [
Ability.basicAttack(600, 5, 600),
Ability.straightShot(800, 7, 3000),
() => {},
() => {},
Ability.basicAttack,
Ability.straightShot,
Ability.control,
Ability.shieldThrow,
]
casting = null
// TODO: teams
@@ -30,8 +30,8 @@ export default class Entity {
return new SAT.Circle(new SAT.Vector(x, y), radius)
}
constructor(...options) {
Object.entries(options).forEach((value, key) => this[key] = value)
constructor(options = {}) {
Object.entries(options).forEach(([key, value]) => this[key] = value)
}
get game() { return this.#game }
@@ -82,11 +82,7 @@ export default class Entity {
return false
}
this.casting.ability.effect.bind(this)(this.casting.cursor)
if (this.casting.ability.cooldown != null) {
this.cooldowns[this.casting.ability.id] = timestamp
}
this.casting.ability.effect(this, this.casting.cursor)
this.casting = null
return true
@@ -123,6 +119,10 @@ export default class Entity {
return entityColliders.concat(terrainColliders)
}
cooldown(id) {
this.cooldowns[id] = this.game?.currentTick ?? 0
}
damage(amount, source = null) {
this.health = Math.min(Math.max(0, this.health - amount), this.maxHealth)
}
@@ -213,6 +213,17 @@ export default class Entity {
this.cast()
this.takeStep()
this.fixPosition()
if (this.health <= 0) {
if (this.id == '1' || this.id == '2') {
this.health = this.maxHealth
if (this.id == '1') {
this.teleport(200, 200)
}
if (this.id == '2') {
this.teleport(1800, 1800)
}
}
}
}
waypoints() {