Update sheets and fix basic bugs

This commit is contained in:
2024-12-04 15:16:33 +01:00
parent 1cc3a0bc21
commit eaba806fec
33 changed files with 453 additions and 696 deletions

View File

@ -27,39 +27,21 @@ export default class LethalFantasySkill extends foundry.abstract.TypeDataModel {
computeBase() {
let actor = this.parent?.actor;
if (Number(this.base)) {
return Number(this.base) + this.bonus;
}
if (!actor) {
return `${this.base } + ${ String(this.bonus)}`;
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
}
let base = this.base.toLowerCase();
let char = actor.system.characteristics[base];
if (!char) {
ui.notifications.error(`The characteristic ${base} is wrong for actor ${actor.name}`);
return `${this.base } + ${ String(this.bonus)}`;
}
return `${this.base } + ${ String(this.bonus)}`;
let charValue = char.value;
return charValue + this.bonus
}
}