display buffs in the client
This commit is contained in:
+23
-12
@@ -153,14 +153,17 @@ export default class Entity {
|
||||
)
|
||||
}
|
||||
|
||||
applyBuff(id) {
|
||||
applyBuff(id, sourceId = null) {
|
||||
const index = this.buffs.findIndex((it) => it.id == id)
|
||||
const source = sourceId ?? this.id
|
||||
const timestamp = this.game?.currentTick ?? 0
|
||||
|
||||
if (index > -1) {
|
||||
this.buffs[index].timestamp = timestamp
|
||||
this.buffs[index].source = source
|
||||
}
|
||||
else {
|
||||
this.buffs.push({ id, timestamp })
|
||||
this.buffs.push({ id, source, timestamp })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,11 +194,14 @@ export default class Entity {
|
||||
.reduce((e1, e2) => (e1?.distanceTo(cursor) ?? Infinity) < e2.distanceTo(cursor) ? e1 : e2, null)
|
||||
}
|
||||
|
||||
damage(amount) {
|
||||
damage(amount, source = null) {
|
||||
let damage = amount
|
||||
if (this.hasBuff(Buff.exposed.id)) {
|
||||
damage *= 3 // TODO: move to buff, make generic
|
||||
this.removeBuff(Buff.exposed.id)
|
||||
const buff = this.getBuff(Buff.exposed.id)
|
||||
if (buff.source == source.id) {
|
||||
damage *= 3 // TODO: move to Buff class to make generic
|
||||
this.removeBuff(Buff.exposed.id)
|
||||
}
|
||||
}
|
||||
|
||||
this.health = Math.min(Math.max(0, this.health - damage), this.maxHealth)
|
||||
@@ -209,6 +215,16 @@ export default class Entity {
|
||||
return this.position.distanceTo(cursor)
|
||||
}
|
||||
|
||||
getBuff(id) {
|
||||
const entityBuff = this.buffs.find((it) => it.id == id)
|
||||
if (entityBuff == null) { return }
|
||||
|
||||
const buffDefinition = this.game?.buffs.find((it) => it.id == entityBuff.id)
|
||||
if (buffDefinition == null) { return }
|
||||
|
||||
return { ...buffDefinition, ...entityBuff }
|
||||
}
|
||||
|
||||
hasBuff(id) {
|
||||
return this.buffs.some((it) => it.id == id)
|
||||
}
|
||||
@@ -405,13 +421,8 @@ export default class Entity {
|
||||
}
|
||||
|
||||
#tickBuff(index) {
|
||||
const entityBuff = this.buffs[index]
|
||||
if (entityBuff == null) { return }
|
||||
|
||||
const buffDefinition = this.game?.buffs.find((it) => it.id == entityBuff.id)
|
||||
if (buffDefinition == null) { return }
|
||||
|
||||
const buff = { ...buffDefinition, ...entityBuff }
|
||||
if (this.buffs[index] == null) { return }
|
||||
const buff = this.getBuff(this.buffs[index].id)
|
||||
const duration = this.game?.secToTick(buff.duration) ?? 0
|
||||
const currentTick = this.game?.currentTick ?? 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user