# 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
import twnet_parser.enum7 as enum7

class ObjCharacter(PrettyPrint):
    def __init__(
            self,
            health: int = 0,
            armor: int = 0,
            ammo_count: int = 0,
            weapon: int = enum7.Weapon.HAMMER.value,
            emote: int = enum7.Emote.NORMAL.value,
            attack_tick: int = 0,
            triggered_events: int = 0
    ) -> None:
        self.item_name: str = 'item.character'
        self.type_id: int = 10
        self.id: int = 0
        self.size: int = 22

        self.health: int = health
        self.armor: int = armor
        self.ammo_count: int = ammo_count
        self.weapon: int = weapon
        self.emote: int = emote
        self.attack_tick: int = attack_tick
        self.triggered_events: int = triggered_events

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

        yield 'health', self.health
        yield 'armor', self.armor
        yield 'ammo_count', self.ammo_count
        yield 'weapon', self.weapon
        yield 'emote', self.emote
        yield 'attack_tick', self.attack_tick
        yield 'triggered_events', self.triggered_events

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'health': self.health,
            'armor': self.armor,
            'ammo_count': self.ammo_count,
            'weapon': self.weapon,
            'emote': self.emote,
            'attack_tick': self.attack_tick,
            'triggered_events': self.triggered_events
        }

    # 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:
        # character_core
        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()

        # character
        self.health = unpacker.get_int()
        self.armor = unpacker.get_int()
        self.ammo_count = unpacker.get_int()
        self.weapon = unpacker.get_int() # enum WEAPON
        self.emote = unpacker.get_int() # enum EMOTE
        self.attack_tick = unpacker.get_int()
        self.triggered_events = unpacker.get_int() # TODO: this is a flag
        return True

    def pack(self) -> bytes:
        return pack_int(self.health) + \
            pack_int(self.armor) + \
            pack_int(self.ammo_count) + \
            pack_int(self.weapon) + \
            pack_int(self.emote) + \
            pack_int(self.attack_tick) + \
            pack_int(self.triggered_events)