Upgrade item sheets

This commit is contained in:
2024-12-03 13:51:38 +01:00
parent df8995f8b7
commit 9775ec9fa1
38 changed files with 1095 additions and 506 deletions

View File

@ -21,4 +21,47 @@ export default class LethalFantasySkill extends foundry.abstract.TypeDataModel {
get skillCategory() {
return game.i18n.localize(CATEGORY[this.category].label)
}
prepareDerivedData() {
super.prepareDerivedData();
this.skillTotal = this.computeBase();
}
computeBase() {
let actor = this.parent?.actor;
if (!actor) {
return `${this.base } + ${ String(this.bonus)}`;
}
// Split the base value per stat : WIS,DEX,STR,INT,CHA (example)
const base = this.base;
let baseSplit = base.split(",");
let baseSplitLength = baseSplit.length;
if ( baseSplitLength > 0) {
// Select the max stat value from the parent actor
let maxStat = 0;
for (let i = 0; i < baseSplitLength; i++) {
const stat = baseSplit[i];
const statValue = actor.system.characteristics[stat.toLowerCase()]?.value || 0;
if (statValue > maxStat) {
maxStat = statValue;
}
}
return maxStat;
} else {
// Split with + calculate the total
baseSplit = base.split("+");
baseSplitLength = baseSplit.length;
if ( baseSplitLength > 0) {
let total = 0;
for (let i = 0; i < baseSplitLength; i++) {
const stat = baseSplit[i];
const statValue = actor.system.characteristics[stat.toLowerCase()]?.value || 0;
total += statValue;
}
return total
}
}
return `${this.base } + ${ String(this.bonus)}`;
}
}