This commit is contained in:
Dapoolp 2025-08-19 20:43:05 +02:00
parent 1b511a587e
commit a54efaeb48
8 changed files with 160 additions and 71 deletions

View file

@ -1,3 +1,6 @@
import { abilities } from "../../../config/actorConfig.mjs";
import { emitAsGM, GMUpdateEvent } from "../../../systemRegistration/socket.mjs";
const fields = foundry.data.fields;
export default class SaveField extends fields.SchemaField {
@ -20,36 +23,95 @@ export default class SaveField extends fields.SchemaField {
}
async execute(config) {
if(!this.hasRoll) {
if(!this.hasSave) return;
if(!config.message) {
const roll = new CONFIG.Dice.daggerheart.DHRoll('');
roll._evaluated = true;
await CONFIG.Dice.daggerheart.DHRoll.toMessage(roll, config);
config.message = await CONFIG.Dice.daggerheart.DHRoll.toMessage(roll, config);
}
if(true) {
if(SaveField.getAutomation() !== CONFIG.DH.SETTINGS.actionAutomationChoices.never.id) {
SaveField.rollAllSave.call(this, config.targets, config.event, config.message);
}
}
async rollSave(actor, event, message) {
static async rollAllSave(targets, event, message) {
if(!targets) return;
targets.forEach(target => {
const actor = fromUuidSync(target.actorId);
if(actor) {
if (game.user === actor.owner)
SaveField.rollSave.call(this, actor, event, message)
.then(result =>
emitAsGM(
GMUpdateEvent.UpdateSaveMessage,
SaveField.updateSaveMessage.bind(this, result, message, target.id),
{
action: this.uuid,
message: message._id,
token: target.id,
result
}
)
);
else
actor.owner
.query('reactionRoll', {
actionId: this.uuid,
actorId: actor.uuid,
event,
message
})
.then(result => SaveField.updateSaveMessage.call(this, result, message, target.id));
}
});
}
static async rollSave(actor, event, message) {
if (!actor) return;
const title = actor.isNPC
? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
: game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
ability: game.i18n.localize(abilities[this.save.trait]?.label)
});
return actor.diceRoll({
event,
title,
roll: {
trait: this.save.trait,
difficulty: this.save.difficulty ?? this.actor?.baseSaveDifficulty,
type: 'reaction'
},
type: 'trait',
hasRoll: true,
data: actor.getRollData()
});
}),
rollConfig = {
event,
title,
roll: {
trait: this.save.trait,
difficulty: this.save.difficulty ?? this.actor?.baseSaveDifficulty,
type: 'reaction'
},
type: 'trait',
hasRoll: true,
data: actor.getRollData()
};
if(SaveField.getAutomation() == CONFIG.DH.SETTINGS.actionAutomationChoices.always.id) rollConfig.dialog = { configure: false };
return actor.diceRoll(rollConfig);
}
static updateSaveMessage(result, message, targetId) {
if (!result) return;
const updateMsg = this.updateChatMessage.bind(this, message, targetId, {
flags: {
[game.system.id]: {
reactionRolls: {
[targetId]:
{
result: result.roll.total,
success: result.roll.success
}
}
}
}
});
if (game.modules.get('dice-so-nice')?.active)
game.dice3d.waitFor3DAnimationByMessageID(result.message.id ?? result.message._id).then(() => updateMsg());
else updateMsg();
}
static getAutomation() {
return (game.user.isGM && game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).roll.save.gm) || (!game.user.isGM && game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).roll.save.players)
}
static rollSaveQuery({ actionId, actorId, event, message }) {
@ -57,7 +119,8 @@ export default class SaveField extends fields.SchemaField {
const actor = await fromUuid(actorId),
action = await fromUuid(actionId);
if (!actor || !actor?.isOwner) reject();
action.rollSave(actor, event, message).then(result => resolve(result));
SaveField.rollSave.call(action, actor, event, message)
.then(result => resolve(result));
});
}
}