From aef48dd46beda4e8d36440da669b8e55451bb8a2 Mon Sep 17 00:00:00 2001 From: Ender Date: Tue, 14 May 2024 13:33:53 +0200 Subject: [PATCH] Subject: Enhance combat mechanics and localization - Introduced new combat-related properties (initiative, group, unable to act) to characters for an enriched gaming experience. - Added German translations for newly introduced terms to ensure consistency within the game's interface. - Capitalized the German translation for "magic" to align with existing convention. - Refactored settings management in player and NPC sheets for better clarity and maintenance. - Implemented logic for handling characters' inability to act in combat, including UI elements for managing this state, thereby increasing gameplay depth. - Adjusted display and management of items and effects to accommodate new combat features, streamlining user interaction and integration with the combat system. - Minor UI and styling adjustments to enhance readability and user experience across character and item sheets. These changes aim to make combat encounters more dynamic and engaging, while also improving the user interface for ease of interaction and consistency. --- lang/de.json | 7 +++- source/combat.ts | 0 source/module/M5Base.ts | 8 +++++ source/module/actors/M5Character.ts | 47 ++++++++++++++++++++++++++ source/style/Character-sheet.less | 1 + source/template.json | 14 +++++--- templates/sheets/character/combat.hbs | 46 +++++++++++++++++++++++++ templates/sheets/character/effects.hbs | 2 +- templates/sheets/character/gear.hbs | 12 +++---- templates/sheets/item/effect.hbs | 5 +++ 10 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 source/combat.ts diff --git a/lang/de.json b/lang/de.json index 21443eb..1087cd0 100644 --- a/lang/de.json +++ b/lang/de.json @@ -20,6 +20,11 @@ "no-encounter": "Kein Kampf", "encounter-not-started": "Kein aktiver Kampf", "initiative": "Initiative", + "initiativeRoll": "Initiative würfeln", + "unableToAct": "Handlungsunfähig", + "unablesToAct": "Macht handlungsunfähig", + "group": "Gruppe", + "leader": "Anführer", "actionrank": "Handlungsrang", "combat-join": "Kampf Beitreten/Handlungsrang zurücksetzen", @@ -276,7 +281,7 @@ "defensive-weapon": "Verteidigungswaffe", "defensive-weapons": "Verteidigungswaffen", "no-skill": "Keine Fertigkeit", - "magic": "magisch", + "magic": "Magisch", "valuable": "Vermögen", "equipped": "Ausgerüstet", "active": "Aktiv", diff --git a/source/combat.ts b/source/combat.ts new file mode 100644 index 0000000..e69de29 diff --git a/source/module/M5Base.ts b/source/module/M5Base.ts index fdc1b26..385d793 100644 --- a/source/module/M5Base.ts +++ b/source/module/M5Base.ts @@ -162,6 +162,14 @@ export interface M5AttributeCalculated extends M5ModResult { export interface M5CharacterCalculatedData { level: number; + initiative: number; + unableToAct: { + effectId: string; + enabled: boolean; + rounds: number; + reason: string; + }; + group: string; movement: number; attributes: { st: M5AttributeCalculated; diff --git a/source/module/actors/M5Character.ts b/source/module/actors/M5Character.ts index 5f42cdc..afc7df0 100644 --- a/source/module/actors/M5Character.ts +++ b/source/module/actors/M5Character.ts @@ -1,3 +1,4 @@ +import { log } from "console"; import { M5Item } from "../items/M5Item"; import { M5Attribute, M5CharacterCalculatedData, M5ItemMod, M5ItemType, M5ModOperation, M5ModResult, M5RollData, M5Skill, M5SkillCalculated } from "../M5Base"; import M5ModAggregate from "./M5ModAggregate"; @@ -86,6 +87,7 @@ export class M5Character extends Actor { ): M5CharacterCalculatedData { let ret: M5CharacterCalculatedData = { level: 0, + initiative: 0, attributes: { st: { value: 0, bonus: 0, mods: [] }, gs: { value: 0, bonus: 0, mods: [] }, @@ -151,6 +153,9 @@ export class M5Character extends Actor { if (!data) return null; ret.level = M5Character.levelFromExp(data.info.race === "Zwerg" ? Math.min(data.calc.stats?.hoard * 2 || 0, data.es) : data.es); + ret.initiative = M5Character.initiativeFromAnfuehren(data.calc.skills?.general, (game as Game).i18n.localize("midgard5.anfuehren"), data.skills.general.anfuehren.fw); + ret.unableToAct = M5Character.unableToActFromEffect(data.calc.gear?.effects); + ret.group = M5Character.groupFromDisposition(this); ret.attributes.st.value = M5Character.attributeMinMax(data.attributes.st); // TODO item effects ret.attributes.gs.value = M5Character.attributeMinMax(data.attributes.gs); @@ -494,6 +499,7 @@ export class M5Character extends Actor { magic: item.system.magic, calc: item.system.calc, equipped: item.system?.equipped || false, + unablesToAct: item.system?.unablesToAct || false, duration: item.system?.duration || { time: 0, unit: "" }, }; }); @@ -604,6 +610,47 @@ export class M5Character extends Actor { return ret === -1 ? M5Character.levelThreshold.length : ret; } + static initiativeFromAnfuehren(list: object, anfuehren: string, unlearned: number): number { + for (const element in list) { + if (list[element].label.toLowerCase() === anfuehren.toLowerCase()) { + return list[element].calc.ew; + } + } + return unlearned; + } + + static unableToActFromEffect(list: object): { effectId: string; enabled: boolean; rounds: number; reason: string } { + console.log("Effects:", list); + for (const element in list) { + if (list[element].unablesToAct) { + return { + effectId: list[element], + enabled: list[element].equipped, + rounds: list[element].duration.time, + reason: list[element].label, + }; + } + } + return { effectId: "", enabled: false, rounds: 0, reason: "" }; + } + + static groupFromDisposition(actor: any): string { + console.log("Group:", actor); + let disposition:number = 0; + if (actor.isToken) { + disposition = actor.token.disposition; + } else { + disposition = actor.prototypeToken.disposition; + } + switch ( disposition ) { + case 1: return "Spieler"; + case -1: return "Gegner"; + case 0: return "Gegner 2"; + case 2: return "Gegner 3"; + default: return "Unbekannt"; + } + } + static readonly defenseThreshold: Array<[number, number]> = [ [30, 18], [25, 17], diff --git a/source/style/Character-sheet.less b/source/style/Character-sheet.less index e8ebd2c..8e0c3b3 100644 --- a/source/style/Character-sheet.less +++ b/source/style/Character-sheet.less @@ -64,6 +64,7 @@ .flexrow { align-items: center; + flex-direction: row; } h3 { diff --git a/source/template.json b/source/template.json index b337148..9926610 100644 --- a/source/template.json +++ b/source/template.json @@ -23,13 +23,16 @@ "origin": "", "faith": "", "level": 1, + "leader": false, "gold": 0, "silver": 0, - "copper": 0, - "showAllItems": false, - "showUnlearned": false + "copper": 0 } }, + "settings": { + "showAllItems": false, + "showUnlearned": false + }, "characterBars": { "lp": { "value": 15, @@ -163,11 +166,11 @@ } }, "character": { - "templates": ["characterBars", "attributes", "characterDescription", "characterHeader", "skills", "gear"], + "templates": ["characterBars", "settings", "attributes", "characterDescription", "characterHeader", "skills", "gear"], "calc": {} }, "npc": { - "templates": ["characterBars", "attributes", "characterDescription", "skills", "gear"], + "templates": ["characterBars", "settings", "attributes", "characterDescription", "skills", "gear"], "calc": {} } }, @@ -374,6 +377,7 @@ }, "effect": { "templates": ["itemDescription", "equippable", "physical", "durationSelection"], + "unablesToAct": false, "rolls": { "formulas": {}, "output": "" diff --git a/templates/sheets/character/combat.hbs b/templates/sheets/character/combat.hbs index bd11d3c..bb2fa21 100644 --- a/templates/sheets/character/combat.hbs +++ b/templates/sheets/character/combat.hbs @@ -1,4 +1,50 @@
+ +
+
+
{{localize "midgard5.initiative"}}: {{data.calc.initiative}}
+
+
+
{{localize "midgard5.group"}}:
+
{{data.calc.group}}
+
+ {{#if data.calc.unableToAct.enabled}} +
+
{{localize "midgard5.unableToAct"}}
+
+
+
+
+     +
{{localize "midgard5.time-round"}}
+
+
+ {{/if}} + {{#unless data.calc.unableToAct.enabled}} +
+
{{localize "midgard5.leader"}}
+
+
+ {{#if data.info.leader}} +
+ +
+ {{/if}} + {{/unless}} +
+
+ +
+
+
{{localize "midgard5.movementPhase"}}
+
+
+ +
+
+
{{localize "midgard5.actionPhase"}}
+
+
diff --git a/templates/sheets/character/effects.hbs b/templates/sheets/character/effects.hbs index 1d06a1b..ebfed31 100644 --- a/templates/sheets/character/effects.hbs +++ b/templates/sheets/character/effects.hbs @@ -3,7 +3,7 @@ {{localize "TYPES.Item.effect"}} - + diff --git a/templates/sheets/character/gear.hbs b/templates/sheets/character/gear.hbs index ec53822..3b7a6d0 100644 --- a/templates/sheets/character/gear.hbs +++ b/templates/sheets/character/gear.hbs @@ -217,8 +217,8 @@

{{localize "midgard5.allItems"}} - - + +

@@ -295,7 +295,7 @@ {{#each data.calc.gear.items as |item itemId|}} - {{#if (or ../data.info.showAllItems (eq item.containerId ""))}} + {{#if (or ../data.settings.showAllItems (eq item.containerId ""))}} @@ -351,7 +351,7 @@ {{#each data.calc.gear.weapons as |item itemId|}} - {{#if (or ../data.info.showAllItems (eq item.containerId ""))}} + {{#if (or ../data.settings.showAllItems (eq item.containerId ""))}} {{item.label}} @@ -397,7 +397,7 @@ {{#each data.calc.gear.defensiveWeapons as |item itemId|}} - {{#if (or ../data.info.showAllItems (eq item.containerId ""))}} + {{#if (or ../data.settings.showAllItems (eq item.containerId ""))}} {{item.label}} @@ -443,7 +443,7 @@ {{#each data.calc.gear.armor as |item itemId|}} - {{#if (or ../data.info.showAllItems (eq item.containerId ""))}} + {{#if (or ../data.settings.showAllItems (eq item.containerId ""))}} {{item.label}} diff --git a/templates/sheets/item/effect.hbs b/templates/sheets/item/effect.hbs index 6c3dd17..42940e2 100644 --- a/templates/sheets/item/effect.hbs +++ b/templates/sheets/item/effect.hbs @@ -16,6 +16,11 @@ + + + + +