From 991c65b10516f268bf1215b2bfa3d2851fe9696f Mon Sep 17 00:00:00 2001 From: Vlyan Date: Mon, 11 Jan 2021 22:33:04 +0100 Subject: [PATCH] 20Q added step 7 and 17 no point rule Fix for skill errors --- .../scripts/actors/twenty-questions-dialog.js | 23 ++++++++++++++++++- system/scripts/actors/twenty-questions.js | 8 +++---- .../actors/twenty-questions-dialog.html | 4 ++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/system/scripts/actors/twenty-questions-dialog.js b/system/scripts/actors/twenty-questions-dialog.js index eed01d1..4aaa519 100644 --- a/system/scripts/actors/twenty-questions-dialog.js +++ b/system/scripts/actors/twenty-questions-dialog.js @@ -131,10 +131,16 @@ export class TwentyQuestionsDialog extends FormApplication { * @return {Object} */ async getData(options = null) { + const skillsPoints = this.object.summariesRingsOrSkills("skillList"); + const skillsList = game.l5r5e.HelpersL5r5e.getSkillsList(true); + const skillsListStep7 = this._getSkillZero(skillsList, skillsPoints, "step7.skill"); + const skillsListStep17 = this._getSkillZero(skillsList, skillsPoints, "step17.skill"); return { ...super.getData(options), ringsList: game.l5r5e.HelpersL5r5e.getRingsList(), - skillsList: game.l5r5e.HelpersL5r5e.getSkillsList(true), + skillsList, + skillsListStep7, + skillsListStep17, noHonorSkillsList: ["commerce", "skulduggery", "medicine", "seafaring", "survival", "labor"], techniquesList: CONFIG.l5r5e.techniques, data: this.object.data, @@ -428,4 +434,19 @@ export class TwentyQuestionsDialog extends FormApplication { cache = cache.filter((e) => !!e && e.id !== itemId); setProperty(this.cache, stepName, cache); } + + /** + * Return the list of skill with only zero point (or 1 in this step) + * @private + */ + _getSkillZero(skillsList, skillsPoints, stepName) { + const stepSkillId = getProperty(this.object.data, stepName); + const out = {}; + Object.entries(skillsList).forEach(([cat, val]) => { + out[cat] = val.filter( + (skill) => stepSkillId === skill.id || !skillsPoints[skill.id] || skillsPoints[skill.id] < 1 + ); + }); + return out; + } } diff --git a/system/scripts/actors/twenty-questions.js b/system/scripts/actors/twenty-questions.js index ca46927..cb9be25 100644 --- a/system/scripts/actors/twenty-questions.js +++ b/system/scripts/actors/twenty-questions.js @@ -320,7 +320,7 @@ export class TwentyQuestions { }; // Rings & Skills, 3pt max for each - const rings = this._summariesRingsOrSkills("ringList"); + const rings = this.summariesRingsOrSkills("ringList"); for (const key in rings) { // ring start at 1 rings[key] = rings[key] + 1; @@ -331,13 +331,13 @@ export class TwentyQuestions { out.summary.rings.push(label); } - const skills = this._summariesRingsOrSkills("skillList"); + const skills = this.summariesRingsOrSkills("skillList"); for (const key in skills) { // skill start at 0 const label = `${game.i18n.localize("l5r5e.skills." + CONFIG.l5r5e.skills.get(key) + "." + key)} (${ skills[key] })`; - if (rings[key] > 3) { + if (skills[key] > 3) { out.errors.push(label); } out.summary.skills.push(label); @@ -368,7 +368,7 @@ export class TwentyQuestions { /** * Return a list of ring/skill */ - _summariesRingsOrSkills(listName) { + summariesRingsOrSkills(listName) { const store = {}; TwentyQuestions[listName].forEach((formName) => { const id = getProperty(this.data, formName); diff --git a/system/templates/actors/twenty-questions-dialog.html b/system/templates/actors/twenty-questions-dialog.html index 86da80e..9de15cb 100644 --- a/system/templates/actors/twenty-questions-dialog.html +++ b/system/templates/actors/twenty-questions-dialog.html @@ -276,7 +276,7 @@ {{#select data.step17.skill}} - {{#each skillsList as |skills catId|}} + {{#each skillsListStep17 as |skills catId|}} {{#each skills as |obj|}}