Beispiel #1
0
        public void TestMobileIncoming(
            ProtocolChanges changes, int hairItemId, int hairHue, int facialHairItemId, int facialHairHue
            )
        {
            var beholder = new Mobile(0x1)
            {
                Name = "Random Mobile 1"
            };

            beholder.DefaultMobileInit();

            var beheld = new Mobile(0x2)
            {
                Name = "Random Mobile 2"
            };

            beheld.DefaultMobileInit();
            beheld.AddItem(
                new Item((Serial)0x1000)
            {
                Layer = Layer.OneHanded
            }
                );

            // Test Dupe
            beheld.AddItem(
                new Item((Serial)0x1001)
            {
                Layer = Layer.OneHanded
            }
                );

            beheld.HairItemID       = hairItemId;
            beheld.HairHue          = hairHue;
            beheld.FacialHairItemID = facialHairItemId;
            beheld.FacialHairHue    = facialHairHue;

            var ns = PacketTestUtilities.CreateTestNetState();

            ns.ProtocolChanges = changes;

            var expected = new MobileIncoming(ns, beholder, beheld).Compile();

            ns.SendMobileIncoming(beholder, beheld);

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

            AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
        }
Beispiel #2
0
        public void TestMobileIncoming(
            ProtocolChanges protocolChanges, int hairItemId, int hairHue, int facialHairItemId, int facialHairHue
            )
        {
            var beholder = new Mobile(0x1)
            {
                Name = "Random Mobile 1"
            };

            beholder.DefaultMobileInit();

            var beheld = new Mobile(0x2)
            {
                Name = "Random Mobile 2"
            };

            beheld.DefaultMobileInit();
            beheld.AddItem(
                new Item((Serial)0x1000)
            {
                Layer = Layer.OneHanded
            }
                );

            // Test Dupe
            beheld.AddItem(
                new Item((Serial)0x1001)
            {
                Layer = Layer.OneHanded
            }
                );

            beheld.HairItemID       = hairItemId;
            beheld.HairHue          = hairHue;
            beheld.FacialHairItemID = facialHairItemId;
            beheld.FacialHairHue    = facialHairHue;

            var ns = new NetState(null)
            {
                ProtocolChanges = protocolChanges
            };

            var data = new MobileIncoming(ns, beholder, beheld).Compile();

            var sa         = ns.StygianAbyss;
            var newPacket  = ns.NewMobileIncoming;
            var itemIdMask = newPacket ? 0xFFFF : 0x7FFF;

            Span <bool> layers = stackalloc bool[256];

#if NO_LOCAL_INIT
            layers.Clear();
#endif

            var items = beheld.Items;
            var count = items.Count;

            if (beheld.HairItemID > 0)
            {
                count++;
            }

            if (beheld.FacialHairItemID > 0)
            {
                count++;
            }

            var length = 23 + count * 9; // Max Size

            Span <byte> expectedData = stackalloc byte[length];
            var         pos          = 0;

            expectedData.Write(ref pos, (byte)0x78);
            pos += 2; // Length

            var isSolidHue = beheld.SolidHueOverride >= 0;

            expectedData.Write(ref pos, beheld.Serial);
            expectedData.Write(ref pos, (ushort)beheld.Body);
            expectedData.Write(ref pos, (ushort)beheld.X);
            expectedData.Write(ref pos, (ushort)beheld.Y);
            expectedData.Write(ref pos, (byte)beheld.Z);
            expectedData.Write(ref pos, (byte)beheld.Direction);
            expectedData.Write(ref pos, (ushort)(isSolidHue ? beheld.SolidHueOverride : beheld.Hue));
            expectedData.Write(ref pos, (byte)beheld.GetPacketFlags(sa));
            expectedData.Write(ref pos, (byte)Notoriety.Compute(beholder, beheld));

            byte layer;

            for (var i = 0; i < items.Count; i++)
            {
                var item = items[i];

                layer = (byte)item.Layer;

                if (!item.Deleted && !layers[layer] && beholder.CanSee(item))
                {
                    layers[layer] = true;

                    expectedData.Write(ref pos, item.Serial);

                    var hue      = isSolidHue ? beheld.SolidHueOverride : item.Hue;
                    var itemID   = item.ItemID & itemIdMask;
                    var writeHue = newPacket || hue != 0;

                    if (!newPacket)
                    {
                        itemID |= 0x8000;
                    }

                    expectedData.Write(ref pos, (ushort)itemID);
                    expectedData.Write(ref pos, layer);
                    if (writeHue)
                    {
                        expectedData.Write(ref pos, (ushort)hue);
                    }
                }
            }

            layer = (byte)Layer.Hair;
            var itemId = beheld.HairItemID;

            if (itemId > 0 && !layers[layer])
            {
                expectedData.Write(ref pos, HairInfo.FakeSerial(beheld));
                var hue = isSolidHue ? beheld.SolidHueOverride : beheld.HairHue;
                itemId &= itemIdMask;
                var writeHue = newPacket || hue != 0;

                if (!newPacket)
                {
                    itemId |= 0x8000;
                }

                expectedData.Write(ref pos, (ushort)itemId);
                expectedData.Write(ref pos, layer);
                if (writeHue)
                {
                    expectedData.Write(ref pos, (ushort)hue);
                }
            }

            layer  = (byte)Layer.FacialHair;
            itemId = beheld.FacialHairItemID;

            if (itemId > 0 && !layers[layer])
            {
                expectedData.Write(ref pos, FacialHairInfo.FakeSerial(beheld));
                var hue = isSolidHue ? beheld.SolidHueOverride : beheld.FacialHairHue;
                itemId &= itemIdMask;
                var writeHue = newPacket || hue != 0;

                if (!newPacket)
                {
                    itemId |= 0x8000;
                }

                expectedData.Write(ref pos, (ushort)itemId);
                expectedData.Write(ref pos, layer);
                if (writeHue)
                {
                    expectedData.Write(ref pos, (ushort)hue);
                }
            }

#if NO_LOCAL_INIT
            expectedData.Write(ref pos, 0); // Zero serial, terminate list
#else
            pos += 4;
#endif

            expectedData.Slice(1, 2).Write((ushort)pos); // Length
            expectedData = expectedData.Slice(0, pos);

            AssertThat.Equal(data, expectedData);
        }