Ejemplo n.º 1
0
        public static void SendMoveBoatHS(this NetState ns, Mobile beholder, BaseBoat boat,
                                          Direction d, int speed, BaseBoat.MovingEntitiesEnumerable ents, int xOffset, int yOffset)
        {
            if (ns?.HighSeas != true)
            {
                return;
            }

            var minLength = 68; // 18 + 5 * 10
            var writer    = new SpanWriter(stackalloc byte[minLength], true);

            writer.Write((byte)0xF6); // Packet ID
            writer.Seek(2, SeekOrigin.Current);

            writer.Write(boat.Serial);
            writer.Write((byte)speed);
            writer.Write((byte)d);
            writer.Write((byte)boat.Facing);
            writer.Write((short)(boat.X + xOffset));
            writer.Write((short)(boat.Y + yOffset));
            writer.Write((short)boat.Z);
            writer.Seek(2, SeekOrigin.Current); // count

            var count = 0;

            foreach (var ent in ents)
            {
                // If we assume that the entities list contains everything a player can see,
                // then this can be removed and the packet can be written once and copied to improve performance
                if (!beholder.CanSee(ent))
                {
                    continue;
                }

                writer.Write(ent.Serial);
                writer.Write((short)(ent.X + xOffset));
                writer.Write((short)(ent.Y + yOffset));
                writer.Write((short)ent.Z);
                ++count;
            }

            writer.Seek(16, SeekOrigin.Begin);
            writer.Write((short)count);
            writer.WritePacketLength();

            ns.Send(writer.Span);
        }
Ejemplo n.º 2
0
        public static void SendMoveBoatHS(this NetState ns, Mobile beholder, BaseBoat boat,
                                          Direction d, int speed, BaseBoat.MovingEntitiesEnumerable ents, int xOffset, int yOffset)
        {
            if (ns?.HighSeas != true)
            {
                return;
            }

            var minLength = 68; // 18 + 5 * 10
            var writer    = new SpanWriter(stackalloc byte[minLength], true);

            writer.Write((byte)0xF6); // Packet ID
            writer.Seek(2, SeekOrigin.Current);

            writer.Write(boat.Serial);
            writer.Write((byte)speed);
            writer.Write((byte)d);
            writer.Write((byte)boat.Facing);
            writer.Write((short)(boat.X + xOffset));
            writer.Write((short)(boat.Y + yOffset));
            writer.Write((short)boat.Z);
            writer.Seek(2, SeekOrigin.Current); // count

            var count = 0;

            foreach (var ent in ents)
            {
                if (!beholder.CanSee(ent))
                {
                    continue;
                }

                writer.Write(ent.Serial);
                writer.Write((short)(ent.X + xOffset));
                writer.Write((short)(ent.Y + yOffset));
                writer.Write((short)ent.Z);
                ++count;
            }

            writer.Seek(16, SeekOrigin.Begin);
            writer.Write((short)count);
            writer.WritePacketLength();

            ns.Send(writer.Span);
        }