diff --git a/src/lang/en.json b/src/lang/en.json index 112bcad..3f374f6 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -15,6 +15,7 @@ "OSE.dialog.partysheet": "Party Overview", "OSE.dialog.selectActors": "Select PCs", "OSE.dialog.dealXP": "Deal XP", + "OSE.dialog.generateSaves": "Generate Saves", "OSE.Formula": "Formula", "OSE.SitMod": "Situational Modifier", diff --git a/src/lang/fr.json b/src/lang/fr.json index 825a5f5..d15c81d 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -15,6 +15,7 @@ "OSE.dialog.partysheet": "Fiche de Groupe", "OSE.dialog.selectActors": "Choisir PJs", "OSE.dialog.dealXP": "Donner XP", + "OSE.dialog.generateSaves": "Générer les Sauvegardes", "OSE.Formula": "Formule", "OSE.SitMod": "Mod. de situation", diff --git a/src/module/actor/character-sheet.js b/src/module/actor/character-sheet.js index ef0e977..bd266dd 100644 --- a/src/module/actor/character-sheet.js +++ b/src/module/actor/character-sheet.js @@ -1,6 +1,7 @@ import { OseActor } from "./entity.js"; import { OseActorSheet } from "./actor-sheet.js"; import { OseCharacterModifiers } from "../dialog/character-modifiers.js"; +import { OseCharacterCreator } from "../dialog/character-creation.js"; /** * Extend the basic ActorSheet with some very simple modifications @@ -33,6 +34,22 @@ export class OseActorSheetCharacter extends OseActorSheet { }); } + /** + * Character creation helpers + * @param {...any} args + */ + async _render(...args) { + super._render(...args).then(() => { + if (this.actor.isNew()) { + event.preventDefault(); + new OseCharacterCreator(this.actor, { + top: this.position.top + 40, + left: this.position.left + (this.position.width - 400) / 2, + }).render(true); + } + }); + } + /** * Prepare data for rendering the Actor sheet * The prepared data object contains both the actor data as well as additional sheet options diff --git a/src/module/actor/entity.js b/src/module/actor/entity.js index 03377b0..cc5c763 100644 --- a/src/module/actor/entity.js +++ b/src/module/actor/entity.js @@ -51,6 +51,56 @@ export class OseActor extends Actor { }); } + isNew() { + const data = this.data.data; + if (this.data.type == 'character') { + let ct = 0; + Object.values(data.scores).forEach((el) => { + ct += el.value; + }) + return ct == 0 ? true : false; + } else if (this.data.type == 'monster') { + let ct = 0; + Object.values(data.saves).forEach(el => { + ct += el.value; + }); + return ct == 0 ? true : false; + } + } + + generator() { + + } + + generateSave(hd) { + let saves = {}; + for (let i = 0; i <= hd; i++) { + let tmp = CONFIG.OSE.monster_saves[i]; + if (tmp) { + saves = tmp; + } + } + this.update({ + "data.saves": { + death: { + value: saves.d + }, + wand: { + value: saves.w + }, + paralysis: { + value: saves.p + }, + breath: { + value: saves.b + }, + spell: { + value: saves.s + } + } + }); + } + /* -------------------------------------------- */ /* Rolls */ /* -------------------------------------------- */ @@ -540,7 +590,7 @@ export class OseActor extends Actor { let total = 0; let treasure = this.data.items.filter(i => (i.type == "item" && i.data.treasure)) treasure.forEach((item) => { - total += item.data.quantity.value * item.data.cost; + total += item.data.quantity.value * item.data.cost; }); data.treasure = total; } diff --git a/src/module/actor/monster-sheet.js b/src/module/actor/monster-sheet.js index 0c79b21..31c43cd 100644 --- a/src/module/actor/monster-sheet.js +++ b/src/module/actor/monster-sheet.js @@ -32,6 +32,38 @@ export class OseActorSheetMonster extends OseActorSheet { }); } + /** + * Monster creation helpers + * @param {...any} args + */ + async _render(...args) { + super._render(...args).then(() => { + if (this.actor.isNew()) { + const template = ` +
`; + new Dialog({ + title: game.i18n.localize("OSE.dialog.generateSaves"), + content: template, + buttons: { + set: { + icon: '', + label: game.i18n.localize("OSE.dialog.generateSaves"), + callback: (html) => { + let hd = html.find('input[name="total"]').val(); + this.actor.generateSave(hd); + }, + }, + }, + }).render(true); + } + }); + } + /** * Prepare data for rendering the Actor sheet * The prepared data object contains both the actor data as well as additional sheet options diff --git a/src/module/config.js b/src/module/config.js index 0ae8e6c..d81e9ea 100644 --- a/src/module/config.js +++ b/src/module/config.js @@ -87,5 +87,70 @@ export const OSE = { splash: "/systems/ose/assets/splash.png", reload: "/systems/ose/assets/reload.png", charge: "/systems/ose/assets/charge.png", + }, + monster_saves: { + 0: { + d: 14, + w: 15, + p: 16, + b: 17, + s: 18 + }, + 1: { + d: 12, + w: 13, + p: 14, + b: 15, + s: 16 + }, + 4: { + d: 10, + w: 11, + p: 12, + b: 13, + s: 14 + }, + 7: { + d: 8, + w: 9, + p: 10, + b: 10, + s: 12 + }, + 10: { + d: 6, + w: 7, + p: 8, + b: 8, + s: 10 + }, + 13: { + d: 4, + w: 5, + p: 6, + b: 5, + s: 8 + }, + 16: { + d: 2, + w: 3, + p: 4, + b: 3, + s: 6 + }, + 19: { + d: 2, + w: 2, + p: 2, + b: 2, + s: 4 + }, + 22: { + d: 2, + w: 2, + p: 2, + b: 2, + s: 2 + }, } }; \ No newline at end of file diff --git a/src/module/dialog/character-creation.js b/src/module/dialog/character-creation.js new file mode 100644 index 0000000..b082b54 --- /dev/null +++ b/src/module/dialog/character-creation.js @@ -0,0 +1,57 @@ +// eslint-disable-next-line no-unused-vars +import { OseActor } from '../actor/entity.js'; + +export class OseCharacterCreator extends FormApplication { + static get defaultOptions() { + const options = super.defaultOptions; + options.id = 'character-creator'; + options.template = + 'systems/ose/templates/actors/dialogs/character-creation.html'; + options.width = 380; + return options; + } + + /* -------------------------------------------- */ + + /** + * Add the Entity name into the window title + * @type {String} + */ + get title() { + return `${this.object.name}: ${game.i18n.localize('OSE.dialog.tweaks')}`; + } + + /* -------------------------------------------- */ + + /** + * Construct and return the data object used to render the HTML template for this form application. + * @return {Object} + */ + getData() { + let data = this.object.data; + data.user = game.user; + data.config = CONFIG.OSE; + return data; + } + + /* -------------------------------------------- */ + + /** @override */ + activateListeners(html) { + super.activateListeners(html); + } + + /** + * This method is called upon form submission after form data is validated + * @param event {Event} The initial triggering submission event + * @param formData {Object} The object of validated form data with which to update the object + * @private + */ + async _updateObject(event, formData) { + event.preventDefault(); + // Update the actor + this.object.update(formData); + // Re-draw the updated sheet + this.object.sheet.render(true); + } +} diff --git a/src/template.json b/src/template.json index 0260b21..da0f4c1 100644 --- a/src/template.json +++ b/src/template.json @@ -31,19 +31,19 @@ }, "saves": { "death": { - "value": 10 + "value": 0 }, "wand": { - "value": 10 + "value": 0 }, "paralysis": { - "value": 10 + "value": 0 }, "breath": { - "value": 10 + "value": 0 }, "spell": { - "value": 10 + "value": 0 } }, "movement": { diff --git a/src/templates/actors/dialogs/character-creation.html b/src/templates/actors/dialogs/character-creation.html new file mode 100644 index 0000000..a587fde --- /dev/null +++ b/src/templates/actors/dialogs/character-creation.html @@ -0,0 +1,7 @@ + \ No newline at end of file