From 65fcebdbdbdc3d857b7dc2e08d179b097f59f3e7 Mon Sep 17 00:00:00 2001 From: Alexander Zielonka Date: Mon, 27 Apr 2026 14:30:02 +0200 Subject: [PATCH] feat(01-01): implement applyAttributeBoost and isValidBoostSet pure functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - applyAttributeBoost: PF2e boost-cap-at-18 rule (Pitfall #8 mitigation) - Returns score + 2 when current < 18 - Returns score + 1 when current >= 18 - isValidBoostSet: validates exactly 4 distinct abilities for boost levels - Pure-function module (no NestJS, no Prisma, no I/O imports) - TypeScript strict, named exports only - 9/9 tests pass — proves Jest infrastructure works on src/modules/**/*.spec.ts --- .../leveling/lib/apply-attribute-boost.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 server/src/modules/leveling/lib/apply-attribute-boost.ts diff --git a/server/src/modules/leveling/lib/apply-attribute-boost.ts b/server/src/modules/leveling/lib/apply-attribute-boost.ts new file mode 100644 index 0000000..d5a586b --- /dev/null +++ b/server/src/modules/leveling/lib/apply-attribute-boost.ts @@ -0,0 +1,26 @@ +/** + * Pure function module — no NestJS, no Prisma, no I/O. + * PF2e Boost Cap rule: +2 if score < 18, +1 if score >= 18 (Pitfall #8). + * See: .planning/phases/01-level-up-pf2e-regelkonform/01-RESEARCH.md §Pattern 3 + */ + +export type AbilityScore = number; + +export type AbilityAbbreviation = 'STR' | 'DEX' | 'CON' | 'INT' | 'WIS' | 'CHA'; + +/** + * Applies a single PF2e attribute boost to a score. + * - Score below 18 → +2 + * - Score at or above 18 → +1 (cap rule, prevents Pitfall #8) + */ +export function applyAttributeBoost(currentScore: AbilityScore): AbilityScore { + return currentScore >= 18 ? currentScore + 1 : currentScore + 2; +} + +/** + * Validates a level-up boost set: must be exactly 4 distinct abilities. + * PF2e: at boost levels (5/10/15/20), the player picks 4 different attributes. + */ +export function isValidBoostSet(targets: readonly string[]): boolean { + return targets.length === 4 && new Set(targets).size === 4; +}