feat: affinity vulnerabilities

This commit is contained in:
cha0s 2019-05-26 11:59:52 -05:00
parent 558fc568c9
commit f38afb942d

View File

@ -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;