fix npc dice roll, and with category id instead of skill id

This commit is contained in:
Vlyan
2020-12-18 23:25:00 +01:00
parent b152018607
commit d3bcfba723
8 changed files with 47 additions and 21 deletions

View File

@@ -41,7 +41,11 @@ export class BaseSheetL5r5e extends ActorSheet {
// *** Skills *** // *** Skills ***
html.find(".skill-name").on("click", (ev) => { html.find(".skill-name").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".skill"); const li = $(ev.currentTarget).parents(".skill");
new game.l5r5e.DicePickerDialog({ skillId: li.data("skill"), actor: this.actor }).render(true); new game.l5r5e.DicePickerDialog({
skillId: li.data("skill"),
skillCatId: li.data("skillcat"),
actor: this.actor,
}).render(true);
}); });
// *** Everything below here is only needed if the sheet is editable *** // *** Everything below here is only needed if the sheet is editable ***

View File

@@ -67,7 +67,7 @@ export class DicePickerDialog extends FormApplication {
* difficulty number (0-9) * difficulty number (0-9)
* difficultyHidden boolean * difficultyHidden boolean
* *
* @param options actor, actorId, ringId, skillId, difficulty, difficultyHidden * @param options actor, actorId, ringId, skillId, skillCatId, difficulty, difficultyHidden
*/ */
constructor(options = null) { constructor(options = null) {
super(options); super(options);
@@ -89,13 +89,16 @@ export class DicePickerDialog extends FormApplication {
this.ringId = options.ringId; this.ringId = options.ringId;
} }
// TODO SkillCategory ? // Skill / SkillCategory
// Skill
if (options?.skillId) { if (options?.skillId) {
this.skillId = options.skillId; this.skillId = options.skillId;
} }
// SkillCategory skillCatId
if (options?.skillCatId) {
this.skillCatId = options.skillCatId;
}
// Difficulty // Difficulty
if (options?.difficulty) { if (options?.difficulty) {
this.difficulty = options.difficulty; this.difficulty = options.difficulty;
@@ -139,24 +142,36 @@ export class DicePickerDialog extends FormApplication {
name: "", name: "",
}; };
const cat = L5R5E.skills.get(skillId); this.skillCatId = L5R5E.skills.get(skillId);
if (!cat) { }
/**
* Set and load skill's required data from actor and skillCatId
* @param skillId
*/
set skillCatId(skillCatId) {
if (!skillCatId) {
return; return;
} }
this._skillData.cat = cat;
this._skillData.name = game.i18n.localize("l5r5e.skills." + cat + "." + this._skillData.id); this._skillData = {
...this._skillData,
value: 0,
cat: skillCatId.toLowerCase().trim(),
name: game.i18n.localize("l5r5e.skills." + skillCatId + "." + (this._skillData.id || "title")),
};
if (!this._actor) { if (!this._actor) {
return; return;
} }
switch (this._actor.data.type) { switch (this._actor.data.type) {
case "character": case "character":
this._skillData.value = this._actor.data.data.skills[cat]?.[this._skillData.id]?.value || 0; this._skillData.value = this._actor.data.data.skills[skillCatId]?.[this._skillData.id] || 0;
break; break;
case "npc": case "npc":
// Skill value is in categories for npc // Skill value is in categories for npc
this._skillData.value = this._actor.data.data.skills[cat] || 0; this._skillData.value = this._actor.data.data.skills[skillCatId] || 0;
break; break;
} }
} }
@@ -367,6 +382,7 @@ export class DicePickerDialog extends FormApplication {
roll.actor = this._actor; roll.actor = this._actor;
roll.l5r5e.stance = approach; roll.l5r5e.stance = approach;
roll.l5r5e.skillId = this._skillData.id; roll.l5r5e.skillId = this._skillData.id;
roll.l5r5e.skillCatId = this._skillData.cat;
roll.l5r5e.summary.difficulty = this._difficulty.difficulty; roll.l5r5e.summary.difficulty = this._difficulty.difficulty;
roll.l5r5e.summary.difficultyHidden = this._difficulty.isHidden; roll.l5r5e.summary.difficultyHidden = this._difficulty.isHidden;

View File

@@ -14,6 +14,7 @@ export class RollL5r5e extends Roll {
this.l5r5e = { this.l5r5e = {
stance: "", stance: "",
skillId: "", skillId: "",
skillCatId: "",
actor: null, actor: null,
dicesTypes: { dicesTypes: {
std: false, std: false,
@@ -197,9 +198,6 @@ export class RollL5r5e extends Roll {
this.roll(); this.roll();
} }
const skillName =
game.i18n.translations.l5r5e.skills?.[L5R5E.skills.get(this.l5r5e.skillId)]?.[this.l5r5e.skillId] || "";
// Define chat data // Define chat data
const chatData = { const chatData = {
formula: isPrivate ? "???" : this._formula, formula: isPrivate ? "???" : this._formula,

View File

@@ -168,6 +168,7 @@
"templates": ["item"], "templates": ["item"],
"category": "", "category": "",
"skill": "melee", "skill": "melee",
"readied": false,
"range": 0, "range": 0,
"damage": 0, "damage": 0,
"deadliness": 0, "deadliness": 0,

View File

@@ -1,7 +1,6 @@
<li class="skill skill-wrapper" data-skill="{{skillId}}"> <li class="skill skill-wrapper" data-skill="{{skillId}}">
<label class="skill-content"> <label class="skill-content">
<span class="skill-name attribute-label rollable">{{ localizeSkill categoryId skillId }}</span> <span class="skill-name attribute-label rollable">{{ localizeSkill categoryId skillId }}</span>
<input type="text" name="data.skills.{{categoryId}}.{{skillId}}.value" value="{{skill.value}}" data-dtype="Number" placeholder="0"/> <input type="text" name="data.skills.{{categoryId}}.{{skillId}}" value="{{skill}}" data-dtype="Number" placeholder="0"/>
</label> </label>
<!-- Roll button -->
</li> </li>

View File

@@ -1,10 +1,10 @@
<ul class="npc-skill">{{!-- Skills --}} <ul class="npc-skill">{{!-- Skills --}}
{{#each data.skills as |skillValue skillCatId|}} {{#each data.skills as |skillValue skillCatId|}}
<li> <li class="skill skill-wrapper" data-skillcat="{{skillCatId}}">
<label> <label for="skill_{{skillCatId}}" class="skill-name">
{{localizeSkill skillCatId "title"}} {{localizeSkill skillCatId "title"}}
<input type="text" name="data.skills.{{skillCatId}}" value="{{skillValue}}" data-dtype="Number" placeholder="0"/>
</label> </label>
<input id="skill_{{skillCatId}}" type="text" name="data.skills.{{skillCatId}}" value="{{skillValue}}" data-dtype="Number" placeholder="0"/>
</li> </li>
{{/each}} {{/each}}
</ul> </ul>

View File

@@ -19,7 +19,11 @@
</span> </span>
<span class="chat-profil-element-skill"> <span class="chat-profil-element-skill">
{{#if l5r5e.skillId}}{{localizeSkillId l5r5e.skillId}}{{/if}} {{#if l5r5e.skillId}}
{{localizeSkillId l5r5e.skillId}}
{{else}}
{{#if l5r5e.skillCatId}}{{localizeSkill l5r5e.skillCatId 'title'}}{{/if}}
{{/if}}
</span> </span>
<span class="chat-profil-element"> <span class="chat-profil-element">

View File

@@ -30,7 +30,11 @@
</div> </div>
<label class="attribute-value checkbox"> <label class="attribute-value checkbox">
<input type="checkbox" name="data.equipped" {{checked item.data.equipped}} /> <input type="checkbox" name="data.equipped" {{checked item.data.equipped}} />
equipped equipped / sheathed (rengainée)
</label>
<label class="attribute-value checkbox">
<input type="checkbox" name="data.readied" {{checked item.data.readied}} />
readied (apprêté)
</label> </label>
</div> </div>