mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
* Updated the background image for the system * Fixed so Weapon/Armor features are added again * Fixed so fear is available as a resource to be deducted by actions (#757) * Changed to use the config labels and src * Updated Weapons * Fixed so the decrease button of simple fear tracker is not visible when not hovered * Fixed so armor preUpdate doesn't fail if no system changes are made * Updated .gitignore and author details (#777) * Add author details and name mapping for chrisryan10 (#773) Co-authored-by: Chris Ryan <chrisr@blackhole> * Add build to ignore for my linux dev (#775) Co-authored-by: Chris Ryan <chrisr@blackhole> --------- Co-authored-by: Chris Ryan <chrisr@blackhole> * Corrected sneak attack active effect (#780) * Fixed a spelling error (#779) * Fix bardic rally showing in damage dialog when it should not (#783) * update spelling (#786) * Translating inventory descriptions (#782) * updated credits for 1.0.1 release (#797) * updated credits for 1.0.1 release * further updated artwork credits * Chagned handlebarhelper rollparsed to be more defensive (#794) * Added missing scene refreshType (#790) * Remove ability use buttons for not owned abilities (#795) * [Fix] PrayerDice Fixed (#799) * Fixed prayer dice, and wheelchair images * Fixed -settings data sources * Dragging features from one adversary to another (#788) * [Fix] Levelup Fixes (#787) * Fixed crash on experience selection. Fixed subclass error on multiclassing * Fixed so multiclasses do not gain the hope feature for the class * Fixed so Class/Subclass features are properly deleted on delevel * Removed automatic deletion of features on delevel when not using levelup auto * Fixed so custom domains can be selected in levelup when multiclassing * Changed so encounter countdowns is a button (#804) * Fixed so that dropping on class/subclass...creates the item on the character (#803) * [BUG] - Importing All Adversaries/Environments (#814) Fixes #774 Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * Bug/671 reaction roll chat title (#809) * Update Reaction Roll Chat Message Title * Removed console log --------- Co-authored-by: WBHarry <williambjrklund@gmail.com> * Improve Trait tooltip display (#817) Fixes #806 Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * [BUG] - Combat Tracker d12 logo not found (#812) Fixes #764 Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * Compendium Browser (#821) * Corrected timbending description localization (#816) * [Fix] Compendium Item (#810) * Corrected Emberwoven Armor * Fixed subclass regression * Fixed so character's with wildcard images don't break beastform (#815) * Fix roll result based duality damage (#822) --------- Co-authored-by: Chris Ryan <73275196+chrisryan10@users.noreply.github.com> Co-authored-by: Chris Ryan <chrisr@blackhole> Co-authored-by: Dapoulp <74197441+Dapoulp@users.noreply.github.com> Co-authored-by: IrkTheImp <41175833+IrkTheImp@users.noreply.github.com> Co-authored-by: CPTN_Cosmo <cptncosmo@gmail.com> Co-authored-by: Josh Q. <jshqntnr13@gmail.com> Co-authored-by: joaquinpereyra98 <24190917+joaquinpereyra98@users.noreply.github.com> Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com>
204 lines
7.6 KiB
JavaScript
204 lines
7.6 KiB
JavaScript
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|
targetHook = null;
|
|
targetSelection = null;
|
|
|
|
async renderHTML() {
|
|
const actor = game.actors.get(this.speaker.actor);
|
|
const actorData =
|
|
actor && this.isContentVisible
|
|
? actor
|
|
: {
|
|
img: this.author.avatar ? this.author.avatar : 'icons/svg/mystery-man.svg',
|
|
name: ''
|
|
};
|
|
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
|
|
const html = await super.renderHTML({ actor: actorData, author: this.author });
|
|
|
|
this.enrichChatMessage(html);
|
|
this.addChatListeners(html);
|
|
|
|
return html;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @inheritDoc */
|
|
prepareData() {
|
|
if (this.isAuthor && this.targetSelection === null) this.targetSelection = this.system.targets?.length > 0;
|
|
super.prepareData();
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @inheritDoc */
|
|
_onCreate(data, options, userId) {
|
|
super._onCreate(data, options, userId);
|
|
if (this.system.registerTargetHook) this.system.registerTargetHook();
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @inheritDoc */
|
|
async _preDelete(options, user) {
|
|
if (this.targetHook !== null) Hooks.off('targetToken', this.targetHook);
|
|
return super._preDelete(options, user);
|
|
}
|
|
|
|
enrichChatMessage(html) {
|
|
const elements = html.querySelectorAll('[data-perm-id]');
|
|
elements.forEach(e => {
|
|
const uuid = e.dataset.permId,
|
|
document = fromUuidSync(uuid);
|
|
if (!document) return;
|
|
|
|
e.setAttribute('data-view-perm', document.testUserPermission(game.user, 'OBSERVER'));
|
|
e.setAttribute('data-use-perm', document.testUserPermission(game.user, 'OWNER'));
|
|
});
|
|
|
|
if (this.isContentVisible && this.type === 'dualityRoll') {
|
|
html.classList.add('duality');
|
|
switch (this.system.roll?.result?.duality) {
|
|
case 1:
|
|
html.classList.add('hope');
|
|
break;
|
|
case -1:
|
|
html.classList.add('fear');
|
|
break;
|
|
default:
|
|
html.classList.add('critical');
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(!game.user.isGM && !this.isAuthor && !this.speakerActor?.isOwner) {
|
|
const buttons = html.querySelectorAll(".ability-card-footer > .ability-use-button");
|
|
buttons.forEach(b => b.remove());
|
|
}
|
|
}
|
|
|
|
addChatListeners(html) {
|
|
html.querySelectorAll('.damage-button').forEach(element =>
|
|
element.addEventListener('click', this.onDamage.bind(this))
|
|
);
|
|
|
|
html.querySelectorAll('.duality-action-effect').forEach(element =>
|
|
element.addEventListener('click', this.onApplyEffect.bind(this))
|
|
);
|
|
|
|
html.querySelectorAll('.roll-target').forEach(element => {
|
|
element.addEventListener('mouseenter', this.hoverTarget);
|
|
element.addEventListener('mouseleave', this.unhoverTarget);
|
|
element.addEventListener('click', this.clickTarget);
|
|
});
|
|
|
|
html.querySelectorAll('.button-target-selection').forEach(element => {
|
|
element.addEventListener('click', this.onTargetSelection.bind(this));
|
|
});
|
|
}
|
|
|
|
getTargetList() {
|
|
const targets = this.system.hitTargets ?? [];
|
|
return targets.map(target => game.canvas.tokens.documentCollection.find(t => t.actor?.uuid === target.actorId));
|
|
}
|
|
|
|
async onDamage(event) {
|
|
event.stopPropagation();
|
|
const targets = this.getTargetList();
|
|
|
|
if (this.system.onSave) {
|
|
const pendingingSaves = this.system.hitTargets.filter(t => t.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>`
|
|
});
|
|
if (!confirm) return;
|
|
}
|
|
}
|
|
|
|
if (targets.length === 0)
|
|
return ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noTargetsSelected'));
|
|
|
|
for (let target of targets) {
|
|
let damages = foundry.utils.deepClone(this.system.damage);
|
|
if (
|
|
!this.system.hasHealing &&
|
|
this.system.onSave &&
|
|
this.system.hitTargets.find(t => t.id === target.id)?.saved?.success === true
|
|
) {
|
|
const mod = CONFIG.DH.ACTIONS.damageOnSave[this.system.onSave]?.mod ?? 1;
|
|
Object.entries(damages).forEach(([k, v]) => {
|
|
v.total = 0;
|
|
v.parts.forEach(part => {
|
|
part.total = Math.ceil(part.total * mod);
|
|
v.total += part.total;
|
|
});
|
|
});
|
|
}
|
|
|
|
this.consumeOnSuccess();
|
|
if (this.system.hasHealing) target.actor.takeHealing(damages);
|
|
else target.actor.takeDamage(damages);
|
|
}
|
|
}
|
|
|
|
getAction(actor, itemId, actionId) {
|
|
const item = actor.items.get(itemId),
|
|
action =
|
|
actor.system.attack?._id === actionId
|
|
? actor.system.attack
|
|
: item.system.attack?._id === actionId
|
|
? item.system.attack
|
|
: item?.system?.actions?.get(actionId);
|
|
return action;
|
|
}
|
|
|
|
async onApplyEffect(event) {
|
|
event.stopPropagation();
|
|
const actor = await foundry.utils.fromUuid(this.system.source.actor);
|
|
if (!actor || !game.user.isGM) return true;
|
|
if (this.system.source.item && this.system.source.action) {
|
|
const action = this.getAction(actor, this.system.source.item, this.system.source.action);
|
|
if (!action || !action?.applyEffects) return;
|
|
const targets = this.getTargetList();
|
|
if (targets.length === 0)
|
|
ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noTargetsSelected'));
|
|
this.consumeOnSuccess();
|
|
await action.applyEffects(event, this, targets);
|
|
}
|
|
}
|
|
|
|
consumeOnSuccess() {
|
|
if (!this.system.successConsumed && !this.targetSelection) {
|
|
const action = this.system.action;
|
|
if (action) action.consume(this.system, true);
|
|
}
|
|
}
|
|
|
|
hoverTarget(event) {
|
|
event.stopPropagation();
|
|
const token = canvas.tokens.get(event.currentTarget.dataset.token);
|
|
if (token && !token?.controlled) token._onHoverIn(event, { hoverOutOthers: true });
|
|
}
|
|
|
|
unhoverTarget(event) {
|
|
const token = canvas.tokens.get(event.currentTarget.dataset.token);
|
|
if (token && !token?.controlled) token._onHoverOut(event);
|
|
}
|
|
|
|
clickTarget(event) {
|
|
event.stopPropagation();
|
|
const token = canvas.tokens.get(event.currentTarget.dataset.token);
|
|
if (!token) {
|
|
ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.attackTargetDoesNotExist'));
|
|
return;
|
|
}
|
|
game.canvas.pan(token);
|
|
}
|
|
|
|
onTargetSelection(event) {
|
|
event.stopPropagation();
|
|
if (!event.target.classList.contains('target-selected'))
|
|
this.system.targetMode = Boolean(event.target.dataset.targetHit);
|
|
}
|
|
}
|