Exemplo n.º 1
0
        public static void SendBatchEntities(this NetState ns, IEnumerable <IEntity> entities, int estimatedCount)
        {
            if (ns?.HighSeas != true)
            {
                return;
            }

            bool isSA = ns.StygianAbyss;
            bool isHS = ns.HighSeas;

            var minLength = PacketContainerBuilder.MinPacketLength
                            + OutgoingEntityPackets.MaxWorldEntityPacketLength
                            * estimatedCount;

            using var builder = new PacketContainerBuilder(stackalloc byte[minLength]);

            Span <byte> buffer = builder.GetSpan(OutgoingEntityPackets.MaxWorldEntityPacketLength);

            foreach (var entity in entities)
            {
                buffer.InitializePacket();
                var bytesWritten = OutgoingEntityPackets.CreateWorldEntity(buffer, entity, isSA, isHS);
                builder.Advance(bytesWritten);
            }

            ns.Send(builder.Finalize());
        }
Exemplo n.º 2
0
        public static void SendWorldItem(this NetState ns, Item item)
        {
            if (ns == null)
            {
                return;
            }

            Span <byte> buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength].InitializePacket();

            var length = ns.StygianAbyss ?
                         OutgoingEntityPackets.CreateWorldEntity(buffer, item, ns.HighSeas) :
                         CreateWorldItem(buffer, item);

            ns.Send(buffer[..length]);