mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-21 18:09:54 +02:00
Initial
This commit is contained in:
parent
8d68166e4c
commit
863b5116f7
5 changed files with 26 additions and 19 deletions
|
|
@ -121,6 +121,9 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application
|
|||
}
|
||||
|
||||
static async submitRoll() {
|
||||
const { damageFormula, resourceFormulas } = this.roll.constructFormulas({ ...this.config, isCritical: false });
|
||||
this.config.damageFormula = damageFormula;
|
||||
this.config.resourceFormulas = resourceFormulas;
|
||||
await this.close({ submitted: true });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -184,8 +184,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
? undefined
|
||||
: (selectedRoll?.roll?.isCritical ?? false);
|
||||
|
||||
partContext.hintText = await this.getInfoTexts(this.party.system.tagTeam.members);
|
||||
partContext.joinedRoll = await this.getJoinedRoll({
|
||||
partContext.hintText = this.getInfoTexts(this.party.system.tagTeam.members);
|
||||
partContext.joinedRoll = this.getJoinedRoll({
|
||||
overrideIsCritical: critSelected,
|
||||
displayVersion: true
|
||||
});
|
||||
|
|
@ -194,7 +194,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
}
|
||||
|
||||
if (Object.keys(this.party.system.tagTeam.members).includes(partId)) {
|
||||
const data = await this.#prepareMemberContext(partId);
|
||||
const data = this.#prepareMemberContext(partId);
|
||||
partContext.hasDamage |= Boolean(data?.damage);
|
||||
partContext.members[partId] = data;
|
||||
}
|
||||
|
|
@ -202,7 +202,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
return partContext;
|
||||
}
|
||||
|
||||
async #prepareMemberContext(partId) {
|
||||
#prepareMemberContext(partId) {
|
||||
const data = this.party.system.tagTeam.members[partId] ?? {};
|
||||
const actor = game.actors.get(partId);
|
||||
if (!actor) console.error(`Failed to get actor ${partId}`);
|
||||
|
|
@ -248,7 +248,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
rollOptions,
|
||||
damageRollOptions,
|
||||
damage: data.damageRollData,
|
||||
critDamage: await this.getCriticalDamage(data.damageRollData),
|
||||
critDamage: this.getCriticalDamage(data.damageRollData),
|
||||
useCritDamage: critSelected || (critSelected === undefined && data.roll?.isCritical)
|
||||
};
|
||||
}
|
||||
|
|
@ -374,7 +374,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
//#endregion
|
||||
//#region Tag Team Roll
|
||||
|
||||
async getInfoTexts(members) {
|
||||
getInfoTexts(members) {
|
||||
let rollsAreFinished = true;
|
||||
let rollIsSelected = false;
|
||||
for (const member of Object.values(members)) {
|
||||
|
|
@ -579,14 +579,14 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
);
|
||||
}
|
||||
|
||||
async getCriticalDamage(origDamage) {
|
||||
getCriticalDamage(origDamage) {
|
||||
const newDamage = origDamage ? ChatDamageData.fromJSON(JSON.stringify(origDamage)) : null;
|
||||
if (newDamage?.main) {
|
||||
const criticalDamage = await getCritDamageBonus(newDamage.main.formula);
|
||||
const criticalDamage = getCritDamageBonus(newDamage.main.terms);
|
||||
if (criticalDamage) {
|
||||
const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true });
|
||||
criticalTerm.evaluate();
|
||||
newDamage.main = await Roll.fromTerms([
|
||||
newDamage.main = Roll.fromTerms([
|
||||
...origDamage.main.terms,
|
||||
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
|
||||
criticalTerm
|
||||
|
|
@ -620,7 +620,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
);
|
||||
}
|
||||
|
||||
async getJoinedRoll({ overrideIsCritical, displayVersion } = {}) {
|
||||
getJoinedRoll({ overrideIsCritical, displayVersion } = {}) {
|
||||
try {
|
||||
const memberValues = Object.values(this.party.system.tagTeam.members);
|
||||
const selectedRoll = memberValues.find(x => x.selected);
|
||||
|
|
@ -641,11 +641,11 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
ChatDamageData.fromJSON(JSON.stringify(baseSecondaryRoll.damageRollData)) : null;
|
||||
|
||||
const isCritical = overrideIsCritical ?? mainRoll.roll.isCritical;
|
||||
if (isCritical) mainRoll.damageRollData = await this.getCriticalDamage(mainRoll.damageRollData);
|
||||
if (isCritical) mainRoll.damageRollData = this.getCriticalDamage(mainRoll.damageRollData);
|
||||
|
||||
if (secondaryRoll.damageRollData) {
|
||||
const secondaryDamage = (displayVersion ? overrideIsCritical : isCritical)
|
||||
? await this.getCriticalDamage(secondaryRoll.damageRollData)
|
||||
? this.getCriticalDamage(secondaryRoll.damageRollData)
|
||||
: secondaryRoll.damageRollData;
|
||||
if (mainRoll.damageRollData) {
|
||||
if (secondaryDamage.main) {
|
||||
|
|
@ -741,7 +741,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
const error = this.checkInitiatorHopeError(this.party.system.tagTeam.initiator);
|
||||
if (error) return error;
|
||||
|
||||
const joinedRoll = await this.getJoinedRoll();
|
||||
const joinedRoll = this.getJoinedRoll();
|
||||
const mainRoll = joinedRoll.rollData;
|
||||
const finalRoll = foundry.utils.deepClone(joinedRoll.roll);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export class ChatDamageData extends foundry.abstract.DataModel {
|
|||
}
|
||||
|
||||
_prepareRolls() {
|
||||
this.main &&= Roll.fromData(this.main);
|
||||
this.main &&= Roll.fromData({ ...this.main, class: 'DamageRoll' }); // Temp overriding to DamageRoll. Should be properly saved on creation instead
|
||||
for (const key of Object.keys(this.resources)) {
|
||||
this.resources[key] = Roll.fromData(this.resources[key]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import DamageDialog from '../applications/dialogs/damageDialog.mjs';
|
||||
import { parseRallyDice, triggerChatRollFx } from '../helpers/utils.mjs';
|
||||
import { getCritDamageBonus, parseRallyDice, triggerChatRollFx } from '../helpers/utils.mjs';
|
||||
import DHRoll from './dhRoll.mjs';
|
||||
|
||||
export default class DamageRoll extends DHRoll {
|
||||
|
|
@ -8,7 +8,12 @@ export default class DamageRoll extends DHRoll {
|
|||
}
|
||||
|
||||
get isCritical() {
|
||||
return !!this.options.isCritical;
|
||||
return true;
|
||||
}
|
||||
|
||||
get modifierTotal() {
|
||||
const criticalDamageBonus = this.isCritical ? getCritDamageBonus(this.terms) : 0;
|
||||
return super.modifierTotal + criticalDamageBonus;
|
||||
}
|
||||
|
||||
static DefaultDialog = DamageDialog;
|
||||
|
|
|
|||
|
|
@ -495,9 +495,8 @@ export function expireActiveEffects(actor, allowedTypes = null) {
|
|||
actor.deleteEmbeddedDocuments('ActiveEffect', effectsToExpire);
|
||||
}
|
||||
|
||||
export async function getCritDamageBonus(formula) {
|
||||
const critRoll = new Roll(formula);
|
||||
await critRoll.evaluate();
|
||||
export function getCritDamageBonus(terms) {
|
||||
const critRoll = Roll.fromTerms(terms);
|
||||
return critRoll.dice.reduce((acc, dice) => acc + dice.faces * dice.results.filter(r => r.active).length, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue