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

@ -1,22 +1,26 @@
Small
1. Add Relationship between skills and skill categories
1. DONE - Add Relationship between skills and skill categories
2. Remove Tables and replace with CSS Grid
3. Fix unaligned CSS
4. Prevent Duplication on Drag and Drop for Skills and Skill Categories, possibly spells too.
DONE - Overriden _onDropItem on Player Sheet
DONE - Skill Categories cannot be renamed if they are owned.
DONE - Skills and Skill Categories are now seperate checks for Drag and Drop as some share names
Spells ?
5. Fix New Ranks Clickboxes - https://discord.com/channels/170995199584108546/670336275496042502/1018530650980102195
6. Fix Favorites Clickboxes on Actor Page
Medium
4. Inventory sorted by types
i. Drag and drop should add an item if it already exists.
i. Drag and drop should increment an item if it already exists.
ii. Equipables
iii. Favorites
5. Creature Sheet
6. Finish Character Sheet
Large
6. Dice Roller
7. Initiative System

View File

@ -27,14 +27,16 @@ export class RMSSActor extends Actor {
if (actorData.type !== 'character') return;
// Calculate Stat Bonuses for the Actor
this.prepareStatBonuses(actorData);
this.calculateStatBonuses(actorData);
// Calculate Resistance Rolls for the Actor
this.prepareResistanceRolls(actorData);
this.calculateResistanceRolls(actorData);
// Iterate through and apply Stat bonuses for Skill Category Items
this.prepareSkillCategoryStatBonuses();
this.calculateSkillCategoryStatBonuses();
// Iterate through and apply Skill Category Bonuses for Skill items
this.calculateSkillBonuses();
}
/**
@ -45,11 +47,10 @@ export class RMSSActor extends Actor {
// Make modifications to data here. For example:
const data = actorData.data;
data.xp = (data.cr * data.cr) * 100;
}
// Tally each stat bonus and populate the total field.
prepareStatBonuses(actorData) {
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);
@ -64,7 +65,7 @@ export class RMSSActor extends Actor {
}
// Calculate each Resistance Roll with the formula on the character sheet.
prepareResistanceRolls(actorData) { // TODO: Add Racial modifiers to resistance
calculateResistanceRolls(actorData) { // TODO: Add Racial modifiers to resistance
const systemData = actorData.system;
actorData.system.resistance_rolls.essence = Number(systemData.stats.empathy.stat_bonus * 3);
actorData.system.resistance_rolls.channeling = Number(systemData.stats.intuition.stat_bonus * 3);
@ -77,19 +78,24 @@ export class RMSSActor extends Actor {
actorData.system.resistance_rolls.arcane = Number(systemData.stats.empathy.stat_bonus) + Number(systemData.stats.intuition.stat_bonus) + Number(systemData.stats.presence.stat_bonus);
}
/*prepareSkillCategoryBonuses() {
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
prepareSkillCategoryStatBonuses() {
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
var app_stat_1 = item.system.app_stat_1;
var app_stat_2 = item.system.app_stat_2;
@ -142,6 +148,7 @@ export class RMSSActor extends Actor {
// This is the format that the select helper on the skill sheet needs
getOwnedSkillCategories() {
var ownedSkillCategories = {None: "None"};
console.log("rmss | actor.js | Getting owned skill categories for: " + this.name);
for (const item of this.items) {
if (item.type === "skill_category") {
ownedSkillCategories[item._id] = item.name;
@ -149,4 +156,16 @@ export class RMSSActor extends Actor {
}
return(ownedSkillCategories);
}
getOwnedSkills() {
var ownedSkills = {None: "None"};
console.log("rmss | actor.js | Getting owned skills for: " + this.name);
for (const item of this.items) {
if (item.type === "skill") {
ownedSkills[item._id] = item.name;
}
}
return(ownedSkills);
}
}

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.
if (itemData.type === 'skill') {
this._prepareSkillCategoryData(itemData);
}
if (itemData.type === 'skill') {
this._prepareSkillData(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 Stat Bonuses
// 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;
}
}
}
}
}

View File

@ -41,7 +41,8 @@ export default class RMSSPlayerSheet extends ActorSheet {
const newitem = await Item.implementation.fromDropData(data);
const itemData = newitem.toObject();
if (itemData.type === "skill_category" || itemData.type === "skill"){
// To Do: Seperate Skills and Skill Categories. Increment Counts for items
if (itemData.type === "skill_category"){
// Get the already owned Items from the actor and push into an array
const owneditems = this.object.getOwnedSkillCategories();
@ -50,6 +51,19 @@ export default class RMSSPlayerSheet extends ActorSheet {
var owneditemslist = Object.values(owneditems);
// Check if the dragged item is not in the array and not owned
if (!owneditemslist.includes(itemData.name)) {
console.log("Not Owned!");
super._onDropItem(event, data);
}
} else if ( itemData.type === "skill") {
// Get the already owned Items from the actor and push into an array
const owneditems = this.object.getOwnedSkills();
console.log(owneditems);
var owneditemslist = Object.values(owneditems);
// Check if the dragged item is not in the array and not owned
if (!owneditemslist.includes(itemData.name)) {
console.log("Not Owned!");
@ -65,6 +79,7 @@ export default class RMSSPlayerSheet extends ActorSheet {
}
_prepareItems(context) {
console.log("rmss | rmss_player_sheet.js | Preparing items for: "+ this.name);
// Initialize containers.
const gear = [];
const playerskill= [];
@ -145,12 +160,16 @@ export default class RMSSPlayerSheet extends ActorSheet {
async _onItemCreate(event) {
event.preventDefault();
const header = event.currentTarget;
// Get the type of item to create.
const type = header.dataset.type;
// Grab any data associated with this control.
const data = duplicate(header.dataset);
// Initialize a default name.
const name = `New ${type.capitalize()}`;
// Prepare the item object.
const itemData = {
name: name,
@ -158,7 +177,6 @@ export default class RMSSPlayerSheet extends ActorSheet {
data: data
};
// Remove the type from the dataset since it's in the itemData.type prop.
//delete itemData.data["type"];
delete itemData.data.type;
// Finally, create the item!
return await Item.create(itemData, {parent: this.actor});

View File

@ -28,7 +28,7 @@ export default class RMSSSkillSheet extends ItemSheet {
// Figure out if a valid Skill Category is already selected
var selected_skillcat = this.prepareSelectedSkillCategory(owned_skillcats, this.object.system.category);
this.prepareSelectedSkillCategoryBonus(selected_skillcat);
//this.prepareSelectedSkillCategoryBonus(selected_skillcat);
let sheetData = {
owner: this.item.isOwner,
@ -82,6 +82,7 @@ export default class RMSSSkillSheet extends ItemSheet {
for (const item of items) {
if (item.type === "skill_category" && item._id === selected_skillcat) {
console.log("rmss | rmss_skill_sheet | Calculating Skill Category bonus for skill: " + this.object.name);
this.object.system.category_bonus = item.system.total_bonus;
}
}