Skip to content

Commit

Permalink
feat(actor): added modifications based on copy the character's sheet
Browse files Browse the repository at this point in the history
This is to new character Agente for Ordem Paranormal
  • Loading branch information
SouOWendel committed Sep 14, 2023
1 parent 32eace5 commit 39cda45
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 106 deletions.
248 changes: 142 additions & 106 deletions module/documents/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,109 +3,145 @@
* @extends {Actor}
*/
export class OrdemActor extends Actor {

/** @override */
prepareData() {
// Prepare data for the actor. Calling the super version of this executes
// the following, in order: data reset (to clear active effects),
// prepareBaseData(), prepareEmbeddedDocuments() (including active effects),
// prepareDerivedData().
super.prepareData();
}

/** @override */
prepareBaseData() {
// Data modifications in this step occur before processing embedded
// documents or derived data.
}

/**
* @override
* Augment the basic actor data with additional dynamic data. Typically,
* you'll want to handle most of your calculated/derived data in this step.
* Data calculated in this step should generally not exist in template.json
* (such as ability modifiers rather than ability scores) and should be
* available both inside and outside of character sheets (such as if an actor
* is queried and has a roll executed directly from it).
*/
prepareDerivedData() {
const actorData = this.data;
const data = actorData.data;
const flags = actorData.flags.ordemparanormal_fvtt || {};

// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
this._prepareCharacterData(actorData);
this._prepareNpcData(actorData);
}

/**
* Prepare Character type specific data
*/
_prepareCharacterData(actorData) {
if (actorData.type !== 'character') return;

// Make modifications to data here. For example:
const data = actorData.data;

// Loop through ability scores, and add their modifiers to our sheet output.
for (let [key, ability] of Object.entries(data.abilities)) {
// Calculate the modifier using d20 rules.
ability.mod = Math.floor((ability.value - 10) / 2);
}
}

/**
* Prepare NPC type specific data.
*/
_prepareNpcData(actorData) {
if (actorData.type !== 'npc') return;

// Make modifications to data here. For example:
const data = actorData.data;
data.xp = (data.cr * data.cr) * 100;
}

/**
* Override getRollData() that's supplied to rolls.
*/
getRollData() {
const data = super.getRollData();

// Prepare character roll data.
this._getCharacterRollData(data);
this._getNpcRollData(data);

return data;
}

/**
* Prepare character roll data.
*/
_getCharacterRollData(data) {
if (this.data.type !== 'character') return;

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

// Add level for easier access, or fall back to 0.
if (data.attributes.level) {
data.lvl = data.attributes.level.value ?? 0;
}
}

/**
* Prepare NPC roll data.
*/
_getNpcRollData(data) {
if (this.data.type !== 'npc') return;

// Process additional NPC data here.
}

}
/** @override */
prepareData() {
// Prepare data for the actor. Calling the super version of this executes
// the following, in order: data reset (to clear active effects),
// prepareBaseData(), prepareEmbeddedDocuments() (including active effects),
// prepareDerivedData().
super.prepareData();
}

/** @override */
prepareBaseData() {
// Data modifications in this step occur before processing embedded
// documents or derived data.
}

/**
* @override
* Augment the basic actor data with additional dynamic data. Typically,
* you'll want to handle most of your calculated/derived data in this step.
* Data calculated in this step should generally not exist in template.json
* (such as ability modifiers rather than ability scores) and should be
* available both inside and outside of character sheets (such as if an actor
* is queried and has a roll executed directly from it).
*/
prepareDerivedData() {
const actorData = this.data;
const data = actorData.data;
const flags = actorData.flags.ordemparanormal_fvtt || {};

// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
this._prepareCharacterData(actorData);
this._prepareNpcData(actorData);
this._prepareAgenteData(actorData);
}

/**
* Preparação dos dados específicos do tipo Agente
*/
_prepareAgenteData(actorData) {
if (actorData.type !== 'Agente') return;

// Make modifications to data here. For example:
const data = actorData.data;

// Loop through ability scores, and add their modifiers to our sheet output.
for (let [key, skillsName] of Object.entries(data.skills)) {
// Calculate the modifier using d20 rules.
skillsName.mod = Math.floor((skillsName.value - 10) / 2);
}
}

/**
* Prepare Character type specific data
*/
_prepareCharacterData(actorData) {
if (actorData.type !== 'character') return;

// Make modifications to data here. For example:
const data = actorData.data;

// Loop through ability scores, and add their modifiers to our sheet output.
for (let [key, ability] of Object.entries(data.abilities)) {
// Calculate the modifier using d20 rules.
ability.mod = Math.floor((ability.value - 10) / 2);
}
}

/**
* Prepare NPC type specific data.
*/
_prepareNpcData(actorData) {
if (actorData.type !== 'npc') return;

// Make modifications to data here. For example:
const data = actorData.data;
data.xp = data.cr * data.cr * 100;
}

/**
* Override getRollData() that's supplied to rolls.
*/
getRollData() {
const data = super.getRollData();

// Prepare character roll data.
this._getCharacterRollData(data);
this._getNpcRollData(data);
this._getAgenteRollData(data);

return data;
}

/**
* Preparação do dados dos agentes.
*/
_getAgenteRollData(data) {
if (this.data.type !== 'Agente') return;

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

// Add level for easier access, or fall back to 0.
if (data.attributes.level) {
data.lvl = data.attributes.level.value ?? 0;
}
}

/**
* Prepare character roll data.
*/
_getCharacterRollData(data) {
if (this.data.type !== 'character') return;

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

// Add level for easier access, or fall back to 0.
if (data.attributes.level) {
data.lvl = data.attributes.level.value ?? 0;
}
}

/**
* Prepare NPC roll data.
*/
_getNpcRollData(data) {
if (this.data.type !== 'npc') return;

// Process additional NPC data here.
}
}
14 changes: 14 additions & 0 deletions module/helpers/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ ORDEMPARANORMAL_FVTT.foobar = {
"cha": "ORDEMPARANORMAL_FVTT.AbilityCha"
};

ORDEMPARANORMAL_FVTT.skills = {
"acrobacia": "ORDEMPARANORMAL_FVTT.SkillAcrobacia",
"adestramento": "ORDEMPARANORMAL_FVTT.SkillAdest",
"artes": "ORDEMPARANORMAL_FVTT.SkillArtes"
};

ORDEMPARANORMAL_FVTT.attributes = {
"Agilidade": "ORDEMPARANORMAL_FVTT.AttAgi",
"Inteligência": "ORDEMPARANORMAL_FVTT.AttInt",
"Vigor": "ORDEMPARANORMAL_FVTT.AttVig",
"Presença": "ORDEMPARANORMAL_FVTT.AttPre",
"Força": "ORDEMPARANORMAL_FVTT.AttFor",
};

ORDEMPARANORMAL_FVTT.abilityAbbreviations = {
"str": "ORDEMPARANORMAL_FVTT.AbilityStrAbbr",
"dex": "ORDEMPARANORMAL_FVTT.AbilityDexAbbr",
Expand Down

0 comments on commit 39cda45

Please sign in to comment.