forked from GitHub-Mirrors/foundry-sw5e
Added new handling for resources/rolling
This commit is contained in:
parent
a2dc561593
commit
f070d2725c
4 changed files with 494 additions and 325 deletions
|
@ -92,8 +92,14 @@ export default class Actor5e extends Actor {
|
|||
init.total = init.mod + init.prof + init.bonus;
|
||||
|
||||
// Prepare power-casting data
|
||||
this._computePowercastingDC(this.data);
|
||||
data.attributes.powerdc = data.attributes.powercasting ? data.abilities[data.attributes.powercasting].dc : 10;
|
||||
this._computePowercastingProgression(this.data);
|
||||
|
||||
// Compute owned item attributes which depend on prepared Actor data
|
||||
this.items.forEach(item => {
|
||||
item.getSaveDC();
|
||||
item.getAttackToHit();
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@ -168,7 +174,10 @@ export default class Actor5e extends Actor {
|
|||
}
|
||||
|
||||
// Load item data for all identified features
|
||||
const features = await Promise.all(ids.map(id => fromUuid(id)));
|
||||
const features = [];
|
||||
for ( let id of ids ) {
|
||||
features.push(await fromUuid(id));
|
||||
}
|
||||
|
||||
// Class powers should always be prepared
|
||||
for ( const feature of features ) {
|
||||
|
@ -312,19 +321,22 @@ export default class Actor5e extends Actor {
|
|||
const joat = flags.jackOfAllTrades;
|
||||
const observant = flags.observantFeat;
|
||||
const skillBonus = Number.isNumeric(bonuses.skill) ? parseInt(bonuses.skill) : 0;
|
||||
let round = Math.floor;
|
||||
for (let [id, skl] of Object.entries(data.skills)) {
|
||||
skl.value = parseFloat(skl.value || 0);
|
||||
skl.value = Math.clamped(Number(skl.value).toNearest(0.5), 0, 2) ?? 0;
|
||||
let round = Math.floor;
|
||||
|
||||
// Apply Remarkable Athlete or Jack of all Trades
|
||||
let multi = skl.value;
|
||||
if ( athlete && (skl.value === 0) && feats.remarkableAthlete.abilities.includes(skl.ability) ) {
|
||||
multi = 0.5;
|
||||
// Remarkable
|
||||
if ( athlete && (skl.value < 0.5) && feats.remarkableAthlete.abilities.includes(skl.ability) ) {
|
||||
skl.value = 0.5;
|
||||
round = Math.ceil;
|
||||
}
|
||||
if ( joat && (skl.value === 0 ) ) multi = 0.5;
|
||||
|
||||
// Retain the maximum skill proficiency when skill proficiencies are merged
|
||||
// Jack of All Trades
|
||||
if ( joat && (skl.value < 0.5) ) {
|
||||
skl.value = 0.5;
|
||||
}
|
||||
|
||||
// Polymorph Skill Proficiencies
|
||||
if ( originalSkills ) {
|
||||
skl.value = Math.max(skl.value, originalSkills[id].value);
|
||||
}
|
||||
|
@ -332,7 +344,7 @@ export default class Actor5e extends Actor {
|
|||
// Compute modifier
|
||||
skl.bonus = checkBonus + skillBonus;
|
||||
skl.mod = data.abilities[skl.ability].mod;
|
||||
skl.prof = round(multi * data.attributes.prof);
|
||||
skl.prof = round(skl.value * data.attributes.prof);
|
||||
skl.total = skl.mod + skl.prof + skl.bonus;
|
||||
|
||||
// Compute passive bonus
|
||||
|
@ -343,23 +355,6 @@ export default class Actor5e extends Actor {
|
|||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Compute the powercasting DC for all item abilities which use power DC scaling
|
||||
* @param {object} actorData The actor data being prepared
|
||||
* @private
|
||||
*/
|
||||
_computePowercastingDC(actorData) {
|
||||
|
||||
// Compute the powercasting DC
|
||||
const data = actorData.data;
|
||||
data.attributes.powerdc = data.attributes.powercasting ? data.abilities[data.attributes.powercasting].dc : 10;
|
||||
|
||||
// Compute ability save DCs that depend on the calling actor
|
||||
this.items.forEach(i => i.getSaveDC());
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Prepare data related to the power-casting capabilities of the Actor
|
||||
* @private
|
||||
|
@ -408,7 +403,7 @@ export default class Actor5e extends Actor {
|
|||
progression.slot = Math.ceil(caster.data.levels / denom);
|
||||
}
|
||||
|
||||
// EXCEPTION: NPC with an explicit powercaster level
|
||||
// EXCEPTION: NPC with an explicit power-caster level
|
||||
if (isNPC && actorData.data.details.powerLevel) {
|
||||
progression.slot = actorData.data.details.powerLevel;
|
||||
}
|
||||
|
@ -419,9 +414,9 @@ export default class Actor5e extends Actor {
|
|||
for ( let [n, lvl] of Object.entries(powers) ) {
|
||||
let i = parseInt(n.slice(-1));
|
||||
if ( Number.isNaN(i) ) continue;
|
||||
if ( Number.isNumeric(lvl.override) ) lvl.max = Math.max(parseInt(lvl.override), 1);
|
||||
if ( Number.isNumeric(lvl.override) ) lvl.max = Math.max(parseInt(lvl.override), 0);
|
||||
else lvl.max = slots[i-1] || 0;
|
||||
lvl.value = Math.min(parseInt(lvl.value), lvl.max);
|
||||
lvl.value = parseInt(lvl.value);
|
||||
}
|
||||
|
||||
// Determine the Actor's pact magic level (if any)
|
||||
|
@ -1108,8 +1103,7 @@ export default class Actor5e extends Actor {
|
|||
|
||||
// Recover power slots
|
||||
for ( let [k, v] of Object.entries(data.powers) ) {
|
||||
if ( !v.max && !v.override ) continue;
|
||||
updateData[`data.powers.${k}.value`] = v.override || v.max;
|
||||
updateData[`data.powers.${k}.value`] = !Number.isNaN(v.override) ? v.override : (v.max ?? 0);
|
||||
}
|
||||
|
||||
// Recover pact slots.
|
||||
|
@ -1186,7 +1180,6 @@ export default class Actor5e extends Actor {
|
|||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
* Transform this Actor into another one.
|
||||
*
|
||||
|
@ -1216,10 +1209,10 @@ export default class Actor5e extends Actor {
|
|||
}
|
||||
|
||||
// Get the original Actor data and the new source data
|
||||
const o = duplicate(this.data);
|
||||
const o = this.toJSON();
|
||||
o.flags.sw5e = o.flags.sw5e || {};
|
||||
o.flags.sw5e.transformOptions = {mergeSkills, mergeSaves};
|
||||
const source = duplicate(target.data);
|
||||
const source = target.toJSON();
|
||||
|
||||
// Prepare new data to merge from the source
|
||||
const d = {
|
||||
|
@ -1227,6 +1220,7 @@ export default class Actor5e extends Actor {
|
|||
name: `${o.name} (${source.name})`, // Append the new shape to your old name
|
||||
data: source.data, // Get the data model of your new form
|
||||
items: source.items, // Get the items of your new form
|
||||
effects: o.effects.concat(source.effects), // Combine active effects from both forms
|
||||
token: source.token, // New token configuration
|
||||
img: source.img, // New appearance
|
||||
permission: o.permission, // Use the original actor permissions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue