ShortcutStore lands in AcDream.Core.Net.Items (not AcDream.Core.Items) because it depends on PlayerDescriptionParser.ShortcutEntry; placing it in AcDream.Core would create a circular dependency (Core.Net already references Core). The test lives in AcDream.Core.Tests which gets Core.Net transitively via App. BuildAddShortcut signature corrected from the old (seq, slotIndex, objectType, targetId) 4×u32 layout to the retail ShortCutData wire format confirmed in the action-bar deep-dive: Index(u32), ObjectId(u32), SpellId(u16), Layer(u16). The old BuildAddShortcut_ThreeFields test is replaced by two new tests that verify both item and spell shortcut packing. WorldSession gains SendAddShortcut / SendRemoveShortcut following the SendChangeCombatMode sender pattern. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
116 lines
4.8 KiB
C#
116 lines
4.8 KiB
C#
using System;
|
|
using System.Buffers.Binary;
|
|
using AcDream.Core.Net.Messages;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Net.Tests.Messages;
|
|
|
|
public sealed class InventoryActionsTests
|
|
{
|
|
[Fact]
|
|
public void BuildStackableMerge_CarriesBothGuidsAndAmount()
|
|
{
|
|
byte[] body = InventoryActions.BuildStackableMerge(
|
|
seq: 1, mergeFromGuid: 0xAA, mergeToGuid: 0xBB, amount: 5);
|
|
|
|
Assert.Equal(24, body.Length);
|
|
Assert.Equal(InventoryActions.StackableMergeOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(0xAAu,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
|
Assert.Equal(0xBBu,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16)));
|
|
Assert.Equal(5u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(20)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildStackableSplitToContainer_FourFields()
|
|
{
|
|
byte[] body = InventoryActions.BuildStackableSplitToContainer(
|
|
seq: 1, stackGuid: 0xAA, containerGuid: 0xBB, placement: 3, amount: 10);
|
|
|
|
Assert.Equal(28, body.Length);
|
|
Assert.Equal(InventoryActions.StackableSplitToContainerOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(3u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(20)));
|
|
Assert.Equal(10u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(24)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildStackableSplitTo3D_TwoFields()
|
|
{
|
|
byte[] body = InventoryActions.BuildStackableSplitTo3D(
|
|
seq: 1, stackGuid: 0xAA, amount: 3);
|
|
Assert.Equal(20, body.Length);
|
|
Assert.Equal(InventoryActions.StackableSplitTo3DOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildStackableSplitToWield_HasEquipLocation()
|
|
{
|
|
byte[] body = InventoryActions.BuildStackableSplitToWield(
|
|
seq: 1, stackGuid: 0xAA, equipLocation: 0x00400000, amount: 1);
|
|
Assert.Equal(0x00400000u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildGiveObjectRequest_TargetItemAmount()
|
|
{
|
|
byte[] body = InventoryActions.BuildGiveObjectRequest(
|
|
seq: 1, targetGuid: 0xAA, itemGuid: 0xBB, amount: 2);
|
|
Assert.Equal(InventoryActions.GiveObjectRequestOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(0xAAu,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
|
Assert.Equal(0xBBu,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16)));
|
|
Assert.Equal(2u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(20)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddShortcut_ItemShortcut_FieldLayout()
|
|
{
|
|
// ShortCutData = Index(u32), ObjectId(u32), SpellId(u16), Layer(u16). Item → spell/layer 0.
|
|
byte[] body = InventoryActions.BuildAddShortcut(seq: 1, index: 0, objectGuid: 0x3E1, spellId: 0, layer: 0);
|
|
Assert.Equal(24, body.Length);
|
|
Assert.Equal(InventoryActions.AddShortcutOpcode,
|
|
System.Buffers.Binary.BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(0u, System.Buffers.Binary.BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12))); // index
|
|
Assert.Equal(0x3E1u, System.Buffers.Binary.BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16))); // objectGuid
|
|
Assert.Equal((ushort)0, System.Buffers.Binary.BinaryPrimitives.ReadUInt16LittleEndian(body.AsSpan(20))); // spellId
|
|
Assert.Equal((ushort)0, System.Buffers.Binary.BinaryPrimitives.ReadUInt16LittleEndian(body.AsSpan(22))); // layer
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddShortcut_SpellShortcut_PacksSpellAndLayerAsU16s()
|
|
{
|
|
byte[] body = InventoryActions.BuildAddShortcut(seq: 1, index: 2, objectGuid: 0, spellId: 0x1234, layer: 3);
|
|
Assert.Equal(0x1234, System.Buffers.Binary.BinaryPrimitives.ReadUInt16LittleEndian(body.AsSpan(20)));
|
|
Assert.Equal(3, System.Buffers.Binary.BinaryPrimitives.ReadUInt16LittleEndian(body.AsSpan(22)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildRemoveShortcut_HasSlotOnly()
|
|
{
|
|
byte[] body = InventoryActions.BuildRemoveShortcut(seq: 1, slotIndex: 5);
|
|
Assert.Equal(16, body.Length);
|
|
Assert.Equal(5u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildTeleToPoi_SimpleIdPayload()
|
|
{
|
|
byte[] body = InventoryActions.BuildTeleToPoi(seq: 1, poiId: 42);
|
|
Assert.Equal(InventoryActions.TeleToPoiOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(42u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
|
}
|
|
}
|