mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-22 02:19: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() {
|
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 });
|
await this.close({ submitted: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -184,8 +184,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
? undefined
|
? undefined
|
||||||
: (selectedRoll?.roll?.isCritical ?? false);
|
: (selectedRoll?.roll?.isCritical ?? false);
|
||||||
|
|
||||||
partContext.hintText = await this.getInfoTexts(this.party.system.tagTeam.members);
|
partContext.hintText = this.getInfoTexts(this.party.system.tagTeam.members);
|
||||||
partContext.joinedRoll = await this.getJoinedRoll({
|
partContext.joinedRoll = this.getJoinedRoll({
|
||||||
overrideIsCritical: critSelected,
|
overrideIsCritical: critSelected,
|
||||||
displayVersion: true
|
displayVersion: true
|
||||||
});
|
});
|
||||||
|
|
@ -194,7 +194,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(this.party.system.tagTeam.members).includes(partId)) {
|
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.hasDamage |= Boolean(data?.damage);
|
||||||
partContext.members[partId] = data;
|
partContext.members[partId] = data;
|
||||||
}
|
}
|
||||||
|
|
@ -202,7 +202,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
return partContext;
|
return partContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
async #prepareMemberContext(partId) {
|
#prepareMemberContext(partId) {
|
||||||
const data = this.party.system.tagTeam.members[partId] ?? {};
|
const data = this.party.system.tagTeam.members[partId] ?? {};
|
||||||
const actor = game.actors.get(partId);
|
const actor = game.actors.get(partId);
|
||||||
if (!actor) console.error(`Failed to get actor ${partId}`);
|
if (!actor) console.error(`Failed to get actor ${partId}`);
|
||||||
|
|
@ -248,7 +248,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
rollOptions,
|
rollOptions,
|
||||||
damageRollOptions,
|
damageRollOptions,
|
||||||
damage: data.damageRollData,
|
damage: data.damageRollData,
|
||||||
critDamage: await this.getCriticalDamage(data.damageRollData),
|
critDamage: this.getCriticalDamage(data.damageRollData),
|
||||||
useCritDamage: critSelected || (critSelected === undefined && data.roll?.isCritical)
|
useCritDamage: critSelected || (critSelected === undefined && data.roll?.isCritical)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -374,7 +374,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
//#endregion
|
//#endregion
|
||||||
//#region Tag Team Roll
|
//#region Tag Team Roll
|
||||||
|
|
||||||
async getInfoTexts(members) {
|
getInfoTexts(members) {
|
||||||
let rollsAreFinished = true;
|
let rollsAreFinished = true;
|
||||||
let rollIsSelected = false;
|
let rollIsSelected = false;
|
||||||
for (const member of Object.values(members)) {
|
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;
|
const newDamage = origDamage ? ChatDamageData.fromJSON(JSON.stringify(origDamage)) : null;
|
||||||
if (newDamage?.main) {
|
if (newDamage?.main) {
|
||||||
const criticalDamage = await getCritDamageBonus(newDamage.main.formula);
|
const criticalDamage = getCritDamageBonus(newDamage.main.terms);
|
||||||
if (criticalDamage) {
|
if (criticalDamage) {
|
||||||
const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true });
|
const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true });
|
||||||
criticalTerm.evaluate();
|
criticalTerm.evaluate();
|
||||||
newDamage.main = await Roll.fromTerms([
|
newDamage.main = Roll.fromTerms([
|
||||||
...origDamage.main.terms,
|
...origDamage.main.terms,
|
||||||
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
|
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
|
||||||
criticalTerm
|
criticalTerm
|
||||||
|
|
@ -620,7 +620,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getJoinedRoll({ overrideIsCritical, displayVersion } = {}) {
|
getJoinedRoll({ overrideIsCritical, displayVersion } = {}) {
|
||||||
try {
|
try {
|
||||||
const memberValues = Object.values(this.party.system.tagTeam.members);
|
const memberValues = Object.values(this.party.system.tagTeam.members);
|
||||||
const selectedRoll = memberValues.find(x => x.selected);
|
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;
|
ChatDamageData.fromJSON(JSON.stringify(baseSecondaryRoll.damageRollData)) : null;
|
||||||
|
|
||||||
const isCritical = overrideIsCritical ?? mainRoll.roll.isCritical;
|
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) {
|
if (secondaryRoll.damageRollData) {
|
||||||
const secondaryDamage = (displayVersion ? overrideIsCritical : isCritical)
|
const secondaryDamage = (displayVersion ? overrideIsCritical : isCritical)
|
||||||
? await this.getCriticalDamage(secondaryRoll.damageRollData)
|
? this.getCriticalDamage(secondaryRoll.damageRollData)
|
||||||
: secondaryRoll.damageRollData;
|
: secondaryRoll.damageRollData;
|
||||||
if (mainRoll.damageRollData) {
|
if (mainRoll.damageRollData) {
|
||||||
if (secondaryDamage.main) {
|
if (secondaryDamage.main) {
|
||||||
|
|
@ -741,7 +741,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
const error = this.checkInitiatorHopeError(this.party.system.tagTeam.initiator);
|
const error = this.checkInitiatorHopeError(this.party.system.tagTeam.initiator);
|
||||||
if (error) return error;
|
if (error) return error;
|
||||||
|
|
||||||
const joinedRoll = await this.getJoinedRoll();
|
const joinedRoll = this.getJoinedRoll();
|
||||||
const mainRoll = joinedRoll.rollData;
|
const mainRoll = joinedRoll.rollData;
|
||||||
const finalRoll = foundry.utils.deepClone(joinedRoll.roll);
|
const finalRoll = foundry.utils.deepClone(joinedRoll.roll);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ export class ChatDamageData extends foundry.abstract.DataModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
_prepareRolls() {
|
_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)) {
|
for (const key of Object.keys(this.resources)) {
|
||||||
this.resources[key] = Roll.fromData(this.resources[key]);
|
this.resources[key] = Roll.fromData(this.resources[key]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import DamageDialog from '../applications/dialogs/damageDialog.mjs';
|
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';
|
import DHRoll from './dhRoll.mjs';
|
||||||
|
|
||||||
export default class DamageRoll extends DHRoll {
|
export default class DamageRoll extends DHRoll {
|
||||||
|
|
@ -8,7 +8,12 @@ export default class DamageRoll extends DHRoll {
|
||||||
}
|
}
|
||||||
|
|
||||||
get isCritical() {
|
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;
|
static DefaultDialog = DamageDialog;
|
||||||
|
|
|
||||||
|
|
@ -495,9 +495,8 @@ export function expireActiveEffects(actor, allowedTypes = null) {
|
||||||
actor.deleteEmbeddedDocuments('ActiveEffect', effectsToExpire);
|
actor.deleteEmbeddedDocuments('ActiveEffect', effectsToExpire);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCritDamageBonus(formula) {
|
export function getCritDamageBonus(terms) {
|
||||||
const critRoll = new Roll(formula);
|
const critRoll = Roll.fromTerms(terms);
|
||||||
await critRoll.evaluate();
|
|
||||||
return critRoll.dice.reduce((acc, dice) => acc + dice.faces * dice.results.filter(r => r.active).length, 0);
|
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