From 002e97988a913c90f492ef41130c479c91c1ce71 Mon Sep 17 00:00:00 2001 From: U~man Date: Thu, 30 Jul 2020 15:40:22 +0200 Subject: [PATCH] ENH: Reset initiative option --- src/lang/en.json | 3 ++- src/lang/fr.json | 3 ++- src/module/combat.js | 10 +++++++++- src/module/settings.js | 1 + src/ose.js | 6 ++++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index 01580ea..431131a 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -162,7 +162,8 @@ "OSE.Setting.Initiative": "Initiative", "OSE.Setting.InitiativeHint": "Grouped or individual initiative. Unique individual is only rolled at the start of the combat", "OSE.Setting.InitiativeOnce": "Unique individual Initiative", - "OSE.Setting.InitiativeReroll": "Individual Initiative per Round", + "OSE.Setting.InitiativeReroll": "Roll individual Initiative each Round", + "OSE.Setting.InitiativeReset": "Reset individual Initiative each Round", "OSE.Setting.InitiativeGroup": "Grouped Initiative", "OSE.Setting.AscendingAC": "Ascending Armor Class", "OSE.Setting.AscendingACHint": "The more the better", diff --git a/src/lang/fr.json b/src/lang/fr.json index e4d20cd..96099b0 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -162,7 +162,8 @@ "OSE.Setting.Initiative": "Initiative", "OSE.Setting.InitiativeHint": "Initiative groupée ou individuelle. L'initiative unique est tirée une seule fois en début de combat.", "OSE.Setting.InitiativeOnce": "Initiative unique individuelle", - "OSE.Setting.InitiativeReroll": "Initiative individuelle", + "OSE.Setting.InitiativeReroll": "Initiative relancée chaque tour", + "OSE.Setting.InitiativeReset": "Initiative mise à zéro chaque tour", "OSE.Setting.InitiativeGroup": "Initiative groupée", "OSE.Setting.AscendingAC": "Classe d'Armure Ascendante", "OSE.Setting.AscendingACHint": "Le plus est le mieux", diff --git a/src/module/combat.js b/src/module/combat.js index 3cfa674..0860636 100644 --- a/src/module/combat.js +++ b/src/module/combat.js @@ -31,6 +31,14 @@ export class OseCombat { } } + static async resetInitiative(combat, data) { + let updates = []; + combat.data.combatants.forEach((c, i) => { + updates.push({_id: c._id, initiative: ""}); + }); + await combat.updateEmbeddedEntity("Combatant", updates); + } + static async individualInitiative(combat, data) { let updates = []; let messages = []; @@ -43,7 +51,7 @@ export class OseCombat { if (combat.settings.skipDefeated && c.defeated) { value = -790; } - updates.push({ _id: c._id, initiative: value }); + updates.push({ _id: c._id, initiative: "value" }); // Determine the roll mode let rollMode = game.settings.get("core", "rollMode"); diff --git a/src/module/settings.js b/src/module/settings.js index 90cc247..e331e60 100644 --- a/src/module/settings.js +++ b/src/module/settings.js @@ -10,6 +10,7 @@ export const registerSettings = function () { choices: { disabled: "OSE.Setting.InitiativeOnce", rerolled: "OSE.Setting.InitiativeReroll", + reset: "OSE.Setting.InitiativeReset", group: "OSE.Setting.InitiativeGroup", }, onChange: _ => window.location.reload() diff --git a/src/ose.js b/src/ose.js index c720d5d..7ab7e14 100644 --- a/src/ose.js +++ b/src/ose.js @@ -128,10 +128,12 @@ Hooks.on("preUpdateCombat", async (combat, data, diff, id) => { if (!data.round) { return; } - if (init == "group") { + if (init === "group") { OseCombat.rollInitiative(combat, data, diff, id); - } else if (init == "rerolled") { + } else if (init === "rerolled") { OseCombat.individualInitiative(combat, data, diff, id); + } else if (init === "reset") { + OseCombat.resetInitiative(combat, data, diff, id); } });