Few fixes

This commit is contained in:
Dapoolp 2025-06-25 12:01:23 +02:00
parent 1bd2bbd02d
commit aacaf516b2
8 changed files with 50 additions and 39 deletions

View file

@ -412,8 +412,8 @@ export class DamageRoll extends DHRoll {
static async postEvaluate(roll, config = {}) {
config.roll = {
result: roll.total,
dice: roll.dice
dice: roll.dice,
type: config.type
};
if (roll.healing) config.roll.type = roll.healing.type;
}
}

View file

@ -68,8 +68,8 @@ export const damageTypes = {
};
export const healingTypes = {
health: {
id: 'health',
hitPoints: {
id: 'hitPoints',
label: 'DAGGERHEART.HealingType.HitPoints.Name',
abbreviation: 'DAGGERHEART.HealingType.HitPoints.Abbreviation'
},

View file

@ -126,7 +126,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
choices: SYSTEM.GENERAL.healingTypes,
required: true,
blank: false,
initial: SYSTEM.GENERAL.healingTypes.health.id,
initial: SYSTEM.GENERAL.healingTypes.hitPoints.id,
label: 'Healing'
}),
value: new fields.EmbeddedDataField(DHActionDiceData)
@ -516,7 +516,8 @@ export class DHHealingAction extends DHBaseAction {
img: x.img,
hit: true
})),
messageTemplate: 'systems/daggerheart/templates/chat/healing-roll.hbs'
messageTemplate: 'systems/daggerheart/templates/chat/healing-roll.hbs',
type: this.healing.type
};
roll = CONFIG.Dice.daggerheart.DamageRoll.build(config);

View file

@ -1,3 +1,5 @@
import { actionsTypes } from '../action/_module.mjs';
/**
* Describes metadata about the item data model type
* @typedef {Object} ItemDataModelMetadata
@ -50,4 +52,24 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
const data = { ...actorRollData, item: { ...this } };
return data;
}
async _preCreate(data, options, user) {
if(!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return;
const actionType = {
weapon: 'attack'
}[this.constructor.metadata.type],
cls = actionsTypes.attack,
action = new cls(
{
_id: foundry.utils.randomID(),
type: actionType,
name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType].name),
...cls.getSourceConfig(this.parent)
},
{
parent: this.parent
}
);
this.updateSource({actions: [action]});
}
}

View file

@ -14,7 +14,8 @@ export default class DHWeapon extends BaseDataItem {
isQuantifiable: true,
embedded: {
feature: 'featureTest'
}
},
hasInitialAction: true
});
}
@ -51,24 +52,6 @@ export default class DHWeapon extends BaseDataItem {
};
}
async _preCreate(data, options, user) {
const actionType = 'attack',
cls = actionsTypes.attack,
action = new cls(
{
_id: foundry.utils.randomID(),
type: actionType,
name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType].name),
...cls.getSourceConfig(this.parent)
},
{
parent: this.parent
}
);
this.updateSource({actions: [action]});
return super._preCreate(data, options, user);
}
async _preUpdate(changes, options, user) {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;

View file

@ -401,22 +401,27 @@ export default class DhpActor extends Actor {
}
}
async takeHealing(resources) {
resources.forEach(r => r.value *= -1);
await this.modifyResource(resources);
}
async modifyResource(resources) {
if (!resources.length) return;
let updates = { actor: { target: this, resources: {} }, armor: { target: this.system.armor, resources: {} } };
resources.forEach(r => {
switch (r.type) {
case 'armorStack':
updates.armor.resources['system.marks.value'] = Math.min(
updates.armor.resources['system.marks.value'] = Math.max(Math.min(
this.system.armor.system.marks.value + r.value,
this.system.armorScore
);
), 0);
break;
default:
updates.actor.resources[`system.resources.${r.type}.value`] = Math.min(
updates.actor.resources[`system.resources.${r.type}.value`] = Math.max(Math.min(
this.system.resources[r.type].value + r.value,
this.system.resources[r.type].max
);
), 0);
break;
}
});

View file

@ -33,7 +33,9 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
html.querySelectorAll('.damage-button').forEach(element =>
element.addEventListener('click', event => this.onDamage(event, data.message))
);
html.querySelectorAll('.healing-button').forEach(element => element.addEventListener('click', this.onHealing));
html.querySelectorAll('.healing-button').forEach(element =>
element.addEventListener('click', event => this.onHealing(event, data.message))
);
html.querySelectorAll('.target-indicator').forEach(element =>
element.addEventListener('click', this.onToggleTargets)
);
@ -87,7 +89,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
onRollHealing = async (event, message) => {
event.stopPropagation();
const actor = this.getActor(message.system.source.actor);
const actor = await this.getActor(message.system.source.actor);
if (!actor || !game.user.isGM) return true;
if (message.system.source.item && message.system.source.action) {
const action = this.getAction(actor, message.system.source.item, message.system.source.action);
@ -98,7 +100,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
onApplyEffect = async (event, message) => {
event.stopPropagation();
const actor = this.getActor(message.system.source.actor);
const actor = await this.getActor(message.system.source.actor);
if (!actor || !game.user.isGM) return true;
if (message.system.source.item && message.system.source.action) {
const action = this.getAction(actor, message.system.source.item, message.system.source.action);
@ -137,22 +139,20 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
if (targets.length === 0)
ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected'));
for (var target of targets) {
await target.actor.takeDamage(message.system.damage.total, message.system.damage.type);
await target.actor.takeDamage(message.system.roll.result, message.system.roll.type);
}
};
onHealing = async event => {
onHealing = async (event, message) => {
event.stopPropagation();
const healing = Number.parseInt(event.currentTarget.dataset.value);
const targets = Array.from(game.user.targets);
if (targets.length === 0)
ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected'));
for (var target of targets) {
await target.actor.modifyResource([{ value: healing, type: event.currentTarget.dataset.type }]);
await target.actor.takeHealing([{ value: message.system.roll.result, type: message.system.roll.type }]);
}
};

View file

@ -24,7 +24,7 @@
</div>
<div class="dice-total">{{roll.result}}</div>
<div class="flexrow">
<button class="healing-button" data-value="{{roll.result}}" data-type="{{roll.type}}"><span>{{localize "DAGGERHEART.Chat.HealingRoll.Heal"}}</span></button>
<button class="healing-button"><span>{{localize "DAGGERHEART.Chat.HealingRoll.Heal"}}</span></button>
</div>
</div>
</div>