From 65be83dc1489ade5b6a336466a14b8c5361fc6fd Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sat, 26 Dec 2020 21:55:23 +0100 Subject: [PATCH] Some progression work, and fixed start rank level to 1 --- system/lang/en-en.json | 5 +- system/lang/es-es.json | 5 +- system/lang/fr-fr.json | 5 +- system/scripts/actors/base-sheet.js | 62 +++++++++++++------ system/scripts/actors/character-sheet.js | 36 +++++++---- system/scripts/config.js | 1 + system/template.json | 2 +- .../actors/character/experience.html | 27 +++++--- .../templates/actors/character/identity.html | 2 +- system/templates/actors/limited-sheet.html | 2 +- 10 files changed, 99 insertions(+), 48 deletions(-) diff --git a/system/lang/en-en.json b/system/lang/en-en.json index 1637a4a..46cbdbb 100644 --- a/system/lang/en-en.json +++ b/system/lang/en-en.json @@ -252,8 +252,9 @@ "total": "Total", "spent": "Used", "saved": "Saved", - "rank": "Rank Total Xp: ", - "curriculum": "in curriculum" + "rank": "Rank Total Xp", + "curriculum": "in curriculum", + "curriculum_validate": "Complete this rank" }, "npc": { "types": { diff --git a/system/lang/es-es.json b/system/lang/es-es.json index 2bfd91a..b6687ce 100644 --- a/system/lang/es-es.json +++ b/system/lang/es-es.json @@ -252,8 +252,9 @@ "total": "Total", "spent": "Usada", "saved": "Restante", - "rank": "Rank Total Xp: ", - "curriculum": "in curriculum" + "rank": "Rank Total Xp", + "curriculum": "in curriculum", + "curriculum_validate": "Complete this rank" }, "npc": { "types": { diff --git a/system/lang/fr-fr.json b/system/lang/fr-fr.json index 354ea0c..0813dcd 100644 --- a/system/lang/fr-fr.json +++ b/system/lang/fr-fr.json @@ -252,8 +252,9 @@ "total": "Totale", "spent": "Dépensée", "saved": "Restante", - "rank": "Xp Total du rang : ", - "curriculum": "Inclus dans le cursus" + "total_xp_rank": "Xp Total du rang", + "curriculum": "Inclus dans le cursus", + "curriculum_validate": "Valider la progression" }, "npc": { "types": { diff --git a/system/scripts/actors/base-sheet.js b/system/scripts/actors/base-sheet.js index dff2209..ab94663 100644 --- a/system/scripts/actors/base-sheet.js +++ b/system/scripts/actors/base-sheet.js @@ -64,25 +64,6 @@ export class BaseSheetL5r5e extends ActorSheet { return; } - // Check if technique is allowed for this character - if ( - !game.user.isGM && - item.data.type === "technique" && - !this.actor.data.data.techniques[item.data.data.technique_type] - ) { - new Dialog({ - title: game.i18n.localize("l5r5e.techniques.title"), - content: game.i18n.localize("l5r5e.techniques.not_allowed"), - buttons: { - ok: { - label: game.i18n.localize("l5r5e.global.ok"), - icon: '', - }, - }, - }).render(true); - return; - } - // Dropped a item with same "id" as one owned, add qte instead if (item.data.data.quantity && this.actor.data.items) { const tmpItem = this.actor.data.items.find((e) => e.name === item.name && e.type === item.type); @@ -104,6 +85,31 @@ export class BaseSheetL5r5e extends ActorSheet { ); } + // Item subtype specific + switch (item.data.type) { + case "advancement": + // Modify the bought at rank to the current actor rank + item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank; + break; + + case "technique": + // Check if technique is allowed for this character + if (!game.user.isGM && !this.actor.data.data.techniques[item.data.data.technique_type]) { + new Dialog({ + title: game.i18n.localize("l5r5e.techniques.title"), + content: game.i18n.localize("l5r5e.techniques.not_allowed"), + buttons: { + ok: { + label: game.i18n.localize("l5r5e.global.ok"), + icon: '', + }, + }, + }).render(true); + return; + } + break; + } + // Ok add item - Foundry override cause props const allowed = Hooks.call("dropActorSheetData", this.actor, this, item); if (allowed === false) { @@ -159,6 +165,18 @@ export class BaseSheetL5r5e extends ActorSheet { html.find(`.item-curriculum`).on("click", (event) => { this._switchSubItemCurriculum(event); }); + html.find(`button[name=validate-curriculum]`).on("click", (event) => { + this.actor.data.data.identity.school_rank = this.actor.data.data.identity.school_rank + 1; + // Update actor + this.actor.update({ + data: { + identity: { + school_rank: this.actor.data.data.identity.school_rank, + }, + }, + }); + this.render(false); + }); } /** @@ -180,6 +198,12 @@ export class BaseSheetL5r5e extends ActorSheet { type: type, }); const item = this.actor.getOwnedItem(created._id); + + // assign current school rank to the new tech + if (item.data.type === "advancement") { + item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank; + } + item.sheet.render(true); } diff --git a/system/scripts/actors/character-sheet.js b/system/scripts/actors/character-sheet.js index 74ded39..de95b3d 100644 --- a/system/scripts/actors/character-sheet.js +++ b/system/scripts/actors/character-sheet.js @@ -39,33 +39,45 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e { getData() { const sheetData = super.getData(); - // Sort Items by rank 0->6 for advancements tab + // Sort Items by rank 1->6 for advancements tab sheetData.items.sort((a, b) => { - return (a.data.bought_at_rank || 0) - (b.data.bought_at_rank || 0); + return (a.data.bought_at_rank || 1) - (b.data.bought_at_rank || 1); }); + // Min rank = 1 + this.actor.data.data.identity.school_rank = Math.max(1, this.actor.data.data.identity.school_rank); + // Xp spent only in current rank - sheetData.data.xp_spent_rank = this.getXpSpentInThisRank(); + const totalXp = this._getXpSpent(); + sheetData.data.xp_spent_rank = totalXp.rank; + sheetData.data.xp_spent = totalXp.total; + sheetData.data.xp_saved = sheetData.data.xp_total - sheetData.data.xp_spent; + sheetData.data.xp_goal = CONFIG.l5r5e.xpPerRank[this.actor.data.data.identity.school_rank - 1] || null; return sheetData; } /** - * Return the current total xp spent for this rank + * Return the total xp spent and the current total xp spent for this rank */ - getXpSpentInThisRank() { - const currentRank = this.actor.data.data.identity.school_rank || 0; - return this.actor.items.reduce((tot, item) => { - if (currentRank + 1 === item.data.data.rank) { - let xp = item.data.data.xp_used || 0; + _getXpSpent() { + const total = { + total: 0, + rank: 0, + }; + const currentRank = this.actor.data.data.identity.school_rank; + this.actor.items.map((item) => { + let xp = item.data.data.xp_used || 0; + total.total = total.total + xp; + if (currentRank === item.data.data.rank) { // if not in curriculum, xp spent /2 for this item if (!item.data.data.in_curriculum && xp > 0) { xp = Math.floor(xp / 2); } - return tot + xp; + total.rank = total.rank + xp; } - return tot; - }, 0); + }); + return total; } } diff --git a/system/scripts/config.js b/system/scripts/config.js index 050f36a..51f1dec 100644 --- a/system/scripts/config.js +++ b/system/scripts/config.js @@ -7,6 +7,7 @@ L5R5E.paths = { L5R5E.stances = ["earth", "air", "water", "fire", "void"]; L5R5E.techniques = ["kata", "kiho", "invocation", "ritual", "shuji", "maho", "ninjutsu"]; +L5R5E.xpPerRank = [20, 24, 32, 44, 60]; // Map SkillId - CategoryId L5R5E.skills = new Map(); diff --git a/system/template.json b/system/template.json index a62355c..77c463e 100644 --- a/system/template.json +++ b/system/template.json @@ -7,7 +7,7 @@ "clan": "", "family": "", "school": "", - "school_rank": 0, + "school_rank": 1, "roles": "" } }, diff --git a/system/templates/actors/character/experience.html b/system/templates/actors/character/experience.html index dab98f8..fd29b93 100644 --- a/system/templates/actors/character/experience.html +++ b/system/templates/actors/character/experience.html @@ -2,20 +2,15 @@ {{ localize 'l5r5e.experience'}} - -
@@ -37,6 +32,22 @@ {{> 'systems/l5r5e/templates/actors/character/advancement.html' advancement=advancement editable=../editable }} {{/ifCond}} {{/each}} + + + + {{#ifCond data.xp_spent_rank '>=' data.xp_goal}} + + {{/ifCond}} + + + {{ localize 'l5r5e.advancements.total_xp_rank' }} ({{data.identity.school_rank}}) : + {{ data.xp_spent_rank }} + {{#if data.xp_goal}}/{{data.xp_goal}}{{/if}} + + +
diff --git a/system/templates/actors/character/identity.html b/system/templates/actors/character/identity.html index 1f446be..dea3f0b 100644 --- a/system/templates/actors/character/identity.html +++ b/system/templates/actors/character/identity.html @@ -14,7 +14,7 @@
  • diff --git a/system/templates/actors/limited-sheet.html b/system/templates/actors/limited-sheet.html index c00c263..5e7e339 100644 --- a/system/templates/actors/limited-sheet.html +++ b/system/templates/actors/limited-sheet.html @@ -20,7 +20,7 @@