`;
@@ -303,8 +307,7 @@ export class DeltaGreenActorSheet extends ActorSheet {
apply:{
label: game.i18n.translations.DG?.Skills?.Apply ?? "Apply",
callback: btn =>{
- const baseRollForumla = btn.find("[name='roll-formula']").val();
- this._applySkillImprovements(baseRollForumla, failures);
+ this._applySkillImprovements(baseRollFormula, failedSkills, failedTypedSkills);
},
}
}
@@ -686,21 +689,22 @@ export class DeltaGreenActorSheet extends ActorSheet {
}
}
- _applySkillImprovements(baseRollFormula, failures) {
+ _applySkillImprovements(baseRollFormula, failedSkills, failedTypedSkills) {
const actorData = this.actor.system;
const resultList = [];
let rollFormula;
+ // Define the amount of dice being rolled, if any.
switch (baseRollFormula) {
case "1":
rollFormula = 1;
break;
case "1d3":
- rollFormula = `${failures.length}d3`;
+ rollFormula = `${failedSkills.length + failedTypedSkills.length}d3`;
break;
case "1d4":
case "1d4-1":
- rollFormula = `${failures.length}d4`;
+ rollFormula = `${failedSkills.length + failedTypedSkills.length}d4`;
break;
default:
}
@@ -709,38 +713,64 @@ export class DeltaGreenActorSheet extends ActorSheet {
if (rollFormula !== 1) {
roll = new Roll(rollFormula, actorData);
roll.evaluate({async: true});
+ // Put the results into a list.
roll.terms[0].results.forEach((result) => resultList.push(baseRollFormula === "1d4-1" ? result.result - 1 : result.result));
}
- let updatedSkills = "";
+ // This will be end up being a list of skills and how much each were improved by. It gets modified in the following loops.
+ let improvedSkillList = "";
- failures.forEach(([skill], value) => {
+ failedSkills.forEach(([skill], value) => {
const updatedData = duplicate(actorData);
- updatedData.skills[skill].proficiency += resultList[value] ?? 1;
+ updatedData.skills[skill].proficiency += resultList[value] ?? 1; // Increase proficiency by die result or by 1 if there is no dice roll.
updatedData.skills[skill].failure = false;
this.actor.update({"system": updatedData});
- // So we can record the skills and how much they were increased by in chat.
- if (updatedSkills === "") {
- updatedSkills += `${game.i18n.localize("DG.Skills." + skill)}: +${resultList[value] ?? 1}%`;
+ // So we can record the regular skills improved and how much they were increased by in chat.
+ // The if statement tells us whether to add a comma before the term or not.
+ if (value === 0) {
+ improvedSkillList += `${game.i18n.localize("DG.Skills." + skill)}: +${resultList[value] ?? 1}%`;
} else {
- updatedSkills += `, ${game.i18n.localize("DG.Skills." + skill)}: +${resultList[value] ?? 1}%`;
+ improvedSkillList += `, ${game.i18n.localize("DG.Skills." + skill)}: +${resultList[value] ?? 1}%`;
}
})
+ failedTypedSkills.forEach(([skillName, skillData], value) => {
+ const updatedData = duplicate(actorData);
+ // We must increase value in the following line by the length of failedSkills, so that we index the entire resultList.
+ // Otherwise we would be adding the same die results to regular skills and typed skills.
+ updatedData.typedSkills[skillName].proficiency += resultList[value + failedSkills.length] ?? 1;
+ updatedData.typedSkills[skillName].failure = false;
+ this.actor.update({"system": updatedData});
+
+ // So we can record the typed skills improved and how much they were increased by in chat.
+ // The if statement tells us whether to add a comma before the term or not.
+ if (value === 0 && improvedSkillList === "") {
+ improvedSkillList += `${game.i18n.localize("DG.TypeSkills." + skillData.group.split(" ").join(""))} (${skillData.label}): +${resultList[value + failedSkills.length] ?? 1}%`;
+ } else {
+ improvedSkillList += `, ${game.i18n.localize("DG.TypeSkills." + skillData.group.split(" ").join(""))} (${skillData.label}): +${resultList[value + failedSkills.length] ?? 1}%`;
+ }
+ })
+
+ let html;
+ html = `
`
+ html += `
${improvedSkillList}
`
+ html += `
`
+
const chatData = {
- speaker: ChatMessage.getSpeaker({actor: this.actor, token: this.token, alias: this.actor.data.name}),
- content: updatedSkills,
- flavor: `${game.i18n.localize("DG.Skills.ApplySkillImprovementsChatFlavor")} +${baseRollFormula}%:`,
+ speaker: ChatMessage.getSpeaker({actor: this.actor, token: this.token, alias: this.actor.name}),
+ content: html,
+ flavor: `${game.i18n.localize("DG.Skills.ApplySkillImprovementsChatFlavor")} +${baseRollFormula}%:`,
type: baseRollFormula === "1" ? 0 : 5, // 0 = CHAT_MESSAGE_TYPES.OTHER, 5 = CHAT_MESSAGE_TYPES.ROLL
- roll: baseRollFormula === "1" ? null : roll, // If adding flat +1, there is no roll.
+ rolls: baseRollFormula === "1" ? [] : [roll], // If adding flat +1, there is no roll.
rollMode: game.settings.get("core", "rollMode")
};
-
- // play the dice rolling sound, like a regular in-chat roll
- if (roll) AudioHelper.play({src: "sounds/dice.wav", volume: 0.8, autoplay: true, loop: false}, true);
-
- ChatMessage.create(chatData, {});
+
+ // play the dice rolling sound, like a regular in-chat roll
+ if (roll) AudioHelper.play({src: "sounds/dice.wav", volume: 0.8, autoplay: true, loop: false}, true);
+
+ ChatMessage.create(chatData, {});
+
}
_onDragStart(event) {