foundry-sw5e/module/combat.js

28 lines
999 B
JavaScript
Raw Permalink Normal View History

2020-06-24 14:23:55 -04:00
/**
2020-09-01 12:13:00 -04:00
* Override the default Initiative formula to customize special behaviors of the SW5e system.
2020-06-24 14:23:55 -04:00
* Apply advantage, proficiency, or bonuses where appropriate
* Apply the dexterity score as a decimal tiebreaker if requested
* See Combat._getInitiativeFormula for more detail.
*/
export const _getInitiativeFormula = function (combatant) {
2020-06-24 14:23:55 -04:00
const actor = combatant.actor;
if (!actor) return "1d20";
2020-06-24 14:23:55 -04:00
const init = actor.data.data.attributes.init;
let nd = 1;
let mods = "";
2021-01-19 21:47:38 -05:00
if (actor.getFlag("sw5e", "halflingLucky")) mods += "r1=1";
if (actor.getFlag("sw5e", "initiativeAdv")) {
nd = 2;
mods += "kh";
}
const parts = [`${nd}d20${mods}`, init.mod, init.prof !== 0 ? init.prof : null, init.bonus !== 0 ? init.bonus : null];
2020-09-11 17:11:11 -04:00
// Optionally apply Dexterity tiebreaker
const tiebreaker = game.settings.get("sw5e", "initiativeDexTiebreaker");
if (tiebreaker) parts.push(actor.data.data.abilities.dex.value / 100);
2020-06-24 14:23:55 -04:00
return parts.filter(p => p !== null).join(" + ");
};