Skip to content

Commit

Permalink
Merge pull request #71 from crash1115/dev
Browse files Browse the repository at this point in the history
v0.6.6 - partially restore better rolls compatibility
  • Loading branch information
crash1115 authored Sep 24, 2021
2 parents 071d8ac + dfc1a6e commit f9acd49
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 0.6.6
- Restores compatibility with Better Rolls. Shift/Ctrl for adv/disadvantage do not work at present, but I wanted to get at least basic functionality restored because people were losing data.

# Version 0.6.5
- Updated Korean translations

Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"url": "https://github.com/crash1115/5e-training",
"readme": "https://github.com/crash1115/5e-training/blob/master/README.md",
"bugs": "https://github.com/crash1115/5e-training/issues",
"version": "0.6.5",
"version": "0.6.6",
"minimumCoreVersion": "0.8.2",
"compatibleCoreVersion": "0.8.9",
"minimumSystemVersion": "1.3.0",
Expand Down Expand Up @@ -42,5 +42,5 @@
}
],
"manifest": "https://raw.githubusercontent.com/crash1115/5e-training/master/module.json",
"download": "https://github.com/crash1115/5e-training/releases/download/v0.6.5/5e-training.zip"
"download": "https://github.com/crash1115/5e-training/releases/download/v0.6.6/5e-training.zip"
}
53 changes: 34 additions & 19 deletions scripts/CrashTrackingAndTraining.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ export default class CrashTrackingAndTraining {
r = await actor.rollAbilityTest(thisItem.ability);
}
if(r){
let rollMode = CrashTrackingAndTraining.getrollmodeString(r.options.advantageMode);
let attemptName = game.i18n.localize("C5ETRAINING.Roll") + " " + abilityName + " (" + rollMode + ")";
let attemptName = game.i18n.localize("C5ETRAINING.Roll") + " " + abilityName;
// Increase progress
thisItem = CrashTrackingAndTraining.calculateNewProgress(thisItem, attemptName, r._total);
let progressChange = CrashTrackingAndTraining.getRollResult(r);
thisItem = CrashTrackingAndTraining.calculateNewProgress(thisItem, attemptName, progressChange);
// Log item completion
CrashTrackingAndTraining.checkCompletion(actor, thisItem, alreadyCompleted);
// Update flags and actor
Expand All @@ -205,10 +205,10 @@ export default class CrashTrackingAndTraining {
r = await actor.rollSkill(thisItem.skill);
}
if(r){
let rollMode = CrashTrackingAndTraining.getrollmodeString(r.options.advantageMode);
let attemptName = game.i18n.localize("C5ETRAINING.Roll") + " " + abilityName + " (" + rollMode + ")";
let attemptName = game.i18n.localize("C5ETRAINING.Roll") + " " + abilityName;
// Increase progress
thisItem = CrashTrackingAndTraining.calculateNewProgress(thisItem, attemptName, r._total);
let progressChange = CrashTrackingAndTraining.getRollResult(r);
thisItem = CrashTrackingAndTraining.calculateNewProgress(thisItem, attemptName, progressChange);
// Log item completion
CrashTrackingAndTraining.checkCompletion(actor, thisItem, alreadyCompleted);
// Update flags and actor
Expand All @@ -230,10 +230,10 @@ export default class CrashTrackingAndTraining {
r = await tool.rollToolCheck();
}
if(r){
let rollMode = CrashTrackingAndTraining.getrollmodeString(r.options.advantageMode);
let attemptName = game.i18n.localize("C5ETRAINING.Roll") + " " + toolName + " (" + rollMode + ")";
let attemptName = game.i18n.localize("C5ETRAINING.Roll") + " " + toolName;
// Increase progress
thisItem = CrashTrackingAndTraining.calculateNewProgress(thisItem, attemptName, r._total);
let progressChange = CrashTrackingAndTraining.getToolRollResult(r);
thisItem = CrashTrackingAndTraining.calculateNewProgress(thisItem, attemptName, progressChange);
// Log item completion
CrashTrackingAndTraining.checkCompletion(actor, thisItem, alreadyCompleted);
// Update flags and actor
Expand Down Expand Up @@ -315,6 +315,31 @@ export default class CrashTrackingAndTraining {
return item;
}

// Gets the result of the roll. Necessary for compatibility with BR, which returns CustomItemRoll objects.
static getRollResult(roll){
let result;
if(game.modules.get("betterrolls5e")?.active){
// result = roll.entries.filter(entry => entry.type=="multiroll")[0].entries.map(x => x.total);
result = roll.entries.filter(entry => entry.type=="multiroll")[0].entries[0].total;
} else {
result = roll._total;
}
return parseInt(result);
}

// Gets the result of the roll. Necessary for compatibility with BR, which returns CustomItemRoll objects.
// This is slightly different for tools because of how the object gets attached to the roll.
static getToolRollResult(roll){
let result;
if(game.modules.get("betterrolls5e")?.active){
// result = roll.BetterRoll.entries.filter(entry => entry.type=="multiroll")[0].entries.map(x => x.total);
result = roll.BetterRoll.entries.filter(entry => entry.type=="multiroll")[0].entries[0].total;
} else {
result = roll._total;
}
return parseInt(result);
}

// Checks for completion of an item and alerts if it's done
static async checkCompletion(actor, item, alreadyCompleted){
if(alreadyCompleted){ return; }
Expand Down Expand Up @@ -381,16 +406,6 @@ export default class CrashTrackingAndTraining {
return rollType;
}

// Takes in the die roll string and returns whether it was made at adv/disadv/normal
static getrollmodeString(type){
let lookup = {
"-1": game.i18n.localize("C5ETRAINING.Disadvantage"),
"0": game.i18n.localize("C5ETRAINING.Normal"),
"1": game.i18n.localize("C5ETRAINING.Advantage")
}
return lookup[type] || "???";
}

// Gets and formats an array of tools the actor has in their inventory. Used for selection menus
static getActorTools(actorId){
let actor = game.actors.get(actorId);
Expand Down

0 comments on commit f9acd49

Please sign in to comment.