From 2452711edb5bf7b06944bdcd800aac96240bc2cb Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Tue, 15 Sep 2026 20:30:32 +0800 Subject: [PATCH] fix(07-04): #06-05-2 prefer the first empty named slot - getCouldEquipSlot tests empty === -1 so the first empty named slot wins instead of always replacing the first match - un-skip the named-slot empty-preference case; canEquipTo string branch untouched --- packages-user/data-base/src/hero/equipment.test.ts | 4 ++-- packages-user/data-base/src/hero/equipment.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages-user/data-base/src/hero/equipment.test.ts b/packages-user/data-base/src/hero/equipment.test.ts index 66ec220..cb76bef 100644 --- a/packages-user/data-base/src/hero/equipment.test.ts +++ b/packages-user/data-base/src/hero/equipment.test.ts @@ -286,8 +286,8 @@ describe('HeroEquipment equip and unequip', () => { expect(equips[1]).toBeNull(); }); - // 疑似 bug:字符串槽位空槽判断条件写反导致总是替换首个匹配槽位,详见 06-TEST-FINDINGS.md #06-05-2 - it.skip('uses the first empty named slot instead of replacing an occupant', () => { + // 验证字符串槽位优先占用首个空槽而非替换占用者(#06-05-2) + it('uses the first empty named slot instead of replacing an occupant', () => { const env = createEnv(); registerItem(env, createItem(10, 'sword', ['weapon'], [['atk', 5]])); registerItem(env, createItem(11, 'axe', ['weapon'], [['atk', 12]])); diff --git a/packages-user/data-base/src/hero/equipment.ts b/packages-user/data-base/src/hero/equipment.ts index f776b66..376eeeb 100644 --- a/packages-user/data-base/src/hero/equipment.ts +++ b/packages-user/data-base/src/hero/equipment.ts @@ -138,7 +138,7 @@ export class HeroEquipment implements IHeroEquipment { this.slots.forEach((name, index) => { if (name !== slot) return; if (first === -1) first = index; - if (empty !== -1 && !this.equips.has(index)) { + if (empty === -1 && !this.equips.has(index)) { empty = index; } });