mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 11:41:08 +01:00
Merged with main
This commit is contained in:
commit
53be047e12
58 changed files with 4027 additions and 1962 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
/**
|
||||
|
|
@ -10,100 +9,101 @@ const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
|||
*/
|
||||
|
||||
export default class Resources extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(options={}) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
id: "resources",
|
||||
classes: [],
|
||||
tag: "div",
|
||||
window: {
|
||||
frame: true,
|
||||
title: "Fear",
|
||||
positioned: true,
|
||||
resizable: true
|
||||
},
|
||||
actions: {
|
||||
setFear: Resources.setFear,
|
||||
increaseFear: Resources.increaseFear
|
||||
},
|
||||
position: {
|
||||
width: 222,
|
||||
height: 222,
|
||||
// top: "200px",
|
||||
// left: "120px"
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
}
|
||||
};
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
resources: {
|
||||
root: true,
|
||||
template: "systems/daggerheart/templates/views/resources.hbs"
|
||||
// template: "templates/ui/players.hbs"
|
||||
/** @inheritDoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
id: 'resources',
|
||||
classes: [],
|
||||
tag: 'div',
|
||||
window: {
|
||||
frame: true,
|
||||
title: 'Fear',
|
||||
positioned: true,
|
||||
resizable: true,
|
||||
minimizable: false
|
||||
},
|
||||
actions: {
|
||||
setFear: Resources.setFear,
|
||||
increaseFear: Resources.increaseFear
|
||||
},
|
||||
position: {
|
||||
width: 222,
|
||||
height: 222
|
||||
// top: "200px",
|
||||
// left: "120px"
|
||||
}
|
||||
};
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
resources: {
|
||||
root: true,
|
||||
template: 'systems/daggerheart/templates/views/resources.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
get currentFear() {
|
||||
return game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
}
|
||||
};
|
||||
|
||||
get currentFear() {
|
||||
return game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
}
|
||||
get maxFear() {
|
||||
return game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.MaxFear);
|
||||
}
|
||||
|
||||
get maxFear() {
|
||||
return game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.MaxFear);
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
/* Rendering */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Rendering */
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
async _prepareContext(_options) {
|
||||
const display = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.DisplayFear),
|
||||
current = this.currentFear,
|
||||
max = this.maxFear,
|
||||
percent = (current / max) * 100,
|
||||
isGM = game.user.isGM;
|
||||
// Return the data for rendering
|
||||
return { display, current, max, percent, isGM };
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _prepareContext(_options) {
|
||||
const display = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.DisplayFear),
|
||||
current = this.currentFear,
|
||||
max = this.maxFear,
|
||||
percent = (current / max) * 100,
|
||||
isGM = game.user.isGM;
|
||||
// Return the data for rendering
|
||||
return {display, current, max, percent, isGM};
|
||||
}
|
||||
/** @override */
|
||||
async _preFirstRender(context, options) {
|
||||
options.position = game.user.getFlag(SYSTEM.id, 'app.resources.position') ?? Resources.DEFAULT_OPTIONS.position;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _preFirstRender(context, options) {
|
||||
options.position = game.user.getFlag(SYSTEM.id, 'app.resources.position') ?? Resources.DEFAULT_OPTIONS.position;
|
||||
}
|
||||
/** @override */
|
||||
async _preRender(context, options) {
|
||||
if (this.currentFear > this.maxFear)
|
||||
await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear, this.maxFear);
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _preRender(context, options) {
|
||||
if(this.currentFear > this.maxFear) await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear, this.maxFear);
|
||||
}
|
||||
_onPosition(position) {
|
||||
game.user.setFlag(SYSTEM.id, 'app.resources.position', position);
|
||||
}
|
||||
|
||||
_onPosition(position) {
|
||||
game.user.setFlag(SYSTEM.id, 'app.resources.position', position);
|
||||
}
|
||||
async close(options = {}) {
|
||||
if (!options.allowed) return;
|
||||
else super.close(options);
|
||||
}
|
||||
|
||||
async close(options={}) {
|
||||
if(!options.allowed) return;
|
||||
else super.close(options);
|
||||
}
|
||||
static async setFear(event, target) {
|
||||
if (!game.user.isGM) return;
|
||||
const fearCount = Number(target.dataset.index ?? 0);
|
||||
await this.updateFear(this.currentFear === fearCount + 1 ? fearCount : fearCount + 1);
|
||||
}
|
||||
|
||||
static async setFear(event, target) {
|
||||
if(!game.user.isGM) return;
|
||||
const fearCount = Number(target.dataset.index ?? 0);
|
||||
await this.updateFear(this.currentFear === fearCount + 1 ? fearCount : fearCount + 1);
|
||||
}
|
||||
static async increaseFear(event, target) {
|
||||
let value = target.dataset.increment ?? 0,
|
||||
operator = value.split('')[0] ?? null;
|
||||
value = Number(value);
|
||||
await this.updateFear(operator ? this.currentFear + value : value);
|
||||
}
|
||||
|
||||
static async increaseFear(event, target) {
|
||||
let value = target.dataset.increment ?? 0,
|
||||
operator = value.split('')[0] ?? null;
|
||||
value = Number(value);
|
||||
await this.updateFear(operator ? this.currentFear + value : value);
|
||||
}
|
||||
|
||||
async updateFear(value) {
|
||||
if(!game.user.isGM) return;
|
||||
value = Math.max(0, Math.min(this.maxFear, value));
|
||||
await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear, value);
|
||||
}
|
||||
}
|
||||
async updateFear(value) {
|
||||
if (!game.user.isGM) return;
|
||||
value = Math.max(0, Math.min(this.maxFear, value));
|
||||
await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear, value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
import { DualityRollColor } from '../config/settingsConfig.mjs';
|
||||
import { defaultLevelTiers, DhLevelTiers } from '../data/levelTier.mjs';
|
||||
import DhAppearance from '../data/settings/Appearance.mjs';
|
||||
import DHAppearanceSettings from './settings/appearanceSettings.mjs';
|
||||
import DhVariantRules from '../data/settings/VariantRules.mjs';
|
||||
import DHVariantRuleSettings from './settings/variantRuleSettings.mjs';
|
||||
|
||||
class DhpAutomationSettings extends FormApplication {
|
||||
constructor(object = {}, options = {}) {
|
||||
|
|
@ -181,7 +185,8 @@ export const registerDHSettings = () => {
|
|||
type: Number,
|
||||
default: 0,
|
||||
onChange: () => {
|
||||
if(ui.resources) ui.resources.render({force: true});
|
||||
if (ui.resources) ui.resources.render({ force: true });
|
||||
ui.combat.render({ force: true });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -193,7 +198,7 @@ export const registerDHSettings = () => {
|
|||
type: Number,
|
||||
default: 12,
|
||||
onChange: () => {
|
||||
if(ui.resources) ui.resources.render({force: true});
|
||||
if (ui.resources) ui.resources.render({ force: true });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -204,15 +209,15 @@ export const registerDHSettings = () => {
|
|||
config: true,
|
||||
type: String,
|
||||
choices: {
|
||||
'token': 'Tokens',
|
||||
'bar': 'Bar',
|
||||
'hide': 'Hide'
|
||||
token: 'Tokens',
|
||||
bar: 'Bar',
|
||||
hide: 'Hide'
|
||||
},
|
||||
default: 'token',
|
||||
onChange: value => {
|
||||
if(ui.resources) {
|
||||
if(value === 'hide') ui.resources.close({allowed: true});
|
||||
else ui.resources.render({force: true});
|
||||
if (ui.resources) {
|
||||
if (value === 'hide') ui.resources.close({ allowed: true });
|
||||
else ui.resources.render({ force: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -251,6 +256,13 @@ export const registerDHSettings = () => {
|
|||
}
|
||||
});
|
||||
|
||||
game.settings.register(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules, {
|
||||
scope: 'world',
|
||||
config: false,
|
||||
type: DhVariantRules,
|
||||
default: DhVariantRules.defaultSchema
|
||||
});
|
||||
|
||||
game.settings.register(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.appearance, {
|
||||
scope: 'client',
|
||||
config: false,
|
||||
|
|
@ -258,6 +270,23 @@ export const registerDHSettings = () => {
|
|||
default: DhAppearance.defaultSchema
|
||||
});
|
||||
|
||||
game.settings.register(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.DualityRollColor, {
|
||||
name: game.i18n.localize('DAGGERHEART.Settings.DualityRollColor.Name'),
|
||||
hint: game.i18n.localize('DAGGERHEART.Settings.DualityRollColor.Hint'),
|
||||
scope: 'world',
|
||||
config: true,
|
||||
type: Number,
|
||||
choices: Object.values(DualityRollColor),
|
||||
default: DualityRollColor.colorful.value
|
||||
});
|
||||
|
||||
game.settings.register(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.LevelTiers, {
|
||||
scope: 'world',
|
||||
config: false,
|
||||
type: DhLevelTiers,
|
||||
default: defaultLevelTiers
|
||||
});
|
||||
|
||||
game.settings.registerMenu(SYSTEM.id, SYSTEM.SETTINGS.menu.Automation.Name, {
|
||||
name: game.i18n.localize('DAGGERHEART.Settings.Menu.Automation.Name'),
|
||||
label: game.i18n.localize('DAGGERHEART.Settings.Menu.Automation.Label'),
|
||||
|
|
@ -291,4 +320,13 @@ export const registerDHSettings = () => {
|
|||
type: DHAppearanceSettings,
|
||||
restricted: false
|
||||
});
|
||||
|
||||
game.settings.registerMenu(SYSTEM.id, SYSTEM.SETTINGS.menu.VariantRules.Name, {
|
||||
name: game.i18n.localize('DAGGERHEART.Settings.Menu.VariantRules.title'),
|
||||
label: game.i18n.localize('DAGGERHEART.Settings.Menu.VariantRules.label'),
|
||||
hint: game.i18n.localize('DAGGERHEART.Settings.Menu.VariantRules.hint'),
|
||||
icon: SYSTEM.SETTINGS.menu.VariantRules.Icon,
|
||||
type: DHVariantRuleSettings,
|
||||
restricted: false
|
||||
});
|
||||
};
|
||||
|
|
|
|||
59
module/applications/settings/variantRuleSettings.mjs
Normal file
59
module/applications/settings/variantRuleSettings.mjs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import DhVariantRules from '../../data/settings/VariantRules.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class DHVariantRuleSettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor() {
|
||||
super({});
|
||||
|
||||
this.settings = new DhVariantRules(
|
||||
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules).toObject()
|
||||
);
|
||||
}
|
||||
|
||||
get title() {
|
||||
return game.i18n.localize('DAGGERHEART.Settings.Menu.VariantRules.name');
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
id: 'daggerheart-appearance-settings',
|
||||
classes: ['daggerheart', 'setting', 'dh-style'],
|
||||
position: { width: '600', height: 'auto' },
|
||||
actions: {
|
||||
reset: this.reset,
|
||||
save: this.save
|
||||
},
|
||||
form: { handler: this.updateData, submitOnChange: true }
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
main: {
|
||||
template: 'systems/daggerheart/templates/settings/variant-rules.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.settingFields = this.settings;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static async updateData(event, element, formData) {
|
||||
const updatedSettings = foundry.utils.expandObject(formData.object);
|
||||
|
||||
await this.settings.updateSource(updatedSettings);
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async reset() {
|
||||
this.settings = new DhVariantRules();
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async save() {
|
||||
await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules, this.settings.toObject());
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -362,7 +362,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
name: x.actor.name,
|
||||
img: x.actor.img,
|
||||
difficulty: x.actor.system.difficulty,
|
||||
evasion: x.actor.system.evasion
|
||||
evasion: x.actor.system.evasion.value
|
||||
}));
|
||||
|
||||
const cls = getDocumentClass('ChatMessage');
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { capitalize } from '../../helpers/utils.mjs';
|
||||
import DhpDeathMove from '../deathMove.mjs';
|
||||
import DhpDowntime from '../downtime.mjs';
|
||||
import DhpLevelup from '../levelup.mjs';
|
||||
import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs';
|
||||
import DaggerheartSheet from './daggerheart-sheet.mjs';
|
||||
import { abilities } from '../../config/actorConfig.mjs';
|
||||
import DhlevelUp from '../levelup.mjs';
|
||||
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
const { TextEditor } = foundry.applications.ux;
|
||||
|
|
@ -167,13 +167,23 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
$(htmlElement).find('.attribute-value').on('change', this.attributeChange.bind(this));
|
||||
$(htmlElement).find('.tab-selector').on('click', this.tabSwitch.bind(this));
|
||||
$(htmlElement).find('.level-title.levelup').on('click', this.openLevelUp.bind(this));
|
||||
$(htmlElement).find('.feature-input').on('change', this.onFeatureInputBlur.bind(this));
|
||||
$(htmlElement).find('.experience-description').on('change', this.experienceDescriptionChange.bind(this));
|
||||
$(htmlElement).find('.experience-value').on('change', this.experienceValueChange.bind(this));
|
||||
$(htmlElement).find('[data-item]').on('change', this.itemUpdate.bind(this));
|
||||
htmlElement
|
||||
.querySelectorAll('.attribute-value')
|
||||
.forEach(element => element.addEventListener('change', this.attributeChange.bind(this)));
|
||||
htmlElement
|
||||
.querySelectorAll('.tab-selector')
|
||||
.forEach(element => element.addEventListener('click', this.tabSwitch.bind(this)));
|
||||
htmlElement.querySelector('.level-title.levelup')?.addEventListener('click', this.openLevelUp.bind(this));
|
||||
htmlElement
|
||||
.querySelectorAll('.feature-input')
|
||||
.forEach(element => element.addEventListener('change', this.onFeatureInputBlur.bind(this)));
|
||||
htmlElement
|
||||
.querySelectorAll('.experience-description')
|
||||
.forEach(element => element.addEventListener('change', this.experienceDescriptionChange.bind(this)));
|
||||
htmlElement
|
||||
.querySelectorAll('.experience-value')
|
||||
.forEach(element => element.addEventListener('change', this.experienceValueChange.bind(this)));
|
||||
htmlElement.querySelector('.level-value').addEventListener('change', this.onLevelChange.bind(this));
|
||||
}
|
||||
|
||||
async _prepareContext(_options) {
|
||||
|
|
@ -188,7 +198,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
context.storyEditor = this.storyEditor;
|
||||
context.multiclassFeatureSetSelected = this.multiclassFeatureSetSelected;
|
||||
|
||||
const selectedAttributes = Object.values(this.document.system.attributes).map(x => x.data.base);
|
||||
const selectedAttributes = Object.values(this.document.system.traits).map(x => x.base);
|
||||
context.abilityScoreArray = JSON.parse(
|
||||
await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.General.AbilityArray)
|
||||
).reduce((acc, x) => {
|
||||
|
|
@ -204,7 +214,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
if (!context.abilityScoreArray.includes(0)) context.abilityScoreArray.push({ name: 0, value: 0 });
|
||||
context.abilityScoresFinished = context.abilityScoreArray.every(x => x.value === 0);
|
||||
|
||||
//FIXME:
|
||||
//FIXME:
|
||||
context.domains = this.document.system.class
|
||||
? {
|
||||
first: this.document.system.class.system.domains[0]
|
||||
|
|
@ -216,9 +226,9 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
: {};
|
||||
|
||||
context.attributes = Object.keys(this.document.system.attributes).reduce((acc, key) => {
|
||||
context.attributes = Object.keys(this.document.system.traits).reduce((acc, key) => {
|
||||
acc[key] = {
|
||||
...this.document.system.attributes[key],
|
||||
...this.document.system.traits[key],
|
||||
name: game.i18n.localize(SYSTEM.ACTOR.abilities[key].name),
|
||||
verbs: SYSTEM.ACTOR.abilities[key].verbs.map(x => game.i18n.localize(x))
|
||||
};
|
||||
|
|
@ -480,7 +490,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
|
||||
async attributeChange(event) {
|
||||
const path = `system.attributes.${event.currentTarget.dataset.attribute}.data.base`;
|
||||
const path = `system.traits.${event.currentTarget.dataset.attribute}.base`;
|
||||
await this.document.update({ [path]: event.currentTarget.value });
|
||||
}
|
||||
|
||||
|
|
@ -532,21 +542,21 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
|
||||
static async toggleAttributeMark(_, button) {
|
||||
const attribute = this.document.system.attributes[button.dataset.attribute];
|
||||
const attribute = this.document.system.traits[button.dataset.attribute];
|
||||
const newMark = this.document.system.availableAttributeMarks
|
||||
.filter(x => x > Math.max.apply(null, this.document.system.attributes[button.dataset.attribute].levelMarks))
|
||||
.filter(x => x > Math.max.apply(null, this.document.system.traits[button.dataset.attribute].levelMarks))
|
||||
.sort((a, b) => (a > b ? 1 : -1))[0];
|
||||
|
||||
if (attribute.levelMark || !newMark) return;
|
||||
|
||||
const path = `system.attributes.${button.dataset.attribute}.levelMarks`;
|
||||
const path = `system.traits.${button.dataset.attribute}.levelMarks`;
|
||||
await this.document.update({ [path]: [...attribute.levelMarks, newMark] });
|
||||
}
|
||||
|
||||
static async toggleHP(_, button) {
|
||||
const healthValue = Number.parseInt(button.dataset.value);
|
||||
const newValue = this.document.system.resources.health.value >= healthValue ? healthValue - 1 : healthValue;
|
||||
await this.document.update({ 'system.resources.health.value': newValue });
|
||||
const newValue = this.document.system.resources.hitPoints.value >= healthValue ? healthValue - 1 : healthValue;
|
||||
await this.document.update({ 'system.resources.hitPoints.value': newValue });
|
||||
}
|
||||
|
||||
static async toggleStress(_, button) {
|
||||
|
|
@ -577,7 +587,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
type: weapon.system.damage.type,
|
||||
bonusDamage: this.document.system.bonuses.damage
|
||||
};
|
||||
const modifier = this.document.system.attributes[weapon.system.trait].data.value;
|
||||
const modifier = this.document.system.traits[weapon.system.trait].value;
|
||||
|
||||
const { roll, hope, fear, advantage, disadvantage, modifiers, bonusDamageString } =
|
||||
await this.document.dualityRoll(
|
||||
|
|
@ -593,7 +603,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
name: x.actor.name,
|
||||
img: x.actor.img,
|
||||
difficulty: x.actor.system.difficulty,
|
||||
evasion: x.actor.system.evasion
|
||||
evasion: x.actor.system.evasion.value
|
||||
}));
|
||||
|
||||
const systemData = {
|
||||
|
|
@ -634,7 +644,12 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
|
||||
openLevelUp() {
|
||||
new DhpLevelup(this.document).render(true);
|
||||
if (!this.document.system.class || !this.document.system.subclass) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.Sheets.PC.Errors.missingClassOrSubclass'));
|
||||
return;
|
||||
}
|
||||
|
||||
new DhlevelUp(this.document).render(true);
|
||||
}
|
||||
|
||||
static domainCardsTab(toVault) {
|
||||
|
|
@ -782,7 +797,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
|
||||
static async makeDeathMove() {
|
||||
if (this.document.system.resources.health.value === this.document.system.resources.health.max) {
|
||||
if (this.document.system.resources.hitPoints.value === this.document.system.resources.hitPoints.max) {
|
||||
await new DhpDeathMove(this.document).render(true);
|
||||
await this.minimize();
|
||||
}
|
||||
|
|
@ -867,6 +882,11 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
await item.update({ [name]: event.currentTarget.value });
|
||||
}
|
||||
|
||||
async onLevelChange(event) {
|
||||
await this.document.updateLevel(Number(event.currentTarget.value));
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async deleteItem(_, button) {
|
||||
const item = await fromUuid($(button).closest('[data-item-id]')[0].dataset.itemId);
|
||||
await item.delete();
|
||||
|
|
@ -1090,7 +1110,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
await itemObject.update({ 'system.active': true });
|
||||
break;
|
||||
case 'inventory-weapon-section':
|
||||
/* FIXME inventoryWeapon is no longer a field
|
||||
/* FIXME inventoryWeapon is no longer a field
|
||||
const existingInventoryWeapon = this.document.items.find(x => x.system.inventoryWeapon);
|
||||
await existingInventoryWeapon?.update({ 'system.inventoryWeapon': false });
|
||||
await itemObject.update({ 'system.inventoryWeapon': true });
|
||||
|
|
|
|||
|
|
@ -52,31 +52,31 @@ export const abilities = {
|
|||
export const featureProperties = {
|
||||
agility: {
|
||||
name: 'DAGGERHEART.Abilities.agility.name',
|
||||
path: actor => actor.system.attributes.agility.data.value
|
||||
path: actor => actor.system.traits.agility.data.value
|
||||
},
|
||||
strength: {
|
||||
name: 'DAGGERHEART.Abilities.strength.name',
|
||||
path: actor => actor.system.attributes.strength.data.value
|
||||
path: actor => actor.system.traits.strength.data.value
|
||||
},
|
||||
finesse: {
|
||||
name: 'DAGGERHEART.Abilities.finesse.name',
|
||||
path: actor => actor.system.attributes.finesse.data.value
|
||||
path: actor => actor.system.traits.finesse.data.value
|
||||
},
|
||||
instinct: {
|
||||
name: 'DAGGERHEART.Abilities.instinct.name',
|
||||
path: actor => actor.system.attributes.instinct.data.value
|
||||
path: actor => actor.system.traits.instinct.data.value
|
||||
},
|
||||
presence: {
|
||||
name: 'DAGGERHEART.Abilities.presence.name',
|
||||
path: actor => actor.system.attributes.presence.data.value
|
||||
path: actor => actor.system.traits.presence.data.value
|
||||
},
|
||||
knowledge: {
|
||||
name: 'DAGGERHEART.Abilities.knowledge.name',
|
||||
path: actor => actor.system.attributes.knowledge.data.value
|
||||
path: actor => actor.system.traits.knowledge.data.value
|
||||
},
|
||||
spellcastingTrait: {
|
||||
name: 'DAGGERHEART.FeatureProperty.SpellcastingTrait',
|
||||
path: actor => actor.system.attributes[actor.system.subclass.system.spellcastingTrait].data.value
|
||||
path: actor => actor.system.traits[actor.system.subclass.system.spellcastingTrait].data.value
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ export const menu = {
|
|||
Range: {
|
||||
Name: 'GameSettingsRange',
|
||||
Icon: 'fa-solid fa-ruler'
|
||||
},
|
||||
VariantRules: {
|
||||
Name: 'GameSettingsVariantrules',
|
||||
Icon: 'fa-solid fa-scale-balanced'
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -27,5 +31,19 @@ export const gameSettings = {
|
|||
AbilityArray: 'AbilityArray',
|
||||
RangeMeasurement: 'RangeMeasurement'
|
||||
},
|
||||
appearance: 'Appearance'
|
||||
DualityRollColor: 'DualityRollColor',
|
||||
LevelTiers: 'LevelTiers',
|
||||
appearance: 'Appearance',
|
||||
variantRules: 'VariantRules'
|
||||
};
|
||||
|
||||
export const DualityRollColor = {
|
||||
colorful: {
|
||||
value: 0,
|
||||
label: 'DAGGERHEART.Settings.DualityRollColor.Options.Colorful'
|
||||
},
|
||||
normal: {
|
||||
value: 1,
|
||||
label: 'DAGGERHEART.Settings.DualityRollColor.Options.Normal'
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
export { default as DhpPC } from './pc.mjs';
|
||||
export { default as DhpCombat } from './combat.mjs';
|
||||
export { default as DhpCombatant } from './combatant.mjs';
|
||||
export { default as DhClass } from './item/class.mjs';
|
||||
export { default as DhSubclass } from './item/subclass.mjs';
|
||||
export { default as DhCombat } from './combat.mjs';
|
||||
export { default as DhCombatant } from './combatant.mjs';
|
||||
export { default as DhpAdversary } from './adversary.mjs';
|
||||
export { default as DhpEnvironment } from './environment.mjs';
|
||||
|
||||
export * as items from "./item/_module.mjs";
|
||||
export * as messages from "./chat-message/_modules.mjs";
|
||||
export * as items from './item/_module.mjs';
|
||||
export * as messages from './chat-message/_modules.mjs';
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
export default class DhpCombat extends foundry.abstract.TypeDataModel {
|
||||
export default class DhCombat extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
actions: new fields.NumberField({ initial: 0, integer: true }),
|
||||
activeCombatant: new fields.StringField({})
|
||||
};
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
export default class DhpCombatant extends foundry.abstract.TypeDataModel {
|
||||
export default class DhCombatant extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
active: new fields.BooleanField({ initial: false })
|
||||
spotlight: new fields.SchemaField({
|
||||
requesting: new fields.BooleanField({ required: true, initial: false })
|
||||
}),
|
||||
actionTokens: new fields.NumberField({ required: true, integer: true, initial: 3 })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
340
module/data/levelTier.mjs
Normal file
340
module/data/levelTier.mjs
Normal file
|
|
@ -0,0 +1,340 @@
|
|||
export class DhLevelTiers extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
tiers: new fields.TypedObjectField(new fields.EmbeddedDataField(DhLevelTier))
|
||||
};
|
||||
}
|
||||
|
||||
get availableChoicesPerLevel() {
|
||||
return Object.values(this.tiers).reduce((acc, tier) => {
|
||||
for (var level = tier.levels.start; level < tier.levels.end + 1; level++) {
|
||||
acc[level] = tier.availableOptions;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
}
|
||||
|
||||
class DhLevelTier extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
tier: new fields.NumberField({ required: true, integer: true }),
|
||||
name: new fields.StringField({ required: true }),
|
||||
levels: new fields.SchemaField({
|
||||
start: new fields.NumberField({ required: true, integer: true }),
|
||||
end: new fields.NumberField({ required: true, integer: true })
|
||||
}),
|
||||
initialAchievements: new fields.SchemaField({
|
||||
experience: new fields.SchemaField({
|
||||
nr: new fields.NumberField({ required: true, initial: 1 }),
|
||||
modifier: new fields.NumberField({ required: true, initial: 2 })
|
||||
}),
|
||||
proficiency: new fields.NumberField({ integer: true, initial: 1 })
|
||||
}),
|
||||
availableOptions: new fields.NumberField({ required: true, initial: 2 }),
|
||||
domainCardByLevel: new fields.NumberField({ initial: 1 }),
|
||||
options: new fields.TypedObjectField(new fields.EmbeddedDataField(DhLevelOption))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class DhLevelOption extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
label: new fields.StringField({ required: true }),
|
||||
checkboxSelections: new fields.NumberField({ required: true, integer: true, initial: 1 }),
|
||||
minCost: new fields.NumberField({ required: true, integer: true, initial: 1 }),
|
||||
type: new fields.StringField({ required: true, choices: LevelOptionType }),
|
||||
value: new fields.NumberField({ integer: true }),
|
||||
amount: new fields.NumberField({ integer: true })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const LevelOptionType = {
|
||||
trait: {
|
||||
id: 'trait',
|
||||
label: 'Character Trait',
|
||||
dataPath: ''
|
||||
},
|
||||
hitPoint: {
|
||||
id: 'hitPoint',
|
||||
label: 'Hit Points',
|
||||
dataPath: 'resources.hitPoints',
|
||||
dataPathData: {
|
||||
property: 'max',
|
||||
dependencies: ['value']
|
||||
}
|
||||
},
|
||||
stress: {
|
||||
id: 'stress',
|
||||
label: 'Stress',
|
||||
dataPath: 'resources.stress',
|
||||
dataPathData: {
|
||||
property: 'max',
|
||||
dependencies: ['value']
|
||||
}
|
||||
},
|
||||
evasion: {
|
||||
id: 'evasion',
|
||||
label: 'Evasion',
|
||||
dataPath: 'evasion'
|
||||
},
|
||||
proficiency: {
|
||||
id: 'proficiency',
|
||||
label: 'Proficiency'
|
||||
},
|
||||
experience: {
|
||||
id: 'experience',
|
||||
label: 'Experience'
|
||||
},
|
||||
domainCard: {
|
||||
id: 'domainCard',
|
||||
label: 'Domain Card'
|
||||
},
|
||||
subclass: {
|
||||
id: 'subclass',
|
||||
label: 'Subclass'
|
||||
},
|
||||
multiclass: {
|
||||
id: 'multiclass',
|
||||
label: 'Multiclass'
|
||||
}
|
||||
};
|
||||
|
||||
export const defaultLevelTiers = {
|
||||
tiers: {
|
||||
2: {
|
||||
tier: 2,
|
||||
name: 'Tier 2',
|
||||
levels: {
|
||||
start: 2,
|
||||
end: 4
|
||||
},
|
||||
initialAchievements: {
|
||||
experience: {
|
||||
nr: 1,
|
||||
modifier: 2
|
||||
},
|
||||
proficiency: 1
|
||||
},
|
||||
availableOptions: 2,
|
||||
domainCardByLevel: 1,
|
||||
options: {
|
||||
trait: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.trait',
|
||||
checkboxSelections: 3,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.trait.id,
|
||||
amount: 2
|
||||
},
|
||||
hitPoint: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.hitPoint',
|
||||
checkboxSelections: 2,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.hitPoint.id,
|
||||
value: 1,
|
||||
value: 1
|
||||
},
|
||||
stress: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.stress',
|
||||
checkboxSelections: 2,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.stress.id,
|
||||
value: 1
|
||||
},
|
||||
experience: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.experience',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.experience.id,
|
||||
value: 1,
|
||||
amount: 2
|
||||
},
|
||||
domainCard: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.domainCard',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.domainCard.id,
|
||||
amount: 1
|
||||
},
|
||||
evasion: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.evasion',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.evasion.id,
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
3: {
|
||||
tier: 3,
|
||||
name: 'Tier 3',
|
||||
levels: {
|
||||
start: 5,
|
||||
end: 7
|
||||
},
|
||||
initialAchievements: {
|
||||
experience: {
|
||||
nr: 1,
|
||||
modifier: 2
|
||||
},
|
||||
proficiency: 1
|
||||
},
|
||||
availableOptions: 2,
|
||||
domainCardByLevel: 1,
|
||||
options: {
|
||||
trait: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.trait',
|
||||
checkboxSelections: 3,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.trait.id,
|
||||
amount: 2
|
||||
},
|
||||
hitPoint: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.hitPoint',
|
||||
checkboxSelections: 2,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.hitPoint.id,
|
||||
value: 1
|
||||
},
|
||||
stress: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.stress',
|
||||
checkboxSelections: 2,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.stress.id,
|
||||
value: 1
|
||||
},
|
||||
experience: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.experience',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.experience.id,
|
||||
value: 1,
|
||||
amount: 2
|
||||
},
|
||||
domainCard: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.domainCard',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.domainCard.id,
|
||||
amount: 1
|
||||
},
|
||||
evasion: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.evasion',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.evasion.id,
|
||||
value: 1
|
||||
},
|
||||
subclass: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.subclass',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.subclass.id
|
||||
},
|
||||
proficiency: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.proficiency',
|
||||
checkboxSelections: 2,
|
||||
minCost: 2,
|
||||
type: LevelOptionType.proficiency.id,
|
||||
value: 1
|
||||
},
|
||||
multiclass: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.multiclass',
|
||||
checkboxSelections: 2,
|
||||
minCost: 2,
|
||||
type: LevelOptionType.multiclass.id
|
||||
}
|
||||
}
|
||||
},
|
||||
4: {
|
||||
tier: 4,
|
||||
name: 'Tier 4',
|
||||
levels: {
|
||||
start: 8,
|
||||
end: 10
|
||||
},
|
||||
initialAchievements: {
|
||||
experience: {
|
||||
nr: 1,
|
||||
modifier: 2
|
||||
},
|
||||
proficiency: 1
|
||||
},
|
||||
availableOptions: 2,
|
||||
domainCardByLevel: 1,
|
||||
options: {
|
||||
trait: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.trait',
|
||||
checkboxSelections: 3,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.trait.id,
|
||||
amount: 2
|
||||
},
|
||||
hitPoint: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.hitPoint',
|
||||
checkboxSelections: 2,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.hitPoint.id,
|
||||
value: 1
|
||||
},
|
||||
stress: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.stress',
|
||||
checkboxSelections: 2,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.stress.id,
|
||||
value: 1
|
||||
},
|
||||
experience: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.experience',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.experience.id,
|
||||
value: 1,
|
||||
amount: 2
|
||||
},
|
||||
domainCard: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.domainCard',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.domainCard.id,
|
||||
amount: 1
|
||||
},
|
||||
evasion: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.evasion',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.evasion.id,
|
||||
value: 1
|
||||
},
|
||||
subclass: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.subclass',
|
||||
checkboxSelections: 1,
|
||||
minCost: 1,
|
||||
type: LevelOptionType.subclass.id
|
||||
},
|
||||
proficiency: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.proficiency',
|
||||
checkboxSelections: 2,
|
||||
minCost: 2,
|
||||
type: LevelOptionType.proficiency.id,
|
||||
value: 1
|
||||
},
|
||||
multiclass: {
|
||||
label: 'DAGGERHEART.LevelUp.Options.multiclass',
|
||||
checkboxSelections: 2,
|
||||
minCost: 2,
|
||||
type: LevelOptionType.multiclass.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
311
module/data/levelup.mjs
Normal file
311
module/data/levelup.mjs
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
import { chunkify } from '../helpers/utils.mjs';
|
||||
import { LevelOptionType } from './levelTier.mjs';
|
||||
|
||||
export class DhLevelup extends foundry.abstract.DataModel {
|
||||
static initializeData(levelTierData, pcLevelData) {
|
||||
const startLevel = pcLevelData.level.current + 1;
|
||||
const currentLevel = pcLevelData.level.current + 1;
|
||||
const endLevel = pcLevelData.level.changed;
|
||||
|
||||
const tiers = {};
|
||||
const levels = {};
|
||||
const tierKeys = Object.keys(levelTierData.tiers);
|
||||
tierKeys.forEach(key => {
|
||||
const tier = levelTierData.tiers[key];
|
||||
const belongingLevels = [];
|
||||
for (var i = tier.levels.start; i <= tier.levels.end; i++) {
|
||||
if (i <= endLevel) {
|
||||
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;
|
||||
}, {})
|
||||
: {};
|
||||
const domainCards = [...Array(tier.domainCardByLevel).keys()].reduce((acc, _) => {
|
||||
const id = foundry.utils.randomID();
|
||||
acc[id] = { uuid: null, itemUuid: null, level: i };
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
levels[i] = DhLevelupLevel.initializeData(pcLevelData.levelups[i], tier.availableOptions, {
|
||||
...initialAchievements,
|
||||
experiences,
|
||||
domainCards
|
||||
});
|
||||
}
|
||||
|
||||
belongingLevels.push(i);
|
||||
}
|
||||
|
||||
tiers[key] = {
|
||||
name: tier.name,
|
||||
belongingLevels: belongingLevels,
|
||||
options: Object.keys(tier.options).reduce((acc, key) => {
|
||||
acc[key] = tier.options[key].toObject();
|
||||
return acc;
|
||||
}, {})
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
tiers,
|
||||
levels,
|
||||
startLevel,
|
||||
currentLevel,
|
||||
endLevel
|
||||
};
|
||||
}
|
||||
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
tiers: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
name: new fields.StringField({ required: true }),
|
||||
belongingLevels: new fields.ArrayField(new fields.NumberField({ required: true, integer: true })),
|
||||
options: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
label: new fields.StringField({ required: true }),
|
||||
checkboxSelections: new fields.NumberField({ required: true, integer: true }),
|
||||
minCost: new fields.NumberField({ required: true, integer: true }),
|
||||
type: new fields.StringField({ required: true, choices: LevelOptionType }),
|
||||
value: new fields.NumberField({ integer: true }),
|
||||
amount: new fields.NumberField({ integer: true })
|
||||
})
|
||||
)
|
||||
})
|
||||
),
|
||||
levels: new fields.TypedObjectField(new fields.EmbeddedDataField(DhLevelupLevel)),
|
||||
startLevel: new fields.NumberField({ required: true, integer: true }),
|
||||
currentLevel: new fields.NumberField({ required: true, integer: true }),
|
||||
endLevel: new fields.NumberField({ required: true, integer: true })
|
||||
};
|
||||
}
|
||||
|
||||
#levelFinished(levelKey) {
|
||||
const allSelectionsMade = this.levels[levelKey].nrSelections.available === 0;
|
||||
const allChoicesMade = Object.keys(this.levels[levelKey].choices).every(choiceKey => {
|
||||
const choice = this.levels[levelKey].choices[choiceKey];
|
||||
return Object.values(choice).every(checkbox => {
|
||||
switch (choiceKey) {
|
||||
case 'trait':
|
||||
case 'experience':
|
||||
case 'domainCard':
|
||||
case 'subclass':
|
||||
return checkbox.amount ? checkbox.data.length === checkbox.amount : checkbox.data.length === 1;
|
||||
case 'multiclass':
|
||||
const classSelected = checkbox.data.length === 1;
|
||||
const domainSelected = checkbox.secondaryData;
|
||||
return classSelected && domainSelected;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
const experiencesSelected = !this.levels[levelKey].achievements.experiences
|
||||
? true
|
||||
: Object.values(this.levels[levelKey].achievements.experiences).every(exp => exp.name);
|
||||
const domainCardsSelected = Object.values(this.levels[levelKey].achievements.domainCards)
|
||||
.filter(x => x.level <= this.endLevel)
|
||||
.every(card => card.uuid);
|
||||
const allAchievementsSelected = experiencesSelected && domainCardsSelected;
|
||||
|
||||
return allSelectionsMade && allChoicesMade && allAchievementsSelected;
|
||||
}
|
||||
|
||||
get currentLevelFinished() {
|
||||
return this.#levelFinished(this.currentLevel);
|
||||
}
|
||||
|
||||
get allLevelsFinished() {
|
||||
return Object.keys(this.levels)
|
||||
.filter(level => Number(level) >= this.startLevel)
|
||||
.every(this.#levelFinished.bind(this));
|
||||
}
|
||||
|
||||
get classUpgradeChoices() {
|
||||
let subclass = null;
|
||||
let multiclass = null;
|
||||
Object.keys(this.levels).forEach(levelKey => {
|
||||
const level = this.levels[levelKey];
|
||||
Object.values(level.choices).forEach(choice => {
|
||||
Object.values(choice).forEach(checkbox => {
|
||||
if (checkbox.type === 'multiclass') {
|
||||
multiclass = {
|
||||
class: checkbox.data.length > 0 ? checkbox.data[0] : null,
|
||||
domain: checkbox.secondaryData ?? null,
|
||||
tier: checkbox.tier,
|
||||
level: levelKey
|
||||
};
|
||||
}
|
||||
if (checkbox.type === 'subclass') {
|
||||
subclass = {
|
||||
tier: checkbox.tier,
|
||||
level: levelKey
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
return { subclass, multiclass };
|
||||
}
|
||||
|
||||
get tiersForRendering() {
|
||||
const tierKeys = Object.keys(this.tiers);
|
||||
const selections = Object.keys(this.levels).reduce(
|
||||
(acc, key) => {
|
||||
const level = this.levels[key];
|
||||
Object.keys(level.choices).forEach(optionKey => {
|
||||
const choice = level.choices[optionKey];
|
||||
Object.keys(choice).forEach(checkboxNr => {
|
||||
const checkbox = choice[checkboxNr];
|
||||
if (!acc[checkbox.tier][optionKey]) acc[checkbox.tier][optionKey] = {};
|
||||
Object.keys(choice).forEach(checkboxNr => {
|
||||
acc[checkbox.tier][optionKey][checkboxNr] = { ...checkbox, level: Number(key) };
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return acc;
|
||||
},
|
||||
tierKeys.reduce((acc, key) => {
|
||||
acc[key] = {};
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
|
||||
const { multiclass, subclass } = this.classUpgradeChoices;
|
||||
return tierKeys.map(tierKey => {
|
||||
const tier = this.tiers[tierKey];
|
||||
const multiclassInTier = multiclass?.tier === Number(tierKey);
|
||||
const subclassInTier = subclass?.tier === Number(tierKey);
|
||||
|
||||
return {
|
||||
name: tier.name,
|
||||
active: this.currentLevel >= Math.min(...tier.belongingLevels),
|
||||
groups: Object.keys(tier.options).map(optionKey => {
|
||||
const option = tier.options[optionKey];
|
||||
|
||||
const checkboxes = [...Array(option.checkboxSelections).keys()].flatMap(index => {
|
||||
const checkboxNr = index + 1;
|
||||
const checkboxData = selections[tierKey]?.[optionKey]?.[checkboxNr];
|
||||
const checkbox = { ...option, checkboxNr, tier: tierKey };
|
||||
|
||||
if (checkboxData) {
|
||||
checkbox.level = checkboxData.level;
|
||||
checkbox.selected = true;
|
||||
checkbox.disabled = checkbox.level !== this.currentLevel;
|
||||
}
|
||||
|
||||
if (optionKey === 'multiclass') {
|
||||
if ((multiclass && !multiclassInTier) || subclassInTier) {
|
||||
checkbox.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (optionKey === 'subclass' && multiclassInTier) {
|
||||
checkbox.disabled = true;
|
||||
}
|
||||
|
||||
return checkbox;
|
||||
});
|
||||
return {
|
||||
label: game.i18n.localize(option.label),
|
||||
checkboxGroups: chunkify(checkboxes, option.minCost, chunkedBoxes => {
|
||||
const anySelected = chunkedBoxes.some(x => x.selected);
|
||||
const anyDisabled = chunkedBoxes.some(x => x.disabled);
|
||||
return {
|
||||
multi: option.minCost > 1,
|
||||
checkboxes: chunkedBoxes.map(x => ({
|
||||
...x,
|
||||
selected: anySelected,
|
||||
disabled: anyDisabled
|
||||
}))
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class DhLevelupLevel extends foundry.abstract.DataModel {
|
||||
static initializeData(levelData = { selections: [] }, maxSelections, achievements) {
|
||||
return {
|
||||
maxSelections: maxSelections,
|
||||
achievements: {
|
||||
experiences: levelData.achievements?.experiences ?? achievements.experiences ?? {},
|
||||
domainCards: levelData.achievements?.domainCards
|
||||
? levelData.achievements.domainCards.reduce((acc, card, index) => {
|
||||
acc[index] = { ...card };
|
||||
return acc;
|
||||
}, {})
|
||||
: (achievements.domainCards ?? {}),
|
||||
proficiency: levelData.achievements?.proficiency ?? achievements.proficiency ?? null
|
||||
},
|
||||
choices: levelData.selections.reduce((acc, data) => {
|
||||
if (!acc[data.optionKey]) acc[data.optionKey] = {};
|
||||
acc[data.optionKey][data.checkboxNr] = { ...data };
|
||||
|
||||
return acc;
|
||||
}, {})
|
||||
};
|
||||
}
|
||||
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
maxSelections: new fields.NumberField({ required: true, integer: true }),
|
||||
achievements: new fields.SchemaField({
|
||||
experiences: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
name: new fields.StringField({ required: true }),
|
||||
modifier: new fields.NumberField({ required: true, integer: true })
|
||||
})
|
||||
),
|
||||
domainCards: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
uuid: new fields.StringField({ required: true, nullable: true, initial: null }),
|
||||
itemUuid: new fields.StringField({ required: true }),
|
||||
level: new fields.NumberField({ required: true, integer: true })
|
||||
})
|
||||
),
|
||||
proficiency: new fields.NumberField({ integer: true })
|
||||
}),
|
||||
choices: new fields.TypedObjectField(
|
||||
new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
tier: new fields.NumberField({ required: true, integer: true }),
|
||||
minCost: new fields.NumberField({ required: true, integer: true }),
|
||||
amount: new fields.NumberField({ integer: true }),
|
||||
value: new fields.StringField(),
|
||||
data: new fields.ArrayField(new fields.StringField()),
|
||||
secondaryData: new fields.StringField(),
|
||||
type: new fields.StringField({ required: true })
|
||||
})
|
||||
)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
get nrSelections() {
|
||||
const selections = Object.keys(this.choices).reduce((acc, choiceKey) => {
|
||||
const choice = this.choices[choiceKey];
|
||||
acc += Object.values(choice).reduce((acc, x) => acc + x.minCost, 0);
|
||||
|
||||
return acc;
|
||||
}, 0);
|
||||
|
||||
return {
|
||||
selections: selections,
|
||||
available: this.maxSelections - selections
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +1,29 @@
|
|||
import { getPathValue, getTier } from '../helpers/utils.mjs';
|
||||
import { getPathValue } from '../helpers/utils.mjs';
|
||||
import { LevelOptionType } from './levelTier.mjs';
|
||||
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
const attributeField = () =>
|
||||
new fields.SchemaField({
|
||||
data: new fields.SchemaField({
|
||||
value: new fields.NumberField({ initial: 0, integer: true }),
|
||||
base: new fields.NumberField({ initial: 0, integer: true }),
|
||||
bonus: new fields.NumberField({ initial: 0, integer: true }),
|
||||
actualValue: new fields.NumberField({ initial: 0, integer: true }),
|
||||
overrideValue: new fields.NumberField({ initial: 0, integer: true })
|
||||
}),
|
||||
levelMarks: new fields.ArrayField(new fields.NumberField({ nullable: true, initial: null, integer: true })),
|
||||
levelMark: new fields.NumberField({ nullable: true, initial: null, integer: true })
|
||||
bonus: new fields.NumberField({ initial: 0, integer: true }),
|
||||
base: new fields.NumberField({ initial: 0, integer: true }),
|
||||
tierMarked: new fields.BooleanField({ required: true, initial: false })
|
||||
});
|
||||
|
||||
const levelUpTier = () => ({
|
||||
attributes: new fields.TypedObjectField(new fields.BooleanField()),
|
||||
hitPointSlots: new fields.TypedObjectField(new fields.BooleanField()),
|
||||
stressSlots: new fields.TypedObjectField(new fields.BooleanField()),
|
||||
experiences: new fields.TypedObjectField(new fields.ArrayField(new fields.StringField({}))),
|
||||
proficiency: new fields.TypedObjectField(new fields.BooleanField()),
|
||||
armorOrEvasionSlot: new fields.TypedObjectField(new fields.StringField({})),
|
||||
subclass: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
multiclass: new fields.BooleanField(),
|
||||
feature: new fields.StringField({})
|
||||
})
|
||||
),
|
||||
multiclass: new fields.TypedObjectField(new fields.BooleanField())
|
||||
});
|
||||
const resourceField = max =>
|
||||
new fields.SchemaField({
|
||||
value: new fields.NumberField({ initial: 0, integer: true }),
|
||||
bonus: new fields.NumberField({ initial: 0, integer: true }),
|
||||
min: new fields.NumberField({ initial: 0, integer: true }),
|
||||
baseMax: new fields.NumberField({ initial: max, integer: true })
|
||||
});
|
||||
|
||||
export default class DhpPC extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
return {
|
||||
resources: new fields.SchemaField({
|
||||
health: new fields.SchemaField({
|
||||
value: new fields.NumberField({ initial: 0, integer: true }),
|
||||
min: new fields.NumberField({ initial: 0, integer: true }),
|
||||
max: new fields.NumberField({ initial: 6, integer: true })
|
||||
}),
|
||||
stress: new fields.SchemaField({
|
||||
value: new fields.NumberField({ initial: 0, integer: true }),
|
||||
min: new fields.NumberField({ initial: 0, integer: true }),
|
||||
max: new fields.NumberField({ initial: 6, integer: true })
|
||||
}),
|
||||
hitPoints: resourceField(6),
|
||||
stress: resourceField(6),
|
||||
hope: new fields.SchemaField({
|
||||
value: new fields.NumberField({ initial: -1, integer: true }), // FIXME. Logic is gte and needs -1 in PC/Hope. Change to 0
|
||||
min: new fields.NumberField({ initial: 0, integer: true })
|
||||
|
|
@ -61,7 +40,7 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
})
|
||||
)
|
||||
}),
|
||||
attributes: new fields.SchemaField({
|
||||
traits: new fields.SchemaField({
|
||||
agility: attributeField(),
|
||||
strength: attributeField(),
|
||||
finesse: attributeField(),
|
||||
|
|
@ -70,22 +49,22 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
knowledge: attributeField()
|
||||
}),
|
||||
proficiency: new fields.SchemaField({
|
||||
value: new fields.NumberField({ initial: 1, integer: true }),
|
||||
min: new fields.NumberField({ initial: 1, integer: true }),
|
||||
max: new fields.NumberField({ initial: 6, integer: true })
|
||||
base: new fields.NumberField({ required: true, initial: 1, integer: true }),
|
||||
bonus: new fields.NumberField({ required: true, initial: 0, integer: true })
|
||||
}),
|
||||
evasion: new fields.SchemaField({
|
||||
bonus: new fields.NumberField({ initial: 0, integer: true })
|
||||
}),
|
||||
evasion: new fields.NumberField({ initial: 0, integer: true }),
|
||||
experiences: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
id: new fields.StringField({ required: true }),
|
||||
level: new fields.NumberField({ required: true, integer: true }),
|
||||
description: new fields.StringField({}),
|
||||
value: new fields.NumberField({ integer: true, nullable: true, initial: null })
|
||||
}),
|
||||
{
|
||||
initial: [
|
||||
{ id: foundry.utils.randomID(), level: 1, description: '', value: 2 },
|
||||
{ id: foundry.utils.randomID(), level: 1, description: '', value: 2 }
|
||||
{ id: foundry.utils.randomID(), description: '', value: 2 },
|
||||
{ id: foundry.utils.randomID(), description: '', value: 2 }
|
||||
]
|
||||
}
|
||||
),
|
||||
|
|
@ -100,30 +79,6 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
maxLoadout: new fields.NumberField({ initial: 2, integer: true }),
|
||||
maxCards: new fields.NumberField({ initial: 2, integer: true })
|
||||
}),
|
||||
levelData: new fields.SchemaField({
|
||||
currentLevel: new fields.NumberField({ initial: 1, integer: true }),
|
||||
changedLevel: new fields.NumberField({ initial: 1, integer: true }),
|
||||
levelups: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
level: new fields.NumberField({ required: true, integer: true }),
|
||||
tier1: new fields.SchemaField({
|
||||
...levelUpTier()
|
||||
}),
|
||||
tier2: new fields.SchemaField(
|
||||
{
|
||||
...levelUpTier()
|
||||
},
|
||||
{ nullable: true, initial: null }
|
||||
),
|
||||
tier3: new fields.SchemaField(
|
||||
{
|
||||
...levelUpTier()
|
||||
},
|
||||
{ nullable: true, initial: null }
|
||||
)
|
||||
})
|
||||
)
|
||||
}),
|
||||
story: new fields.SchemaField({
|
||||
background: new fields.HTMLField(),
|
||||
appearance: new fields.HTMLField(),
|
||||
|
|
@ -140,15 +95,11 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
armorMarks: new fields.SchemaField({
|
||||
max: new fields.NumberField({ initial: 6, integer: true }),
|
||||
value: new fields.NumberField({ initial: 0, integer: true })
|
||||
})
|
||||
}),
|
||||
levelData: new fields.EmbeddedDataField(DhPCLevelData)
|
||||
};
|
||||
}
|
||||
|
||||
get canLevelUp() {
|
||||
// return Object.values(this.levels.data).some(x => !x.completed);
|
||||
return this.levelData.currentLevel !== this.levelData.changedLevel;
|
||||
}
|
||||
|
||||
get tier() {
|
||||
return this.#getTier(this.levelData.currentLevel);
|
||||
}
|
||||
|
|
@ -281,31 +232,6 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
}
|
||||
}
|
||||
|
||||
get totalAttributeMarks() {
|
||||
return Object.keys(this.levelData.levelups).reduce((nr, level) => {
|
||||
const nrAttributeMarks = Object.keys(this.levelData.levelups[level]).reduce((nr, tier) => {
|
||||
nr += Object.keys(this.levelData.levelups[level][tier]?.attributes ?? {}).length * 2;
|
||||
|
||||
return nr;
|
||||
}, 0);
|
||||
|
||||
nr.push(...Array(nrAttributeMarks).fill(Number.parseInt(level)));
|
||||
|
||||
return nr;
|
||||
}, []);
|
||||
}
|
||||
|
||||
get availableAttributeMarks() {
|
||||
const attributeMarks = Object.keys(this.attributes).flatMap(y => this.attributes[y].levelMarks);
|
||||
return this.totalAttributeMarks.reduce((acc, attribute) => {
|
||||
if (!attributeMarks.findSplice(x => x === attribute)) {
|
||||
acc.push(attribute);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
get effects() {
|
||||
return this.parent.items.reduce((acc, item) => {
|
||||
const effects = item.system.effectData;
|
||||
|
|
@ -357,141 +283,37 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
: null;
|
||||
}
|
||||
|
||||
prepareBaseData() {
|
||||
this.resources.hitPoints.max = this.resources.hitPoints.baseMax + this.resources.hitPoints.bonus;
|
||||
this.resources.stress.max = this.resources.stress.baseMax + this.resources.stress.bonus;
|
||||
this.evasion.value = (this.class?.system?.evasion ?? 0) + this.evasion.bonus;
|
||||
this.proficiency.value = this.proficiency.base + this.proficiency.bonus;
|
||||
|
||||
for (var attributeKey in this.traits) {
|
||||
const attribute = this.traits[attributeKey];
|
||||
attribute.value = attribute.base + attribute.bonus;
|
||||
}
|
||||
}
|
||||
|
||||
prepareDerivedData() {
|
||||
this.resources.hope.max = 6 - this.story.scars.length;
|
||||
if (this.resources.hope.value >= this.resources.hope.max) {
|
||||
this.resources.hope.value = Math.max(this.resources.hope.max - 1, 0);
|
||||
}
|
||||
|
||||
for (var attributeKey in this.attributes) {
|
||||
const attribute = this.attributes[attributeKey];
|
||||
const armor = this.armor;
|
||||
this.damageThresholds = {
|
||||
major: armor
|
||||
? armor.system.baseThresholds.major + this.levelData.level.current
|
||||
: this.levelData.level.current,
|
||||
severe: armor
|
||||
? armor.system.baseThresholds.severe + this.levelData.level.current
|
||||
: this.levelData.level.current * 2
|
||||
};
|
||||
|
||||
attribute.levelMark = attribute.levelMarks.find(x => this.isSameTier(x)) ?? null;
|
||||
|
||||
const actualValue = attribute.data.base + attribute.levelMarks.length + attribute.data.bonus;
|
||||
attribute.data.actualValue = actualValue;
|
||||
attribute.data.value = attribute.data.overrideValue
|
||||
? attribute.data.overrideValue
|
||||
: attribute.data.actualValue;
|
||||
}
|
||||
|
||||
this.evasion = this.class?.system?.evasion ?? 0;
|
||||
// this.armor.value = this.activeArmor?.baseScore ?? 0;
|
||||
this.damageThresholds = this.computeDamageThresholds();
|
||||
|
||||
this.applyLevels();
|
||||
this.applyEffects();
|
||||
}
|
||||
|
||||
computeDamageThresholds() {
|
||||
// TODO: missing weapon features and domain cards calculation
|
||||
if (!this.armor) {
|
||||
return {
|
||||
major: this.levelData.currentLevel,
|
||||
severe: this.levelData.currentLevel * 2
|
||||
};
|
||||
}
|
||||
const {
|
||||
baseThresholds: { major = 0, severe = 0 }
|
||||
} = this.armor.system;
|
||||
return {
|
||||
major: major + this.levelData.currentLevel,
|
||||
severe: severe + this.levelData.currentLevel
|
||||
};
|
||||
}
|
||||
|
||||
applyLevels() {
|
||||
let healthBonus = 0,
|
||||
stressBonus = 0,
|
||||
proficiencyBonus = 0,
|
||||
evasionBonus = 0,
|
||||
armorBonus = 0;
|
||||
let experienceBonuses = {};
|
||||
let advancementFirst = null,
|
||||
advancementSecond = null;
|
||||
for (var level in this.levelData.levelups) {
|
||||
var levelData = this.levelData.levelups[level];
|
||||
for (var tier in levelData) {
|
||||
var tierData = levelData[tier];
|
||||
if (tierData) {
|
||||
healthBonus += Object.keys(tierData.hitPointSlots).length;
|
||||
stressBonus += Object.keys(tierData.stressSlots).length;
|
||||
proficiencyBonus += Object.keys(tierData.proficiency).length;
|
||||
advancementFirst =
|
||||
Object.keys(tierData.subclass).length > 0 && level >= 5 && level <= 7
|
||||
? { ...tierData.subclass[0], tier: getTier(Number.parseInt(level), true) }
|
||||
: advancementFirst;
|
||||
advancementSecond =
|
||||
Object.keys(tierData.subclass).length > 0 && level >= 8 && level <= 10
|
||||
? { ...tierData.subclass[0], tier: getTier(Number.parseInt(level), true) }
|
||||
: advancementSecond;
|
||||
|
||||
for (var index in Object.keys(tierData.experiences)) {
|
||||
for (var experienceKey in tierData.experiences[index]) {
|
||||
var experience = tierData.experiences[index][experienceKey];
|
||||
experienceBonuses[experience] = experienceBonuses[experience]
|
||||
? experienceBonuses[experience] + 1
|
||||
: 1;
|
||||
}
|
||||
}
|
||||
|
||||
evasionBonus += Object.keys(tierData.armorOrEvasionSlot).filter(
|
||||
x => tierData.armorOrEvasionSlot[x] === 'evasion'
|
||||
).length;
|
||||
armorBonus += Object.keys(tierData.armorOrEvasionSlot).filter(
|
||||
x => tierData.armorOrEvasionSlot[x] === 'armor'
|
||||
).length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.resources.health.max += healthBonus;
|
||||
this.resources.stress.max += stressBonus;
|
||||
this.proficiency.value += proficiencyBonus;
|
||||
this.evasion += evasionBonus;
|
||||
this.armorMarks = {
|
||||
max: this.armor ? this.armor.system.marks.max + armorBonus : 0,
|
||||
value: this.armor ? this.armor.system.marks.value : 0
|
||||
};
|
||||
|
||||
this.experiences = this.experiences.map(x => ({ ...x, value: x.value + (experienceBonuses[x.id] ?? 0) }));
|
||||
|
||||
const subclassFeatures = this.subclassFeatures;
|
||||
if (advancementFirst) {
|
||||
if (advancementFirst.multiclass) {
|
||||
this.multiclassSubclass.system[`${advancementFirst.feature}Feature`].unlocked = true;
|
||||
this.multiclassSubclass.system[`${advancementFirst.feature}Feature`].tier = advancementFirst.tier;
|
||||
subclassFeatures.multiclassSubclass[advancementFirst.feature].forEach(x => (x.system.disabled = false));
|
||||
} else {
|
||||
this.subclass.system[`${advancementFirst.feature}Feature`].unlocked = true;
|
||||
this.subclass.system[`${advancementFirst.feature}Feature`].tier = advancementFirst.tier;
|
||||
subclassFeatures.subclass[advancementFirst.feature].forEach(x => (x.system.disabled = false));
|
||||
}
|
||||
}
|
||||
if (advancementSecond) {
|
||||
if (advancementSecond.multiclass) {
|
||||
this.multiclassSubclass.system[`${advancementSecond.feature}Feature`].unlocked = true;
|
||||
this.multiclassSubclass.system[`${advancementSecond.feature}Feature`].tier = advancementSecond.tier;
|
||||
subclassFeatures.multiclassSubclass[advancementSecond.feature].forEach(
|
||||
x => (x.system.disabled = false)
|
||||
);
|
||||
} else {
|
||||
this.subclass.system[`${advancementSecond.feature}Feature`].unlocked = true;
|
||||
this.subclass.system[`${advancementSecond.feature}Feature`].tier = advancementSecond.tier;
|
||||
subclassFeatures.subclass[advancementSecond.feature].forEach(x => (x.system.disabled = false));
|
||||
}
|
||||
}
|
||||
|
||||
//General progression
|
||||
for (var i = 0; i < this.levelData.currentLevel; i++) {
|
||||
const tier = getTier(i + 1);
|
||||
if (tier !== 'tier0') {
|
||||
this.domainData.maxLoadout = Math.min(this.domainData.maxLoadout + 1, 5);
|
||||
this.domainData.maxCards += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
applyEffects() {
|
||||
const effects = this.effects;
|
||||
for (var key in effects) {
|
||||
|
|
@ -499,10 +321,10 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
for (var effect of effectType) {
|
||||
switch (key) {
|
||||
case SYSTEM.EFFECTS.effectTypes.health.id:
|
||||
this.resources.health.max += effect.value.valueData.value;
|
||||
this.resources.hitPoints.bonus += effect.value.valueData.value;
|
||||
break;
|
||||
case SYSTEM.EFFECTS.effectTypes.stress.id:
|
||||
this.resources.stress.max += effect.value.valueData.value;
|
||||
this.resources.stress.bonus += effect.value.valueData.value;
|
||||
break;
|
||||
case SYSTEM.EFFECTS.effectTypes.damage.id:
|
||||
this.bonuses.damage.push({
|
||||
|
|
@ -529,10 +351,6 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
return twoHanded ? 'twoHanded' : oneHanded ? 'oneHanded' : null;
|
||||
}
|
||||
|
||||
isSameTier(level) {
|
||||
return this.#getTier(this.levelData.currentLevel) === this.#getTier(level);
|
||||
}
|
||||
|
||||
#getTier(level) {
|
||||
if (level >= 8) return 3;
|
||||
else if (level >= 5) return 2;
|
||||
|
|
@ -540,3 +358,55 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
else return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class DhPCLevelData extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
return {
|
||||
level: new fields.SchemaField({
|
||||
current: new fields.NumberField({ required: true, integer: true, initial: 1 }),
|
||||
changed: new fields.NumberField({ required: true, integer: true, initial: 1 })
|
||||
}),
|
||||
levelups: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
achievements: new fields.SchemaField(
|
||||
{
|
||||
experiences: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
name: new fields.StringField({ required: true }),
|
||||
modifier: new fields.NumberField({ required: true, integer: true })
|
||||
})
|
||||
),
|
||||
domainCards: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
uuid: new fields.StringField({ required: true }),
|
||||
itemUuid: new fields.StringField({ required: true })
|
||||
})
|
||||
),
|
||||
proficiency: new fields.NumberField({ integer: true })
|
||||
},
|
||||
{ nullable: true, initial: null }
|
||||
),
|
||||
selections: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
tier: new fields.NumberField({ required: true, integer: true }),
|
||||
level: new fields.NumberField({ required: true, integer: true }),
|
||||
optionKey: new fields.StringField({ required: true }),
|
||||
type: new fields.StringField({ required: true, choices: LevelOptionType }),
|
||||
checkboxNr: new fields.NumberField({ required: true, integer: true }),
|
||||
value: new fields.NumberField({ integer: true }),
|
||||
minCost: new fields.NumberField({ integer: true }),
|
||||
amount: new fields.NumberField({ integer: true }),
|
||||
data: new fields.ArrayField(new fields.StringField({ required: true })),
|
||||
secondaryData: new fields.StringField(),
|
||||
itemUuid: new fields.StringField({ required: true })
|
||||
})
|
||||
)
|
||||
})
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
get canLevelUp() {
|
||||
return this.level.current < this.level.changed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
module/data/settings/VariantRules.mjs
Normal file
13
module/data/settings/VariantRules.mjs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export default class DhVariantRules extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
actionTokens: new fields.SchemaField({
|
||||
enabled: new fields.BooleanField({ required: true, initial: false }),
|
||||
tokens: new fields.NumberField({ required: true, integer: true, initial: 3 })
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
static defaultSchema = {};
|
||||
}
|
||||
|
|
@ -6,13 +6,16 @@ import { setDiceSoNiceForDualityRoll } from '../helpers/utils.mjs';
|
|||
|
||||
export default class DhpActor extends Actor {
|
||||
async _preCreate(data, options, user) {
|
||||
if ( (await super._preCreate(data, options, user)) === false ) return false;
|
||||
|
||||
if ((await super._preCreate(data, options, user)) === false) return false;
|
||||
|
||||
// Configure prototype token settings
|
||||
const prototypeToken = {};
|
||||
if ( this.type === "pc" ) Object.assign(prototypeToken, {
|
||||
sight: { enabled: true }, actorLink: true, disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY
|
||||
});
|
||||
if (this.type === 'pc')
|
||||
Object.assign(prototypeToken, {
|
||||
sight: { enabled: true },
|
||||
actorLink: true,
|
||||
disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY
|
||||
});
|
||||
this.updateSource({ prototypeToken });
|
||||
}
|
||||
|
||||
|
|
@ -21,46 +24,103 @@ export default class DhpActor extends Actor {
|
|||
}
|
||||
|
||||
async _preUpdate(changed, options, user) {
|
||||
//Level Down
|
||||
if (
|
||||
changed.system?.levelData?.changedLevel &&
|
||||
this.system.levelData.currentLevel > changed.system.levelData.changedLevel
|
||||
) {
|
||||
changed.system.levelData.currentLevel = changed.system.levelData.changedLevel;
|
||||
changed.system.levelData.levelups = Object.keys(this.system.levelData.levelups).reduce((acc, x) => {
|
||||
if (x > changed.system.levelData.currentLevel) {
|
||||
acc[`-=${x}`] = null;
|
||||
super._preUpdate(changed, options, user);
|
||||
}
|
||||
|
||||
async updateLevel(newLevel) {
|
||||
if (this.type !== 'pc' || newLevel === this.system.levelData.level.changed) return;
|
||||
|
||||
if (newLevel > this.system.levelData.level.current) {
|
||||
await this.update({ 'system.levelData.level.changed': newLevel });
|
||||
} else {
|
||||
const updatedLevelups = Object.keys(this.system.levelData.levelups).reduce((acc, level) => {
|
||||
if (Number(level) > newLevel) acc[`-=${level}`] = null;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const domainCards = Object.keys(this.system.levelData.levelups)
|
||||
.filter(x => x > newLevel)
|
||||
.flatMap(levelKey => {
|
||||
const level = this.system.levelData.levelups[levelKey];
|
||||
const achievementCards = level.achievements.domainCards.map(x => x.itemUuid);
|
||||
const advancementCards = level.selections.filter(x => x.type === 'domainCard').map(x => x.itemUuid);
|
||||
return [...achievementCards, ...advancementCards];
|
||||
});
|
||||
|
||||
for (var domainCard of domainCards) {
|
||||
const itemCard = await this.items.find(x => x.uuid === domainCard);
|
||||
itemCard.delete();
|
||||
}
|
||||
|
||||
await this.update({
|
||||
system: {
|
||||
levelData: {
|
||||
level: {
|
||||
current: newLevel,
|
||||
changed: newLevel
|
||||
},
|
||||
levelups: updatedLevelups
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
async levelUp(levelupData) {
|
||||
const levelups = {};
|
||||
for (var levelKey of Object.keys(levelupData)) {
|
||||
const level = levelupData[levelKey];
|
||||
const achievementDomainCards = [];
|
||||
for (var card of Object.values(level.achievements.domainCards)) {
|
||||
const item = await foundry.utils.fromUuid(card.uuid);
|
||||
const embeddedItem = await this.createEmbeddedDocuments('Item', [item.toObject()]);
|
||||
card.itemUuid = embeddedItem[0].uuid;
|
||||
achievementDomainCards.push(card);
|
||||
}
|
||||
|
||||
changed.system.attributes = Object.keys(this.system.attributes).reduce((acc, key) => {
|
||||
acc[key] = {
|
||||
levelMarks: this.system.attributes[key].levelMarks.filter(
|
||||
x => x <= changed.system.levelData.currentLevel
|
||||
)
|
||||
};
|
||||
const selections = [];
|
||||
for (var optionKey of Object.keys(level.choices)) {
|
||||
const selection = level.choices[optionKey];
|
||||
for (var checkboxNr of Object.keys(selection)) {
|
||||
const checkbox = selection[checkboxNr];
|
||||
let itemUuid = null;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
if (checkbox.type === 'domainCard') {
|
||||
const item = await foundry.utils.fromUuid(checkbox.data[0]);
|
||||
const embeddedItem = await this.createEmbeddedDocuments('Item', [item.toObject()]);
|
||||
itemUuid = embeddedItem[0].uuid;
|
||||
}
|
||||
|
||||
changed.system.experiences = this.system.experiences.filter(
|
||||
x => x.level <= changed.system.levelData.currentLevel
|
||||
);
|
||||
|
||||
if (
|
||||
this.system.multiclass &&
|
||||
this.system.multiclass.system.multiclass > changed.system.levelData.changedLevel
|
||||
) {
|
||||
const multiclassFeatures = this.items.filter(x => x.system.multiclass);
|
||||
for (var feature of multiclassFeatures) {
|
||||
await feature.delete();
|
||||
selections.push({
|
||||
...checkbox,
|
||||
level: Number(levelKey),
|
||||
optionKey: optionKey,
|
||||
checkboxNr: Number(checkboxNr),
|
||||
itemUuid
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
levelups[levelKey] = {
|
||||
achievements: {
|
||||
...level.achievements,
|
||||
domainCards: achievementDomainCards
|
||||
},
|
||||
selections: selections
|
||||
};
|
||||
}
|
||||
|
||||
super._preUpdate(changed, options, user);
|
||||
await this.update({
|
||||
system: {
|
||||
levelData: {
|
||||
level: {
|
||||
current: this.system.levelData.level.changed
|
||||
},
|
||||
levelups: levelups
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async diceRoll(modifier, shiftKey) {
|
||||
|
|
@ -286,9 +346,9 @@ export default class DhpActor extends Actor {
|
|||
: 0;
|
||||
|
||||
const update = {
|
||||
'system.resources.health.value': Math.min(
|
||||
this.system.resources.health.value + hpDamage,
|
||||
this.system.resources.health.max
|
||||
'system.resources.hitPoints.value': Math.min(
|
||||
this.system.resources.hitPoints.value + hpDamage,
|
||||
this.system.resources.hitPoints.max
|
||||
)
|
||||
};
|
||||
|
||||
|
|
@ -311,9 +371,9 @@ export default class DhpActor extends Actor {
|
|||
switch (type) {
|
||||
case SYSTEM.GENERAL.healingTypes.health.id:
|
||||
update = {
|
||||
'system.resources.health.value': Math.min(
|
||||
this.system.resources.health.value + healing,
|
||||
this.system.resources.health.max
|
||||
'system.resources.hitPoints.value': Math.min(
|
||||
this.system.resources.hitPoints.value + healing,
|
||||
this.system.resources.hitPoints.max
|
||||
)
|
||||
};
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1,44 +1,19 @@
|
|||
import { GMUpdateEvent, socketEvent } from '../helpers/socket.mjs';
|
||||
|
||||
export default class DhpCombat extends Combat {
|
||||
_sortCombatants(a, b) {
|
||||
if (a.isNPC !== b.isNPC) {
|
||||
const aVal = a.isNPC ? 0 : 1;
|
||||
const bVal = b.isNPC ? 0 : 1;
|
||||
async startCombat() {
|
||||
this._playCombatSound('startEncounter');
|
||||
const updateData = { round: 1, turn: null };
|
||||
Hooks.callAll('combatStart', this, updateData);
|
||||
await this.update(updateData);
|
||||
return this;
|
||||
}
|
||||
|
||||
return aVal - bVal;
|
||||
_sortCombatants(a, b) {
|
||||
const aNPC = Number(a.isNPC);
|
||||
const bNPC = Number(b.isNPC);
|
||||
if (aNPC !== bNPC) {
|
||||
return aNPC - bNPC;
|
||||
}
|
||||
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
|
||||
async useActionToken(combatantId) {
|
||||
const automateActionPoints = await game.settings.get(
|
||||
SYSTEM.id,
|
||||
SYSTEM.SETTINGS.gameSettings.Automation.ActionPoints
|
||||
);
|
||||
|
||||
if (game.user.isGM) {
|
||||
if (this.system.actions < 1) return;
|
||||
|
||||
const update = automateActionPoints
|
||||
? { 'system.activeCombatant': combatantId, 'system.actions': Math.max(this.system.actions - 1, 0) }
|
||||
: { 'system.activeCombatant': combatantId };
|
||||
|
||||
await this.update(update);
|
||||
} else {
|
||||
const update = automateActionPoints
|
||||
? { 'system.activeCombatant': combatantId, 'system.actions': this.system.actions + 1 }
|
||||
: { 'system.activeCombatant': combatantId };
|
||||
|
||||
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: {
|
||||
action: GMUpdateEvent.UpdateDocument,
|
||||
uuid: this.uuid,
|
||||
update: update
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,22 +3,19 @@ import { getWidthOfText } from './utils.mjs';
|
|||
export default class RegisterHandlebarsHelpers {
|
||||
static registerHelpers() {
|
||||
Handlebars.registerHelper({
|
||||
looseEq: this.looseEq,
|
||||
times: this.times,
|
||||
join: this.join,
|
||||
add: this.add,
|
||||
subtract: this.subtract,
|
||||
objectSelector: this.objectSelector,
|
||||
includes: this.includes,
|
||||
simpleEditor: this.simpleEditor,
|
||||
debug: this.debug
|
||||
debug: this.debug,
|
||||
signedNumber: this.signedNumber,
|
||||
switch: this.switch,
|
||||
case: this.case
|
||||
});
|
||||
}
|
||||
|
||||
static looseEq(a, b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
static times(nr, block) {
|
||||
var accum = '';
|
||||
for (var i = 0; i < nr; ++i) accum += block.fn(i);
|
||||
|
|
@ -77,33 +74,25 @@ export default class RegisterHandlebarsHelpers {
|
|||
return new Handlebars.SafeString(html);
|
||||
}
|
||||
|
||||
static rangePicker(options) {
|
||||
let { name, value, min, max, step } = options.hash;
|
||||
name = name || 'range';
|
||||
value = value ?? '';
|
||||
if (Number.isNaN(value)) value = '';
|
||||
const html = `<input type="range" name="${name}" value="${value}" min="${min}" max="${max}" step="${step}"/>
|
||||
<span class="range-value">${value}</span>`;
|
||||
return new Handlebars.SafeString(html);
|
||||
}
|
||||
|
||||
static includes(list, item) {
|
||||
return list.includes(item);
|
||||
}
|
||||
|
||||
static simpleEditor(content, options) {
|
||||
const {
|
||||
target,
|
||||
editable = true,
|
||||
button,
|
||||
engine = 'tinymce',
|
||||
collaborate = false,
|
||||
class: cssClass
|
||||
} = options.hash;
|
||||
const config = { name: target, value: content, button, collaborate, editable, engine };
|
||||
const element = foundry.applications.fields.createEditorInput(config);
|
||||
if (cssClass) element.querySelector('.editor-content').classList.add(cssClass);
|
||||
return new Handlebars.SafeString(element.outerHTML);
|
||||
static signedNumber(number) {
|
||||
return number >= 0 ? `+${number}` : number;
|
||||
}
|
||||
|
||||
static switch(value, options) {
|
||||
this.switch_value = value;
|
||||
this.switch_break = false;
|
||||
return options.fn(this);
|
||||
}
|
||||
|
||||
static case(value, options) {
|
||||
if (value == this.switch_value) {
|
||||
this.switch_break = true;
|
||||
return options.fn(this);
|
||||
}
|
||||
}
|
||||
|
||||
static debug(a) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { getDiceSoNicePresets } from '../config/generalConfig.mjs';
|
||||
import Tagify from '@yaireo/tagify';
|
||||
|
||||
export const loadCompendiumOptions = async compendiums => {
|
||||
const compendiumValues = [];
|
||||
|
|
@ -131,3 +132,93 @@ export const setDiceSoNiceForDualityRoll = (rollResult, advantage, disadvantage)
|
|||
rollResult.dice[2].options.appearance = diceSoNicePresets.disadvantage;
|
||||
}
|
||||
};
|
||||
|
||||
export const chunkify = (array, chunkSize, mappingFunc) => {
|
||||
var chunkifiedArray = [];
|
||||
for (let i = 0; i < array.length; i += chunkSize) {
|
||||
const chunk = array.slice(i, i + chunkSize);
|
||||
if (mappingFunc) {
|
||||
chunkifiedArray.push(mappingFunc(chunk));
|
||||
} else {
|
||||
chunkifiedArray.push(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
return chunkifiedArray;
|
||||
};
|
||||
|
||||
export const tagifyElement = (element, options, onChange, tagifyOptions = {}) => {
|
||||
const { maxTags } = tagifyOptions;
|
||||
const tagifyElement = new Tagify(element, {
|
||||
tagTextProp: 'name',
|
||||
enforceWhitelist: true,
|
||||
whitelist: Object.keys(options).map(key => {
|
||||
const option = options[key];
|
||||
return {
|
||||
value: key,
|
||||
name: game.i18n.localize(option.label),
|
||||
src: option.src
|
||||
};
|
||||
}),
|
||||
maxTags: maxTags,
|
||||
dropdown: {
|
||||
mapValueTo: 'name',
|
||||
searchKeys: ['name'],
|
||||
enabled: 0,
|
||||
maxItems: 20,
|
||||
closeOnSelect: true,
|
||||
highlightFirst: false
|
||||
},
|
||||
templates: {
|
||||
tag(tagData) {
|
||||
return `<tag title="${tagData.title || tagData.value}"
|
||||
contenteditable='false'
|
||||
spellcheck='false'
|
||||
tabIndex="${this.settings.a11y.focusableTags ? 0 : -1}"
|
||||
class="${this.settings.classNames.tag} ${tagData.class ? tagData.class : ''}"
|
||||
${this.getAttributes(tagData)}>
|
||||
<x class="${this.settings.classNames.tagX}" role='button' aria-label='remove tag'></x>
|
||||
<div>
|
||||
<span class="${this.settings.classNames.tagText}">${tagData[this.settings.tagTextProp] || tagData.value}</span>
|
||||
${tagData.src ? `<img src="${tagData.src}"></i>` : ''}
|
||||
</div>
|
||||
</tag>`;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const onSelect = async event => {
|
||||
const inputElement = event.detail.tagify.DOM.originalInput;
|
||||
const selectedOptions = event.detail?.value ? JSON.parse(event.detail.value) : [];
|
||||
|
||||
const unusedDropDownItems = event.detail.tagify.suggestedListItems;
|
||||
const missingOptions = Object.keys(options).filter(x => !unusedDropDownItems.find(item => item.value === x));
|
||||
const removedItem = missingOptions.find(x => !selectedOptions.find(item => item.value === x));
|
||||
const addedItem = removedItem
|
||||
? null
|
||||
: selectedOptions.find(x => !missingOptions.find(item => item === x.value));
|
||||
|
||||
const changedItem = { option: removedItem ?? addedItem.value, removed: Boolean(removedItem) };
|
||||
|
||||
onChange(selectedOptions, changedItem, inputElement);
|
||||
};
|
||||
tagifyElement.on('change', onSelect);
|
||||
};
|
||||
|
||||
export const getDeleteKeys = (property, innerProperty, innerPropertyDefaultValue) => {
|
||||
return Object.keys(property).reduce((acc, key) => {
|
||||
if (innerProperty) {
|
||||
if (innerPropertyDefaultValue !== undefined) {
|
||||
acc[`${key}`] = {
|
||||
[innerProperty]: innerPropertyDefaultValue
|
||||
};
|
||||
} else {
|
||||
acc[`${key}.-=${innerProperty}`] = null;
|
||||
}
|
||||
} else {
|
||||
acc[`-=${key}`] = null;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,199 +1,100 @@
|
|||
import { GMUpdateEvent, socketEvent } from '../helpers/socket.mjs';
|
||||
|
||||
export default class DhpCombatTracker extends foundry.applications.sidebar.tabs.CombatTracker {
|
||||
constructor(data, context) {
|
||||
super(data, context);
|
||||
|
||||
Hooks.on(socketEvent.DhpFearUpdate, this.onFearUpdate);
|
||||
}
|
||||
|
||||
get template() {
|
||||
return 'systems/daggerheart/templates/ui/combatTracker.hbs';
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
html.on('click', '.token-action-tokens .use-action-token', this.useActionToken.bind(this));
|
||||
html.on('click', '.encounter-gm-resources .trade-actions', this.tradeActions.bind(this));
|
||||
html.on('click', '.encounter-gm-resources .trade-fear', this.tradeFear.bind(this));
|
||||
html.on('click', '.encounter-gm-resources .icon-button.up', this.increaseResource.bind(this));
|
||||
html.on('click', '.encounter-gm-resources .icon-button.down', this.decreaseResource.bind(this));
|
||||
}
|
||||
|
||||
async useActionToken(event) {
|
||||
event.stopPropagation();
|
||||
const combatant = event.currentTarget.dataset.combatant;
|
||||
await game.combat.useActionToken(combatant);
|
||||
}
|
||||
|
||||
async tradeActions(event) {
|
||||
if (event.currentTarget.classList.contains('disabled')) return;
|
||||
|
||||
const currentFear = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
const value = currentFear + 1;
|
||||
|
||||
if (value <= 6) {
|
||||
Hooks.callAll(socketEvent.GMUpdate, GMUpdateEvent.UpdateFear, null, value);
|
||||
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: { action: GMUpdateEvent.UpdateFear, update: value }
|
||||
});
|
||||
await game.combat.update({ 'system.actions': game.combat.system.actions - 2 });
|
||||
export default class DhCombatTracker extends foundry.applications.sidebar.tabs.CombatTracker {
|
||||
static DEFAULT_OPTIONS = {
|
||||
actions: {
|
||||
requestSpotlight: this.requestSpotlight,
|
||||
toggleSpotlight: this.toggleSpotlight,
|
||||
setActionTokens: this.setActionTokens
|
||||
}
|
||||
}
|
||||
|
||||
async tradeFear() {
|
||||
if (event.currentTarget.classList.contains('disabled')) return;
|
||||
|
||||
const currentFear = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
const value = currentFear - 1;
|
||||
if (value >= 0) {
|
||||
Hooks.callAll(socketEvent.GMUpdate, GMUpdateEvent.UpdateFear, null, value);
|
||||
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: { action: GMUpdateEvent.UpdateFear, update: value }
|
||||
});
|
||||
await game.combat.update({ 'system.actions': game.combat.system.actions + 2 });
|
||||
}
|
||||
}
|
||||
|
||||
async increaseResource(event) {
|
||||
if (event.currentTarget.dataset.type === 'action') {
|
||||
await game.combat.update({ 'system.actions': game.combat.system.actions + 1 });
|
||||
}
|
||||
|
||||
const currentFear = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
const value = currentFear + 1;
|
||||
if (event.currentTarget.dataset.type === 'fear' && value <= 6) {
|
||||
Hooks.callAll(socketEvent.GMUpdate, GMUpdateEvent.UpdateFear, null, value);
|
||||
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: { action: GMUpdateEvent.UpdateFear, update: value }
|
||||
});
|
||||
}
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
async decreaseResource(event) {
|
||||
if (event.currentTarget.dataset.type === 'action' && game.combat.system.actions - 1 >= 0) {
|
||||
await game.combat.update({ 'system.actions': game.combat.system.actions - 1 });
|
||||
}
|
||||
|
||||
const currentFear = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
const value = currentFear - 1;
|
||||
if (event.currentTarget.dataset.type === 'fear' && value >= 0) {
|
||||
Hooks.callAll(socketEvent.GMUpdate, GMUpdateEvent.UpdateFear, null, value);
|
||||
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: { action: GMUpdateEvent.UpdateFear, update: value }
|
||||
});
|
||||
}
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
async getData(options = {}) {
|
||||
let context = await super.getData(options);
|
||||
|
||||
// Get the combat encounters possible for the viewed Scene
|
||||
const combat = this.viewed;
|
||||
const hasCombat = combat !== null;
|
||||
const combats = this.combats;
|
||||
const currentIdx = combats.findIndex(c => c === combat);
|
||||
const previousId = currentIdx > 0 ? combats[currentIdx - 1].id : null;
|
||||
const nextId = currentIdx < combats.length - 1 ? combats[currentIdx + 1].id : null;
|
||||
const settings = game.settings.get('core', Combat.CONFIG_SETTING);
|
||||
|
||||
// Prepare rendering data
|
||||
context = foundry.utils.mergeObject(context, {
|
||||
combats: combats,
|
||||
currentIndex: currentIdx + 1,
|
||||
combatCount: combats.length,
|
||||
hasCombat: hasCombat,
|
||||
combat,
|
||||
turns: [],
|
||||
previousId,
|
||||
nextId,
|
||||
started: this.started,
|
||||
control: false,
|
||||
settings,
|
||||
linked: combat?.scene !== null,
|
||||
labels: {}
|
||||
});
|
||||
context.labels.scope = game.i18n.localize(`COMBAT.${context.linked ? 'Linked' : 'Unlinked'}`);
|
||||
if (!hasCombat) return context;
|
||||
|
||||
// Format information about each combatant in the encounter
|
||||
let hasDecimals = false;
|
||||
const turns = [];
|
||||
for (let [i, combatant] of combat.turns.entries()) {
|
||||
if (!combatant.visible) continue;
|
||||
|
||||
// Prepare turn data
|
||||
const resource =
|
||||
combatant.permission >= CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER ? combatant.resource : null;
|
||||
const turn = {
|
||||
id: combatant.id,
|
||||
name: combatant.name,
|
||||
img: await this._getCombatantThumbnail(combatant),
|
||||
active: combatant.id === combat.system.activeCombatant,
|
||||
owner: combatant.isOwner,
|
||||
defeated: combatant.isDefeated,
|
||||
hidden: combatant.hidden,
|
||||
initiative: combatant.initiative,
|
||||
hasRolled: combatant.initiative !== null,
|
||||
hasResource: resource !== null,
|
||||
resource: resource,
|
||||
canPing: combatant.sceneId === canvas.scene?.id && game.user.hasPermission('PING_CANVAS'),
|
||||
playerCharacter: game.user?.character?.id === combatant.actor.id,
|
||||
ownedByPlayer: combatant.hasPlayerOwner
|
||||
};
|
||||
if (turn.initiative !== null && !Number.isInteger(turn.initiative)) hasDecimals = true;
|
||||
turn.css = [turn.active ? 'active' : '', turn.hidden ? 'hidden' : '', turn.defeated ? 'defeated' : '']
|
||||
.join(' ')
|
||||
.trim();
|
||||
|
||||
// Actor and Token status effects
|
||||
turn.effects = new Set();
|
||||
if (combatant.token) {
|
||||
combatant.token.effects.forEach(e => turn.effects.add(e));
|
||||
if (combatant.token.overlayEffect) turn.effects.add(combatant.token.overlayEffect);
|
||||
}
|
||||
if (combatant.actor) {
|
||||
for (const effect of combatant.actor.temporaryEffects) {
|
||||
if (effect.statuses.has(CONFIG.specialStatusEffects.DEFEATED)) turn.defeated = true;
|
||||
else if (effect.icon) turn.effects.add(effect.icon);
|
||||
}
|
||||
}
|
||||
turns.push(turn);
|
||||
}
|
||||
|
||||
// Format initiative numeric precision
|
||||
const precision = CONFIG.Combat.initiative.decimals;
|
||||
turns.forEach(t => {
|
||||
if (t.initiative !== null) t.initiative = t.initiative.toFixed(hasDecimals ? precision : 0);
|
||||
});
|
||||
|
||||
const fear = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
|
||||
// Merge update data for rendering
|
||||
return foundry.utils.mergeObject(context, {
|
||||
round: combat.round,
|
||||
turn: combat.turn,
|
||||
turns: turns,
|
||||
control: combat.combatant?.players?.includes(game.user),
|
||||
fear: fear
|
||||
});
|
||||
}
|
||||
|
||||
onFearUpdate = async () => {
|
||||
this.render(true);
|
||||
};
|
||||
|
||||
async close(options) {
|
||||
Hooks.off(socketEvent.DhpFearUpdate, this.onFearUpdate);
|
||||
static PARTS = {
|
||||
header: {
|
||||
template: 'systems/daggerheart/templates/ui/combat/combatTrackerHeader.hbs'
|
||||
},
|
||||
tracker: {
|
||||
template: 'systems/daggerheart/templates/ui/combat/combatTracker.hbs'
|
||||
},
|
||||
footer: {
|
||||
template: 'systems/daggerheart/templates/ui/combat/combatTrackerFooter.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
return super.close(options);
|
||||
async _prepareCombatContext(context, options) {
|
||||
await super._prepareCombatContext(context, options);
|
||||
|
||||
Object.assign(context, {
|
||||
fear: game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear)
|
||||
});
|
||||
}
|
||||
|
||||
async _prepareTrackerContext(context, options) {
|
||||
await super._prepareTrackerContext(context, options);
|
||||
|
||||
const adversaries = context.turns?.filter(x => x.isNPC) ?? [];
|
||||
const characters = context.turns?.filter(x => !x.isNPC) ?? [];
|
||||
|
||||
Object.assign(context, {
|
||||
actionTokens: game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules).actionTokens,
|
||||
adversaries,
|
||||
characters
|
||||
});
|
||||
}
|
||||
|
||||
async _prepareTurnContext(combat, combatant, index) {
|
||||
const turn = await super._prepareTurnContext(combat, combatant, index);
|
||||
return { ...turn, isNPC: combatant.isNPC, system: combatant.system.toObject() };
|
||||
}
|
||||
|
||||
_getCombatContextOptions() {
|
||||
return [
|
||||
{
|
||||
name: 'COMBAT.ClearMovementHistories',
|
||||
icon: '<i class="fa-solid fa-shoe-prints"></i>',
|
||||
condition: () => game.user.isGM && this.viewed?.combatants.size > 0,
|
||||
callback: () => this.viewed.clearMovementHistories()
|
||||
},
|
||||
{
|
||||
name: 'COMBAT.Delete',
|
||||
icon: '<i class="fa-solid fa-trash"></i>',
|
||||
condition: () => game.user.isGM && !!this.viewed,
|
||||
callback: () => this.viewed.endCombat()
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
static async requestSpotlight(_, target) {
|
||||
const { combatantId } = target.closest('[data-combatant-id]')?.dataset ?? {};
|
||||
const combatant = this.viewed.combatants.get(combatantId);
|
||||
await combatant.update({
|
||||
'system.spotlight': {
|
||||
requesting: !combatant.system.spotlight.requesting
|
||||
}
|
||||
});
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async toggleSpotlight(_, target) {
|
||||
const { combatantId } = target.closest('[data-combatant-id]')?.dataset ?? {};
|
||||
const combatant = this.viewed.combatants.get(combatantId);
|
||||
|
||||
const toggleTurn = this.viewed.combatants.contents
|
||||
.sort(this.viewed._sortCombatants)
|
||||
.map(x => x.id)
|
||||
.indexOf(combatantId);
|
||||
|
||||
await this.viewed.update({ turn: this.viewed.turn === toggleTurn ? null : toggleTurn });
|
||||
await combatant.update({ 'system.spotlight.requesting': false });
|
||||
}
|
||||
|
||||
static async setActionTokens(_, target) {
|
||||
const { combatantId, tokenIndex } = target.closest('[data-combatant-id]')?.dataset ?? {};
|
||||
|
||||
const combatant = this.viewed.combatants.get(combatantId);
|
||||
const changeIndex = Number(tokenIndex);
|
||||
const newIndex = combatant.system.actionTokens > changeIndex ? changeIndex : changeIndex + 1;
|
||||
|
||||
await combatant.update({ 'system.actionTokens': newIndex });
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
import { GMUpdateEvent, socketEvent } from '../helpers/socket.mjs';
|
||||
|
||||
export default class DhpPlayers extends foundry.applications.ui.Players {
|
||||
constructor(data, context) {
|
||||
super(data, context);
|
||||
|
||||
Hooks.on(socketEvent.DhpFearUpdate, this.onFearUpdate);
|
||||
}
|
||||
|
||||
get template() {
|
||||
return 'systems/daggerheart/templates/ui/players.hbs';
|
||||
}
|
||||
|
||||
async getData(options = {}) {
|
||||
const context = super.getData(options);
|
||||
context.fear = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
context.user = game.user;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
// Toggle online/offline
|
||||
html.find('.players-mode').click(this._onToggleOfflinePlayers.bind(this));
|
||||
html.find('.fear-control.up').click(async event => await this.updateFear(event, 1));
|
||||
html.find('.fear-control.down').click(async event => await this.updateFear(event, -1));
|
||||
|
||||
// Context menu
|
||||
const contextOptions = this._getUserContextOptions();
|
||||
Hooks.call('getUserContextOptions', html, contextOptions);
|
||||
new ContextMenu(html, '.player', contextOptions);
|
||||
}
|
||||
|
||||
async updateFear(_, change) {
|
||||
const fear = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
const value = Math.max(Math.min(fear + change, 6), 0);
|
||||
Hooks.callAll(socketEvent.GMUpdate, GMUpdateEvent.UpdateFear, null, value);
|
||||
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: { action: GMUpdateEvent.UpdateFear, update: value }
|
||||
});
|
||||
}
|
||||
|
||||
onFearUpdate = async () => {
|
||||
this.render(true);
|
||||
};
|
||||
|
||||
async close(options) {
|
||||
Hooks.off(socketEvent.DhpFearUpdate, this.onFearUpdate);
|
||||
|
||||
return super.close(options);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue