fix: saving equipped items

This commit is contained in:
Matyáš Caras 2022-05-24 09:40:21 +02:00 committed by GitHub
parent b8ffa7871d
commit 6e55242fb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View file

@ -44,10 +44,10 @@ class FightHandler:
def show(self): def show(self):
system("cls||clear") system("cls||clear")
p = math.trunc(self.hp/self.max*10) p = math.trunc(self.hp/self.max*10)
h = "🟥"*p h = f"{Fore.RED}{Fore.RESET}"*p
j = math.trunc(self.my/30*10) j = math.trunc(self.my/30*10)
a = "🟩"*j a = f"{Fore.GREEN}{Fore.RESET}"*j
if str(p).endswith(".5"): if str(p).endswith(".5"):
h += "" h += ""
if str(a).endswith(".5"): if str(a).endswith(".5"):
@ -113,8 +113,12 @@ class FightHandler:
name = list(self.attacks[p].keys())[0] name = list(self.attacks[p].keys())[0]
enemyAtk = self.attacks[p][name]["atk"] enemyAtk = self.attacks[p][name]["atk"]
enemyDef = self.enemyDef enemyDef = self.enemyDef
playerAtk = self.equipped["weapon"].attack playerAtk = 0
playerDef = self.equipped["armor"].defense playerDef = 0
if self.equipped["weapon"] is not None:
playerAtk = self.equipped["weapon"].attack
if self.equipped["armor"] is not None:
playerDef = self.equipped["armor"].defense
c = enemyAtk - playerDef c = enemyAtk - playerDef
e = playerAtk - enemyDef e = playerAtk - enemyDef
@ -131,6 +135,7 @@ class FightHandler:
class FightMenu(MenuManager): # Upravené menu, které nemá input na konci, protože to jinak buguje class FightMenu(MenuManager): # Upravené menu, které nemá input na konci, protože to jinak buguje
def __init__(self,selections:list,additional:str): def __init__(self,selections:list,additional:str):
keyboard.remove_all_hotkeys()
self.selected = 0 self.selected = 0
self.selections = selections self.selections = selections
self.additional = additional self.additional = additional

View file

@ -169,6 +169,7 @@ class Game: # Hlavní třída, uchovává údaje o hře
elif (sel == len(actions_desc)-1): # Uložit a ukončit elif (sel == len(actions_desc)-1): # Uložit a ukončit
self.save.currentPrompt = self.current self.save.currentPrompt = self.current
self.save.inventory = self.inventory self.save.inventory = self.inventory
self.save.equipped = self.equipped
self.save.save() self.save.save()
exit(0) exit(0)
else: else:
@ -219,7 +220,7 @@ class Game: # Hlavní třída, uchovává údaje o hře
return newText return newText
def load(file_path,lang): # Načte hru z YAML souboru def load(file_path,lang): # Načte hru z YAML souboru
with open(file_path) as f: with open(file_path, encoding="utf-8") as f:
data = yaml.load(f,Loader=SafeLoader) data = yaml.load(f,Loader=SafeLoader)
g = Game(data,lang) g = Game(data,lang)
return g return g