예제 #1
0
        public void TestDisplayContextMenu()
        {
            var m = new Mobile(0x1);

            m.DefaultMobileInit();

            var item = new ContextMenuItem(Serial.LastItem + 1);
            var menu = new ContextMenu(m, item);

            Span <byte> data = new DisplayContextMenu(menu).Compile();

            int length = 12 + menu.Entries.Length * 8;

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

            int pos = 0;

            expectedData[pos++] = 0xBF;                     // Packet ID
            ((ushort)length).CopyTo(ref pos, expectedData); // Length
            ((ushort)0x14).CopyTo(ref pos, expectedData);   // Command
            ((ushort)0x02).CopyTo(ref pos, expectedData);   // Subcommand
            menu.Target.Serial.CopyTo(ref pos, expectedData);
            var entries = menu.Entries;

            expectedData[pos++] = (byte)entries.Length;

            for (int i = 0; i < entries.Length; i++)
            {
                var entry = entries[i];
                entry.Number.CopyTo(ref pos, expectedData);
                ((ushort)i).CopyTo(ref pos, expectedData);

                var flags = entry.Flags;

                var range = entry.Range;

                if (range == -1)
                {
                    range = 18;
                }

                if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
                {
                    flags |= CMEFlags.Disabled;
                }

                ((ushort)flags).CopyTo(ref pos, expectedData);
            }

            AssertThat.Equal(data, expectedData);
        }
예제 #2
0
        public void TestDisplayContextMenuOld()
        {
            var m = new Mobile(0x1);

            m.DefaultMobileInit();

            var item = new ContextMenuItem(Serial.LastItem + 1);
            var menu = new ContextMenu(m, item);

            var data = new DisplayContextMenuOld(menu).Compile();

            var length = 12 + menu.Entries.Sum(entry => 6 + ((entry.Color & 0xFFFF) != 0xFFFF ? 2 : 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)0x14);   // Command
            expectedData.Write(ref pos, (ushort)0x01);   // Subcommand
            expectedData.Write(ref pos, menu.Target.Serial);
            var entries = menu.Entries;

            expectedData.Write(ref pos, (byte)entries.Length);

            for (var i = 0; i < entries.Length; i++)
            {
                var entry = entries[i];
                expectedData.Write(ref pos, (ushort)i);
                expectedData.Write(ref pos, (ushort)(entry.Number - 3000000));

                var flags = entry.Flags;

                var color = entry.Color & 0xFFFF;

                if (color != 0xFFFF)
                {
                    flags |= CMEFlags.Colored;
                }

                var range = entry.Range;

                if (range == -1)
                {
                    range = 18;
                }

                if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
                {
                    flags |= CMEFlags.Disabled;
                }

                expectedData.Write(ref pos, (ushort)flags);

                if ((flags & CMEFlags.Colored) != 0)
                {
                    expectedData.Write(ref pos, (ushort)color);
                }
            }

            AssertThat.Equal(data, expectedData);
        }