@@ -449,6 +449,39 @@ func TestRuntimeItemUseConsumesBootstrapConsumableWithoutMutatingPersistedPoints
449449 }
450450}
451451
452+ func TestRuntimeItemUseRejectsVnumMismatchedTemplateWithoutMutation (t * testing.T ) {
453+ persisted := loginticket.Character {
454+ ID : 0x01030103 ,
455+ VID : 0x02040103 ,
456+ Name : "PeerTwo" ,
457+ Points : [255 ]int32 {1 : 700 },
458+ Inventory : []inventory.ItemInstance {
459+ {ID : 11 , Vnum : 27001 , Count : 3 , Slot : 5 },
460+ {ID : 12 , Vnum : 27001 , Count : 2 , Slot : 6 },
461+ },
462+ }
463+ runtime := NewRuntime (persisted , SessionLink {Login : "peer-two" , CharacterIndex : 1 })
464+
465+ result , ok := runtime .UseItem (5 , bootstrapConsumableTemplate (27002 , 1 , 1 , 50 , "consume:27002:+50" ))
466+ if ok {
467+ t .Fatalf ("expected vnum-mismatched item use to fail, got result %+v" , result )
468+ }
469+ move , ok := runtime .UseItemOnItem (5 , 6 , bootstrapConsumableTemplate (27002 , 1 , 1 , 50 , "consume:27002:+50" ))
470+ if ok {
471+ t .Fatalf ("expected vnum-mismatched item-use-to-item to fail, got result %+v" , move )
472+ }
473+ live := runtime .LiveCharacter ()
474+ if live .Points [1 ] != persisted .Points [1 ] {
475+ t .Fatalf ("vnum-mismatched item use mutated points: got %d want %d" , live .Points [1 ], persisted .Points [1 ])
476+ }
477+ if ! reflect .DeepEqual (live .Inventory , persisted .Inventory ) {
478+ t .Fatalf ("vnum-mismatched item use mutated live inventory: got %#v want %#v" , live .Inventory , persisted .Inventory )
479+ }
480+ if ! reflect .DeepEqual (runtime .PersistedSnapshot ().Inventory , persisted .Inventory ) {
481+ t .Fatalf ("vnum-mismatched item use mutated persisted inventory: got %#v want %#v" , runtime .PersistedSnapshot ().Inventory , persisted .Inventory )
482+ }
483+ }
484+
452485func TestRuntimeItemUseRemovesTheLastConsumableStack (t * testing.T ) {
453486 persisted := loginticket.Character {
454487 ID : 0x01030102 ,
0 commit comments