using UnityEngine;
using NeonTea.Quakeball.TeaNet.Packets;

namespace NeonTea.Quakeball.Networking.Packets {
    public class PlayerUpdatePckt : Packet {

        public ulong PlayerId;

        public Vector3 MoveDirection;
        public byte MoveStyle;
        public float Pitch;
        public float Yaw;

        public PlayerUpdatePckt() { }

        public PlayerUpdatePckt(Vector3 moveDirection, byte moveStyle, float pitch, float yaw, ulong id = 0) {
            MoveDirection = moveDirection;
            MoveStyle = moveStyle;
            Pitch = pitch;
            Yaw = yaw;
            PlayerId = id;
        }

        public override void Read(ByteBuffer buffer) {
            PlayerId = buffer.ReadULong();
            MoveDirection = buffer.ReadVector3();
            MoveStyle = buffer.Read();
            Pitch = buffer.ReadFloat();
            Yaw = buffer.ReadFloat();
        }

        public override void Write(ByteBuffer buffer) {
            buffer.Write(PlayerId);
            buffer.Write(MoveDirection);
            buffer.Write(MoveStyle);
            buffer.Write(Pitch);
            buffer.Write(Yaw);
        }
    }

    public class PlayerSyncPacket : Packet {
        public ulong PlayerId;
        public bool Unsynced;

        public Vector3 Location;
        public Vector3 GroundVelocity;

        public PlayerSyncPacket() { }
        public PlayerSyncPacket(ulong id, bool unsynced, Vector3 location, Vector3 groundVelocity) {
            PlayerId = id;
            Unsynced = unsynced;
            Location = location;
            GroundVelocity = groundVelocity;
        }

        public override void Read(ByteBuffer buffer) {
            PlayerId = buffer.ReadULong();
            Unsynced = buffer.ReadBool();
            Location = buffer.ReadVector3();
            GroundVelocity = buffer.ReadVector3();
        }

        public override void Write(ByteBuffer buffer) {
            buffer.Write(PlayerId);
            buffer.Write(Unsynced);
            buffer.Write(Location);
            buffer.Write(GroundVelocity);
        }
    }
}
