Skip to content

Commit

Permalink
feat(actor and fix): added the @RollInitiative tag to generate roll f…
Browse files Browse the repository at this point in the history
…ormula and to use it in combat

fix the roll initiative in combat page of FoundryVTT
  • Loading branch information
SouOWendel committed Oct 17, 2023
1 parent 5957453 commit f3a2dd1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions module/documents/actor.mjs
Expand Up @@ -92,7 +92,7 @@ export class OrdemActor extends Actor {
else if (skillsName.degree.label == 'Expert') skillsName.value = 15;
else skillsName.value = 0;

console.log(JSON.stringify(skillsName.degree) + skillsName.value);
// console.log(JSON.stringify(skillsName.degree) + skillsName.value);
}
}

Expand All @@ -114,17 +114,30 @@ export class OrdemActor extends Actor {
_getAgentRollData(data) {
if (this.data.type !== 'agent') return;

// Copy the ability scores to the top level, so that rolls can use
// formulas like `@str.mod + 4`.
// Copy the skills scores to the top level, so that rolls can use
// formulas like `@iniciativa.value + 4`.
if (data.skills) {
for (const [k, v] of Object.entries(data.skills)) {
data[k] = foundry.utils.deepClone(v);
}
}

// Copy the attributes to the top level, so that rolls can use
// formulas like `@agi.value`.
if(data.attributes) {
for (const [k, v] of Object.entries(data.attributes)) {
data[k] = foundry.utils.deepClone(v);
}
}

if(data.attributes && data.skills) {
data.rollInitiative = data.attributes.agi.value + 'd20' +
((data.attributes.agi.value == 0) ? 'kl' : 'kh') + '+' + data.skills.iniciativa.value;
}

// Add level for easier access, or fall back to 0.
if (data.NEX) {
data.lvl = data.NEX.value ?? 0;
data.nex = data.NEX.value ?? 0;
}
}
}
3 changes: 2 additions & 1 deletion module/ordemparanormal_fvtt.mjs
Expand Up @@ -30,8 +30,9 @@ Hooks.once('init', async function () {
* Set an initiative formula for the system
* @type {String}
*/

CONFIG.Combat.initiative = {
formula: '(@skills.attributos.agi.value)d20 + @skills.iniciativa.value',
formula: '@rollInitiative',
decimals: 2,
};

Expand Down

0 comments on commit f3a2dd1

Please sign in to comment.