private void HandleDrawObjectPacket(DrawObjectPacket packet)
        {
            if (packet.Id == legacyApi.Me.PlayerId)
            {
                player.Location           = packet.Location;
                player.PredictedLocation  = packet.Location;
                player.Direction          = packet.Direction;
                player.PredictedDirection = packet.Direction;
                player.MovementType       = packet.MovementType;

                player.Color     = packet.Color;
                player.BodyType  = packet.Type;
                player.Flags     = packet.Flags;
                player.Notoriety = packet.Notoriety;

                player.ResetWalkRequestQueue();
                player.CurrentSequenceKey = 0;
                OnWalkRequestDequeued();

                if (gameObjects[packet.Id] is Mobile mobile)
                {
                    gameObjects.UpdateObject(mobile.Update(packet.Type, packet.Location, packet.Color, packet.Direction,
                                                           packet.MovementType,
                                                           packet.Notoriety, packet.Flags));
                }
                else
                {
                    mobile = new Mobile(packet.Id, packet.Type, packet.Location, packet.Color,
                                        packet.Direction, packet.MovementType,
                                        packet.Notoriety, packet.Flags);
                    gameObjects.AddObject(mobile);
                }
            }
        }
        public void Can_deserialize_object_without_items()
        {
            var drawObjectPacketWithoutItems = FakePackets.Instantiate(source: new byte[]
            {
                0x78,                   // packet
                0x00, 0x17,             // length
                0x00, 0x00, 0x00, 0x01, // id
                0x01, 0x90,             // type
                0x12, 0x9B,             // xpos
                0x05, 0x53,             // ypos
                0x0A,                   // zpos
                0x07,                   // direction/facing
                0x83, 0xEA,             // color
                0x00,                   // status flag
                0x01,                   // notoriety
                0x00, 0x00, 0x00, 0x00  // EOF
            });

            var drawObjectPacket = new DrawObjectPacket();

            drawObjectPacket.Deserialize(drawObjectPacketWithoutItems);

            drawObjectPacket.Id.Should().Be(new ObjectId(0x00000001));
            drawObjectPacket.Type.Should().Be((ModelId)0x0190);
            drawObjectPacket.Location.X.Should().Be(0x129B);
            drawObjectPacket.Location.Y.Should().Be(0x0553);
            drawObjectPacket.Location.Z.Should().Be(0x0A);
            drawObjectPacket.Direction.Should().Be(Direction.Northwest);
            drawObjectPacket.MovementType.Should().Be(MovementType.Walk);
            drawObjectPacket.Notoriety.Should().Be(Notoriety.Innocent);
            drawObjectPacket.Color.Should().Be((Color)0x83EA);
            drawObjectPacket.Items.Should().BeEmpty();
        }
        public void Can_deserialize_object_with_item_with_color()
        {
            var packetWithOneItemWithoutColor = FakePackets.Instantiate(new byte[]
            {
                0x78,                   // packet
                0x00, 0x20,             // length
                0x00, 0x00, 0x00, 0x01, // id
                0x01, 0x90,             // type
                0x12, 0x9B,             // xpos
                0x05, 0x53,             // ypos
                0x0A,                   // zpos
                0x07,                   // direction/facing
                0x83, 0xEA,             // color
                0x00,                   // status flag
                0x01,                   // notoriety
                0x40, 0x00, 0x00, 0x02, // item id
                0xA0, 0x3B,             // item type
                0x0B,                   // layer
                0x04, 0x4E,             // color
                0x00, 0x00, 0x00, 0x00  // EOF
            });

            var materializedPacket = new DrawObjectPacket();

            materializedPacket.Deserialize(packetWithOneItemWithoutColor);
            var items = materializedPacket.Items.ToArray();

            items.Length.Should().Be(1);
            items.First().Id.Should().Be(new ObjectId(0x40000002));
            items.First().Type.Should().Be((ModelId)(0xA03B - 0x8000));
            items.First().Amount.Should().Be(1);
            items.First().ContainerId.Should().Be(new ObjectId(0x00000001u));
            items.First().Layer.Should().Be(Layer.Hair);
            items.First().Color.Should().Be((Color)0x044E);
        }
Exemple #4
0
        public void Can_seserialize_object_without_items()
        {
            var packet = new DrawObjectPacket();

            packet.Id           = 0x00000001;
            packet.Type         = 0x0190;
            packet.Location     = new Location3D(0x129B, 0x0553, 0x0A);
            packet.Direction    = Direction.Northwest;
            packet.MovementType = MovementType.Walk;
            packet.Color        = (Color)0x83EA;
            packet.Flags        = 0x00;
            packet.Notoriety    = Notoriety.Innocent;
            packet.Items        = Enumerable.Empty <Item>();

            packet.Serialize().Payload.Should().BeEquivalentTo(new byte[]
            {
                0x78,                   // packet
                0x00, 0x17,             // length
                0x00, 0x00, 0x00, 0x01, // id
                0x01, 0x90,             // type
                0x12, 0x9B,             // xpos
                0x05, 0x53,             // ypos
                0x0A,                   // zpos
                0x07,                   // direction/facing
                0x83, 0xEA,             // color
                0x00,                   // status flag
                0x01,                   // notoriety
                0x00, 0x00, 0x00, 0x00  // EOF
            });
        }
        public void Can_deserialize_packet_with_item_without_color()
        {
            var packetWithOneItemWithoutColor = FakePackets.Instantiate(new byte[]
            {
                0x78,                   // packet
                0x00, 0x1E,             // length
                0x00, 0x00, 0x00, 0x01, // id
                0x01, 0x90,             // type
                0x12, 0x9B,             // xpos
                0x05, 0x53,             // ypos
                0x0A,                   // zpos
                0x07,                   // direction/facing
                0x83, 0xEA,             // color
                0x00,                   // status flag
                0x01,                   // notoriety
                0x40, 0x00, 0x00, 0x0C, // item1 id
                0x0F, 0x44,             // item1 type
                0x02,                   // layer
                0x00, 0x00, 0x00, 0x00  // EOF
            });

            var materializedPacket = new DrawObjectPacket();

            materializedPacket.Deserialize(packetWithOneItemWithoutColor);
            var items = materializedPacket.Items.ToArray();

            items.Length.Should().Be(1);
            items.First().Id.Should().Be(new ObjectId(0x4000000C));
            items.First().Type.Should().Be((ModelId)0x0F44);
            items.First().Amount.Should().Be(1);
            items.First().ContainerId.Should().Be(new ObjectId(0x00000001u));
            items.First().Layer.Should().Be(Layer.TwoHandedWeapon);
        }
        private void HandleDrawObjectPacket(DrawObjectPacket packet)
        {
            gameObjects.AddItemRange(packet.Items);

            if (packet.Id == legacyApi.Me.PlayerId)
            {
                return;
            }

            if (gameObjects[packet.Id] is Mobile mobile)
            {
                var updatedMobile = mobile.Update(packet.Type, packet.Location, packet.Color, packet.Direction,
                                                  packet.MovementType,
                                                  packet.Notoriety, packet.Flags);

                gameObjects.UpdateObject(updatedMobile);
                CheckFlagsChange(mobile, updatedMobile);
            }
            else
            {
                mobile = new Mobile(packet.Id, packet.Type, packet.Location, packet.Color,
                                    packet.Direction, packet.MovementType,
                                    packet.Notoriety, packet.Flags);
                gameObjects.AddObject(mobile);
                OnMobileEnteredView(mobile);
            }
        }
        private void EnterGamePre7000()
        {
            var loginConfirmPacket = new CharLocaleAndBodyPacket()
            {
                PlayerId     = legacyApi.Me.PlayerId,
                BodyType     = legacyApi.Me.BodyType,
                Direction    = legacyApi.Me.Direction,
                MovementType = legacyApi.Me.MovementType,
                Location     = legacyApi.Me.Location,
            };

            SendToClient(loginConfirmPacket.Serialize());
            SendToClient(new SetMapPacket(reloginInfo.MapId).RawPacket);

            var enableFeaturesPacket = packetRegistry.Instantiate <EnableLockedClientFeaturesPacket>(0xB9);

            enableFeaturesPacket.Flags = reloginInfo.EnabledFeatureFlags;
            SendToClient(enableFeaturesPacket.Serialize());

            SendToClient(new Packet(new byte[] { 0x55 }));

            var drawPlayer = new DrawGamePlayerPacket(legacyApi.Me.PlayerId, legacyApi.Me.BodyType, legacyApi.Me.Location,
                                                      legacyApi.Me.Direction, legacyApi.Me.MovementType, legacyApi.Me.Color);

            SendToClient(drawPlayer.Serialize());

            foreach (var obj in UO.Items.OnGround())
            {
                var objectInfo = new ObjectInfoPacket(obj.Id, obj.Type, obj.Location, obj.Color, obj.Amount);
                SendToClient(objectInfo.RawPacket);
            }

            SendToClient(new Packet(new byte[] { 0xBF, 0x00, 0x0D, 0x00, 0x05, 0x00, 0x00, 0x02, 0x80, 0x01, 0xFF, 0xFF, 0xA7, }));

            foreach (var mobile in UO.Mobiles)
            {
                var drawPacket = new DrawObjectPacket();
                drawPacket.Color        = mobile.Color.HasValue ? mobile.Color.Value : (Color)0;
                drawPacket.Direction    = mobile.Orientation.HasValue ? mobile.Orientation.Value : Direction.North;
                drawPacket.Flags        = mobile.Flags;
                drawPacket.Id           = mobile.Id;
                drawPacket.Location     = mobile.Location;
                drawPacket.MovementType = mobile.CurrentMovementType.HasValue ? mobile.CurrentMovementType.Value : MovementType.Walk;
                drawPacket.Notoriety    = mobile.Notoriety.HasValue ? mobile.Notoriety.Value : Notoriety.Innocent;
                drawPacket.Type         = mobile.Type;

                var items = UO.Items.InContainer(mobile.Id).Where(i => i.Layer.HasValue).ToArray();
                drawPacket.Items = items;

                SendToClient(drawPacket.Serialize());
            }
        }
Exemple #8
0
        private void HandleDrawObject(DrawObjectPacket packet)
        {
            lock (trackedObjects)
            {
                if (trackedObjects.TryGetValue(packet.Id, out var payload))
                {
                    if (payload == null || payload.Length != packet.RawPacket.Length)
                    {
                        payload = new byte[packet.RawPacket.Length];
                    }

                    packet.RawPacket.Payload.CopyTo(payload, 0);
                    trackedObjects[packet.Id] = payload;
                }
            }
        }
Exemple #9
0
        public void Can_serialize_object_with_item_with_color()
        {
            var packet = new DrawObjectPacket();

            packet.Id           = 0x00000001;
            packet.Type         = 0x0190;
            packet.Location     = new Location3D(0x129B, 0x0553, 0x0A);
            packet.Direction    = Direction.Northwest;
            packet.MovementType = MovementType.Walk;
            packet.Color        = (Color)0x83EA;
            packet.Flags        = 0x00;
            packet.Notoriety    = Notoriety.Innocent;

            packet.Items = new[]
            {
                new Item(0x40000002, 0xA03B - 0x8000, 1, new Location3D(), (Color)0x044E, 0x00000001, Layer.Hair)
            };

            packet.Serialize().Payload.Should().BeEquivalentTo(new byte[]
            {
                0x78,                   // packet
                0x00, 0x20,             // length
                0x00, 0x00, 0x00, 0x01, // id
                0x01, 0x90,             // type
                0x12, 0x9B,             // xpos
                0x05, 0x53,             // ypos
                0x0A,                   // zpos
                0x07,                   // direction/facing
                0x83, 0xEA,             // color
                0x00,                   // status flag
                0x01,                   // notoriety
                0x40, 0x00, 0x00, 0x02, // item id
                0xA0, 0x3B,             // item type
                0x0B,                   // layer
                0x04, 0x4E,             // color
                0x00, 0x00, 0x00, 0x00  // EOF
            });
        }
Exemple #10
0
        public void Can_serialize_packet_with_item_without_color()
        {
            var packet = new DrawObjectPacket();

            packet.Id           = 0x00000001;
            packet.Type         = 0x0190;
            packet.Location     = new Location3D(0x129B, 0x0553, 0x0A);
            packet.Direction    = (Direction)0x07;
            packet.MovementType = MovementType.Walk;
            packet.Color        = (Color)0x83EA;
            packet.Flags        = 0;
            packet.Notoriety    = (Notoriety)0x01;
            packet.Items        = new[]
            {
                new Item(0x4000000C, 0x0F44, 1, new Location3D(), null, 0x00000001, Layer.TwoHandedWeapon)
            };

            packet.Serialize().Payload.Should().BeEquivalentTo(new byte[]
            {
                0x78,                   // packet
                0x00, 0x1E,             // length
                0x00, 0x00, 0x00, 0x01, // id
                0x01, 0x90,             // type
                0x12, 0x9B,             // xpos
                0x05, 0x53,             // ypos
                0x0A,                   // zpos
                0x07,                   // direction/facing
                0x83, 0xEA,             // color
                0x00,                   // status flag
                0x01,                   // notoriety
                0x40, 0x00, 0x00, 0x0C, // item1 id
                0x0F, 0x44,             // item1 type
                0x02,                   // layer
                0x00, 0x00, 0x00, 0x00  // EOF
            });
        }