Skip to content

Commit 6a5bcb9

Browse files
committed
test: cover partial use-to-item quickslots
1 parent 847c5d0 commit 6a5bcb9

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

internal/minimal/factory_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,6 +3897,57 @@ func TestItemUseToItemQuickslotSyncDeletesConsumedSourceSlot(t *testing.T) {
38973897
}
38983898
}
38993899

3900+
func TestItemUseToItemQuickslotSyncDeletesChangedTargetSlotOnPartialMerge(t *testing.T) {
3901+
persisted := loginticket.Character{
3902+
ID: 0x01030103,
3903+
VID: 0x02040103,
3904+
Name: "PeerThree",
3905+
Inventory: []inventory.ItemInstance{{ID: 21, Vnum: 27001, Count: 7, Slot: 5}, {ID: 22, Vnum: 27001, Count: 8, Slot: 6}},
3906+
Quickslots: []loginticket.Quickslot{
3907+
{Position: 2, Type: quickslotproto.TypeItem, Slot: 5},
3908+
{Position: 7, Type: quickslotproto.TypeItem, Slot: 6},
3909+
{Position: 8, Type: quickslotproto.TypeItem, Slot: 6},
3910+
{Position: 9, Type: quickslotproto.TypeSkill, Slot: 6},
3911+
},
3912+
}
3913+
selectedPlayer := player.NewRuntime(persisted, player.SessionLink{Login: "peer-three", CharacterIndex: 1})
3914+
mergeResult := inventory.MoveResult{
3915+
Changed: true,
3916+
From: 5,
3917+
To: 6,
3918+
FromOccupied: true,
3919+
FromItem: inventory.ItemInstance{ID: 21, Vnum: 27001, Count: 5, Slot: 5},
3920+
ToOccupied: true,
3921+
ToItem: inventory.ItemInstance{ID: 22, Vnum: 27001, Count: 10, Slot: 6},
3922+
CountOnly: true,
3923+
}
3924+
3925+
frames, ok := itemUseToItemQuickslotSyncFrames(selectedPlayer, mergeResult)
3926+
if !ok {
3927+
t.Fatal("expected partial use-to-item quickslot sync to succeed")
3928+
}
3929+
if len(frames) != 2 {
3930+
t.Fatalf("expected two quickslot deletes for changed target stack, got %d", len(frames))
3931+
}
3932+
for index, raw := range frames {
3933+
deleted, err := quickslotproto.DecodeDel(decodeSingleFrame(t, raw))
3934+
if err != nil {
3935+
t.Fatalf("decode quickslot delete %d: %v", index, err)
3936+
}
3937+
wantPosition := []uint8{7, 8}[index]
3938+
if deleted.Position != wantPosition {
3939+
t.Fatalf("expected target item quickslot position %d to be deleted at index %d, got %d", wantPosition, index, deleted.Position)
3940+
}
3941+
}
3942+
wantLiveQuickslots := []loginticket.Quickslot{
3943+
{Position: 2, Type: quickslotproto.TypeItem, Slot: 5},
3944+
{Position: 9, Type: quickslotproto.TypeSkill, Slot: 6},
3945+
}
3946+
if got := selectedPlayer.LiveQuickslots(); !reflect.DeepEqual(got, wantLiveQuickslots) {
3947+
t.Fatalf("unexpected live quickslots after partial use-to-item merge: got %#v want %#v", got, wantLiveQuickslots)
3948+
}
3949+
}
3950+
39003951
func decodeSingleFrame(t *testing.T, raw []byte) frame.Frame {
39013952
t.Helper()
39023953

0 commit comments

Comments
 (0)