From 59b5a603a01b4b43e5fce67515c94967ff67e3bd Mon Sep 17 00:00:00 2001 From: Thayol Date: Wed, 22 Jan 2025 23:33:48 +0900 Subject: [PATCH] generalize buff damage multipliers --- src/buff.js | 2 ++ src/entity.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/buff.js b/src/buff.js index 4180edf..baf7607 100644 --- a/src/buff.js +++ b/src/buff.js @@ -5,6 +5,7 @@ export default class Buff { name = 'Buff' + damageMultiplier = null duration = 0 #effect = null @@ -22,5 +23,6 @@ export default class Buff { id: 'exposed', name: 'Exposed', duration: 4, + onHitMultiplier: 3, }) } diff --git a/src/entity.js b/src/entity.js index 48e7c51..3fae6ed 100644 --- a/src/entity.js +++ b/src/entity.js @@ -324,15 +324,21 @@ export default class Entity { damage(amount, source = null) { if (this.dead) { return } - let damage = amount + let customMultipliers = 0 if (this.hasBuff(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 + customMultipliers += (buff.onHitMultiplier - 1) 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) }