Skip to content

Commit e87aba6

Browse files
committed
test: cover use-to-item zero-count target rejection
1 parent 819b3d5 commit e87aba6

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

internal/player/runtime_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,32 @@ func TestRuntimeDropInventoryItemRejectsDuplicateSlotOccupancyWithoutMutation(t
746746
}
747747
}
748748

749+
func TestRuntimeUseItemOnItemRejectsZeroCountTargetWithoutMutation(t *testing.T) {
750+
persisted := loginticket.Character{
751+
ID: 0x01030102,
752+
VID: 0x02040102,
753+
Name: "ZeroTargetPeer",
754+
Inventory: []inventory.ItemInstance{
755+
{ID: 11, Vnum: 27001, Count: 3, Slot: 5},
756+
{ID: 12, Vnum: 27001, Count: 0, Slot: 8},
757+
},
758+
Quickslots: []loginticket.Quickslot{{Position: 2, Type: quickslotproto.TypeItem, Slot: 8}},
759+
}
760+
runtime := NewRuntime(persisted, SessionLink{Login: "zero-target-peer", CharacterIndex: 1})
761+
before := runtime.LiveCharacter()
762+
template := itemcatalog.Template{Vnum: 27001, Name: "Small Red Potion", Stackable: true, MaxCount: 200}
763+
764+
if result, ok := runtime.UseItemOnItem(5, 8, template); ok {
765+
t.Fatalf("expected zero-count target use-to-item to fail closed, got %+v", result)
766+
}
767+
if got := runtime.LiveCharacter(); !reflect.DeepEqual(got, before) {
768+
t.Fatalf("zero-count target use-to-item mutated live character: got %#v want %#v", got, before)
769+
}
770+
if got := runtime.PersistedSnapshot(); !reflect.DeepEqual(got.Inventory, persisted.Inventory) || !reflect.DeepEqual(got.Quickslots, persisted.Quickslots) {
771+
t.Fatalf("zero-count target use-to-item mutated persisted state: inventory=%#v quickslots=%#v", got.Inventory, got.Quickslots)
772+
}
773+
}
774+
749775
func TestRuntimeUseItemOnItemRejectsAuthoredJobSexAndLevelRestrictionsWithoutMutation(t *testing.T) {
750776
cases := []struct {
751777
name string

0 commit comments

Comments
 (0)