mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
* Updated the background image for the system * Fixed so Weapon/Armor features are added again * Fixed so fear is available as a resource to be deducted by actions (#757) * Changed to use the config labels and src * Updated Weapons * Fixed so the decrease button of simple fear tracker is not visible when not hovered * Fixed so armor preUpdate doesn't fail if no system changes are made * Updated .gitignore and author details (#777) * Add author details and name mapping for chrisryan10 (#773) * Add build to ignore for my linux dev (#775) --------- * Corrected sneak attack active effect (#780) * Fixed a spelling error (#779) * Fix bardic rally showing in damage dialog when it should not (#783) * update spelling (#786) * Translating inventory descriptions (#782) * updated credits for 1.0.1 release (#797) * updated credits for 1.0.1 release * further updated artwork credits * Chagned handlebarhelper rollparsed to be more defensive (#794) * Added missing scene refreshType (#790) * Remove ability use buttons for not owned abilities (#795) * [Fix] PrayerDice Fixed (#799) * Fixed prayer dice, and wheelchair images * Fixed -settings data sources * Dragging features from one adversary to another (#788) * [Fix] Levelup Fixes (#787) * Fixed crash on experience selection. Fixed subclass error on multiclassing * Fixed so multiclasses do not gain the hope feature for the class * Fixed so Class/Subclass features are properly deleted on delevel * Removed automatic deletion of features on delevel when not using levelup auto * Fixed so custom domains can be selected in levelup when multiclassing * Changed so encounter countdowns is a button (#804) * Fixed so that dropping on class/subclass...creates the item on the character (#803) * [BUG] - Importing All Adversaries/Environments (#814) Fixes #774 * Bug/671 reaction roll chat title (#809) * Update Reaction Roll Chat Message Title * Removed console log --------- * Improve Trait tooltip display (#817) Fixes #806 * [BUG] - Combat Tracker d12 logo not found (#812) Fixes #764 * Compendium Browser (#821) * Corrected timbending description localization (#816) * [Fix] Compendium Item (#810) * Corrected Emberwoven Armor * Fixed subclass regression * Fixed so character's with wildcard images don't break beastform (#815) * Fix roll result based duality damage (#822) * Impproved Adversary Sheet Data Display (#751) * Impproved Adversary Sheet Data Display Fixes #604 * FIX: formula lables for attacks and weapons --------- * Fixed so exp increases can be selected normally (#835) * Update localization of rollSelection.hbs (#841) The Fear label lacked a localization path * renamed .md files (#834) * Removed the unintended icons that came from merge conflicts (#838) * Sheet image position (#861) * Remove extra result text from reaction chat message (#860) * Remove extra result text from reaction chat message * Remove log * [Fix] 850 - Downtime Refreshes (#859) * Fixed the filtering of refreshable features * Raised version * [Fix] 691 - CharacterCreation Improvement (#863) * Removed main creation tab. Added equipment to remaining tab * Fixed MixedAncestry name setting * Fixed tab after first creation * Fix/857 generic roll buttons (#866) * Action Macro working again * Remove buttons from generic roll for non-gm * Update sidebar.less Armor Slots label padding, for translations (#872) Equalizes the vertical and horizontal padding on the Armor Slots status label, to allow for more (much needed) room for the upcoming French translation (and others in the future). Doesn't change anything for the display in English. * Hid item attachments for now (#876) * Fixed so effects supposed to use item data use the model directly, since items have no rolldata (#883) * Made sure the beastform user isn't moved onto other duplicate actors. Fixed scrolling text duplication (#882) * Change the critical damage max calculation (#890) * Change the critical damage max calculation to avoid setting the rolled portion to maximum all the time. * Change to the more neater code * Restored package.json --------- * Fix movement (#885) * Changed so companion can level up on its own (#879) * Fix the missing ancestries in the SRD (#888) * Removed the old, now unused companion levelup button (#893) * Fixed so custom downtime moves will display their descriptions in the tooltip (#894) * Made coinflip icons in chat round (#895) * Fixed undefined case (#898) * Fix/877 hope update order (#896) * Action Macro working again * k * Fix Hope gain on Duality Roll * [Feature] Descriptions enhancements (#887) * add style to hover items and add start setting to features be expanded by default * REFACTOR: now prepare description onRender and simply the other methods * add setting to extend description from items and add molilo contacts in system.json --------- * Fixed traits container styling in light-mode (#899) * [BUG] - Movement Button selector not showing current mode (#912) Fixes #910 * Fix/864 chat targeting (#911) * Fix targeting * Fix chat target selection * Uncomment chatDisplay * Removed unessecary arg * [Feature] 648 - Mark Defeated Actors (#914) * Improved death marking styling * Added automation for defeated status * Fixed so the tracker recognises and sets the correct defeated statuses depending on type * Fixed so missing statuses doesn't cause crashes * Increased companion sheet width by 40 pixels * Added missing inheritDoc * Removed fas * FIX: use img instead of icons con statusEffectConfigns (#917) Authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> --------- Co-authored-by: Chris Ryan <73275196+chrisryan10@users.noreply.github.com> Co-authored-by: Chris Ryan <chrisr@blackhole> Co-authored-by: Dapoulp <74197441+Dapoulp@users.noreply.github.com> Co-authored-by: IrkTheImp <41175833+IrkTheImp@users.noreply.github.com> Co-authored-by: CPTN_Cosmo <cptncosmo@gmail.com> Co-authored-by: Josh Q. <jshqntnr13@gmail.com> Co-authored-by: joaquinpereyra98 <24190917+joaquinpereyra98@users.noreply.github.com> Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> Co-authored-by: SunnySunSun <snysun@pm.me> Co-authored-by: Murilo Brito <91566541+moliloo@users.noreply.github.com>
333 lines
13 KiB
JavaScript
333 lines
13 KiB
JavaScript
import DamageDialog from '../applications/dialogs/damageDialog.mjs';
|
|
import DHRoll from './dhRoll.mjs';
|
|
|
|
export default class DamageRoll extends DHRoll {
|
|
constructor(formula, data = {}, options = {}) {
|
|
super(formula, data, options);
|
|
}
|
|
|
|
static DefaultDialog = DamageDialog;
|
|
|
|
static async buildEvaluate(roll, config = {}, message = {}) {
|
|
if (config.evaluate !== false) for (const roll of config.roll) await roll.roll.evaluate();
|
|
|
|
roll._evaluated = true;
|
|
const parts = config.roll.map(r => this.postEvaluate(r));
|
|
|
|
config.damage = this.unifyDamageRoll(parts);
|
|
}
|
|
|
|
static postEvaluate(roll, config = {}) {
|
|
return {
|
|
...roll,
|
|
...super.postEvaluate(roll.roll, config),
|
|
damageTypes: [...(roll.damageTypes ?? [])],
|
|
roll: roll.roll,
|
|
type: config.type,
|
|
modifierTotal: this.calculateTotalModifiers(roll.roll)
|
|
};
|
|
}
|
|
|
|
static async buildPost(roll, config, message) {
|
|
const chatMessage = config.source?.message
|
|
? ui.chat.collection.get(config.source.message)
|
|
: getDocumentClass('ChatMessage').applyRollMode({}, config.rollMode);
|
|
if (game.modules.get('dice-so-nice')?.active) {
|
|
const pool = foundry.dice.terms.PoolTerm.fromRolls(
|
|
Object.values(config.damage).flatMap(r => r.parts.map(p => p.roll))
|
|
),
|
|
diceRoll = Roll.fromTerms([pool]);
|
|
await game.dice3d.showForRoll(diceRoll, game.user, true, chatMessage.whisper, chatMessage.blind);
|
|
}
|
|
await super.buildPost(roll, config, message);
|
|
if (config.source?.message) {
|
|
chatMessage.update({ 'system.damage': config.damage });
|
|
}
|
|
}
|
|
|
|
static unifyDamageRoll(rolls) {
|
|
const unified = {};
|
|
rolls.forEach(r => {
|
|
const resource = unified[r.applyTo] ?? { formula: '', total: 0, parts: [] };
|
|
resource.formula += `${resource.formula !== '' ? ' + ' : ''}${r.formula}`;
|
|
resource.total += r.total;
|
|
resource.parts.push(r);
|
|
unified[r.applyTo] = resource;
|
|
});
|
|
return unified;
|
|
}
|
|
|
|
static formatGlobal(rolls) {
|
|
let formula, total;
|
|
const applyTo = new Set(rolls.flatMap(r => r.applyTo));
|
|
if (applyTo.size > 1) {
|
|
const data = {};
|
|
rolls.forEach(r => {
|
|
if (data[r.applyTo]) {
|
|
data[r.applyTo].formula += ` + ${r.formula}`;
|
|
data[r.applyTo].total += r.total;
|
|
} else {
|
|
data[r.applyTo] = {
|
|
formula: r.formula,
|
|
total: r.total
|
|
};
|
|
}
|
|
});
|
|
formula = Object.entries(data).reduce((a, [k, v]) => a + ` ${k}: ${v.formula}`, '');
|
|
total = Object.entries(data).reduce((a, [k, v]) => a + ` ${k}: ${v.total}`, '');
|
|
} else {
|
|
formula = rolls.map(r => r.formula).join(' + ');
|
|
total = rolls.reduce((a, c) => a + c.total, 0);
|
|
}
|
|
return { formula, total };
|
|
}
|
|
|
|
applyBaseBonus(part) {
|
|
const modifiers = [],
|
|
type = this.options.messageType ?? (this.options.hasHealing ? 'healing' : 'damage'),
|
|
options = part ?? this.options;
|
|
|
|
modifiers.push(...this.getBonus(`${type}`, `${type.capitalize()} Bonus`));
|
|
if (!this.options.hasHealing) {
|
|
options.damageTypes?.forEach(t => {
|
|
modifiers.push(...this.getBonus(`${type}.${t}`, `${t.capitalize()} ${type.capitalize()} Bonus`));
|
|
});
|
|
const weapons = ['primaryWeapon', 'secondaryWeapon'];
|
|
weapons.forEach(w => {
|
|
if (this.options.source.item && this.options.source.item === this.data[w]?.id)
|
|
modifiers.push(...this.getBonus(`${type}.${w}`, 'Weapon Bonus'));
|
|
});
|
|
}
|
|
|
|
return modifiers;
|
|
}
|
|
|
|
constructFormula(config) {
|
|
this.options.roll.forEach((part, index) => {
|
|
part.roll = new Roll(Roll.replaceFormulaData(part.formula, config.data));
|
|
this.constructFormulaPart(config, part, index);
|
|
});
|
|
return this.options.roll;
|
|
}
|
|
|
|
constructFormulaPart(config, part, index) {
|
|
part.roll.terms = Roll.parse(part.roll.formula, config.data);
|
|
|
|
if (part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
|
part.modifiers = this.applyBaseBonus(part);
|
|
this.addModifiers(part);
|
|
part.modifiers?.forEach(m => {
|
|
part.roll.terms.push(...this.formatModifier(m.value));
|
|
});
|
|
}
|
|
|
|
/* To Remove When Reaction System */
|
|
if (index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
|
for (const mod in config.modifiers) {
|
|
const modifier = config.modifiers[mod];
|
|
if (modifier.beforeCrit === true && (modifier.enabled || modifier.value)) modifier.callback(part);
|
|
}
|
|
}
|
|
|
|
if (part.extraFormula) {
|
|
part.roll.terms.push(
|
|
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
|
|
...this.constructor.parse(part.extraFormula, this.options.data)
|
|
);
|
|
}
|
|
|
|
if (config.isCritical && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
|
const total = part.roll.dice.reduce((acc, term) => acc + term._faces*term._number, 0);
|
|
if (total > 0) {
|
|
part.roll.terms.push(...this.formatModifier(total));
|
|
}
|
|
}
|
|
|
|
/* To Remove When Reaction System */
|
|
if (index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
|
for (const mod in config.modifiers) {
|
|
const modifier = config.modifiers[mod];
|
|
if (!modifier.beforeCrit && (modifier.enabled || modifier.value)) modifier.callback(part);
|
|
}
|
|
}
|
|
|
|
return (part.roll._formula = this.constructor.getFormula(part.roll.terms));
|
|
}
|
|
|
|
/* To Remove When Reaction System */
|
|
static temporaryModifierBuilder(config) {
|
|
const mods = {};
|
|
if (config.data?.parent) {
|
|
if (config.data.parent.appliedEffects) {
|
|
// Bardic Rally
|
|
const rallyChoices = config.data?.parent?.appliedEffects.reduce((a, c) => {
|
|
const change = c.changes.find(ch => ch.key === 'system.bonuses.rally');
|
|
if (change) a.push({ value: c.id, label: change.value });
|
|
return a;
|
|
}, [])
|
|
if(rallyChoices.length) {
|
|
mods.rally = {
|
|
label: 'DAGGERHEART.CLASS.Feature.rallyDice',
|
|
values: rallyChoices,
|
|
value: null,
|
|
beforeCrit: true,
|
|
callback: part => {
|
|
const rallyFaces = config.modifiers.rally.values.find(
|
|
r => r.value === config.modifiers.rally.value
|
|
)?.label;
|
|
part.roll.terms.push(
|
|
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
|
|
...this.parse(`1${rallyFaces}`)
|
|
);
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
const item = config.data.parent.items?.get(config.source.item);
|
|
if (item) {
|
|
// Massive (Weapon Feature)
|
|
if (item.system.itemFeatures.find(f => f.value === 'massive'))
|
|
mods.massive = {
|
|
label: CONFIG.DH.ITEM.weaponFeatures.massive.label,
|
|
enabled: true,
|
|
callback: part => {
|
|
part.roll.terms[0].modifiers.push(`kh${part.roll.terms[0].number}`);
|
|
part.roll.terms[0].number += 1;
|
|
}
|
|
};
|
|
|
|
// Powerful (Weapon Feature)
|
|
if (item.system.itemFeatures.find(f => f.value === 'powerful'))
|
|
mods.powerful = {
|
|
label: CONFIG.DH.ITEM.weaponFeatures.powerful.label,
|
|
enabled: true,
|
|
callback: part => {
|
|
part.roll.terms[0].modifiers.push(`kh${part.roll.terms[0].number}`);
|
|
part.roll.terms[0].number += 1;
|
|
}
|
|
};
|
|
|
|
// Brutal (Weapon Feature)
|
|
if (item.system.itemFeatures.find(f => f.value === 'brutal'))
|
|
mods.brutal = {
|
|
label: CONFIG.DH.ITEM.weaponFeatures.brutal.label,
|
|
enabled: true,
|
|
beforeCrit: true,
|
|
callback: part => {
|
|
part.roll.terms[0].modifiers.push(`x${part.roll.terms[0].faces}`);
|
|
}
|
|
};
|
|
|
|
// Serrated (Weapon Feature)
|
|
if (item.system.itemFeatures.find(f => f.value === 'serrated'))
|
|
mods.serrated = {
|
|
label: CONFIG.DH.ITEM.weaponFeatures.serrated.label,
|
|
enabled: true,
|
|
callback: part => {
|
|
part.roll.terms[0].modifiers.push(`sc8`);
|
|
}
|
|
};
|
|
|
|
// Self-Correcting (Weapon Feature)
|
|
if (item.system.itemFeatures.find(f => f.value === 'selfCorrecting'))
|
|
mods.selfCorrecting = {
|
|
label: CONFIG.DH.ITEM.weaponFeatures.selfCorrecting.label,
|
|
enabled: true,
|
|
callback: part => {
|
|
part.roll.terms[0].modifiers.push(`sc6`);
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
config.modifiers = mods;
|
|
return mods;
|
|
}
|
|
|
|
static async reroll(target, message) {
|
|
const { damageType, part, dice, result } = target.dataset;
|
|
const rollPart = message.system.damage[damageType].parts[part];
|
|
|
|
let diceIndex = 0;
|
|
let parsedRoll = game.system.api.dice.DamageRoll.fromData({
|
|
...rollPart.roll,
|
|
terms: rollPart.roll.terms.map(term => {
|
|
const isDie = term.class === 'Die';
|
|
const fixedTerm = {
|
|
...term,
|
|
...(isDie ? { results: rollPart.dice[diceIndex].results } : {})
|
|
};
|
|
|
|
if (isDie) diceIndex++;
|
|
return fixedTerm;
|
|
}),
|
|
class: 'DamageRoll',
|
|
evaluated: false
|
|
});
|
|
|
|
const parsedDiceTerms = Object.keys(parsedRoll.terms).reduce((acc, key) => {
|
|
const term = parsedRoll.terms[key];
|
|
if (term instanceof CONFIG.Dice.termTypes.DiceTerm) acc[Object.keys(acc).length] = term;
|
|
return acc;
|
|
}, {});
|
|
const term = parsedDiceTerms[dice];
|
|
const termResult = parsedDiceTerms[dice].results[result];
|
|
|
|
const newIndex = parsedDiceTerms[dice].results.length;
|
|
await term.reroll(`/r1=${termResult.result}`);
|
|
|
|
if (game.modules.get('dice-so-nice')?.active) {
|
|
const newResult = parsedDiceTerms[dice].results[newIndex];
|
|
const diceSoNiceRoll = {
|
|
_evaluated: true,
|
|
dice: [
|
|
new foundry.dice.terms.Die({
|
|
...term,
|
|
total: newResult.result,
|
|
faces: term._faces,
|
|
results: [newResult]
|
|
})
|
|
],
|
|
options: { appearance: {} }
|
|
};
|
|
|
|
await game.dice3d.showForRoll(diceSoNiceRoll, game.user, true);
|
|
}
|
|
|
|
await parsedRoll.evaluate();
|
|
|
|
const results = parsedRoll.dice[dice].results.map(result => ({
|
|
...result,
|
|
discarded: !result.active
|
|
}));
|
|
const newResult = results.splice(results.length - 1, 1);
|
|
results.splice(Number(result) + 1, 0, newResult[0]);
|
|
|
|
const rerolledDice = parsedRoll.dice.map((x, index) => {
|
|
const isRerollDice = index === Number(dice);
|
|
if (!isRerollDice) return { ...x, dice: x.denomination };
|
|
return {
|
|
dice: parsedRoll.dice[dice].denomination,
|
|
total: parsedRoll.dice[dice].total,
|
|
results: results.map(result => ({
|
|
...result,
|
|
hasRerolls: result.hasRerolls || isRerollDice
|
|
}))
|
|
};
|
|
});
|
|
|
|
const updateMessage = game.messages.get(message._id);
|
|
await updateMessage.update({
|
|
[`system.damage.${damageType}`]: {
|
|
...updateMessage,
|
|
total: parsedRoll.total,
|
|
[`parts.${part}`]: {
|
|
...rollPart,
|
|
total: parsedRoll.total,
|
|
dice: rerolledDice
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|