Working on Skills and some fixes

- Added Skills to character sheet
- Added migration to old skills
- Added icon on skills
- Added actor.isNpc
- Money out of system
This commit is contained in:
Vlyan
2023-01-08 15:12:22 +01:00
parent 1ec9e65ca5
commit 710afd9804
22 changed files with 302 additions and 145 deletions

View File

@@ -6,7 +6,7 @@ export class MigrationL5r5e {
* Minimum Version needed for migration stuff to trigger
* @type {string}
*/
static NEEDED_VERSION = "1.3.0";
static NEEDED_VERSION = "2.0.0";
/**
* Return true if the version need some updates
@@ -28,6 +28,11 @@ export class MigrationL5r5e {
return;
}
// Wait for translation to load
if (!options.force && typeof Babele !== "undefined") {
await new Promise((r) => setTimeout(r, 5000));
}
// if (MigrationL5r5e.needUpdate("1.3.0")) {
// ChatMessage.create({"content": "<strong>L5R5E v1.3.0 :</strong><br>"});
// }
@@ -42,7 +47,7 @@ export class MigrationL5r5e {
// Migrate World Actors
for (let actor of game.actors.contents) {
try {
const updateData = MigrationL5r5e._migrateActorData(actor, options);
const updateData = await MigrationL5r5e._migrateActorData(actor, options);
if (!foundry.utils.isEmpty(updateData)) {
console.log(`L5R5E | Migrating Actor document ${actor.name}[${actor._id}]`);
await actor.update(updateData);
@@ -227,7 +232,7 @@ export class MigrationL5r5e {
* @param options
* @return {Object} The updateData to apply
*/
static _migrateActorData(actor, options = { force: false }) {
static async _migrateActorData(actor, options = { force: false }) {
const updateData = {};
const system = actor.system;
@@ -245,7 +250,7 @@ export class MigrationL5r5e {
}
// NPC are now without autostats, we need to save the value
if (actor.type === "npc") {
if (actor.isNpc) {
if (system.endurance < 1) {
updateData["system.endurance"] = (Number(system.rings.earth) + Number(system.rings.fire)) * 2;
updateData["system.composure"] = (Number(system.rings.earth) + Number(system.rings.water)) * 2;
@@ -266,7 +271,7 @@ export class MigrationL5r5e {
}
// NPC have now more than a Strength and a Weakness
if (actor.type === "npc" && system.rings_affinities?.strength) {
if (actor.isNpc && system.rings_affinities?.strength) {
const aff = system.rings_affinities;
updateData["system.rings_affinities." + aff.strength.ring] = aff.strength.value;
updateData["system.rings_affinities." + aff.weakness.ring] = aff.weakness.value;
@@ -278,6 +283,28 @@ export class MigrationL5r5e {
}
// ***** End of 1.3.0 *****
// ***** Start of 2.0.0 *****
if (options?.force || MigrationL5r5e.needUpdate("2.0.0")) {
// Only PC : Convert fixed skills to items list
if (actor.isCharacter && Array.from(actor.items).every(i => i.type !== "skill")) {
// Add skills items
const update = {items: [], name: actor.name};
await game.l5r5e.ActorL5r5e.addSkillsFromCompendiums(update);
// Set actor value
update.items.forEach(item => {
const skillId = item.flags?.l5r5e?.skillCoreId;
const skillCatId = CONFIG.l5r5e.skills.get(skillId);
if (skillCatId && system.skills[skillCatId][skillId]) {
item.system.rank = system.skills[skillCatId][skillId];
}
});
updateData.items = update.items;
}
}
// ***** End of 2.0.0 *****
return updateData;
}