# generated by scripts/generate_messages.py

from typing import Any, Dict

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

class ObjCharacterCore(PrettyPrint):
    def __init__(
            self,
            tick: int = 0,
            x: int = 0,
            y: int = 0,
            vel_x: int = 0,
            vel_y: int = 0,
            angle: int = 0,
            direction: int = 0,
            jumped: int = 0,
            hooked_player: int = 0,
            hook_state: int = 0,
            hook_tick: int = 0,
            hook_x: int = 0,
            hook_y: int = 0,
            hook_dx: int = 0,
            hook_dy: int = 0
    ) -> None:
        self.item_name: str = 'item.character_core'
        self.type_id: int = 9
        self.id: int = 0
        self.size: int = 15

        self.tick: int = tick
        self.x: int = x
        self.y: int = y
        self.vel_x: int = vel_x
        self.vel_y: int = vel_y
        self.angle: int = angle
        self.direction: int = direction
        self.jumped: int = jumped
        self.hooked_player: int = hooked_player
        self.hook_state: int = hook_state
        self.hook_tick: int = hook_tick
        self.hook_x: int = hook_x
        self.hook_y: int = hook_y
        self.hook_dx: int = hook_dx
        self.hook_dy: int = hook_dy

    def __iter__(self):
        yield 'item_name', self.item_name
        yield 'type_id', self.type_id
        yield 'id', self.id
        yield 'size', self.size

        yield 'tick', self.tick
        yield 'x', self.x
        yield 'y', self.y
        yield 'vel_x', self.vel_x
        yield 'vel_y', self.vel_y
        yield 'angle', self.angle
        yield 'direction', self.direction
        yield 'jumped', self.jumped
        yield 'hooked_player', self.hooked_player
        yield 'hook_state', self.hook_state
        yield 'hook_tick', self.hook_tick
        yield 'hook_x', self.hook_x
        yield 'hook_y', self.hook_y
        yield 'hook_dx', self.hook_dx
        yield 'hook_dy', self.hook_dy

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'tick': self.tick,
            'x': self.x,
            'y': self.y,
            'vel_x': self.vel_x,
            'vel_y': self.vel_y,
            'angle': self.angle,
            'direction': self.direction,
            'jumped': self.jumped,
            'hooked_player': self.hooked_player,
            'hook_state': self.hook_state,
            'hook_tick': self.hook_tick,
            'hook_x': self.hook_x,
            'hook_y': self.hook_y,
            'hook_dx': self.hook_dx,
            'hook_dy': self.hook_dy
        }

    # 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.tick = unpacker.get_int()
        self.x = unpacker.get_int()
        self.y = unpacker.get_int()
        self.vel_x = unpacker.get_int()
        self.vel_y = unpacker.get_int()
        self.angle = unpacker.get_int()
        self.direction = unpacker.get_int()
        self.jumped = unpacker.get_int()
        self.hooked_player = unpacker.get_int()
        self.hook_state = unpacker.get_int()
        self.hook_tick = unpacker.get_int()
        self.hook_x = unpacker.get_int()
        self.hook_y = unpacker.get_int()
        self.hook_dx = unpacker.get_int()
        self.hook_dy = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.tick) + \
            pack_int(self.x) + \
            pack_int(self.y) + \
            pack_int(self.vel_x) + \
            pack_int(self.vel_y) + \
            pack_int(self.angle) + \
            pack_int(self.direction) + \
            pack_int(self.jumped) + \
            pack_int(self.hooked_player) + \
            pack_int(self.hook_state) + \
            pack_int(self.hook_tick) + \
            pack_int(self.hook_x) + \
            pack_int(self.hook_y) + \
            pack_int(self.hook_dx) + \
            pack_int(self.hook_dy)