Files
foundryvtt-wh4-lang-fr-fr/scripts/TCtXPvDpbfz1yrVZ.js

86 lines
2.0 KiB
JavaScript

let choice1 = [
{
type : "skill",
name : "Corps à corps (Base)",
diff : {
system : {
advances : {
value : 20
}
}
}
}
]
let choice2 = [
{
type : "skill",
name : "Corps à corps (A deux mains)",
diff : {
system : {
advances : {
value : 20
}
}
}
}
]
let choice = await foundry.applications.api.DialogV2.wait({
window : {title : "Choix"},
content :
`<p>
Sélectionnez votre choix
</p>
<ol>
<li>Corps à corps (Base)</li>
<li>Corps à corps (A deux mains)</li>
</ol>
`,
buttons : [
{
action : "basic",
label : "Base",
callback : () => {
return choice1
}
},
{
action : "twoHanded",
label : "A deux mains",
callback : () => {
return choice2
}
}
]
})
let updateObj = this.actor.toObject();
let items = []
for (let c of choice)
{
let existing
if (c.type == "skill")
{
existing = updateObj.items.find(i => i.name == c.name && i.type == c.type)
if (existing && c.diff?.system?.advances?.value)
{
existing.system.advances.value += c.diff.system.advances.value
}
}
if (!existing)
{
let item = await game.wfrp4e.utility.find(c.name, c.type)
if (item)
{
item = item.toObject()
items.push(foundry.utils.mergeObject(item, (c.diff || {})))
}
else
ui.notifications.warn(`Impossible de trouver ${c.name}`, {permanent : true})
}
}
await this.actor.update(updateObj)
this.actor.createEmbeddedDocuments("Item", items);