generalize buff damage multipliers

This commit is contained in:
2025-01-22 23:33:48 +09:00
parent 4c76d5dbde
commit 59b5a603a0
2 changed files with 10 additions and 2 deletions
+2
View File
@@ -5,6 +5,7 @@ export default class Buff {
name = 'Buff' name = 'Buff'
damageMultiplier = null
duration = 0 duration = 0
#effect = null #effect = null
@@ -22,5 +23,6 @@ export default class Buff {
id: 'exposed', id: 'exposed',
name: 'Exposed', name: 'Exposed',
duration: 4, duration: 4,
onHitMultiplier: 3,
}) })
} }
+8 -2
View File
@@ -324,15 +324,21 @@ export default class Entity {
damage(amount, source = null) { damage(amount, source = null) {
if (this.dead) { return } if (this.dead) { return }
let damage = amount let customMultipliers = 0
if (this.hasBuff(Buff.exposed.id)) { if (this.hasBuff(Buff.exposed.id)) {
const buff = this.getBuff(Buff.exposed.id) const buff = this.getBuff(Buff.exposed.id)
if (buff.source == source.id) { if (buff.source == source.id) {
damage *= 3 // TODO: move to Buff class to make generic customMultipliers += (buff.onHitMultiplier - 1)
this.removeBuff(Buff.exposed.id) this.removeBuff(Buff.exposed.id)
} }
} }
const damageMultiplerBuffs = source.buffs.map((it) => it.getBuff).filter((it) => it != null && it.damageMultiplier != null)
const buffPassiveDamageMultiplier = damageMultiplerBuffs.reduce((it) => it.damageMultiplier - 1, 0)
const damageMultipler = 1 + buffPassiveDamageMultiplier + customMultipliers
const damage = amount * damageMultipler
this.health = Math.min(Math.max(0, this.health - damage), this.maxHealth) this.health = Math.min(Math.max(0, this.health - damage), this.maxHealth)
} }