trait: introduces a first draft of the Mediating Dialog for restoring Astralpoints

main
macniel 2026-07-29 11:21:35 +02:00
parent 6231da455f
commit 3e4d623352
6 changed files with 226 additions and 14 deletions

View File

@ -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)
}))
}
}

View File

@ -26,6 +26,7 @@ import {SpellDialog} from "../dialog/spellDialog.mjs";
import {displayRoll} from "../globals/displayRoll.js"; import {displayRoll} from "../globals/displayRoll.js";
import {ResourceType} from "../data/character.mjs"; import {ResourceType} from "../data/character.mjs";
import {EditResourceDialog} from "../dialog/resourceDialog.mjs"; import {EditResourceDialog} from "../dialog/resourceDialog.mjs";
import {MeditatingDialog} from "../dialog/meditatingDialog.mjs";
const {HandlebarsApplicationMixin, DocumentSheetV2} = foundry.applications.api const {HandlebarsApplicationMixin, DocumentSheetV2} = foundry.applications.api
const {ActorSheetV2} = foundry.applications.sheets const {ActorSheetV2} = foundry.applications.sheets
@ -64,6 +65,7 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
cancelCooldown: CharacterSheet.#cancelCooldown, cancelCooldown: CharacterSheet.#cancelCooldown,
activateCooldown: CharacterSheet.#activateCooldown, activateCooldown: CharacterSheet.#activateCooldown,
rest: CharacterSheet.#startResting, rest: CharacterSheet.#startResting,
meditate: CharacterSheet.#startMeditating,
removeEffect: CharacterSheet.#removeEffect, removeEffect: CharacterSheet.#removeEffect,
rollDamage: CharacterSheet.#rollDamage, rollDamage: CharacterSheet.#rollDamage,
openItemBrowser: CharacterSheet.openItemBrowser, openItemBrowser: CharacterSheet.openItemBrowser,
@ -337,6 +339,11 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
dialog.render(true) dialog.render(true)
} }
static #startMeditating(event, target) {
const dialog = new MeditatingDialog(this.document)
dialog.render(true)
}
static async #removeEffect(event, target) { static async #removeEffect(event, target) {
const {actorId, effectId} = target.dataset const {actorId, effectId} = target.dataset

View File

@ -16,6 +16,8 @@ export class XmlImport {
#unknownSpecialAbilities = [] #unknownSpecialAbilities = []
#unknownAdvantage = [] #unknownAdvantage = []
#ritualkenntnisse = {}
#months = [ #months = [
"Praios", "Praios",
"Rondra", "Rondra",
@ -297,7 +299,6 @@ export class XmlImport {
} }
} }
} }
this.#mapSpecialAbilities(actor, specialAbilities)
json.liturgien = liturgies json.liturgien = liturgies
let combatValues = [] let combatValues = []
@ -315,7 +316,7 @@ export class XmlImport {
if (!options.skipSpells) this.#mapSpells(actor, held) if (!options.skipSpells) this.#mapSpells(actor, held)
if (!options.skipLiturgies) this.#mapLiturgies(actor, liturgies) if (!options.skipLiturgies) this.#mapLiturgies(actor, liturgies)
if (!options.skipEquipment) this.#mapEquipment(actor, held) if (!options.skipEquipment) this.#mapEquipment(actor, held)
if (!options.skipSpecialAbilities) this.#mapSpecialAbilities(actor, specialAbilities)
let notes = [] let notes = []
for (let note in held.kommentare) { for (let note in held.kommentare) {
note = held.kommentare[note] note = held.kommentare[note]
@ -465,8 +466,10 @@ export class XmlImport {
for (let talent in held.talentliste.talent) { for (let talent in held.talentliste.talent) {
talent = held.talentliste.talent[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', [ actor.createEmbeddedDocuments('Item', [
new Blessing({ new Blessing({
@ -627,15 +630,32 @@ export class XmlImport {
}) })
}) })
} else { } else {
actor.createEmbeddedDocuments('Item', [
new SpecialAbility({
name: specialAbility.name, if (specialAbility.name.startsWith("Ritualkenntnis")) {
type: "SpecialAbility", actor.createEmbeddedDocuments('Item', [
system: { new SpecialAbility({
description: specialAbility.auswahl?.wahl?.join("\n"), 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) this.#unknownSpecialAbilities.push(specialAbility.name)
} }

View File

@ -95,7 +95,8 @@
.button { .button {
margin-bottom: 8px; margin-bottom: 8px;
display: flex;
justify-content: space-between;
} }
.attack { .attack {

View File

@ -57,6 +57,9 @@
<div class="sidebar-element button"> <div class="sidebar-element button">
<button type="button" data-action="rest"><i class="fa-solid fa-bed"></i> Rasten</button> <button type="button" data-action="rest"><i class="fa-solid fa-bed"></i> Rasten</button>
{{#if this.hasSpells}}
<button type="button" data-action="meditate"><i class="fa-solid fa-person-praying"></i> Meditieren</button>
{{/if}}
</div> </div>
{{#each attacks}} {{#each attacks}}

View File

@ -0,0 +1,46 @@
<section>
<div class="options">
<label>
<span>Ritual der Meditation</span>
<select name="skill">
{{selectOptions rituale}}
<option value="Musizieren">Elfisch</option>
<option value="Selbstbeherrschung">Schelmisch</option>
</select>
</label>
</div>
<div class="options">
<label>
<input type="checkbox" name="astralmeditation" {{checked this.hasAstraleMeditation}}/>
<span>Astrale Meditation erlernt</span>
</label>
</div>
<div class="options">
<label>
<input type="checkbox" name="thonnys" {{checked this.hasThonnys}}/>
<span>Thonnys verfügbar</span>
</label>
</div>
<div class="options">
<label>
<span>Lebenspunkte Umwandeln</span>
<input name="aspRegain" type="number"/>
</label>
</div>
<fieldset>
<legend>Modifikatoren</legend>
<div class="results">
<span id="header_skill">Probe</span>
<output name="talentprobe">{{talentprobe}}</output>
<span>Dauer</span>
<output name="duration">{{duration}}</output>
<span>Kosten</span>
<output name="costs">{{costs}}</output>
<span>Bei Erfolg</span>
<output name="result">{{result}}</output>
</div>
</fieldset>
<button type="button" class="actions" data-action="regenerate"><i class="fa-solid fa-person-praying"></i> Meditieren</button>
</section>