public void TestDisplayEquipmentInfo(string name, bool unidentified)
        {
            var m = new Mobile((Serial)0x1);

            m.DefaultMobileInit();
            m.RawName = name;

            var item = new Item(World.NewItem);

            var info = new EquipmentInfo(
                500000,
                m,
                unidentified,
                new[]
            {
                new EquipInfoAttribute(500001, 1),
                new EquipInfoAttribute(500002, 2),
                new EquipInfoAttribute(500002, 3)
            }
                );

            var expected = new DisplayEquipmentInfo(item, info).Compile();

            var ns = PacketTestUtilities.CreateTestNetState();

            ns.SendDisplayEquipmentInfo(
                item.Serial,
                info.Number,
                info.Crafter?.RawName,
                info.Unidentified,
                new List <EquipInfoAttribute>(info.Attributes)
                );

            var result = ns.SendPipe.Reader.TryRead();

            AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
        }
        public void TestDisplayEquipmentInfo()
        {
            var m = new Mobile(0x1);

            m.DefaultMobileInit();

            var item = new Item(Serial.LastItem + 1);

            var info = new EquipmentInfo(
                500000,
                m,
                false,
                new []
            {
                new EquipInfoAttribute(500001, 1),
                new EquipInfoAttribute(500002, 2),
                new EquipInfoAttribute(500002, 3)
            }
                );

            Span <byte> data = new DisplayEquipmentInfo(item, info).Compile();

            var attrs = info.Attributes;

            int length = 17 + (info.Unidentified ? 4 : 0) + attrs.Length * 6;

            if (info.Crafter != null)
            {
                length += 6 + (info.Crafter.Name?.Length ?? 0);
            }

            Span <byte> expectedData = stackalloc byte[length];

            int pos = 0;

            expectedData[pos++] = 0xBF;                     // Packet ID
            ((ushort)length).CopyTo(ref pos, expectedData); // Length
            ((ushort)0x10).CopyTo(ref pos, expectedData);   // Subcommand
            item.Serial.CopyTo(ref pos, expectedData);
            info.Number.CopyTo(ref pos, expectedData);
            if (info.Crafter != null)
            {
                var name = info.Crafter.Name ?? "";
                (-3).CopyTo(ref pos, expectedData);
                ((ushort)name.Length).CopyTo(ref pos, expectedData);
                name.CopyASCIITo(ref pos, expectedData);
            }

            if (info.Unidentified)
            {
                (-4).CopyTo(ref pos, expectedData);
            }

            for (var i = 0; i < attrs.Length; i++)
            {
                var attr = attrs[i];
                attr.Number.CopyTo(ref pos, expectedData);
                ((ushort)attr.Charges).CopyTo(ref pos, expectedData);
            }

            (-1).CopyTo(ref pos, expectedData);

            AssertThat.Equal(data, expectedData);
        }
Beispiel #3
0
        public void TestDisplayEquipmentInfo()
        {
            var m = new Mobile(0x1);

            m.DefaultMobileInit();

            var item = new Item(Serial.LastItem + 1);

            var info = new EquipmentInfo(
                500000,
                m,
                false,
                new[]
            {
                new EquipInfoAttribute(500001, 1),
                new EquipInfoAttribute(500002, 2),
                new EquipInfoAttribute(500002, 3)
            }
                );

            var data = new DisplayEquipmentInfo(item, info).Compile();

            var attrs = info.Attributes;

            var length = 17 + (info.Unidentified ? 4 : 0) + attrs.Length * 6;

            if (info.Crafter != null)
            {
                length += 6 + (info.Crafter.Name?.Length ?? 0);
            }

            Span <byte> expectedData = stackalloc byte[length];

            var pos = 0;

            expectedData.Write(ref pos, (byte)0xBF);     // Packet ID
            expectedData.Write(ref pos, (ushort)length); // Length
            expectedData.Write(ref pos, (ushort)0x10);   // Subcommand
            expectedData.Write(ref pos, item.Serial);
            expectedData.Write(ref pos, info.Number);
            if (info.Crafter != null)
            {
                var name = info.Crafter.Name ?? "";
                expectedData.Write(ref pos, -3);
                expectedData.Write(ref pos, (ushort)name.Length);
                expectedData.WriteAscii(ref pos, name);
            }

            if (info.Unidentified)
            {
                expectedData.Write(ref pos, -4);
            }

            for (var i = 0; i < attrs.Length; i++)
            {
                var attr = attrs[i];
                expectedData.Write(ref pos, attr.Number);
                expectedData.Write(ref pos, (ushort)attr.Charges);
            }

            expectedData.Write(ref pos, -1);

            AssertThat.Equal(data, expectedData);
        }