Rework folder organization
This commit is contained in:
248
module/documents/actor.js
Normal file
248
module/documents/actor.js
Normal file
@ -0,0 +1,248 @@
|
||||
export class RMSSActor 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();
|
||||
}
|
||||
|
||||
prepareDerivedData() {
|
||||
const actorData = this;
|
||||
const systemData = actorData.system;
|
||||
const flags = actorData.flags.rmss || {};
|
||||
|
||||
// Make separate methods for each Actor type (character, npc, etc.) to keep
|
||||
// things organized.
|
||||
this._prepareCharacterData(actorData);
|
||||
this._prepareNpcData(actorData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare Character specific data.
|
||||
* @param {Actor} actorData The NPC Object to prepare data for
|
||||
*/
|
||||
_prepareCharacterData(actorData) {
|
||||
if (actorData.type !== "character") return;
|
||||
|
||||
// Calculate Stat Bonuses for the Actor
|
||||
this.calculateStatBonuses(actorData);
|
||||
|
||||
// Calculate Resistance Rolls for the Actor
|
||||
this.calculateResistanceRolls(actorData);
|
||||
|
||||
// Iterate through and apply Stat bonuses for Skill Category Items
|
||||
this.calculateSkillCategoryStatBonuses();
|
||||
|
||||
// Iterate through and apply Skill Category Bonuses for Skill items
|
||||
this.calculateSkillBonuses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare NPC specific data.
|
||||
* @param {Actor} actorData The NPC Object to prepare data for
|
||||
*/
|
||||
_prepareNpcData(actorData) {
|
||||
if (actorData.type !== "npc") return;
|
||||
|
||||
// Make modifications to data here. For example:
|
||||
const data = actorData.data;
|
||||
}
|
||||
|
||||
// Tally each stat bonus and populate the total field.
|
||||
calculateStatBonuses(actorData) {
|
||||
const systemData = actorData.system;
|
||||
|
||||
actorData.system.stats.agility.stat_bonus = Number(systemData.stats.agility.racial_bonus)
|
||||
+ Number(systemData.stats.agility.special_bonus)
|
||||
+ Number(systemData.stats.agility.basic_bonus);
|
||||
|
||||
actorData.system.stats.constitution.stat_bonus = Number(systemData.stats.constitution.racial_bonus)
|
||||
+ Number(systemData.stats.constitution.special_bonus)
|
||||
+ Number(systemData.stats.constitution.basic_bonus);
|
||||
|
||||
actorData.system.stats.memory.stat_bonus = Number(systemData.stats.memory.racial_bonus)
|
||||
+ Number(systemData.stats.memory.special_bonus)
|
||||
+ Number(systemData.stats.memory.basic_bonus);
|
||||
|
||||
actorData.system.stats.reasoning.stat_bonus = Number(systemData.stats.reasoning.racial_bonus)
|
||||
+ Number(systemData.stats.reasoning.special_bonus)
|
||||
+ Number(systemData.stats.reasoning.basic_bonus);
|
||||
|
||||
|
||||
actorData.system.stats.self_discipline.stat_bonus = Number(systemData.stats.self_discipline.racial_bonus)
|
||||
+ Number(systemData.stats.self_discipline.special_bonus)
|
||||
+ Number(systemData.stats.self_discipline.basic_bonus);
|
||||
|
||||
actorData.system.stats.empathy.stat_bonus = Number(systemData.stats.empathy.racial_bonus)
|
||||
+ Number(systemData.stats.empathy.special_bonus)
|
||||
+ Number(systemData.stats.empathy.basic_bonus);
|
||||
|
||||
actorData.system.stats.intuition.stat_bonus = Number(systemData.stats.intuition.racial_bonus)
|
||||
+ Number(systemData.stats.intuition.special_bonus)
|
||||
+ Number(systemData.stats.intuition.basic_bonus);
|
||||
|
||||
actorData.system.stats.presence.stat_bonus = Number(systemData.stats.presence.racial_bonus)
|
||||
+ Number(systemData.stats.presence.special_bonus)
|
||||
+ Number(systemData.stats.presence.basic_bonus);
|
||||
|
||||
actorData.system.stats.quickness.stat_bonus = Number(systemData.stats.quickness.racial_bonus)
|
||||
+ Number(systemData.stats.quickness.special_bonus)
|
||||
+ Number(systemData.stats.quickness.basic_bonus);
|
||||
|
||||
actorData.system.stats.strength.stat_bonus = Number(systemData.stats.strength.racial_bonus)
|
||||
+ Number(systemData.stats.strength.special_bonus)
|
||||
+ Number(systemData.stats.strength.basic_bonus);
|
||||
}
|
||||
|
||||
// Calculate each Resistance Roll with the formula on the character sheet.
|
||||
calculateResistanceRolls(actorData) {
|
||||
const systemData = actorData.system;
|
||||
|
||||
actorData.system.resistance_rolls.essence.value = Number(systemData.stats.empathy.stat_bonus * 3);
|
||||
|
||||
actorData.system.resistance_rolls.channeling.value = Number(systemData.stats.intuition.stat_bonus * 3);
|
||||
|
||||
actorData.system.resistance_rolls.mentalism.value = Number(systemData.stats.presence.stat_bonus * 3);
|
||||
|
||||
actorData.system.resistance_rolls.fear.value = Number(systemData.stats.self_discipline.stat_bonus * 3);
|
||||
|
||||
actorData.system.resistance_rolls.poison_disease.value = Number(systemData.stats.constitution.stat_bonus * 3);
|
||||
|
||||
actorData.system.resistance_rolls.chann_ess.value = Number(systemData.stats.intuition.stat_bonus)
|
||||
+ Number(systemData.stats.empathy.stat_bonus);
|
||||
|
||||
actorData.system.resistance_rolls.chann_ment.value = Number(systemData.stats.intuition.stat_bonus)
|
||||
+ Number(systemData.stats.presence.stat_bonus);
|
||||
|
||||
actorData.system.resistance_rolls.ess_ment.value = Number(systemData.stats.empathy.stat_bonus)
|
||||
+ Number(systemData.stats.presence.stat_bonus);
|
||||
|
||||
actorData.system.resistance_rolls.arcane.value = Number(systemData.stats.empathy.stat_bonus)
|
||||
+ Number(systemData.stats.intuition.stat_bonus)
|
||||
+ Number(systemData.stats.presence.stat_bonus);
|
||||
|
||||
actorData.system.resistance_rolls.essence.total = actorData.system.resistance_rolls.essence.value
|
||||
+ actorData.system.resistance_rolls.essence.race_mod;
|
||||
|
||||
actorData.system.resistance_rolls.channeling.total = actorData.system.resistance_rolls.channeling.value
|
||||
+ actorData.system.resistance_rolls.channeling.race_mod;
|
||||
|
||||
actorData.system.resistance_rolls.mentalism.total = actorData.system.resistance_rolls.mentalism.value
|
||||
+ actorData.system.resistance_rolls.mentalism.race_mod;
|
||||
|
||||
actorData.system.resistance_rolls.fear.total = actorData.system.resistance_rolls.fear.value
|
||||
+ actorData.system.resistance_rolls.fear.race_mod;
|
||||
|
||||
actorData.system.resistance_rolls.poison_disease.total = actorData.system.resistance_rolls.poison_disease.value
|
||||
+ actorData.system.resistance_rolls.poison_disease.race_mod;
|
||||
|
||||
actorData.system.resistance_rolls.chann_ess.total = actorData.system.resistance_rolls.chann_ess.value
|
||||
+ actorData.system.resistance_rolls.chann_ess.race_mod;
|
||||
|
||||
actorData.system.resistance_rolls.chann_ment.total = actorData.system.resistance_rolls.chann_ment.value
|
||||
+ actorData.system.resistance_rolls.chann_ment.race_mod;
|
||||
|
||||
actorData.system.resistance_rolls.ess_ment.total = actorData.system.resistance_rolls.ess_ment.value
|
||||
+ actorData.system.resistance_rolls.ess_ment.race_mod;
|
||||
|
||||
actorData.system.resistance_rolls.arcane.total = actorData.system.resistance_rolls.arcane.value
|
||||
+ actorData.system.resistance_rolls.arcane.race_mod;
|
||||
}
|
||||
|
||||
calculateSkillBonuses() {
|
||||
for (const item of this.items) {
|
||||
if (item.type === "skill") {
|
||||
console.log(`rmss | actor.js | Calculating skill bonus for Skill: ${item.name}`);
|
||||
console.log(`rmss | actor.js | Updating Skill Category Bonus for Skill: ${item.name}`);
|
||||
item.calculateSelectedSkillCategoryBonus(item);
|
||||
console.log(`rmss | actor.js | Updating Skill Total Bonus for Skill: ${item.name}`);
|
||||
item.calculateSkillTotalBonus(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tallys the bonus for each Stat that is applicable to the Skill Category and then updates the total
|
||||
calculateSkillCategoryStatBonuses() {
|
||||
for (const item of this.items) {
|
||||
if (item.type === "skill_category") {
|
||||
|
||||
console.log(`rmss | actor.js | Calculating Skill Category Stat Bonuses for: ${item.name}`);
|
||||
// Get all the applicable stats for this skill category
|
||||
let app_stat_1 = item.system.app_stat_1;
|
||||
let app_stat_2 = item.system.app_stat_2;
|
||||
let app_stat_3 = item.system.app_stat_3;
|
||||
|
||||
// If the first one is None we don't need to do anything further
|
||||
if (app_stat_1 === "None") {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
let applicable_stat_bonus = 0;
|
||||
|
||||
let app_stat_1_found = false;
|
||||
let app_stat_2_found = false;
|
||||
let app_stat_3_found = false;
|
||||
|
||||
// Iterate through the applicable stats and find their full names
|
||||
for (const stat in CONFIG.rmss.stats) {
|
||||
// If the configured App Stat matches the one of the stats in config
|
||||
if (app_stat_1 === CONFIG.rmss.stats[stat].shortname) {
|
||||
app_stat_1_found = true;
|
||||
// Get the Stat Bonus
|
||||
applicable_stat_bonus = applicable_stat_bonus + this.system.stats[stat].stat_bonus;
|
||||
}
|
||||
if (app_stat_2 === CONFIG.rmss.stats[stat].shortname) {
|
||||
app_stat_2_found = true;
|
||||
applicable_stat_bonus = applicable_stat_bonus + this.system.stats[stat].stat_bonus;
|
||||
}
|
||||
if (app_stat_3 === CONFIG.rmss.stats[stat].shortname) {
|
||||
app_stat_3_found = true;
|
||||
applicable_stat_bonus = applicable_stat_bonus + this.system.stats[stat].stat_bonus;
|
||||
}
|
||||
}
|
||||
|
||||
if (app_stat_1_found === true && app_stat_2_found === true && app_stat_3_found === true) {
|
||||
// Apply the update if we found stat bonuses for every applicable stat
|
||||
item.system.stat_bonus = applicable_stat_bonus;
|
||||
|
||||
// Update the total in the Item
|
||||
item.calculateSkillCategoryTotalBonus(item);
|
||||
}
|
||||
else if (app_stat_1_found === true && app_stat_2_found === true && app_stat_3_found === false) {
|
||||
// Apply the update if we found stat bonuses for the first two applicable stats
|
||||
item.system.stat_bonus = applicable_stat_bonus;
|
||||
|
||||
// Update the total in the Item
|
||||
item.calculateSkillCategoryTotalBonus(item);
|
||||
}
|
||||
else if (app_stat_1_found === true && app_stat_2_found === false && app_stat_3_found === false) {
|
||||
// Apply the update if we found stat bonuses for the first applicable stat
|
||||
item.system.stat_bonus = applicable_stat_bonus;
|
||||
|
||||
// Update the total in the Item
|
||||
item.calculateSkillCategoryTotalBonus(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For each skill category return an object in this format.
|
||||
// {{ _id: "skill category name"}}
|
||||
// This is the format that the select helper on the skill sheet needs
|
||||
|
||||
getOwnedItemsByType(item_type) {
|
||||
let ownedItems = {None: "None"};
|
||||
console.log(`rmss | actor.js | Getting owned ${item_type} for: ${this.name}`);
|
||||
for (const item of this.items) {
|
||||
if (item.type === item_type) {
|
||||
ownedItems[item._id] = item.name;
|
||||
}
|
||||
}
|
||||
return (ownedItems);
|
||||
}
|
||||
}
|
118
module/documents/item.js
Normal file
118
module/documents/item.js
Normal file
@ -0,0 +1,118 @@
|
||||
export class RMSSItem extends Item {
|
||||
|
||||
/** @override */
|
||||
prepareData() {
|
||||
// Prepare data for the item. Calling the super version of this executes
|
||||
// the following, in order: data reset (to clear active effects),
|
||||
// prepareBaseData(), prepareEmbeddedDocuments() (including active effects),
|
||||
// prepareDerivedData().
|
||||
console.log(`rmss | item.js | prepareData for: ${this.name}`);
|
||||
super.prepareData();
|
||||
}
|
||||
|
||||
// Set the icon images for newly created images.
|
||||
async _preCreate(data, options, userId) {
|
||||
await super._preCreate(data, options, userId);
|
||||
|
||||
// Do not set on copied items if they have a custom Icon.
|
||||
if (!data.name.includes("(Copy)"))
|
||||
{
|
||||
if (this.type === "armor") {
|
||||
await this.updateSource({img: "systems/rmss/assets/default/armor.svg"});
|
||||
}
|
||||
else if (this.type === "weapon") {
|
||||
await this.updateSource({img: "systems/rmss/assets/default/weapon.svg"});
|
||||
}
|
||||
else if (this.type === "skill") {
|
||||
await this.updateSource({img: "systems/rmss/assets/default/skill.svg"});
|
||||
}
|
||||
else if (this.type === "skill_category") {
|
||||
await this.updateSource({img: "systems/rmss/assets/default/skill_category.svg"});
|
||||
}
|
||||
else if (this.type === "spell") {
|
||||
await this.updateSource({img: "systems/rmss/assets/default/spell.svg"});
|
||||
}
|
||||
else if (this.type === "herb_or_poison") {
|
||||
await this.updateSource({img: "systems/rmss/assets/default/herb_or_poison.svg"});
|
||||
}
|
||||
else if (this.type === "transport") {
|
||||
await this.updateSource({img: "systems/rmss/assets/default/transport.svg"});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prepareDerivedData() {
|
||||
const itemData = this;
|
||||
const systemData = itemData.system;
|
||||
const flags = itemData.flags.rmss || {};
|
||||
|
||||
// Make separate methods for each item type to keep things organized.
|
||||
|
||||
if (itemData.type === "skill") {
|
||||
this._prepareSkillCategoryData(itemData);
|
||||
}
|
||||
|
||||
if (itemData.type === "skill") {
|
||||
this._prepareSkillData(itemData);
|
||||
}
|
||||
}
|
||||
|
||||
_prepareSkillCategoryData(itemData) {
|
||||
if (itemData.type !== "skill_category") return;
|
||||
console.log(`rmss | item.js | Preparing Skill Category Data for: ${itemData.name}`);
|
||||
// Calculate Skill Category Total Bonus
|
||||
this.calculateSkillCategoryTotalBonus(itemData);
|
||||
}
|
||||
|
||||
_prepareSkillData(itemData) {
|
||||
if (itemData.type !== "skill") return;
|
||||
console.log(`rmss | item.js | Preparing Skill Data for: ${itemData.name}`);
|
||||
// Make modifications to data here. For example:
|
||||
// const systemData = itemData.system;
|
||||
// Calculate Skill Category Bonus
|
||||
this.calculateSelectedSkillCategoryBonus(itemData);
|
||||
// Calculate Skill Total Bonus
|
||||
this.calculateSkillTotalBonus(itemData);
|
||||
}
|
||||
|
||||
calculateSkillCategoryTotalBonus(itemData) {
|
||||
if (this.type === "skill_category") {
|
||||
console.log(`rmss | item.js | Calculating Skill Category Total Bonus for: ${itemData.name}`);
|
||||
const systemData = itemData.system;
|
||||
itemData.system.total_bonus = Number(systemData.rank_bonus)
|
||||
+ Number(systemData.stat_bonus)
|
||||
+ Number(systemData.prof_bonus)
|
||||
+ Number(systemData.special_bonus_1)
|
||||
+ Number(systemData.special_bonus_2);
|
||||
}
|
||||
}
|
||||
|
||||
calculateSkillTotalBonus(itemData) {
|
||||
if (this.type === "skill") {
|
||||
const systemData = itemData.system;
|
||||
console.log(`rmss | item.js | Calculating Skill Total Bonus for: ${itemData.name}`);
|
||||
itemData.system.total_bonus = Number(systemData.rank_bonus)
|
||||
+ Number(systemData.category_bonus)
|
||||
+ Number(systemData.item_bonus)
|
||||
+ Number(systemData.special_bonus_1)
|
||||
+ Number(systemData.special_bonus_2);
|
||||
}
|
||||
}
|
||||
|
||||
calculateSelectedSkillCategoryBonus(itemData) {
|
||||
if (this.isEmbedded === null) {
|
||||
console.log(`rmss | item.js | Skill ${this.name} has no owner. Not calculating Skill Category bonus`);
|
||||
}
|
||||
else
|
||||
{
|
||||
const items = this.parent.items;
|
||||
console.log(`rmss | item.js | Skill ${this.name} has owner, calculating skill category bonus.`);
|
||||
for (const item of items) {
|
||||
if (item.type === "skill_category" && item._id === itemData.system.category) {
|
||||
console.log(`rmss | item.js | Calculating Skill Category bonus for skill: ${this.name}`);
|
||||
this.system.category_bonus = item.system.total_bonus;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user