quakeball/Assets/Scripts/Networking/Packets/PlayerActionPckt.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2020-08-08 03:21:02 +02:00
using NeonTea.Quakeball.TeaNet.Packets;
namespace NeonTea.Quakeball.Networking.Packets {
public class PlayerActionPckt : Packet {
public ulong PlayerId;
public PlayerAction Action;
2020-08-08 03:53:38 +02:00
public Serializable Serializable;
2020-08-08 03:21:02 +02:00
public PlayerActionPckt() { }
public PlayerActionPckt(PlayerAction action, ulong id = 0) {
Action = action;
PlayerId = id;
}
public override void Read(ByteBuffer buffer) {
PlayerId = buffer.ReadULong();
switch (buffer.Read()) {
case 0:
Action = PlayerAction.Jump;
break;
2020-08-08 03:53:38 +02:00
case 1:
Action = PlayerAction.Shoot;
ShootData data = new ShootData();
data.Read(buffer);
Serializable = data;
break;
2020-08-08 03:21:02 +02:00
}
}
public override void Write(ByteBuffer buffer) {
buffer.Write(PlayerId);
buffer.Write((byte)Action);
2020-08-08 03:53:38 +02:00
if (Action == PlayerAction.Shoot) {
buffer.Write(Serializable);
}
2020-08-08 03:21:02 +02:00
}
}
public enum PlayerAction {
Null = byte.MaxValue,
Jump = 0,
2020-08-08 03:53:38 +02:00
Shoot = 1,
}
public class ShootData : Serializable {
public void Read(ByteBuffer buffer) {
}
public void Write(ByteBuffer buffer) {
}
2020-08-08 03:21:02 +02:00
}
}