# generated by scripts/generate_messages.py

from twnet_parser.pretty_print import PrettyPrint
from twnet_parser.packer import Unpacker
from twnet_parser.packer import pack_int

class ObjPlayerInfo(PrettyPrint):
    def __init__(
            self,
            player_flags: int = 0,
            score: int = 0,
            latency: int = 0
    ) -> None:
        self.item_name: str = 'connless.player_info'
        self.type_id: int = 11
        self.id: int = 0
        self.size: int = 3

        self.player_flags: int = player_flags
        self.score: int = score
        self.latency: int = latency

    # first byte of data
    # has to be the first byte of the message payload
    # NOT the chunk header and NOT the message id
    def unpack(self, unpacker: Unpacker) -> bool:
        self.player_flags = unpacker.get_int() # TODO: this is a flag
        self.score = unpacker.get_int()
        self.latency = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.player_flags) + \
            pack_int(self.score) + \
            pack_int(self.latency)