mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
[Feature] 1033 - Consume Quantity On Use (#1106)
* Initial migration * Updated compendium YML * Added Quantity as a possible cost * Added quantity consumption to all Compendium Consumables * . * Added DestroyOnEmpty property
This commit is contained in:
parent
9dd773001d
commit
8fd63d5963
397 changed files with 1276 additions and 930 deletions
|
|
@ -96,5 +96,60 @@ export async function runMigrations() {
|
|||
lastMigrationVersion = '1.1.1';
|
||||
}
|
||||
|
||||
if (foundry.utils.isNewerVersion('1.2.0', lastMigrationVersion)) {
|
||||
const lockedPacks = [];
|
||||
const compendiumItems = [];
|
||||
for (let pack of game.packs) {
|
||||
if (pack.locked) {
|
||||
lockedPacks.push(pack.collection);
|
||||
await pack.configure({ locked: false });
|
||||
}
|
||||
const documents = await pack.getDocuments();
|
||||
|
||||
compendiumItems.push(...documents.filter(x => x.system?.metadata?.hasActions));
|
||||
compendiumItems.push(
|
||||
...documents
|
||||
.filter(x => x.items)
|
||||
.flatMap(actor => actor.items.filter(x => x.system?.metadata?.hasActions))
|
||||
);
|
||||
}
|
||||
|
||||
const worldItems = game.items.filter(x => x.system.metadata.hasActions);
|
||||
const worldActorItems = Array.from(game.actors).flatMap(actor =>
|
||||
actor.items.filter(x => x.system.metadata.hasActions)
|
||||
);
|
||||
|
||||
const validCostKeys = Object.keys(CONFIG.DH.GENERAL.abilityCosts);
|
||||
for (let item of [...worldItems, ...worldActorItems, ...compendiumItems]) {
|
||||
for (let action of item.system.actions) {
|
||||
const resourceCostIndexes = Object.keys(action.cost).reduce(
|
||||
(acc, index) => (!validCostKeys.includes(action.cost[index].key) ? [...acc, Number(index)] : acc),
|
||||
[]
|
||||
);
|
||||
if (resourceCostIndexes.length === 0) continue;
|
||||
|
||||
await action.update({
|
||||
cost: action.cost.map((cost, index) => {
|
||||
const { keyIsID, ...rest } = cost;
|
||||
if (!resourceCostIndexes.includes(index)) return { ...rest };
|
||||
|
||||
return {
|
||||
...rest,
|
||||
key: 'resource',
|
||||
itemId: cost.key
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (let packId of lockedPacks) {
|
||||
const pack = game.packs.get(packId);
|
||||
await pack.configure({ locked: true });
|
||||
}
|
||||
|
||||
lastMigrationVersion = '1.2.0';
|
||||
}
|
||||
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion, lastMigrationVersion);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue