2020-08-07 02:45:29 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using NeonTea.Quakeball.TeaNet.Packets;
|
|
|
|
|
|
2020-08-07 20:20:13 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using NeonTea.Quakeball.Networking;
|
|
|
|
|
|
|
|
|
|
namespace NeonTea.Quakeball.Networking.Packets {
|
|
|
|
|
public class MultiplePlayerUpdatesPckt : Packet {
|
|
|
|
|
|
|
|
|
|
public List<PlayerUpdatePckt> Updates = new List<PlayerUpdatePckt>();
|
|
|
|
|
|
|
|
|
|
public MultiplePlayerUpdatesPckt() { }
|
|
|
|
|
|
|
|
|
|
public MultiplePlayerUpdatesPckt(List<NetPlayer> players) {
|
2020-08-07 21:07:58 +02:00
|
|
|
|
foreach (NetPlayer p in players) {
|
2020-08-07 21:40:37 +02:00
|
|
|
|
if (p.Controlled == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-08-07 21:07:58 +02:00
|
|
|
|
Updates.Add(p.Controlled.CreatePacket(p.Id));
|
|
|
|
|
}
|
2020-08-07 20:20:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Read(ByteBuffer buffer) {
|
2020-08-07 21:07:58 +02:00
|
|
|
|
Updates.Clear();
|
|
|
|
|
int count = buffer.ReadInt();
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
PlayerUpdatePckt pckt = new PlayerUpdatePckt();
|
|
|
|
|
pckt.Read(buffer);
|
|
|
|
|
Updates.Add(pckt);
|
|
|
|
|
}
|
2020-08-07 20:20:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Write(ByteBuffer buffer) {
|
2020-08-07 21:07:58 +02:00
|
|
|
|
buffer.Write(Updates.Count);
|
|
|
|
|
foreach (PlayerUpdatePckt p in Updates) {
|
|
|
|
|
p.Write(buffer);
|
|
|
|
|
}
|
2020-08-07 20:20:13 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 02:45:29 +02:00
|
|
|
|
public class PlayerUpdatePckt : Packet {
|
|
|
|
|
|
2020-08-07 05:24:46 +02:00
|
|
|
|
public ulong PlayerId;
|
|
|
|
|
|
2020-08-07 02:45:29 +02:00
|
|
|
|
public Vector3 MoveDirection;
|
|
|
|
|
public byte MoveStyle;
|
|
|
|
|
public bool Jumping;
|
|
|
|
|
public float Pitch;
|
|
|
|
|
public float Yaw;
|
|
|
|
|
|
|
|
|
|
public PlayerUpdatePckt() { }
|
|
|
|
|
|
2020-08-07 21:07:58 +02:00
|
|
|
|
public PlayerUpdatePckt(Vector3 moveDirection, byte moveStyle, bool jumping, float pitch, float yaw, ulong id = 0) {
|
2020-08-07 02:45:29 +02:00
|
|
|
|
MoveDirection = moveDirection;
|
|
|
|
|
MoveStyle = moveStyle;
|
|
|
|
|
Jumping = jumping;
|
|
|
|
|
Pitch = pitch;
|
|
|
|
|
Yaw = yaw;
|
2020-08-07 21:07:58 +02:00
|
|
|
|
PlayerId = id;
|
2020-08-07 02:45:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Read(ByteBuffer buffer) {
|
2020-08-07 05:24:46 +02:00
|
|
|
|
PlayerId = buffer.ReadULong();
|
|
|
|
|
float x = buffer.ReadFloat();
|
|
|
|
|
float y = buffer.ReadFloat();
|
|
|
|
|
float z = buffer.ReadFloat();
|
|
|
|
|
MoveDirection = new Vector3(x, y, z);
|
|
|
|
|
MoveStyle = buffer.Read();
|
|
|
|
|
Jumping = buffer.ReadBool();
|
|
|
|
|
Pitch = buffer.ReadFloat();
|
|
|
|
|
Yaw = buffer.ReadFloat();
|
2020-08-07 02:45:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Write(ByteBuffer buffer) {
|
2020-08-07 05:24:46 +02:00
|
|
|
|
buffer.Write(PlayerId);
|
|
|
|
|
buffer.Write(MoveDirection.x);
|
|
|
|
|
buffer.Write(MoveDirection.y);
|
|
|
|
|
buffer.Write(MoveDirection.z);
|
|
|
|
|
buffer.Write(MoveStyle);
|
|
|
|
|
buffer.Write(Jumping);
|
|
|
|
|
buffer.Write(Pitch);
|
|
|
|
|
buffer.Write(Yaw);
|
2020-08-07 02:45:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|