fix(game): grantXp event fires only on level transition, not while at-band (#45)
CI / build + unit + e2e (pull_request) Successful in 3m8s
CI / build + unit + e2e (pull_request) Successful in 3m8s
This commit is contained in:
@@ -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)', () => {
|
||||
|
||||
+2
-1
@@ -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}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user