Compare commits

...

7 commits

12 changed files with 71 additions and 86 deletions

View file

@ -24,7 +24,7 @@ import TokenManager from './module/documents/tokenManager.mjs';
CONFIG.DH = SYSTEM; CONFIG.DH = SYSTEM;
CONFIG.TextEditor.enrichers.push(...enricherConfig); CONFIG.TextEditor.enrichers.push(...enricherConfig);
CONFIG.Dice.rolls = [BaseRoll, DHRoll, DualityRoll, D20Roll, DamageRoll, FateRoll]; CONFIG.Dice.rolls = [Roll = BaseRoll, DHRoll, DualityRoll, D20Roll, DamageRoll, FateRoll];
CONFIG.Dice.daggerheart = { CONFIG.Dice.daggerheart = {
DHRoll: DHRoll, DHRoll: DHRoll,
DualityRoll: DualityRoll, DualityRoll: DualityRoll,

View file

@ -141,7 +141,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
const hasRolled = Boolean(data.rollData); const hasRolled = Boolean(data.rollData);
if (!hasRolled) return false; if (!hasRolled) return false;
return !data.rollData.options.hasDamage || Boolean(data.rollData.options.damage); return !data.rollData.options.hasDamage || data.damageRollData.active;
}); });
return context; return context;
@ -182,7 +182,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
const selectedRoll = Object.values(this.party.system.tagTeam.members).find(member => member.selected); const selectedRoll = Object.values(this.party.system.tagTeam.members).find(member => member.selected);
const critSelected = !selectedRoll const critSelected = !selectedRoll
? undefined ? undefined
: (selectedRoll?.rollData?.options?.roll?.isCritical ?? false); : (selectedRoll?.roll?.isCritical ?? false);
partContext.hintText = await this.getInfoTexts(this.party.system.tagTeam.members); partContext.hintText = await this.getInfoTexts(this.party.system.tagTeam.members);
partContext.joinedRoll = await this.getJoinedRoll({ partContext.joinedRoll = await this.getJoinedRoll({
@ -236,7 +236,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
} }
const selectedRoll = Object.values(this.party.system.tagTeam.members).find(member => member.selected); const selectedRoll = Object.values(this.party.system.tagTeam.members).find(member => member.selected);
const critSelected = !selectedRoll ? undefined : (selectedRoll?.rollData?.options?.roll?.isCritical ?? false); const critSelected = !selectedRoll ? undefined : (selectedRoll?.roll?.isCritical ?? false);
return { return {
...data, ...data,
@ -249,7 +249,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
damageRollOptions, damageRollOptions,
damage: data.damageRollData, damage: data.damageRollData,
critDamage: await this.getCriticalDamage(data.damageRollData), critDamage: await this.getCriticalDamage(data.damageRollData),
useCritDamage: critSelected || (critSelected === undefined && data.rollData?.options?.roll?.isCritical) useCritDamage: critSelected || (critSelected === undefined && data.roll?.isCritical)
}; };
} }
@ -379,7 +379,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
let rollIsSelected = false; let rollIsSelected = false;
for (const member of Object.values(members)) { for (const member of Object.values(members)) {
const rollFinished = Boolean(member.rollData); const rollFinished = Boolean(member.rollData);
const damageFinished = member.rollData?.options?.hasDamage ? Boolean(member.rollData.options.damage) : true; const damageFinished = member.rollData?.options?.hasDamage ? member.damageRollData.active : true;
rollsAreFinished = rollsAreFinished && rollFinished && damageFinished; rollsAreFinished = rollsAreFinished && rollFinished && damageFinished;
rollIsSelected = rollIsSelected || member.selected; rollIsSelected = rollIsSelected || member.selected;
@ -540,17 +540,10 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
await action.workflow.get('damage').execute(config, null, true); await action.workflow.get('damage').execute(config, null, true);
if (!config.damage) return; if (!config.damage) return;
const current = this.party.system.tagTeam.members[memberKey].rollData;
await this.updatePartyData( await this.updatePartyData(
{ {
[`system.tagTeam.members.${memberKey}.rollData`]: { [`system.tagTeam.members.${memberKey}.damageRollData`]: config.damage
...current,
options: {
...current.options,
damage: config.damage
}
}
}, },
this.getUpdatingParts(button) this.getUpdatingParts(button)
); );
@ -558,52 +551,25 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
static async #removeDamageRoll(_, button) { static async #removeDamageRoll(_, button) {
const { memberKey } = button.dataset; const { memberKey } = button.dataset;
const current = this.party.system.tagTeam.members[memberKey].rollData;
this.updatePartyData( this.updatePartyData(
{ {
[`system.tagTeam.members.${memberKey}.rollData`]: { [`system.tagTeam.members.${memberKey}.damageRollData.types`]:
...current, _replace({})
options: {
...current.options,
damage: null
}
}
}, },
this.getUpdatingParts(button) this.getUpdatingParts(button)
); );
} }
static async #rerollDamageDice(_, button) { static async #rerollDamageDice(_, button) {
const { memberKey, damageKey, part, dice } = button.dataset; const { memberKey, damageKey, diceIndex, resultIndex } = button.dataset;
const memberData = this.party.system.tagTeam.members[memberKey]; const memberData = this.party.system.tagTeam.members[memberKey];
const partData = memberData.rollData.options.damage[damageKey].parts[part]; await memberData.damageRollData.rerollDamageDie(damageKey, diceIndex, resultIndex);
const activeDiceResultKey = Object.keys(partData.dice[dice].results).find(
index => partData.dice[dice].results[index].active
);
const { parsedRoll, rerolledDice } = await game.system.api.dice.DamageRoll.reroll(
partData,
dice,
activeDiceResultKey
);
const rollData = this.party.system.tagTeam.members[memberKey].rollData;
rollData.options.damage[damageKey].parts = rollData.options.damage[damageKey].parts.map((damagePart, index) => {
if (index !== Number.parseInt(part)) return damagePart;
return {
...damagePart,
total: parsedRoll.total,
dice: rerolledDice
};
});
rollData.options.damage[damageKey].total = rollData.options.damage[damageKey].parts.reduce((acc, part) => {
acc += part.total;
return acc;
}, 0);
this.updatePartyData( this.updatePartyData(
{ {
[`system.tagTeam.members.${memberKey}.rollData`]: rollData [`system.tagTeam.members.${memberKey}.damageRollData.types`]: {
[damageKey]: memberData.damageRollData.types[damageKey].toJSON()
}
}, },
this.getUpdatingParts(button) this.getUpdatingParts(button)
); );
@ -622,6 +588,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
new foundry.dice.terms.OperatorTerm({ operator: '+' }), new foundry.dice.terms.OperatorTerm({ operator: '+' }),
criticalTerm criticalTerm
]); ]);
newDamage.types[key].options = foundry.utils.deepClone(origDamage.types[key].options);
} }
return newDamage; return newDamage;
@ -629,6 +596,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
static async #selectRoll(_, button) { static async #selectRoll(_, button) {
const { memberKey } = button.dataset; const { memberKey } = button.dataset;
this.updatePartyData( this.updatePartyData(
{ {
[`system.tagTeam.members`]: Object.entries(this.party.system.tagTeam.members).reduce( [`system.tagTeam.members`]: Object.entries(this.party.system.tagTeam.members).reduce(
@ -639,7 +607,12 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
{} {}
) )
}, },
this.getUpdatingParts(button) /* Selecting a roll must update all member sections hbs to display the correct damage information incase of a critical */
[
...Object.keys(this.party.system.tagTeam.members),
this.constructor.PARTS.rollSelection.id,
this.constructor.PARTS.result.id
]
); );
} }
@ -663,9 +636,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
secondaryRoll.damageRollData = baseSecondaryRoll.damageRollData ? secondaryRoll.damageRollData = baseSecondaryRoll.damageRollData ?
ChatDamageData.fromJSON(JSON.stringify(baseSecondaryRoll.damageRollData)) : null; ChatDamageData.fromJSON(JSON.stringify(baseSecondaryRoll.damageRollData)) : null;
const systemData = mainRoll.rollData.options; const isCritical = overrideIsCritical ?? mainRoll.roll.isCritical;
const isCritical = overrideIsCritical ?? systemData.roll.isCritical; if (isCritical) mainRoll.damageRollData = await this.getCriticalDamage(mainRoll.damageRollData);
if (isCritical) mainRoll.damageRollData = await this.getCriticalDamage(systemData.damageRollData);
if (secondaryRoll.damageRollData) { if (secondaryRoll.damageRollData) {
const secondaryDamage = (displayVersion ? overrideIsCritical : isCritical) const secondaryDamage = (displayVersion ? overrideIsCritical : isCritical)
@ -679,6 +651,16 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
new foundry.dice.terms.OperatorTerm({ operator: '+' }), new foundry.dice.terms.OperatorTerm({ operator: '+' }),
...baseSecondaryRoll.damageRollData.types[key].terms ...baseSecondaryRoll.damageRollData.types[key].terms
]); ]);
/* Joining the roll.options of both rolls */
const joinedDamageTypes = new Set([
...baseMainRoll.damageRollData.types[key].options.damageTypes,
...baseSecondaryRoll.damageRollData.types[key].options.damageTypes
]);
mainRoll.damageRollData.types[key].options = {
...baseMainRoll.damageRollData.types[key].options,
damageTypes: [...joinedDamageTypes]
};
} else { } else {
mainRoll.damageRollData.types[key] = damage; mainRoll.damageRollData.types[key] = damage;
} }

View file

@ -3,7 +3,6 @@ import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayFie
import TagTeamData from '../tagTeamData.mjs'; import TagTeamData from '../tagTeamData.mjs';
import GroupRollData from '../groupRollData.mjs'; import GroupRollData from '../groupRollData.mjs';
import { GoldField } from '../fields/actorField.mjs'; import { GoldField } from '../fields/actorField.mjs';
import { ChatDamageData } from '../chat-message/chatDamageData.mjs';
export default class DhParty extends BaseDataActor { export default class DhParty extends BaseDataActor {
/** @inheritdoc */ /** @inheritdoc */
@ -49,14 +48,6 @@ export default class DhParty extends BaseDataActor {
} }
} }
prepareDerivedData() {
for (const memberKey in this.tagTeam.members) {
const member = this.tagTeam.members[memberKey];
member.damageRollData = member.rollData?.options.damage ?
ChatDamageData.fromJSON(JSON.stringify(member.rollData.options.damage)) : null;
}
}
_onCreate(data, options, userId) { _onCreate(data, options, userId) {
super._onCreate(data, options, userId); super._onCreate(data, options, userId);

View file

@ -118,9 +118,9 @@ export default class DamageField extends fields.SchemaField {
const hpDamageMultiplier = config.actionActor?.system.rules?.attack?.damage?.hpDamageMultiplier ?? 1; const hpDamageMultiplier = config.actionActor?.system.rules?.attack?.damage?.hpDamageMultiplier ?? 1;
const hpDamageTakenMultiplier = actor.system.rules?.attack?.damage?.hpDamageTakenMultiplier; const hpDamageTakenMultiplier = actor.system.rules?.attack?.damage?.hpDamageTakenMultiplier;
if (configDamage.hitPoints) { if (configDamage.hitPoints) {
configDamage.hitPoints.roll = configDamage.hitPoints.roll.toJSON(); configDamage.hitPoints = configDamage.hitPoints.toJSON();
configDamage.hitPoints.roll.total = Math.ceil( configDamage.hitPoints.total = Math.ceil(
configDamage.hitPoints.roll.total * hpDamageMultiplier * hpDamageTakenMultiplier configDamage.hitPoints.total * hpDamageMultiplier * hpDamageTakenMultiplier
); );
} }

View file

@ -1,3 +1,5 @@
import { ChatDamageData } from './chat-message/chatDamageData.mjs';
export default class TagTeamData extends foundry.abstract.DataModel { export default class TagTeamData extends foundry.abstract.DataModel {
static defineSchema() { static defineSchema() {
const fields = foundry.data.fields; const fields = foundry.data.fields;
@ -37,6 +39,7 @@ export class MemberData extends foundry.abstract.DataModel {
}), }),
rollChoice: new fields.StringField({ nullable: true, initial: null }), rollChoice: new fields.StringField({ nullable: true, initial: null }),
rollData: new fields.JSONField({ nullable: true, initial: null }), rollData: new fields.JSONField({ nullable: true, initial: null }),
damageRollData: new fields.EmbeddedDataField(ChatDamageData),
selected: new fields.BooleanField({ initial: false }) selected: new fields.BooleanField({ initial: false })
}; };
} }

View file

@ -4,4 +4,8 @@ export default class BaseRoll extends Roll {
/** @inheritdoc */ /** @inheritdoc */
static TOOLTIP_TEMPLATE = 'systems/daggerheart/templates/ui/chat/foundryRollTooltip.hbs'; static TOOLTIP_TEMPLATE = 'systems/daggerheart/templates/ui/chat/foundryRollTooltip.hbs';
get modifierTotal() {
return this.total - this.dice.reduce((acc, dice) => acc + dice.total, 0);
}
} }

View file

@ -19,7 +19,7 @@ export default class DamageRoll extends DHRoll {
for (const roll of config.roll) { for (const roll of config.roll) {
await roll.roll.evaluate(); await roll.roll.evaluate();
roll.roll.options = { damageTypes: roll.damageTypes ?? [] }; roll.roll.options = { damageTypes: roll.damageTypes ? [...roll.damageTypes] : [] };
if (!config.damage?.types) config.damage = { types: {} }; if (!config.damage?.types) config.damage = { types: {} };
config.damage.types[roll.applyTo] = roll.roll; config.damage.types[roll.applyTo] = roll.roll;
@ -37,7 +37,7 @@ export default class DamageRoll extends DHRoll {
if (game.modules.get('dice-so-nice')?.active) { if (game.modules.get('dice-so-nice')?.active) {
config.mute = true; config.mute = true;
const pool = foundry.dice.terms.PoolTerm.fromRolls( const pool = foundry.dice.terms.PoolTerm.fromRolls(
Object.values(config.damage.types).map(x => x.roll) Object.values(config.damage.types)
); );
diceRolls.push(Roll.fromTerms([pool])); diceRolls.push(Roll.fromTerms([pool]));
} }

View file

@ -660,12 +660,12 @@ export default class DhpActor extends Actor {
Object.entries(damages).forEach(([key, damage]) => { Object.entries(damages).forEach(([key, damage]) => {
if (key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) if (key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id)
damage.roll.total = this.calculateDamage(damage.roll.total, damage.damageTypes); damage.total = this.calculateDamage(damage.total, damage.damageTypes);
const update = updates.find(u => u.key === key); const update = updates.find(u => u.key === key);
if (update) { if (update) {
update.value += damage.roll.total; update.value += damage.total;
update.damageTypes.add(...new Set(damage.damageTypes)); update.damageTypes.add(...new Set(damage.damageTypes));
} else updates.push({ value: damage.roll.total, key, damageTypes: new Set(damage.damageTypes) }); } else updates.push({ value: damage.total, key, damageTypes: new Set(damage.damageTypes) });
}); });
if (Hooks.call(`${CONFIG.DH.id}.postCalculateDamage`, this, damages) === false) return null; if (Hooks.call(`${CONFIG.DH.id}.postCalculateDamage`, this, damages) === false) return null;

View file

@ -2,15 +2,19 @@
<div class="roll-data {{#if isCritical}}critical{{/if}}"> <div class="roll-data {{#if isCritical}}critical{{/if}}">
<div class="duality-label"> <div class="duality-label">
<span>{{localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name")}}:</span> <span>{{localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name")}}:</span>
<span>{{damage.roll.total}}</span> <span>{{roll.total}}</span>
</div> </div>
<div class="roll-dice-container"> <div class="roll-dice-container">
{{#each roll.dice as |dice index|}} {{#each roll.dice}}
<a class="roll-dice" data-action="rerollDamageDice" data-member-key="{{../../../key}}" data-damage-key="{{@../../key}}" data-dice="{{index}}"> {{#each results as |result index|}}
<span class="dice-label">{{dice.total}}</span> {{#if result.active}}
<img src="{{concat "systems/daggerheart/assets/icons/dice/hope/" dice.denomination ".svg"}}" /> <a class="roll-dice" data-action="rerollDamageDice" data-member-key="{{../../../key}}" data-damage-key="{{@../../key}}" data-dice-index="{{@../key}}" data-result-index="{{index}}">
</a> <span class="dice-label">{{result.result}}</span>
<img src="{{concat "systems/daggerheart/assets/icons/dice/hope/" ../denomination ".svg"}}" />
</a>
{{/if}}
{{/each}}
{{#unless @last}} {{#unless @last}}
<span class="roll-operator">+</span> <span class="roll-operator">+</span>
{{/unless}} {{/unless}}

View file

@ -21,7 +21,7 @@
{{#each joinedRoll.damageRollData.types as |damage key|}} {{#each joinedRoll.damageRollData.types as |damage key|}}
<div class="result-info"> <div class="result-info">
<div>{{localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name")}}</div> <div>{{localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name")}}</div>
<div class="damage-info">{{damage.roll.total}}</div> <div class="damage-info">{{damage.total}}</div>
</div> </div>
{{/each}} {{/each}}
</div> </div>

View file

@ -64,7 +64,10 @@
{{#if roll}} {{#if roll}}
<div class="roll-data {{#if roll.withHope}}hope{{else if roll.withFear}}fear{{else}}critical{{/if}}"> <div class="roll-data {{#if roll.withHope}}hope{{else if roll.withFear}}fear{{else}}critical{{/if}}">
<div class="duality-label">{{roll.total}} {{localize "DAGGERHEART.GENERAL.withThing" thing=roll.totalLabel}}</div> <div class="duality-label">
{{roll.total}}
{{#if roll.isCritical}}{{roll.totalLabel}}{{else}}{{localize "DAGGERHEART.GENERAL.withThing" thing=roll.totalLabel}}{{/if}}
</div>
<div class="roll-dice-container"> <div class="roll-dice-container">
<a class="roll-dice" data-action="rerollDice" data-member="{{@root.partId}}" data-dice-type="hope"> <a class="roll-dice" data-action="rerollDice" data-member="{{@root.partId}}" data-dice-type="hope">
<span class="dice-label">{{roll.dHope.total}}</span> <span class="dice-label">{{roll.dHope.total}}</span>
@ -100,15 +103,12 @@
<a class="roll-button" data-action="makeDamageRoll" data-member-key="{{@root.partId}}" {{#unless readyToRoll}}disabled{{/unless}}> <a class="roll-button" data-action="makeDamageRoll" data-member-key="{{@root.partId}}" {{#unless readyToRoll}}disabled{{/unless}}>
<img src="systems/daggerheart/assets/icons/dice/hope/d20.svg" /> <img src="systems/daggerheart/assets/icons/dice/hope/d20.svg" />
</a> </a>
<a class="delete-button" data-action="removeDamageRoll" data-member-key="{{@root.partId}}" {{#unless damage.active}}disabled{{/unless}}>
{{#if damage}} <i class="fa-solid fa-trash"></i>
<a class="delete-button" data-action="removeDamageRoll" data-member-key="{{@root.partId}}" {{#unless rollData.options.damage}}disabled{{/unless}}> </a>
<i class="fa-solid fa-trash"></i>
</a>
{{/if}}
</div> </div>
</span> </span>
{{#if damage}} {{#if damage.active}}
{{#if useCritDamage}} {{#if useCritDamage}}
{{> "systems/daggerheart/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs" damage=critDamage isCritical=true }} {{> "systems/daggerheart/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs" damage=critDamage isCritical=true }}
{{else}} {{else}}

View file

@ -39,7 +39,7 @@
{{#if active}} {{#if active}}
<div class="roll-die{{#unless @../first}} has-plus{{/unless}}"> <div class="roll-die{{#unless @../first}} has-plus{{/unless}}">
<div <div
class="dice reroll-button {{../dice}}" class="dice reroll-button {{../denomination}}"
data-die-index="0" data-type="damage" data-damage-type="{{@../../key}}" data-dice="{{@../key}}" data-result="{{@key}}" data-die-index="0" data-type="damage" data-damage-type="{{@../../key}}" data-dice="{{@../key}}" data-result="{{@key}}"
> >
{{#if hasRerolls}}<i class="fa-solid fa-dice dice-rerolled" data-tooltip="{{localize "DAGGERHEART.GENERAL.rerolled"}}"></i>{{/if}} {{#if hasRerolls}}<i class="fa-solid fa-dice dice-rerolled" data-tooltip="{{localize "DAGGERHEART.GENERAL.rerolled"}}"></i>{{/if}}
@ -49,6 +49,7 @@
{{/if}} {{/if}}
{{/each}} {{/each}}
{{/each}} {{/each}}
{{#if roll.modifierTotal}} {{#if roll.modifierTotal}}
<div class="roll-die{{#if (gt roll.modifierTotal 0)}} has-plus{{/if}}"> <div class="roll-die{{#if (gt roll.modifierTotal 0)}} has-plus{{/if}}">
<div class="font-20">{{roll.modifierTotal}}</div> <div class="font-20">{{roll.modifierTotal}}</div>