Skip to content

Commit f0e501a

Browse files
committed
feature(py): Populating storage enemies
1 parent 74bdc0c commit f0e501a

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from database import Database
2+
from utils import debug, error
3+
from colorama import Style
4+
import random
5+
6+
def enemie_storage(db: Database):
7+
8+
table_name = Style.BRIGHT + "ARMAZENAMENTO INIMIGO" + Style.NORMAL
9+
10+
try:
11+
db.cur.execute("SELECT id, vida_maxima FROM inimigo")
12+
inimigos = db.cur.fetchall()
13+
14+
db.cur.execute("SELECT id, tipo, nome, drop_inimigos_media FROM item")
15+
itens = db.cur.fetchall()
16+
17+
valores_insercao = []
18+
19+
for inimigo in inimigos:
20+
inimigo_id, vida_maxima = inimigo
21+
22+
if vida_maxima < 50:
23+
categoria = 1
24+
elif vida_maxima < 100:
25+
categoria = 2
26+
else:
27+
categoria = 3
28+
29+
for item in itens:
30+
item_id, tipo, nome, drop_inimigos_media = item
31+
32+
if categoria == 1:
33+
chance = random.randint(1, 3)
34+
elif categoria == 2:
35+
chance = random.randint(1, 6)
36+
else:
37+
chance = random.randint(1, 10)
38+
39+
if chance == 1:
40+
valores_insercao.append((inimigo_id, item_id))
41+
42+
db.cur.executemany(
43+
"""
44+
INSERT INTO armazenamento_inimigo (inimigo_id, armazenamento_id)
45+
VALUES (%s, %s)
46+
""", valores_insercao
47+
)
48+
49+
db.conn.commit()
50+
debug(f"default: {table_name} updated successfully!")
51+
52+
return len(valores_insercao)
53+
54+
except Exception as e:
55+
db.conn.rollback()
56+
error(f"default: error occurred while populating {table_name}: {e}")
57+
return 0

source/database/defaults/storage/storage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def storage(item_name: str, quantity: int, db: Database) -> int:
3131

3232
def populate_storage(db: Database):
3333

34-
table_name = Style.BRIGHT + "STORAGE" + Style.NORMAL
34+
table_name = Style.BRIGHT + "ARMAZENAMENTO" + Style.NORMAL
3535

3636
try:
3737
db.cur.execute("SELECT nome FROM item;")

source/default.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from database.defaults.npc.citizen import citizens, merchants, questers
99

10-
from database.defaults.storage import quest, storage
10+
from database.defaults.storage import quest, storage, enemie_storage
1111

1212
from database.defaults.map import regions as r, sub_regions as sr, sub_regions_connections as src
1313

@@ -63,8 +63,9 @@ def populate_database(db: Database):
6363

6464
writted_scroll.writted_scrolls(db, scrolls_id_start)
6565

66-
quest.quests(db)
6766
storage.populate_storage(db)
67+
enemie_storage.enemie_storage(db)
68+
quest.quests(db)
6869

6970
#potions
7071
potions.potions(db)

0 commit comments

Comments
 (0)