From 9d1a8e9d89403cbf4b71d4cf26d33965e13fa887 Mon Sep 17 00:00:00 2001 From: Kamil Krzywda Date: Sun, 4 Oct 2026 02:50:47 +0000 Subject: [PATCH] fix(game): grantXp event fires only on level transition, not while at-band (#45) --- lib/game/skills.test.ts | 6 ++++++ lib/game/skills.ts | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/game/skills.test.ts b/lib/game/skills.test.ts index 4c11604..575f38c 100644 --- a/lib/game/skills.test.ts +++ b/lib/game/skills.test.ts @@ -35,6 +35,12 @@ describe('grantXp — +1 XP to every listed member; event only on a titled-band const { events } = grantXp([row('c1', 'NAVIGATION', 4, 24), row('c1', 'SCANNING', 0, 0)], ['c1'], 'NAVIGATION', { c1: pilot }) expect(events).toEqual(['BEN OKONKWO is now a MASTER PILOT — NAVIGATION L5']) }) + it('no event when a member is already at the titled level (stays at L3 after gaining xp)', () => { + // Member at SCANNING L3 (xp 16) gains 1 → xp 17, still L3 → NO event + const rows = [row('c1', 'SCANNING', 3, 16), row('c1', 'NAVIGATION', 0, 0)] + const { events } = grantXp(rows, ['c1'], 'SCANNING', { c1: { name: 'X', role: 'SCIENTIST' } }) + expect(events).toHaveLength(0) + }) }) describe('titleFor — from the member\'s HIGHEST skill level', () => { it('SCIENTIST with SCANNING L3 + RESEARCH L5 → MASTER SCIENTIST (highest wins)', () => { diff --git a/lib/game/skills.ts b/lib/game/skills.ts index 941d478..ff82b42 100644 --- a/lib/game/skills.ts +++ b/lib/game/skills.ts @@ -45,8 +45,9 @@ export function grantXp( for (const crewId of crewIds) { const member = members[crewId] if (!member) continue + const oldLevel = skillRows.find((r) => r.crewId === crewId && r.skill === skill)?.level ?? 0 const newLevel = rows.find((r) => r.crewId === crewId && r.skill === skill)?.level ?? 0 - if (newLevel === 3 || newLevel === 5) { + if (newLevel > oldLevel && (newLevel === 3 || newLevel === 5)) { const title = titleFor(member, rows.filter((r) => r.crewId === crewId)) if (title) events.push(`${member.name} is now a ${title} — ${skill} L${newLevel}`) }