From 34e8998305ca184a42e357d13387048c792b1aa7 Mon Sep 17 00:00:00 2001 From: Byroks Date: Sat, 23 Mar 2024 20:08:30 +0100 Subject: [PATCH 1/2] #91 Automatische Praxispunkte MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: + implementation von Automatischen Praxispunkten + Hinzufügen von System Settings zur abschaltung von Automatischen Praxispunkten + Aufräumen von Helpers und settings in eigene Dateien --- lang/de.json | 3 +- source/helpers.ts | 110 ++++++++++++++++++++++++++++++++ source/index.ts | 107 ++----------------------------- source/module/M5Base.ts | 2 +- source/module/items/M5Item.ts | 2 +- source/module/rolls/M5Roll.ts | 38 ++++++++++- source/settings.ts | 16 +++++ templates/sheets/item/class.hbs | 2 +- 8 files changed, 175 insertions(+), 105 deletions(-) create mode 100644 source/helpers.ts create mode 100644 source/settings.ts diff --git a/lang/de.json b/lang/de.json index 4ed4493..35393b2 100644 --- a/lang/de.json +++ b/lang/de.json @@ -295,10 +295,11 @@ "midgard5.spell-process-nekromantie": "Nekromantie", "midgard5.spell-process-runenstaebe": "Runenstäbe", "midgard5.spell-process-thaumatherapie": "Thaumatherapie", + "midgard5.spell-process-thaumagraphie": "Thaumagraphie", "midgard5.spell-process-veraendern": "Verändern", "midgard5.spell-process-vigilsignien": "Vigilsignien", "midgard5.spell-process-wundertat": "Wundertat", - "midgard5.spell-process-wilder_Dweomer": "Wilder Dweomer", + "midgard5.spell-process-wilder_dweomer": "Wilder Dweomer", "midgard5.spell-process-zerstoeren": "Zerstören", "midgard5.spell-process-zauberlied": "Zauberlieder", "midgard5.spell-process-zaubersalz": "Zaubersalze", diff --git a/source/helpers.ts b/source/helpers.ts new file mode 100644 index 0000000..f0c0572 --- /dev/null +++ b/source/helpers.ts @@ -0,0 +1,110 @@ +/* global Handlebars, game, TextEditor, WOD5E */ + +import { M5Skill } from "./module/M5Base"; +import { M5Character } from "./module/actors/M5Character"; + +/** + * Define any helpers necessary for working with Handlebars + * @return {Promise} + */ +export const loadHelpers = async function () { + Handlebars.registerHelper("times", (n: number, block) => { + var accum = ""; + for (let i = 0; i < n; ++i) accum += block.fn(i); + return accum; + }); + + Handlebars.registerHelper("array", (arr: any[], index: number) => { + return arr[index]; + }); + + Handlebars.registerHelper("m5concat", (...values) => { + const options = values.pop(); + const join = options.hash?.join || ""; + //return new Handlebars.SafeString(values.join(join)); + return values.map((val) => val.toString()).join(join); + }); + + Handlebars.registerHelper("add", (...values) => { + const options = values.pop(); + return values.reduce((prev, cur) => prev + cur); + }); + + Handlebars.registerHelper("localizeMidgard", (str: string) => { + const template = Handlebars.compile("{{localize value}}"); + return template({ + value: "midgard5." + str, + }); + }); + + Handlebars.registerHelper("skillBonus", (actorId: string, skill: M5Skill) => { + const actor = (game as Game).actors.get(actorId) as M5Character; + return actor.skillBonus(skill).toString(); + }); + + Handlebars.registerHelper("skillEw", (actorId: string, skill: M5Skill) => { + const actor = (game as Game).actors.get(actorId) as M5Character; + return actor.skillEw(skill).toString(); + }); + + Handlebars.registerHelper("skill", (skillId: string) => { + return (game as Game).items.get(skillId); + }); + + Handlebars.registerHelper("itemValue", (id: string, path: string) => { + let obj = (game as Game).items.get(id); + path.split(".").forEach((p) => (obj = obj[p])); + return `${obj}`; + }); + + Handlebars.registerHelper("actorItemValue", (actorId: any, itemId: string, path: string, token?: boolean) => { + //console.log("actorItemValue", actorId, itemId, path) + const actor = (game as Game).actors.get(actorId); + let obj = actor.items.get(itemId)?.system; + path.split(".").forEach((p) => { + if (obj) obj = obj[p]; + }); + return `${obj}`; + }); + + Handlebars.registerHelper("icon", (relpath: string) => { + return `systems/midgard5/assets/icons/${relpath}`; + }); + + Handlebars.registerHelper("isSkillInList", (skillName: string, list: any) => { + for (let key in list) { + if (list[key]?.label?.toLowerCase() === skillName?.toLowerCase()) { + return true; + } + } + return false; + }); + + Handlebars.registerHelper("skillEwInList", (skillName: string, list: any) => { + for (let key in list) { + if (list[key]?.label?.toLowerCase() === skillName?.toLowerCase()) { + return list[key].calc.ew; + } + } + return false; + }); + + Handlebars.registerHelper("stripHtml", function (param) { + var regex = /(<([^>]+)>)/gi; + return param.replace(regex, ""); + }); + + Handlebars.registerHelper("contains", (label: string, contains: string) => { + return label.toLowerCase().includes(contains.toLowerCase()); + }); + + Handlebars.registerHelper("count", (object: any) => { + var length = 0; + for (var key in object) { + if (object.hasOwnProperty(key)) { + ++length; + } + } + return length; + }); +}; diff --git a/source/index.ts b/source/index.ts index 49f7311..2d4de52 100644 --- a/source/index.ts +++ b/source/index.ts @@ -2,112 +2,17 @@ import Logger from "./utils/Logger"; import M5CharacterSheet from "./module/sheets/M5CharacterSheet"; import preloadTemplates from "./PreloadTemplates"; import { M5Character } from "./module/actors/M5Character"; -import { M5ItemMod, M5ModOperation, M5Skill, M5TimeUnit } from "./module/M5Base"; +import { M5ModOperation, M5TimeUnit } from "./module/M5Base"; import { M5ItemSheet } from "./module/sheets/M5ItemSheet"; import { M5Item } from "./module/items/M5Item"; +import { loadHelpers } from "./helpers"; +import { loadSettings } from "./settings"; Hooks.once("init", async () => { Logger.log("M5 | Initialisierung Midgard 5"); - Handlebars.registerHelper("times", (n: number, block) => { - var accum = ""; - for (let i = 0; i < n; ++i) accum += block.fn(i); - return accum; - }); - - Handlebars.registerHelper("array", (arr: any[], index: number) => { - return arr[index]; - }); - - Handlebars.registerHelper("m5concat", (...values) => { - const options = values.pop(); - const join = options.hash?.join || ""; - //return new Handlebars.SafeString(values.join(join)); - return values.map((val) => val.toString()).join(join); - }); - - Handlebars.registerHelper("add", (...values) => { - const options = values.pop(); - return values.reduce((prev, cur) => prev + cur); - }); - - Handlebars.registerHelper("localizeMidgard", (str: string) => { - const template = Handlebars.compile("{{localize value}}"); - return template({ - value: "midgard5." + str, - }); - }); - - Handlebars.registerHelper("skillBonus", (actorId: string, skill: M5Skill) => { - const actor = (game as Game).actors.get(actorId) as M5Character; - return actor.skillBonus(skill).toString(); - }); - - Handlebars.registerHelper("skillEw", (actorId: string, skill: M5Skill) => { - const actor = (game as Game).actors.get(actorId) as M5Character; - return actor.skillEw(skill).toString(); - }); - - Handlebars.registerHelper("skill", (skillId: string) => { - return (game as Game).items.get(skillId); - }); - - Handlebars.registerHelper("itemValue", (id: string, path: string) => { - let obj = (game as Game).items.get(id); - path.split(".").forEach((p) => (obj = obj[p])); - return `${obj}`; - }); - - Handlebars.registerHelper("actorItemValue", (actorId: any, itemId: string, path: string, token?: boolean) => { - //console.log("actorItemValue", actorId, itemId, path) - const actor = (game as Game).actors.get(actorId); - let obj = actor.items.get(itemId)?.system; - path.split(".").forEach((p) => { - if (obj) obj = obj[p]; - }); - return `${obj}`; - }); - - Handlebars.registerHelper("icon", (relpath: string) => { - return `systems/midgard5/assets/icons/${relpath}`; - }); - - Handlebars.registerHelper("isSkillInList", (skillName: string, list: any) => { - for (let key in list) { - if (list[key]?.label?.toLowerCase() === skillName?.toLowerCase()) { - return true; - } - } - return false; - }); - - Handlebars.registerHelper("skillEwInList", (skillName: string, list: any) => { - for (let key in list) { - if (list[key]?.label?.toLowerCase() === skillName?.toLowerCase()) { - return list[key].calc.ew; - } - } - return false; - }); - - Handlebars.registerHelper("stripHtml", function (param) { - var regex = /(<([^>]+)>)/gi; - return param.replace(regex, ""); - }); - - Handlebars.registerHelper("contains", (label: string, contains: string) => { - return label.toLowerCase().includes(contains.toLowerCase()); - }); - - Handlebars.registerHelper("count", (object: any) => { - var length = 0; - for (var key in object) { - if (object.hasOwnProperty(key)) { - ++length; - } - } - return length; - }); + // Load settings into Foundry + loadSettings(); // Default Sheet für Items definieren und das Standardsheet deaktivieren Items.unregisterSheet("core", ItemSheet); @@ -121,6 +26,8 @@ Hooks.once("init", async () => { CONFIG.Item.documentClass = M5Item; //RegisterSettings(); await preloadTemplates(); + + loadHelpers(); }); Hooks.once("setup", () => { diff --git a/source/module/M5Base.ts b/source/module/M5Base.ts index 586b84f..004e1f1 100644 --- a/source/module/M5Base.ts +++ b/source/module/M5Base.ts @@ -29,7 +29,7 @@ export interface M5RollData { c: any; i: any; iType: string; - rolls: {}; + rolls: any; res: { label: string; }; diff --git a/source/module/items/M5Item.ts b/source/module/items/M5Item.ts index c4eb60c..72845cc 100644 --- a/source/module/items/M5Item.ts +++ b/source/module/items/M5Item.ts @@ -323,7 +323,7 @@ export class M5Item extends Item { } } - const roll = new M5Roll(rollData, this.actor, item.name); + const roll = new M5Roll(rollData, this.actor, item.name, item.id); return roll.toMessage(); } else { ChatMessage.create({ diff --git a/source/module/rolls/M5Roll.ts b/source/module/rolls/M5Roll.ts index 9a5f316..62e95e5 100644 --- a/source/module/rolls/M5Roll.ts +++ b/source/module/rolls/M5Roll.ts @@ -11,7 +11,7 @@ export class M5Roll { public _total: number = 0; public pool: PoolTerm = null; - constructor(public data: M5RollData, public actor: any, public label: string) { + constructor(public data: M5RollData, public actor: any, public label: string, public id?: string) { //super(null) //this.data = rollData } @@ -88,6 +88,42 @@ export class M5Roll { }); this.data.res.label = this.label; + if ((game as Game).settings.get("midgard5", "automatedPP")) { + if ((this.data.i.type === "language" || this.data.i.type === "general") && this.data.rolls[0].dice[0] >= 0) { + this.actor.items.get(this.id).update({ + system: { + pp: this.data.i.pp + 1, + }, + }); + } else if (this.data.rolls[0].dice[0] === 20) { + if (this.data.i.type === "combat") { + // Rolling through skill + this.actor.items.get(this.id).update({ + system: { + pp: this.data.i.pp + 1, + }, + }); + } else if (this.data.iType === "weapon") { + // Rolling through Weapon Item + const skill = this.actor.items.get(this.data.i.skillId); + skill.update({ + system: { + pp: skill.system.pp + 1, + }, + }); + } else if (this.data.iType === "spell") { + // Rolling through Spell Item + const klasse = this.actor.items.find((x) => x.type === "class" && x.system.equipped); + klasse.update({ + system: { + lernKostenZauber: { + [this.data.i.process]: { pp: klasse.system.lernKostenZauber[this.data.i.process].pp + 1 }, + }, + }, + }); + } + } + } this._evaluated = true; return this; diff --git a/source/settings.ts b/source/settings.ts new file mode 100644 index 0000000..d9ba705 --- /dev/null +++ b/source/settings.ts @@ -0,0 +1,16 @@ +/* global game */ + +/** + * Define all game settings here + * @return {Promise} + */ +export const loadSettings = async function () { + (game as Game).settings.register("midgard5", "automatedPP", { + name: "Automatische Praxispunkte", + hint: "Falls aktiv, werden Praxispunkte automatisch angerechnet.", + scope: "world", + config: true, + default: true, + type: Boolean, + }); +}; diff --git a/templates/sheets/item/class.hbs b/templates/sheets/item/class.hbs index e12e040..6e657c0 100644 --- a/templates/sheets/item/class.hbs +++ b/templates/sheets/item/class.hbs @@ -89,7 +89,7 @@ {{#each data.lernKostenZauber as |wert name|}} - + {{/each}} -- 2.40.1 From e59352cc3fecb78d89bfcd9fa13b3bf47dfa1ed0 Mon Sep 17 00:00:00 2001 From: LeFrique Date: Sun, 24 Mar 2024 15:01:07 +0100 Subject: [PATCH 2/2] Fix & Bonus + Fixed wrong calculation for PP + Added defensiveWeapon for PP + Added Musizieren skills as on KOD S. 118 - Deleted thaumagraphie as spellprocess in de.json because its a skill --- lang/de.json | 7 +++++-- source/module/rolls/M5Roll.ts | 10 +++++++++- source/template.json | 6 +++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lang/de.json b/lang/de.json index 35393b2..d6aff9d 100644 --- a/lang/de.json +++ b/lang/de.json @@ -181,7 +181,11 @@ "midgard5.meditieren": "Meditieren", "midgard5.menschenkenntnis": "Menschenkenntnis", "midgard5.meucheln": "Meucheln", - "midgard5.musizieren": "Musizieren", + "midgard5.musizierenFloete": "Musizieren (Flöten)", + "midgard5.musizierenBlas": "Musizieren (Blasinstrumente)", + "midgard5.musizierenRythmus": "Musizieren (Rythmusinstrumente)", + "midgard5.musizierenStreich": "Musizieren (Streichinstrumente)", + "midgard5.musizierenZupf": "Musizieren (Zupfinstrumente)", "midgard5.naturkunde": "Naturkunde", "midgard5.ninjutsu": "NinJutsu", "midgard5.orakelkunst": "Orakelkunst", @@ -295,7 +299,6 @@ "midgard5.spell-process-nekromantie": "Nekromantie", "midgard5.spell-process-runenstaebe": "Runenstäbe", "midgard5.spell-process-thaumatherapie": "Thaumatherapie", - "midgard5.spell-process-thaumagraphie": "Thaumagraphie", "midgard5.spell-process-veraendern": "Verändern", "midgard5.spell-process-vigilsignien": "Vigilsignien", "midgard5.spell-process-wundertat": "Wundertat", diff --git a/source/module/rolls/M5Roll.ts b/source/module/rolls/M5Roll.ts index 62e95e5..2fd137b 100644 --- a/source/module/rolls/M5Roll.ts +++ b/source/module/rolls/M5Roll.ts @@ -89,7 +89,7 @@ export class M5Roll { this.data.res.label = this.label; if ((game as Game).settings.get("midgard5", "automatedPP")) { - if ((this.data.i.type === "language" || this.data.i.type === "general") && this.data.rolls[0].dice[0] >= 0) { + if ((this.data.i.type === "language" || this.data.i.type === "general") && this.data.rolls[0].dice[0] >= 16) { this.actor.items.get(this.id).update({ system: { pp: this.data.i.pp + 1, @@ -111,6 +111,14 @@ export class M5Roll { pp: skill.system.pp + 1, }, }); + } else if (this.data.iType === "defensiveWeapon") { + // Rolling through defensiveWeapon Item + const skill = this.actor.items.get(this.data.i.skillId); + skill.update({ + system: { + pp: skill.system.pp + 1, + }, + }); } else if (this.data.iType === "spell") { // Rolling through Spell Item const klasse = this.actor.items.find((x) => x.type === "class" && x.system.equipped); diff --git a/source/template.json b/source/template.json index 23483b4..de2ef9e 100644 --- a/source/template.json +++ b/source/template.json @@ -101,7 +101,11 @@ "meditieren": { "fw": 0, "attribute": "wk", "initial": 8, "pp": 0 }, "menschenkenntnis": { "fw": 3, "attribute": "in", "initial": 8, "pp": 0 }, "meucheln": { "fw": 0, "attribute": "gs", "initial": 8, "pp": 0 }, - "musizieren": { "fw": 0, "attribute": "gs", "initial": 12, "pp": 0 }, + "musizierenFloete": { "fw": 0, "attribute": "gs", "initial": 12, "pp": 0 }, + "musizierenBlas": { "fw": 0, "attribute": "gs", "initial": 12, "pp": 0 }, + "musizierenRythmus": { "fw": 0, "attribute": "gs", "initial": 12, "pp": 0 }, + "musizierenStreich": { "fw": 0, "attribute": "gs", "initial": 12, "pp": 0 }, + "musizierenZupf": { "fw": 0, "attribute": "gs", "initial": 12, "pp": 0 }, "ninjutsu": { "fw": 0, "attribute": "gw", "initial": 8, "pp": 0 }, "naturkunde": { "fw": 0, "attribute": "in", "initial": 8, "pp": 0 }, "orakelkunst": { "fw": 0, "attribute": "in", "initial": 8, "pp": 0 }, -- 2.40.1