Merge pull request #107 from ThomasRubini/startGame
This commit is contained in:
commit
320b733bfd
@ -14,21 +14,21 @@ def get_text_from_lid(lang: str, lid: int) -> str:
|
|||||||
texts = db.session.query(Text).filter_by(LANG=lang, LID=lid).all()
|
texts = db.session.query(Text).filter_by(LANG=lang, LID=lid).all()
|
||||||
return random.choice(texts).TEXT
|
return random.choice(texts).TEXT
|
||||||
|
|
||||||
def get_random_place() -> Place:
|
def get_random_places(n) -> Place:
|
||||||
"""
|
"""
|
||||||
Returns a random place from the database.
|
Returns a random place from the database.
|
||||||
|
|
||||||
:return: a Place object
|
:return: a Place object
|
||||||
"""
|
"""
|
||||||
return random.choice(db.session.query(Place).all())
|
return random.sample(db.session.query(Place).all(), n)
|
||||||
|
|
||||||
def get_random_npc() -> Npc :
|
def get_random_npcs(n: int = 1) -> Npc :
|
||||||
"""
|
"""
|
||||||
Returns a random npc from the database
|
Returns a random npc from the database
|
||||||
|
|
||||||
:return: a Npc object
|
:return: a Npc object
|
||||||
"""
|
"""
|
||||||
return random.choice(db.session.query(Npc).all())
|
return random.sample(db.session.query(Npc).all(), n)
|
||||||
|
|
||||||
def get_npc_random_trait_id(npc_id: int) -> int:
|
def get_npc_random_trait_id(npc_id: int) -> int:
|
||||||
"""
|
"""
|
||||||
|
@ -277,20 +277,12 @@ def generate_game_data(lang: str) -> tuple[dict, dict]:
|
|||||||
data = {}
|
data = {}
|
||||||
data["npcs"] = {}
|
data["npcs"] = {}
|
||||||
reactions_table = {}
|
reactions_table = {}
|
||||||
npcs = []
|
npcs = list(dbutils.get_random_npcs(5))
|
||||||
while len(npcs) != 5:
|
|
||||||
npc = dbutils.get_random_npc()
|
|
||||||
if npc not in npcs:
|
|
||||||
npcs.append(npc)
|
|
||||||
for npc in npcs:
|
for npc in npcs:
|
||||||
data["npcs"][str(npc.NPC_ID)] = generate_npc_text(npc, lang)
|
data["npcs"][str(npc.NPC_ID)] = generate_npc_text(npc, lang)
|
||||||
reactions_table[str(npc.NPC_ID)] = dbutils.get_npc_random_trait_id(npc)
|
reactions_table[str(npc.NPC_ID)] = dbutils.get_npc_random_trait_id(npc)
|
||||||
|
|
||||||
places = []
|
places = list(dbutils.get_random_places(3))
|
||||||
while len(places) != 3:
|
|
||||||
place = dbutils.get_random_place()
|
|
||||||
if place not in places:
|
|
||||||
places.append(place)
|
|
||||||
|
|
||||||
data["rooms"] = generate_place_data(npcs, places, lang)
|
data["rooms"] = generate_place_data(npcs, places, lang)
|
||||||
data["questions"] = {}
|
data["questions"] = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user