Skip to content

Commit

Permalink
Merge pull request #194 from AnimaBeyondDevelop/fix/weapon-template-h…
Browse files Browse the repository at this point in the history
…asOwnStr

fix - weapon template hasOwnStr
  • Loading branch information
JulenBordonaba authored Aug 21, 2024
2 parents 9c51a78 + f00eaea commit 4119ad5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/module/migration/migrations/6-fix-old-modifiers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//import { systemDataField } from '../../../types/foundry-vtt-types/src/foundry/common/data/fields.mjs';
import { ABFItems } from '../../items/ABFItems';
/** @typedef {import('./Migration').Migration} Migration
/** @type Migration */
Expand Down
32 changes: 32 additions & 0 deletions src/module/migration/migrations/7-fix-weapons-ownStrength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @typedef {import('./Migration').Migration} Migration
/** @type Migration */
export const Migration7WeaponsOwnStrength = {
version: 7,
title: 'Migrate weapons own strength',
description:
'Shoot weapons often has its own strength for calculating the damage modifiers. ' +
'However, this are sometimes in an old argument `system.weaponFue`.\n' +
'Additionally, weapons have a `system.hasOwnStr` used to distinguish these cases. ' +
'This migration will ensure weapons have all this values syncronised.',
filterItems(item) {
return item.type === 'weapon' && !!item.system.isRanged.value;
},
filterActors(actor) {
return actor.getWeapons().filter(w => w.system.isRanged.value).length !== 0;
},
async updateItem(item) {
if (item.type !== 'weapon') {
console.error('AnimaBF | weapon filter in migration not working');
return;
}

if (item.system.weaponStrength.base.value === 0 && item.system.weaponFue?.value) {
item.system.weaponStrength.base.value = item.system.weaponFue?.value ?? 0;
}

item.system.hasOwnStr = { value: !!item.system.weaponStrength.base.value };

return item;
}
};
22 changes: 22 additions & 0 deletions src/module/migration/migrations/8-remove-unused-weaponFue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** @typedef {import('./Migration').Migration} Migration
/** @type Migration */
export const Migration8RemoveWeaponFue = {
version: 8,
title: 'Remove old, unused `weaponFue` from weapons',
description:
'`system.weaponFue` in weapons is no longer used, so this migration removes it.',
filterItems(item) {
return item.type === 'weapon';
},
filterActors(actor) {
return actor.getWeapons().length !== 0;
},
async updateItem(item) {
if (item.type !== 'weapon') {
console.error('AnimaBF | weapon filter in migration not working');
return;
}
await item.update({ 'system.-=weaponFue': null });
}
};
2 changes: 2 additions & 0 deletions src/module/migration/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export { Migration3AlternativeAct } from './3-fix-alternative-act';
export { Migration4PsychicDisciplinesMentalPatterns } from './4-fix-psychic-disciplines-mental-patterns';
export { Migration5UpdateSpellsPowers } from './5-update-spells-powers';
export { Migration6OldModifiers } from './6-fix-old-modifiers';
export { Migration7WeaponsOwnStrength } from './7-fix-weapons-ownStrength';
export { Migration8RemoveWeaponFue } from './8-remove-unused-weaponFue';
3 changes: 3 additions & 0 deletions src/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@
"martialKnowledge": { "value": 0 }
},
"weapon": {
"equipped": { "value": false },
"isShield": { "value": false },
"special": { "value": "" },
"integrity": {
"base": { "value": 0 },
Expand Down Expand Up @@ -707,6 +709,7 @@
"cadence": { "value": "" },
"reload": { "base": { "value": 0 }, "final": { "value": 0 } },
"sizeProportion": { "value": "" },
"hasOwnStr": { "value": false },
"weaponStrength": { "base": { "value": 0 }, "final": { "value": 0 } },
"critic": { "primary": { "value": "-" }, "secondary": { "value": "-" } }
},
Expand Down

0 comments on commit 4119ad5

Please sign in to comment.