This commit is contained in:
WBHarry 2026-03-06 08:30:50 -05:00 committed by GitHub
commit 374ef6040f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 335 additions and 181 deletions

View file

@ -55,6 +55,10 @@ export default class CharacterSheet extends DHBaseActorSheet {
{
dragSelector: '[data-item-id][draggable="true"], [data-item-id] [draggable="true"]',
dropSelector: null
},
{
dragSelector: null,
dropSelector: '.character-sidebar-sheet'
}
],
contextMenus: [
@ -260,6 +264,9 @@ export default class CharacterSheet extends DHBaseActorSheet {
*/
async _prepareSidebarContext(context, _options) {
context.isDeath = this.document.system.deathMoveViable;
context.sidebarFavoritesEmpty = this.document.system.sidebarFavorites.length === 0;
context.showfavorites = !context.sidebarFavoritesEmpty || this.document.system.usedUnarmed;
context.sidebarFavorites = this.document.system.sidebarFavorites.sort((a, b) => a.name.localeCompare(b.name));
}
/**
@ -309,7 +316,9 @@ export default class CharacterSheet extends DHBaseActorSheet {
icon: 'fa-solid fa-arrow-up',
condition: target => {
const doc = getDocFromElementSync(target);
return doc && doc.system.inVault;
const inCharacterSidebar =
this.document.type === 'character' && target.closest('.items-sidebar-list');
return doc && doc.system.inVault && !inCharacterSidebar;
},
callback: async target => {
const doc = await getDocFromElement(target);
@ -323,7 +332,9 @@ export default class CharacterSheet extends DHBaseActorSheet {
icon: 'fa-solid fa-bolt-lightning',
condition: target => {
const doc = getDocFromElementSync(target);
return doc && doc.system.inVault;
const inCharacterSidebar =
this.document.type === 'character' && target.closest('.items-sidebar-list');
return doc && doc.system.inVault && !inCharacterSidebar;
},
callback: async (target, event) => {
const doc = await getDocFromElement(target);
@ -362,7 +373,9 @@ export default class CharacterSheet extends DHBaseActorSheet {
icon: 'fa-solid fa-arrow-down',
condition: target => {
const doc = getDocFromElementSync(target);
return doc && !doc.system.inVault;
const inCharacterSidebar =
this.document.type === 'character' && target.closest('.items-sidebar-list');
return doc && !doc.system.inVault && !inCharacterSidebar;
},
callback: async target => (await getDocFromElement(target)).update({ 'system.inVault': true })
}
@ -741,8 +754,6 @@ export default class CharacterSheet extends DHBaseActorSheet {
await config.resourceUpdates.updateResources();
}
//TODO: redo toggleEquipItem method
/**
* Toggles the equipped state of an item (armor or weapon).
* @type {ApplicationClickAction}
@ -750,32 +761,14 @@ export default class CharacterSheet extends DHBaseActorSheet {
static async #toggleEquipItem(_event, button) {
const item = await getDocFromElement(button);
if (!item) return;
if (item.system.equipped) {
await item.update({ 'system.equipped': false });
return;
}
switch (item.type) {
case 'armor':
const currentArmor = this.document.system.armor;
if (currentArmor) {
await currentArmor.update({ 'system.equipped': false });
}
await item.update({ 'system.equipped': true });
break;
case 'weapon':
if (this.document.effects.find(x => !x.disabled && x.type === 'beastform')) {
return ui.notifications.warn(
game.i18n.localize('DAGGERHEART.UI.Notifications.beastformEquipWeapon')
);
}
await this.document.system.constructor.unequipBeforeEquip.bind(this.document.system)(item);
await item.update({ 'system.equipped': true });
break;
}
const changedData = await this.document.toggleEquipItem(item);
const removedData = changedData.filter(x => !x.add);
this.document.update({
'system.sidebarFavorites': [
...this.document.system.sidebarFavorites.filter(x => removedData.every(r => r.item.id !== x.id))
]
});
}
/**
@ -835,12 +828,13 @@ export default class CharacterSheet extends DHBaseActorSheet {
*/
static async #toggleVault(_event, button) {
const doc = await getDocFromElement(button);
const { available } = this.document.system.loadoutSlot;
if (doc.system.inVault && !available && !doc.system.loadoutIgnore) {
return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.loadoutMaxReached'));
}
await doc?.update({ 'system.inVault': !doc.system.inVault });
const changedData = await this.document.toggleDomainCardVault(doc);
const removedData = changedData.filter(x => !x.add);
this.document.update({
'system.sidebarFavorites': [
...this.document.system.sidebarFavorites.filter(x => removedData.every(r => r.item.id !== x.id))
]
});
}
/**
@ -962,6 +956,11 @@ export default class CharacterSheet extends DHBaseActorSheet {
}
async _onDropItem(event, item) {
const sidebarDrop = event.target.closest('.character-sidebar-sheet');
if (sidebarDrop) {
return this._onSidebarDrop(event, item);
}
const setupCriticalItemTypes = ['class', 'subclass', 'ancestry', 'community'];
if (this.document.system.needsCharacterSetup && setupCriticalItemTypes.includes(item.type)) {
const confirmed = await foundry.applications.api.DialogV2.confirm({
@ -1012,4 +1011,18 @@ export default class CharacterSheet extends DHBaseActorSheet {
itemData = itemData instanceof Array ? itemData : [itemData];
return this.document.createEmbeddedDocuments('Item', itemData);
}
async _onSidebarDrop(event, item) {
if (!item.testUserPermission(game.user, 'OWNER')) return;
if (!(item instanceof game.system.api.documents.DHItem)) return;
if (!this.document.items.get(item.id)) return;
const allowedItemTypes = ['domainCard', 'feature', 'weapon', 'armor', 'loot', 'consumable'];
if (!allowedItemTypes.includes(item.type)) return;
if (this.document.system.sidebarFavorites.some(x => x.id === item.id)) return;
this.document.setFavoriteItem(item, true);
}
}

View file

@ -532,6 +532,40 @@ export default function DHApplicationMixin(Base) {
callback: async target => (await getDocFromElement(target)).toChat(this.document.uuid)
});
options.push({
name: 'Unfavorite',
icon: 'fa-regular fa-star',
condition: target => {
const doc = getDocFromElementSync(target);
const isFavorited = this.document.system.sidebarFavorites.some(x => x.id === doc.id);
return this.document.type === 'character' && isFavorited;
},
callback: async (target, _event) => {
const doc = await getDocFromElement(target);
this.document.update({
'system.sidebarFavorites': this.document.system.sidebarFavorites.filter(x => x.id !== doc.id)
});
}
});
options.push({
name: 'Favorite',
icon: 'fa-solid fa-star',
condition: target => {
const doc = getDocFromElementSync(target);
const isFavorited = this.document.system.sidebarFavorites.some(x => x.id === doc.id);
return (
!(doc instanceof game.system.api.documents.DhActiveEffect) &&
this.document.type === 'character' &&
!isFavorited
);
},
callback: async (target, _event) => {
const doc = await getDocFromElement(target);
this.document.setFavoriteItem(doc, true);
}
});
if (deletable)
options.push({
name: 'CONTROLS.CommonDelete',

View file

@ -506,8 +506,8 @@ export const subclassFeatureLabels = {
* @property {number[]} damage
*/
/**
* @type {Record<string, Record<2 | 3 | 4, TierData>}
/**
* @type {Record<string, Record<2 | 3 | 4, TierData>}
* Scaling data used to change an adversary's tier. Each rank is applied incrementally.
*/
export const adversaryScalingData = {
@ -518,7 +518,7 @@ export const adversaryScalingData = {
severeThreshold: 10,
hp: 1,
stress: 2,
attack: 2,
attack: 2
},
3: {
difficulty: 2,
@ -526,7 +526,7 @@ export const adversaryScalingData = {
severeThreshold: 15,
hp: 1,
stress: 0,
attack: 2,
attack: 2
},
4: {
difficulty: 2,
@ -534,7 +534,7 @@ export const adversaryScalingData = {
severeThreshold: 25,
hp: 1,
stress: 0,
attack: 2,
attack: 2
}
},
horde: {
@ -544,7 +544,7 @@ export const adversaryScalingData = {
severeThreshold: 8,
hp: 2,
stress: 0,
attack: 0,
attack: 0
},
3: {
difficulty: 2,
@ -552,7 +552,7 @@ export const adversaryScalingData = {
severeThreshold: 12,
hp: 0,
stress: 1,
attack: 1,
attack: 1
},
4: {
difficulty: 2,
@ -560,7 +560,7 @@ export const adversaryScalingData = {
severeThreshold: 15,
hp: 2,
stress: 0,
attack: 0,
attack: 0
}
},
leader: {
@ -570,7 +570,7 @@ export const adversaryScalingData = {
severeThreshold: 10,
hp: 0,
stress: 0,
attack: 1,
attack: 1
},
3: {
difficulty: 2,
@ -578,7 +578,7 @@ export const adversaryScalingData = {
severeThreshold: 15,
hp: 1,
stress: 0,
attack: 2,
attack: 2
},
4: {
difficulty: 2,
@ -586,7 +586,7 @@ export const adversaryScalingData = {
severeThreshold: 25,
hp: 1,
stress: 1,
attack: 3,
attack: 3
}
},
minion: {
@ -596,7 +596,7 @@ export const adversaryScalingData = {
severeThreshold: 0,
hp: 0,
stress: 0,
attack: 1,
attack: 1
},
3: {
difficulty: 2,
@ -604,7 +604,7 @@ export const adversaryScalingData = {
severeThreshold: 0,
hp: 0,
stress: 1,
attack: 1,
attack: 1
},
4: {
difficulty: 2,
@ -612,7 +612,7 @@ export const adversaryScalingData = {
severeThreshold: 0,
hp: 0,
stress: 0,
attack: 1,
attack: 1
}
},
ranged: {
@ -622,7 +622,7 @@ export const adversaryScalingData = {
severeThreshold: 6,
hp: 1,
stress: 0,
attack: 1,
attack: 1
},
3: {
difficulty: 2,
@ -630,7 +630,7 @@ export const adversaryScalingData = {
severeThreshold: 14,
hp: 1,
stress: 1,
attack: 2,
attack: 2
},
4: {
difficulty: 2,
@ -638,7 +638,7 @@ export const adversaryScalingData = {
severeThreshold: 10,
hp: 1,
stress: 1,
attack: 1,
attack: 1
}
},
skulk: {
@ -648,7 +648,7 @@ export const adversaryScalingData = {
severeThreshold: 8,
hp: 1,
stress: 1,
attack: 1,
attack: 1
},
3: {
difficulty: 2,
@ -656,7 +656,7 @@ export const adversaryScalingData = {
severeThreshold: 12,
hp: 1,
stress: 1,
attack: 1,
attack: 1
},
4: {
difficulty: 2,
@ -664,7 +664,7 @@ export const adversaryScalingData = {
severeThreshold: 10,
hp: 1,
stress: 1,
attack: 1,
attack: 1
}
},
solo: {
@ -674,7 +674,7 @@ export const adversaryScalingData = {
severeThreshold: 10,
hp: 0,
stress: 1,
attack: 2,
attack: 2
},
3: {
difficulty: 2,
@ -682,7 +682,7 @@ export const adversaryScalingData = {
severeThreshold: 15,
hp: 2,
stress: 1,
attack: 2,
attack: 2
},
4: {
difficulty: 2,
@ -690,7 +690,7 @@ export const adversaryScalingData = {
severeThreshold: 25,
hp: 0,
stress: 1,
attack: 3,
attack: 3
}
},
standard: {
@ -700,7 +700,7 @@ export const adversaryScalingData = {
severeThreshold: 8,
hp: 0,
stress: 0,
attack: 1,
attack: 1
},
3: {
difficulty: 2,
@ -708,7 +708,7 @@ export const adversaryScalingData = {
severeThreshold: 15,
hp: 1,
stress: 1,
attack: 1,
attack: 1
},
4: {
difficulty: 2,
@ -716,7 +716,7 @@ export const adversaryScalingData = {
severeThreshold: 15,
hp: 0,
stress: 1,
attack: 1,
attack: 1
}
},
support: {
@ -726,7 +726,7 @@ export const adversaryScalingData = {
severeThreshold: 8,
hp: 1,
stress: 1,
attack: 1,
attack: 1
},
3: {
difficulty: 2,
@ -734,7 +734,7 @@ export const adversaryScalingData = {
severeThreshold: 12,
hp: 0,
stress: 0,
attack: 1,
attack: 1
},
4: {
difficulty: 2,
@ -742,27 +742,27 @@ export const adversaryScalingData = {
severeThreshold: 10,
hp: 1,
stress: 1,
attack: 1,
attack: 1
}
}
};
/**
/**
* Scaling data used for an adversary's damage.
* Tier 4 is missing certain adversary types and therefore skews upwards.
* We manually set tier 4 data to hopefully lead to better results
*/
export const adversaryExpectedDamage = {
basic: {
1: { mean: 7.321428571428571, deviation: 1.962519002770912 },
2: { mean: 12.444444444444445, deviation: 2.0631069425529676 },
3: { mean: 15.722222222222221, deviation: 2.486565208464823 },
4: { mean: 26, deviation: 5.2 }
},
minion: {
1: { mean: 2.142857142857143, deviation: 1.0690449676496976 },
2: { mean: 5, deviation: 0.816496580927726 },
3: { mean: 6.5, deviation: 2.1213203435596424 },
4: { mean: 11, deviation: 1 }
}
basic: {
1: { mean: 7.321428571428571, deviation: 1.962519002770912 },
2: { mean: 12.444444444444445, deviation: 2.0631069425529676 },
3: { mean: 15.722222222222221, deviation: 2.486565208464823 },
4: { mean: 26, deviation: 5.2 }
},
minion: {
1: { mean: 2.142857142857143, deviation: 1.0690449676496976 },
2: { mean: 5, deviation: 0.816496580927726 },
3: { mean: 6.5, deviation: 2.1213203435596424 },
4: { mean: 11, deviation: 1 }
}
};

View file

@ -6,6 +6,7 @@ import DhCreature from './creature.mjs';
import { attributeField, resourceField, stressDamageReductionRule, bonusField } from '../fields/actorField.mjs';
import { ActionField } from '../fields/actionField.mjs';
import DHCharacterSettings from '../../applications/sheets-configs/character-settings.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
export default class DhCharacter extends DhCreature {
/**@override */
@ -317,7 +318,8 @@ export default class DhCharacter extends DhCreature {
hint: 'DAGGERHEART.ACTORS.Character.roll.guaranteedCritical.hint'
})
})
})
}),
sidebarFavorites: new ForeignDocumentUUIDArrayField({ type: 'Item' })
};
}
@ -586,28 +588,6 @@ export default class DhCharacter extends DhCreature {
return diceTypes[attackDiceIndex];
}
static async unequipBeforeEquip(itemToEquip) {
const primary = this.primaryWeapon,
secondary = this.secondaryWeapon;
if (itemToEquip.system.secondary) {
if (primary && primary.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) {
await primary.update({ 'system.equipped': false });
}
if (secondary) {
await secondary.update({ 'system.equipped': false });
}
} else {
if (secondary && itemToEquip.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) {
await secondary.update({ 'system.equipped': false });
}
if (primary) {
await primary.update({ 'system.equipped': false });
}
}
}
prepareBaseData() {
this.evasion += this.class.value?.system?.evasion ?? 0;

View file

@ -992,4 +992,111 @@ export default class DhpActor extends Actor {
return allTokens;
}
async toggleDomainCardVault(card, options = { render: true }) {
const { render } = options;
const { available } = this.system.loadoutSlot;
if (card.system.inVault && !available && !card.system.loadoutIgnore) {
return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.loadoutMaxReached'));
}
const toVault = options.toVault ?? !card.system.inVault;
await card?.update({ 'system.inVault': toVault }, { render });
return [{ item: card, add: !toVault }];
}
async unequipBeforeEquip(itemToEquip, options = { render: true }) {
const { render } = options;
const primary = this.system.primaryWeapon,
secondary = this.system.secondaryWeapon;
let unequippedItems = [];
if (itemToEquip.system.secondary) {
if (primary && primary.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) {
unequippedItems.push(primary);
}
if (secondary) {
unequippedItems.push(secondary);
}
} else {
if (secondary && itemToEquip.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) {
unequippedItems.push(secondary);
}
if (primary) {
unequippedItems.push(primary);
}
}
for (const item of unequippedItems) await item?.update({ 'system.equipped': false }, { render });
return unequippedItems;
}
async toggleEquipItem(item, options = { render: true }) {
const { render } = options;
const changedItems = [];
const updateAndAddChangedItem = async (item, equip) => {
changedItems.push({ item, add: equip });
await item.update({ 'system.equipped': equip }, { render });
};
if (item.system.equipped && [undefined, false].includes(options.equip)) {
await updateAndAddChangedItem(item, false);
return changedItems;
}
switch (item.type) {
case 'armor':
const currentArmor = this.system.armor;
if (currentArmor) {
await updateAndAddChangedItem(currentArmor, false);
}
await updateAndAddChangedItem(item, true);
break;
case 'weapon':
if (this.effects.find(x => !x.disabled && x.type === 'beastform')) {
return ui.notifications.warn(
game.i18n.localize('DAGGERHEART.UI.Notifications.beastformEquipWeapon')
);
}
const unequippedItems = await this.unequipBeforeEquip(item, { render: false });
changedItems.push(...unequippedItems.map(x => ({ item: x, add: false })));
await updateAndAddChangedItem(item, true);
break;
}
return changedItems;
}
/* This is very convoluted, and there is almost certainly a better way to do it. I couldn't get it working any better way atm though. */
async setFavoriteItem(item, setFavorited) {
const favoritesToRemove = [];
const favoritesToAdd = [];
if (['weapon', 'armor'].includes(item.type)) {
const changedData = await this.toggleEquipItem(item, { render: false, equip: setFavorited });
for (const data of changedData) {
if (data.add) favoritesToAdd.push(data.item);
else favoritesToRemove.push(data.item);
}
} else if (item.type === 'domainCard') {
const changedData = await this.toggleDomainCardVault(item, { render: false, toVault: !setFavorited });
for (const data of changedData) {
if (data.add) favoritesToAdd.push(data.item);
else favoritesToRemove.push(data.item);
}
} else if (setFavorited) favoritesToAdd.push(item);
else favoritesToRemove.push(item);
this.update({
'system.sidebarFavorites': [
...this.system.sidebarFavorites.filter(x => favoritesToRemove.every(r => r.id !== x.id)),
...favoritesToAdd
]
});
}
}

View file

@ -229,5 +229,11 @@ export default class DHItem extends foundry.documents.Item {
async _preDelete() {
this.deleteTriggers();
if (this.parent?.type === 'character') {
const filteredFavorites = this.parent.system.sidebarFavorites.filter(x => x.id !== this.id);
if (this.parent.system.sidebarFavorites.length !== filteredFavorites.length)
this.parent.update({ 'system.sidebarFavorites': filteredFavorites });
}
}
}