From a0c2822dacb3d08c1b24c80c5c50c66ef8e1de60 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Sun, 24 Jul 2022 20:38:42 +0200 Subject: [PATCH] Added "extra" damage type Takes on the same damage type as the last damage applied during the same action, otherwise deals "extra" damage --- .../applyPropertyByType/applyDamage.js | 9 ++++++++ .../api/engine/actions/applyTriggers.js | 8 ++++--- .../engine/computation/CreatureComputation.js | 22 +++++-------------- .../utility/getEffectivePropTags.js | 17 ++++++++++++++ app/imports/constants/DAMAGE_TYPES.js | 1 + 5 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 app/imports/api/engine/computation/utility/getEffectivePropTags.js diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyDamage.js b/app/imports/api/engine/actions/applyPropertyByType/applyDamage.js index ebf7448b..f8b6eb8b 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyDamage.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyDamage.js @@ -68,6 +68,15 @@ export default function applyDamage(node, { // Round the damage to a whole number damage = Math.floor(damage); + // Convert extra damage into the stored type + if (prop.damageType === 'extra' && scope['$lastDamageType']) { + prop.damageType = scope['$lastDamageType']; + } + // Store current damage type + if (prop.damageType !== 'healing') { + scope['$lastDamageType'] = prop.damageType; + } + // Memoise the damage suffix for the log let suffix = (criticalHit ? ' critical ' : ' ') + prop.damageType + diff --git a/app/imports/api/engine/actions/applyTriggers.js b/app/imports/api/engine/actions/applyTriggers.js index 3844ae15..30b1790e 100644 --- a/app/imports/api/engine/actions/applyTriggers.js +++ b/app/imports/api/engine/actions/applyTriggers.js @@ -4,6 +4,7 @@ import { getPropertyDecendants } from '/imports/api/engine/loadCreatures.js'; import { nodeArrayToTree } from '/imports/api/parenting/nodesToTree.js'; import applyProperty from '/imports/api/engine/actions/applyProperty.js'; import { difference, intersection } from 'lodash'; +import getEffectivePropTags from '/imports/api/engine/computation/utility/getEffectivePropTags.js'; export default function applyTriggers(node, { creature, targets, scope, log }, timing) { const prop = node.node; @@ -25,10 +26,11 @@ export default function applyTriggers(node, { creature, targets, scope, log }, t function triggerMatchTags(trigger, prop) { let matched = false; + const propTags = getEffectivePropTags(prop); // Check the target tags if ( !trigger.targetTags?.length || - difference(trigger.targetTags, prop.tags).length === 0 + difference(trigger.targetTags, propTags).length === 0 ) { matched = true; } @@ -38,14 +40,14 @@ function triggerMatchTags(trigger, prop) { if (matched) return; if ( !extra.tags.length || - difference(extra.tags, prop.tags).length === 0 + difference(extra.tags, propTags).length === 0 ) { matched = true; } } else if (extra.operation === 'NOT') { if ( extra.tags.length && - intersection(extra.tags, prop.tags) + intersection(extra.tags, propTags) ) { return false; } diff --git a/app/imports/api/engine/computation/CreatureComputation.js b/app/imports/api/engine/computation/CreatureComputation.js index fb850129..1fe14769 100644 --- a/app/imports/api/engine/computation/CreatureComputation.js +++ b/app/imports/api/engine/computation/CreatureComputation.js @@ -1,5 +1,6 @@ import { EJSON } from 'meteor/ejson'; import createGraph from 'ngraph.graph'; +import getEffectivePropTags from '/imports/api/engine/computation/utility/getEffectivePropTags.js'; export default class CreatureComputation { constructor(properties, creature, variables){ @@ -22,28 +23,15 @@ export default class CreatureComputation { // Store by id this.propsById[prop._id] = prop; - // Store tags - const storePropOnTag = (prop, tag) => { + // Store sets of ids in each tag + getEffectivePropTags(prop).forEach(tag => { if (!tag) return; - if (this.propsWithTag[tag]){ + if (this.propsWithTag[tag]) { this.propsWithTag[tag].push(prop._id); } else { this.propsWithTag[tag] = [prop._id]; } - } - // Store sets of ids in each tag - if (prop.tags){ - prop.tags.forEach(tag => { - storePropOnTag(prop, tag); - }); - } - // Store tags for the property type - storePropOnTag(prop, `#${prop.type}`); - // Store tags for some string properties - storePropOnTag(prop, prop.damageType); - storePropOnTag(prop, prop.skillType); - storePropOnTag(prop, prop.attributeType); - storePropOnTag(prop, prop.reset); + }); // Store the prop in the dependency graph this.dependencyGraph.addNode(prop._id, prop); diff --git a/app/imports/api/engine/computation/utility/getEffectivePropTags.js b/app/imports/api/engine/computation/utility/getEffectivePropTags.js new file mode 100644 index 00000000..e3e52bf2 --- /dev/null +++ b/app/imports/api/engine/computation/utility/getEffectivePropTags.js @@ -0,0 +1,17 @@ +export default function getEffectivePropTags(prop) { + if (!prop.tags) return []; + const tags = [...prop.tags]; + // Tags for the property type, separate #damage from #healing + if (prop.type === 'damage' && prop.damageType === 'healing') { + tags.push('#healing'); + } else { + tags.push(`#${prop.type}`); + } + + // Tags for some string properties + if (prop.damageType) tags.push(prop.damageType); + if (prop.skillType) tags.push(prop.skillType); + if (prop.attributeType) tags.push(prop.attributeType); + if (prop.reset) tags.push(prop.reset); + return tags; +} diff --git a/app/imports/constants/DAMAGE_TYPES.js b/app/imports/constants/DAMAGE_TYPES.js index 9e544266..beb02518 100644 --- a/app/imports/constants/DAMAGE_TYPES.js +++ b/app/imports/constants/DAMAGE_TYPES.js @@ -13,6 +13,7 @@ const DAMAGE_TYPES = Object.freeze([ 'psychic', 'radiant', 'thunder', + 'extra', ]); export default DAMAGE_TYPES;