mirror of
https://github.com/motajs/template.git
synced 2026-09-25 20:10:17 +08:00
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
This commit is contained in:
parent
04943416a5
commit
2452711edb
@ -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]]));
|
||||
|
||||
@ -138,7 +138,7 @@ export class HeroEquipment<THero> implements IHeroEquipment<THero> {
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user