from characters import *
from items import *
import random, time, os
from helpers import Dice
class Location:
    def __init__(self, name, description, monsters, loot_table):
        self.name = name
        self.description = description
        self.monsters = monsters
        self.loot_table = loot_table
        self.actions = {
            "explore": self.explore,
            "rest": self.rest,
            "leave":  self.leave
        }
        pass

    def enter(self, player):
        self.player = player
        self.actions["inventory"] = self.player.use_item
        print("Miejsce: " + self.description)

        while True:
            print("dostepne opcje:")
            for o in self.actions:
                print(f"- {o}")
            choice = input("wybierz akcje: ")
            while choice not in self.actions:
                print("zly wybor")
                choice = input("wybierz akcje: ")
            if self.actions[choice]():
                break


    def leave(self):
        return True

    def rest(self):
        print("odpoczywasz i odnawiasz sily.")
        self.player.hp += 10
        if self.player.hp > self.player.max_hp:
            self.player.hp = self.player.max_hp

    def explore(self):
        dice_roll = Dice.roll(6)
        if dice_roll <= 3:
            if self.monsters:
                os.system("cls")
                enemy_class = random.choice(self.monsters)
                enemy = enemy_class()
                print(f"napotykasz wroga: {enemy.name}")
                time.sleep(1)
                self.player.fight(enemy)
                if not self.player.is_alive():
                    return True
        elif dice_roll >=4 and self.loot_table:
            os.system("cls")
            item = random.choice(self.loot_table)
            print(f"znalazles: {item.name}")
            self.player.inventory.append(item)
            self.loot_table.remove(item)
            time.sleep(1)

    def __str__(self):
        return self.name
        pass

    def __repr__(self):
        return self.__str__()
        pass




forest = Location(
    "Las",
    "Gesty las pelen Goblinow.",
    [Goblin, Goblin, Orc],
    [Potion(), Weapon("Luk", 1)]
)
cave = Location(
    "Jaskinia",
    "Ciemna jaskinia. Czujesz pelno orkow.",
    [Goblin, Goblin, Orc],
    [Potion(), Weapon("Topor", 3)]
)


village = Location(
    "Wioska",
    "Spokojna wioska. Mozesz odpoczac.",
    [],
    [Potion(), Potion()]
)