Skip to content

Commit

Permalink
Fixed the spell cost migration with procedure provided by Shourn
Browse files Browse the repository at this point in the history
  • Loading branch information
Azurelol committed Jan 19, 2025
1 parent 9e73445 commit 54719c1
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions module/documents/items/spell/spell-migrations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@ function migrateQualityToOpportunity(source) {
* @param {SpellDataModel} source
*/
function migrateCostAndTargets(source) {
if (source.mpCost && source.cost && source.targeting) {
if (source.mpCost && !source.cost) {
source.cost = {};
source.cost.resource = 'mp';
source.cost.amount = source.mpCost.value;
const costRegex = /^\s*(?<cost>\d*)/;
const match = costRegex.exec(source.mpCost.value);
source.cost.amount = match ? Number(match.groups.cost) : 0;
// Delete old fields for clarity
delete source.mpCost;
}
if (source.maxTargets && source.target && !source.targeting) {
source.targeting = {};
source.targeting.max = source.maxTargets.value;

if (source.targeting.max > 1) {
if (/weapon/i.test(source.target.value)) {
source.targeting.rule = Targeting.rule.weapon;
} else if (/special/i.test(source.target.value)) {
source.targeting.rule = Targeting.rule.special;
} else if (source.targeting.max > 1) {
source.targeting.rule = Targeting.rule.multiple;
} else if (source.targeting.max === 1) {
source.targeting.rule = Targeting.rule.single;
} else {
source.targeting.rule = Targeting.rule.self;
}

// Delete old properties?
delete source.mpCost;
// Delete old fields for clarity
delete source.maxTargets;
delete source.target;
}
Expand Down

0 comments on commit 54719c1

Please sign in to comment.