mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 19:51:08 +01:00
[Feature] Item Resource Support (#328)
* Initial * Resource setup finished * Fixed so that costs can be used * Corrected standard resources * Actions can only use item resources from their parent item * Fixed up dice * Fixed resource dice positioning * Fixed parsing of resource.max * Fixed styling on settings tab * Added manual input for Dice Resources * Lightmode fixes * Fixed Feature spellcasting modifier * Bugfix for item input to resourceDiceDialog * Item fix for TokenInput * PR Fixes
This commit is contained in:
parent
eefa116d9a
commit
4be3e6179c
53 changed files with 972 additions and 329 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { itemAbleRollParse } from '../helpers/utils.mjs';
|
||||
|
||||
export default class DhActiveEffect extends ActiveEffect {
|
||||
get isSuppressed() {
|
||||
// If this is a copied effect from an attachment, never suppress it
|
||||
|
|
@ -24,16 +26,18 @@ export default class DhActiveEffect extends ActiveEffect {
|
|||
*/
|
||||
get isAttached() {
|
||||
if (!this.parent || !this.parent.parent) return false;
|
||||
|
||||
|
||||
// Check if this item's UUID is in any actor's armor or weapon attachment lists
|
||||
const actor = this.parent.parent;
|
||||
if (!actor || !actor.items) return false;
|
||||
|
||||
|
||||
return actor.items.some(item => {
|
||||
return (item.type === 'armor' || item.type === 'weapon') &&
|
||||
item.system?.attached &&
|
||||
Array.isArray(item.system.attached) &&
|
||||
item.system.attached.includes(this.parent.uuid);
|
||||
return (
|
||||
(item.type === 'armor' || item.type === 'weapon') &&
|
||||
item.system?.attached &&
|
||||
Array.isArray(item.system.attached) &&
|
||||
item.system.attached.includes(this.parent.uuid)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -51,11 +55,7 @@ export default class DhActiveEffect extends ActiveEffect {
|
|||
}
|
||||
|
||||
static applyField(model, change, field) {
|
||||
const isItemTarget = change.value.toLowerCase().startsWith('item.');
|
||||
change.value = isItemTarget ? change.value.slice(5) : change.value;
|
||||
change.value = Roll.safeEval(
|
||||
Roll.replaceFormulaData(change.value, isItemTarget ? change.effect.parent : model)
|
||||
);
|
||||
change.value = itemAbleRollParse(change.value, model, change.effect.parent);
|
||||
super.applyField(model, change, field);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -396,7 +396,7 @@ export default class DhpActor extends Actor {
|
|||
if (Hooks.call(`${CONFIG.DH.id}.preTakeDamage`, this, baseDamage, type) === false) return null;
|
||||
|
||||
if (this.type === 'companion') {
|
||||
await this.modifyResource([{ value: 1, type: 'stress' }]);
|
||||
await this.modifyResource([{ value: 1, key: 'stress' }]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -418,8 +418,8 @@ export default class DhpActor extends Actor {
|
|||
const { modifiedDamage, armorSpent, stressSpent } = armorStackResult;
|
||||
updates.find(u => u.type === 'hitPoints').value = modifiedDamage;
|
||||
updates.push(
|
||||
...(armorSpent ? [{ value: armorSpent, type: 'armorStack' }] : []),
|
||||
...(stressSpent ? [{ value: stressSpent, type: 'stress' }] : [])
|
||||
...(armorSpent ? [{ value: armorSpent, key: 'armorStack' }] : []),
|
||||
...(stressSpent ? [{ value: stressSpent, key: 'stress' }] : [])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -434,8 +434,8 @@ export default class DhpActor extends Actor {
|
|||
|
||||
/* if(this.system.resistance[type]?.immunity) return 0;
|
||||
if(this.system.resistance[type]?.resistance) baseDamage = Math.ceil(baseDamage / 2); */
|
||||
if(this.canResist(type, 'immunity')) return 0;
|
||||
if(this.canResist(type, 'resistance')) baseDamage = Math.ceil(baseDamage / 2);
|
||||
if (this.canResist(type, 'immunity')) return 0;
|
||||
if (this.canResist(type, 'resistance')) baseDamage = Math.ceil(baseDamage / 2);
|
||||
|
||||
// const flatReduction = this.system.resistance[type].reduction;
|
||||
const flatReduction = this.getDamageTypeReduction(type);
|
||||
|
|
@ -448,13 +448,16 @@ export default class DhpActor extends Actor {
|
|||
}
|
||||
|
||||
canResist(type, resistance) {
|
||||
if(!type) return 0;
|
||||
if (!type) return 0;
|
||||
return type.every(t => this.system.resistance[t]?.[resistance] === true);
|
||||
}
|
||||
|
||||
getDamageTypeReduction(type) {
|
||||
if(!type) return 0;
|
||||
const reduction = Object.entries(this.system.resistance).reduce((a, [index, value]) => type.includes(index) ? Math.min(value.reduction, a) : a, Infinity);
|
||||
if (!type) return 0;
|
||||
const reduction = Object.entries(this.system.resistance).reduce(
|
||||
(a, [index, value]) => (type.includes(index) ? Math.min(value.reduction, a) : a),
|
||||
Infinity
|
||||
);
|
||||
return reduction === Infinity ? 0 : reduction;
|
||||
}
|
||||
|
||||
|
|
@ -467,39 +470,61 @@ export default class DhpActor extends Actor {
|
|||
if (!resources.length) return;
|
||||
|
||||
if (resources.find(r => r.type === 'stress')) this.convertStressDamageToHP(resources);
|
||||
let updates = { actor: { target: this, resources: {} }, armor: { target: this.system.armor, resources: {} } };
|
||||
let updates = {
|
||||
actor: { target: this, resources: {} },
|
||||
armor: { target: this.system.armor, resources: {} },
|
||||
items: {}
|
||||
};
|
||||
resources.forEach(r => {
|
||||
switch (r.type) {
|
||||
case 'fear':
|
||||
ui.resources.updateFear(
|
||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear) + r.value
|
||||
);
|
||||
break;
|
||||
case 'armorStack':
|
||||
updates.armor.resources['system.marks.value'] = Math.max(
|
||||
Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore),
|
||||
0
|
||||
);
|
||||
break;
|
||||
default:
|
||||
updates.actor.resources[`system.resources.${r.type}.value`] = Math.max(
|
||||
Math.min(
|
||||
this.system.resources[r.type].value + r.value,
|
||||
this.system.resources[r.type].max
|
||||
),
|
||||
0
|
||||
);
|
||||
break;
|
||||
if (r.keyIsID) {
|
||||
updates.items[r.key] = {
|
||||
target: r.target,
|
||||
resources: {
|
||||
'system.resource.value': r.target.system.resource.value + r.value
|
||||
}
|
||||
};
|
||||
} else {
|
||||
switch (r.key) {
|
||||
case 'fear':
|
||||
ui.resources.updateFear(
|
||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear) + r.value
|
||||
);
|
||||
break;
|
||||
case 'armorStack':
|
||||
updates.armor.resources['system.marks.value'] = Math.max(
|
||||
Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore),
|
||||
0
|
||||
);
|
||||
break;
|
||||
default:
|
||||
updates.actor.resources[`system.resources.${r.key}.value`] = Math.max(
|
||||
Math.min(this.system.resources[r.key].value + r.value, this.system.resources[r.key].max),
|
||||
0
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
Object.values(updates).forEach(async u => {
|
||||
if (Object.keys(u.resources).length > 0) {
|
||||
await emitAsGM(
|
||||
GMUpdateEvent.UpdateDocument,
|
||||
u.target.update.bind(u.target),
|
||||
u.resources,
|
||||
u.target.uuid
|
||||
);
|
||||
Object.keys(updates).forEach(async key => {
|
||||
const u = updates[key];
|
||||
if (key === 'items') {
|
||||
Object.values(u).forEach(async item => {
|
||||
await emitAsGM(
|
||||
GMUpdateEvent.UpdateDocument,
|
||||
item.target.update.bind(item.target),
|
||||
item.resources,
|
||||
item.target.uuid
|
||||
);
|
||||
});
|
||||
} else {
|
||||
if (Object.keys(u.resources).length > 0) {
|
||||
await emitAsGM(
|
||||
GMUpdateEvent.UpdateDocument,
|
||||
u.target.update.bind(u.target),
|
||||
u.resources,
|
||||
u.target.uuid
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue