mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
.
This commit is contained in:
parent
09ef7fa96f
commit
b0f8442aaa
2 changed files with 46 additions and 29 deletions
|
|
@ -511,7 +511,7 @@ export default function DHApplicationMixin(Base) {
|
||||||
icon: 'fa-solid fa-trash',
|
icon: 'fa-solid fa-trash',
|
||||||
condition: target => {
|
condition: target => {
|
||||||
const doc = getDocFromElementSync(target);
|
const doc = getDocFromElementSync(target);
|
||||||
return doc && doc.type !== 'beastform';
|
return !doc || doc.type !== 'beastform';
|
||||||
},
|
},
|
||||||
callback: async (target, event) => {
|
callback: async (target, event) => {
|
||||||
const doc = await getDocFromElement(target);
|
const doc = await getDocFromElement(target);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { getScrollTextData } from '../../helpers/utils.mjs';
|
import { getScrollTextData, itemAbleRollParse } from '../../helpers/utils.mjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ArmorEffects are ActiveEffects that have a static changes field of length 1. It includes current and maximum armor.
|
* ArmorEffects are ActiveEffects that have a static changes field of length 1. It includes current and maximum armor.
|
||||||
|
|
@ -12,6 +12,11 @@ export default class ArmorEffect extends foundry.data.ActiveEffectTypeDataModel
|
||||||
...super.defineSchema(),
|
...super.defineSchema(),
|
||||||
changes: new fields.ArrayField(
|
changes: new fields.ArrayField(
|
||||||
new fields.SchemaField({
|
new fields.SchemaField({
|
||||||
|
key: new fields.StringField({
|
||||||
|
required: true,
|
||||||
|
nullable: false,
|
||||||
|
initial: 'system.armorScore'
|
||||||
|
}),
|
||||||
type: new fields.StringField({
|
type: new fields.StringField({
|
||||||
required: true,
|
required: true,
|
||||||
blank: false,
|
blank: false,
|
||||||
|
|
@ -27,11 +32,10 @@ export default class ArmorEffect extends foundry.data.ActiveEffectTypeDataModel
|
||||||
min: 0,
|
min: 0,
|
||||||
label: 'DAGGERHEART.GENERAL.value'
|
label: 'DAGGERHEART.GENERAL.value'
|
||||||
}),
|
}),
|
||||||
max: new fields.NumberField({
|
max: new fields.StringField({
|
||||||
required: true,
|
required: true,
|
||||||
integer: true,
|
nullable: false,
|
||||||
initial: 1,
|
initial: '1',
|
||||||
min: 1,
|
|
||||||
label: 'DAGGERHEART.GENERAL.max'
|
label: 'DAGGERHEART.GENERAL.max'
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
|
@ -99,7 +103,13 @@ export default class ArmorEffect extends foundry.data.ActiveEffectTypeDataModel
|
||||||
get armorChange() {
|
get armorChange() {
|
||||||
if (this.changes.length !== 1)
|
if (this.changes.length !== 1)
|
||||||
throw new Error('Unexpected error. An armor effect should have a changes field of length 1.');
|
throw new Error('Unexpected error. An armor effect should have a changes field of length 1.');
|
||||||
return this.changes[0];
|
|
||||||
|
const actor = this.parent.actor?.type === 'character' ? this.parent.actor : null;
|
||||||
|
const changeData = this.changes[0];
|
||||||
|
return {
|
||||||
|
...changeData,
|
||||||
|
max: actor ? itemAbleRollParse(changeData.max, actor, this.parent.parent) : changeData.max
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get armorData() {
|
get armorData() {
|
||||||
|
|
@ -121,21 +131,22 @@ export default class ArmorEffect extends foundry.data.ActiveEffectTypeDataModel
|
||||||
static orderEffectsForAutoChange(armorEffects, increasing) {
|
static orderEffectsForAutoChange(armorEffects, increasing) {
|
||||||
const getEffectWeight = effect => {
|
const getEffectWeight = effect => {
|
||||||
switch (effect.parent.type) {
|
switch (effect.parent.type) {
|
||||||
case 'loot':
|
|
||||||
case 'consumable':
|
|
||||||
return 2;
|
|
||||||
case 'class':
|
case 'class':
|
||||||
case 'subclass':
|
case 'subclass':
|
||||||
case 'ancestry':
|
case 'ancestry':
|
||||||
case 'community':
|
case 'community':
|
||||||
case 'feature':
|
case 'feature':
|
||||||
case 'domainCard':
|
case 'domainCard':
|
||||||
return 3;
|
return 2;
|
||||||
case 'weapon':
|
|
||||||
case 'armor':
|
case 'armor':
|
||||||
|
return 3;
|
||||||
|
case 'loot':
|
||||||
|
case 'consumable':
|
||||||
return 4;
|
return 4;
|
||||||
case 'character':
|
case 'weapon':
|
||||||
return 5;
|
return 5;
|
||||||
|
case 'character':
|
||||||
|
return 6;
|
||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -148,11 +159,6 @@ export default class ArmorEffect extends foundry.data.ActiveEffectTypeDataModel
|
||||||
|
|
||||||
/* Overrides */
|
/* Overrides */
|
||||||
|
|
||||||
prepareBaseData() {
|
|
||||||
const armorChange = this.armorChange;
|
|
||||||
armorChange.key = 'system.armorScore';
|
|
||||||
}
|
|
||||||
|
|
||||||
static getDefaultObject() {
|
static getDefaultObject() {
|
||||||
return {
|
return {
|
||||||
type: 'armor',
|
type: 'armor',
|
||||||
|
|
@ -174,21 +180,32 @@ export default class ArmorEffect extends foundry.data.ActiveEffectTypeDataModel
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (changes.system.changes.length === 1) {
|
||||||
changes.system.changes.length === 1 &&
|
if (changes.system.changes[0].type !== CONFIG.DH.GENERAL.activeEffectModes.armor.id) {
|
||||||
changes.system.changes[0].type !== CONFIG.DH.GENERAL.activeEffectModes.armor.id
|
ui.notifications.error(
|
||||||
) {
|
game.i18n.localize('DAGGERHEART.UI.Notifications.cannotAlterArmorEffectType')
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.cannotAlterArmorEffectType'));
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes.system.changes[0].value !== this.armorChange.value && this.parent.actor?.type === 'character') {
|
if (changes.system.changes[0].key !== 'system.armorScore') {
|
||||||
|
ui.notifications.error(
|
||||||
|
game.i18n.localize('DAGGERHEART.UI.Notifications.cannotAlterArmorEffectKey')
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
changes.system.changes[0].value !== this.armorChange.value &&
|
||||||
|
this.parent.actor?.type === 'character'
|
||||||
|
) {
|
||||||
const increased = changes.system.changes[0].value > this.armorChange.value;
|
const increased = changes.system.changes[0].value > this.armorChange.value;
|
||||||
const value = -1 * (this.armorChange.value - changes.system.changes[0].value);
|
const value = -1 * (this.armorChange.value - changes.system.changes[0].value);
|
||||||
options.scrollingTextData = [getScrollTextData(increased, value, 'armor')];
|
options.scrollingTextData = [getScrollTextData(increased, value, 'armor')];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_onUpdate(changes, options, userId) {
|
_onUpdate(changes, options, userId) {
|
||||||
super._onUpdate(changes, options, userId);
|
super._onUpdate(changes, options, userId);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue