import helper
from people import player
from people.pedestrian import Pedestrian


class Police(Pedestrian):
    def __init__(self, pos):
        helper.living_police += 1
        super().__init__(pos)
        self.relation = self.Relation.ENEMY
        self.card.set_texture(self.police_tex)
        self.number = 12
        self.number_np.hide()

    def attack(self, is_attacker, event):
        super().attack(is_attacker, event)
        if event.get_into_node_path() == player.instance.push_collider:
            self.number += 1

    def __del__(self):
        helper.living_police -= 1
        super().__del__()

    def _update_enemy(self):
        if self.action_state == self.ActionState.IDLE:
            self._target = self.find_aggro_target()
            if self._target is None:
                self._target = player.instance
            self.action_state = self.ActionState.AGGRO
        elif self.action_state == self.ActionState.AGGRO or self.action_state == self.ActionState.ATTACK:
            if not self._target.alive:
                self._target = None
                self.wander()
                return
            aggro_vector = self._target.pos - self.pos
            self.velocity = aggro_vector.normalized() * self.speed()
        else:
            print("unusual police state:", self.action_state)
