2024-05-16 17:57:51 +02:00
|
|
|
let caster = this.effect.sourceActor
|
|
|
|
let targetedItem = this.actor.items.get(this.effect.flags.wfrp4e.itemTargets[0])
|
|
|
|
|
|
|
|
let qualities = foundry.utils.deepClone(game.wfrp4e.config.itemQualities);
|
|
|
|
let flaws = foundry.utils.deepClone(game.wfrp4e.config.itemFlaws);
|
|
|
|
|
2024-06-06 22:46:40 +02:00
|
|
|
if (targetedItem.type == "weapon") {
|
|
|
|
foundry.utils.mergeObject(qualities, game.wfrp4e.config.weaponQualities)
|
|
|
|
foundry.utils.mergeObject(flaws, game.wfrp4e.config.weaponFlaws)
|
2024-05-16 17:57:51 +02:00
|
|
|
}
|
2024-06-06 22:46:40 +02:00
|
|
|
else if (targetedItem.type == "armour") {
|
|
|
|
foundry.utils.mergeObject(qualities, game.wfrp4e.config.armorQualities)
|
|
|
|
foundry.utils.mergeObject(flaws, game.wfrp4e.config.armorFlaws)
|
2024-05-16 17:57:51 +02:00
|
|
|
}
|
|
|
|
|
2024-06-06 22:46:40 +02:00
|
|
|
for (let q in qualities) {
|
|
|
|
// If the weapon already has a flaw, don't put it in the dialog
|
|
|
|
if (targetedItem.system.properties.qualities[q]) {
|
|
|
|
delete qualities[q]
|
|
|
|
}
|
2024-05-16 17:57:51 +02:00
|
|
|
}
|
2024-06-06 22:46:40 +02:00
|
|
|
for (let f in flaws) {
|
|
|
|
// If a weapon doesn't have a flaw, don't put it in the dialog
|
|
|
|
if (!targetedItem.system.properties.flaws[f]) {
|
|
|
|
delete flaws[f]
|
|
|
|
}
|
2024-05-16 17:57:51 +02:00
|
|
|
}
|
2024-06-06 22:46:40 +02:00
|
|
|
|
2024-05-17 01:07:37 +02:00
|
|
|
let added = await ItemDialog.create(ItemDialog.objectToArray(qualities), "unlimited", "Choisissez la Qualité à ajouter");
|
2024-05-16 17:57:51 +02:00
|
|
|
let removed = []
|
2024-06-06 22:46:40 +02:00
|
|
|
if (!foundry.utils.isEmpty(flaws)) {
|
|
|
|
removed = await ItemDialog.create(ItemDialog.objectToArray(flaws), "unlimited", "Choisissez le Défaut à enlever");
|
2024-05-16 17:57:51 +02:00
|
|
|
}
|
|
|
|
|
2024-06-06 22:46:40 +02:00
|
|
|
this.effect.updateSource({ "flags.wfrp4e.propertiesChanged": { added: added.map(i => i.id), removed: removed.map(i => i.id) } })
|