functioning spells & more

This commit is contained in:
Byroks committed 2026-10-21 19:18:13 +02:00
1 parent 2291c5d1e6
commit e4eecb7b8e
28 files changed
+681 -131

No files matched your search

+43
View File
@@ -17,6 +17,49 @@ export class M6ArmorSheet extends M6ItemSheet {
};
}
static TABS = {
primary: {
tabs: [
{
id: "eigenschaften",
icon: "fa-shield-halved"
},
{
id: "beschreibung",
icon: "fa-feather-pointed"
},
{
id: "effects",
icon: "fa-bolt"
}
],
initial: "eigenschaften",
labelPrefix: "Midgard6.Sheets.Tabs"
}
};
/** @inheritdoc */
static PARTS = {
header: {
template: systemPath("templates/item/header.hbs")
},
tabs: {
template: systemPath("templates/shared/tabs.hbs")
},
eigenschaften: {
template: systemPath("templates/item/rüstung/eigenschaften.hbs"),
scrollable: [""]
},
beschreibung: {
template: systemPath("templates/item/description.hbs"),
scrollable: [""]
},
effects: {
template: systemPath("templates/shared/effects.hbs"),
scrollable: [""]
}
};
static #cycleEquip() {
this.item.update({
system: {
+88 -45
View File
@@ -1,6 +1,7 @@
import { systemPath } from "../constants.mjs";
import { prepareActiveEffectCategories } from "../helpers/utils.mjs";
import { addSpezialisierung, editSepzialisierung } from "./components/spezialisierung-actions.mjs";
import { prepArmor, prepWeapons, prepWeight, prepSpells } from "./components/character-prep.mjs";
const { api, sheets } = foundry.applications;
@@ -25,6 +26,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
toggleEffect: this.#toggleEffect,
rollSkill: this.#rollSkill,
rollWeapon: this.#rollWeapon,
rollSpell: this.#rollSpell,
cycleEquip: this.#cycleEquip,
addSpezialisierung: addSpezialisierung,
editSepzialisierung: editSepzialisierung
@@ -41,23 +43,24 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
primary: {
tabs: [
{
id: "properties",
id: "eigenschaften",
icon: "fa-shield-halved"
},
{
id: "items",
icon: "fa-suitcase"
},
{
id: "biographie",
icon: "fa-feather"
id: "zauber",
icon: "fa-hand-sparkles"
},
{
id: "effects",
icon: "fa-bolt"
}
],
initial: "properties",
initial: "eigenschaften",
labelPrefix: "Midgard6.Sheets.Tabs"
}
};
@@ -67,13 +70,17 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
/** @inheritdoc */
static PARTS = {
tabs: {
template: systemPath("templates/actor/tabs.hbs")
template: systemPath("templates/shared/tabs.hbs")
},
header: {
template: systemPath("templates/actor/header.hbs")
},
properties: {
template: systemPath("templates/shared/properties.hbs"),
eigenschaften: {
template: systemPath("templates/actor/eigenschaften.hbs"),
scrollable: [""]
},
zauber: {
template: systemPath("templates/actor/zauber.hbs"),
scrollable: [""]
},
items: {
@@ -106,6 +113,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
/** @inheritdoc */
async _prepareContext(options) {
const context = await super._prepareContext(options);
await prepArmor(this.actor);
Object.assign(context, {
owner: this.document.isOwner,
@@ -125,23 +133,24 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
/** @inheritdoc */
async _preparePartContext(partId, context) {
switch (partId) {
// case "stats":
// context.fields = await this._getResources();
// context.tab = context.tabs[partId];
// break;
case "effects":
context.effects = prepareActiveEffectCategories(this.actor.allApplicableEffects());
context.tab = context.tabs[partId];
break;
case "properties":
case "eigenschaften":
context.skills = await this._getSkills();
context.resistenzen = await this._getResistenzen();
context.equippedWeapons = await this._prepWeapons();
context.equippedWeapons = await prepWeapons(this.actor);
context.equippedSpells = await prepSpells(this.actor);
context.tab = context.tabs[partId];
break;
case "items":
context.itemTypes = await this._getItems();
context.gewicht = this._clacWeight();
context.gewicht = await prepWeight(this.actor);
context.tab = context.tabs[partId];
break;
case "zauber":
context.zauber = await this._getZauber();
context.tab = context.tabs[partId];
break;
}
@@ -257,28 +266,10 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
return fieldSets;
}
async _prepWeapons() {
const weaponItems = this.actor.items.filter((x) => x.type === "weapon" && x.system.equipped);
const weapons = [];
weaponItems.forEach((weapon) => {
const skill = foundry.utils.getProperty(this.actor, weapon.system.fertigkeit);
const w = {
name: weapon.name,
skillValue: skill.value,
bonusValue:
skill.bonuses.find((x) => x.name === weapon.system.spezialisierung)?.level + 1 || "",
img: weapon.img,
skillPath: weapon.system.fertigkeit,
path: weapon.system.fertigkeit,
id: weapon.id
};
weapons.push(w);
});
return weapons;
}
static async #cycleEquip(event, target) {
console.warn(target.dataset);
const item = this.actor.items.get(target.dataset.itemId);
console.warn(item);
item.update({
system: {
equipped: !item.system.equipped
@@ -329,15 +320,8 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
return types;
}
_clacWeight() {
const items = this.actor.items.filter((x) => x.system.gewicht);
let gewicht = items.reduce((accumulator, item) => accumulator + item.system.gewicht, 0);
let traglast = Math.max(this.actor.system.skills.körper.athletik.value, 10);
return {
traglast,
gewicht
};
_getZauber() {
return this.actor.items.filter((item) => item.type === "zauber");
}
/* -------------------------------------------------- */
@@ -427,6 +411,65 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
effect.update({ disabled: !effect.disabled });
}
static async #rollSpell(event, target) {
const dataset = target.dataset;
const skill = foundry.utils.getProperty(this.actor, "system.skills.magie.zaubern");
const item = this.actor.items.get(dataset.itemId);
const actor = this.actor;
const dialogResult = await this.rollDialog({
name: dataset.name,
skill,
damageRoll: item.system.eigenschaften.schaden,
preSelectedSpez: item.system.eigenschaften.ursprung,
actor
});
console.log("Dialog Result", dialogResult);
if (dialogResult === "abort") {
return;
}
// Construct the Roll instance
const skillValue = skill.value;
let die = "";
switch (dialogResult.vorteil) {
case -1:
die = "2d20kl";
break;
case 1:
die = "2d20kh";
break;
default:
die = "1d20";
break;
}
let rollTerm = "@die + @skill";
let rollFlavor = dataset.name;
let roll;
if (dialogResult.spezLevel) {
rollTerm += " + @spezBonus";
rollFlavor += ": " + dialogResult.spezName;
}
if (dialogResult.customRoll) {
roll = new Roll(dialogResult.customRoll);
} else {
roll = new Roll(
rollTerm,
{ die: die, skill: skillValue, spezBonus: dialogResult.spezLevel + 1 },
{ flavor: rollFlavor }
);
}
// The parsed terms of the roll formula
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
// Execute the roll
await roll.evaluate();
roll.toMessage();
}
static async #rollSkill(event, target) {
const dataset = target.dataset;
const skill = foundry.utils.getProperty(this.actor, target.dataset.path.replace(".value", ""));
@@ -437,7 +480,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
actor
});
console.log("Dialog Result", dialogResult);
if (!dialogResult) {
if (dialogResult === "abort") {
return;
}
// Construct the Roll instance
@@ -496,7 +539,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
actor
});
console.log("Dialog Result", dialogResult);
if (!dialogResult) {
if (dialogResult === "abort") {
return;
}
// Construct the Roll instance
+74
View File
@@ -0,0 +1,74 @@
export async function prepArmor(actor) {
const actorData = actor.system;
// 1. Basis-Wert festlegen
let baseRüstwert = actorData.rüstwert || 0;
// 2. Ausgerüstete Rüstung finden und addieren
const equippedMainArmor = actor.items.filter(
(i) => i.type === "armor" && i.system.equipped && !i.system.zusätzlich
);
const equippedAddArmor = actor.items.filter(
(i) => i.type === "armor" && i.system.equipped && i.system.zusätzlich
);
let armorBonus = Math.max(...equippedMainArmor.map((x) => x.system.rüstwert), 0);
for (let armor of equippedAddArmor) {
armorBonus += armor.system.rüstwert;
}
// 3. Finalen Standard-Wert berechnen
actorData.rüstwert = baseRüstwert + armorBonus;
}
export async function prepWeapons(actor) {
const weaponItems = actor.items.filter((x) => x.type === "weapon" && x.system.equipped);
const weapons = [];
weaponItems.forEach((weapon) => {
const skill = foundry.utils.getProperty(actor, weapon.system.fertigkeit);
const w = {
name: weapon.name,
skillValue: skill.value,
bonusValue:
skill.bonuses.find((x) => x.name === weapon.system.spezialisierung)?.level + 1 || "",
img: weapon.img,
skillPath: weapon.system.fertigkeit,
path: weapon.system.fertigkeit,
id: weapon.id
};
weapons.push(w);
});
return weapons;
}
export async function prepSpells(actor) {
const spellItems = actor.items.filter((x) => x.type === "zauber" && x.system.equipped);
const spells = [];
const skill = foundry.utils.getProperty(actor, "system.skills.magie.zaubern");
console.warn(skill, spellItems);
spellItems.forEach((spell) => {
const w = {
name: spell.name,
skillValue: skill.value,
bonusValue:
skill.bonuses.find((x) => x.name === spell.system.eigenschaften.ursprung)?.level + 1 || "",
img: spell.img,
skillPath: "system.skills.magie.zaubern",
path: "Zaubern",
id: spell.id
};
spells.push(w);
});
return spells;
}
export async function prepWeight(actor) {
const items = actor.items.filter((x) => x.system.gewicht);
let gewicht = items.reduce((accumulator, item) => accumulator + item.system.gewicht, 0);
let traglast = Math.max(actor.system.skills.körper.athletik.value, 10);
return {
traglast,
gewicht
};
}
+1 -1
View File
@@ -57,7 +57,7 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet
template: systemPath("templates/item/header.hbs")
},
tabs: {
template: systemPath("templates/actor/tabs.hbs")
template: systemPath("templates/shared/tabs.hbs")
},
beschreibung: {
template: systemPath("templates/item/description.hbs"),
+2 -2
View File
@@ -44,10 +44,10 @@ export class M6WeaponSheet extends M6ItemSheet {
template: systemPath("templates/item/header.hbs")
},
tabs: {
template: systemPath("templates/actor/tabs.hbs")
template: systemPath("templates/shared/tabs.hbs")
},
eigenschaften: {
template: systemPath("templates/item/eigenschaften.hbs"),
template: systemPath("templates/item/waffen/eigenschaften.hbs"),
scrollable: [""]
},
beschreibung: {
+108
View File
@@ -0,0 +1,108 @@
import { prepareActiveEffectCategories } from "../helpers/utils.mjs";
import { systemPath } from "../constants.mjs";
import { M6ItemSheet } from "./item-sheet.mjs";
const { api, sheets } = foundry.applications;
/**
* Extend the basic ItemSheet with some very simple modifications.
*/
export class M6ZauberSheet extends M6ItemSheet {
static get DEFAULT_OPTIONS() {
return {
...super.DEFAULT_OPTIONS, // Kopiert alle bestehenden Actions aus M6ItemSheet
actions: {
...super.DEFAULT_OPTIONS.actions,
cycleEquip: this.#cycleEquip // Fügt NUR für dieses Sheet die neue Action hinzu
}
};
}
static TABS = {
primary: {
tabs: [
{
id: "eigenschaften",
icon: "fa-shield-halved"
},
{
id: "beschreibung",
icon: "fa-feather-pointed"
}
],
initial: "eigenschaften",
labelPrefix: "Midgard6.Sheets.Tabs"
}
};
/** @inheritdoc */
static PARTS = {
header: {
template: systemPath("templates/zauber/header.hbs")
},
tabs: {
template: systemPath("templates/shared/tabs.hbs")
},
eigenschaften: {
template: systemPath("templates/zauber/eigenschaften.hbs"),
scrollable: [""]
},
beschreibung: {
template: systemPath("templates/zauber/description.hbs"),
scrollable: [""]
}
};
async _addSpecifics(context) {
context.zauberFields = await this._getFields();
context.bonuses = foundry.utils.getProperty(this.actor, "system.skills.magie.zaubern").bonuses;
console.warn(context);
}
static #cycleEquip() {
this.item.update({
system: {
equipped: !this.item.system.equipped
}
});
}
/* -------------------------------------------------- */
/**
* Handles the system fields for the form-fields generic.
*/
async _getFields() {
const doc = this.item;
const source = doc._source;
const systemFields = CONFIG.Item.dataModels[doc.type]?.schema.fields;
const fieldSets = {};
// TODO: Find a clever way to handle enrichment
for (const field of Object.values(systemFields ?? {})) {
const path = `system.${field.name}`;
if (field instanceof foundry.data.fields.SchemaField) {
const fieldset = { fieldset: true, legend: field.label, fields: {} };
await this.#addSystemFields(fieldset, field.fields, source, path);
fieldSets[field.name] = fieldset;
} else {
fieldSets[field.name] = { field, value: foundry.utils.getProperty(source, path) };
}
}
return fieldSets;
}
/* -------------------------------------------------- */
/**
* Recursively add system model fields to the fieldset.
*/
async #addSystemFields(fieldset, schema, source, _path = "system") {
for (const field of Object.values(schema)) {
const path = `${_path}.${field.name}`;
if (field instanceof foundry.data.fields.SchemaField) {
this.#addSystemFields(fieldset, field.fields, source, path);
} else if (field.constructor.hasFormSupport) {
fieldset.fields[field.name] = { field, value: foundry.utils.getProperty(source, path) };
}
}
}
}