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 ***
html.find(".skill-name").on("click", (ev) => {
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 ***

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,6 @@
<li class="skill skill-wrapper" data-skill="{{skillId}}">
<label class="skill-content">
<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>
<!-- Roll button -->
</li>

View File

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

View File

@@ -19,7 +19,11 @@
</span>
<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 class="chat-profil-element">

View File

@@ -30,7 +30,11 @@
</div>
<label class="attribute-value checkbox">
<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>
</div>