# Path: monsteractor.py
# class TryPutToSleep(Leaf):
#     def __init__(self):
#         super(TryPutToSleep, self).__init__()
#         self.component_type = "try_put_to_sleep"
# 
#     def first_tick(self, time):
#         if self.parent_may_sleep():
#             self.parent.set_child(SleepingEntity())
#         self.parent.remove_component(self)
# 
#     def parent_may_sleep(self):
#         return self.parent.status_flags.has_status(StatusFlags.IS_ALIVE)
# 
# Path: monstertables.py
# class DungeonTableItem(object):
#     def __init__(self, creator):
# def filter_monster_table_by_depth(table, depth):
# def from_table_pick_n_items_for_depth(table, n, depth, game_state):
# 
# Path: tools.py
# def time_it(name, func):
#     start = time.clock()
#     result = func()
#     elapsed = time.clock() - start
#     print name + ": " + str(elapsed)
#     return result


import random
import dungeongenerator
import spawner
from monsteractor import TryPutToSleep
from monstertables import from_table_pick_n_items_for_depth, dungeon_table, dungeon_equipment_table, dungeon_usable_item_table
from tools import time_it


class Dungeon(object):
    def __init__(self, game_state):
        self.level_count = 10
        self._dungeon_levels = [None]
        self.game_state = game_state

    def get_dungeon_level(self, depth):
        if depth >= self.level_count:
            self.game_state.has_won = True
            return None
        while len(self._dungeon_levels) <= depth:
            self._dungeon_levels.append(self._generate_dungeon_level(len(self._dungeon_levels)))
        return self._dungeon_levels[depth]

    def __getstate__(self):
        return dict(self.__dict__)

    def __setstate__(self, state):
        self.__dict__.update(state)

    def _generate_dungeon_level(self, depth):
        self.game_state.draw_loading_screen("Generating Dungeon...")
        size = 600 + depth * 20

        dungeon_level = time_it("dungeon_level_generation",
                                (lambda: dungeongenerator.generate_dungeon_floor(size, depth)))
        minimum_monsters = int(4 + depth * 1.2)
        monsters_to_spawn = random.randrange(minimum_monsters, minimum_monsters + 3)

# Path: monsteractor.py
# class TryPutToSleep(Leaf):
#     def __init__(self):
#         super(TryPutToSleep, self).__init__()
#         self.component_type = "try_put_to_sleep"
# 
#     def first_tick(self, time):
#         if self.parent_may_sleep():
#             self.parent.set_child(SleepingEntity())
#         self.parent.remove_component(self)
# 
#     def parent_may_sleep(self):
#         return self.parent.status_flags.has_status(StatusFlags.IS_ALIVE)
# 
# Path: monstertables.py
# class DungeonTableItem(object):
#     def __init__(self, creator):
# def filter_monster_table_by_depth(table, depth):
# def from_table_pick_n_items_for_depth(table, n, depth, game_state):
# 
# Path: tools.py
# def time_it(name, func):
#     start = time.clock()
#     result = func()
#     elapsed = time.clock() - start
#     print name + ": " + str(elapsed)
#     return result


# Path: dungeon.py
import random
import dungeongenerator
import spawner
from monsteractor import TryPutToSleep
from monstertables import from_table_pick_n_items_for_depth, dungeon_table, dungeon_equipment_table, dungeon_usable_item_table
from tools import time_it



class Dungeon(object):
    def __init__(self, game_state):
        self.level_count = 10
        self._dungeon_levels = [None]
        self.game_state = game_state

    def get_dungeon_level(self, depth):
        if depth >= self.level_count:
            self.game_state.has_won = True
            return None
        while len(self._dungeon_levels) <= depth:
            self._dungeon_levels.append(self._generate_dungeon_level(len(self._dungeon_levels)))
        return self._dungeon_levels[depth]

    def __getstate__(self):
        return dict(self.__dict__)

    def __setstate__(self, state):
        self.__dict__.update(state)

    def _generate_dungeon_level(self, depth):
        self.game_state.draw_loading_screen("Generating Dungeon...")
        size = 600 + depth * 20

        dungeon_level = time_it("dungeon_level_generation",
                                (lambda: dungeongenerator.generate_dungeon_floor(size, depth)))
        minimum_monsters = int(4 + depth * 1.2)
        monsters_to_spawn = random.randrange(minimum_monsters, minimum_monsters + 3)

        monsters = from_table_pick_n_items_for_depth(dungeon_table, monsters_to_spawn,