mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Feature/165 action save (#231)
* Roll All Save button + Merge Attack & Roll Chat message * Fix conflicts again
This commit is contained in:
parent
b7e4169079
commit
8b834036fa
18 changed files with 369 additions and 140 deletions
|
|
@ -25,6 +25,9 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
html.querySelectorAll('.target-save-container').forEach(element =>
|
||||
element.addEventListener('click', event => this.onRollSave(event, data.message))
|
||||
);
|
||||
html.querySelectorAll('.roll-all-save-button').forEach(element =>
|
||||
element.addEventListener('click', event => this.onRollAllSave(event, data.message))
|
||||
);
|
||||
html.querySelectorAll('.duality-action-effect').forEach(element =>
|
||||
element.addEventListener('click', event => this.onApplyEffect(event, data.message))
|
||||
);
|
||||
|
|
@ -33,6 +36,9 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
element.addEventListener('mouseleave', this.unhoverTarget);
|
||||
element.addEventListener('click', this.clickTarget);
|
||||
});
|
||||
html.querySelectorAll('.button-target-selection').forEach(element => {
|
||||
element.addEventListener('click', event => this.onTargetSelection(event, data.message))
|
||||
});
|
||||
html.querySelectorAll('.damage-button').forEach(element =>
|
||||
element.addEventListener('click', event => this.onDamage(event, data.message))
|
||||
);
|
||||
|
|
@ -107,7 +113,6 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
tokenId = event.target.closest('[data-token]')?.dataset.token,
|
||||
token = game.canvas.tokens.get(tokenId);
|
||||
if (!token?.actor || !token.isOwner) return true;
|
||||
console.log(token.actor.canUserModify(game.user, 'update'));
|
||||
if (message.system.source.item && message.system.source.action) {
|
||||
const action = this.getAction(actor, message.system.source.item, message.system.source.action);
|
||||
if (!action || !action?.hasSave) return;
|
||||
|
|
@ -115,6 +120,14 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
}
|
||||
};
|
||||
|
||||
onRollAllSave = async (event, message) => {
|
||||
event.stopPropagation();
|
||||
const targets = event.target.parentElement.querySelectorAll('.target-section > [data-token] .target-save-container');
|
||||
targets.forEach((el) => {
|
||||
el.dispatchEvent(new PointerEvent("click", { shiftKey: true}))
|
||||
})
|
||||
}
|
||||
|
||||
onApplyEffect = async (event, message) => {
|
||||
event.stopPropagation();
|
||||
const actor = await this.getActor(message.system.source.actor);
|
||||
|
|
@ -122,10 +135,30 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
if (message.system.source.item && message.system.source.action) {
|
||||
const action = this.getAction(actor, message.system.source.item, message.system.source.action);
|
||||
if (!action || !action?.applyEffects) return;
|
||||
await action.applyEffects(event, message);
|
||||
const { isHit, targets } = this.getTargetList(event, message);
|
||||
if (targets.length === 0)
|
||||
ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected'));
|
||||
await action.applyEffects(event, message, targets);
|
||||
}
|
||||
};
|
||||
|
||||
onTargetSelection = async (event, message) => {
|
||||
event.stopPropagation();
|
||||
const targetSelection = Boolean(event.target.dataset.targetHit),
|
||||
msg = ui.chat.collection.get(message._id);
|
||||
if(msg.system.targetSelection === targetSelection) return;
|
||||
if(targetSelection !== true && !Array.from(game.user.targets).length) return ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected'));
|
||||
msg.system.targetSelection = targetSelection;
|
||||
msg.system.prepareDerivedData();
|
||||
ui.chat.updateMessage(msg);
|
||||
}
|
||||
|
||||
getTargetList = (event, message) => {
|
||||
const targetSelection = event.target.closest('.message-content').querySelector('.button-target-selection.target-selected'),
|
||||
isHit = Boolean(targetSelection.dataset.targetHit);
|
||||
return {isHit, targets: isHit ? message.system.targets.filter(t => t.hit === true).map(target => game.canvas.tokens.get(target.id)) : Array.from(game.user.targets)};
|
||||
}
|
||||
|
||||
hoverTarget = event => {
|
||||
event.stopPropagation();
|
||||
const token = canvas.tokens.get(event.currentTarget.dataset.token);
|
||||
|
|
@ -150,15 +183,11 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
|
||||
onDamage = async (event, message) => {
|
||||
event.stopPropagation();
|
||||
const targets = event.currentTarget.dataset.targetHit
|
||||
? message.system.targets.map(target => game.canvas.tokens.get(target.id))
|
||||
: Array.from(game.user.targets);
|
||||
const { isHit, targets } = this.getTargetList(event, message);
|
||||
|
||||
if (message.system.onSave && event.currentTarget.dataset.targetHit) {
|
||||
const pendingingSaves = message.system.targets.filter(
|
||||
target => target.hit && target.saved.success === null
|
||||
);
|
||||
if (pendingingSaves.length) {
|
||||
if(message.system.onSave && isHit) {
|
||||
const pendingingSaves = message.system.targets.filter(target => target.hit && target.saved.success === null);
|
||||
if(pendingingSaves.length) {
|
||||
const confirm = await foundry.applications.api.DialogV2.confirm({
|
||||
window: { title: 'Pending Reaction Rolls found' },
|
||||
content: `<p>Some Tokens still need to roll their Reaction Roll.</p><p>Are you sure you want to continue ?</p><p><i>Undone reaction rolls will be considered as failed</i></p>`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue