Calculate skill total bonuses

This commit is contained in:
Anthony Murphy
2022-09-12 06:22:55 +10:00
parent 3a585a5772
commit d5d5785383
5 changed files with 116 additions and 36 deletions

View File

@ -6,6 +6,7 @@ export class RMSSItem extends Item {
// 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();
}
@ -40,40 +41,77 @@ export class RMSSItem extends Item {
}
}
calculateSkillCategoryTotalBonus(itemData) {
if (this.type === "skill_category") {
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);
}
}
prepareDerivedData() {
const itemData = this;
const systemData = itemData.system;
const flags = itemData.flags.rmss || {};
// Make separate methods for each item type to keep things organized.
this._prepareSkillCategoryData(itemData);
this._prepareSkillData(itemData);
if (itemData.type === 'skill') {
this._prepareSkillCategoryData(itemData);
}
if (itemData.type === 'skill') {
this._prepareSkillData(itemData);
}
}
_prepareSkillCategoryData(itemData) {
_prepareSkillCategoryData(itemData) {
if (itemData.type !== 'skill_category') return;
// Make modifications to data here. For example:
//const data = itemData.data;
// Calculate Stat Bonuses
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 Stat Bonuses
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);
// 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;
}
}
}
}
}