20Q added step 7 and 17 no point rule

Fix for skill errors
This commit is contained in:
Vlyan
2021-01-11 22:33:04 +01:00
parent a02337205c
commit 991c65b105
3 changed files with 28 additions and 7 deletions

View File

@@ -131,10 +131,16 @@ export class TwentyQuestionsDialog extends FormApplication {
* @return {Object} * @return {Object}
*/ */
async getData(options = null) { 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 { return {
...super.getData(options), ...super.getData(options),
ringsList: game.l5r5e.HelpersL5r5e.getRingsList(), ringsList: game.l5r5e.HelpersL5r5e.getRingsList(),
skillsList: game.l5r5e.HelpersL5r5e.getSkillsList(true), skillsList,
skillsListStep7,
skillsListStep17,
noHonorSkillsList: ["commerce", "skulduggery", "medicine", "seafaring", "survival", "labor"], noHonorSkillsList: ["commerce", "skulduggery", "medicine", "seafaring", "survival", "labor"],
techniquesList: CONFIG.l5r5e.techniques, techniquesList: CONFIG.l5r5e.techniques,
data: this.object.data, data: this.object.data,
@@ -428,4 +434,19 @@ export class TwentyQuestionsDialog extends FormApplication {
cache = cache.filter((e) => !!e && e.id !== itemId); cache = cache.filter((e) => !!e && e.id !== itemId);
setProperty(this.cache, stepName, cache); 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;
}
} }

View File

@@ -320,7 +320,7 @@ export class TwentyQuestions {
}; };
// Rings & Skills, 3pt max for each // Rings & Skills, 3pt max for each
const rings = this._summariesRingsOrSkills("ringList"); const rings = this.summariesRingsOrSkills("ringList");
for (const key in rings) { for (const key in rings) {
// ring start at 1 // ring start at 1
rings[key] = rings[key] + 1; rings[key] = rings[key] + 1;
@@ -331,13 +331,13 @@ export class TwentyQuestions {
out.summary.rings.push(label); out.summary.rings.push(label);
} }
const skills = this._summariesRingsOrSkills("skillList"); const skills = this.summariesRingsOrSkills("skillList");
for (const key in skills) { for (const key in skills) {
// skill start at 0 // skill start at 0
const label = `${game.i18n.localize("l5r5e.skills." + CONFIG.l5r5e.skills.get(key) + "." + key)} (${ const label = `${game.i18n.localize("l5r5e.skills." + CONFIG.l5r5e.skills.get(key) + "." + key)} (${
skills[key] skills[key]
})`; })`;
if (rings[key] > 3) { if (skills[key] > 3) {
out.errors.push(label); out.errors.push(label);
} }
out.summary.skills.push(label); out.summary.skills.push(label);
@@ -368,7 +368,7 @@ export class TwentyQuestions {
/** /**
* Return a list of ring/skill * Return a list of ring/skill
*/ */
_summariesRingsOrSkills(listName) { summariesRingsOrSkills(listName) {
const store = {}; const store = {};
TwentyQuestions[listName].forEach((formName) => { TwentyQuestions[listName].forEach((formName) => {
const id = getProperty(this.data, formName); const id = getProperty(this.data, formName);

View File

@@ -276,7 +276,7 @@
<select name="step7.skill" class="skill-select"> <select name="step7.skill" class="skill-select">
{{#select data.step7.skill}} {{#select data.step7.skill}}
<option value="none">{{localize 'l5r5e.twenty_questions.choose_one_skill'}}</option> <option value="none">{{localize 'l5r5e.twenty_questions.choose_one_skill'}}</option>
{{#each skillsList as |skills catId|}} {{#each skillsListStep7 as |skills catId|}}
<optgroup label="{{localizeSkill catId 'title'}}"> <optgroup label="{{localizeSkill catId 'title'}}">
{{#each skills as |obj|}} {{#each skills as |obj|}}
<option value="{{obj.id}}">{{obj.label}}</option> <option value="{{obj.id}}">{{obj.label}}</option>
@@ -413,7 +413,7 @@
<select name="step17.skill" class="skill-select"> <select name="step17.skill" class="skill-select">
{{#select data.step17.skill}} {{#select data.step17.skill}}
<option value="none">{{localize 'l5r5e.twenty_questions.choose_one_skill'}}</option> <option value="none">{{localize 'l5r5e.twenty_questions.choose_one_skill'}}</option>
{{#each skillsList as |skills catId|}} {{#each skillsListStep17 as |skills catId|}}
<optgroup label="{{localizeSkill catId 'title'}}"> <optgroup label="{{localizeSkill catId 'title'}}">
{{#each skills as |obj|}} {{#each skills as |obj|}}
<option value="{{obj.id}}">{{obj.label}}</option> <option value="{{obj.id}}">{{obj.label}}</option>