From f38afb942d26486642aa3c524adba7b3ea1b5cba Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 26 May 2019 11:59:52 -0500 Subject: [PATCH] feat: affinity vulnerabilities --- common/combat/vulnerable.trait.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/common/combat/vulnerable.trait.js b/common/combat/vulnerable.trait.js index 56af30c..cffb1e3 100644 --- a/common/combat/vulnerable.trait.js +++ b/common/combat/vulnerable.trait.js @@ -31,6 +31,7 @@ export class Vulnerable extends Trait { playDamagingSound, ], }, + vulnerabilities: undefined, } } @@ -178,16 +179,23 @@ export class Vulnerable extends Trait { const damageSpecs = entity.damageSpecs; for (let i = 0; i < damageSpecs.length; ++i) { const damageSpec = damageSpecs[i]; + let power = damageSpec.power; + // Check if vulnerable to this affinity. + if (this.params.vulnerabilities) { + if (damageSpec.affinity in this.params.vulnerabilities) { + power *= this.params.vulnerabilities[damageSpec.affinity]; + } + } if (this.locks.has(damageSpec)) { continue; } this.locks.set(damageSpec, damageSpec.lock); const variance = Math.random() * damageSpec.variance * 2 - damageSpec.variance; - const difference = damageSpec.power * variance; + const difference = power * variance; // Account for variance past 0, so track if it's damage or not. - let amount = Math.round(damageSpec.power + difference); + let amount = Math.round(power + difference); let isDamage; - if (damageSpec.power < 0) { + if (power < 0) { isDamage = false; if (amount > 0) { amount = 0;