[Feature] 946 - Damage/Effect ChatMessages (#1089)

* Initial damage message

* Added hover functionality to adversary damage cards

* Added effect message

* enhance chat messages styles

* .

* Fixed promise lockup

* .

* Fixed token path for message

---------

Co-authored-by: moliloo <dev.murilobrito@gmail.com>
This commit is contained in:
WBHarry 2025-10-29 18:56:37 +01:00 committed by GitHub
parent 906c7ac853
commit ff79dd19bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 450 additions and 12 deletions

View file

@ -2307,6 +2307,9 @@
"label": "Apply Effects",
"hint": "Automatically apply effects. Targets must be selected before the action is made and Reaction Roll Automation must be different than Never. Bypass users permissions."
}
},
"summaryMessages": {
"label": "Summary Messages"
}
},
"defeated": {
@ -2428,6 +2431,7 @@
"action": {
"title": "Action"
},
"appliedTo": "Applied To",
"applyEffect": {
"title": "Apply Effects - {name}"
},
@ -2437,6 +2441,11 @@
"rollHealing": "Roll Healing",
"applyEffect": "Apply Effects"
},
"clearResource": "Clear {quantity} {resource}",
"damageSummary": {
"title": "Damage Applied",
"healingTitle": "Healing Applied"
},
"damageRoll": {
"title": "Damage - {damage}",
"dealDamageToTargets": "Damage Hit Targets",
@ -2458,12 +2467,16 @@
"dualityRoll": {
"abilityCheckTitle": "{ability} Check"
},
"effectSummary": {
"title": "Effects Applied"
},
"featureTitle": "Class Feature",
"healingRoll": {
"title": "Heal - {damage}",
"heal": "Heal",
"applyHealing": "Apply Healing"
},
"markResource": "Mark {quantity} {resource}",
"refreshMessage": {
"title": "Feature Refresh",
"header": "Refreshed"

View file

@ -1,9 +1,11 @@
import DHAbilityUse from './abilityUse.mjs';
import DHActorRoll from './actorRoll.mjs';
import DHSystemMessage from './systemMessage.mjs';
export const config = {
abilityUse: DHAbilityUse,
adversaryRoll: DHActorRoll,
damageRoll: DHActorRoll,
dualityRoll: DHActorRoll
dualityRoll: DHActorRoll,
systemMessage: DHSystemMessage
};

View file

@ -0,0 +1,9 @@
export default class DHSystemMessage extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
useTitle: new fields.BooleanField({ initial: true })
};
}
}

View file

@ -81,6 +81,9 @@ export default class DamageField extends fields.SchemaField {
static async applyDamage(config, targets = null, force = false) {
targets ??= config.targets.filter(target => target.hit);
if (!config.damage || !targets?.length || (!DamageField.getApplyAutomation() && !force)) return;
const targetDamage = [];
const damagePromises = [];
for (let target of targets) {
const actor = fromUuidSync(target.actorId);
if (!actor) continue;
@ -95,9 +98,45 @@ export default class DamageField extends fields.SchemaField {
});
}
if (config.hasHealing) actor.takeHealing(config.damage);
else actor.takeDamage(config.damage, config.isDirect);
if (config.hasHealing)
damagePromises.push(
actor
.takeHealing(config.damage)
.then(updates => targetDamage.push({ token: actor.token ?? actor.prototypeToken, updates }))
);
else
damagePromises.push(
actor
.takeDamage(config.damage, config.isDirect)
.then(updates => targetDamage.push({ token: actor.token ?? actor.prototypeToken, updates }))
);
}
Promise.all(damagePromises).then(async _ => {
const summaryMessageSettings = game.settings.get(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Automation
).summaryMessages;
if (!summaryMessageSettings.damage) return;
const cls = getDocumentClass('ChatMessage');
const msg = {
type: 'systemMessage',
user: game.user.id,
speaker: cls.getSpeaker(),
title: game.i18n.localize(
`DAGGERHEART.UI.Chat.damageSummary.${config.hasHealing ? 'healingTitle' : 'title'}`
),
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/ui/chat/damageSummary.hbs',
{
targets: targetDamage
}
)
};
cls.create(msg);
});
}
/**

View file

@ -46,17 +46,48 @@ export default class EffectsField extends fields.ArrayField {
*/
static async applyEffects(targets) {
if (!this.effects?.length || !targets?.length) return;
let effects = this.effects;
targets.forEach(async token => {
const messageTargets = [];
targets.forEach(async baseToken => {
if (this.hasSave && token.saved.success === true) effects = this.effects.filter(e => e.onSave === true);
if (!effects.length) return;
const token = canvas.tokens.get(baseToken.id);
if (!token) return;
messageTargets.push(token.document);
effects.forEach(async e => {
const actor = canvas.tokens.get(token.id)?.actor,
effect = this.item.effects.get(e._id);
if (!actor || !effect) return;
await EffectsField.applyEffect(effect, actor);
const effect = this.item.effects.get(e._id);
if (!token.actor || !effect) return;
await EffectsField.applyEffect(effect, token.actor);
});
});
if (messageTargets.length === 0) return;
const summaryMessageSettings = game.settings.get(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Automation
).summaryMessages;
if (!summaryMessageSettings.effects) return;
const cls = getDocumentClass('ChatMessage');
const msg = {
type: 'systemMessage',
user: game.user.id,
speaker: cls.getSpeaker(),
title: game.i18n.localize('DAGGERHEART.UI.Chat.effectSummary.title'),
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/ui/chat/effectSummary.hbs',
{
effects: this.effects.map(e => this.item.effects.get(e._id)),
targets: messageTargets
}
)
};
cls.create(msg);
}
/**

View file

@ -2,6 +2,10 @@ export default class DhAutomation extends foundry.abstract.DataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
summaryMessages: new fields.SchemaField({
damage: new fields.BooleanField({ initial: true, label: 'DAGGERHEART.GENERAL.damage' }),
effects: new fields.BooleanField({ initial: true, label: 'DAGGERHEART.GENERAL.Effect.plural' })
}),
hopeFear: new fields.SchemaField({
gm: new fields.BooleanField({
required: true,

View file

@ -599,6 +599,8 @@ export default class DhpActor extends Actor {
await this.modifyResource(updates);
if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, updates) === false) return null;
return updates;
}
calculateDamage(baseDamage, type) {
@ -647,6 +649,8 @@ export default class DhpActor extends Actor {
await this.modifyResource(updates);
if (Hooks.call(`${CONFIG.DH.id}.postTakeHealing`, this, updates) === false) return null;
return updates;
}
async modifyResource(resources) {

View file

@ -143,6 +143,12 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
html.querySelectorAll('.button-target-selection').forEach(element => {
element.addEventListener('click', this.onTargetSelection.bind(this));
});
html.querySelectorAll('.token-target-container').forEach(element => {
element.addEventListener('pointerover', this.hoverTarget);
element.addEventListener('pointerout', this.unhoverTarget);
element.addEventListener('click', this.clickTarget);
});
}
async onRollDamage(event) {

View file

@ -14,7 +14,8 @@ export default class RegisterHandlebarsHelpers {
getProperty: foundry.utils.getProperty,
setVar: this.setVar,
empty: this.empty,
pluralize: this.pluralize
pluralize: this.pluralize,
positive: this.positive
});
}
static add(a, b) {
@ -89,4 +90,8 @@ export default class RegisterHandlebarsHelpers {
const key = isSingular ? `${baseKey}.single` : `${baseKey}.plural`;
return game.i18n.localize(key);
}
static positive(a) {
return Math.abs(Number(a));
}
}

View file

@ -29,7 +29,6 @@ export const preloadHandlebarsTemplates = async function () {
'systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs',
'systems/daggerheart/templates/dialogs/downtime/activities.hbs',
'systems/daggerheart/templates/dialogs/dice-roll/costSelection.hbs',
'systems/daggerheart/templates/ui/chat/parts/roll-part.hbs',
'systems/daggerheart/templates/ui/chat/parts/damage-part.hbs',
'systems/daggerheart/templates/ui/chat/parts/target-part.hbs',

View file

@ -0,0 +1,87 @@
@import '../../utils/colors.less';
#interface.theme-light {
.daggerheart.chat.damage-summary .token-target-container {
&:hover {
background: @dark-blue-10;
}
header {
.actor-name {
color: @dark;
}
&::after {
background: @dark-blue;
}
}
}
}
.daggerheart.chat.damage-summary {
display: flex;
flex-direction: column;
gap: 5px;
padding: 0;
.token-target-container {
display: flex;
flex-direction: column;
gap: 2px;
cursor: pointer;
transition: all 0.3s ease;
border-radius: 6px;
&:hover {
background: @golden-10;
}
header {
display: flex;
align-items: center;
gap: 5px;
pointer-events: none;
position: relative;
margin-bottom: 10px;
img {
width: 40px;
height: 40px;
padding: 0;
border-radius: 50%;
}
.actor-name {
margin: 0;
color: @beige;
font-size: var(--font-size-20);
padding: 8px;
}
&::after {
content: '';
position: absolute;
bottom: -10px;
background: @golden;
mask-image: linear-gradient(270deg, transparent 0%, black 50%, transparent 100%);
height: 2px;
width: 100%;
}
}
.damage-container {
display: flex;
flex-direction: column;
justify-content: center;
gap: 5px;
pointer-events: none;
margin-top: 5px;
list-style: disc;
.damage-row {
padding: 0 2px;
gap: 4px;
}
}
}
}

View file

@ -0,0 +1,166 @@
@import '../../utils/colors.less';
#interface.theme-light {
.daggerheart.chat.effect-summary {
.effect-header,
.actor-header {
&::before,
&::after {
height: 2px;
background: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, @dark-blue 100%);
}
&::after {
background: linear-gradient(90deg, @dark-blue 0%, rgba(0, 0, 0, 0) 100%);
}
span {
color: @dark;
}
}
.token-target-container,
.effect-target-container {
.effect-label .title,
.title {
color: @dark-blue;
}
.effect-label {
border-color: @dark-blue;
}
&:hover {
background: @dark-blue-10;
}
}
}
}
.daggerheart.chat.effect-summary {
display: flex;
flex-direction: column;
.effect-header,
.actor-header {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 5px;
&::before,
&::after {
content: '';
flex: 1;
height: 2px;
background: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, @golden 100%);
}
&::after {
background: linear-gradient(90deg, @golden 0%, rgba(0, 0, 0, 0) 100%);
}
span {
color: @beige;
padding: 0 10px;
white-space: nowrap;
}
}
.effects-container {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-bottom: 8px;
}
.targets-container {
display: flex;
flex-direction: column;
gap: 5px;
}
.token-target-container {
display: flex;
align-items: center;
gap: 13px;
border-radius: 6px;
padding: 0 2px;
border-radius: 6px;
background: transparent;
transition: all 0.3s ease;
padding: 5px;
cursor: pointer;
transition: all 0.3s ease;
&:hover {
background: @golden-10;
}
img {
width: 40px;
height: 40px;
border-radius: 50%;
pointer-events: none;
}
.title {
font-size: var(--font-size-20);
color: @golden;
font-weight: 700;
margin: 0;
pointer-events: none;
}
}
details[open] {
.fa-chevron-down {
transform: rotate(180deg);
transition: all 0.3s ease;
}
}
.effect-target-container {
width: 100%;
transition: all 0.3s ease;
cursor: pointer;
&:hover {
background: @golden-10;
}
.fa-chevron-down {
transition: all 0.3s ease;
margin-left: auto;
}
.effect-label {
display: flex;
flex-direction: row;
align-items: center;
margin: 8px 8px 0;
padding-bottom: 5px;
width: -webkit-fill-available;
gap: 13px;
border-bottom: 1px solid @golden;
.effect-img {
width: 40px;
height: 40px;
border-radius: 3px;
object-fit: cover;
}
.title {
font-size: var(--font-size-20);
color: @golden;
font-weight: 700;
margin: 0;
}
}
.description {
padding: 8px;
}
}
}

View file

@ -1,7 +1,9 @@
@import './chat/ability-use.less';
@import './chat/action.less';
@import './chat/chat.less';
@import './chat/damage-summary.less';
@import './chat/downtime.less';
@import './chat/effect-summary.less';
@import './chat/refresh-message.less';
@import './chat/sheet.less';

View file

@ -266,7 +266,8 @@
"dualityRoll": {},
"adversaryRoll": {},
"damageRoll": {},
"abilityUse": {}
"abilityUse": {},
"systemMessage": {}
}
},
"background": "systems/daggerheart/assets/logos/FoundrybornBackgroundLogo.png",

View file

@ -7,7 +7,11 @@
<label>{{localize "DAGGERHEART.SETTINGS.Automation.FIELDS.hopeFear.label"}}</label>
{{formGroup settingFields.schema.fields.hopeFear.fields.gm value=settingFields._source.hopeFear.gm localize=true}}
{{formGroup settingFields.schema.fields.hopeFear.fields.players value=settingFields._source.hopeFear.players localize=true}}
</div>
<div class="form-group setting-two-values">
<label>{{localize "DAGGERHEART.SETTINGS.Automation.FIELDS.summaryMessages.label"}}</label>
{{formGroup settingFields.schema.fields.summaryMessages.fields.damage value=settingFields._source.summaryMessages.damage localize=true}}
{{formGroup settingFields.schema.fields.summaryMessages.fields.effects value=settingFields._source.summaryMessages.effects localize=true}}
</div>
{{formGroup settingFields.schema.fields.actionPoints value=settingFields._source.actionPoints localize=true}}
{{formGroup settingFields.schema.fields.hordeDamage value=settingFields._source.hordeDamage localize=true}}

View file

@ -0,0 +1,33 @@
<ul class="daggerheart chat damage-summary">
{{#each targets}}
<li class="token-target-container" data-token="{{this.token.id}}">
<header>
<img src="{{this.token.texture.src}}" />
<h2 class="actor-name">{{this.token.name}}</h2>
</header>
<ul class="damage-container">
{{#each this.updates}}
<li class="damage-row">
{{#if (gte this.value 0)}}
<span>
{{
localize "DAGGERHEART.UI.Chat.markResource"
quantity=this.value
resource=(localize (concat "DAGGERHEART.CONFIG.HealingType." this.key ".name"))
}}
</span>
{{else}}
<span>
{{
localize "DAGGERHEART.UI.Chat.clearResource"
quantity=(positive this.value)
resource=(localize (concat "DAGGERHEART.CONFIG.HealingType." this.key ".name"))
}}
</span>
{{/if}}
</li>
{{/each}}
</ul>
</li>
{{/each}}
</ul>

View file

@ -0,0 +1,33 @@
<div class="daggerheart chat effect-summary">
<div class="effect-header">
<span>{{localize "DAGGERHEART.GENERAL.Effect.plural"}}</span>
</div>
<div class="effects-container">
{{#each effects}}
<details class="effect-target-container">
<summary class="effect-label">
<img class="effect-img" src="{{this.img}}" />
<h2 class="title">{{this.name}}</h2>
<i class="fa-solid fa-chevron-down"></i>
</summary>
<div class="description">
{{{this.description}}}
</div>
</details>
{{/each}}
</div>
{{#if targets}}
<div class="actor-header">
<span>{{localize "DAGGERHEART.UI.Chat.appliedTo"}}</span>
</div>
<div class="targets-container">
{{#each targets}}
<div class="token-target-container" data-token="{{this.id}}">
<img src="{{this.texture.src}}" />
<h2 class="title">{{this.name}}</h2>
</div>
{{/each}}
</div>
{{/if}}
</div>