generalize buff damage multipliers
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
+8
-2
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user