Fix js error when Advancement is not in a actor

This commit is contained in:
Vlyan
2021-01-22 15:08:26 +01:00
parent 2cdce21407
commit a958e17278

View File

@@ -95,46 +95,55 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
* @private
*/
async _updateChoice(oldChoice, newChoice) {
let skillCatId = null;
const actor = duplicate(this.actor.data.data);
let xp_used = this.object.data.data.xp_used;
let name = this.object.data.name;
let img = this.object.data.img;
// Old choices
if (oldChoice.ring) {
actor.rings[oldChoice.ring] = Math.max(1, actor.rings[oldChoice.ring] - 1);
}
if (oldChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(oldChoice.skill);
actor.skills[skillCatId][oldChoice.skill] = Math.max(0, actor.skills[skillCatId][oldChoice.skill] - 1);
}
// new choices
// Modify image to reflect choice
if (newChoice.ring) {
actor.rings[newChoice.ring] = actor.rings[newChoice.ring] + 1;
xp_used = actor.rings[newChoice.ring] * CONFIG.l5r5e.xp.ringCostMultiplier;
name =
game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) +
` +1 (${actor.rings[newChoice.ring] - 1} -> ${actor.rings[newChoice.ring]})`;
img = `systems/l5r5e/assets/icons/rings/${newChoice.ring}.svg`;
}
if (newChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(newChoice.skill);
actor.skills[skillCatId][newChoice.skill] = actor.skills[skillCatId][newChoice.skill] + 1;
xp_used = actor.skills[skillCatId][newChoice.skill] * CONFIG.l5r5e.xp.skillCostMultiplier;
name =
game.i18n.localize(`l5r5e.skills.${skillCatId}.${newChoice.skill}`) +
` +1 (${actor.skills[skillCatId][newChoice.skill] - 1} -> ${
actor.skills[skillCatId][newChoice.skill]
})`;
} else if (newChoice.skill) {
img = `systems/l5r5e/assets/dices/default/skill_blank.svg`;
}
// Update Actor
await this.actor.update({
data: diffObject(this.actor.data.data, actor),
});
// Object embed in actor ?
if (this.actor) {
const actor = duplicate(this.actor.data.data);
let skillCatId = null;
// Old choices
if (oldChoice.ring) {
actor.rings[oldChoice.ring] = Math.max(1, actor.rings[oldChoice.ring] - 1);
}
if (oldChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(oldChoice.skill);
actor.skills[skillCatId][oldChoice.skill] = Math.max(0, actor.skills[skillCatId][oldChoice.skill] - 1);
}
// new choices
if (newChoice.ring) {
actor.rings[newChoice.ring] = actor.rings[newChoice.ring] + 1;
xp_used = actor.rings[newChoice.ring] * CONFIG.l5r5e.xp.ringCostMultiplier;
name =
game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) +
` +1 (${actor.rings[newChoice.ring] - 1} -> ${actor.rings[newChoice.ring]})`;
}
if (newChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(newChoice.skill);
actor.skills[skillCatId][newChoice.skill] = actor.skills[skillCatId][newChoice.skill] + 1;
xp_used = actor.skills[skillCatId][newChoice.skill] * CONFIG.l5r5e.xp.skillCostMultiplier;
name =
game.i18n.localize(`l5r5e.skills.${skillCatId}.${newChoice.skill}`) +
` +1 (${actor.skills[skillCatId][newChoice.skill] - 1} -> ${
actor.skills[skillCatId][newChoice.skill]
})`;
}
// Update Actor
await this.actor.update({
data: diffObject(this.actor.data.data, actor),
});
}
// Update object
await this.object.update({