Skip to content

Commit

Permalink
fix stat block parser
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-man committed Oct 15, 2024
1 parent 39f899d commit 09f0c4c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions modules/apps/stat-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default class StatBlockParser extends FormApplication {


async _updateObject(event, formData) {
let {name, type, data, items} = await StatBlockParser.parseStatBlock(formData.statBlock, this.object.type)
await this.object.update({name, type, data})
let {name, type, system, items} = await StatBlockParser.parseStatBlock(formData.statBlock, this.object.type)
await this.object.update({name, type, system})
await this.object.createEmbeddedDocuments("Item", items)
}

Expand Down Expand Up @@ -328,22 +328,23 @@ export default class StatBlockParser extends FormApplication {
traits.forEach(t => {
delete t._id
})
let effects = trappings.reduce((total, trapping) => total.concat(trapping.effects), []).concat(talents.reduce((total, talent) => total.concat(talent.effects), [])).concat(traits.reduce((total, trait) => total.concat(trait.effects), []))
effects = effects.filter(e => !!e)
effects = effects.filter(e => e.transfer)


let items = skills.concat(talents).concat(traits).concat(trappings).concat(moneyItems)

let effects = items.reduce((effects, item) => effects.concat(item.effects), []);

effects.forEach(e => {
let charChanges = e.changes.filter(c => c.key.includes("characteristics"))
for(let change of charChanges)
for(let c of e.changes)
{
let split = change.key.split(".")
let target = split.slice(1).join(".")
foundry.utils.setProperty(model, target, (getProperty(model, target) + (-1 * change.value))) // Counteract effect changes
let systemPath = c.key.replace("system.", "");
if (hasProperty(model, systemPath))
{
setProperty(model, systemPath, -1 * Number(c.value) + getProperty(model, systemPath));
}
}
})

return { name, type, data: model, items: skills.concat(talents).concat(traits).concat(trappings).concat(moneyItems), effects }

return { name, type, system: model, items}
}

}

0 comments on commit 09f0c4c

Please sign in to comment.