mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
* Updated the background image for the system * Fixed so Weapon/Armor features are added again * Fixed so fear is available as a resource to be deducted by actions (#757) * Changed to use the config labels and src * Updated Weapons * Fixed so the decrease button of simple fear tracker is not visible when not hovered * Fixed so armor preUpdate doesn't fail if no system changes are made * Updated .gitignore and author details (#777) * Add author details and name mapping for chrisryan10 (#773) Co-authored-by: Chris Ryan <chrisr@blackhole> * Add build to ignore for my linux dev (#775) Co-authored-by: Chris Ryan <chrisr@blackhole> --------- Co-authored-by: Chris Ryan <chrisr@blackhole> * Corrected sneak attack active effect (#780) * Fixed a spelling error (#779) * Fix bardic rally showing in damage dialog when it should not (#783) * update spelling (#786) * Translating inventory descriptions (#782) * updated credits for 1.0.1 release (#797) * updated credits for 1.0.1 release * further updated artwork credits * Chagned handlebarhelper rollparsed to be more defensive (#794) * Added missing scene refreshType (#790) * Remove ability use buttons for not owned abilities (#795) * [Fix] PrayerDice Fixed (#799) * Fixed prayer dice, and wheelchair images * Fixed -settings data sources * Dragging features from one adversary to another (#788) * [Fix] Levelup Fixes (#787) * Fixed crash on experience selection. Fixed subclass error on multiclassing * Fixed so multiclasses do not gain the hope feature for the class * Fixed so Class/Subclass features are properly deleted on delevel * Removed automatic deletion of features on delevel when not using levelup auto * Fixed so custom domains can be selected in levelup when multiclassing * Changed so encounter countdowns is a button (#804) * Fixed so that dropping on class/subclass...creates the item on the character (#803) * [BUG] - Importing All Adversaries/Environments (#814) Fixes #774 Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * Bug/671 reaction roll chat title (#809) * Update Reaction Roll Chat Message Title * Removed console log --------- Co-authored-by: WBHarry <williambjrklund@gmail.com> * Improve Trait tooltip display (#817) Fixes #806 Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * [BUG] - Combat Tracker d12 logo not found (#812) Fixes #764 Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * Compendium Browser (#821) * Corrected timbending description localization (#816) * [Fix] Compendium Item (#810) * Corrected Emberwoven Armor * Fixed subclass regression * Fixed so character's with wildcard images don't break beastform (#815) * Fix roll result based duality damage (#822) * Impproved Adversary Sheet Data Display (#751) * Impproved Adversary Sheet Data Display Fixes #604 * FIX: formula lables for attacks and weapons --------- Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * Fixed so exp increases can be selected normally (#835) * Update localization of rollSelection.hbs (#841) The Fear label lacked a localization path * renamed .md files (#834) * Removed the unintended icons that came from merge conflicts (#838) * Sheet image position (#861) * Remove extra result text from reaction chat message (#860) * Remove extra result text from reaction chat message * Remove log * [Fix] 850 - Downtime Refreshes (#859) * Fixed the filtering of refreshable features * Raised version * [Fix] 691 - CharacterCreation Improvement (#863) * Removed main creation tab. Added equipment to remaining tab * Fixed MixedAncestry name setting * Fixed tab after first creation * Fix/857 generic roll buttons (#866) * Action Macro working again * Remove buttons from generic roll for non-gm * Update sidebar.less Armor Slots label padding, for translations (#872) Equalizes the vertical and horizontal padding on the Armor Slots status label, to allow for more (much needed) room for the upcoming French translation (and others in the future). Doesn't change anything for the display in English. * Hid item attachments for now (#876) * Fixed so effects supposed to use item data use the model directly, since items have no rolldata (#883) * Made sure the beastform user isn't moved onto other duplicate actors. Fixed scrolling text duplication (#882) * Change the critical damage max calculation (#890) * Change the critical damage max calculation to avoid setting the rolled portion to maximum all the time. * Change to the more neater code * Restored package.json --------- Co-authored-by: Chris Ryan <chrisr@blackhole> Co-authored-by: WBHarry <williambjrklund@gmail.com> * Fix movement (#885) * Changed so companion can level up on its own (#879) * Fix the missing ancestries in the SRD (#888) Co-authored-by: Chris Ryan <chrisr@blackhole> * Removed the old, now unused companion levelup button (#893) * Fixed so custom downtime moves will display their descriptions in the tooltip (#894) * Made coinflip icons in chat round (#895) * Fixed undefined case (#898) * Fix/877 hope update order (#896) * Action Macro working again * k * Fix Hope gain on Duality Roll * [Feature] Descriptions enhancements (#887) * add style to hover items and add start setting to features be expanded by default * REFACTOR: now prepare description onRender and simply the other methods * add setting to extend description from items and add molilo contacts in system.json --------- Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * Fixed traits container styling in light-mode (#899) * [BUG] - Movement Button selector not showing current mode (#912) Fixes #910 Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> * Fix/864 chat targeting (#911) * Fix targeting * Fix chat target selection * Uncomment chatDisplay * Removed unessecary arg * [Feature] 648 - Mark Defeated Actors (#914) * Improved death marking styling * Added automation for defeated status * Fixed so the tracker recognises and sets the correct defeated statuses depending on type * Fixed so missing statuses doesn't cause crashes * Increased companion sheet width by 40 pixels * Added missing inheritDoc * Removed fas * FIX: use img instead of icons con statusEffectConfigns (#917) Authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> --------- Co-authored-by: Chris Ryan <73275196+chrisryan10@users.noreply.github.com> Co-authored-by: Chris Ryan <chrisr@blackhole> Co-authored-by: Dapoulp <74197441+Dapoulp@users.noreply.github.com> Co-authored-by: IrkTheImp <41175833+IrkTheImp@users.noreply.github.com> Co-authored-by: CPTN_Cosmo <cptncosmo@gmail.com> Co-authored-by: Josh Q. <jshqntnr13@gmail.com> Co-authored-by: joaquinpereyra98 <24190917+joaquinpereyra98@users.noreply.github.com> Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> Co-authored-by: SunnySunSun <snysun@pm.me> Co-authored-by: Murilo Brito <91566541+moliloo@users.noreply.github.com>
293 lines
10 KiB
JavaScript
293 lines
10 KiB
JavaScript
import DHActionConfig from '../../applications/sheets-configs/action-config.mjs';
|
|
import { itemAbleRollParse } from '../../helpers/utils.mjs';
|
|
import MappingField from './mappingField.mjs';
|
|
|
|
/**
|
|
* Specialized collection type for stored actions.
|
|
* @param {DataModel} model The parent DataModel to which this ActionCollection belongs.
|
|
* @param {Action[]} entries The actions to store.
|
|
*/
|
|
export class ActionCollection extends Collection {
|
|
constructor(model, entries) {
|
|
super();
|
|
this.#model = model;
|
|
for (const entry of entries) {
|
|
if (!(entry instanceof game.system.api.models.actions.actionsTypes.base)) continue;
|
|
this.set(entry._id, entry);
|
|
}
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
/* Properties */
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
* The parent DataModel to which this ActionCollection belongs.
|
|
* @type {DataModel}
|
|
*/
|
|
#model;
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* -------------------------------------------- */
|
|
/* Methods */
|
|
/* -------------------------------------------- */
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
* Test the given predicate against every entry in the Collection.
|
|
* @param {function(*, number, ActionCollection): boolean} predicate The predicate.
|
|
* @returns {boolean}
|
|
*/
|
|
every(predicate) {
|
|
return this.reduce((pass, v, i) => pass && predicate(v, i, this), true);
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
* Convert the ActionCollection to an array of simple objects.
|
|
* @param {boolean} [source=true] Draw data for contained Documents from the underlying data source?
|
|
* @returns {object[]} The extracted array of primitive objects.
|
|
*/
|
|
toObject(source = true) {
|
|
return this.map(doc => doc.toObject(source));
|
|
}
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
* Field that stores actions.
|
|
*/
|
|
export class ActionsField extends MappingField {
|
|
constructor(options) {
|
|
super(new ActionField(), options);
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @inheritDoc */
|
|
initialize(value, model, options) {
|
|
const actions = Object.values(super.initialize(value, model, options));
|
|
return new ActionCollection(model, actions);
|
|
}
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
* Field that stores action data and swaps class based on action type.
|
|
*/
|
|
export class ActionField extends foundry.data.fields.ObjectField {
|
|
getModel(value) {
|
|
return (
|
|
game.system.api.models.actions.actionsTypes[value.type] ??
|
|
null
|
|
);
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
_cleanType(value, options) {
|
|
if (!(typeof value === 'object')) value = {};
|
|
const cls = this.getModel(value);
|
|
if (cls) return cls.cleanData(value, options);
|
|
return value;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
initialize(value, model, options = {}) {
|
|
const cls = this.getModel(value);
|
|
if (cls) return new cls(value, { parent: model, ...options });
|
|
return foundry.utils.deepClone(value);
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
* Migrate this field's candidate source data.
|
|
* @param {object} sourceData Candidate source data of the root model.
|
|
* @param {any} fieldData The value of this field within the source data.
|
|
*/
|
|
migrateSource(sourceData, fieldData) {
|
|
const cls = this.getModel(fieldData);
|
|
if (cls) cls.migrateDataSafe(fieldData);
|
|
}
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
export function ActionMixin(Base) {
|
|
class Action extends Base {
|
|
static metadata = Object.freeze({
|
|
name: 'Action',
|
|
label: 'DAGGERHEART.GENERAL.Action.single',
|
|
sheetClass: DHActionConfig
|
|
});
|
|
|
|
static _sheets = new Map();
|
|
|
|
static get documentName() {
|
|
return this.metadata.name;
|
|
}
|
|
|
|
get documentName() {
|
|
return this.constructor.documentName;
|
|
}
|
|
|
|
static defaultName() {
|
|
return this.documentName;
|
|
}
|
|
|
|
get relativeUUID() {
|
|
return `.Item.${this.item.id}.Action.${this.id}`;
|
|
}
|
|
|
|
get uuid() {
|
|
return `${this.item.uuid}.${this.documentName}.${this.id}`;
|
|
}
|
|
|
|
get sheet() {
|
|
if (!this.constructor._sheets.has(this.uuid)) {
|
|
const sheet = new this.constructor.metadata.sheetClass(this);
|
|
this.constructor._sheets.set(this.uuid, sheet);
|
|
}
|
|
return this.constructor._sheets.get(this.uuid);
|
|
}
|
|
|
|
get inCollection() {
|
|
return foundry.utils.getProperty(this.parent, this.systemPath) instanceof Collection;
|
|
}
|
|
|
|
get remainingUses() {
|
|
if (!this.uses) return null;
|
|
|
|
return Math.max(
|
|
(this.uses.max ? itemAbleRollParse(this.uses.max, this.actor) : 0) - (this.uses.value ?? 0),
|
|
0
|
|
);
|
|
}
|
|
|
|
static async create(data, operation = {}) {
|
|
const { parent, renderSheet } = operation;
|
|
let { type } = data;
|
|
if (!type || !game.system.api.models.actions.actionsTypes[type]) {
|
|
({ type } =
|
|
(await foundry.applications.api.DialogV2.input({
|
|
window: { title: game.i18n.localize('DAGGERHEART.CONFIG.SelectAction.selectType') },
|
|
position: { width: 300 },
|
|
classes: ['daggerheart', 'dh-style'],
|
|
content: await foundry.applications.handlebars.renderTemplate(
|
|
'systems/daggerheart/templates/actionTypes/actionType.hbs',
|
|
{
|
|
types: CONFIG.DH.ACTIONS.actionTypes,
|
|
itemName: parent.parent?.name
|
|
}
|
|
),
|
|
ok: {
|
|
label: game.i18n.format('DOCUMENT.Create', {
|
|
type: game.i18n.localize('DAGGERHEART.GENERAL.Action.single')
|
|
})
|
|
}
|
|
})) ?? {});
|
|
}
|
|
if (!type) return;
|
|
|
|
const cls = game.system.api.models.actions.actionsTypes[type];
|
|
const action = new cls(
|
|
{
|
|
type,
|
|
...cls.getSourceConfig(parent)
|
|
},
|
|
{
|
|
parent
|
|
}
|
|
);
|
|
const created = await parent.parent.update({ [`system.actions.${action.id}`]: action.toObject() });
|
|
const newAction = created.system.actions.get(action.id);
|
|
if (!newAction) return null;
|
|
if (renderSheet) newAction.sheet.render({ force: true });
|
|
return newAction;
|
|
}
|
|
|
|
async update(updates, options = {}) {
|
|
const isSetting = !this.parent.parent;
|
|
const basePath = isSetting ? this.systemPath : `system.${this.systemPath}`;
|
|
const path = this.inCollection ? `${basePath}.${this.id}` : basePath;
|
|
let result = null;
|
|
if (isSetting) {
|
|
await this.parent.updateSource({ [path]: updates }, options);
|
|
result = this.parent;
|
|
} else {
|
|
result = await this.item.update({ [path]: updates }, options);
|
|
}
|
|
|
|
return this.inCollection
|
|
? foundry.utils.getProperty(result, basePath)?.get(this.id)
|
|
: foundry.utils.getProperty(result, basePath);
|
|
}
|
|
|
|
delete() {
|
|
if (!this.inCollection) return this.item;
|
|
const action = foundry.utils.getProperty(this.item, `system.${this.systemPath}`)?.get(this.id);
|
|
if (!action) return this.item;
|
|
this.item.update({ [`system.${this.systemPath}.-=${this.id}`]: null });
|
|
this.constructor._sheets.get(this.uuid)?.close();
|
|
}
|
|
|
|
async deleteDialog() {
|
|
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
|
window: {
|
|
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
|
type: game.i18n.localize(`DAGGERHEART.GENERAL.Action.single`),
|
|
name: this.name
|
|
})
|
|
},
|
|
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', {
|
|
name: this.name
|
|
})
|
|
});
|
|
if (!confirmed) return;
|
|
return this.delete();
|
|
}
|
|
|
|
async toChat(origin) {
|
|
const cls = getDocumentClass('ChatMessage');
|
|
const systemData = {
|
|
title: game.i18n.localize('DAGGERHEART.CONFIG.ActionType.action'),
|
|
origin: origin,
|
|
action: { name: this.name, img: this.img, tags: this.tags ? this.tags : ['Spell', 'Arcana', 'Lv 10'] },
|
|
itemOrigin: this.item,
|
|
description: this.description
|
|
};
|
|
const msg = {
|
|
type: 'abilityUse',
|
|
user: game.user.id,
|
|
actor: { name: this.actor.name, img: this.actor.img },
|
|
author: this.author,
|
|
speaker: cls.getSpeaker(),
|
|
title: game.i18n.localize('DAGGERHEART.UI.Chat.action.title'),
|
|
system: systemData,
|
|
content: await foundry.applications.handlebars.renderTemplate(
|
|
'systems/daggerheart/templates/ui/chat/action.hbs',
|
|
systemData
|
|
),
|
|
flags: {
|
|
daggerheart: {
|
|
cssClass: 'dh-chat-message dh-style'
|
|
}
|
|
}
|
|
};
|
|
|
|
ChatMessage.applyRollMode(msg, game.settings.get('core', 'rollMode'));
|
|
cls.create(msg);
|
|
}
|
|
}
|
|
|
|
return Action;
|
|
}
|