Skip to content

Commit 37ab51b

Browse files
committed
test: cover anti-stack pickup placement
1 parent 046fa21 commit 37ab51b

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

internal/player/runtime_inventory_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,32 @@ func TestPickupGroundItemWithTemplateRejectsAuthoredRestrictionsWithoutMutation(
397397
}
398398
}
399399

400+
func TestPickupGroundItemWithAntiStackTemplateUsesFreshCarriedSlot(t *testing.T) {
401+
runtime := NewRuntime(loginticket.Character{
402+
Inventory: []inventory.ItemInstance{{ID: 41, Vnum: 27001, Count: 198, Slot: 5}},
403+
}, SessionLink{})
404+
template := itemcatalog.Template{Vnum: 27001, Name: "Bound Red Potion", Stackable: true, MaxCount: 200, AntiStack: true}
405+
groundItem := inventory.ItemInstance{ID: 42, Vnum: 27001, Count: 2}
406+
407+
result, ok := runtime.PickupGroundItemWithTemplate(groundItem, 5, template)
408+
if !ok {
409+
t.Fatal("expected anti-stack pickup to use a fresh carried slot instead of merging")
410+
}
411+
if result.Merged || result.Split || result.Updated.ID != 0 || len(result.UpdatedItems) != 0 {
412+
t.Fatalf("expected fresh-slot anti-stack pickup result, got %+v", result)
413+
}
414+
if result.Placed.ID != 42 || result.Placed.Vnum != 27001 || result.Placed.Count != 2 || result.Placed.Slot != 0 {
415+
t.Fatalf("unexpected anti-stack placed item: %+v", result.Placed)
416+
}
417+
wantInventory := []inventory.ItemInstance{
418+
{ID: 42, Vnum: 27001, Count: 2, Slot: 0},
419+
{ID: 41, Vnum: 27001, Count: 198, Slot: 5},
420+
}
421+
if got := runtime.LiveInventory(); !reflect.DeepEqual(got, wantInventory) {
422+
t.Fatalf("anti-stack pickup should not merge with compatible stack: got %#v want %#v", got, wantInventory)
423+
}
424+
}
425+
400426
func TestUseItemOnItemConsolidatesFullSourceAndKeepsTargetQuickslotStable(t *testing.T) {
401427
runtime := NewRuntime(loginticket.Character{
402428
Inventory: []inventory.ItemInstance{

0 commit comments

Comments
 (0)