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) {
|
|
|
|
const actor = combatant.actor;
|
|
|
|
if ( !actor ) return "1d20";
|
|
|
|
const init = actor.data.data.attributes.init;
|
|
|
|
const parts = ["1d20", init.mod, (init.prof !== 0) ? init.prof : null, (init.bonus !== 0) ? init.bonus : null];
|
|
|
|
if ( actor.getFlag("sw5e", "initiativeAdv") ) parts[0] = "2d20kh";
|
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(" + ");
|
|
|
|
};
|
2020-09-11 17:11:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: A temporary shim until 0.7.x becomes stable
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
TokenConfig.getTrackedAttributes = function(data, _path=[]) {
|
|
|
|
|
|
|
|
// Track the path and record found attributes
|
|
|
|
const attributes = {
|
|
|
|
"bar": [],
|
|
|
|
"value": []
|
|
|
|
};
|
|
|
|
|
|
|
|
// Recursively explore the object
|
|
|
|
for ( let [k, v] of Object.entries(data) ) {
|
|
|
|
let p = _path.concat([k]);
|
|
|
|
|
|
|
|
// Check objects for both a "value" and a "max"
|
|
|
|
if ( v instanceof Object ) {
|
|
|
|
const isBar = ("value" in v) && ("max" in v);
|
|
|
|
if ( isBar ) attributes.bar.push(p);
|
|
|
|
else {
|
|
|
|
const inner = this.getTrackedAttributes(data[k], p);
|
|
|
|
attributes.bar.push(...inner.bar);
|
|
|
|
attributes.value.push(...inner.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise identify values which are numeric or null
|
|
|
|
else if ( Number.isNumeric(v) || (v === null) ) {
|
|
|
|
attributes.value.push(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return attributes;
|
|
|
|
};
|