mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-19 08:20:30 +01:00
Added DestroyOnEmpty property
This commit is contained in:
parent
4dfc18f727
commit
7082cc009f
65 changed files with 87 additions and 20 deletions
|
|
@ -199,14 +199,16 @@ export default class CostField extends fields.ArrayField {
|
|||
switch (r.key) {
|
||||
case CONFIG.DH.GENERAL.itemAbilityCosts.resource.id:
|
||||
return {
|
||||
'system.resource.value': r.target.system.resource.value + r.value
|
||||
path: 'system.resource.value',
|
||||
value: r.target.system.resource.value + r.value
|
||||
};
|
||||
case CONFIG.DH.GENERAL.itemAbilityCosts.quantity.id:
|
||||
return {
|
||||
'system.quantity': r.target.system.quantity + r.value
|
||||
path: 'system.quantity',
|
||||
value: r.target.system.quantity + r.value
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
return { path: '', value: undefined };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import { ActionField } from '../fields/actionField.mjs';
|
||||
|
||||
export default class DHConsumable extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -19,7 +18,8 @@ export default class DHConsumable extends BaseDataItem {
|
|||
const fields = foundry.data.fields;
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
consumeOnUse: new fields.BooleanField({ initial: false })
|
||||
consumeOnUse: new fields.BooleanField({ initial: true }),
|
||||
destroyOnEmpty: new fields.BooleanField({ initial: true })
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -27,14 +27,4 @@ export default class DHConsumable extends BaseDataItem {
|
|||
|
||||
/**@override */
|
||||
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/round-potion.svg';
|
||||
|
||||
async _preUpdate(changes, options, userId) {
|
||||
const allowed = await super._preUpdate(changes, options, userId);
|
||||
if (allowed === false) return;
|
||||
|
||||
if (changes.system?.quantity !== undefined && Number(changes.system.quantity) === 0) {
|
||||
this.parent.delete();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -660,10 +660,21 @@ export default class DhpActor extends Actor {
|
|||
|
||||
resources.forEach(r => {
|
||||
if (r.itemId) {
|
||||
updates.items[r.key] = {
|
||||
target: r.target,
|
||||
resources: game.system.api.fields.ActionFields.CostField.getItemIdCostUpdate(r)
|
||||
};
|
||||
const { path, value } = game.system.api.fields.ActionFields.CostField.getItemIdCostUpdate(r);
|
||||
|
||||
if (
|
||||
r.key === 'quantity' &&
|
||||
r.target.type === 'consumable' &&
|
||||
value === 0 &&
|
||||
r.target.system.destroyOnEmpty
|
||||
) {
|
||||
r.target.delete();
|
||||
} else {
|
||||
updates.items[r.key] = {
|
||||
target: r.target,
|
||||
resources: { [path]: value }
|
||||
};
|
||||
}
|
||||
} else {
|
||||
switch (r.key) {
|
||||
case 'fear':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue