mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-22 02:19:54 +02:00
Merge branch 'main' into feature/granular-action-outcomes
This commit is contained in:
commit
2e9dede678
207 changed files with 2666 additions and 1798 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import { abilities } from '../../config/actorConfig.mjs';
|
||||
import { burden } from '../../config/generalConfig.mjs';
|
||||
import { createEmbeddedItemsWithEffects, createEmbeddedItemWithEffects } from '../../helpers/utils.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
|
|
@ -154,8 +153,8 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
v.active = this.tabGroups[v.group]
|
||||
? this.tabGroups[v.group] === v.id
|
||||
: this.tabGroups.primary !== 'equipment'
|
||||
? v.active
|
||||
: false;
|
||||
? v.active
|
||||
: false;
|
||||
v.cssClass = v.active ? 'active' : '';
|
||||
|
||||
switch (v.id) {
|
||||
|
|
@ -211,9 +210,9 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
|
||||
context.suggestedTraits = this.setup.class.system
|
||||
? Object.keys(this.setup.class.system.characterGuide.suggestedTraits).map(traitKey => {
|
||||
const trait = this.setup.class.system.characterGuide.suggestedTraits[traitKey];
|
||||
return `${game.i18n.localize(`DAGGERHEART.CONFIG.Traits.${traitKey}.short`)} ${trait > 0 ? `+${trait}` : trait}`;
|
||||
})
|
||||
const trait = this.setup.class.system.characterGuide.suggestedTraits[traitKey];
|
||||
return `${game.i18n.localize(`DAGGERHEART.CONFIG.Traits.${traitKey}.short`)} ${trait > 0 ? `+${trait}` : trait}`;
|
||||
})
|
||||
: [];
|
||||
context.traits = {
|
||||
values: Object.keys(this.setup.traits).map(traitKey => {
|
||||
|
|
@ -441,16 +440,15 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
|
||||
if (type === 'subclasses') {
|
||||
const classItem = this.setup.class;
|
||||
const uuid = classItem?._stats.compendiumSource ?? classItem?.uuid;
|
||||
presets.filter = {
|
||||
'system.linkedClass': { key: 'system.linkedClass', value: uuid }
|
||||
'system.linkedClass': { key: 'system.linkedClass', value: classItem?.sourceUuid }
|
||||
};
|
||||
}
|
||||
|
||||
if (equipment.includes(type))
|
||||
presets.filter = {
|
||||
'system.tier': { key: 'system.tier', value: 1 },
|
||||
'type': { key: 'type', value: type }
|
||||
type: { key: 'type', value: type }
|
||||
};
|
||||
|
||||
ui.compendiumBrowser.open(presets);
|
||||
|
|
@ -524,37 +522,52 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
}
|
||||
};
|
||||
|
||||
await createEmbeddedItemWithEffects(this.character, ancestry);
|
||||
await createEmbeddedItemWithEffects(this.character, this.setup.community);
|
||||
await createEmbeddedItemWithEffects(this.character, this.setup.class);
|
||||
await createEmbeddedItemWithEffects(this.character, this.setup.subclass);
|
||||
await createEmbeddedItemsWithEffects(this.character, Object.values(this.setup.domainCards));
|
||||
// Inner function to create the base item data
|
||||
async function createEmbeddedItemData(baseData) {
|
||||
const uuid = baseData.uuid ?? baseData._uuid
|
||||
const data = baseData instanceof Item ? baseData : await foundry.utils.fromUuid(baseData.uuid) ?? baseData;
|
||||
return {
|
||||
...baseData,
|
||||
id: data.id,
|
||||
uuid: uuid,
|
||||
_uuid: uuid,
|
||||
effects: data.effects?.map(effect => effect.toObject()),
|
||||
flags: baseData.flags ?? data.flags,
|
||||
_stats: {
|
||||
...data._stats,
|
||||
compendiumSource: uuid.startsWith('Compendium.') ? uuid : null,
|
||||
duplicateSource: uuid && !uuid.startsWith('Compendium.') ? uuid : null
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Add the class first. All other items validate it during pre creation
|
||||
await this.character.createEmbeddedDocuments('Item', [await createEmbeddedItemData(this.setup.class)]);
|
||||
|
||||
// Add the remaining items
|
||||
const newItems = [
|
||||
await createEmbeddedItemData(ancestry),
|
||||
await createEmbeddedItemData(this.setup.community),
|
||||
await createEmbeddedItemData(this.setup.subclass),
|
||||
...(await Promise.all(
|
||||
Object.values(this.setup.domainCards).map(d => createEmbeddedItemData(d))
|
||||
))
|
||||
];
|
||||
if (this.equipment.armor.uuid)
|
||||
await createEmbeddedItemWithEffects(this.character, this.equipment.armor, {
|
||||
...this.equipment.armor,
|
||||
system: { ...this.equipment.armor.system, equipped: true }
|
||||
});
|
||||
newItems.push(await createEmbeddedItemData(this.equipment.armor));
|
||||
if (this.equipment.primaryWeapon.uuid)
|
||||
await createEmbeddedItemWithEffects(this.character, this.equipment.primaryWeapon, {
|
||||
...this.equipment.primaryWeapon,
|
||||
system: { ...this.equipment.primaryWeapon.system, equipped: true }
|
||||
});
|
||||
newItems.push(await createEmbeddedItemData(this.equipment.primaryWeapon));
|
||||
if (this.equipment.secondaryWeapon.uuid)
|
||||
await createEmbeddedItemWithEffects(this.character, this.equipment.secondaryWeapon, {
|
||||
...this.equipment.secondaryWeapon,
|
||||
system: { ...this.equipment.secondaryWeapon.system, equipped: true }
|
||||
});
|
||||
newItems.push(await createEmbeddedItemData(this.equipment.secondaryWeapon));
|
||||
if (this.equipment.inventory.choiceA.uuid)
|
||||
await createEmbeddedItemWithEffects(this.character, this.equipment.inventory.choiceA);
|
||||
newItems.push(await createEmbeddedItemData(this.equipment.inventory.choiceA));
|
||||
if (this.equipment.inventory.choiceB.uuid)
|
||||
await createEmbeddedItemWithEffects(this.character, this.equipment.inventory.choiceB);
|
||||
|
||||
await createEmbeddedItemsWithEffects(
|
||||
this.character,
|
||||
this.setup.class.system.inventory.take.filter(x => x)
|
||||
);
|
||||
newItems.push(await createEmbeddedItemData(this.equipment.inventory.choiceB));
|
||||
for (const item of this.setup.class.system.inventory.take.filter(x => x)) {
|
||||
newItems.push(await createEmbeddedItemData(item));
|
||||
}
|
||||
|
||||
await this.character.createEmbeddedDocuments('Item', newItems);
|
||||
await this.character.update(
|
||||
{
|
||||
system: {
|
||||
|
|
@ -587,26 +600,14 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
const item = await foundry.utils.fromUuid(data.uuid);
|
||||
if (item.type === 'ancestry' && event.target.closest('.primary-ancestry-card')) {
|
||||
this.setup.ancestryName.primary = item.name;
|
||||
this.setup.primaryAncestry = {
|
||||
...item,
|
||||
effects: Array.from(item.effects).map(x => x.toObject()),
|
||||
uuid: item.uuid
|
||||
};
|
||||
this.setup.primaryAncestry = item;
|
||||
} else if (item.type === 'ancestry' && event.target.closest('.secondary-ancestry-card')) {
|
||||
this.setup.ancestryName.secondary = item.name;
|
||||
this.setup.secondaryAncestry = {
|
||||
...item,
|
||||
effects: Array.from(item.effects).map(x => x.toObject()),
|
||||
uuid: item.uuid
|
||||
};
|
||||
this.setup.secondaryAncestry = item;
|
||||
} else if (item.type === 'community' && event.target.closest('.community-card')) {
|
||||
this.setup.community = {
|
||||
...item,
|
||||
effects: Array.from(item.effects).map(x => x.toObject()),
|
||||
uuid: item.uuid
|
||||
};
|
||||
this.setup.community = item;
|
||||
} else if (item.type === 'class' && event.target.closest('.class-card')) {
|
||||
this.setup.class = { ...item, effects: Array.from(item.effects).map(x => x.toObject()), uuid: item.uuid };
|
||||
this.setup.class = item;
|
||||
this.setup.subclass = {};
|
||||
this.setup.domainCards = {
|
||||
[foundry.utils.randomID()]: {},
|
||||
|
|
@ -619,11 +620,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
return;
|
||||
}
|
||||
|
||||
this.setup.subclass = {
|
||||
...item,
|
||||
effects: Array.from(item.effects).map(x => x.toObject()),
|
||||
uuid: item.uuid
|
||||
};
|
||||
this.setup.subclass = item;
|
||||
} else if (item.type === 'domainCard' && event.target.closest('.domain-card')) {
|
||||
if (!this.setup.class.uuid) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.missingClass'));
|
||||
|
|
@ -645,14 +642,14 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
return;
|
||||
}
|
||||
|
||||
this.setup.domainCards[event.target.closest('.domain-card').dataset.card] = { ...item, uuid: item.uuid };
|
||||
this.setup.domainCards[event.target.closest('.domain-card').dataset.card] = item;
|
||||
} else if (item.type === 'armor' && event.target.closest('.armor-card')) {
|
||||
if (item.system.tier > 1) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.itemTooHighTier'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.equipment.armor = { ...item, uuid: item.uuid };
|
||||
this.equipment.armor = item;
|
||||
} else if (item.type === 'weapon' && event.target.closest('.primary-weapon-card')) {
|
||||
if (item.system.secondary) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.notPrimary'));
|
||||
|
|
@ -668,7 +665,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
this.equipment.secondaryWeapon = {};
|
||||
}
|
||||
|
||||
this.equipment.primaryWeapon = { ...item, uuid: item.uuid };
|
||||
this.equipment.primaryWeapon = item;
|
||||
} else if (item.type === 'weapon' && event.target.closest('.secondary-weapon-card')) {
|
||||
if (this.equipment.primaryWeapon?.system?.burden === burden.twoHanded.value) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.primaryIsTwoHanded'));
|
||||
|
|
@ -685,7 +682,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
return;
|
||||
}
|
||||
|
||||
this.equipment.secondaryWeapon = { ...item, uuid: item.uuid };
|
||||
this.equipment.secondaryWeapon = item;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
}
|
||||
if (rest.hasOwnProperty('trait')) {
|
||||
this.config.roll.trait = rest.trait;
|
||||
if (!this.config.source.item)
|
||||
if (!this.config.source.item && this.config.roll.trait)
|
||||
this.config.title = game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
||||
ability: game.i18n.localize(abilities[this.config.roll.trait]?.label)
|
||||
});
|
||||
|
|
@ -196,14 +196,14 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
this.config.costs.indexOf(this.config.costs.find(c => c.extKey === button.dataset.key)) > -1
|
||||
? this.config.costs.filter(x => x.extKey !== button.dataset.key)
|
||||
: [
|
||||
...this.config.costs,
|
||||
{
|
||||
extKey: button.dataset.key,
|
||||
key: this.config?.data?.parent?.isNPC ? 'fear' : 'hope',
|
||||
value: 1,
|
||||
name: this.config.data?.system.experiences?.[button.dataset.key]?.name
|
||||
}
|
||||
];
|
||||
...this.config.costs,
|
||||
{
|
||||
extKey: button.dataset.key,
|
||||
key: this.config?.data?.parent?.isNPC ? 'fear' : 'hope',
|
||||
value: 1,
|
||||
name: this.config.data?.system.experiences?.[button.dataset.key]?.name
|
||||
}
|
||||
];
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
@ -213,8 +213,8 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
this.config.actionType = this.reactionOverride
|
||||
? 'reaction'
|
||||
: this.config.actionType === 'reaction'
|
||||
? 'action'
|
||||
: this.config.actionType;
|
||||
? 'action'
|
||||
: this.config.actionType;
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async submitRoll() {
|
||||
static async submitRoll(event) {
|
||||
await this.close({ submitted: true });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,13 +138,13 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
|
|||
const stressReductionStress = this.availableStressReductions
|
||||
? stressReductions.reduce((acc, red) => acc + red.cost, 0)
|
||||
: 0;
|
||||
const stress = this.actor.system.resources.stress;
|
||||
context.stress =
|
||||
selectedStressMarks.length > 0 || this.availableStressReductions
|
||||
? {
|
||||
value:
|
||||
this.actor.system.resources.stress.value + selectedStressMarks.length + stressReductionStress,
|
||||
max: this.actor.system.resources.stress.max
|
||||
}
|
||||
value: stress.value + selectedStressMarks.length + stressReductionStress,
|
||||
max: stress.max
|
||||
}
|
||||
: null;
|
||||
|
||||
context.maxArmorUsed = maxArmorUsed;
|
||||
|
|
@ -176,7 +176,6 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
|
|||
}
|
||||
|
||||
static updateData(event, _, formData) {
|
||||
const form = foundry.utils.expandObject(formData.object);
|
||||
this.render(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -259,10 +259,10 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
|||
const resetValue = increasing
|
||||
? 0
|
||||
: feature.system.resource.max
|
||||
? new Roll(
|
||||
? new Roll(
|
||||
Roll.replaceFormulaData(feature.system.resource.max, this.actor.getRollData())
|
||||
).evaluateSync().total
|
||||
: 0;
|
||||
: 0;
|
||||
|
||||
await feature.update({ 'system.resource.value': resetValue });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { ResourceUpdateMap } from '../../data/action/baseAction.mjs';
|
||||
import { shouldUseHopeFearAutomation } from '../../helpers/utils.mjs';
|
||||
import { emitGMUpdate, GMUpdateEvent, RefreshType, socketEvent } from '../../systemRegistration/socket.mjs';
|
||||
import Party from '../sheets/actors/party.mjs';
|
||||
|
||||
|
|
@ -167,8 +168,8 @@ export default class GroupRollDialog extends HandlebarsApplicationMixin(Applicat
|
|||
partContext.groupRoll = {
|
||||
totalLabel: leader?.rollData
|
||||
? game.i18n.format('DAGGERHEART.GENERAL.withThing', {
|
||||
thing: leader.roll.totalLabel
|
||||
})
|
||||
thing: leader.roll.totalLabel
|
||||
})
|
||||
: null,
|
||||
totalDualityClass: leader?.roll?.isCritical ? 'critical' : leader?.roll?.withHope ? 'hope' : 'fear',
|
||||
total: leaderTotal + modifierTotal,
|
||||
|
|
@ -480,19 +481,22 @@ export default class GroupRollDialog extends HandlebarsApplicationMixin(Applicat
|
|||
|
||||
await cls.create(msgData);
|
||||
|
||||
const resourceMap = new ResourceUpdateMap(actor);
|
||||
if (totalRoll.isCritical) {
|
||||
resourceMap.addResources([
|
||||
{ key: 'stress', value: -1, total: 1 },
|
||||
{ key: 'hope', value: 1, total: 1 }
|
||||
]);
|
||||
} else if (totalRoll.withHope) {
|
||||
resourceMap.addResources([{ key: 'hope', value: 1, total: 1 }]);
|
||||
} else {
|
||||
resourceMap.addResources([{ key: 'fear', value: 1, total: 1 }]);
|
||||
}
|
||||
/* Handle resource updates for the finished GroupRoll */
|
||||
if (shouldUseHopeFearAutomation({ gmAsPlayer: true })) {
|
||||
const resourceMap = new ResourceUpdateMap(actor);
|
||||
if (totalRoll.isCritical) {
|
||||
resourceMap.addResources([
|
||||
{ key: 'stress', value: -1 },
|
||||
{ key: 'hope', value: 1 }
|
||||
]);
|
||||
} else if (totalRoll.withHope) {
|
||||
resourceMap.addResources([{ key: 'hope', value: 1 }]);
|
||||
} else {
|
||||
resourceMap.addResources([{ key: 'fear', value: 1 }]);
|
||||
}
|
||||
|
||||
resourceMap.updateResources();
|
||||
resourceMap.updateResources();
|
||||
}
|
||||
|
||||
/* Fin */
|
||||
this.cancelRoll({ confirm: false });
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ export default class ItemTransferDialog extends HandlebarsApplicationMixin(Appli
|
|||
const homebrewKey = CONFIG.DH.SETTINGS.gameSettings.Homebrew;
|
||||
const currencySetting = game.settings.get(CONFIG.DH.id, homebrewKey).currency?.[currency] ?? null;
|
||||
const max = item?.system.quantity ?? originActor.system.gold[currency] ?? 0;
|
||||
const isQuantifiable = targetActor.system.metadata.quantifiable?.includes(item?.type);
|
||||
|
||||
return {
|
||||
originActor,
|
||||
|
|
@ -46,7 +47,7 @@ export default class ItemTransferDialog extends HandlebarsApplicationMixin(Appli
|
|||
itemImage: item?.img,
|
||||
currencyIcon: currencySetting?.icon,
|
||||
max,
|
||||
initial: targetActor.system.metadata.quantifiable?.includes(item.type) ? max : 1,
|
||||
initial: isQuantifiable || !!currencySetting ? max : 1,
|
||||
title: item?.name ?? currencySetting?.label
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { ResourceUpdateMap } from '../../data/action/baseAction.mjs';
|
||||
import { MemberData } from '../../data/tagTeamData.mjs';
|
||||
import { getCritDamageBonus } from '../../helpers/utils.mjs';
|
||||
import { getCritDamageBonus, shouldUseHopeFearAutomation } from '../../helpers/utils.mjs';
|
||||
import { emitGMUpdate, GMUpdateEvent, RefreshType, socketEvent } from '../../systemRegistration/socket.mjs';
|
||||
import Party from '../sheets/actors/party.mjs';
|
||||
|
||||
|
|
@ -9,6 +10,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
constructor(party) {
|
||||
super({ id: `TagTeamDialog-${party.id}` });
|
||||
|
||||
this.usesTagTeamHopeCost = true;
|
||||
this.party = party;
|
||||
this.partyMembers = party.system.partyMembers
|
||||
.filter(x => Party.DICE_ROLL_ACTOR_TYPES.includes(x.type))
|
||||
|
|
@ -20,7 +22,9 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
owned: member.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)
|
||||
}));
|
||||
|
||||
this.initiator = { cost: 3 };
|
||||
this.initiator = { cost:
|
||||
this.party.system.schema.fields.tagTeam.fields.initiator.fields.cost.initial
|
||||
};
|
||||
this.openForAllPlayers = true;
|
||||
|
||||
this.tabGroups.application = Object.keys(party.system.tagTeam.members).length
|
||||
|
|
@ -94,9 +98,13 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
?.addEventListener('input', this.updateInitiatorMemberField.bind(this));
|
||||
|
||||
htmlElement
|
||||
.querySelector('.initiator-cost-field')
|
||||
.querySelector('.initiator-cost-input')
|
||||
?.addEventListener('input', this.updateInitiatorCostField.bind(this));
|
||||
|
||||
htmlElement
|
||||
.querySelector('.initiator-cost-enabled-checkbox')
|
||||
?.addEventListener('change', this.toggleInitiatorCostEnabled.bind(this));
|
||||
|
||||
htmlElement
|
||||
.querySelector('.openforall-field')
|
||||
?.addEventListener('change', this.updateOpenForAllField.bind(this));
|
||||
|
|
@ -156,6 +164,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
.map(x => ({ value: x.id, label: x.name }));
|
||||
partContext.initiatorDisabled = !selectedMembers.length;
|
||||
partContext.openForAllPlayers = this.openForAllPlayers;
|
||||
partContext.usesTagTeamHopeCost = this.usesTagTeamHopeCost;
|
||||
|
||||
break;
|
||||
case 'tagTeamRoll':
|
||||
|
|
@ -397,6 +406,13 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
this.render();
|
||||
}
|
||||
|
||||
toggleInitiatorCostEnabled(_event) {
|
||||
this.usesTagTeamHopeCost = !this.usesTagTeamHopeCost;
|
||||
this.initiator.cost = this.usesTagTeamHopeCost ?
|
||||
this.party.system.schema.fields.tagTeam.fields.initiator.fields.cost.initial : 0;
|
||||
this.render();
|
||||
}
|
||||
|
||||
updateOpenForAllField(event) {
|
||||
this.openForAllPlayers = event.target.checked;
|
||||
this.render();
|
||||
|
|
@ -653,8 +669,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
const baseSecondaryRoll = selectedRoll
|
||||
? memberValues.find(x => !x.selected)
|
||||
: memberValues.length > 1
|
||||
? memberValues[1]
|
||||
: null;
|
||||
? memberValues[1]
|
||||
: null;
|
||||
|
||||
if (!baseMainRoll?.rollData || !baseSecondaryRoll) return null;
|
||||
|
||||
|
|
@ -752,32 +768,37 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
|
||||
/* Handle resource updates from the finished TagTeamRoll */
|
||||
const tagTeamData = this.party.system.tagTeam;
|
||||
const fearUpdate = { key: 'fear', value: null, total: null, enabled: true };
|
||||
for (let memberId in tagTeamData.members) {
|
||||
const resourceUpdates = [];
|
||||
const rollGivesHope = finalRoll.isCritical || finalRoll.withHope;
|
||||
if (memberId === tagTeamData.initiator.memberId) {
|
||||
const value = tagTeamData.initiator.cost
|
||||
? rollGivesHope
|
||||
? 1 - tagTeamData.initiator.cost
|
||||
: -tagTeamData.initiator.cost
|
||||
: 1;
|
||||
resourceUpdates.push({ key: 'hope', value: value, total: -value, enabled: true });
|
||||
} else if (rollGivesHope) {
|
||||
resourceUpdates.push({ key: 'hope', value: 1, total: -1, enabled: true });
|
||||
}
|
||||
if (finalRoll.isCritical) resourceUpdates.push({ key: 'stress', value: -1, total: 1, enabled: true });
|
||||
if (finalRoll.withFear) {
|
||||
fearUpdate.value = fearUpdate.value === null ? 1 : fearUpdate.value + 1;
|
||||
fearUpdate.total = fearUpdate.total === null ? -1 : fearUpdate.total - 1;
|
||||
}
|
||||
|
||||
game.actors.get(memberId).modifyResource(resourceUpdates);
|
||||
const actorResourceMaps = Object.keys(tagTeamData.members).reduce((acc, key) => {
|
||||
acc[key] = new ResourceUpdateMap(game.actors.get(key));
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
if (shouldUseHopeFearAutomation({ gmAsPlayer: true })) {
|
||||
const fearResourceMap = actorResourceMaps[tagTeamData.initiator.memberId];
|
||||
for (const memberId in tagTeamData.members) {
|
||||
const resourceMap = actorResourceMaps[memberId];
|
||||
if (finalRoll.isCritical) {
|
||||
resourceMap.addResources([
|
||||
{ key: 'stress', value: -1, enabled: true },
|
||||
{ key: 'hope', value: 1, enabled: true }
|
||||
]);
|
||||
} else if (finalRoll.withHope) {
|
||||
resourceMap.addResources([{ key: 'hope', value: 1, enabled: true }]);
|
||||
} else if (finalRoll.withFear) {
|
||||
fearResourceMap.addResources([{ key: 'fear', value: 1, enabled: true }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Even with Hope/Fear automation off, the hope cost of performing the TagTeamRoll can still optionally be subtracted */
|
||||
if (tagTeamData.initiator.cost) {
|
||||
const resourceMap = actorResourceMaps[tagTeamData.initiator.memberId];
|
||||
resourceMap.addResources([{ key: 'hope', value: -tagTeamData.initiator.cost, enabled: true }]);
|
||||
}
|
||||
|
||||
if (fearUpdate.value) {
|
||||
mainActor.modifyResource([fearUpdate]);
|
||||
}
|
||||
for (const resourceMap of Object.values(actorResourceMaps))
|
||||
resourceMap.updateResources();
|
||||
|
||||
/* Fin */
|
||||
this.cancelRoll({ confirm: false });
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
).showGenericStatusEffects;
|
||||
context.genericStatusEffects = useGeneric
|
||||
? Object.keys(context.statusEffects).reduce((acc, key) => {
|
||||
const effect = context.statusEffects[key];
|
||||
if (!effect.systemEffect) acc[key] = effect;
|
||||
const effect = context.statusEffects[key];
|
||||
if (!effect.systemEffect) acc[key] = effect;
|
||||
|
||||
return acc;
|
||||
}, {})
|
||||
return acc;
|
||||
}, {})
|
||||
: null;
|
||||
|
||||
context.hasCompanion = this.actor.system.companion;
|
||||
|
|
@ -68,11 +68,11 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
const warning =
|
||||
tokensWithoutActors.length === 1
|
||||
? game.i18n.format('DAGGERHEART.UI.Notifications.tokenActorMissing', {
|
||||
name: tokensWithoutActors[0].name
|
||||
})
|
||||
name: tokensWithoutActors[0].name
|
||||
})
|
||||
: game.i18n.format('DAGGERHEART.UI.Notifications.tokenActorsMissing', {
|
||||
names: tokensWithoutActors.map(x => x.name).join(', ')
|
||||
});
|
||||
names: tokensWithoutActors.map(x => x.name).join(', ')
|
||||
});
|
||||
|
||||
const tokens = canvas.tokens.controlled
|
||||
.filter(t => t.actor && !DHTokenHUD.#nonCombatTypes.includes(t.actor.type))
|
||||
|
|
@ -174,8 +174,8 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
nonZeroIndex === sideMiddle
|
||||
? 0
|
||||
: nonZeroIndex < sideMiddle
|
||||
? -nonZeroIndex
|
||||
: nonZeroIndex - sideMiddle;
|
||||
? -nonZeroIndex
|
||||
: nonZeroIndex - sideMiddle;
|
||||
return { x: actorX - sizeX * distance, y: actorY - sizeY * distanceCoefficient };
|
||||
} else if (index < side + inbetween) {
|
||||
const inbetweenIndex = nonZeroIndex - side;
|
||||
|
|
@ -183,8 +183,8 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
inbetweenIndex === inbetweenMiddle
|
||||
? 0
|
||||
: inbetweenIndex < inbetweenMiddle
|
||||
? -inbetweenIndex
|
||||
: inbetweenIndex - inbetweenMiddle;
|
||||
? -inbetweenIndex
|
||||
: inbetweenIndex - inbetweenMiddle;
|
||||
return { x: actorX + sizeX * distanceCoefficient, y: actorY + sizeY * distance };
|
||||
} else if (index < 2 * side + inbetween) {
|
||||
const sideIndex = nonZeroIndex - side - inbetween;
|
||||
|
|
@ -192,8 +192,8 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
sideIndex === sideMiddle
|
||||
? 0
|
||||
: sideIndex < sideMiddle
|
||||
? sideIndex
|
||||
: -(sideIndex - sideMiddle);
|
||||
? sideIndex
|
||||
: -(sideIndex - sideMiddle);
|
||||
return { x: actorX + sizeX * distance, y: actorY + sizeY * distanceCoefficient };
|
||||
} else {
|
||||
const inbetweenIndex = nonZeroIndex - 2 * side - inbetween;
|
||||
|
|
@ -201,8 +201,8 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
inbetweenIndex === inbetweenMiddle
|
||||
? 0
|
||||
: inbetweenIndex < inbetweenMiddle
|
||||
? inbetweenIndex
|
||||
: -(inbetweenIndex - inbetweenMiddle);
|
||||
? inbetweenIndex
|
||||
: -(inbetweenIndex - inbetweenMiddle);
|
||||
return { x: actorX - sizeX * distanceCoefficient, y: actorY + sizeY * distance };
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -210,9 +210,9 @@ export default class DhCharacterLevelUp extends LevelUpBase {
|
|||
|
||||
achievementExperiences = level.achievements.experiences
|
||||
? Object.values(level.achievements.experiences).reduce((acc, experience) => {
|
||||
if (experience.name) acc.push(experience);
|
||||
return acc;
|
||||
}, [])
|
||||
if (experience.name) acc.push(experience);
|
||||
return acc;
|
||||
}, [])
|
||||
: [];
|
||||
}
|
||||
|
||||
|
|
@ -315,15 +315,15 @@ export default class DhCharacterLevelUp extends LevelUpBase {
|
|||
: null;
|
||||
advancement[choiceKey] = multiclassItem
|
||||
? {
|
||||
...multiclassItem.toObject(),
|
||||
domain: checkbox.secondaryData.domain
|
||||
? game.i18n.localize(
|
||||
CONFIG.DH.DOMAIN.allDomains()[checkbox.secondaryData.domain]
|
||||
.label
|
||||
)
|
||||
: null,
|
||||
subclass: subclass ? subclass.name : null
|
||||
}
|
||||
...multiclassItem.toObject(),
|
||||
domain: checkbox.secondaryData.domain
|
||||
? game.i18n.localize(
|
||||
CONFIG.DH.DOMAIN.allDomains()[checkbox.secondaryData.domain]
|
||||
.label
|
||||
)
|
||||
: null,
|
||||
subclass: subclass ? subclass.name : null
|
||||
}
|
||||
: {};
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,9 +77,9 @@ export default class DhCompanionLevelUp extends BaseLevelUp {
|
|||
|
||||
achievementExperiences = level.achievements.experiences
|
||||
? Object.values(level.achievements.experiences).reduce((acc, experience) => {
|
||||
if (experience.name) acc.push(experience);
|
||||
return acc;
|
||||
}, [])
|
||||
if (experience.name) acc.push(experience);
|
||||
return acc;
|
||||
}, [])
|
||||
: [];
|
||||
}
|
||||
context.achievements = {
|
||||
|
|
@ -155,15 +155,15 @@ export default class DhCompanionLevelUp extends BaseLevelUp {
|
|||
vicious: {
|
||||
damage: advancement.vicious?.damage
|
||||
? {
|
||||
old: actorDamageDice,
|
||||
new: advancement.vicious.damage
|
||||
}
|
||||
old: actorDamageDice,
|
||||
new: advancement.vicious.damage
|
||||
}
|
||||
: null,
|
||||
range: advancement.vicious?.range
|
||||
? {
|
||||
old: game.i18n.localize(`DAGGERHEART.CONFIG.Range.${actorRange}.name`),
|
||||
new: game.i18n.localize(advancement.vicious.range.label)
|
||||
}
|
||||
old: game.i18n.localize(`DAGGERHEART.CONFIG.Range.${actorRange}.name`),
|
||||
new: game.i18n.localize(advancement.vicious.range.label)
|
||||
}
|
||||
: null
|
||||
},
|
||||
simple: advancement.simple ?? {}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { abilities, subclassFeatureLabels } from '../../config/actorConfig.mjs';
|
||||
import { getDeleteKeys, tagifyElement } from '../../helpers/utils.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
|
@ -135,192 +134,6 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
|
|||
context.tabs.advancements.progress = { selected: selections, max: currentLevel.maxSelections };
|
||||
context.showTabs = this.tabGroups.primary !== 'summary';
|
||||
break;
|
||||
|
||||
const actorArmor = this.actor.system.armor;
|
||||
const levelKeys = Object.keys(this.levelup.levels);
|
||||
let achivementProficiency = 0;
|
||||
const achievementCards = [];
|
||||
let achievementExperiences = [];
|
||||
for (var levelKey of levelKeys) {
|
||||
const level = this.levelup.levels[levelKey];
|
||||
if (Number(levelKey) < this.levelup.startLevel) continue;
|
||||
|
||||
achivementProficiency += level.achievements.proficiency ?? 0;
|
||||
const cards = level.achievements.domainCards ? Object.values(level.achievements.domainCards) : null;
|
||||
if (cards) {
|
||||
for (var card of cards) {
|
||||
const itemCard = await foundry.utils.fromUuid(card.uuid);
|
||||
achievementCards.push(itemCard);
|
||||
}
|
||||
}
|
||||
|
||||
achievementExperiences = level.achievements.experiences
|
||||
? Object.values(level.achievements.experiences).reduce((acc, experience) => {
|
||||
if (experience.name) acc.push(experience);
|
||||
return acc;
|
||||
}, [])
|
||||
: [];
|
||||
}
|
||||
|
||||
context.achievements = {
|
||||
proficiency: {
|
||||
old: this.actor.system.proficiency,
|
||||
new: this.actor.system.proficiency + achivementProficiency,
|
||||
shown: achivementProficiency > 0
|
||||
},
|
||||
damageThresholds: {
|
||||
major: {
|
||||
old: this.actor.system.damageThresholds.major,
|
||||
new: this.actor.system.damageThresholds.major + changedActorLevel - currentActorLevel
|
||||
},
|
||||
severe: {
|
||||
old: this.actor.system.damageThresholds.severe,
|
||||
new:
|
||||
this.actor.system.damageThresholds.severe +
|
||||
(actorArmor
|
||||
? changedActorLevel - currentActorLevel
|
||||
: (changedActorLevel - currentActorLevel) * 2)
|
||||
},
|
||||
unarmored: !actorArmor
|
||||
},
|
||||
domainCards: {
|
||||
values: achievementCards,
|
||||
shown: achievementCards.length > 0
|
||||
},
|
||||
experiences: {
|
||||
values: achievementExperiences
|
||||
}
|
||||
};
|
||||
|
||||
const advancement = {};
|
||||
for (var levelKey of levelKeys) {
|
||||
const level = this.levelup.levels[levelKey];
|
||||
if (Number(levelKey) < this.levelup.startLevel) continue;
|
||||
|
||||
for (var choiceKey of Object.keys(level.choices)) {
|
||||
const choice = level.choices[choiceKey];
|
||||
for (var checkbox of Object.values(choice)) {
|
||||
switch (choiceKey) {
|
||||
case 'proficiency':
|
||||
case 'hitPoint':
|
||||
case 'stress':
|
||||
case 'evasion':
|
||||
advancement[choiceKey] = advancement[choiceKey]
|
||||
? advancement[choiceKey] + Number(checkbox.value)
|
||||
: Number(checkbox.value);
|
||||
break;
|
||||
case 'trait':
|
||||
if (!advancement[choiceKey]) advancement[choiceKey] = {};
|
||||
for (var traitKey of checkbox.data) {
|
||||
if (!advancement[choiceKey][traitKey]) advancement[choiceKey][traitKey] = 0;
|
||||
advancement[choiceKey][traitKey] += 1;
|
||||
}
|
||||
break;
|
||||
case 'domainCard':
|
||||
if (!advancement[choiceKey]) advancement[choiceKey] = [];
|
||||
if (checkbox.data.length === 1) {
|
||||
const choiceItem = await foundry.utils.fromUuid(checkbox.data[0]);
|
||||
advancement[choiceKey].push(choiceItem.toObject());
|
||||
}
|
||||
break;
|
||||
case 'experience':
|
||||
if (!advancement[choiceKey]) advancement[choiceKey] = [];
|
||||
const data = checkbox.data.map(data => {
|
||||
const experience = Object.keys(this.actor.system.experiences).find(
|
||||
x => x === data
|
||||
);
|
||||
return this.actor.system.experiences[experience]?.description ?? '';
|
||||
});
|
||||
advancement[choiceKey].push({ data: data, value: checkbox.value });
|
||||
break;
|
||||
case 'subclass':
|
||||
if (checkbox.data[0]) {
|
||||
const subclassItem = await foundry.utils.fromUuid(checkbox.data[0]);
|
||||
if (!advancement[choiceKey]) advancement[choiceKey] = [];
|
||||
advancement[choiceKey].push({
|
||||
...subclassItem.toObject(),
|
||||
featureLabel: game.i18n.localize(
|
||||
subclassFeatureLabels[Number(checkbox.secondaryData.featureState)]
|
||||
)
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'multiclass':
|
||||
const multiclassItem = await foundry.utils.fromUuid(checkbox.data[0]);
|
||||
const subclass = multiclassItem
|
||||
? await foundry.utils.fromUuid(checkbox.secondaryData.subclass)
|
||||
: null;
|
||||
advancement[choiceKey] = multiclassItem
|
||||
? {
|
||||
...multiclassItem.toObject(),
|
||||
domain: checkbox.secondaryData.domain
|
||||
? game.i18n.localize(
|
||||
CONFIG.DH.DOMAIN.allDomains()[checkbox.secondaryData.domain]
|
||||
.label
|
||||
)
|
||||
: null,
|
||||
subclass: subclass ? subclass.name : null
|
||||
}
|
||||
: {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.advancements = {
|
||||
statistics: {
|
||||
proficiency: {
|
||||
old: context.achievements.proficiency.new,
|
||||
new: context.achievements.proficiency.new + (advancement.proficiency ?? 0)
|
||||
},
|
||||
hitPoints: {
|
||||
old: this.actor.system.resources.hitPoints.max,
|
||||
new: this.actor.system.resources.hitPoints.max + (advancement.hitPoint ?? 0)
|
||||
},
|
||||
stress: {
|
||||
old: this.actor.system.resources.stress.max,
|
||||
new: this.actor.system.resources.stress.max + (advancement.stress ?? 0)
|
||||
},
|
||||
evasion: {
|
||||
old: this.actor.system.evasion,
|
||||
new: this.actor.system.evasion + (advancement.evasion ?? 0)
|
||||
}
|
||||
},
|
||||
traits: Object.keys(this.actor.system.traits).reduce((acc, traitKey) => {
|
||||
if (advancement.trait?.[traitKey]) {
|
||||
if (!acc) acc = {};
|
||||
acc[traitKey] = {
|
||||
label: game.i18n.localize(abilities[traitKey].label),
|
||||
old: this.actor.system.traits[traitKey].value,
|
||||
new: this.actor.system.traits[traitKey].value + advancement.trait[traitKey]
|
||||
};
|
||||
}
|
||||
return acc;
|
||||
}, null),
|
||||
domainCards: advancement.domainCard ?? [],
|
||||
experiences:
|
||||
advancement.experience?.flatMap(x => x.data.map(data => ({ name: data, modifier: x.value }))) ??
|
||||
[],
|
||||
multiclass: advancement.multiclass,
|
||||
subclass: advancement.subclass
|
||||
};
|
||||
|
||||
context.advancements.statistics.proficiency.shown =
|
||||
context.advancements.statistics.proficiency.new > context.advancements.statistics.proficiency.old;
|
||||
context.advancements.statistics.hitPoints.shown =
|
||||
context.advancements.statistics.hitPoints.new > context.advancements.statistics.hitPoints.old;
|
||||
context.advancements.statistics.stress.shown =
|
||||
context.advancements.statistics.stress.new > context.advancements.statistics.stress.old;
|
||||
context.advancements.statistics.evasion.shown =
|
||||
context.advancements.statistics.evasion.new > context.advancements.statistics.evasion.old;
|
||||
context.advancements.statistics.shown =
|
||||
context.advancements.statistics.proficiency.shown ||
|
||||
context.advancements.statistics.hitPoints.shown ||
|
||||
context.advancements.statistics.stress.shown ||
|
||||
context.advancements.statistics.evasion.shown;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return context;
|
||||
|
|
@ -358,14 +171,14 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
|
|||
const experienceIncreaseTagify = htmlElement.querySelector('.levelup-experience-increases');
|
||||
if (experienceIncreaseTagify) {
|
||||
const allExperiences = {
|
||||
...this.actor.system.experiences,
|
||||
...Object.values(this.levelup.levels).reduce((acc, level) => {
|
||||
for (const key of Object.keys(level.achievements.experiences)) {
|
||||
acc[key] = level.achievements.experiences[key];
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {})
|
||||
}, {}),
|
||||
...this.actor.system.experiences
|
||||
};
|
||||
tagifyElement(
|
||||
experienceIncreaseTagify,
|
||||
|
|
@ -384,37 +197,35 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
|
|||
this._dragDrop.forEach(d => d.bind(htmlElement));
|
||||
}
|
||||
|
||||
tagifyUpdate =
|
||||
type =>
|
||||
async (_, { option, removed }) => {
|
||||
const updatePath = Object.keys(this.levelup.levels[this.levelup.currentLevel].choices).reduce(
|
||||
(acc, choiceKey) => {
|
||||
const choice = this.levelup.levels[this.levelup.currentLevel].choices[choiceKey];
|
||||
Object.keys(choice).forEach(checkboxNr => {
|
||||
const checkbox = choice[checkboxNr];
|
||||
if (
|
||||
choiceKey === type &&
|
||||
(removed ? checkbox.data.includes(option) : checkbox.data.length < checkbox.amount)
|
||||
) {
|
||||
acc = `levels.${this.levelup.currentLevel}.choices.${choiceKey}.${checkboxNr}.data`;
|
||||
}
|
||||
});
|
||||
tagifyUpdate = type => async (_, { option, removed }) => {
|
||||
const updatePath = Object.keys(this.levelup.levels[this.levelup.currentLevel].choices).reduce(
|
||||
(acc, choiceKey) => {
|
||||
const choice = this.levelup.levels[this.levelup.currentLevel].choices[choiceKey];
|
||||
Object.keys(choice).forEach(checkboxNr => {
|
||||
const checkbox = choice[checkboxNr];
|
||||
if (
|
||||
choiceKey === type &&
|
||||
(removed ? checkbox.data.includes(option) : checkbox.data.length < checkbox.amount)
|
||||
) {
|
||||
acc = `levels.${this.levelup.currentLevel}.choices.${choiceKey}.${checkboxNr}.data`;
|
||||
}
|
||||
});
|
||||
|
||||
return acc;
|
||||
},
|
||||
null
|
||||
);
|
||||
return acc;
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
if (!updatePath) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noSelectionsLeft'));
|
||||
return;
|
||||
}
|
||||
if (!updatePath) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noSelectionsLeft'));
|
||||
return;
|
||||
}
|
||||
|
||||
const currentData = foundry.utils.getProperty(this.levelup, updatePath);
|
||||
const updatedData = removed ? currentData.filter(x => x !== option) : [...currentData, option];
|
||||
await this.levelup.updateSource({ [updatePath]: updatedData });
|
||||
this.render();
|
||||
};
|
||||
const currentData = foundry.utils.getProperty(this.levelup, updatePath);
|
||||
const updatedData = removed ? currentData.filter(x => x !== option) : [...currentData, option];
|
||||
await this.levelup.updateSource({ [updatePath]: updatedData });
|
||||
this.render();
|
||||
};
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
const { levelup } = foundry.utils.expandObject(formData.object);
|
||||
|
|
@ -593,10 +404,10 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
|
|||
const domainCards = this.levelup.levels[this.levelup.currentLevel].achievements.domainCards;
|
||||
const illegalDomainCards = option.secondaryData.domain
|
||||
? Object.keys(domainCards)
|
||||
.map(key => ({ ...domainCards[key], key }))
|
||||
.filter(
|
||||
x => x.uuid && foundry.utils.fromUuidSync(x.uuid).system.domain === option.secondaryData.domain
|
||||
)
|
||||
.map(key => ({ ...domainCards[key], key }))
|
||||
.filter(
|
||||
x => x.uuid && foundry.utils.fromUuidSync(x.uuid).system.domain === option.secondaryData.domain
|
||||
)
|
||||
: [];
|
||||
illegalDomainCards.forEach(card => {
|
||||
update[`levels.${this.levelup.currentLevel}.achievements.domainCards.${card.key}.uuid`] = null;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import DhAppearance from '../../data/settings/Appearance.mjs';
|
||||
import { getDiceSoNicePreset } from '../../config/generalConfig.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
/**
|
||||
* @import DhAppearance from '../../data/settings/Appearance.mjs';
|
||||
* @import {ApplicationClickAction} from "@client/applications/_types.mjs"
|
||||
*/
|
||||
|
||||
/** Settings menu for appearance settings */
|
||||
export default class DHAppearanceSettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
|
||||
switch (partId) {
|
||||
case 'domains':
|
||||
const selectedDomain = this.selected.domain ? this.settings.domains[this.selected.domain] : null;
|
||||
const selectedDomain = this.settings.domains[this.selected.domain] ?? null;
|
||||
const enrichedDescription = selectedDomain
|
||||
? await foundry.applications.ux.TextEditor.implementation.enrichHTML(selectedDomain.description)
|
||||
: null;
|
||||
|
|
@ -251,8 +251,8 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
const configTitle = isDowntime
|
||||
? game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.downtimeMove')
|
||||
: type === 'armorFeatures'
|
||||
? game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.armorFeature')
|
||||
: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.weaponFeature');
|
||||
? game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.armorFeature')
|
||||
: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.weaponFeature');
|
||||
|
||||
const editedBase = await game.system.api.applications.sheetConfigs.SettingFeatureConfig.configure(
|
||||
configTitle,
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
};
|
||||
}
|
||||
|
||||
if (this.action.parent.metadata.isInventoryItem) {
|
||||
if (this.action.parent.metadata?.isInventoryItem) {
|
||||
options.quantity = {
|
||||
label: 'DAGGERHEART.GENERAL.itemQuantity',
|
||||
group: 'Global'
|
||||
|
|
|
|||
|
|
@ -10,11 +10,7 @@ export default class DHAdversarySettings extends DHBaseActorSettings {
|
|||
actions: {
|
||||
addExperience: DHAdversarySettings.#addExperience,
|
||||
removeExperience: DHAdversarySettings.#removeExperience
|
||||
},
|
||||
dragDrop: [
|
||||
{ dragSelector: null, dropSelector: '.tab.features' },
|
||||
{ dragSelector: '.feature-item', dropSelector: null }
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
/**@override */
|
||||
|
|
@ -38,7 +34,8 @@ export default class DHAdversarySettings extends DHBaseActorSettings {
|
|||
},
|
||||
features: {
|
||||
id: 'features',
|
||||
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/features.hbs'
|
||||
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/features.hbs',
|
||||
scrollable: ['']
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -54,12 +51,16 @@ export default class DHAdversarySettings extends DHBaseActorSettings {
|
|||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
|
||||
const featureForms = ['passive', 'action', 'reaction'];
|
||||
context.features = context.document.system.features.sort((a, b) =>
|
||||
a.system.featureForm !== b.system.featureForm
|
||||
? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm)
|
||||
: a.sort - b.sort
|
||||
);
|
||||
// Get feature groups. Uncategorized go to actions
|
||||
const featureFormsTypes = ['passive', 'action', 'reaction'];
|
||||
const features = this.document.system.features.sort((a, b) => a.sort - b.sort);
|
||||
const featureGroups = featureFormsTypes.map(t => ({
|
||||
featureForm: t,
|
||||
label: _loc(CONFIG.DH.ITEM.featureForm[t]),
|
||||
features: features.filter(f => f.system.featureForm === t)
|
||||
}));
|
||||
featureGroups[1].features.push(...features.filter(f => !featureFormsTypes.includes(f.system.featureForm)));
|
||||
context.featureGroups = featureGroups;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
|
@ -97,32 +98,4 @@ export default class DHAdversarySettings extends DHBaseActorSettings {
|
|||
|
||||
await this.actor.update({ [`system.experiences.${target.dataset.experience}`]: _del });
|
||||
}
|
||||
|
||||
async _onDragStart(event) {
|
||||
const featureItem = event.currentTarget.closest('.feature-item');
|
||||
|
||||
if (featureItem) {
|
||||
const feature = this.actor.items.get(featureItem.id);
|
||||
const featureData = { type: 'Item', uuid: feature.uuid, fromInternal: true };
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
|
||||
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
|
||||
}
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
event.stopPropagation();
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item?.type === 'feature') {
|
||||
if (data.fromInternal && item.parent?.uuid === this.actor.uuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const itemData = item.toObject();
|
||||
delete itemData._id;
|
||||
|
||||
await this.actor.createEmbeddedDocuments('Item', [itemData]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export default class DHEnvironmentSettings extends DHBaseActorSettings {
|
|||
dragDrop: [
|
||||
{ dragSelector: null, dropSelector: '.category-container' },
|
||||
{ dragSelector: null, dropSelector: '.tab.features' },
|
||||
{ dragSelector: '.feature-item', dropSelector: null }
|
||||
{ dragSelector: '.feature-item, .inventory-item[data-type="adversary"]', dropSelector: null }
|
||||
]
|
||||
};
|
||||
|
||||
|
|
@ -32,11 +32,13 @@ export default class DHEnvironmentSettings extends DHBaseActorSettings {
|
|||
},
|
||||
features: {
|
||||
id: 'features',
|
||||
template: 'systems/daggerheart/templates/sheets-settings/environment-settings/features.hbs'
|
||||
template: 'systems/daggerheart/templates/sheets-settings/environment-settings/features.hbs',
|
||||
scrollable: ['']
|
||||
},
|
||||
adversaries: {
|
||||
id: 'adversaries',
|
||||
template: 'systems/daggerheart/templates/sheets-settings/environment-settings/adversaries.hbs'
|
||||
template: 'systems/daggerheart/templates/sheets-settings/environment-settings/adversaries.hbs',
|
||||
scrollable: ['']
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -52,12 +54,16 @@ export default class DHEnvironmentSettings extends DHBaseActorSettings {
|
|||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
|
||||
const featureForms = ['passive', 'action', 'reaction'];
|
||||
context.features = context.document.system.features.sort((a, b) =>
|
||||
a.system.featureForm !== b.system.featureForm
|
||||
? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm)
|
||||
: a.sort - b.sort
|
||||
);
|
||||
// Get feature groups. Uncategorized go to actions
|
||||
const featureFormsTypes = ['passive', 'action', 'reaction'];
|
||||
const features = this.document.system.features.sort((a, b) => a.sort - b.sort);
|
||||
const featureGroups = featureFormsTypes.map(t => ({
|
||||
featureForm: t,
|
||||
label: _loc(CONFIG.DH.ITEM.featureForm[t]),
|
||||
features: features.filter(f => f.system.featureForm === t)
|
||||
}));
|
||||
featureGroups[1].features.push(...features.filter(f => !featureFormsTypes.includes(f.system.featureForm)));
|
||||
context.featureGroups = featureGroups;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
|
@ -110,33 +116,30 @@ export default class DHEnvironmentSettings extends DHBaseActorSettings {
|
|||
}
|
||||
|
||||
async _onDragStart(event) {
|
||||
const featureItem = event.currentTarget.closest('.feature-item');
|
||||
|
||||
if (featureItem) {
|
||||
const feature = this.actor.items.get(featureItem.id);
|
||||
const featureData = { type: 'Item', uuid: feature.uuid, fromInternal: true };
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
|
||||
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
|
||||
const element = event.currentTarget.closest('.inventory-item[data-type=adversary]');
|
||||
if (element) {
|
||||
const adversaryData = { type: 'Actor', uuid: element.dataset.itemUuid };
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(adversaryData));
|
||||
event.dataTransfer.setDragImage(element, 60, 0);
|
||||
} else {
|
||||
return super._onDragStart(event);
|
||||
}
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
event.stopPropagation();
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (data.fromInternal && item?.parent?.uuid === this.actor.uuid) return;
|
||||
|
||||
if (item.type === 'adversary' && event.target.closest('.category-container')) {
|
||||
const doc = await fromUuid(data.uuid);
|
||||
if (doc?.type === 'adversary' && event.target.closest('.category-container')) {
|
||||
const target = event.target.closest('.category-container');
|
||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
|
||||
const current = foundry.utils.getProperty(this.actor, path).map(x => x.uuid);
|
||||
await this.actor.update({
|
||||
[path]: [...current, item.uuid]
|
||||
});
|
||||
this.render();
|
||||
} else if (item.type === 'feature' && event.target.closest('.tab.features')) {
|
||||
await this.actor.createEmbeddedDocuments('Item', [item]);
|
||||
this.render();
|
||||
if (!current.includes(doc.uuid)) {
|
||||
await this.actor.update({ [path]: [...current, doc.uuid] });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
return super._onDrop(event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ export default class DHNPCSettings extends DHBaseActorSettings {
|
|||
},
|
||||
features: {
|
||||
id: 'features',
|
||||
template: 'systems/daggerheart/templates/sheets-settings/npc-settings/features.hbs'
|
||||
template: 'systems/daggerheart/templates/sheets-settings/npc-settings/features.hbs',
|
||||
scrollable: ['']
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -43,43 +44,17 @@ export default class DHNPCSettings extends DHBaseActorSettings {
|
|||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
|
||||
const featureForms = ['passive', 'action', 'reaction'];
|
||||
context.features = context.document.system.features.sort((a, b) =>
|
||||
a.system.featureForm !== b.system.featureForm
|
||||
? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm)
|
||||
: a.sort - b.sort
|
||||
);
|
||||
// Get feature groups. Uncategorized go to actions
|
||||
const featureFormsTypes = ['passive', 'action', 'reaction'];
|
||||
const features = this.document.system.features.sort((a, b) => a.sort - b.sort);
|
||||
const featureGroups = featureFormsTypes.map(t => ({
|
||||
featureForm: t,
|
||||
label: _loc(CONFIG.DH.ITEM.featureForm[t]),
|
||||
features: features.filter(f => f.system.featureForm === t)
|
||||
}));
|
||||
featureGroups[1].features.push(...features.filter(f => !featureFormsTypes.includes(f.system.featureForm)));
|
||||
context.featureGroups = featureGroups;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
async _onDragStart(event) {
|
||||
const featureItem = event.currentTarget.closest('.feature-item');
|
||||
|
||||
if (featureItem) {
|
||||
const feature = this.actor.items.get(featureItem.id);
|
||||
const featureData = { type: 'Item', uuid: feature.uuid, fromInternal: true };
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
|
||||
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
|
||||
}
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
event.stopPropagation();
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item?.type === 'feature') {
|
||||
if (data.fromInternal && item.parent?.uuid === this.actor.uuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const itemData = item.toObject();
|
||||
delete itemData._id;
|
||||
|
||||
await this.actor.createEmbeddedDocuments('Item', [itemData]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,8 +168,8 @@ export default class SettingFeatureConfig extends HandlebarsApplicationMixin(App
|
|||
updatedEffects = deleteEffect
|
||||
? currentEffects.filter(x => x.id !== effectData.id)
|
||||
: existingEffectIndex === -1
|
||||
? [...currentEffects, effectData]
|
||||
: currentEffects.with(existingEffectIndex, effectData);
|
||||
? [...currentEffects, effectData]
|
||||
: currentEffects.with(existingEffectIndex, effectData);
|
||||
await this.updateMove({
|
||||
[`${this.movePath}.effects`]: updatedEffects
|
||||
});
|
||||
|
|
@ -235,9 +235,9 @@ export default class SettingFeatureConfig extends HandlebarsApplicationMixin(App
|
|||
return this.hasEffects
|
||||
? tabs
|
||||
: Object.keys(tabs).reduce((acc, key) => {
|
||||
if (key !== 'effects') acc[key] = tabs[key];
|
||||
return acc;
|
||||
}, {});
|
||||
if (key !== 'effects') acc[key] = tabs[key];
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
/** @override */
|
||||
|
|
|
|||
8
module/applications/sheets/actors/_types.d.ts
vendored
Normal file
8
module/applications/sheets/actors/_types.d.ts
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import DhCompanion from '../../../data/actor/companion.mjs';
|
||||
import DhpActor from '../../../documents/actor.mjs';
|
||||
|
||||
declare module './companion.mjs' {
|
||||
export default interface DhCompanionSheet {
|
||||
actor: DhpActor<DhCompanion>;
|
||||
}
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ export default class AdversarySheet extends DHBaseActorSheet {
|
|||
context.resources.stress.emptyPips =
|
||||
context.resources.stress.max < maxResource ? maxResource - context.resources.stress.max : 0;
|
||||
|
||||
const featureForms = ['passive', 'action', 'reaction'];
|
||||
const featureForms = Object.keys(CONFIG.DH.ITEM.featureForm);
|
||||
context.features = this.document.system.features.sort((a, b) =>
|
||||
a.system.featureForm !== b.system.featureForm
|
||||
? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm)
|
||||
|
|
@ -131,6 +131,15 @@ export default class AdversarySheet extends DHBaseActorSheet {
|
|||
return context;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
_prepareTabs(group) {
|
||||
const result = super._prepareTabs(group);
|
||||
if (group === 'primary') {
|
||||
result.notes.empty = !this.document.system.notes?.trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
|
@ -186,15 +195,6 @@ export default class AdversarySheet extends DHBaseActorSheet {
|
|||
});
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
async _onDragStart(event) {
|
||||
const inventoryItem = event.currentTarget.closest('.inventory-item');
|
||||
if (inventoryItem) {
|
||||
event.dataTransfer.setDragImage(inventoryItem.querySelector('img'), 60, 0);
|
||||
}
|
||||
super._onDragStart(event);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
|
||||
const levelups = Object.values(actor.system.levelData?.levelups) ?? [];
|
||||
const uuid = item.uuid;
|
||||
const sourceUuid = item._stats.compendiumSource; // on older characters this may be missing
|
||||
const sourceUuid = item.sourceUuid; // on older characters this may be missing
|
||||
return levelups.some(data => {
|
||||
if (item.type === 'subclass') {
|
||||
const selectedSubclasses = data.selections.map(s => s.secondaryData?.subclass).filter(s => !!s);
|
||||
|
|
@ -785,11 +785,11 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
filter:
|
||||
key === 'subclasses'
|
||||
? {
|
||||
'system.linkedClass.uuid': {
|
||||
key: 'system.linkedClass.uuid',
|
||||
value: this.document.system.class.value?._stats.compendiumSource
|
||||
}
|
||||
}
|
||||
'system.linkedClass.uuid': {
|
||||
key: 'system.linkedClass.uuid',
|
||||
value: this.document.system.class.value?._stats.compendiumSource
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
render: {
|
||||
noFolder: true
|
||||
|
|
@ -809,7 +809,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
|
||||
/* This could be avoided by baking config.costs into config.resourceUpdates. Didn't feel like messing with it at the time */
|
||||
const costResources =
|
||||
result.costs?.filter(x => x.enabled).map(cost => ({ ...cost, value: -cost.value, total: -cost.total })) ||
|
||||
result.costs?.filter(x => x.enabled).map(cost => ({ ...cost, value: -cost.value })) ||
|
||||
{};
|
||||
result.resourceUpdates.addResources(costResources);
|
||||
await result.resourceUpdates.updateResources();
|
||||
|
|
@ -1193,15 +1193,6 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
});
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
async _onDragStart(event) {
|
||||
const inventoryItem = event.currentTarget.closest('.inventory-item');
|
||||
if (inventoryItem) {
|
||||
event.dataTransfer.setDragImage(inventoryItem.querySelector('img'), 60, 0);
|
||||
}
|
||||
super._onDragStart(event);
|
||||
}
|
||||
|
||||
async _onDropItem(event, item) {
|
||||
const setupCriticalItemTypes = ['class', 'subclass', 'ancestry', 'community'];
|
||||
if (this.document.system.needsCharacterSetup && setupCriticalItemTypes.includes(item.type)) {
|
||||
|
|
|
|||
|
|
@ -62,9 +62,7 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
|
|||
await this.document.update({ 'system.resources.stress.value': newValue });
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/** @this {DhCompanionSheet} **/
|
||||
static async #actionRoll(event) {
|
||||
const partner = this.actor.system.partner;
|
||||
const config = {
|
||||
|
|
@ -80,6 +78,7 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
|
|||
|
||||
const result = await partner.diceRoll(config);
|
||||
this.consumeResource(result?.costs);
|
||||
result?.resourceUpdates.updateResources();
|
||||
}
|
||||
|
||||
// Remove when Action Refactor part #2 done
|
||||
|
|
|
|||
|
|
@ -72,13 +72,22 @@ export default class DhpEnvironment extends DHBaseActorSheet {
|
|||
return applicationOptions;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
_prepareTabs(group) {
|
||||
const result = super._prepareTabs(group);
|
||||
if (group === 'primary') {
|
||||
result.potentialAdversaries.empty = foundry.utils.isEmpty(this.document.system.potentialAdversaries);
|
||||
result.notes.empty = !this.document.system.notes?.trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async _preparePartContext(partId, context, options) {
|
||||
context = await super._preparePartContext(partId, context, options);
|
||||
switch (partId) {
|
||||
case 'header':
|
||||
await this._prepareHeaderContext(context, options);
|
||||
|
||||
break;
|
||||
case 'features':
|
||||
await this._prepareFeaturesContext(context, options);
|
||||
|
|
|
|||
|
|
@ -162,9 +162,9 @@ export default class Party extends DHBaseActorSheet {
|
|||
difficulty: actor.system.difficulty,
|
||||
traits: actor.system.traits
|
||||
? traits.map(t => ({
|
||||
label: game.i18n.localize(`DAGGERHEART.CONFIG.Traits.${t}.short`),
|
||||
value: actor.system.traits[t].value
|
||||
}))
|
||||
label: game.i18n.localize(`DAGGERHEART.CONFIG.Traits.${t}.short`),
|
||||
value: actor.system.traits[t].value
|
||||
}))
|
||||
: null,
|
||||
weapons
|
||||
});
|
||||
|
|
@ -306,7 +306,7 @@ export default class Party extends DHBaseActorSheet {
|
|||
|
||||
static async downtimeMoveQuery({ actorId, downtimeType }) {
|
||||
const actor = await foundry.utils.fromUuid(actorId);
|
||||
if (!actor || !actor?.isOwner) reject();
|
||||
if (!actor || !actor?.isOwner) return;
|
||||
new game.system.api.applications.dialogs.Downtime(actor, downtimeType === 'shortRest').render({
|
||||
force: true
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import DHApplicationMixin from './application-mixin.mjs';
|
||||
const { DocumentSheetV2 } = foundry.applications.api;
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
|
||||
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
|
||||
/**
|
||||
* @typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base settings sheet for Daggerheart actors.
|
||||
* @extends {DHApplicationMixin<DocumentSheetV2>}
|
||||
* @extends {DHApplicationMixin<ActorSheetV2>}
|
||||
*/
|
||||
export default class DHBaseActorSettings extends DHApplicationMixin(DocumentSheetV2) {
|
||||
export default class DHBaseActorSettings extends DHApplicationMixin(ActorSheetV2) {
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['dialog'],
|
||||
|
|
@ -23,7 +25,7 @@ export default class DHBaseActorSettings extends DHApplicationMixin(DocumentShee
|
|||
},
|
||||
dragDrop: [
|
||||
{ dragSelector: null, dropSelector: '.tab.features' },
|
||||
{ dragSelector: '.feature-item', dropSelector: null }
|
||||
{ dragSelector: '.feature-item, .inventory-item[data-type="feature"]', dropSelector: null }
|
||||
]
|
||||
};
|
||||
|
||||
|
|
@ -34,7 +36,7 @@ export default class DHBaseActorSettings extends DHApplicationMixin(DocumentShee
|
|||
return options;
|
||||
}
|
||||
|
||||
/**@returns {foundry.documents.Actor} */
|
||||
/** @returns {foundry.documents.Actor} */
|
||||
get actor() {
|
||||
return this.document;
|
||||
}
|
||||
|
|
@ -73,4 +75,32 @@ export default class DHBaseActorSettings extends DHApplicationMixin(DocumentShee
|
|||
|
||||
return context;
|
||||
}
|
||||
|
||||
async _onDragStart(event) {
|
||||
const featureItemEl = event.currentTarget.closest('.feature-item, .inventory-item[data-type="feature"]');
|
||||
const feature = this.actor.items.get(featureItemEl?.dataset.itemId);
|
||||
if (feature && event.target.closest('.tab.features')) {
|
||||
const featureData = { ...feature.toDragData(), fromInternal: true };
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
|
||||
event.dataTransfer.setDragImage(featureItemEl.querySelector('img'), 60, 0);
|
||||
}
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
event.stopPropagation();
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item?.type === 'feature') {
|
||||
if (data.fromInternal && item.parent?.uuid === this.actor.uuid) {
|
||||
return super._onDrop(event);
|
||||
}
|
||||
|
||||
const itemData = item.toObject();
|
||||
delete itemData._id;
|
||||
await this.actor.createEmbeddedDocuments('Item', [itemData]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Setting sheets do not auto extend */
|
||||
async _autoExpandDescriptions() {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { getDocFromElement, getDocFromElementSync, tagifyElement } from '../../.
|
|||
const typeSettingsMap = {
|
||||
character: 'extendCharacterDescriptions',
|
||||
adversary: 'extendAdversaryDescriptions',
|
||||
npc: 'extendAdversaryDescriptions',
|
||||
environment: 'extendEnvironmentDescriptions',
|
||||
ancestry: 'extendItemDescriptions',
|
||||
community: 'extendItemDescriptions',
|
||||
|
|
@ -262,7 +263,7 @@ export default function DHApplicationMixin(Base) {
|
|||
|
||||
if (!!this.options.contextMenus.length) this._createContextMenus();
|
||||
|
||||
this.#autoExtendDescriptions(context);
|
||||
this._autoExpandDescriptions(context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
|
|
@ -361,18 +362,17 @@ export default function DHApplicationMixin(Base) {
|
|||
*/
|
||||
async _onDragStart(event) {
|
||||
const inventoryItem = event.currentTarget.closest('.inventory-item');
|
||||
if (inventoryItem) {
|
||||
const { type, itemUuid } = inventoryItem.dataset;
|
||||
if (type === 'effect') {
|
||||
const effect = await foundry.utils.fromUuid(itemUuid);
|
||||
const effectData = {
|
||||
type: 'ActiveEffect',
|
||||
data: { ...effect.toObject(), _id: null },
|
||||
fromInternal: this.document.uuid
|
||||
};
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(effectData));
|
||||
event.dataTransfer.setDragImage(inventoryItem.querySelector('img'), 60, 0);
|
||||
}
|
||||
if (!inventoryItem) return;
|
||||
|
||||
const { type, itemUuid } = inventoryItem.dataset;
|
||||
const effect = type === 'effect' ? await foundry.utils.fromUuid(itemUuid) : null;
|
||||
if (effect) {
|
||||
const effectData = {
|
||||
...effect.toDragData(),
|
||||
fromInternal: this.document.uuid
|
||||
};
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(effectData));
|
||||
event.dataTransfer.setDragImage(inventoryItem.querySelector('img'), 60, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -382,14 +382,33 @@ export default function DHApplicationMixin(Base) {
|
|||
* @protected
|
||||
*/
|
||||
_onDrop(event) {
|
||||
// Potentially handle subclasses that dont descend from actor/item sheet.
|
||||
event.stopPropagation();
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
if (data.type === 'ActiveEffect' && data.fromInternal !== this.document.uuid) {
|
||||
this.document.createEmbeddedDocuments('ActiveEffect', [data.data]);
|
||||
} else {
|
||||
// Fallback to super, but note that item sheets do not have this function
|
||||
return super._onDrop?.(event);
|
||||
return super._onDrop?.(event);
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
_onSortItem(event, item) {
|
||||
// If we are dragging a feature past its allowed feature form, put it in the front or in the back
|
||||
const doc = this.actor.items.get(item.id);
|
||||
const dropTargetEl = event.target.closest('[data-item-id]');
|
||||
const dropTarget = this.actor.items.get(dropTargetEl?.dataset.itemId);
|
||||
if (doc?.type === 'feature' && dropTarget?.type === 'feature' && doc.system.featureForm !== dropTarget.system.featureForm) {
|
||||
const siblings = this.actor.itemTypes.feature
|
||||
.filter(f => f.system.featureForm === doc.system.featureForm)
|
||||
.sort((a, b) => a.sort - b.sort);
|
||||
if (siblings.length > 1) {
|
||||
const featureForms = Object.keys(CONFIG.DH.ITEM.featureForm);
|
||||
const thisFeatureIdx = featureForms.indexOf(doc.system.featureForm);
|
||||
const targetFeatureIdx = featureForms.indexOf(dropTarget.system.featureForm);
|
||||
const target = targetFeatureIdx < thisFeatureIdx ? siblings[0] : siblings.at(-1);
|
||||
const sortUpdates = foundry.utils.performIntegerSort(doc, { target, siblings });
|
||||
const updateData = sortUpdates.map(u => ({ ...u.update, _id: u.target._id }));
|
||||
return this.actor.updateEmbeddedDocuments('Item', updateData);
|
||||
}
|
||||
}
|
||||
|
||||
return super._onSortItem?.(event, item);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
|
@ -499,7 +518,7 @@ export default function DHApplicationMixin(Base) {
|
|||
const doc = await getDocFromElement(target),
|
||||
action = doc?.system?.attack ?? doc;
|
||||
const config = action.prepareConfig(event);
|
||||
config.effects = await game.system.api.data.actions.actionsTypes.base.getEffects(
|
||||
config.effects = await game.system.api.data.actions.actionsTypes.base.getActionRelevantEffects(
|
||||
this.document,
|
||||
doc
|
||||
);
|
||||
|
|
@ -584,7 +603,7 @@ export default function DHApplicationMixin(Base) {
|
|||
const doc = await fromUuid(itemUuid);
|
||||
|
||||
//get inventory-item description element
|
||||
const descriptionElement = el.querySelector('.invetory-description');
|
||||
const descriptionElement = el.querySelector('.inventory-description');
|
||||
if (!doc || !descriptionElement) continue;
|
||||
|
||||
// localize the description (idk if it's still necessary)
|
||||
|
|
@ -612,8 +631,9 @@ export default function DHApplicationMixin(Base) {
|
|||
/**
|
||||
* Extend inventory description when enabled in settings.
|
||||
* @returns {Promise<void>}
|
||||
* @protected
|
||||
*/
|
||||
async #autoExtendDescriptions(context) {
|
||||
async _autoExpandDescriptions(context) {
|
||||
const inventoryItems = this.element.querySelectorAll('.inventory-item[data-item-uuid]');
|
||||
for (const el of inventoryItems) {
|
||||
// Get the doc uuid from the element
|
||||
|
|
@ -716,16 +736,16 @@ export default function DHApplicationMixin(Base) {
|
|||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #onCreateDoc(event, target) {
|
||||
const { documentClass, type, inVault, disabled } = target.dataset;
|
||||
const { documentClass, type, inVault, disabled, featureForm } = target.dataset;
|
||||
const parentIsItem = this.document.documentName === 'Item';
|
||||
const featureOnCharacter = this.document.parent?.type === 'character' && type === 'feature';
|
||||
const parent = featureOnCharacter
|
||||
? this.document.parent
|
||||
: parentIsItem && documentClass === 'Item'
|
||||
? type === 'action'
|
||||
? this.document.system
|
||||
: null
|
||||
: this.document;
|
||||
? type === 'action'
|
||||
? this.document.system
|
||||
: null
|
||||
: this.document;
|
||||
|
||||
let systemData = {};
|
||||
if (featureOnCharacter) {
|
||||
|
|
@ -734,6 +754,7 @@ export default function DHApplicationMixin(Base) {
|
|||
identifier: this.document.system.isMulticlass ? 'multiclass' : null
|
||||
};
|
||||
}
|
||||
if (featureForm) systemData.featureForm = featureForm;
|
||||
|
||||
const cls =
|
||||
type === 'action' ? game.system.api.models.actions.actionsTypes.base : getDocumentClass(documentClass);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import { getDocFromElement, itemIsIdentical } from '../../../helpers/utils.mjs';
|
||||
import DHBaseActorSettings from './actor-setting.mjs';
|
||||
import DHApplicationMixin from './application-mixin.mjs';
|
||||
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
|
||||
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
|
||||
/**
|
||||
* @import DHBaseActorSettings from './actor-setting.mjs';
|
||||
* @typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction
|
||||
*/
|
||||
|
||||
/**
|
||||
* A base actor sheet extending {@link ActorSheetV2} via {@link DHApplicationMixin}
|
||||
|
|
@ -210,7 +212,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
const doc = await getDocFromElement(target),
|
||||
action = doc?.system?.attack ?? doc;
|
||||
const config = action.prepareConfig(event);
|
||||
config.effects = await game.system.api.data.actions.actionsTypes.base.getEffects(
|
||||
config.effects = await game.system.api.data.actions.actionsTypes.base.getActionRelevantEffects(
|
||||
this.document,
|
||||
doc
|
||||
);
|
||||
|
|
@ -377,7 +379,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
action: 'update',
|
||||
documentName: 'Item',
|
||||
parent: targetActor,
|
||||
updates: [{ '_id': existing.id, 'system.quantity': existing.system.quantity + quantity }]
|
||||
updates: [{ _id: existing.id, 'system.quantity': existing.system.quantity + quantity }]
|
||||
});
|
||||
} else {
|
||||
const itemsToCreate = [];
|
||||
|
|
@ -410,7 +412,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
action: 'update',
|
||||
documentName: 'Item',
|
||||
parent: originActor,
|
||||
updates: [{ '_id': item.id, 'system.quantity': item.system.quantity - quantity }]
|
||||
updates: [{ _id: item.id, 'system.quantity': item.system.quantity - quantity }]
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -447,13 +449,15 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
|
||||
const item = await getDocFromElement(event.target);
|
||||
if (item) {
|
||||
const inventoryItem = event.currentTarget.closest('.inventory-item');
|
||||
const dragData = {
|
||||
...item.toDragData(),
|
||||
originActor: this.document.uuid,
|
||||
originId: item.id,
|
||||
type: item.documentName,
|
||||
uuid: item.uuid
|
||||
originId: item.id
|
||||
};
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(dragData));
|
||||
if (inventoryItem) event.dataTransfer.setDragImage(inventoryItem.querySelector('img'), 60, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
super._onDragStart(event);
|
||||
|
|
|
|||
|
|
@ -29,16 +29,6 @@ export default function ItemAttachmentSheet(Base) {
|
|||
}
|
||||
};
|
||||
|
||||
async _preparePartContext(partId, context) {
|
||||
await super._preparePartContext(partId, context);
|
||||
|
||||
if (partId === 'attachments') {
|
||||
context.attachedItems = await prepareAttachmentContext(this.document);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
|||
const item = await fromUuid(data.uuid);
|
||||
const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
|
||||
if (itemType === 'class') {
|
||||
const uuid = item._stats.compendiumSource ?? item.uuid;
|
||||
const uuid = item.sourceUuid;
|
||||
if (this.document.system.linkedClass !== uuid) {
|
||||
await this.document.update({ 'system.linkedClass': uuid });
|
||||
// Re-render all class sheets for instant feedback
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
export default class DhActorDirectory extends foundry.applications.sidebar.tabs.ActorDirectory {
|
||||
static DEFAULT_OPTIONS = {
|
||||
renderUpdateKeys: ['system.levelData.level.current', 'system.partner', 'system.tier']
|
||||
renderUpdateKeys: ['system.levelData.level.current', 'system.partner', 'system.tier', 'system.type']
|
||||
};
|
||||
|
||||
static _entryPartial = 'systems/daggerheart/templates/ui/sidebar/actor-document-partial.hbs';
|
||||
|
|
@ -13,8 +13,8 @@ export default class DhActorDirectory extends foundry.applications.sidebar.tabs.
|
|||
return document.type === 'adversary'
|
||||
? game.i18n.localize(adversaryTypes[document.system.type]?.label ?? 'TYPES.Actor.adversary')
|
||||
: document.type === 'environment'
|
||||
? game.i18n.localize(environmentTypes[document.system.type]?.label ?? 'TYPES.Actor.environment')
|
||||
: null;
|
||||
? game.i18n.localize(environmentTypes[document.system.type]?.label ?? 'TYPES.Actor.environment')
|
||||
: null;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,3 +8,4 @@ export { default as DhHotbar } from './hotbar.mjs';
|
|||
export { default as DhSceneNavigation } from './sceneNavigation.mjs';
|
||||
export { ItemBrowser } from './itemBrowser.mjs';
|
||||
export { default as DhProgress } from './progress.mjs';
|
||||
export { default as DhGamePause } from './gamePause.mjs';
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
const advantage = rollCommand.advantage
|
||||
? CONFIG.DH.ACTIONS.advantageState.advantage.value
|
||||
: rollCommand.disadvantage
|
||||
? CONFIG.DH.ACTIONS.advantageState.disadvantage.value
|
||||
: undefined;
|
||||
? CONFIG.DH.ACTIONS.advantageState.disadvantage.value
|
||||
: undefined;
|
||||
const difficulty = rollCommand.difficulty;
|
||||
const grantResources = rollCommand.grantResources;
|
||||
|
||||
|
|
@ -50,8 +50,8 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
const title =
|
||||
(flavor ?? traitValue)
|
||||
? game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
||||
ability: game.i18n.localize(SYSTEM.ACTOR.abilities[traitValue].label)
|
||||
})
|
||||
ability: game.i18n.localize(CONFIG.DH.ACTOR.abilities[traitValue].label)
|
||||
})
|
||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality');
|
||||
|
||||
enrichedDualityRoll({
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
|
|||
|
||||
static PARTS = {
|
||||
countdowns: {
|
||||
template: 'systems/daggerheart/templates/ui/countdown-edit.hbs',
|
||||
template: 'systems/daggerheart/templates/ui/countdowns/countdown-edit.hbs',
|
||||
scrollable: ['.expanded-view', '.edit-content']
|
||||
}
|
||||
};
|
||||
|
|
@ -45,7 +45,7 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
|
|||
context.isGM = game.user.isGM;
|
||||
context.ownershipDefaultOptions = CONFIG.DH.GENERAL.basicOwnershiplevels;
|
||||
context.defaultOwnership = this.data.defaultOwnership;
|
||||
context.countdownBaseTypes = CONFIG.DH.GENERAL.countdownBaseTypes;
|
||||
context.countdownTypes = CONFIG.DH.GENERAL.countdownTypes;
|
||||
context.countdownProgressionTypes = CONFIG.DH.GENERAL.countdownProgressionTypes;
|
||||
context.countdownLoopingTypes = CONFIG.DH.GENERAL.countdownLoopingTypes;
|
||||
context.hideNewCountdowns = this.hideNewCountdowns;
|
||||
|
|
@ -56,13 +56,13 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
|
|||
? countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.increasing.id
|
||||
? 'DAGGERHEART.UI.Countdowns.increasingLoop'
|
||||
: countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.decreasing.id
|
||||
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
|
||||
: 'DAGGERHEART.UI.Countdowns.loop'
|
||||
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
|
||||
: 'DAGGERHEART.UI.Countdowns.loop'
|
||||
: null;
|
||||
const randomizeValid = !new Roll(countdown.progress.startFormula ?? '').isDeterministic;
|
||||
acc[key] = {
|
||||
...countdown,
|
||||
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].label),
|
||||
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownTypes[countdown.type].label),
|
||||
progress: {
|
||||
...countdown.progress,
|
||||
typeName: game.i18n.localize(
|
||||
|
|
@ -148,11 +148,11 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
|
|||
}
|
||||
|
||||
async gmSetSetting(data) {
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, data),
|
||||
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.Refresh,
|
||||
data: { refreshType: RefreshType.Countdown }
|
||||
});
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, data);
|
||||
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.Refresh,
|
||||
data: { refreshType: RefreshType.Countdown }
|
||||
});
|
||||
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,14 @@ const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
|||
*/
|
||||
|
||||
export default class DhCountdowns extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
previousCountdownData = null;
|
||||
changedCountdownsForAnimation = new Set();
|
||||
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
|
||||
this.previousCountdownData =
|
||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns).countdowns;
|
||||
this.setupHooks();
|
||||
}
|
||||
|
||||
|
|
@ -31,9 +36,10 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
minimizable: false
|
||||
},
|
||||
actions: {
|
||||
toggleViewMode: DhCountdowns.#toggleViewMode,
|
||||
editCountdowns: DhCountdowns.#editCountdowns,
|
||||
loopCountdown: DhCountdowns.#loopCountdown,
|
||||
toggleViewMode: DhCountdowns.#onToggleViewMode,
|
||||
toggleCountdownTypes: DhCountdowns.#onToggleCountdownTypes,
|
||||
editCountdowns: DhCountdowns.#onEditCountdowns,
|
||||
loopCountdown: DhCountdowns.#onLoopCountdown,
|
||||
decreaseCountdown: (_, target) => this.editCountdown(false, target),
|
||||
increaseCountdown: (_, target) => this.editCountdown(true, target)
|
||||
},
|
||||
|
|
@ -48,11 +54,20 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
static PARTS = {
|
||||
resources: {
|
||||
root: true,
|
||||
template: 'systems/daggerheart/templates/ui/countdowns.hbs'
|
||||
template: 'systems/daggerheart/templates/ui/countdowns/countdowns-view.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
/**@inheritdoc */
|
||||
/**
|
||||
* Returns all visible countdown types
|
||||
* @returns {string[]}
|
||||
*/
|
||||
get visibleCountdownTypes() {
|
||||
const { encounter, narrative } = CONFIG.DH.GENERAL.countdownTypes;
|
||||
return game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes)
|
||||
?? [encounter.id, narrative.id];
|
||||
}
|
||||
|
||||
async _renderFrame(options) {
|
||||
const frame = await super._renderFrame(options);
|
||||
|
||||
|
|
@ -65,6 +80,57 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
return frame;
|
||||
}
|
||||
|
||||
|
||||
async _onRender(context, options) {
|
||||
await super._onRender(context, options);
|
||||
|
||||
/* Handle rendering/hiding/positioning of the countdown UI */
|
||||
this.element.hidden = !game.user.isGM && this.#getCountdowns().length === 0;
|
||||
if (options?.force) {
|
||||
document.getElementById('ui-right-column-1')?.appendChild(this.element);
|
||||
}
|
||||
|
||||
this.previousCountdownData = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns)
|
||||
.countdowns;
|
||||
|
||||
/* Handle animations to draw attention to countdown values changing */
|
||||
const typesToAnimate = new Set();
|
||||
for (const countdownKey of this.changedCountdownsForAnimation) {
|
||||
const shimmerAnimation = [
|
||||
{ backgroundPositionX: '98%' },
|
||||
{ backgroundPositionX: '0%' }
|
||||
];
|
||||
const shimmerTiming = {
|
||||
duration: 1000,
|
||||
iterations: 1
|
||||
};
|
||||
|
||||
const element = this.element.querySelector(`.countdown-container[data-countdown="${countdownKey}"]`);
|
||||
element?.animate(shimmerAnimation, shimmerTiming);
|
||||
|
||||
const countdown = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns)
|
||||
.countdowns[countdownKey];
|
||||
if (!this.visibleCountdownTypes.includes(countdown?.type))
|
||||
typesToAnimate.add(countdown.type);
|
||||
}
|
||||
|
||||
for (const type of typesToAnimate) {
|
||||
const pulseAnimation = [
|
||||
{ boxShadow: '0 0 1px 1px var(--golden)' },
|
||||
{ boxShadow: '0 0 2px 2px var(--golden)' }
|
||||
];
|
||||
const pulseTiming = {
|
||||
duration: 1000,
|
||||
iterations: 3
|
||||
};
|
||||
|
||||
const element = this.element.querySelector(`.header-type-toggles .header-type[data-type="${type}"]`);
|
||||
element?.animate(pulseAnimation, pulseTiming);
|
||||
}
|
||||
|
||||
this.changedCountdownsForAnimation.clear();
|
||||
}
|
||||
|
||||
/** Returns countdown data filtered by ownership */
|
||||
#getCountdowns() {
|
||||
const setting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
|
||||
|
|
@ -76,16 +142,10 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
return values.filter(v => v.ownership !== CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE);
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
context.isGM = game.user.isGM;
|
||||
|
||||
context.iconOnly =
|
||||
game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode) ===
|
||||
CONFIG.DH.GENERAL.countdownAppMode.iconOnly;
|
||||
_getCountdownData() {
|
||||
const setting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
|
||||
context.countdowns = this.#getCountdowns().reduce((acc, { key, countdown, ownership }) => {
|
||||
|
||||
return this.#getCountdowns().reduce((acc, { key, countdown, ownership }) => {
|
||||
const playersWithAccess = game.users.reduce((acc, user) => {
|
||||
const ownership = DhCountdowns.#getPlayerOwnership(user, setting, countdown);
|
||||
if (!user.isGM && ownership && ownership !== CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE) {
|
||||
|
|
@ -101,14 +161,14 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
? countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.increasing.id
|
||||
? 'DAGGERHEART.UI.Countdowns.increasingLoop'
|
||||
: countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.decreasing.id
|
||||
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
|
||||
: 'DAGGERHEART.UI.Countdowns.loop'
|
||||
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
|
||||
: 'DAGGERHEART.UI.Countdowns.loop'
|
||||
: null;
|
||||
const loopDisabled =
|
||||
!countdownEditable ||
|
||||
(isLooping && (countdown.progress.current > 0 || countdown.progress.start === '0'));
|
||||
|
||||
acc[key] = {
|
||||
acc[countdown.type][key] = {
|
||||
...countdown,
|
||||
editable: countdownEditable,
|
||||
noPlayerAccess: nonGmPlayers.length && playersWithAccess.length === 0,
|
||||
|
|
@ -117,7 +177,38 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
loopTooltip: isLooping && game.i18n.localize(loopTooltip)
|
||||
};
|
||||
return acc;
|
||||
}, {});
|
||||
}, Object.keys(CONFIG.DH.GENERAL.countdownTypes).reduce((acc, key) => {
|
||||
acc[key] = {};
|
||||
return acc;
|
||||
}, {}));
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
context.isGM = game.user.isGM;
|
||||
|
||||
context.iconOnly =
|
||||
game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode)
|
||||
=== CONFIG.DH.GENERAL.countdownAppMode.iconOnly;
|
||||
|
||||
context.userCountdownTypes = this.visibleCountdownTypes;
|
||||
|
||||
context.typeToggles =
|
||||
Object.values(CONFIG.DH.GENERAL.countdownTypes).map(type => ({
|
||||
type: type.id,
|
||||
label: game.i18n.localize(type.shortLabel),
|
||||
active: context.userCountdownTypes.includes(type.id)
|
||||
}));
|
||||
|
||||
context.countdowns = this._getCountdownData();
|
||||
context.countdownTypesWithVisibleEntries = this.#getCountdowns().reduce((acc, data) => {
|
||||
if (context.userCountdownTypes.includes(data.countdown.type) && !acc.includes(data.countdown.type))
|
||||
acc.push(data.countdown.type);
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
|
||||
return context;
|
||||
}
|
||||
|
|
@ -147,7 +238,8 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
return true;
|
||||
}
|
||||
|
||||
static async #toggleViewMode() {
|
||||
/** @this {DhCountdowns} */
|
||||
static async #onToggleViewMode() {
|
||||
const currentMode = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownMode);
|
||||
const appMode = CONFIG.DH.GENERAL.countdownAppMode;
|
||||
const newMode = currentMode === appMode.textIcon ? appMode.iconOnly : appMode.textIcon;
|
||||
|
|
@ -158,15 +250,30 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async #editCountdowns() {
|
||||
/** @this {DhCountdowns} */
|
||||
static async #onToggleCountdownTypes(event, target) {
|
||||
const currentTypes = this.visibleCountdownTypes;
|
||||
const { type } = target.dataset;
|
||||
const newTypes = event.shiftKey ?
|
||||
[type] :
|
||||
currentTypes.includes(type) ? currentTypes.filter(x => x !== type) : [...currentTypes, type];
|
||||
await game.user.setFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.userFlags.countdownTypeModes, newTypes);
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
/** @this {DhCountdowns} */
|
||||
static async #onEditCountdowns() {
|
||||
new game.system.api.applications.ui.CountdownEdit().render(true);
|
||||
}
|
||||
|
||||
static async #loopCountdown(_, target) {
|
||||
/** @this {DhCountdowns} */
|
||||
static async #onLoopCountdown(_, target) {
|
||||
if (!DhCountdowns.canPerformEdit()) return;
|
||||
|
||||
const settings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
|
||||
const countdown = settings.countdowns[target.id];
|
||||
const countdownId = target.closest('[data-countdown]').dataset.countdown;
|
||||
const countdown = settings.countdowns[countdownId];
|
||||
|
||||
let progressMax = countdown.progress.start;
|
||||
let message = null;
|
||||
|
|
@ -180,12 +287,12 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.increasing.id
|
||||
? Number(progressMax) + 1
|
||||
: countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.decreasing.id
|
||||
? Math.max(Number(progressMax) - 1, 0)
|
||||
: progressMax;
|
||||
? Math.max(Number(progressMax) - 1, 0)
|
||||
: progressMax;
|
||||
|
||||
await waitForDiceSoNice(message);
|
||||
await settings.updateSource({
|
||||
[`countdowns.${target.id}.progress`]: {
|
||||
[`countdowns.${countdownId}.progress`]: {
|
||||
current: newMax,
|
||||
start: newMax
|
||||
}
|
||||
|
|
@ -199,22 +306,23 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
if (!DhCountdowns.canPerformEdit()) return;
|
||||
|
||||
const settings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
|
||||
const countdown = settings.countdowns[target.id];
|
||||
const countdownId = target.closest('[data-countdown]').dataset.countdown;
|
||||
const countdown = settings.countdowns[countdownId];
|
||||
const newCurrent = increase
|
||||
? Math.min(countdown.progress.current + 1, countdown.progress.start)
|
||||
: Math.max(countdown.progress.current - 1, 0);
|
||||
await settings.updateSource({ [`countdowns.${target.id}.progress.current`]: newCurrent });
|
||||
await settings.updateSource({ [`countdowns.${countdownId}.progress.current`]: newCurrent });
|
||||
await emitGMUpdate(GMUpdateEvent.UpdateCountdowns, DhCountdowns.gmSetSetting.bind(settings), settings, null, {
|
||||
refreshType: RefreshType.Countdown
|
||||
});
|
||||
}
|
||||
|
||||
static async gmSetSetting(data) {
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, data),
|
||||
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.Refresh,
|
||||
data: { refreshType: RefreshType.Countdown }
|
||||
});
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, data);
|
||||
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.Refresh,
|
||||
data: { refreshType: RefreshType.Countdown }
|
||||
});
|
||||
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
|
||||
}
|
||||
|
||||
|
|
@ -234,29 +342,31 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
* Sends updates of the countdowns to the GM player. Since this is asynchronous, be sure to
|
||||
* update all the countdowns at the same time.
|
||||
*
|
||||
* @param {...any} progressTypes Countdowns to be updated
|
||||
* @param {...(string | { type: string; undo?: boolean })} progressTypes Countdowns to be updated
|
||||
*/
|
||||
static async updateCountdowns(...progressTypes) {
|
||||
progressTypes = progressTypes.map(p => typeof p === 'string' ? { type: p } : p);
|
||||
const { countdownAutomation } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
|
||||
if (!countdownAutomation) return;
|
||||
|
||||
const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
|
||||
const updatedCountdowns = Object.keys(countdownSetting.countdowns).reduce((acc, key) => {
|
||||
const countdown = countdownSetting.countdowns[key];
|
||||
if (progressTypes.indexOf(countdown.progress.type) !== -1 && countdown.progress.current > 0) {
|
||||
acc.push(key);
|
||||
const progressData = progressTypes.find(x => x.type === countdown.progress.type);
|
||||
if (progressData && countdown.progress.current > 0) {
|
||||
acc[key] = { value: progressData.undo ? 1 : -1 };
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
}, {});
|
||||
|
||||
const countdownData = countdownSetting.toObject();
|
||||
const settings = {
|
||||
...countdownData,
|
||||
countdowns: Object.keys(countdownData.countdowns).reduce((acc, key) => {
|
||||
const countdown = foundry.utils.deepClone(countdownData.countdowns[key]);
|
||||
if (updatedCountdowns.includes(key)) {
|
||||
countdown.progress.current -= 1;
|
||||
if (updatedCountdowns[key]) {
|
||||
countdown.progress.current += updatedCountdowns[key].value;
|
||||
}
|
||||
|
||||
acc[key] = countdown;
|
||||
|
|
@ -267,12 +377,4 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
refreshType: RefreshType.Countdown
|
||||
});
|
||||
}
|
||||
|
||||
async _onRender(context, options) {
|
||||
await super._onRender(context, options);
|
||||
this.element.hidden = !game.user.isGM && this.#getCountdowns().length === 0;
|
||||
if (options?.force) {
|
||||
document.getElementById('ui-right-column-1')?.appendChild(this.element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,10 +67,10 @@ export default class DhEffectsDisplay extends HandlebarsApplicationMixin(Applica
|
|||
const actor = token
|
||||
? token.actor
|
||||
: canvas.tokens.controlled.length === 0
|
||||
? !game.user.isGM
|
||||
? game.user.character
|
||||
: null
|
||||
: canvas.tokens.controlled[0].actor;
|
||||
? !game.user.isGM
|
||||
? game.user.character
|
||||
: null
|
||||
: canvas.tokens.controlled[0].actor;
|
||||
return getIconVisibleActiveEffects(actor?.getActiveEffects() ?? []);
|
||||
};
|
||||
|
||||
|
|
|
|||
23
module/applications/ui/gamePause.mjs
Normal file
23
module/applications/ui/gamePause.mjs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
export default class DhGamePause extends foundry.applications.ui.GamePause {
|
||||
async _onRender(context, options) {
|
||||
await super._onRender(context, options);
|
||||
|
||||
/* Avoid altering the styling if a module has subscribed to the renderGamePause hook */
|
||||
if (!Hooks.events.renderGamePause?.length) {
|
||||
this.element.classList.add('dh-style');
|
||||
}
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
|
||||
/* Avoid altering the gamepause context if a module has subscribed to the renderGamePause hook */
|
||||
if (!Hooks.events.renderGamePause?.length) {
|
||||
context.spin = options.spin ?? false;
|
||||
context.icon = options.icon ?? 'systems/daggerheart/assets/logos/compatible_with_DH_logos-10.png';
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
|
@ -155,15 +155,15 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
const targetEdge = this.#getEdgeBoundary(targetBounds, originPoint, targetPoint);
|
||||
const adjustedOriginPoint = originEdge
|
||||
? canvas.grid.getTopLeftPoint({
|
||||
x: originEdge.x + Math.sign(originPoint.x - originEdge.x),
|
||||
y: originEdge.y + Math.sign(originPoint.y - originEdge.y)
|
||||
})
|
||||
x: originEdge.x + Math.sign(originPoint.x - originEdge.x),
|
||||
y: originEdge.y + Math.sign(originPoint.y - originEdge.y)
|
||||
})
|
||||
: originPoint;
|
||||
const adjustDestinationPoint = targetEdge
|
||||
? canvas.grid.getTopLeftPoint({
|
||||
x: targetEdge.x + Math.sign(targetPoint.x - targetEdge.x),
|
||||
y: targetEdge.y + Math.sign(targetPoint.y - targetEdge.y)
|
||||
})
|
||||
x: targetEdge.x + Math.sign(targetPoint.x - targetEdge.x),
|
||||
y: targetEdge.y + Math.sign(targetPoint.y - targetEdge.y)
|
||||
})
|
||||
: targetPoint;
|
||||
const distance = canvas.grid.measurePath([
|
||||
{ ...adjustedOriginPoint, elevation: 0 },
|
||||
|
|
@ -248,7 +248,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
_drawBar(number, bar, data) {
|
||||
_drawBar(index, bar, data) {
|
||||
// Determine sizing
|
||||
const { width, height } = this.document.getSize();
|
||||
const s = canvas.dimensions.uiScale;
|
||||
|
|
@ -256,9 +256,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
const bh = 8 * (this.document.height >= 2 ? 1.5 : 1) * s;
|
||||
|
||||
// Determine the color to use
|
||||
const Color = foundry.utils.Color;
|
||||
const fillColor = number === 0 ? Color.fromRGB([1, 0, 0]) : Color.fromString('#0032b1');
|
||||
const emptyColor = Color.fromRGB([0, 0, 0]);
|
||||
const { full: fullColor, empty: emptyColor } = this._getBarColors(index, data);
|
||||
|
||||
// Draw the bar (accounting floating point numbers from bar animations)
|
||||
const widthUnit = bw / Math.ceil(data.max);
|
||||
|
|
@ -268,7 +266,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
const x = mark * widthUnit;
|
||||
const marked = mark < Math.ceil(data.value);
|
||||
const remainder = mark === Math.ceil(data.value) - 1 ? data.value % 1 : 0;
|
||||
const color = !marked ? emptyColor : remainder ? emptyColor.mix(fillColor, remainder) : fillColor;
|
||||
const color = !marked ? emptyColor : remainder ? emptyColor.mix(fullColor, remainder) : fullColor;
|
||||
if (mark === 0 || mark === sections.length - 1) {
|
||||
bar.beginFill(color, marked ? 1.0 : 0.5).drawRect(x, 0, widthUnit, bh, 2 * s); // Would like drawRoundedRect, but it's very troublsome with the corners. Leaving for now.
|
||||
} else {
|
||||
|
|
@ -277,7 +275,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
}
|
||||
|
||||
// Set position
|
||||
const posY = number === 0 ? height - bh : 0;
|
||||
const posY = index === 0 ? height - bh : 0;
|
||||
bar.position.set(0, posY);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ export const itemAttachmentSource = 'attachmentSource';
|
|||
|
||||
export const userFlags = {
|
||||
welcomeMessage: 'welcome-message',
|
||||
countdownMode: 'countdown-mode'
|
||||
countdownMode: 'countdown-mode',
|
||||
countdownTypeModes: 'countdown-type-modes'
|
||||
};
|
||||
|
||||
export const combatToggle = 'combat-toggle-origin';
|
||||
|
|
|
|||
|
|
@ -867,27 +867,27 @@ export const abilityCosts = {
|
|||
export const countdownProgressionTypes = {
|
||||
actionRoll: {
|
||||
id: 'actionRoll',
|
||||
label: 'DAGGERHEART.CONFIG.CountdownType.actionRoll'
|
||||
label: 'DAGGERHEART.CONFIG.CountdownProgressType.actionRoll'
|
||||
},
|
||||
characterAttack: {
|
||||
id: 'characterAttack',
|
||||
label: 'DAGGERHEART.CONFIG.CountdownType.characterAttack'
|
||||
label: 'DAGGERHEART.CONFIG.CountdownProgressType.characterAttack'
|
||||
},
|
||||
characterSpotlight: {
|
||||
id: 'characterSpotlight',
|
||||
label: 'DAGGERHEART.CONFIG.CountdownType.characterSpotlight'
|
||||
label: 'DAGGERHEART.CONFIG.CountdownProgressType.characterSpotlight'
|
||||
},
|
||||
custom: {
|
||||
id: 'custom',
|
||||
label: 'DAGGERHEART.CONFIG.CountdownType.custom'
|
||||
label: 'DAGGERHEART.CONFIG.CountdownProgressType.custom'
|
||||
},
|
||||
fear: {
|
||||
id: 'fear',
|
||||
label: 'DAGGERHEART.CONFIG.CountdownType.fear'
|
||||
label: 'DAGGERHEART.CONFIG.CountdownProgressType.fear'
|
||||
},
|
||||
spotlight: {
|
||||
id: 'spotlight',
|
||||
label: 'DAGGERHEART.CONFIG.CountdownType.spotlight'
|
||||
label: 'DAGGERHEART.CONFIG.CountdownProgressType.spotlight'
|
||||
}
|
||||
};
|
||||
export const rollTypes = {
|
||||
|
|
@ -935,17 +935,6 @@ export const simpleOwnershiplevels = {
|
|||
...basicOwnershiplevels
|
||||
};
|
||||
|
||||
export const countdownBaseTypes = {
|
||||
narrative: {
|
||||
id: 'narrative',
|
||||
label: 'DAGGERHEART.APPLICATIONS.Countdown.types.narrative'
|
||||
},
|
||||
encounter: {
|
||||
id: 'encounter',
|
||||
label: 'DAGGERHEART.APPLICATIONS.Countdown.types.encounter'
|
||||
}
|
||||
};
|
||||
|
||||
export const countdownLoopingTypes = {
|
||||
noLooping: {
|
||||
id: 'noLooping',
|
||||
|
|
@ -970,6 +959,19 @@ export const countdownAppMode = {
|
|||
iconOnly: 'icon-only'
|
||||
};
|
||||
|
||||
export const countdownTypes = {
|
||||
encounter: {
|
||||
id: 'encounter',
|
||||
label: 'DAGGERHEART.CONFIG.CountdownType.encounter.label',
|
||||
shortLabel: 'DAGGERHEART.CONFIG.CountdownType.encounter.shortLabel'
|
||||
},
|
||||
narrative: {
|
||||
id: 'narrative',
|
||||
label: 'DAGGERHEART.CONFIG.CountdownType.narrative.label',
|
||||
shortLabel: 'DAGGERHEART.CONFIG.CountdownType.narrative.shortLabel'
|
||||
}
|
||||
};
|
||||
|
||||
export const sceneRangeMeasurementSetting = {
|
||||
disable: {
|
||||
id: 'disable',
|
||||
|
|
|
|||
|
|
@ -127,8 +127,8 @@ export const typeConfig = {
|
|||
isSecondary
|
||||
? 'DAGGERHEART.ITEMS.Weapon.secondaryWeapon.short'
|
||||
: isSecondary === false
|
||||
? 'DAGGERHEART.ITEMS.Weapon.primaryWeapon.short'
|
||||
: '-'
|
||||
? 'DAGGERHEART.ITEMS.Weapon.primaryWeapon.short'
|
||||
: '-'
|
||||
},
|
||||
{
|
||||
key: 'system.tier',
|
||||
|
|
|
|||
|
|
@ -79,8 +79,8 @@ export default class DHAttackAction extends DHDamageAction {
|
|||
const str = damageString
|
||||
? damageString
|
||||
: game.i18n.format('DAGGERHEART.GENERAL.missingX', {
|
||||
x: game.i18n.localize('DAGGERHEART.GENERAL.damage')
|
||||
});
|
||||
x: game.i18n.localize('DAGGERHEART.GENERAL.damage')
|
||||
});
|
||||
|
||||
const icons = Array.from(type)
|
||||
.map(t => CONFIG.DH.GENERAL.damageTypes[t]?.icon)
|
||||
|
|
|
|||
|
|
@ -54,6 +54,10 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
return {};
|
||||
}
|
||||
|
||||
get hasDescription() {
|
||||
return Boolean(this.description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Map containing each Action step based on fields define in schema. Ordered by Fields order property.
|
||||
*
|
||||
|
|
@ -144,8 +148,8 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
return this.item instanceof DhpActor
|
||||
? this.item
|
||||
: this.item?.parent instanceof DhpActor
|
||||
? this.item.parent
|
||||
: null;
|
||||
? this.item.parent
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -223,12 +227,13 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
* @returns {object}
|
||||
*/
|
||||
async use(event, configOptions = {}) {
|
||||
if (!this.actor) throw new Error("An Action can't be used outside of an Actor context.");
|
||||
if (!this.actor) throw new Error('An Action can\'t be used outside of an Actor context.');
|
||||
|
||||
let config = this.prepareConfig(event, configOptions);
|
||||
if (!config) return;
|
||||
|
||||
config.effects = await game.system.api.data.actions.actionsTypes.base.getEffects(this.actor, this.item);
|
||||
config.effects =
|
||||
await game.system.api.data.actions.actionsTypes.base.getActionRelevantEffects(this.actor, this.item);
|
||||
|
||||
if (Hooks.call(`${CONFIG.DH.id}.preUseAction`, this, config) === false) return;
|
||||
|
||||
|
|
@ -300,17 +305,17 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
|
||||
const groupAttackTokens = this.damage.groupAttack
|
||||
? game.system.api.fields.ActionFields.DamageField.getGroupAttackTokens(
|
||||
this.actor.id,
|
||||
this.damage.groupAttack
|
||||
)
|
||||
this.actor.id,
|
||||
this.damage.groupAttack
|
||||
)
|
||||
: null;
|
||||
|
||||
config.damageOptions = {
|
||||
groupAttack: this.damage.groupAttack
|
||||
? {
|
||||
numAttackers: Math.max(groupAttackTokens.length, 1),
|
||||
range: this.damage.groupAttack
|
||||
}
|
||||
numAttackers: Math.max(groupAttackTokens.length, 1),
|
||||
range: this.damage.groupAttack
|
||||
}
|
||||
: null
|
||||
};
|
||||
}
|
||||
|
|
@ -333,27 +338,45 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the all potentially applicable effects on the actor
|
||||
* Get the all potentially applicable effects on the actor for the action's RollDialog
|
||||
* @param {DHActor} actor The actor performing the action
|
||||
* @param {DHItem|DhActor} effectParent The parent of the effect
|
||||
* @returns {DhActiveEffect[]}
|
||||
*/
|
||||
static async getEffects(actor, effectParent) {
|
||||
static async getActionRelevantEffects(actor, effectParent) {
|
||||
if (!actor) return [];
|
||||
|
||||
return Array.from(await actor.allApplicableEffects({ noTransferArmor: true, noSelfArmor: true })).filter(
|
||||
effect => {
|
||||
/* Effects on weapons only ever apply for the weapon itself */
|
||||
if (effect.parent.type === 'weapon') {
|
||||
/* Unless they're secondary - then they apply only to other primary weapons */
|
||||
if (effect.parent.system.secondary) {
|
||||
if (effectParent?.type !== 'weapon' || effectParent?.system.secondary) return false;
|
||||
} else if (effectParent?.id !== effect.parent.id) return false;
|
||||
}
|
||||
// Changes on weapon effects are not typically only applicable to show in the roll dialog for the weapon itself
|
||||
// The exemptions to this rule are listed below
|
||||
const weaponTransferredEffectKeys = [
|
||||
'system.bonuses.roll.spellcast.bonus'
|
||||
];
|
||||
|
||||
return !effect.isSuppressed;
|
||||
const results = [];
|
||||
const applicableEffects = await actor.allApplicableEffects({ noTransferArmor: true, noSelfArmor: true });
|
||||
for (const effect of [...applicableEffects].filter(e => !e.isSuppressed)) {
|
||||
if (effect.parent.type === 'weapon') {
|
||||
// Effects on weapons only ever apply for the weapon itself (with a few exceptions)
|
||||
const restricted =
|
||||
effect.parent.system.secondary
|
||||
// Secondary applies only to other primary weapons
|
||||
? effectParent?.type !== 'weapon' || effectParent?.system.secondary
|
||||
// Primary only applies to itself
|
||||
: effectParent?.id !== effect.parent.id;
|
||||
if (restricted) {
|
||||
const sourceChanges = effect._source.system.changes;
|
||||
const changes = sourceChanges.filter(x => weaponTransferredEffectKeys.includes(x.key));
|
||||
if (changes.length) {
|
||||
results.push(effect.clone({ 'system.changes': changes }));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
results.push(effect);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -428,7 +451,15 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
|
||||
static migrateData(source) {
|
||||
if (source.damage?.parts && Array.isArray(source.damage.parts)) {
|
||||
let hitPointsExists = source.damage.parts.some(x => x.applyTo === 'hitPoints');
|
||||
source.damage.parts = source.damage.parts.reduce((acc, part) => {
|
||||
if (!part.applyTo && hitPointsExists) return acc;
|
||||
|
||||
if (!part.applyTo) {
|
||||
hitPointsExists = true;
|
||||
part.applyTo = 'hitPoints';
|
||||
}
|
||||
|
||||
acc[part.applyTo] = part;
|
||||
return acc;
|
||||
}, {});
|
||||
|
|
@ -459,8 +490,7 @@ export class ResourceUpdateMap extends Map {
|
|||
} else if (!existing?.clear) {
|
||||
this.set(resource.key, {
|
||||
...existing,
|
||||
value: existing.value + (resource.value ?? 0),
|
||||
total: existing.total + (resource.total ?? 0)
|
||||
value: existing.value + (resource.value ?? 0)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,13 +90,13 @@ export default class BeastformEffect extends BaseEffect {
|
|||
...baseUpdate,
|
||||
x,
|
||||
y,
|
||||
'texture': {
|
||||
texture: {
|
||||
enabled: this.characterTokenData.usesDynamicToken,
|
||||
src: token.flags.daggerheart?.beastformTokenImg ?? this.characterTokenData.tokenImg,
|
||||
scaleX: this.characterTokenData.tokenSize.scale,
|
||||
scaleY: this.characterTokenData.tokenSize.scale
|
||||
},
|
||||
'ring': {
|
||||
ring: {
|
||||
subject: {
|
||||
texture:
|
||||
token.flags.daggerheart?.beastformSubjectTexture ?? this.characterTokenData.tokenRingImg
|
||||
|
|
|
|||
|
|
@ -166,10 +166,10 @@ export default class ArmorChange extends foundry.abstract.DataModel {
|
|||
value:
|
||||
change.type === 'armor'
|
||||
? {
|
||||
...change.value,
|
||||
current: Math.min(change.value.current, newMax),
|
||||
max: newMax
|
||||
}
|
||||
...change.value,
|
||||
current: Math.min(change.value.current, newMax),
|
||||
max: newMax
|
||||
}
|
||||
: change.value
|
||||
}))
|
||||
];
|
||||
|
|
|
|||
14
module/data/actor/_types.d.ts
vendored
Normal file
14
module/data/actor/_types.d.ts
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import DhpActor from '../../documents/actor.mjs'
|
||||
import DhCharacter from './character.mjs';
|
||||
|
||||
declare module './base.mjs' {
|
||||
export default interface BaseDataActor {
|
||||
parent: DhpActor<this>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module './companion.mjs' {
|
||||
export default interface DhCompanion {
|
||||
partner: DhpActor<DhCharacter>;
|
||||
}
|
||||
}
|
||||
|
|
@ -87,6 +87,7 @@ export default class DhpAdversary extends DhCreature {
|
|||
parts: {
|
||||
hitPoints: {
|
||||
type: ['physical'],
|
||||
applyTo: 'hitPoints',
|
||||
value: {
|
||||
multiplier: 'flat'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
import DHBaseActorSettings from '../../applications/sheets/api/actor-setting.mjs';
|
||||
import DHItem from '../../documents/item.mjs';
|
||||
import { createShallowProxy, getScrollTextData } from '../../helpers/utils.mjs';
|
||||
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
/**
|
||||
* @import DHItem from '../../documents/item.mjs';
|
||||
* @import DHBaseActorSettings from '../../applications/sheets/api/actor-setting.mjs';
|
||||
*/
|
||||
|
||||
/** Function to generate resistance fields for damage types */
|
||||
const resistanceField = (resistanceLabel, immunityLabel, reductionLabel) =>
|
||||
new fields.SchemaField({
|
||||
resistance: new fields.BooleanField({
|
||||
|
|
@ -96,6 +100,8 @@ export const commonActorRules = (extendedData = { damageReduction: {}, attack: {
|
|||
* @property {Boolean} isNPC - This data model represents a NPC?
|
||||
* @property {typeof DHBaseActorSettings} settingSheet - The sheet class used to render the settings UI for this actor type.
|
||||
*/
|
||||
|
||||
/** Base actor type data model for all actors in Daggerheart */
|
||||
export default class BaseDataActor extends foundry.abstract.TypeDataModel {
|
||||
/** @returns {ActorDataModelMetadata}*/
|
||||
static get metadata() {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,18 @@ export default class DhCharacter extends DhCreature {
|
|||
core: new fields.BooleanField({ initial: false })
|
||||
})
|
||||
),
|
||||
gold: new GoldField(),
|
||||
gold: new GoldField({
|
||||
initial: () => {
|
||||
const homebrew = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew);
|
||||
const { coins, handfuls, bags, chests } = homebrew.currency;
|
||||
return {
|
||||
coins: coins.enabled ? coins.initialAmount : 0,
|
||||
handfuls: handfuls.enabled ? handfuls.initialAmount : 0,
|
||||
bags: bags.enabled ? bags.initialAmount : 0,
|
||||
chests: chests.enabled ? chests.initialAmount : 0
|
||||
};
|
||||
}
|
||||
}),
|
||||
scars: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.GENERAL.scars' }),
|
||||
biography: new fields.SchemaField({
|
||||
background: new fields.HTMLField(),
|
||||
|
|
@ -96,6 +107,7 @@ export default class DhCharacter extends DhCreature {
|
|||
parts: {
|
||||
hitPoints: {
|
||||
type: ['physical'],
|
||||
applyTo: 'hitPoints',
|
||||
value: {
|
||||
custom: {
|
||||
enabled: true,
|
||||
|
|
@ -304,7 +316,12 @@ export default class DhCharacter extends DhCreature {
|
|||
label: 'DAGGERHEART.ACTORS.Character.defaultDisadvantageDice'
|
||||
})
|
||||
})
|
||||
})
|
||||
}),
|
||||
/** Accumulated armor score from all sources */
|
||||
armorScore: new fields.SchemaField({
|
||||
value: new fields.NumberField(),
|
||||
max: new fields.NumberField()
|
||||
}, { persisted: false })
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -315,8 +332,8 @@ export default class DhCharacter extends DhCreature {
|
|||
return currentLevel === 1
|
||||
? 1
|
||||
: Object.values(game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers).find(
|
||||
tier => currentLevel >= tier.levels.start && currentLevel <= tier.levels.end
|
||||
).tier;
|
||||
tier => currentLevel >= tier.levels.start && currentLevel <= tier.levels.end
|
||||
).tier;
|
||||
}
|
||||
|
||||
get ancestry() {
|
||||
|
|
@ -400,8 +417,8 @@ export default class DhCharacter extends DhCreature {
|
|||
|
||||
get domainCards() {
|
||||
const domainCards = this.parent.items.filter(x => x.type === 'domainCard');
|
||||
const loadout = domainCards.filter(x => !x.system.inVault);
|
||||
const vault = domainCards.filter(x => x.system.inVault);
|
||||
const loadout = domainCards.filter(x => !x.system.inVault).sort((a, b) => a.sort - b.sort);
|
||||
const vault = domainCards.filter(x => x.system.inVault).sort((a, b) => a.sort - b.sort);
|
||||
|
||||
return {
|
||||
loadout: loadout,
|
||||
|
|
@ -520,20 +537,20 @@ export default class DhCharacter extends DhCreature {
|
|||
|
||||
if (armorSource.type === 'armor') {
|
||||
armorUpdates[armorSource.parent.id].updates.push({
|
||||
'_id': armorSource.id,
|
||||
_id: armorSource.id,
|
||||
'system.armor.current': armorSource.system.armor.current + usedArmorChange
|
||||
});
|
||||
} else {
|
||||
effectUpdates[armorSource.parent.id].updates.push({
|
||||
'_id': armorSource.id,
|
||||
_id: armorSource.id,
|
||||
'system.changes': armorSource.system.changes.map(change => ({
|
||||
...change,
|
||||
value:
|
||||
change.type === 'armor'
|
||||
? {
|
||||
...change.value,
|
||||
current: armorSource.system.armorChange.value.current + usedArmorChange
|
||||
}
|
||||
...change.value,
|
||||
current: armorSource.system.armorChange.value.current + usedArmorChange
|
||||
}
|
||||
: change.value
|
||||
}))
|
||||
});
|
||||
|
|
@ -621,21 +638,21 @@ export default class DhCharacter extends DhCreature {
|
|||
},
|
||||
...(multiclassFeatures.length
|
||||
? {
|
||||
multiclassFeatures: {
|
||||
title: `${game.i18n.localize('DAGGERHEART.GENERAL.multiclass')} - ${this.multiclass.value?.name}`,
|
||||
type: 'multiclass',
|
||||
values: multiclassFeatures
|
||||
}
|
||||
}
|
||||
multiclassFeatures: {
|
||||
title: `${game.i18n.localize('DAGGERHEART.GENERAL.multiclass')} - ${this.multiclass.value?.name}`,
|
||||
type: 'multiclass',
|
||||
values: multiclassFeatures
|
||||
}
|
||||
}
|
||||
: {}),
|
||||
...(multiclassSubclassFeatures.length
|
||||
? {
|
||||
multiclassSubclassFeatures: {
|
||||
title: `${game.i18n.localize('DAGGERHEART.GENERAL.multiclass')} ${game.i18n.localize('TYPES.Item.subclass')} - ${this.multiclass.subclass?.name}`,
|
||||
type: 'multiclassSubclass',
|
||||
values: multiclassSubclassFeatures
|
||||
}
|
||||
}
|
||||
multiclassSubclassFeatures: {
|
||||
title: `${game.i18n.localize('DAGGERHEART.GENERAL.multiclass')} ${game.i18n.localize('TYPES.Item.subclass')} - ${this.multiclass.subclass?.name}`,
|
||||
type: 'multiclassSubclass',
|
||||
values: multiclassSubclassFeatures
|
||||
}
|
||||
}
|
||||
: {}),
|
||||
companionFeatures: {
|
||||
title: game.i18n.localize('DAGGERHEART.ACTORS.Character.companionFeatures'),
|
||||
|
|
@ -659,8 +676,8 @@ export default class DhCharacter extends DhCreature {
|
|||
(this.primaryWeapon && this.secondaryWeapon)
|
||||
? burden.twoHanded.value
|
||||
: this.primaryWeapon || this.secondaryWeapon
|
||||
? burden.oneHanded.value
|
||||
: null;
|
||||
? burden.oneHanded.value
|
||||
: null;
|
||||
}
|
||||
|
||||
get deathMoveViable() {
|
||||
|
|
@ -726,8 +743,8 @@ export default class DhCharacter extends DhCreature {
|
|||
currentLevel === 1
|
||||
? null
|
||||
: Object.values(game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers).find(
|
||||
tier => currentLevel >= tier.levels.start && currentLevel <= tier.levels.end
|
||||
).tier;
|
||||
tier => currentLevel >= tier.levels.start && currentLevel <= tier.levels.end
|
||||
).tier;
|
||||
if (game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto) {
|
||||
for (let levelKey in this.levelData.levelups) {
|
||||
const level = this.levelData.levelups[levelKey];
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ export default class DhCompanion extends DhCreature {
|
|||
parts: {
|
||||
hitPoints: {
|
||||
type: ['physical'],
|
||||
applyTo: 'hitPoints',
|
||||
value: {
|
||||
dice: 'd6',
|
||||
multiplier: 'prof'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { calculateExpectedValue, parseTermsFromSimpleFormula } from '../../helpers/utils.mjs';
|
||||
import { adversaryExpectedDamage, adversaryScalingData } from '../../config/actorConfig.mjs';
|
||||
import { parseInlineParams } from '../../enrichers/parser.mjs';
|
||||
|
||||
export function getTierAdjustedAdversary(source, tier) {
|
||||
const currentTier = source.tier ?? 1;
|
||||
|
|
@ -60,8 +61,8 @@ export function getTierAdjustedAdversary(source, tier) {
|
|||
const descriptionFormulas = [];
|
||||
for (const withDescription of [item.system, ...Object.values(item.system.actions)]) {
|
||||
withDescription.description = withDescription.description.replace(damageRegex, (match, inner) => {
|
||||
const { value: formula } = parseInlineParams(inner);
|
||||
if (!formula || !type) return match;
|
||||
const { value: formula } = parseInlineParams(inner, { first: 'value' });
|
||||
if (!formula) return match;
|
||||
|
||||
try {
|
||||
const newFormula = calculateAdjustedDamage(formula, 'action', damageMeta)?.formula;
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ export class DhCompanionLevelup extends foundry.abstract.DataModel {
|
|||
const initialAchievements = i === tier.levels.start ? tier.initialAchievements : {};
|
||||
const experiences = initialAchievements.experience
|
||||
? [...Array(initialAchievements.experience.nr).keys()].reduce((acc, _) => {
|
||||
acc[foundry.utils.randomID()] = {
|
||||
name: '',
|
||||
modifier: initialAchievements.experience.modifier
|
||||
};
|
||||
return acc;
|
||||
}, {})
|
||||
acc[foundry.utils.randomID()] = {
|
||||
name: '',
|
||||
modifier: initialAchievements.experience.modifier
|
||||
};
|
||||
return acc;
|
||||
}, {})
|
||||
: {};
|
||||
|
||||
const currentChoices = pcLevelData.levelups[i]?.selections?.length;
|
||||
|
|
@ -302,9 +302,9 @@ export class DhLevelupLevel extends foundry.abstract.DataModel {
|
|||
experiences: levelData.achievements?.experiences ?? achievements.experiences ?? {},
|
||||
domainCards: levelData.achievements?.domainCards
|
||||
? levelData.achievements.domainCards.reduce((acc, card, index) => {
|
||||
acc[index] = { ...card };
|
||||
return acc;
|
||||
}, {})
|
||||
acc[index] = { ...card };
|
||||
return acc;
|
||||
}, {})
|
||||
: (achievements.domainCards ?? {}),
|
||||
proficiency: levelData.achievements?.proficiency ?? achievements.proficiency ?? null
|
||||
},
|
||||
|
|
|
|||
|
|
@ -13,6 +13,54 @@ export default class DhCountdowns extends foundry.abstract.DataModel {
|
|||
})
|
||||
};
|
||||
}
|
||||
|
||||
handleChange() {
|
||||
const previousCountdowns = foundry.ui.countdowns.previousCountdownData;
|
||||
const changedCountdowns = Object.entries(this.countdowns).reduce((acc, [key, countdown]) => {
|
||||
const previousCountdown = previousCountdowns[key];
|
||||
if (!previousCountdown || (previousCountdown.progress.current !== countdown.progress.current)) {
|
||||
acc.push(key);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
for (const countdownKey of changedCountdowns)
|
||||
foundry.ui.countdowns.changedCountdownsForAnimation.add(countdownKey);
|
||||
}
|
||||
|
||||
static migrateData(source) {
|
||||
const migrateOldCountdowns = (data, type) => {
|
||||
for (const key of Object.keys(data.countdowns)) {
|
||||
const countdown = data.countdowns[key];
|
||||
source.countdowns[key] = {
|
||||
...countdown,
|
||||
type: type,
|
||||
ownership: Object.keys(countdown.ownership.players).reduce((acc, key) => {
|
||||
acc[key] =
|
||||
countdown.ownership.players[key].type === 1 ? 2 : countdown.ownership.players[key].type;
|
||||
return acc;
|
||||
}, {}),
|
||||
progress: {
|
||||
...countdown.progress,
|
||||
type: countdown.progress.type.value
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
source[type] = null;
|
||||
};
|
||||
|
||||
if (source.narrative) {
|
||||
migrateOldCountdowns(source.narrative, 'narrative');
|
||||
}
|
||||
|
||||
if (source.encounter) {
|
||||
migrateOldCountdowns(source.encounter, 'encounter');
|
||||
}
|
||||
|
||||
return super.migrateData(source);
|
||||
}
|
||||
}
|
||||
|
||||
export class DhCountdown extends foundry.abstract.DataModel {
|
||||
|
|
@ -21,7 +69,8 @@ export class DhCountdown extends foundry.abstract.DataModel {
|
|||
return {
|
||||
type: new fields.StringField({
|
||||
required: true,
|
||||
choices: CONFIG.DH.GENERAL.countdownBaseTypes,
|
||||
choices: CONFIG.DH.GENERAL.countdownTypes,
|
||||
initial: CONFIG.DH.GENERAL.countdownTypes.encounter.id,
|
||||
label: 'DAGGERHEART.GENERAL.type'
|
||||
}),
|
||||
name: new fields.StringField({
|
||||
|
|
@ -77,15 +126,15 @@ export class DhCountdown extends foundry.abstract.DataModel {
|
|||
static defaultCountdown(type, playerHidden) {
|
||||
const ownership = playerHidden
|
||||
? game.users.reduce((acc, user) => {
|
||||
if (!user.isGM) {
|
||||
acc[user.id] = CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE;
|
||||
}
|
||||
return acc;
|
||||
}, {})
|
||||
if (!user.isGM) {
|
||||
acc[user.id] = CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE;
|
||||
}
|
||||
return acc;
|
||||
}, {})
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
type: type ?? CONFIG.DH.GENERAL.countdownBaseTypes.narrative.id,
|
||||
type: type ?? CONFIG.DH.GENERAL.countdownTypes.encounter.id,
|
||||
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Countdown.newCountdown'),
|
||||
img: 'icons/magic/time/hourglass-yellow-green.webp',
|
||||
ownership: ownership,
|
||||
|
|
@ -102,8 +151,8 @@ export class DhCountdown extends foundry.abstract.DataModel {
|
|||
value: user.isGM
|
||||
? CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER
|
||||
: this.ownership.players[user.id] && this.ownership.players[user.id].type !== -1
|
||||
? this.ownership.players[user.id].type
|
||||
: this.ownership.default,
|
||||
? this.ownership.players[user.id].type
|
||||
: this.ownership.default,
|
||||
isGM: user.isGM
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -105,8 +105,8 @@ export default class BeastformField extends fields.SchemaField {
|
|||
baseSize === 'custom'
|
||||
? 'custom'
|
||||
: (Object.keys(CONFIG.DH.ACTOR.tokenSize).find(
|
||||
x => CONFIG.DH.ACTOR.tokenSize[x].value === CONFIG.DH.ACTOR.tokenSize[baseSize].value + 1
|
||||
) ?? baseSize);
|
||||
x => CONFIG.DH.ACTOR.tokenSize[x].value === CONFIG.DH.ACTOR.tokenSize[baseSize].value + 1
|
||||
) ?? baseSize);
|
||||
formData.system.tokenSize = {
|
||||
...evolvedData.form.system.tokenSize,
|
||||
size: evolvedSize
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ export default class CostField extends fields.ArrayField {
|
|||
c.key === 'fear'
|
||||
? game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear)
|
||||
: resources[c.key].isReversed
|
||||
? resources[c.key].max - resources[c.key].value
|
||||
: resources[c.key].value;
|
||||
? resources[c.key].max - resources[c.key].value
|
||||
: resources[c.key].value;
|
||||
if (c.scalable) c.maxStep = Math.floor((c.max - c.value) / c.step);
|
||||
return c;
|
||||
});
|
||||
|
|
@ -149,8 +149,8 @@ export default class CostField extends fields.ArrayField {
|
|||
!resources[c.key]
|
||||
? a
|
||||
: a && resources[c.key].isReversed
|
||||
? resources[c.key].value + (c.total ?? c.value) <= resources[c.key].max
|
||||
: resources[c.key]?.value >= (c.total ?? c.value),
|
||||
? resources[c.key].value + (c.total ?? c.value) <= resources[c.key].max
|
||||
: resources[c.key]?.value >= (c.total ?? c.value),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ export default class CountdownField extends fields.ArrayField {
|
|||
...game.system.api.data.countdowns.DhCountdown.defineSchema(),
|
||||
type: new fields.StringField({
|
||||
required: true,
|
||||
choices: CONFIG.DH.GENERAL.countdownBaseTypes,
|
||||
initial: CONFIG.DH.GENERAL.countdownBaseTypes.encounter.id,
|
||||
choices: CONFIG.DH.GENERAL.countdownTypes,
|
||||
initial: CONFIG.DH.GENERAL.countdownTypes.encounter.id,
|
||||
label: 'DAGGERHEART.GENERAL.type'
|
||||
}),
|
||||
name: new fields.StringField({
|
||||
|
|
@ -87,11 +87,11 @@ export default class CountdownField extends fields.ArrayField {
|
|||
CONFIG.DH.id,
|
||||
CONFIG.DH.SETTINGS.gameSettings.Countdowns,
|
||||
countdownSetting.toObject()
|
||||
),
|
||||
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.Refresh,
|
||||
data: { refreshType: RefreshType.Countdown }
|
||||
});
|
||||
);
|
||||
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.Refresh,
|
||||
data: { refreshType: RefreshType.Countdown }
|
||||
});
|
||||
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
|
||||
},
|
||||
data,
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@ export default class EffectsField extends fields.ArrayField {
|
|||
token: messageToken,
|
||||
conditionImmunities: Object.values(conditionImmunities).some(x => x)
|
||||
? game.i18n.format('DAGGERHEART.UI.Chat.effectSummary.immunityTo', {
|
||||
immunities: Object.keys(conditionImmunities)
|
||||
.filter(x => conditionImmunities[x])
|
||||
.map(x => game.i18n.localize(conditions[x].name))
|
||||
.join(', ')
|
||||
})
|
||||
immunities: Object.keys(conditionImmunities)
|
||||
.filter(x => conditionImmunities[x])
|
||||
.map(x => game.i18n.localize(conditions[x].name))
|
||||
.join(', ')
|
||||
})
|
||||
: null
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -69,11 +69,11 @@ export default class SaveField extends fields.SchemaField {
|
|||
game.user === actor.owner
|
||||
? SaveField.rollSave.call(this, actor, event)
|
||||
: actor.owner.query('reactionRoll', {
|
||||
actionId: this.uuid,
|
||||
actorId: actor.uuid,
|
||||
event,
|
||||
message
|
||||
});
|
||||
actionId: this.uuid,
|
||||
actorId: actor.uuid,
|
||||
event,
|
||||
message
|
||||
});
|
||||
const result = await rollSave;
|
||||
await SaveField.updateSaveMessage.call(this, result, message, target.id);
|
||||
subResolve();
|
||||
|
|
@ -97,8 +97,8 @@ export default class SaveField extends fields.SchemaField {
|
|||
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)
|
||||
}),
|
||||
ability: game.i18n.localize(abilities[this.save.trait]?.label)
|
||||
}),
|
||||
rollConfig = {
|
||||
event,
|
||||
title,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { itemAbleRollParse, triggerChatRollFx } from '../../../helpers/utils.mjs';
|
||||
import { getWorldActor, itemAbleRollParse, triggerChatRollFx } from '../../../helpers/utils.mjs';
|
||||
import FormulaField from '../formulaField.mjs';
|
||||
|
||||
const fields = foundry.data.fields;
|
||||
|
|
@ -42,7 +42,7 @@ export default class DHSummonField extends fields.ArrayField {
|
|||
const count = roll.total;
|
||||
if (!roll.isDeterministic) rolls.push(roll);
|
||||
|
||||
const actor = await DHSummonField.getWorldActor(await foundry.utils.fromUuid(summon.actorUUID));
|
||||
const actor = await getWorldActor(await foundry.utils.fromUuid(summon.actorUUID));
|
||||
/* Extending summon data in memory so it's available in actionField.toChat. Think it's harmless, but ugly. Could maybe find a better way. */
|
||||
summon.actor = actor.toObject();
|
||||
|
||||
|
|
@ -62,19 +62,6 @@ export default class DHSummonField extends fields.ArrayField {
|
|||
DHSummonField.handleSummon(summonData, this.actor);
|
||||
}
|
||||
|
||||
/* Check for any available instances of the actor present in the world if we're missing artwork in the compendium. If none exists, create one. */
|
||||
static async getWorldActor(baseActor) {
|
||||
const dataType = game.system.api.data.actors[`Dh${baseActor.type.capitalize()}`];
|
||||
if (baseActor.inCompendium && dataType && baseActor.img === dataType.DEFAULT_ICON) {
|
||||
const worldActorCopy = game.actors.find(x => x.name === baseActor.name);
|
||||
if (worldActorCopy) return worldActorCopy;
|
||||
|
||||
return await game.system.api.documents.DhpActor.create(baseActor.toObject());
|
||||
}
|
||||
|
||||
return baseActor;
|
||||
}
|
||||
|
||||
static async handleSummon(summonData, actionActor) {
|
||||
await CONFIG.ux.TokenManager.createTokensWithPreview(summonData, { elevation: actionActor.token?.elevation });
|
||||
|
||||
|
|
|
|||
|
|
@ -116,13 +116,16 @@ class ResourcesField extends fields.TypedObjectField {
|
|||
}
|
||||
|
||||
class GoldField extends fields.SchemaField {
|
||||
constructor() {
|
||||
super({
|
||||
coins: new fields.NumberField({ initial: 0, integer: true }),
|
||||
handfuls: new fields.NumberField({ initial: 1, integer: true }),
|
||||
bags: new fields.NumberField({ initial: 0, integer: true }),
|
||||
chests: new fields.NumberField({ initial: 0, integer: true })
|
||||
});
|
||||
constructor(options = {}) {
|
||||
super(
|
||||
{
|
||||
coins: new fields.NumberField({ initial: 0, integer: true }),
|
||||
handfuls: new fields.NumberField({ initial: 1, integer: true }),
|
||||
bags: new fields.NumberField({ initial: 0, integer: true }),
|
||||
chests: new fields.NumberField({ initial: 0, integer: true })
|
||||
},
|
||||
options
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export default class FormulaField extends foundry.data.fields.StringField {
|
|||
let roll = null;
|
||||
try {
|
||||
roll = new Roll(value.replace(/@([a-z.0-9_-]+)/gi, '1'));
|
||||
} catch (_) {
|
||||
} catch {
|
||||
roll = new Roll(value.replace(/@([a-z.0-9_-]+)/gi, 'd6'));
|
||||
}
|
||||
roll.evaluateSync({ strict: false });
|
||||
|
|
|
|||
8
module/data/item/_types.d.ts
vendored
Normal file
8
module/data/item/_types.d.ts
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import DHItem from '../../documents/item.mjs';
|
||||
|
||||
declare module './base.mjs' {
|
||||
export default interface BaseDataItem {
|
||||
parent: DHItem<this>;
|
||||
actor: DhpActor;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import ItemLinkFields from '../../data/fields/itemLinkFields.mjs';
|
||||
import { getFeaturesHTMLData } from '../../helpers/utils.mjs';
|
||||
import { fromUuids, getFeaturesHTMLData } from '../../helpers/utils.mjs';
|
||||
|
||||
export default class DHAncestry extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -45,6 +45,10 @@ export default class DHAncestry extends BaseDataItem {
|
|||
|
||||
/**@inheritdoc */
|
||||
async getDescriptionData() {
|
||||
// Preload all ancestry features for acquisition from the cache
|
||||
// todo: make feature acquisition async and replace feature helpers for methods
|
||||
await fromUuids(this._source.features.map(f => f.item));
|
||||
|
||||
const baseDescription = this.description;
|
||||
const features = await getFeaturesHTMLData(this.features);
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ export default class DHArmor extends AttachableItem {
|
|||
);
|
||||
}
|
||||
|
||||
get itemFeatures() {
|
||||
return this.armorFeatures;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async getDescriptionData() {
|
||||
const baseDescription = this.description;
|
||||
|
|
@ -169,8 +173,4 @@ export default class DHArmor extends AttachableItem {
|
|||
const labels = [`${game.i18n.localize('DAGGERHEART.ITEMS.Armor.baseScore')}: ${this.armor.max}`];
|
||||
return labels;
|
||||
}
|
||||
|
||||
get itemFeatures() {
|
||||
return this.armorFeatures;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,8 +208,8 @@ export default class DHBeastform extends BaseDataItem {
|
|||
const autoTokenSize =
|
||||
this.tokenSize.size !== 'custom'
|
||||
? game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes[
|
||||
this.tokenSize.size
|
||||
]
|
||||
this.tokenSize.size
|
||||
]
|
||||
: null;
|
||||
const width = autoTokenSize ?? this.tokenSize.width;
|
||||
const height = autoTokenSize ?? this.tokenSize.height;
|
||||
|
|
|
|||
|
|
@ -70,14 +70,14 @@ export default class DHClass extends BaseDataItem {
|
|||
}
|
||||
|
||||
async fetchSubclasses() {
|
||||
const uuids = [this.parent.uuid, this.parent._stats?.compendiumSource].filter(u => !!u);
|
||||
const subclasses = game.items.filter(x => x.type === 'subclass' && uuids.includes(x.system.linkedClass));
|
||||
const sourceUuid = this.parent.sourceUuid;
|
||||
const subclasses = game.items.filter(x => x.type === 'subclass' && x.system.linkedClass === sourceUuid);
|
||||
for (const pack of game.packs) {
|
||||
const packIds = [];
|
||||
const indexes = await pack.getIndex({ fields: ['system.linkedClass'] });
|
||||
for (const index of indexes) {
|
||||
if (index.type !== 'subclass') continue;
|
||||
if (!uuids.includes(index.system?.linkedClass)) continue;
|
||||
if (index.system?.linkedClass !== sourceUuid) continue;
|
||||
if (subclasses.find(x => x.uuid === index.uuid)) continue;
|
||||
packIds.push(index._id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { getFeaturesHTMLData } from '../../helpers/utils.mjs';
|
||||
import { fromUuids, getFeaturesHTMLData } from '../../helpers/utils.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
import BaseDataItem from './base.mjs';
|
||||
|
||||
|
|
@ -27,6 +27,10 @@ export default class DHCommunity extends BaseDataItem {
|
|||
|
||||
/**@inheritdoc */
|
||||
async getDescriptionData() {
|
||||
// Preload all community features for acquisition from the cache
|
||||
// todo: make feature acquisition async and replace feature helpers for methods
|
||||
await fromUuids(this._source.features);
|
||||
|
||||
const baseDescription = this.description;
|
||||
const features = await getFeaturesHTMLData(this.features);
|
||||
|
||||
|
|
|
|||
|
|
@ -70,9 +70,7 @@ export default class DHSubclass extends BaseDataItem {
|
|||
return false;
|
||||
}
|
||||
|
||||
const match = [multiclass, actorClass].find(
|
||||
c => c && (c._stats.compendiumSource ?? c.uuid) === this.linkedClass
|
||||
);
|
||||
const match = [multiclass, actorClass].find(c => c && c.sourceUuid === this.linkedClass);
|
||||
if (!match) {
|
||||
const key = multiclass ? 'subclassNotInMulticlass' : 'subclassNotInClass';
|
||||
ui.notifications.warn(`DAGGERHEART.UI.Notifications.${key}`, { localize: true });
|
||||
|
|
@ -91,7 +89,7 @@ export default class DHSubclass extends BaseDataItem {
|
|||
? game.i18n.localize(CONFIG.DH.ACTOR.abilities[this.spellcastingTrait].label)
|
||||
: null;
|
||||
|
||||
// Preload all class features for acquisition from the cache
|
||||
// Preload all subclass features for acquisition from the cache
|
||||
// todo: make feature acquisition async and replace feature helpers for methods
|
||||
await fromUuids(this._source.features.map(f => f.item));
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,10 @@ export default class DHWeapon extends AttachableItem {
|
|||
);
|
||||
}
|
||||
|
||||
get itemFeatures() {
|
||||
return this.weaponFeatures;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async getDescriptionData() {
|
||||
const baseDescription = this.description;
|
||||
|
|
@ -269,8 +273,4 @@ export default class DHWeapon extends AttachableItem {
|
|||
|
||||
return labels;
|
||||
}
|
||||
|
||||
get itemFeatures() {
|
||||
return this.weaponFeatures;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ export class DhLevelup extends foundry.abstract.DataModel {
|
|||
const initialAchievements = i === tier.levels.start ? tier.initialAchievements : {};
|
||||
const experiences = initialAchievements.experience
|
||||
? [...Array(initialAchievements.experience.nr).keys()].reduce((acc, _) => {
|
||||
acc[foundry.utils.randomID()] = {
|
||||
name: '',
|
||||
modifier: initialAchievements.experience.modifier
|
||||
};
|
||||
return acc;
|
||||
}, {})
|
||||
acc[foundry.utils.randomID()] = {
|
||||
name: '',
|
||||
modifier: initialAchievements.experience.modifier
|
||||
};
|
||||
return acc;
|
||||
}, {})
|
||||
: {};
|
||||
|
||||
const domainCards = [...Array(tier.domainCardByLevel).keys()].reduce((acc, _) => {
|
||||
|
|
@ -298,9 +298,9 @@ export class DhLevelupLevel extends foundry.abstract.DataModel {
|
|||
experiences: levelData.achievements?.experiences ?? achievements.experiences ?? {},
|
||||
domainCards: levelData.achievements?.domainCards
|
||||
? levelData.achievements.domainCards.reduce((acc, card, index) => {
|
||||
acc[index] = { ...card };
|
||||
return acc;
|
||||
}, {})
|
||||
acc[index] = { ...card };
|
||||
return acc;
|
||||
}, {})
|
||||
: (achievements.domainCards ?? {}),
|
||||
proficiency: levelData.achievements?.proficiency ?? achievements.proficiency ?? null
|
||||
},
|
||||
|
|
|
|||
|
|
@ -149,12 +149,15 @@ export default class RegisteredTriggers extends Map {
|
|||
|
||||
const result = await command(...args);
|
||||
if (result?.updates?.length) updates.push(...result.updates);
|
||||
} catch (_) {
|
||||
} catch {
|
||||
const item = await foundry.utils.fromUuid(itemUuid);
|
||||
const triggerName = game.i18n.localize(triggerData.label);
|
||||
ui.notifications.error(
|
||||
console.error(
|
||||
game.i18n.format('DAGGERHEART.CONFIG.Triggers.triggerError', {
|
||||
trigger: triggerName,
|
||||
actor: currentActor?.name
|
||||
actor: currentActor?.name,
|
||||
item: item?.name ?? '<Missing Item>',
|
||||
itemUuid: item?.uuid ?? '<Missing UUID>'
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { defaultRestOptions } from '../../config/generalConfig.mjs';
|
|||
import { resetAndRerenderActors } from '../../helpers/utils.mjs';
|
||||
import { ActionsField } from '../fields/actionField.mjs';
|
||||
|
||||
const currencyField = (initial, label, icon) =>
|
||||
const currencyField = (initial, label, icon, initialAmount = 0) =>
|
||||
new foundry.data.fields.SchemaField({
|
||||
enabled: new foundry.data.fields.BooleanField({ required: true, initial: true }),
|
||||
label: new foundry.data.fields.StringField({
|
||||
|
|
@ -10,7 +10,14 @@ const currencyField = (initial, label, icon) =>
|
|||
initial,
|
||||
label
|
||||
}),
|
||||
icon: new foundry.data.fields.StringField({ required: true, nullable: false, blank: true, initial: icon })
|
||||
icon: new foundry.data.fields.StringField({ required: true, nullable: false, blank: true, initial: icon }),
|
||||
initialAmount: new foundry.data.fields.NumberField({
|
||||
required: true,
|
||||
integer: true,
|
||||
min: 0,
|
||||
initial: initialAmount,
|
||||
label: 'DAGGERHEART.SETTINGS.Homebrew.currency.initialAmount'
|
||||
})
|
||||
});
|
||||
|
||||
const restMoveField = () =>
|
||||
|
|
@ -108,7 +115,8 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
|||
handfuls: currencyField(
|
||||
'Handfuls',
|
||||
'DAGGERHEART.SETTINGS.Homebrew.currency.handfulName',
|
||||
'fa-solid fa-coins'
|
||||
'fa-solid fa-coins',
|
||||
1
|
||||
),
|
||||
bags: currencyField('Bags', 'DAGGERHEART.SETTINGS.Homebrew.currency.bagName', 'fa-solid fa-sack'),
|
||||
chests: currencyField(
|
||||
|
|
@ -193,6 +201,7 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
|||
for (const type of ['coins', 'handfuls', 'bags', 'chests']) {
|
||||
const initial = this.schema.fields.currency.fields[type].getInitialValue();
|
||||
source.currency[type] = foundry.utils.mergeObject(initial, source.currency[type], { inplace: false });
|
||||
source.currency[type].initialAmount ??= 0;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,16 +100,19 @@ export default class D20Roll extends DHRoll {
|
|||
|
||||
this.options.roll.modifiers = this.applyBaseBonus();
|
||||
|
||||
const actorExperiences = this.options.roll.companionRoll
|
||||
? (this.options.data?.companion?.system.experiences ?? {})
|
||||
: (this.options.data.system?.experiences ?? {});
|
||||
this.options.experiences?.forEach(m => {
|
||||
if (actorExperiences[m])
|
||||
this.options.roll.modifiers.push({
|
||||
label: actorExperiences[m].name,
|
||||
value: actorExperiences[m].value
|
||||
});
|
||||
});
|
||||
let actorExperiences = this.options.data.system?.experiences ?? {};
|
||||
if (this.options.roll.companionRoll) {
|
||||
const companion = typeof this.options.data.companion === 'string' ?
|
||||
foundry.utils.fromUuidSync(this.options.data.companion) :
|
||||
this.options.data.companion;
|
||||
actorExperiences = companion?.system?.experiences ?? {};
|
||||
}
|
||||
for (const m of this.options.experiences?.filter(m => !!actorExperiences[m]) ?? []) {
|
||||
this.options.roll.modifiers.push({
|
||||
label: actorExperiences[m].name,
|
||||
value: actorExperiences[m].value
|
||||
});
|
||||
}
|
||||
|
||||
this.addModifiers();
|
||||
if (this.options.extraFormula) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ export default class DHRoll extends Roll {
|
|||
|
||||
static DefaultDialog = D20RollDialog;
|
||||
|
||||
/**
|
||||
* @param {Partial<RollConfig>} config
|
||||
* @returns {Promise<RollConfig>}
|
||||
*/
|
||||
static async build(config = {}, message = {}) {
|
||||
const roll = await this.buildConfigure(config, message);
|
||||
if (!roll) return;
|
||||
|
|
@ -34,9 +38,14 @@ export default class DHRoll extends Roll {
|
|||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Partial<RollConfig>} config
|
||||
* @returns {Promise<RollConfig>}
|
||||
*/
|
||||
static async buildConfigure(config = {}, message = {}) {
|
||||
config.hooks = [...this.getHooks(), ''];
|
||||
config.dialog ??= {};
|
||||
config.damageOptions ??= {};
|
||||
|
||||
for (const hook of config.hooks) {
|
||||
if (Hooks.call(`${CONFIG.DH.id}.preRoll${hook.capitalize()}`, config, message) === false) return null;
|
||||
|
|
@ -103,9 +112,9 @@ export default class DHRoll extends Roll {
|
|||
if (action?.chatDisplay) {
|
||||
actionDescription = action
|
||||
? await foundry.applications.ux.TextEditor.implementation.enrichHTML(action.description, {
|
||||
relativeTo: config.data,
|
||||
rollData: config.data.getRollData?.() ?? {}
|
||||
})
|
||||
relativeTo: config.data,
|
||||
rollData: config.data.getRollData?.() ?? {}
|
||||
})
|
||||
: null;
|
||||
config.actionChatMessageHandled = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import D20RollDialog from '../applications/dialogs/d20RollDialog.mjs';
|
||||
import D20Roll from './d20Roll.mjs';
|
||||
import { parseRallyDice, setDiceSoNiceForDualityRoll } from '../helpers/utils.mjs';
|
||||
import { parseRallyDice, setDiceSoNiceForDualityRoll, shouldUseHopeFearAutomation } from '../helpers/utils.mjs';
|
||||
import { getDiceSoNicePresets } from '../config/generalConfig.mjs';
|
||||
import { updateResourcesForDualityReroll } from './helpers.mjs';
|
||||
|
||||
|
|
@ -109,10 +109,10 @@ export default class DualityRoll extends D20Roll {
|
|||
const label = this.guaranteedCritical
|
||||
? 'DAGGERHEART.GENERAL.guaranteedCriticalSuccess'
|
||||
: this.isCritical
|
||||
? 'DAGGERHEART.GENERAL.criticalSuccess'
|
||||
: this.withHope
|
||||
? 'DAGGERHEART.GENERAL.hope'
|
||||
: 'DAGGERHEART.GENERAL.fear';
|
||||
? 'DAGGERHEART.GENERAL.criticalSuccess'
|
||||
: this.withHope
|
||||
? 'DAGGERHEART.GENERAL.hope'
|
||||
: 'DAGGERHEART.GENERAL.fear';
|
||||
|
||||
return game.i18n.localize(label);
|
||||
}
|
||||
|
|
@ -147,8 +147,8 @@ export default class DualityRoll extends D20Roll {
|
|||
const advDieClass = this.hasAdvantage
|
||||
? game.system.api.dice.diceTypes.AdvantageDie
|
||||
: this.hasDisadvantage
|
||||
? game.system.api.dice.diceTypes.DisadvantageDie
|
||||
: null;
|
||||
? game.system.api.dice.diceTypes.DisadvantageDie
|
||||
: null;
|
||||
if (advDieClass) {
|
||||
const advDie = new advDieClass({ faces: this.advantageFaces, number: this.advantageNumber });
|
||||
if (this.terms.length < 4) {
|
||||
|
|
@ -312,11 +312,9 @@ export default class DualityRoll extends D20Roll {
|
|||
}
|
||||
|
||||
static async addDualityResourceUpdates(config) {
|
||||
const automationSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
|
||||
const hopeFearAutomation = automationSettings.hopeFear;
|
||||
if (
|
||||
!config.source?.actor ||
|
||||
(game.user.isGM ? !hopeFearAutomation.gm : !hopeFearAutomation.players) ||
|
||||
!shouldUseHopeFearAutomation() ||
|
||||
config.actionType === 'reaction' ||
|
||||
config.skips?.resources
|
||||
)
|
||||
|
|
@ -334,15 +332,15 @@ export default class DualityRoll extends D20Roll {
|
|||
const fear =
|
||||
(config.roll.result.duality === -1 ? 1 : 0) - (config.rerolledRoll.result.duality === -1 ? 1 : 0);
|
||||
|
||||
if (hope !== 0) updates.push({ key: 'hope', value: hope, total: -1 * hope, enabled: true });
|
||||
if (stress !== 0) updates.push({ key: 'stress', value: -1 * stress, total: stress, enabled: true });
|
||||
if (fear !== 0) updates.push({ key: 'fear', value: fear, total: -1 * fear, enabled: true });
|
||||
if (hope !== 0) updates.push({ key: 'hope', value: hope, enabled: true });
|
||||
if (stress !== 0) updates.push({ key: 'stress', value: -1 * stress, enabled: true });
|
||||
if (fear !== 0) updates.push({ key: 'fear', value: fear, enabled: true });
|
||||
}
|
||||
} else {
|
||||
if (config.roll.isCritical || config.roll.result.duality === 1)
|
||||
updates.push({ key: 'hope', value: 1, total: -1, enabled: true });
|
||||
if (config.roll.isCritical) updates.push({ key: 'stress', value: -1, total: 1, enabled: true });
|
||||
if (config.roll.result.duality === -1) updates.push({ key: 'fear', value: 1, total: -1, enabled: true });
|
||||
updates.push({ key: 'hope', value: 1, enabled: true });
|
||||
if (config.roll.isCritical) updates.push({ key: 'stress', value: -1, enabled: true });
|
||||
if (config.roll.result.duality === -1) updates.push({ key: 'fear', value: 1, enabled: true });
|
||||
}
|
||||
|
||||
if (updates.length) {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,28 @@
|
|||
export function updateResourcesForDualityReroll(oldDuality, newDuality, actor) {
|
||||
const { hopeFear } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
|
||||
if (game.user.isGM ? !hopeFear.gm : !hopeFear.players) return;
|
||||
import { ResourceUpdateMap } from '../data/action/baseAction.mjs';
|
||||
|
||||
const updates = [];
|
||||
export function updateResourcesForDualityReroll(oldDuality, newDuality, actor) {
|
||||
const hope = (newDuality >= 0 ? 1 : 0) - (oldDuality >= 0 ? 1 : 0);
|
||||
const stress = (newDuality === 0 ? 1 : 0) - (oldDuality === 0 ? 1 : 0);
|
||||
const fear = (newDuality === -1 ? 1 : 0) - (oldDuality === -1 ? 1 : 0);
|
||||
|
||||
if (hope !== 0) updates.push({ key: 'hope', value: hope, total: -1 * hope, enabled: true });
|
||||
if (stress !== 0) updates.push({ key: 'stress', value: -1 * stress, total: stress, enabled: true });
|
||||
if (fear !== 0) updates.push({ key: 'fear', value: fear, total: -1 * fear, enabled: true });
|
||||
const { hopeFear, countdownAutomation } =
|
||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
|
||||
|
||||
const resourceUpdates = new ResourceUpdateMap(actor);
|
||||
resourceUpdates.addResources(updates);
|
||||
resourceUpdates.updateResources();
|
||||
if (game.user.isGM ? hopeFear.gm : hopeFear.players) {
|
||||
const updates = [];
|
||||
if (hope !== 0) updates.push({ key: 'hope', value: hope, enabled: true });
|
||||
if (stress !== 0) updates.push({ key: 'stress', value: -1 * stress, enabled: true });
|
||||
if (fear !== 0) updates.push({ key: 'fear', value: fear, enabled: true })
|
||||
|
||||
const resourceUpdates = new ResourceUpdateMap(actor);
|
||||
resourceUpdates.addResources(updates);
|
||||
resourceUpdates.updateResources();
|
||||
}
|
||||
|
||||
if (countdownAutomation && fear !== 0) {
|
||||
game.system.api.applications.ui.DhCountdowns.updateCountdowns({
|
||||
type: CONFIG.DH.GENERAL.countdownProgressionTypes.fear.id,
|
||||
undo: fear === 1 ? false : true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
22
module/documents/_types.d.ts
vendored
Normal file
22
module/documents/_types.d.ts
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import BaseDataActor from '../data/actor/base.mjs'
|
||||
import DHItem from './item.mjs';
|
||||
import BaseDataItem from '../data/item/base.mjs';
|
||||
import DhActiveEffect from './activeEffect.mjs';
|
||||
import EmbeddedCollection from '@common/abstract/embedded-collection.mjs';
|
||||
|
||||
declare module './actor.mjs' {
|
||||
export default interface DhpActor<T extends BaseDataActor = BaseDataActor> {
|
||||
system: T;
|
||||
items: EmbeddedCollection<DHItem>;
|
||||
effects: EmbeddedCollection<DhActiveEffect>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module './item.mjs' {
|
||||
export default interface DHItem<T extends BaseDataItem = BaseDataItem> {
|
||||
parent: DhpActor;
|
||||
actor: DhpActor;
|
||||
system: T;
|
||||
effects: EmbeddedCollection<DhActiveEffect>;
|
||||
}
|
||||
}
|
||||
|
|
@ -65,6 +65,10 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
|||
);
|
||||
}
|
||||
|
||||
get hasDescription() {
|
||||
return Boolean(this.description);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Event Handlers */
|
||||
/* -------------------------------------------- */
|
||||
|
|
@ -175,8 +179,8 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
|||
return model instanceof documentClass
|
||||
? model
|
||||
: model.parent
|
||||
? this.#resolveParentDocument(model.parent, documentClass)
|
||||
: null;
|
||||
? this.#resolveParentDocument(model.parent, documentClass)
|
||||
: null;
|
||||
}
|
||||
|
||||
static getChangeValue(model, change, effect) {
|
||||
|
|
@ -212,7 +216,7 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
|||
try {
|
||||
const evl = new Function('sandbox', `with (sandbox) { return ${expression}}`);
|
||||
result = evl(Roll.MATH_PROXY);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
return expression;
|
||||
}
|
||||
|
||||
|
|
@ -224,12 +228,13 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
|||
* @returns {string[]} An array of localized tag strings.
|
||||
*/
|
||||
_getTags() {
|
||||
const tags = [
|
||||
`${game.i18n.localize(this.parent.system.metadata.label)}: ${this.parent.name}`,
|
||||
game.i18n.localize(
|
||||
this.isTemporary ? 'DAGGERHEART.EFFECTS.Duration.temporary' : 'DAGGERHEART.EFFECTS.Duration.passive'
|
||||
)
|
||||
];
|
||||
const tags = [];
|
||||
const originActor = DhActiveEffect.#resolveParentDocument(fromUuidSync(this.origin, { strict: false }), Actor);
|
||||
if (originActor && originActor !== this.actor) {
|
||||
tags.push(_loc('DAGGERHEART.EFFECTS.OriginTag', { name: originActor.name }));
|
||||
} else if (!(this.parent instanceof Actor)) {
|
||||
tags.push(`${_loc(this.parent.system.metadata.label)}: ${this.parent.name}`);
|
||||
}
|
||||
|
||||
for (const statusId of this.statuses) {
|
||||
const status = CONFIG.statusEffects.find(s => s.id === statusId);
|
||||
|
|
|
|||
|
|
@ -531,21 +531,7 @@ export default class DhpActor extends Actor {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {object} config
|
||||
* @param {Event} config.event
|
||||
* @param {string} config.title
|
||||
* @param {object} config.roll
|
||||
* @param {number} config.roll.modifier
|
||||
* @param {boolean} [config.roll.simple=false]
|
||||
* @param {string} [config.roll.type]
|
||||
* @param {number} [config.roll.difficulty]
|
||||
* @param {boolean} [config.hasDamage]
|
||||
* @param {boolean} [config.hasEffect]
|
||||
* @param {object} [config.chatMessage]
|
||||
* @param {string} config.chatMessage.template
|
||||
* @param {boolean} [config.chatMessage.mute]
|
||||
* @param {object} [config.targets]
|
||||
* @param {object} [config.costs]
|
||||
* @param {Partial<RollConfig>} config
|
||||
*/
|
||||
async diceRoll(config) {
|
||||
config.source = { ...(config.source ?? {}), actor: this.uuid };
|
||||
|
|
@ -563,7 +549,7 @@ export default class DhpActor extends Actor {
|
|||
headerTitle: game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
||||
ability: abilityLabel
|
||||
}),
|
||||
effects: await game.system.api.data.actions.actionsTypes.base.getEffects(this),
|
||||
effects: await game.system.api.data.actions.actionsTypes.base.getActionRelevantEffects(this),
|
||||
roll: {
|
||||
trait: trait,
|
||||
type: 'trait'
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|||
actor && this.isContentVisible
|
||||
? actor
|
||||
: {
|
||||
img: this.author.avatar ? this.author.avatar : 'icons/svg/mystery-man.svg',
|
||||
name: ''
|
||||
};
|
||||
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 });
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|||
if (this.system.action) {
|
||||
const actor = await foundry.utils.fromUuid(config.source.actor);
|
||||
const item = actor?.items.get(config.source.item) ?? null;
|
||||
config.effects = await game.system.api.data.actions.actionsTypes.base.getEffects(actor, item);
|
||||
config.effects = await game.system.api.data.actions.actionsTypes.base.getActionRelevantEffects(actor, item);
|
||||
await this.system.action.workflow.get('damage')?.execute(config, this._id, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -290,14 +290,14 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|||
behaviors:
|
||||
effects.length > 0
|
||||
? [
|
||||
{
|
||||
name: game.i18n.localize('TYPES.RegionBehavior.applyActiveEffect'),
|
||||
type: 'applyActiveEffect',
|
||||
system: {
|
||||
effects: effects
|
||||
}
|
||||
}
|
||||
]
|
||||
{
|
||||
name: game.i18n.localize('TYPES.RegionBehavior.applyActiveEffect'),
|
||||
type: 'applyActiveEffect',
|
||||
system: {
|
||||
effects: effects
|
||||
}
|
||||
}
|
||||
]
|
||||
: [],
|
||||
displayMeasurements: true,
|
||||
locked: false,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,9 @@ export default class DhpCombat extends Combat {
|
|||
for (let actor of actors) {
|
||||
await actor.createEmbeddedDocuments(
|
||||
'ActiveEffect',
|
||||
effects.filter(x => x.effectTargetTypes.includes(actor.type))
|
||||
effects
|
||||
.filter(x => x.effectTargetTypes.includes(actor.type))
|
||||
.map(x => foundry.utils.deepClone(x))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,16 @@ import ActionSelectionDialog from '../applications/dialogs/actionSelectionDialog
|
|||
* @extends {foundry.documents.Item}
|
||||
*/
|
||||
export default class DHItem extends foundry.documents.Item {
|
||||
/**
|
||||
* Returns the uuid of the original item this item was derived from,
|
||||
* or its own uuid if its a compendium item or not derived from a source item.
|
||||
* @returns {string}
|
||||
*/
|
||||
get sourceUuid() {
|
||||
const isCompendium = this._id && this.pack && !this.isEmbedded;
|
||||
return isCompendium ? this.uuid : this._stats.duplicateSource ?? this._stats.compendiumSource ?? this.uuid;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
prepareEmbeddedDocuments() {
|
||||
super.prepareEmbeddedDocuments();
|
||||
|
|
@ -79,6 +89,10 @@ export default class DHItem extends foundry.documents.Item {
|
|||
return !pack?.locked && this.isOwner && isValidType && hasActions;
|
||||
}
|
||||
|
||||
get hasDescription() {
|
||||
return Boolean(this.system.description) || Boolean(this.system.itemFeatures?.length);
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
static async createDialog(data = {}, createOptions = {}, options = {}) {
|
||||
const { folders, types, template, context = {}, ...dialogOptions } = options;
|
||||
|
|
@ -98,8 +112,8 @@ export default class DHItem extends foundry.documents.Item {
|
|||
isInventoryItem === true
|
||||
? 'Inventory Items' //TODO localize
|
||||
: isInventoryItem === false
|
||||
? 'Character Items' //TODO localize
|
||||
: 'Other'; //TODO localize
|
||||
? 'Character Items' //TODO localize
|
||||
: 'Other'; //TODO localize
|
||||
|
||||
return { value: type, label, group };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ export default class DHToken extends CONFIG.Token.documentClass {
|
|||
}
|
||||
let x = 0.5 * bottom;
|
||||
let y = 0.25;
|
||||
for (let k = width - bottom; k--; ) {
|
||||
for (let k = width - bottom; k--;) {
|
||||
points.push(x, y);
|
||||
x += 0.5;
|
||||
y -= 0.25;
|
||||
|
|
@ -333,7 +333,7 @@ export default class DHToken extends CONFIG.Token.documentClass {
|
|||
y += 0.25;
|
||||
}
|
||||
points.push(x, y);
|
||||
for (let k = bottom; k--; ) {
|
||||
for (let k = bottom; k--;) {
|
||||
y += 0.5;
|
||||
points.push(x, y);
|
||||
x += 0.5;
|
||||
|
|
@ -341,14 +341,14 @@ export default class DHToken extends CONFIG.Token.documentClass {
|
|||
points.push(x, y);
|
||||
}
|
||||
y += 0.5;
|
||||
for (let k = top; k--; ) {
|
||||
for (let k = top; k--;) {
|
||||
points.push(x, y);
|
||||
x -= 0.5;
|
||||
y += 0.25;
|
||||
points.push(x, y);
|
||||
y += 0.5;
|
||||
}
|
||||
for (let k = width - top; k--; ) {
|
||||
for (let k = width - top; k--;) {
|
||||
points.push(x, y);
|
||||
x -= 0.5;
|
||||
y += 0.25;
|
||||
|
|
@ -357,7 +357,7 @@ export default class DHToken extends CONFIG.Token.documentClass {
|
|||
y -= 0.25;
|
||||
}
|
||||
points.push(x, y);
|
||||
for (let k = top; k--; ) {
|
||||
for (let k = top; k--;) {
|
||||
y -= 0.5;
|
||||
points.push(x, y);
|
||||
x -= 0.5;
|
||||
|
|
@ -365,7 +365,7 @@ export default class DHToken extends CONFIG.Token.documentClass {
|
|||
points.push(x, y);
|
||||
}
|
||||
y -= 0.5;
|
||||
for (let k = bottom; k--; ) {
|
||||
for (let k = bottom; k--;) {
|
||||
points.push(x, y);
|
||||
x += 0.5;
|
||||
y -= 0.25;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { parseInlineParams } from './parser.mjs';
|
||||
|
||||
export default function DhDamageEnricher(match, _options) {
|
||||
const { value, type, inline } = parseInlineParams(match[1]);
|
||||
const { value, type, inline } = parseInlineParams(match[1], { first: 'value' });
|
||||
if (!value || !type) return match[0];
|
||||
return getDamageMessage(value, type, inline, match[0]);
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ export const renderDamageButton = async event => {
|
|||
{
|
||||
formula: value,
|
||||
applyTo: CONFIG.DH.GENERAL.healingTypes.hitPoints.id,
|
||||
type: type
|
||||
damageTypes: type
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ function getDualityMessage(roll, flavor) {
|
|||
(roll?.trait
|
||||
? game.i18n.format('DAGGERHEART.GENERAL.rollWith', { roll: trait })
|
||||
: roll?.reaction
|
||||
? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
|
||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality'));
|
||||
? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
|
||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality'));
|
||||
|
||||
const dataLabel = trait
|
||||
? game.i18n.localize(abilities[roll.trait].label)
|
||||
|
|
@ -25,14 +25,14 @@ function getDualityMessage(roll, flavor) {
|
|||
const advantage = roll?.advantage
|
||||
? CONFIG.DH.ACTIONS.advantageState.advantage.value
|
||||
: roll?.disadvantage
|
||||
? CONFIG.DH.ACTIONS.advantageState.disadvantage.value
|
||||
: undefined;
|
||||
? CONFIG.DH.ACTIONS.advantageState.disadvantage.value
|
||||
: undefined;
|
||||
const advantageLabel =
|
||||
advantage === CONFIG.DH.ACTIONS.advantageState.advantage.value
|
||||
? 'Advantage'
|
||||
: advantage === CONFIG.DH.ACTIONS.advantageState.disadvantage.value
|
||||
? 'Disadvantage'
|
||||
: undefined;
|
||||
? 'Disadvantage'
|
||||
: undefined;
|
||||
|
||||
const dualityElement = document.createElement('span');
|
||||
dualityElement.innerHTML = `
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export const renderFateButton = async event => {
|
|||
const fateTypeData = getFateTypeData(button.dataset?.fatetype);
|
||||
|
||||
if (!fateTypeData) ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
|
||||
const { value: fateType, label: fateTypeLabel } = fateTypeData;
|
||||
const { value: fateType } = fateTypeData;
|
||||
|
||||
await enrichedFateRoll(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ export default function DhTemplateEnricher(match, _options) {
|
|||
const range =
|
||||
params.range && Number.isNaN(Number(params.range))
|
||||
? Object.values(CONFIG.DH.GENERAL.templateRanges).find(
|
||||
x => x.id.toLowerCase() === params.range || x.short === params.range
|
||||
)?.id
|
||||
x => x.id.toLowerCase() === params.range || x.short === params.range
|
||||
)?.id
|
||||
: params.range;
|
||||
|
||||
if (!CONFIG.DH.GENERAL.templateTypes[type] || !range) return match[0];
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export function parseInlineParams(paramString, { first } = {}) {
|
|||
const parts = paramString.split('|').map(x => x.trim());
|
||||
const params = {};
|
||||
for (const [idx, param] of parts.entries()) {
|
||||
if (first && idx === 0) {
|
||||
if (first && idx === 0 && !param.includes(':')) {
|
||||
params[first] = param;
|
||||
} else {
|
||||
const parts = param.split(':');
|
||||
|
|
|
|||
|
|
@ -108,9 +108,9 @@ export const tagifyElement = (element, baseOptions, onChange, tagifyOptions = {}
|
|||
const options = Array.isArray(baseOptions)
|
||||
? baseOptions
|
||||
: Object.keys(baseOptions).map(optionKey => ({
|
||||
...baseOptions[optionKey],
|
||||
id: optionKey
|
||||
}));
|
||||
...baseOptions[optionKey],
|
||||
id: optionKey
|
||||
}));
|
||||
|
||||
const tagifyElement = new Tagify(element, {
|
||||
tagTextProp: 'name',
|
||||
|
|
@ -318,7 +318,7 @@ export function getDocFromElementSync(element) {
|
|||
const target = element.closest('[data-item-uuid]');
|
||||
try {
|
||||
return foundry.utils.fromUuidSync(target.dataset.itemUuid) ?? null;
|
||||
} catch (_) {
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -377,7 +377,7 @@ export const itemAbleRollParse = (value, actor, item) => {
|
|||
|
||||
try {
|
||||
return Roll.replaceFormulaData(slicedValue, rollData);
|
||||
} catch (_) {
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
|
@ -418,40 +418,6 @@ export function createScrollText(actor, data) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function createEmbeddedItemWithEffects(actor, baseData, update) {
|
||||
const data = baseData.uuid.startsWith('Compendium') ? await foundry.utils.fromUuid(baseData.uuid) : baseData;
|
||||
const [doc] = await actor.createEmbeddedDocuments('Item', [
|
||||
{
|
||||
...(update ?? data),
|
||||
...baseData,
|
||||
id: data.id,
|
||||
uuid: data.uuid,
|
||||
_uuid: data.uuid,
|
||||
effects: data.effects?.map(effect => effect.toObject()),
|
||||
_stats: {
|
||||
...data._stats,
|
||||
compendiumSource: data.pack ? `Compendium.${data.pack}.Item.${data.id}` : null
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
export async function createEmbeddedItemsWithEffects(actor, baseData) {
|
||||
const effectData = [];
|
||||
for (let d of baseData) {
|
||||
const data = d.uuid.startsWith('Compendium') ? await foundry.utils.fromUuid(d.uuid) : d;
|
||||
effectData.push({
|
||||
...data,
|
||||
id: data.id,
|
||||
uuid: data.uuid,
|
||||
effects: data.effects?.map(effect => effect.toObject())
|
||||
});
|
||||
}
|
||||
await actor.createEmbeddedDocuments('Item', effectData);
|
||||
}
|
||||
|
||||
export function shuffleArray(array) {
|
||||
let currentIndex = array.length;
|
||||
while (currentIndex != 0) {
|
||||
|
|
@ -605,8 +571,8 @@ export function calculateExpectedValue(formulaOrTerms) {
|
|||
const terms = Array.isArray(formulaOrTerms)
|
||||
? formulaOrTerms
|
||||
: typeof formulaOrTerms === 'string'
|
||||
? parseTermsFromSimpleFormula(formulaOrTerms)
|
||||
: [formulaOrTerms];
|
||||
? parseTermsFromSimpleFormula(formulaOrTerms)
|
||||
: [formulaOrTerms];
|
||||
return terms.reduce((r, t) => r + (t.bonus ?? 0) + (t.diceQuantity ? (t.diceQuantity * (t.faces + 1)) / 2 : 0), 0);
|
||||
}
|
||||
|
||||
|
|
@ -656,8 +622,8 @@ export async function RefreshFeatures(
|
|||
'resource.value': increasing
|
||||
? 0
|
||||
: game.system.api.documents.DhActiveEffect.effectSafeEval(
|
||||
Roll.replaceFormulaData(item.system.resource.max, actor.getRollData())
|
||||
)
|
||||
Roll.replaceFormulaData(item.system.resource.max, actor.getRollData())
|
||||
)
|
||||
};
|
||||
}
|
||||
if (item.system.metadata?.hasActions) {
|
||||
|
|
@ -879,6 +845,7 @@ export async function fromUuids(uuids) {
|
|||
const packEmbeddedEntries = entries.filter(
|
||||
e =>
|
||||
!(e.value instanceof Document) &&
|
||||
e.parsed &&
|
||||
e.parsed.collection instanceof foundry.documents.collections.CompendiumCollection &&
|
||||
e.parsed.embedded.length > 0
|
||||
);
|
||||
|
|
@ -895,7 +862,7 @@ export async function fromUuids(uuids) {
|
|||
const pack = game.packs.get(packGroup[0].value.pack);
|
||||
if (!pack) continue;
|
||||
|
||||
const ids = packGroup.map(p => p.parsed.id);
|
||||
const ids = packGroup.map(p => p.parsed?.id).filter(id => !!id);
|
||||
const documents = await pack.getDocuments({ _id__in: ids });
|
||||
for (const p of packGroup) {
|
||||
p.value = documents.find(d => d.id === p.parsed.id) ?? p.value;
|
||||
|
|
@ -918,3 +885,31 @@ export async function triggerChatRollFx(rolls, options = { whisper: false, blind
|
|||
foundry.audio.AudioHelper.play({ src: CONFIG.sounds.dice });
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldUseHopeFearAutomation(options = { gmAsPlayer: true }) {
|
||||
const { hopeFear } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
|
||||
return (!game.user.isGM || options.gmAsPlayer) ? hopeFear.players : hopeFear.gm;
|
||||
}
|
||||
|
||||
export async function getWorldActor(baseActor) {
|
||||
if (baseActor.inCompendium) {
|
||||
const worldActorCopy = game.actors.find(x =>
|
||||
x._stats.compendiumSource === baseActor.uuid &&
|
||||
(!x.prototypeToken.actorLink || x.name === baseActor.name)
|
||||
);
|
||||
|
||||
if (worldActorCopy)
|
||||
return worldActorCopy;
|
||||
|
||||
const baseActorData = baseActor;
|
||||
return await game.system.api.documents.DhpActor.create({
|
||||
...baseActorData,
|
||||
_stats: {
|
||||
...baseActorData._stats,
|
||||
compendiumSource: baseActor.uuid
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return baseActor;
|
||||
}
|
||||
|
|
@ -50,6 +50,7 @@ export const preloadHandlebarsTemplates = async function () {
|
|||
'systems/daggerheart/templates/ui/chat/parts/target-part.hbs',
|
||||
'systems/daggerheart/templates/ui/chat/parts/button-part.hbs',
|
||||
'systems/daggerheart/templates/ui/itemBrowser/itemContainer.hbs',
|
||||
'systems/daggerheart/templates/ui/countdowns/parts/countdowns.hbs',
|
||||
'systems/daggerheart/templates/scene/dh-config.hbs',
|
||||
'systems/daggerheart/templates/settings/appearance-settings/diceSoNiceTab.hbs',
|
||||
'systems/daggerheart/templates/sheets/activeEffect/typeChanges/armorChange.hbs'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { defaultRestOptions } from '../config/generalConfig.mjs';
|
||||
import { RefreshType, socketEvent } from './socket.mjs';
|
||||
|
||||
export async function runMigrations() {
|
||||
let lastMigrationVersion = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion);
|
||||
|
|
@ -24,8 +23,8 @@ export async function runMigrations() {
|
|||
const { originItemType, isMulticlass, identifier } = item.system;
|
||||
const base = originItemType
|
||||
? actor.items.find(
|
||||
x => x.type === originItemType && Boolean(isMulticlass) === Boolean(x.system.isMulticlass)
|
||||
)
|
||||
x => x.type === originItemType && Boolean(isMulticlass) === Boolean(x.system.isMulticlass)
|
||||
)
|
||||
: null;
|
||||
if (base) {
|
||||
const feature = base.system.features.find(x => x.item && x.item.uuid === item.uuid);
|
||||
|
|
@ -153,61 +152,26 @@ export async function runMigrations() {
|
|||
await pack.configure({ locked: true });
|
||||
}
|
||||
|
||||
/* Migrate old countdown structure */
|
||||
const countdownSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
|
||||
const getCountdowns = (data, type) => {
|
||||
return Object.keys(data.countdowns).reduce((acc, key) => {
|
||||
const countdown = data.countdowns[key];
|
||||
acc[key] = {
|
||||
...countdown,
|
||||
type: type,
|
||||
ownership: Object.keys(countdown.ownership.players).reduce((acc, key) => {
|
||||
acc[key] =
|
||||
countdown.ownership.players[key].type === 1 ? 2 : countdown.ownership.players[key].type;
|
||||
return acc;
|
||||
}, {}),
|
||||
progress: {
|
||||
...countdown.progress,
|
||||
type: countdown.progress.type.value
|
||||
}
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
await countdownSettings.updateSource({
|
||||
countdowns: {
|
||||
...getCountdowns(countdownSettings.narrative, CONFIG.DH.GENERAL.countdownBaseTypes.narrative.id),
|
||||
...getCountdowns(countdownSettings.encounter, CONFIG.DH.GENERAL.countdownBaseTypes.encounter.id)
|
||||
}
|
||||
});
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, countdownSettings);
|
||||
|
||||
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.Refresh,
|
||||
data: { refreshType: RefreshType.Countdown }
|
||||
});
|
||||
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
|
||||
|
||||
lastMigrationVersion = '1.2.0';
|
||||
}
|
||||
|
||||
if (foundry.utils.isNewerVersion('1.2.7', lastMigrationVersion)) {
|
||||
const tagTeam = game.settings.get(CONFIG.DH.id, 'TagTeamRoll');
|
||||
const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator);
|
||||
const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => {
|
||||
if (!game.actors.some(actor => actor.id === id)) {
|
||||
acc[id] = _del;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
try {
|
||||
const tagTeam = game.settings.get(CONFIG.DH.id, 'TagTeamRoll');
|
||||
const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator);
|
||||
const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => {
|
||||
if (!game.actors.some(actor => actor.id === id)) {
|
||||
acc[id] = _del;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
await tagTeam.updateSource({
|
||||
initiator: initatorMissing ? null : tagTeam.initiator,
|
||||
members: missingMembers
|
||||
});
|
||||
await game.settings.set(CONFIG.DH.id, 'TagTeamRoll', tagTeam);
|
||||
await tagTeam.updateSource({
|
||||
initiator: initatorMissing ? null : tagTeam.initiator,
|
||||
members: missingMembers
|
||||
});
|
||||
await game.settings.set(CONFIG.DH.id, 'TagTeamRoll', tagTeam);
|
||||
} catch { }
|
||||
|
||||
lastMigrationVersion = '1.2.7';
|
||||
}
|
||||
|
|
@ -303,6 +267,8 @@ export async function runMigrations() {
|
|||
|
||||
/* Migrate existing effects modifying armor, creating new Armor Effects instead */
|
||||
const migrateEffects = async entity => {
|
||||
if (!entity?.effects) return;
|
||||
|
||||
for (const effect of entity.effects) {
|
||||
if (effect.system.changes.every(x => x.key !== 'system.armorScore')) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -199,7 +199,10 @@ const registerNonConfigSettings = () => {
|
|||
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns, {
|
||||
scope: 'world',
|
||||
config: false,
|
||||
type: DhCountdowns
|
||||
type: DhCountdowns,
|
||||
onChange: value => {
|
||||
value.handleChange();
|
||||
}
|
||||
});
|
||||
|
||||
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue