Damage multipliers are now applied to damage dealt
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { some, intersection, difference } from 'lodash';
|
||||
import applyProperty from '../applyProperty.js';
|
||||
import { dealDamageWork } from '/imports/api/creature/creatureProperties/methods/dealDamage.js';
|
||||
import {insertCreatureLog} from '/imports/api/creature/log/CreatureLogs.js';
|
||||
@@ -62,13 +63,16 @@ export default function applyDamage(node, {
|
||||
prop.amount.value = toString(reduced);
|
||||
}
|
||||
|
||||
const damage = +reduced.value;
|
||||
let damage = +reduced.value;
|
||||
|
||||
// If we didn't end up with a constant of finite amount, give up
|
||||
if (reduced?.parseType !== 'constant' && !isFinite(reduced.value)){
|
||||
return applyChildren();
|
||||
}
|
||||
|
||||
// Round the damage to a whole number
|
||||
damage = Math.floor(damage);
|
||||
|
||||
// Memoise the damage suffix for the log
|
||||
let suffix = (criticalHit ? ' critical ' : ' ') +
|
||||
prop.damageType +
|
||||
@@ -78,6 +82,14 @@ export default function applyDamage(node, {
|
||||
// Iterate through all the targets
|
||||
damageTargets.forEach(target => {
|
||||
|
||||
// Apply weaknesses/resistances/immunities
|
||||
damage = applyDamageMultipliers({
|
||||
target,
|
||||
damage,
|
||||
damageProp: prop,
|
||||
logValue
|
||||
});
|
||||
|
||||
// Deal the damage to the target
|
||||
let damageDealt = dealDamageWork({
|
||||
creature: target,
|
||||
@@ -114,3 +126,51 @@ export default function applyDamage(node, {
|
||||
});
|
||||
return applyChildren();
|
||||
}
|
||||
|
||||
function applyDamageMultipliers({target, damage, damageProp, logValue}){
|
||||
const damageType = damageProp?.damageType;
|
||||
if (!damageType) return;
|
||||
|
||||
const multiplier = target?.variables?.[damageType];
|
||||
if (!multiplier) return;
|
||||
|
||||
const damageTypeText = damageType == 'healing' ? 'healing': `${damageType} damage`;
|
||||
|
||||
if (
|
||||
multiplier.immunity &&
|
||||
some(multiplier.immunities, multiplierAppliesTo(damageProp))
|
||||
){
|
||||
logValue.push(`Immune to ${damageTypeText}`);
|
||||
return 0;
|
||||
} else {
|
||||
if (
|
||||
multiplier.resistance &&
|
||||
some(multiplier.resistances, multiplierAppliesTo(damageProp))
|
||||
){
|
||||
logValue.push(`Resistant to ${damageTypeText}`);
|
||||
damage = Math.floor(damage / 2);
|
||||
}
|
||||
if (
|
||||
multiplier.vulnerability &&
|
||||
some(multiplier.vulnerabilities, multiplierAppliesTo(damageProp))
|
||||
){
|
||||
logValue.push(`Vulnerable to ${damageTypeText}`);
|
||||
damage = Math.floor(damage * 2);
|
||||
}
|
||||
return damage;
|
||||
}
|
||||
}
|
||||
|
||||
function multiplierAppliesTo(damageProp){
|
||||
return multiplier => {
|
||||
const hasRequiredTags = difference(
|
||||
multiplier.includeTags, damageProp.tags
|
||||
).length === 0;
|
||||
|
||||
const hasNoExcludedTags = intersection(
|
||||
multiplier.excludeTags, damageProp.tags
|
||||
).length === 0;
|
||||
|
||||
return hasRequiredTags && hasNoExcludedTags;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
{{ name }}
|
||||
</v-sheet>
|
||||
<div
|
||||
class="flex-grow-1 layout align-center justify-center flex-wrap"
|
||||
class="flex-grow-1 d-flex align-center flex-wrap"
|
||||
style="width: 100%;"
|
||||
>
|
||||
<div
|
||||
@@ -32,6 +32,7 @@
|
||||
'flex-wrap': wrap,
|
||||
'mono': isMono,
|
||||
'flex-grow-0': calculation && calculation.effects,
|
||||
'flex-grow-1': !calculation || !calculation.effects,
|
||||
'ma-3': calculation && calculation.effects,
|
||||
...$attrs.class,
|
||||
}"
|
||||
|
||||
Reference in New Issue
Block a user