mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
* add basic drag drop window * add better field * make effects copy onto actor on attachment * make items from inventory draggable * working drop from inventory * remove duplication issue * add attachment only flag and logic * add weapons to attachables * remove debug logs * try to make it drier * remove unecessary try catch * remove extra configs * remove superfluous comments * remove spurious defenses * make drier * remove unecessary code * deduplicate and simplify * its a desert * standardize to be more similar to class item code * fix bug of duplicate effects being created * fix localization string * fix bug of item equiping and un equiping * remove this since were not going to be using attachmentonly * update attachment tab with comments * remove attachment only logic in favor of just transfer * change flags * change armor and weapon to be attachableItem * change armor and weapon to be attachableItem * change weapon to use mixin * add mixin to armor * move everything to mixin sheet * refactor code for review comments * cleanup and somehow git is ignoring some changes * see if this picks up the changes now * Import/Export updates --------- Co-authored-by: psitacus <walther.johnson@ucalgary.ca> Co-authored-by: WBHarry <williambjrklund@gmail.com>
147 lines
6 KiB
JavaScript
147 lines
6 KiB
JavaScript
import AttachableItem from './attachableItem.mjs';
|
|
import { actionsTypes } from '../action/_module.mjs';
|
|
import ActionField from '../fields/actionField.mjs';
|
|
|
|
export default class DHWeapon extends AttachableItem {
|
|
/** @inheritDoc */
|
|
static get metadata() {
|
|
return foundry.utils.mergeObject(super.metadata, {
|
|
label: 'TYPES.Item.weapon',
|
|
type: 'weapon',
|
|
hasDescription: true,
|
|
isQuantifiable: true,
|
|
isInventoryItem: true
|
|
// hasInitialAction: true
|
|
});
|
|
}
|
|
|
|
/** @inheritDoc */
|
|
static defineSchema() {
|
|
const fields = foundry.data.fields;
|
|
return {
|
|
...super.defineSchema(),
|
|
tier: new fields.NumberField({ required: true, integer: true, initial: 1, min: 1 }),
|
|
equipped: new fields.BooleanField({ initial: false }),
|
|
|
|
//SETTINGS
|
|
secondary: new fields.BooleanField({ initial: false }),
|
|
burden: new fields.StringField({ required: true, choices: CONFIG.DH.GENERAL.burden, initial: 'oneHanded' }),
|
|
weaponFeatures: new fields.ArrayField(
|
|
new fields.SchemaField({
|
|
value: new fields.StringField({
|
|
required: true,
|
|
choices: CONFIG.DH.ITEM.weaponFeatures,
|
|
blank: true
|
|
}),
|
|
effectIds: new fields.ArrayField(new fields.StringField({ required: true })),
|
|
actionIds: new fields.ArrayField(new fields.StringField({ required: true }))
|
|
})
|
|
),
|
|
attack: new ActionField({
|
|
initial: {
|
|
name: 'Attack',
|
|
img: 'icons/skills/melee/blood-slash-foam-red.webp',
|
|
_id: foundry.utils.randomID(),
|
|
systemPath: 'attack',
|
|
type: 'attack',
|
|
range: 'melee',
|
|
target: {
|
|
type: 'any',
|
|
amount: 1
|
|
},
|
|
roll: {
|
|
trait: 'agility',
|
|
type: 'weapon'
|
|
},
|
|
damage: {
|
|
parts: [
|
|
{
|
|
type: ['physical'],
|
|
value: {
|
|
multiplier: 'prof',
|
|
dice: 'd8'
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}),
|
|
actions: new fields.ArrayField(new ActionField())
|
|
};
|
|
}
|
|
|
|
get actionsList() {
|
|
return [this.attack, ...this.actions];
|
|
}
|
|
|
|
get customActions() {
|
|
return this.actions.filter(
|
|
action => !this.weaponFeatures.some(feature => feature.actionIds.includes(action.id))
|
|
);
|
|
}
|
|
|
|
async _preUpdate(changes, options, user) {
|
|
const allowed = await super._preUpdate(changes, options, user);
|
|
if (allowed === false) return false;
|
|
|
|
if (changes.system?.weaponFeatures) {
|
|
const removed = this.weaponFeatures.filter(x => !changes.system.weaponFeatures.includes(x));
|
|
const added = changes.system.weaponFeatures.filter(x => !this.weaponFeatures.includes(x));
|
|
|
|
const removedEffectsUpdate = [];
|
|
const removedActionsUpdate = [];
|
|
for (let weaponFeature of removed) {
|
|
removedEffectsUpdate.push(...weaponFeature.effectIds);
|
|
removedActionsUpdate.push(...weaponFeature.actionIds);
|
|
}
|
|
|
|
await this.parent.deleteEmbeddedDocuments('ActiveEffect', removedEffectsUpdate);
|
|
changes.system.actions = this.actions.filter(x => !removedActionsUpdate.includes(x._id));
|
|
|
|
for (let weaponFeature of added) {
|
|
const featureData = CONFIG.DH.ITEM.weaponFeatures[weaponFeature.value];
|
|
if (featureData.effects?.length > 0) {
|
|
const embeddedItems = await this.parent.createEmbeddedDocuments('ActiveEffect', [
|
|
{
|
|
name: game.i18n.localize(featureData.label),
|
|
description: game.i18n.localize(featureData.description),
|
|
changes: featureData.effects.flatMap(x => x.changes)
|
|
}
|
|
]);
|
|
weaponFeature.effectIds = embeddedItems.map(x => x.id);
|
|
}
|
|
|
|
const newActions = [];
|
|
if (featureData.actions?.length > 0) {
|
|
for (let action of featureData.actions) {
|
|
const embeddedEffects = await this.parent.createEmbeddedDocuments(
|
|
'ActiveEffect',
|
|
(action.effects ?? []).map(effect => ({
|
|
...effect,
|
|
transfer: false,
|
|
name: game.i18n.localize(effect.name),
|
|
description: game.i18n.localize(effect.description)
|
|
}))
|
|
);
|
|
const cls = actionsTypes[action.type];
|
|
newActions.push(
|
|
new cls(
|
|
{
|
|
...action,
|
|
_id: foundry.utils.randomID(),
|
|
name: game.i18n.localize(action.name),
|
|
description: game.i18n.localize(action.description),
|
|
effects: embeddedEffects.map(x => ({ _id: x.id }))
|
|
},
|
|
{ parent: this }
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
changes.system.actions = [...this.actions, ...newActions];
|
|
weaponFeature.actionIds = newActions.map(x => x._id);
|
|
}
|
|
}
|
|
}
|
|
}
|