From 8b0e11f071d419b71b5df697541308bf3efa578f Mon Sep 17 00:00:00 2001 From: macniel Date: Mon, 13 Oct 2025 23:45:01 +0200 Subject: [PATCH] imports combatstatistics --- src/module/data/skill.mjs | 2 +- src/module/sheets/characterSheet.mjs | 15 +++++++++++-- src/module/xml-import/xml-import.mjs | 32 +++++++++++++++++++++------- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/module/data/skill.mjs b/src/module/data/skill.mjs index ca23862e..6c41045d 100644 --- a/src/module/data/skill.mjs +++ b/src/module/data/skill.mjs @@ -10,7 +10,7 @@ export class SkillDataModel extends BaseItem { gruppe: new StringField({required: true}), taw: new NumberField({integer: true, initial: 0}), at: new NumberField({required: false, integer: true, initial: 0}), - pa: new NumberField({required: false, integer: true, initial: 0}), + pa: new NumberField({required: false, integer: true, nullable: true, initial: 0}), probe: new ArrayField(new StringField(), {exact: 3}), // References one of the eight attributes by name voraussetzung: new SchemaField({ talent: new StringField({model: SkillDataModel}), diff --git a/src/module/sheets/characterSheet.mjs b/src/module/sheets/characterSheet.mjs index 7a626b42..60176c50 100644 --- a/src/module/sheets/characterSheet.mjs +++ b/src/module/sheets/characterSheet.mjs @@ -94,10 +94,22 @@ export class CharacterSheet extends ActorSheet { eigenschaft2: werte[1].name, eigenschaft3: werte[2].name, probe: `(${eigenschaften.join("/")})`, + id: item._id, at: item.system.at, pa: item.system.pa, - id: item._id, + komplexität: item.system.komplexität }; + + if (talentGruppe === "Kampf") { + + if (item.system.pa != null) { // has no parry value so it must be ranged talent (TODO: but it isnt as there can be combatstatistics which has no pa value assigned to) + obj.at = item.system.at + context.derived.at.aktuell + obj.pa = item.system.pa + context.derived.pa.aktuell + } else { + obj.at = item.system.at + context.derived.fk.aktuell + } + } + context.skills[talentGruppe].push(obj); context.flatSkills.push(obj); } @@ -379,7 +391,6 @@ export class CharacterSheet extends ActorSheet { const fkitems = fernkampf.system.rangedSkills.map(async (skillInQuestion) => await this.object.items.getName(skillInQuestion)) fkitems.forEach(async skill => { const obj = await skill - console.log(this.object.system.fk, obj.system.at); context.attacks.push({ name: obj.name, using: fernkampf.name, diff --git a/src/module/xml-import/xml-import.mjs b/src/module/xml-import/xml-import.mjs index 6efb67d7..1e7eadce 100644 --- a/src/module/xml-import/xml-import.mjs +++ b/src/module/xml-import/xml-import.mjs @@ -74,7 +74,7 @@ function getJsonFromXML(dom) { return jsonResult; } -async function addSkillFromCompendiumByNameToActor(talentName, taw, actor) { +async function addSkillFromCompendiumByNameToActor(talentName, taw, actor, combatStatistics, attributes) { const compendiumOfSkills = game.packs.get('DSA_4-1.talente'); const talentId = compendiumOfSkills.index.find(skill => skill.name === talentName) if (talentId) { @@ -83,7 +83,21 @@ async function addSkillFromCompendiumByNameToActor(talentName, taw, actor) { try { const embeddedDocument = (await actor.createEmbeddedDocuments('Item', [talent]))[0] - embeddedDocument.update({system: {taw: taw}}); + if (talent.system.gruppe === "Kampf") { + const atbasis = attributes.find(p => p.name === "at").value + const pabasis = attributes.find(p => p.name === "pa").value + const combatStatistic = combatStatistics.find(p => p.name === talent.name) + if (combatStatistic) { // melee with AT/PA values + let at = combatStatistic.at - atbasis ?? 0 + let pa = combatStatistic.pa - pabasis ?? 0 + console.log({system: {taw, at, pa}}) + embeddedDocument.update({system: {taw, at, pa}}); + } else { // ranged with only AT values which is equal to taw + embeddedDocument.update({system: {taw: taw, at: taw, pa: null}}); // at is already at raw taw and wasn't influenced by helden-software precalculations + } + } else { + embeddedDocument.update({system: {taw: taw, at: null, pa: null}}); // just regular talent with taw + } } catch (error) { console.error(`${talentName} not found in items`, error) } @@ -171,7 +185,7 @@ function calculateBirthdate(json) { return `${day}. ${month} ${year} BF` } -function mapSkills(actor, held) { +function mapSkills(actor, held, kampfwerte) { for (let talent in held.talentliste.talent) { talent = held.talentliste.talent[talent] @@ -191,7 +205,8 @@ function mapSkills(actor, held) { } else { // proceed - addSkillFromCompendiumByNameToActor(talent.name, talent.value, actor) + const eigenschaften = held.eigenschaften.eigenschaft + addSkillFromCompendiumByNameToActor(talent.name, talent.value, actor, kampfwerte, eigenschaften) } } } @@ -333,10 +348,6 @@ function mapRawJson(actor, rawJson) { json.sonderfertigkeiten = specialAbilities json.liturgien = liturgies - mapSkills(actor, held) - mapSpells(actor, held) - mapMiracles(actor, liturgies) - let combatValues = [] for (let combatValue in held.kampf.kampfwerte) { combatValue = held.kampf.kampfwerte[combatValue] @@ -347,6 +358,11 @@ function mapRawJson(actor, rawJson) { }) } json.kampfwerte = combatValues + + mapSkills(actor, held, combatValues) + mapSpells(actor, held) + mapMiracles(actor, liturgies) + let notes = [] for (let note in held.kommentare) { note = held.kommentare[note]