diff --git a/src/module/dialog/meditatingDialog.mjs b/src/module/dialog/meditatingDialog.mjs new file mode 100644 index 00000000..4c01313a --- /dev/null +++ b/src/module/dialog/meditatingDialog.mjs @@ -0,0 +1,135 @@ +import {XmlImport} from "../xml-import/xml-import.mjs"; +import {SpecialAbility} from "../documents/specialAbility.mjs"; + +const { + ApplicationV2, + HandlebarsApplicationMixin +} = foundry.applications.api + +export class MeditatingDialog extends HandlebarsApplicationMixin(ApplicationV2) { + + static DEFAULT_OPTIONS = { + classes: ['dsa41', 'dialog', 'meditating'], + tag: "form", + position: { + width: 320, + height: 433 + }, + window: { + resizable: false, + title: 'Meditieren' + }, + form: { + submitOnChange: true, + closeOnSubmit: false, + }, + } + + static PARTS = { + form: { + template: 'systems/DSA_4-1/templates/dialog/meditating-dialog.hbs', + } + } + + /** + * @type {Actor} + * @private + */ + _actor = null + + constructor(actor) { + super(); + this._actor = actor + } + + static async #onSubmitForm(event, form, formData) { + event.preventDefault() + + } + + #hatSonderfertigkeit(name) { + return this._actor.itemTypes["SpecialAbility"]?.find(p => p.name === name) != null + } + + async _prepareContext(options) { + const context = await super._prepareContext(options) + + context.hasAstraleMeditation = this.#hatSonderfertigkeit("Astrale Meditation") + context.hasThonnys = false + + + + context.rituale = {} + + this._actor.itemTypes["SpecialAbility"]?.filter(p => p.name.startsWith("Ritualkenntnis")).forEach( p => { + context.rituale[p.name] = p.name.split("Ritualkenntnis:")[1].trim() + }) + + context.duration = "0" + context.costs = "0 + 1d3" + context.result = 0 + + return context + } + + + #update(context) { + // params + const aspregain = this.element.querySelector('[name="aspRegain"]').value + const thonnys = !!this.element.querySelector('[name="thonnys"]:checked') + const astralmeditation = !!this.element.querySelector('[name="astralmeditation"]:checked') + const talent = this.element.querySelector('[name="skill"]').value + const rituale = this._actor.itemTypes["SpecialAbility"]?.filter(p => p.name.startsWith("Ritualkenntnis")) + + let wert = rituale.find( p => context.rituale[talent])?.system.value.split(talent + ": ")[1].trim() ?? null + + let ritualWert = 0 + + if (!wert) { + console.log("Ritualkenntniswert nicht gefunden für", talent) + // maybe its actually a talent? + + const actualTalent = this._actor.itemTypes["Skill"].find(p => p.name === talent) + if (actualTalent) { + wert = actualTalent.system.taw + ritualWert = wert + "/2" + } + } else { + ritualWert = Number(wert) + } + + // outputs + const probe = this.element.querySelector("[name='talentprobe']") + const dauer = this.element.querySelector("[name='duration']") + const costs = this.element.querySelector("[name='costs']") + const result = this.element.querySelector("[name='result']") + + let penalty + let bonus = " +"+ ritualWert + + if (astralmeditation && thonnys) { + bonus = " +" + ritualWert + " +3" + } + + if (astralmeditation && thonnys) { + penalty = "" + } else { + penalty = " +1d3" + } + + probe.value = "IN/CH/KO " + bonus + costs.value = ""+aspregain + penalty + " LeP" + dauer.value = aspregain + " Spielrunden" + result.value = aspregain + " AsP" + + } + + _onRender(context, options) { + this.#update(context) + + this.element.querySelectorAll('[name="thonnys"], [name="astralmeditation"], [name="skill"], [name="aspRegain"]').forEach(e => e.addEventListener('change', (event) => { + this.#update(context) + })) + + } +} \ No newline at end of file diff --git a/src/module/sheets/characterSheet.mjs b/src/module/sheets/characterSheet.mjs index 6df735c9..843df74f 100644 --- a/src/module/sheets/characterSheet.mjs +++ b/src/module/sheets/characterSheet.mjs @@ -26,6 +26,7 @@ import {SpellDialog} from "../dialog/spellDialog.mjs"; import {displayRoll} from "../globals/displayRoll.js"; import {ResourceType} from "../data/character.mjs"; import {EditResourceDialog} from "../dialog/resourceDialog.mjs"; +import {MeditatingDialog} from "../dialog/meditatingDialog.mjs"; const {HandlebarsApplicationMixin, DocumentSheetV2} = foundry.applications.api const {ActorSheetV2} = foundry.applications.sheets @@ -64,6 +65,7 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) { cancelCooldown: CharacterSheet.#cancelCooldown, activateCooldown: CharacterSheet.#activateCooldown, rest: CharacterSheet.#startResting, + meditate: CharacterSheet.#startMeditating, removeEffect: CharacterSheet.#removeEffect, rollDamage: CharacterSheet.#rollDamage, openItemBrowser: CharacterSheet.openItemBrowser, @@ -337,6 +339,11 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) { dialog.render(true) } + static #startMeditating(event, target) { + const dialog = new MeditatingDialog(this.document) + dialog.render(true) + } + static async #removeEffect(event, target) { const {actorId, effectId} = target.dataset diff --git a/src/module/xml-import/xml-import.mjs b/src/module/xml-import/xml-import.mjs index 0f324fe2..1e4b512c 100644 --- a/src/module/xml-import/xml-import.mjs +++ b/src/module/xml-import/xml-import.mjs @@ -16,6 +16,8 @@ export class XmlImport { #unknownSpecialAbilities = [] #unknownAdvantage = [] + #ritualkenntnisse = {} + #months = [ "Praios", "Rondra", @@ -297,7 +299,6 @@ export class XmlImport { } } } - this.#mapSpecialAbilities(actor, specialAbilities) json.liturgien = liturgies let combatValues = [] @@ -315,7 +316,7 @@ export class XmlImport { if (!options.skipSpells) this.#mapSpells(actor, held) if (!options.skipLiturgies) this.#mapLiturgies(actor, liturgies) if (!options.skipEquipment) this.#mapEquipment(actor, held) - + if (!options.skipSpecialAbilities) this.#mapSpecialAbilities(actor, specialAbilities) let notes = [] for (let note in held.kommentare) { note = held.kommentare[note] @@ -465,8 +466,10 @@ export class XmlImport { for (let talent in held.talentliste.talent) { talent = held.talentliste.talent[talent] - // hook liturgy - if (talent.name.startsWith("Liturgiekenntnis")) { + + if (talent.name.startsWith("Ritualkenntnis")) { // hook Ritualkenntnisse + this.#ritualkenntnisse[talent.name] = talent.value; + } else if (talent.name.startsWith("Liturgiekenntnis")) { // hook liturgy actor.createEmbeddedDocuments('Item', [ new Blessing({ @@ -627,15 +630,32 @@ export class XmlImport { }) }) } else { - actor.createEmbeddedDocuments('Item', [ - new SpecialAbility({ - name: specialAbility.name, - type: "SpecialAbility", - system: { - description: specialAbility.auswahl?.wahl?.join("\n"), - } - }) - ]) + + + if (specialAbility.name.startsWith("Ritualkenntnis")) { + actor.createEmbeddedDocuments('Item', [ + new SpecialAbility({ + name: specialAbility.name, + type: "SpecialAbility", + system: { + name: specialAbility.name, + value: specialAbility.name + "(" + this.#ritualkenntnisse[specialAbility.name] + ")", + description: specialAbility.auswahl?.wahl?.join("\n"), + } + }) + ]) + } else { + actor.createEmbeddedDocuments('Item', [ + new SpecialAbility({ + name: specialAbility.name, + type: "SpecialAbility", + system: { + name: specialAbility.name, + description: specialAbility.auswahl?.wahl?.join("\n"), + } + }) + ]) + } this.#unknownSpecialAbilities.push(specialAbility.name) } diff --git a/src/style/molecules/_sidebar-elements.scss b/src/style/molecules/_sidebar-elements.scss index b0376eb1..11e82eb0 100644 --- a/src/style/molecules/_sidebar-elements.scss +++ b/src/style/molecules/_sidebar-elements.scss @@ -95,7 +95,8 @@ .button { margin-bottom: 8px; - + display: flex; + justify-content: space-between; } .attack { diff --git a/src/templates/actor/character/main-sheet.hbs b/src/templates/actor/character/main-sheet.hbs index 2389e217..73fa4545 100644 --- a/src/templates/actor/character/main-sheet.hbs +++ b/src/templates/actor/character/main-sheet.hbs @@ -57,6 +57,9 @@ {{#each attacks}} diff --git a/src/templates/dialog/meditating-dialog.hbs b/src/templates/dialog/meditating-dialog.hbs new file mode 100644 index 00000000..04c28609 --- /dev/null +++ b/src/templates/dialog/meditating-dialog.hbs @@ -0,0 +1,46 @@ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ Modifikatoren +
+ Probe + {{talentprobe}} + Dauer + {{duration}} + Kosten + {{costs}} + Bei Erfolg + {{result}} + +
+
+ +
\ No newline at end of file