import logging

from .random_utils import generate_random_mob_list, generate_random_rooms

logger = logging.getLogger(__name__)


class Level:
    """ Class Level """

    def __init__(self, difficulty, player, mob_list):
        """ Chargement du niveau """
        logger.debug("Loading Level")
        self.mobs_in_level = generate_random_mob_list(mob_list, difficulty)
        self.exit_level = True
        self.player = player
        self.rooms = generate_random_rooms(self.mobs_in_level, difficulty)  # Liste des pièces du niveau
        self.current_room_index = 0  # Index de la pièce actuelle

        logger.debug("Level Loaded")

    def combat(self, mob, player):
        pvs = []
        while mob.current_pv > 0 and player.current_pv > 0:
            if mob.speed > player.speed:
                mob.perform_attack(player)
                player.perform_attack(mob)
            else:
                player.perform_attack(mob)
                mob.perform_attack(player)
            pvs.append({
                'player': player.current_pv,
                'mob': mob.current_pv
            })
        return pvs
