Better import and various stuff
This commit is contained in:
@ -27,6 +27,12 @@ export class RMSSActor extends Actor {
|
||||
_prepareCharacterData(actorData) {
|
||||
if (actorData.type !== "character") return;
|
||||
|
||||
console.log("*****Flag", this.getFlag("world", "importing"));
|
||||
|
||||
if (this.getFlag("world", "importing")) {
|
||||
return; // Don't calculate skill bonuses if we are importing
|
||||
}
|
||||
|
||||
this.calculateBasicStatBonus(actorData);
|
||||
|
||||
// Calculate Stat Bonuses for the Actor
|
||||
@ -233,9 +239,7 @@ export class RMSSActor extends Actor {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -46,10 +46,11 @@ export class RMSSItem extends Item {
|
||||
prepareDerivedData() {
|
||||
const itemData = this;
|
||||
const systemData = itemData.system;
|
||||
const flags = itemData.flags.rmss || {};
|
||||
|
||||
if (this.parent?.getFlag("world", "importing")) {
|
||||
return; // Don't calculate skill bonuses if we are importing
|
||||
}
|
||||
// Make separate methods for each item type to keep things organized.
|
||||
|
||||
if (itemData.type === "skill") {
|
||||
this._prepareSkillCategoryData(itemData);
|
||||
}
|
||||
@ -68,6 +69,7 @@ export class RMSSItem extends Item {
|
||||
|
||||
_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;
|
||||
@ -103,12 +105,18 @@ export class RMSSItem extends Item {
|
||||
|
||||
calculateSelectedSkillCategoryBonus(itemData) {
|
||||
// Find the relevant skill category
|
||||
if (!this.parent) { return; } // Only if attached to an actor
|
||||
|
||||
let skillC = this.parent?.items || RFRPUtility.getSkillCategories();
|
||||
if (skillC) {
|
||||
let item = skillC.find(it => it.type == "skill_category" && it.name.toLowerCase() == itemData.system.category.toLowerCase());
|
||||
this.system.category_bonus = item.system.total_bonus;
|
||||
if (item) {
|
||||
this.system.category_bonus = item.system.total_bonus;
|
||||
} else {
|
||||
ui.notifications.warn(`Skill Category ${itemData.system.category} not found for Skill ${itemData.name}`);
|
||||
}
|
||||
} else {
|
||||
ui.notifications.warn("No Skill Categories found. Please create a Skill Category.");
|
||||
ui.notifications.info("No Skill Categories found. Please create a Skill Category.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,11 +90,11 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
context.system.attributes.power_points.modifier = "PP Exhaustion Penalty: -20 ";
|
||||
break;
|
||||
case (powerpointPercentage < 75):
|
||||
console.log("Less than 75");
|
||||
//console.log("Less than 75");
|
||||
context.system.attributes.power_points.modifier = "PP Exhaustion Penalty: -10 ";
|
||||
break;
|
||||
default:
|
||||
console.log("Setting Default");
|
||||
//console.log("Setting Default");
|
||||
context.system.attributes.power_points.modifier = "PP Exhaustion Penalty: 0 ";
|
||||
}
|
||||
|
||||
@ -117,11 +117,11 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: -15 ";
|
||||
break;
|
||||
case (exhaustionPercentage < 75):
|
||||
console.log("Less than 75");
|
||||
//console.log("Less than 75");
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: -5 ";
|
||||
break;
|
||||
default:
|
||||
console.log("Setting Default");
|
||||
//console.log("Setting Default");
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: 0 ";
|
||||
}
|
||||
|
||||
@ -175,28 +175,17 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
s.skills.push(sk);
|
||||
}
|
||||
}
|
||||
// Sort skills with localcompare
|
||||
s.skills.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
// Sort Skill/Skillcat Arrays
|
||||
skillcat.sort(function(a, b) {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
playerskill.sort(function(a, b) {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
// Sort all items
|
||||
skillcat.sort((a, b) => a.name.localeCompare(b.name));
|
||||
gear.sort((a, b) => a.name.localeCompare(b.name));
|
||||
weapons.sort((a, b) => a.name.localeCompare(b.name));
|
||||
armor.sort((a, b) => a.name.localeCompare(b.name));
|
||||
herbs.sort((a, b) => a.name.localeCompare(b.name));
|
||||
spells.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
// Assign and return
|
||||
context.gear = gear;
|
||||
|
@ -11,6 +11,7 @@ export default class RMSSToolsSCImporter extends FormApplication {
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["form"],
|
||||
width: 520,
|
||||
popOut: true,
|
||||
title: "Import Skill Categories",
|
||||
template: "systems/fvtt-rolemaster-frp/templates/sheets/apps/app_skill_category_importer.html"
|
||||
@ -29,34 +30,38 @@ export default class RMSSToolsSCImporter extends FormApplication {
|
||||
}
|
||||
|
||||
async _updateObject(event, formData) {
|
||||
//console.log("Update ", event, formData);
|
||||
await this.character.setFlag("world", "importing", true);
|
||||
|
||||
let itemType = event.submitter.value;
|
||||
let toDelete = [];
|
||||
for (const item of this.character.items) {
|
||||
if (item.type === itemType) {
|
||||
toDelete.push(item.id);
|
||||
}
|
||||
if (itemType == "skill_category" && item.type === "skill") {
|
||||
toDelete.push(item.id); // Delete also skill when re-importing skill categories.
|
||||
}
|
||||
}
|
||||
this.character.deleteEmbeddedDocuments("Item", toDelete);
|
||||
await this.character.deleteEmbeddedDocuments("Item", toDelete);
|
||||
|
||||
let comp = (itemType == "skill") ? formData.selectOptionsSkills : formData.selectOptionsCategories;
|
||||
const pack = game.packs.get(comp);
|
||||
const skillCategoryData = await pack.getIndex();
|
||||
|
||||
console.log("Importing New Skills/Skill Categories.");
|
||||
let newDocuments = [];
|
||||
let gameSystem = RFRPUtility.getGameSystem();
|
||||
for (const sc of skillCategoryData) {
|
||||
const newitem = await pack.getDocument(sc._id);
|
||||
|
||||
let newDocuments = [];
|
||||
const newitem = await pack.getDocument(sc._id);
|
||||
if (newitem.type === itemType && (newitem.system.game_system === "common" || newitem.system.game_system === gameSystem)) {
|
||||
//console.log(newitem);
|
||||
newDocuments.push(newitem);
|
||||
}
|
||||
if (newDocuments.length > 0) {
|
||||
await Item.createDocuments(newDocuments, {parent: this.character});
|
||||
}
|
||||
}
|
||||
if (newDocuments.length > 0) {
|
||||
await Item.createDocuments(newDocuments, {parent: this.character});
|
||||
}
|
||||
|
||||
await this.character.setFlag("world", "importing", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user