path-of-the-loner/database/databases/lootDB.py
2025-03-03 16:47:07 +01:00

50 lines
1.2 KiB
Python

# lootDB
from models.loots.loot import Loot
from models.heroes.monster import Monster
from models.heroes.hero import Hero
# pour éviter les pb d'import circulaire
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from database.mainDB import MainDB
class LootDB:
def __init__(self, db: "MainDB") -> None:
self.db = db
def get_loots_by_hero_and_loot_type(self, hero: Hero, loot_type: int) -> list:
query = """
SELECT l.*
FROM loots l
INNER JOIN characters_has_loots chl ON l.id = chl.loot_type
WHERE chl.character_type = ? AND l.types_id = ?;
"""
values = (hero.type, loot_type)
self.db.sql_query(query, values)
results = self.db.cursor.fetchall()
loots = []
for result in results:
loots.append(self.define_loot(result))
return loots
def define_loot(self, result: list) -> dict:
id = result[0]
title = result[1]
type = result[2]
loot_value = result[3]
value = result[4]
description = result[5]
drop_rate = result[6]
loot = Loot(title, description, type, loot_value, value, drop_rate)
loot.id = id
return loot