foundryvtt-wh4-lang-fr-fr/scripts/v5xrDWcrTNFJkyQB.js

84 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2024-05-16 17:57:51 +02:00
let choice1 = [
2024-06-06 22:46:40 +02:00
{
type: "skill",
name: "Projectiles (Arc)",
diff: {
system: {
advances: {
value: 10
2024-05-16 17:57:51 +02:00
}
2024-06-06 22:46:40 +02:00
}
2024-05-16 17:57:51 +02:00
}
2024-06-06 22:46:40 +02:00
},
{
type: "weapon",
name: "Arc long",
},
{
type: "ammunition",
name: "Flèche",
}
2024-05-16 17:57:51 +02:00
]
let choice2 = [
]
let choice = await Dialog.wait({
2024-06-06 22:46:40 +02:00
title: "Option",
content:
2024-05-16 17:57:51 +02:00
`<p>
Ajouter l'ption?
2024-05-16 17:57:51 +02:00
</p>
<ol>
<li>Ranged (Bow) +10 and a Longbow with 12 Arrows</li>
</ol>
`,
2024-06-06 22:46:40 +02:00
buttons: {
1: {
label: "Oui",
callback: () => {
return choice1;
}
},
2: {
label: "Non",
callback: () => {
return choice2;
}
2024-05-16 17:57:51 +02:00
}
2024-06-06 22:46:40 +02:00
}
2024-05-16 17:57:51 +02:00
})
let updateObj = this.actor.toObject();
let items = []
2024-06-06 22:46:40 +02:00
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
2024-05-16 17:57:51 +02:00
}
2024-06-06 22:46:40 +02:00
}
2024-05-16 17:57:51 +02:00
2024-06-06 22:46:40 +02:00
if (!existing) {
let item = await game.wfrp4e.utility.find(c.name, c.type)
if (item) {
item = item.toObject()
equip(item);
items.push(foundry.utils.mergeObject(item, (c.diff || {})))
2024-05-16 17:57:51 +02:00
}
2024-06-06 22:46:40 +02:00
else
ui.notifications.warn(`Impossible de trouver ${talent}`, { permanent: true })
}
2024-05-16 17:57:51 +02:00
}
await this.actor.update(updateObj)
this.actor.createEmbeddedDocuments("Item", items);
2024-06-06 22:46:40 +02:00
function equip(item) {
if (item.type == "armour")
item.system.worn.value = true
else if (item.type == "weapon")
item.system.equipped = true
else if (item.type == "trapping" && item.system.trappingType.value == "clothingAccessories")
item.system.worn = true
2024-05-16 17:57:51 +02:00
}