From 25f66d624b627934519b0ff8f4b562f51a956828 Mon Sep 17 00:00:00 2001 From: Cromha Date: Sat, 13 Jan 2024 19:00:28 +0100 Subject: [PATCH 1/7] progress[major] - first part of mission handling --- .github/workflows/cd.yaml | 8 ++-- compile.sh | 1 + data/dialog.yaml | 4 ++ data/mission.yaml | 12 +++-- docs/BUILDING.md | 1 + schemas/missions.yaml | 13 ++++++ source/main.py | 66 +++++++++++++++++++++++++++- source/mission_handling.py | 90 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 schemas/missions.yaml create mode 100644 source/mission_handling.py diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 9d30854..94dacce 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -42,7 +42,7 @@ jobs: pip install -r requirements.txt pip install PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec mv dist/Bane-Of-Wargs Bane-Of-Wargs-Linux - name: Upload artifact uses: actions/upload-artifact@v3 @@ -77,7 +77,7 @@ jobs: pip install -r requirements.txt pip install PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs mv dist/Bane-Of-Wargs Bane-Of-Wargs-Mac - name: Upload artifact uses: actions/upload-artifact@v3 @@ -112,7 +112,7 @@ jobs: pip install -r requirements.txt pip install windows-curses PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec mv dist/Bane-Of-Wargs.exe Bane-Of-Wargs.exe - name: Upload artifact uses: actions/upload-artifact@v3 @@ -165,7 +165,7 @@ jobs: - name: Download Artifacts uses: actions/download-artifact@v3 with: - path: ${{ github.workspace }} + path: ${{ github.workspace }} - name: Add ${{ env.OUTPUT_LINUX }} to release tag continue-on-error: true run: | diff --git a/compile.sh b/compile.sh index da4c2cd..8eebf0c 100755 --- a/compile.sh +++ b/compile.sh @@ -12,6 +12,7 @@ source/map_item.py \ source/train.py \ source/logger_sys.py \ source/term_menu.py \ +source/mission_handling.py \ --add-data yamale/VERSION:yamale \ --collect-submodules fsspec \ --collect-submodules appdirs \ diff --git a/data/dialog.yaml b/data/dialog.yaml index 40fa6e2..d160073 100644 --- a/data/dialog.yaml +++ b/data/dialog.yaml @@ -61,3 +61,7 @@ generic steel gate blocking east: - "You must find the key to open it!" scene: Steel Gate +first mission: + use actions: False + phrases: + - "First mission! yay!" diff --git a/data/mission.yaml b/data/mission.yaml index d967893..38b59a4 100644 --- a/data/mission.yaml +++ b/data/mission.yaml @@ -1,3 +1,9 @@ -Hunt Down Yrch Covet: - name: "Hunt Down Yrch Covet" - description: "" +First Mission: + name: "First Mission" + description: "Go to $destination" + source: 0 + destination: 5 + on offer: + dialog: "first mission" + on complete: + dialog: "first mission" diff --git a/docs/BUILDING.md b/docs/BUILDING.md index e169d86..cb6e74f 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -53,6 +53,7 @@ source/map_item.py \ source/train.py \ source/logger_sys.py \ source/term_menu.py \ +source/mission_handling.py \ --add-data yamale/VERSION:yamale \ --collect-submodules fsspec \ --collect-submodules appdirs \ diff --git a/schemas/missions.yaml b/schemas/missions.yaml new file mode 100644 index 0000000..cc4f186 --- /dev/null +++ b/schemas/missions.yaml @@ -0,0 +1,13 @@ +name: str() +description: str() +deadline: int(required=False) +stopovers: list(int(required=False)) +to offer: any(required=False) +to complete: any(required=False) +to fail: any(required=False) +source: int() +destination: int() +on offer: any(required=False) +on complete: any(required=False) +on fail: any(required=False) +enemies: any(required=False) diff --git a/source/main.py b/source/main.py index a8595df..5e6de12 100644 --- a/source/main.py +++ b/source/main.py @@ -5,6 +5,7 @@ import train import map_item import term_menu +import mission_handling import os import sys import time @@ -2160,7 +2161,7 @@ def run(play): print("ELAPSED DAYS: " + COLOR_STYLE_BRIGHT + COLOR_MAGENTA + str(round(player["elapsed time game days"], 1)) + COLOR_RESET_ALL) text = '=' print_separator(text) - options = ['Visited Places', 'Encountered Monsters', 'Encountered People'] + options = ['Visited Places', 'Encountered Monsters', 'Encountered People', 'Tasks'] choice = term_menu.show_menu(options) logger_sys.log_message(f"INFO: Playing has chosen option '{choice}'") if choice == 'Visited Places': @@ -2489,6 +2490,69 @@ def run(play): print(COLOR_YELLOW + "You don't know about that enemy." + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player doesn't know about npc '{which_npc}' --> canceling") time.sleep(1.5) + elif choice == 'Tasks': + print("ACTIVE TASKS:") + tasks_list = player["active missions"] + logger_sys.log_message(f"INFO: Printing player active missions: '{tasks_list}'") + + count = 0 + while count < len(tasks_list): + current_task = tasks_list[count] + current_task_name = mission[str(current_task)]["name"] + tasks_list.remove(current_task) + tasks_list.append(current_task_name) + + count += 1 + + tasks_list_str = str(tasks_list) + tasks_list_str = tasks_list_str.replace("'None', ", '') + tasks_list_str = tasks_list_str.replace("'", '') + tasks_list_str = tasks_list_str.replace("[", ' -') + tasks_list_str = tasks_list_str.replace("]", '') + tasks_list_str = tasks_list_str.replace(", ", '\n -') + + print(tasks_list_str) + text = '=' + print_separator(text) + which_task = input("> ") + logger_sys.log_message(f"INFO: Player has chosen task '{which_task}' to display information about") + if which_task in tasks_list: + logger_sys.log_message(f"INFO: Printing mission '{which_task}' information") + + mission_id = mission_handling.get_mission_id_from_name(which_task, mission) + + text = '=' + print_separator(text) + print("NAME: " + mission[mission_id]["name"]) + print("DESCRIPTION:") + mission_handling.print_description(mission[mission_id], map) + + destination_point = map["point" + str(mission[mission_id]["destination"])] + destination = str("X:" + COLOR_GREEN + COLOR_STYLE_BRIGHT + str(destination_point["x"]) + COLOR_RESET_ALL + ", Y:" + COLOR_GREEN + COLOR_STYLE_BRIGHT + str(destination_point["x"]) + COLOR_RESET_ALL) + + print("") + print("DESTINATION: " + destination) + if 'stopovers' in list(mission[mission_id]): + mission_stopovers = mission[mission_id]["stopovers"] + new_mission_stopovers = [] + count = 0 + while count < len(mission_stopovers): + current_map_point_data = map["point" + str(mission_stopovers[count])] + current_map_point_coordinates = "[X:" + str(current_map_point_data["x"]) + ",Y:" + str(current_map_point_data["y"]) +"]" + new_mission_stopovers.append(current_map_point_coordinates) + + count += 1 + new_mission_stopovers = str(new_mission_stopovers) + print("STOPOVERS: " + new_mission_stopovers) + + text = '=' + print_separator(text) + wait = input("") + else: + print("") + print(COLOR_YELLOW + "You do not currently have a mission named like that" + COLOR_RESET_ALL) + logger_sys.log_message(f"INFO: Player doesn't know about mission '{which_task}' --> canceling") + time.sleep(1.5) elif command.lower().startswith('i'): text = '=' print_separator(text) diff --git a/source/mission_handling.py b/source/mission_handling.py new file mode 100644 index 0000000..597609c --- /dev/null +++ b/source/mission_handling.py @@ -0,0 +1,90 @@ +import yaml +import term_menu +import logger_sys +import os +from colorama import Fore, Back, Style, deinit, init +from colors import * + +# initialize colorama +init() + + +# Functions to handle missions +def get_mission_id_from_name(mission_name, mission_data): + global mission_id + count = 0 + continue_action = True + + while count < len(list(mission_data)) and continue_action == True: + current_mission_data = mission_data[str(list(mission_data)[count])] + if current_mission_data["name"] == mission_name: + continue_action = False + mission_id = str(list(mission_data)[count]) + + count += 1 + return mission_id + +def print_description(mission_data, map): + + # Get text replacements + # Payment of the mission when completed + payment_for_mission = None + if "on complete" in list(mission_data): + if "payment" in list(mission_data["on complete"]): + payment_for_mission = mission_data["on complete"]["payment"] + # Destination of the mission + destination_point = map["point" + str(mission_data["destination"])] + destination_for_mission = "[X:" + str(destination_point["x"]) + ", Y:" + str(destination_point["y"]) + "]" + # Deadline of the mission to be completed + deadline_for_mission = None + if "deadline" in list(mission_data): + deadline_for_mission = mission_data["deadline"] + # Stopovers of the mission + stopovers_for_mission = None + if "stopovers" in list(mission_data): + stopovers_for_mission = mission_data["stopovers"] + new_stopovers_for_mission = [] + count = 0 + while count < len(stopovers_for_mission): + current_map_point_data = map["point" + str(stopovers_for_mission[count])] + current_map_point_coordinates = "[X:" + str(current_map_point_data["x"]) + ", Y:" + str(current_map_point_data["y"]) + "]" + new_stopovers_for_mission.append(current_map_point_coordinates) + + count += 1 + new_stopovers_for_mission = str(new_stopovers_for_mission) + + # Load text replacements + mission_text_replacements = { + "$name_mission": mission_data["name"], + "$description": mission_data["description"], + "$payment": payment_for_mission, + "$destination": destination_for_mission, + "$deadline": deadline_for_mission, + "$stopovers": new_stopovers_for_mission + } + + + text = str(mission_data["description"]) + # Replace text replacement in the description by + # its corresponding value in the mission_text_replacements + # dictionary defined sooner + count = 0 + while count < len(list(mission_text_replacements)): + current_text_replacement = list(mission_text_replacements)[count] + text = text.replace(current_text_replacement, str(mission_text_replacements[current_text_replacement])) + + count += 1 + + # Print the text + new_input = "" + for i, letter in enumerate(text): + if i % 54 == 0: + new_input += '\n' + new_input += letter + + # This is just because at the beginning too a `\n` character gets added + new_input = new_input[1:] + print(str(new_input)) + +# deinitialize colorama +deinit() From 6c3c11aa278aaf1309ef5ba7f85220fa3fd4d0d1 Mon Sep 17 00:00:00 2001 From: Cromha Date: Sat, 13 Jan 2024 19:01:19 +0100 Subject: [PATCH 2/7] tweak[minor] - made the `> ` cursor when asking for player input flashy green like selection menus --- source/battle.py | 6 +++--- source/main.py | 22 +++++++++++----------- source/train.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/battle.py b/source/battle.py index c9a83e1..016b268 100644 --- a/source/battle.py +++ b/source/battle.py @@ -267,7 +267,7 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin print_separator(text) print(" ") - startup_action = input("> ") + startup_action = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) print("") text = '=' @@ -294,7 +294,7 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin player_inventory = player_inventory.replace(", ", '\n -') print("INVENTORY:") print(player_inventory) - item_input = input("> ") + item_input = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) # use item if item_input in player["inventory"]: if item[item_input]["type"] == "Consumable" or item[item_input]["type"] == "Food": @@ -457,7 +457,7 @@ def fight(player, item, enemy, map, map_location, enemies_remaining, lists): print_separator(text) print("INVENTORY:") print(player_inventory) - item_input = input("> ") + item_input = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) # use item if item_input in player["inventory"]: if item[item_input]["type"] == "Consumable" or item[item_input]["type"] == "Food": diff --git a/source/main.py b/source/main.py index 5e6de12..5ad0baa 100644 --- a/source/main.py +++ b/source/main.py @@ -2081,7 +2081,7 @@ def run(play): player = start_player play = 0 return play - command = input("> ") + command = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) print(" ") logger_sys.log_message(f"INFO: Player ran command '{command}'") logger_sys.log_message(f"INFO: Checking if a ground item is present at map point 'point{map_location}'") @@ -2175,7 +2175,7 @@ def run(play): print(zones_list) text = '=' print_separator(text) - which_zone = input("> ") + which_zone = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen zone '{which_zone}' to check") if which_zone in player["visited zones"]: logger_sys.log_message(f"INFO: Printing zone '{which_zone}' information to GUI") @@ -2381,7 +2381,7 @@ def run(play): print(enemies_list) text = '=' print_separator(text) - which_enemy = input("> ") + which_enemy = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen enemy '{which_enemy}' to display information") if which_enemy == "None": print(" ") @@ -2435,7 +2435,7 @@ def run(play): print(enemies_list) text = '=' print_separator(text) - which_npc = input("> ") + which_npc = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen npc '{which_npc}' to display information about") if which_npc == "None": print(" ") @@ -2514,7 +2514,7 @@ def run(play): print(tasks_list_str) text = '=' print_separator(text) - which_task = input("> ") + which_task = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen task '{which_task}' to display information about") if which_task in tasks_list: logger_sys.log_message(f"INFO: Printing mission '{which_task}' information") @@ -2586,7 +2586,7 @@ def run(play): print(player_inventory) text = '=' print_separator(text) - which_item = input("> ") + which_item = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen item '{which_item}' to display information about") if which_item in player["inventory"]: text = '=' @@ -2901,7 +2901,7 @@ def run(play): remove_gold(str(mount_cost)) generated_mount_uuid = generate_random_uuid() print("How you mount should be named ?") - new_mount_name = input("> ") + new_mount_name = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen name '{new_mount_name}' for its new mount") mounts_names_list = [] count = 0 @@ -3007,7 +3007,7 @@ def run(play): print(deposited_mounts_names) text = '=' print_separator(text) - which_mount = input("> ") + which_mount = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen mount '{which_mount}' to ride") if which_mount in deposited_mounts_names_list: # get what is the uuid of the mount of this name @@ -3210,7 +3210,7 @@ def run(play): print(player_orders_to_collect) text = '=' print_separator(text) - which_order = input("> ") + which_order = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen order '{which_order}'") if which_order in player_orders_number: current_order_uuid = str(list(player["orders"])[int(which_order)]) @@ -3353,7 +3353,7 @@ def run(play): print(mounts_names_list_str) text = '=' print_separator(text) - which_mount = input("> ") + which_mount = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen option '{which_mount}' to examine") if which_mount in mounts_names_list: text = '=' @@ -3427,7 +3427,7 @@ def run(play): player["current mount"] = " " elif choice == 'Rename': print("Select a new name for your mount") - new_name = input("> ") + new_name = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) logger_sys.log_message(f"INFO: Player has chosen as a new name for mount '{which_mount}' '{new_name}'") if new_name in mounts_names_list: logger_sys.log_message("INFO: Canceling mount renaming process --> already has a mount name like hat") diff --git a/source/train.py b/source/train.py index 909a6b3..e4aeb34 100644 --- a/source/train.py +++ b/source/train.py @@ -59,7 +59,7 @@ def training_loop(mount_uuid, player, item, mounts, stable): print("FEEDING ITEMS:") print(player_feeding_items_text) print_separator(text) - which_food = str(input("> ")) + which_food = str(input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL)) if which_food in player_feeding_items and which_food in player["inventory"]: player["inventory"].remove(which_food) player["xp"] += random.randint(1, 4) From d9d13fba85e10dc30076f2f440a83d06cfeb9c2d Mon Sep 17 00:00:00 2001 From: Cromha Date: Sun, 14 Jan 2024 07:52:44 +0100 Subject: [PATCH 3/7] progress - progressed in the mission handling offering part --- .github/workflows/cd.yaml | 6 +- compile.sh | 1 + data/dialog.yaml | 5 - docs/BUILDING.md | 1 + source/dialog_handling.py | 204 ++++++++++++++++++++++++++++++++++++ source/main.py | 205 +++++-------------------------------- source/mission_handling.py | 41 ++++++++ 7 files changed, 277 insertions(+), 186 deletions(-) create mode 100644 source/dialog_handling.py diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 94dacce..1d82829 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -42,7 +42,7 @@ jobs: pip install -r requirements.txt pip install PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec mv dist/Bane-Of-Wargs Bane-Of-Wargs-Linux - name: Upload artifact uses: actions/upload-artifact@v3 @@ -77,7 +77,7 @@ jobs: pip install -r requirements.txt pip install PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs mv dist/Bane-Of-Wargs Bane-Of-Wargs-Mac - name: Upload artifact uses: actions/upload-artifact@v3 @@ -112,7 +112,7 @@ jobs: pip install -r requirements.txt pip install windows-curses PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec mv dist/Bane-Of-Wargs.exe Bane-Of-Wargs.exe - name: Upload artifact uses: actions/upload-artifact@v3 diff --git a/compile.sh b/compile.sh index 8eebf0c..3b89ee5 100755 --- a/compile.sh +++ b/compile.sh @@ -13,6 +13,7 @@ source/train.py \ source/logger_sys.py \ source/term_menu.py \ source/mission_handling.py \ +source/dialog_handling.py \ --add-data yamale/VERSION:yamale \ --collect-submodules fsspec \ --collect-submodules appdirs \ diff --git a/data/dialog.yaml b/data/dialog.yaml index d160073..4ffab9c 100644 --- a/data/dialog.yaml +++ b/data/dialog.yaml @@ -60,8 +60,3 @@ generic steel gate blocking east: - "There is a strong steel gate blocking anyone wanting to go further east." - "You must find the key to open it!" scene: Steel Gate - -first mission: - use actions: False - phrases: - - "First mission! yay!" diff --git a/docs/BUILDING.md b/docs/BUILDING.md index cb6e74f..cf9c728 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -54,6 +54,7 @@ source/train.py \ source/logger_sys.py \ source/term_menu.py \ source/mission_handling.py \ +source/dialog_handling.py \ --add-data yamale/VERSION:yamale \ --collect-submodules fsspec \ --collect-submodules appdirs \ diff --git a/source/dialog_handling.py b/source/dialog_handling.py new file mode 100644 index 0000000..c033387 --- /dev/null +++ b/source/dialog_handling.py @@ -0,0 +1,204 @@ +import logger_sys +import appdirs +import sys +import time +import random +from colorama import Fore, Back, Style, deinit, init +from colors import * + +# Initialize colorama +init() + +# Get program directory +program_dir = str(appdirs.user_config_dir(appname='Bane-Of-Wargs')) + +# Functions to handle dialogs +def print_speech_text_effect(text, preferences): + text = str(text) + "\n" + new_input = "" + for i, letter in enumerate(text): + if i % 54 == 0: + new_input += '\n' + new_input += letter + if preferences["speed up"] == False: + for character in new_input: + sys.stdout.write(character) + sys.stdout.flush() + time.sleep(round(random.uniform(.05, .1), 2)) + else: + for character in new_input: + sys.stdout.write(character) + sys.stdout.flush() + time.sleep(.02) + +def print_dialog(current_dialog, dialog, preferences, text_replacements_generic, player, drinks): + current_dialog_name = current_dialog + logger_sys.log_message(f"INFO: Printing dialog '{current_dialog_name}'") + current_dialog = dialog[str(current_dialog)] + dialog_len = len(current_dialog["phrases"]) + if "scene" in current_dialog: + current_dialog_scene = str(current_dialog["scene"]) + logger_sys.log_message(f"INFO: Printing dialog '{current_dialog_name}' scene at '{program_dir}/game/imgs/{current_dialog_scene}.txt'") + if preferences["latest preset"]["type"] == 'vanilla': + with open(program_dir + '/game/imgs/' + str(current_dialog["scene"]) + '.txt') as f: + to_print = str(f.read()) + to_print = to_print.replace('$RED', '\033[0;31m') + to_print = to_print.replace('$GREEN', '\033[0;32m') + to_print = to_print.replace('$YELLOW', '\033[0;33m') + to_print = to_print.replace('$BLUE', '\033[0;34m') + to_print = to_print.replace('$PURPLE', '\033[0;34m') + to_print = to_print.replace('$CYAN', '\033[0;36m') + to_print = to_print.replace('$WHITE', '\033[0;37m') + to_print = to_print.replace('$BLACK', '\033[0;30m') + to_print = to_print.replace('$BROWN', '\033[0;33m') + to_print = to_print.replace('$GRAY', '\033[1;30m') + print(to_print) + else: + current_plugin = str(preferences["latest preset"]["plugin"]) + logger_sys.log_message(f"INFO: Printing dialog '{current_dialog_name}' scene at '{program_dir}/plugins/{current_plugin}/imgs/{current_dialog_scene}.txt'") + with open(program_dir + '/plugins/' + str(preferences["latest preset"]["plugin"]) + '/imgs/' + str(current_dialog["scene"]) + '.txt') as f: + to_print = str(f.read()) + to_print = to_print.replace('$RED', '\033[0;31m') + to_print = to_print.replace('$GREEN', '\033[0;32m') + to_print = to_print.replace('$YELLOW', '\033[0;33m') + to_print = to_print.replace('$BLUE', '\033[0;34m') + to_print = to_print.replace('$PURPLE', '\033[0;34m') + to_print = to_print.replace('$CYAN', '\033[0;36m') + to_print = to_print.replace('$WHITE', '\033[0;37m') + to_print = to_print.replace('$BLACK', '\033[0;30m') + to_print = to_print.replace('$BROWN', '\033[0;33m') + to_print = to_print.replace('$GRAY', '\033[1;30m') + print(to_print) + count = 0 + logger_sys.log_message(f"INFO: Printing dialog '{current_dialog_name}' phrases") + while count < dialog_len: + text = str(current_dialog["phrases"][int(count)]) + count = 0 + while count < len(list(text_replacements_generic)): + current_text_replacement = str(list(text_replacements_generic)[count]) + text = text.replace(current_text_replacement, str(text_replacements_generic[current_text_replacement])) + count += 1 + print_speech_text_effect(text, preferences) + count += 1 + if current_dialog["use actions"] == True: + logger_sys.log_message(f"INFO: Executing dialog '{current_dialog_name}' actions on the player") + actions = current_dialog["actions"] + if "give item" in actions: + given_items = actions["give item"] + given_items_len = len(given_items) + count = 0 + logger_sys.log_message(f"INFO: Giving to the player items '{given_items}'") + while count < given_items_len: + selected_item = given_items[count] + player["inventory"].append(selected_item) + count += 1 + if "add attributes" in actions: + count = 0 + added_attributes = actions["add attributes"] + added_attributes_len = len(added_attributes) + logger_sys.log_message(f"INFO: Adding attributes '{added_attributes}' to the player") + while count < added_attributes_len: + selected_attribute = added_attributes[count] + player["attributes"].append(selected_attribute) + count += 1 + if "health modification" in actions: + if "diminution" in actions["health modification"]: + logger_sys.log_message("INFO: Removing " + actions["health modification"]["diminution"] + " hp from the player's health") + player["health"] -= actions["health modification"]["diminution"] + if "augmentation" in actions["health modification"]: + logger_sys.log_message("INFO: Adding " + actions["health modification"]["augmentation"] + " hp from the player's health") + player["health"] += actions["health modification"]["augmentation"] + if "max health" in actions["health modification"]: + if "diminution" in actions["health modification"]["max health"]: + logger_sys.log_message("INFO: Removing " + actions["health modification"]["max health"]["diminution"] + " hp from the player's max health") + player["max health"] -= actions["health modification"]["max health"]["diminution"] + if "augmentation" in actions["health modification"]["max health"]: + logger_sys.log_message("INFO: Adding " + actions["health modification"]["max health"]["augmentation"] + " hp from the player's max health") + player["max health"] += actions["health modification"]["max health"]["augmentation"] + if "gold modification" in actions: + if "diminution" in actions["gold modification"]: + logger_sys.log_message("INFO: Removing " + actions["gold modification"]["diminution"] + " gold to the player") + player["gold"] -= actions["gold modification"]["diminution"] + if "augmentation" in actions["gold modification"]: + logger_sys.log_message("INFO: Adding " + actions["gold modification"]["diminution"] + " gold to the player") + player["gold"] += actions["gold modification"]["augmentation"] + if "remove item" in actions: + removed_items = actions["remove item"] + removed_items_len = len(removed_items) + count = 0 + logger_sys.log_message(f"INFO: Removing items '{removed_items}' from player's inventory") + while count < removed_items_len: + selected_item = removed_items[count] + player["inventory"].remove(selected_item) + count += 1 + if "add to diary" in actions: + if "known zones" in actions["add to diary"]: + added_visited_zones = actions["add to diary"]["known zones"] + added_visited_zones_len = len(added_visited_zones) + count = 0 + logger_sys.log_message(f"INFO: Adding zones '{added_visited_zones}' to player's visited zones") + while count < added_visited_zones_len: + selected_zone = added_visited_zones[count] + player["visited zones"].append(selected_zone) + count += 1 + if "known enemies" in actions["add to diary"]: + added_known_enemies = actions["add to diary"]["known enemies"] + added_known_enemies_len = len(added_known_enemies) + count = 0 + logger_sys.log_message(f"INFO: Adding enemies '{added_known_enemies}' to player's known enemies") + while count < added_known_enemies_len: + selected_enemy = added_known_enemies[count] + player["enemies list"].append(selected_enemy) + count += 1 + if "known npcs" in actions["add to diary"]: + added_known_npcs = actions["add to diary"]["known npcs"] + added_known_npcs_len = len(added_known_npcs) + count = 0 + logger_sys.log_message(f"INFO: Adding npcs '{added_known_npcs}' to player's known npcs") + while count < added_known_npcs_len: + selected_npc = added_known_npcs[count] + player["met npcs name"].append(selected_npc) + count += 1 + if "remove to diary" in actions: + if "known zones" in actions["remove to diary"]: + removed_visited_zones = actions["remove to diary"]["known zones"] + removed_visited_zones_len = len(removed_visited_zones) + count = 0 + logger_sys.log_message(f"INFO: Removing zones '{added_visited_zones}' to player's visited zones") + while count < removed_visited_zones_len: + selected_zone = removed_visited_zones[count] + player["visited zones"].remove(selected_zone) + count += 1 + if "known enemies" in actions["remove to diary"]: + removed_known_enemies = actions["remove to diary"]["known enemies"] + removed_known_enemies_len = len(removed_known_enemies) + count = 0 + logger_sys.log_message(f"INFO: Removing enemies '{added_known_enemies}' to player's known enemies") + while count < removed_known_enemies_len: + selected_enemy = removed_known_npcs[count] + player["enemies list"].remove(selected_enemy) + count += 1 + if "known npcs" in actions["remove to diary"]: + removed_known_npcs = actions["remove to diary"]["known npcs"] + removed_known_npcs_len = len(removed_known_npcs) + count = 0 + logger_sys.log_message(f"INFO: Removing npcs '{added_known_npcs}' to player's known npcs") + while count < removed_known_npcs_len: + selected_npc = removed_known_npcs[count] + player["met npcs name"].append(selected_npc) + count += 1 + if "use drink" in actions: + used_drinks = actions["use drink"] + used_drinks_len = len(used_drinks) + count = 0 + logger_sys.log_message(f"INFO: Using drinks '{used_drinks}'") + while count < used_drinks_len: + selected_drink = used_drinks_len[count] + if drinks[selected_drink]["healing level"] == 999: + player["health"] = player["max health"] + else: + player["health"] += drinks[selected_drink]["healing level"] + + +# Deinitialize colorama +deinit() diff --git a/source/main.py b/source/main.py index 5ad0baa..0d260d9 100644 --- a/source/main.py +++ b/source/main.py @@ -6,6 +6,7 @@ import map_item import term_menu import mission_handling +import dialog_handling import os import sys import time @@ -905,174 +906,6 @@ def print_long_string(text): } logger_sys.log_message(f"INFO: Loaded generic texts replacements: '{text_replacements_generic}'") -def print_dialog(current_dialog): - current_dialog_name = current_dialog - logger_sys.log_message(f"INFO: Printing dialog '{current_dialog_name}'") - current_dialog = dialog[str(current_dialog)] - dialog_len = len(current_dialog["phrases"]) - if "scene" in current_dialog: - current_dialog_scene = str(current_dialog["scene"]) - logger_sys.log_message(f"INFO: Printing dialog '{current_dialog_name}' scene at '{program_dir}/game/imgs/{current_dialog_scene}.txt'") - if preferences["latest preset"]["type"] == 'vanilla': - with open(program_dir + '/game/imgs/' + str(current_dialog["scene"]) + '.txt') as f: - to_print = str(f.read()) - to_print = to_print.replace('$RED', '\033[0;31m') - to_print = to_print.replace('$GREEN', '\033[0;32m') - to_print = to_print.replace('$YELLOW', '\033[0;33m') - to_print = to_print.replace('$BLUE', '\033[0;34m') - to_print = to_print.replace('$PURPLE', '\033[0;34m') - to_print = to_print.replace('$CYAN', '\033[0;36m') - to_print = to_print.replace('$WHITE', '\033[0;37m') - to_print = to_print.replace('$BLACK', '\033[0;30m') - to_print = to_print.replace('$BROWN', '\033[0;33m') - to_print = to_print.replace('$GRAY', '\033[1;30m') - print(to_print) - else: - current_plugin = str(preferences["latest preset"]["plugin"]) - logger_sys.log_message(f"INFO: Printing dialog '{current_dialog_name}' scene at '{program_dir}/plugins/{current_plugin}/imgs/{current_dialog_scene}.txt'") - with open(program_dir + '/plugins/' + str(preferences["latest preset"]["plugin"]) + '/imgs/' + str(current_dialog["scene"]) + '.txt') as f: - to_print = str(f.read()) - to_print = to_print.replace('$RED', '\033[0;31m') - to_print = to_print.replace('$GREEN', '\033[0;32m') - to_print = to_print.replace('$YELLOW', '\033[0;33m') - to_print = to_print.replace('$BLUE', '\033[0;34m') - to_print = to_print.replace('$PURPLE', '\033[0;34m') - to_print = to_print.replace('$CYAN', '\033[0;36m') - to_print = to_print.replace('$WHITE', '\033[0;37m') - to_print = to_print.replace('$BLACK', '\033[0;30m') - to_print = to_print.replace('$BROWN', '\033[0;33m') - to_print = to_print.replace('$GRAY', '\033[1;30m') - print(to_print) - count = 0 - logger_sys.log_message(f"INFO: Printing dialog '{current_dialog_name}' phrases") - while count < dialog_len: - text = str(current_dialog["phrases"][int(count)]) - count = 0 - while count < len(list(text_replacements_generic)): - current_text_replacement = str(list(text_replacements_generic)[count]) - text = text.replace(current_text_replacement, str(text_replacements_generic[current_text_replacement])) - count += 1 - print_speech_text_effect(text) - count += 1 - if current_dialog["use actions"] == True: - logger_sys.log_message(f"INFO: Executing dialog '{current_dialog_name}' actions on the player") - actions = current_dialog["actions"] - if "give item" in actions: - given_items = actions["give item"] - given_items_len = len(given_items) - count = 0 - logger_sys.log_message(f"INFO: Giving to the player items '{give_items}'") - while count < given_items_len: - selected_item = given_items[count] - player["inventory"].append(selected_item) - count += 1 - if "add attributes" in actions: - count = 0 - added_attributes = actions["add attributes"] - added_attributes_len = len(added_attributes) - logger_sys.log_message(f"INFO: Adding attributes '{added_attributes}' to the player") - while count < added_attributes_len: - selected_attribute = added_attributes[count] - player["attributes"].append(selected_attribute) - count += 1 - if "health modification" in actions: - if "diminution" in actions["health modification"]: - logger_sys.log_message("INFO: Removing " + actions["health modification"]["diminution"] + " hp from the player's health") - player["health"] -= actions["health modification"]["diminution"] - if "augmentation" in actions["health modification"]: - logger_sys.log_message("INFO: Adding " + actions["health modification"]["augmentation"] + " hp from the player's health") - player["health"] += actions["health modification"]["augmentation"] - if "max health" in actions["health modification"]: - if "diminution" in actions["health modification"]["max health"]: - logger_sys.log_message("INFO: Removing " + actions["health modification"]["max health"]["diminution"] + " hp from the player's max health") - player["max health"] -= actions["health modification"]["max health"]["diminution"] - if "augmentation" in actions["health modification"]["max health"]: - logger_sys.log_message("INFO: Adding " + actions["health modification"]["max health"]["augmentation"] + " hp from the player's max health") - player["max health"] += actions["health modification"]["max health"]["augmentation"] - if "gold modification" in actions: - if "diminution" in actions["gold modification"]: - logger_sys.log_message("INFO: Removing " + actions["gold modification"]["diminution"] + " gold to the player") - player["gold"] -= actions["gold modification"]["diminution"] - if "augmentation" in actions["gold modification"]: - logger_sys.log_message("INFO: Adding " + actions["gold modification"]["diminution"] + " gold to the player") - player["gold"] += actions["gold modification"]["augmentation"] - if "remove item" in actions: - removed_items = actions["remove item"] - removed_items_len = len(removed_items) - count = 0 - logger_sys.log_message(f"INFO: Removing items '{removed_items}' from player's inventory") - while count < removed_items_len: - selected_item = removed_items[count] - player["inventory"].remove(selected_item) - count += 1 - if "add to diary" in actions: - if "known zones" in actions["add to diary"]: - added_visited_zones = actions["add to diary"]["known zones"] - added_visited_zones_len = len(added_visited_zones) - count = 0 - logger_sys.log_message(f"INFO: Adding zones '{added_visited_zones}' to player's visited zones") - while count < added_visited_zones_len: - selected_zone = added_visited_zones[count] - player["visited zones"].append(selected_zone) - count += 1 - if "known enemies" in actions["add to diary"]: - added_known_enemies = actions["add to diary"]["known enemies"] - added_known_enemies_len = len(added_known_enemies) - count = 0 - logger_sys.log_message(f"INFO: Adding enemies '{added_known_enemies}' to player's known enemies") - while count < added_known_enemies_len: - selected_enemy = added_known_enemies[count] - player["enemies list"].append(selected_enemy) - count += 1 - if "known npcs" in actions["add to diary"]: - added_known_npcs = actions["add to diary"]["known npcs"] - added_known_npcs_len = len(added_known_npcs) - count = 0 - logger_sys.log_message(f"INFO: Adding npcs '{added_known_npcs}' to player's known npcs") - while count < added_known_npcs_len: - selected_npc = added_known_npcs[count] - player["met npcs name"].append(selected_npc) - count += 1 - if "remove to diary" in actions: - if "known zones" in actions["remove to diary"]: - removed_visited_zones = actions["remove to diary"]["known zones"] - removed_visited_zones_len = len(removed_visited_zones) - count = 0 - logger_sys.log_message(f"INFO: Removing zones '{added_visited_zones}' to player's visited zones") - while count < removed_visited_zones_len: - selected_zone = removed_visited_zones[count] - player["visited zones"].remove(selected_zone) - count += 1 - if "known enemies" in actions["remove to diary"]: - removed_known_enemies = actions["remove to diary"]["known enemies"] - removed_known_enemies_len = len(removed_known_enemies) - count = 0 - logger_sys.log_message(f"INFO: Removing enemies '{added_known_enemies}' to player's known enemies") - while count < removed_known_enemies_len: - selected_enemy = removed_known_npcs[count] - player["enemies list"].remove(selected_enemy) - count += 1 - if "known npcs" in actions["remove to diary"]: - removed_known_npcs = actions["remove to diary"]["known npcs"] - removed_known_npcs_len = len(removed_known_npcs) - count = 0 - logger_sys.log_message(f"INFO: Removing npcs '{added_known_npcs}' to player's known npcs") - while count < removed_known_npcs_len: - selected_npc = removed_known_npcs[count] - player["met npcs name"].append(selected_npc) - count += 1 - if "use drink" in actions: - used_drinks = actions["use drink"] - used_drinks_len = len(used_drinks) - count = 0 - logger_sys.log_message(f"INFO: Using drinks '{used_drinks}'") - while count < used_drinks_len: - selected_drink = used_drinks_len[count] - if drinks[selected_drink]["healing level"] == 999: - player["health"] = player["max health"] - else: - player["health"] += drinks[selected_drink]["healing level"] - def generate_random_uuid(): logger_sys.log_message("INFO: Generating new random UUID using 'uuid.4' method") import uuid @@ -1523,7 +1356,7 @@ def run(play): if player["start dialog"]["heard start dialog"] == False: start_dialog = player["start dialog"]["dialog"] logger_sys.log_message("INFO: Displaying start dialog '{start_dialog}' to player") - print_dialog(player["start dialog"]["dialog"]) + dialog_handling.print_dialog(player["start dialog"]["dialog"], dialog, preferences, text_replacements_generic, player, drinks) text = '=' print_separator(text) @@ -1600,7 +1433,7 @@ def run(play): count += 1 if has_required_attributes and has_required_locations and has_required_enemies and has_required_npcs: logger_sys.log_message(f"INFO: Player has all required stuff to display dialog '{current_dialog}' --> displaying it and adding map location '{map_location}' to the player's heard dialogs save list") - print_dialog(current_dialog) + dialog_handling.print_dialog(current_dialog, dialog, preferences, text_replacements_generic, player, drinks) player["heard dialogs"].append(map_location) text = '=' print_separator(text) @@ -1810,6 +1643,14 @@ def run(play): print(take_item) print("") logger_sys.log_message(f"INFO: Checking if an npc is present at map point 'point{map_location}'") + # Mission detection + count = 0 + while count < len(list(mission)): + current_mission_data = mission[list(mission)[count]] + if int(current_mission_data["source"]) == int(map_location) and str(list(mission)[count]) not in player["offered missions"]: + mission_handling.offer_mission(str(list(mission)[count]), player, mission, dialog, preferences, text_replacements_generic, drinks) + + count += 1 if "npc" in map["point" + str(map_location)] and map_location not in player["met npcs"]: current_npc = str(map["point" + str(map_location)]["npc"]) logger_sys.log_message(f"INFO: Current map point 'point{map_location}' has npc: '{current_npc}'") @@ -2493,16 +2334,19 @@ def run(play): elif choice == 'Tasks': print("ACTIVE TASKS:") tasks_list = player["active missions"] + if tasks_list == None: + tasks_list = ["You have no tasks"] logger_sys.log_message(f"INFO: Printing player active missions: '{tasks_list}'") - count = 0 - while count < len(tasks_list): - current_task = tasks_list[count] - current_task_name = mission[str(current_task)]["name"] - tasks_list.remove(current_task) - tasks_list.append(current_task_name) + if tasks_list != ["You have no tasks"]: + count = 0 + while count < len(tasks_list): + current_task = tasks_list[count] + current_task_name = mission[str(current_task)]["name"] + tasks_list.remove(current_task) + tasks_list.append(current_task_name) - count += 1 + count += 1 tasks_list_str = str(tasks_list) tasks_list_str = tasks_list_str.replace("'None', ", '') @@ -2547,7 +2391,12 @@ def run(play): text = '=' print_separator(text) - wait = input("") + options = ['Abort', 'Exit'] + choice = term_menu.show_menu(options) + if choice == 'Abort': + wait = input("Are you sure you want to abort this mission? (y/n) ") + if wait.startswith('y'): + player["active missions"].remove(mission_id) else: print("") print(COLOR_YELLOW + "You do not currently have a mission named like that" + COLOR_RESET_ALL) diff --git a/source/mission_handling.py b/source/mission_handling.py index 597609c..550004e 100644 --- a/source/mission_handling.py +++ b/source/mission_handling.py @@ -2,6 +2,7 @@ import term_menu import logger_sys import os +import dialog_handling from colorama import Fore, Back, Style, deinit, init from colors import * @@ -11,6 +12,7 @@ # Functions to handle missions def get_mission_id_from_name(mission_name, mission_data): + logger_sys.log_message(f"INFO: Getting mission name '{mission_name}' corresponding id") global mission_id count = 0 continue_action = True @@ -22,10 +24,13 @@ def get_mission_id_from_name(mission_name, mission_data): mission_id = str(list(mission_data)[count]) count += 1 + logger_sys.log_message(f"INFO: Found corresponding id of mission name '{mission_name}': {mission_id}") return mission_id def print_description(mission_data, map): + logger_sys.log_message(f"INFO: Printing mission '{mission_data}' description to GUI") + logger_sys.log_message(f"INFO: Generating mission text replacements") # Get text replacements # Payment of the mission when completed payment_for_mission = None @@ -62,6 +67,7 @@ def print_description(mission_data, map): "$deadline": deadline_for_mission, "$stopovers": new_stopovers_for_mission } + logger_sys.log_message(f"INFO: Loading missions text replacements: '{mission_text_replacements}'") text = str(mission_data["description"]) @@ -86,5 +92,40 @@ def print_description(mission_data, map): new_input = new_input[1:] print(str(new_input)) +def offer_mission(mission_id, player, missions_data, dialog, preferences, text_replacements_generic, drinks): + logger_sys.log_message(f"INFO: Offering mission '{mission_id}' to player") + data = missions_data[mission_id] + + # Add the mission ID to the player's + # offered missions list + player["offered missions"].append(mission_id) + + # Trigger the mission 'on offer' + # triggers if there are + + logger_sys.log_message(f"INFO: Triggering mission '{mission_id}' 'on offer' triggers") + if "on offer" in list(data): + # Only ask for accepting mission if there is a dialog, + # else, make the player automatically accept it + if "dialog" in list(data["on offer"]): + dialog_handling.print_dialog(data["on offer"]["dialog"], dialog, preferences, text_replacements_generic, player, drinks) + accept = input("Do you want to accept this task? (y/n)") + print("=======================================================") + if accept.startswith('y'): + if player["active missions"] == None: + player["active missions"] = [] + player["active missions"].append(mission_id) + else: + if player["active missions"] == None: + player["active missions"] = [] + player["active missions"].append(mission_id) + if "payment" in list(data["on offer"]): + player["gold"] += int(data["on offer"]["payment"]) + if "fine" in list(data["on offer"]): + player["gold"] -= int(data["on offer"]["fine"]) + if "exp addition" in list(data["on offer"]): + player["exp"] += int(data["on offer"]["exp addition"]) + logger_sys.log_message(f"INFO: Finished triggering mission '{mission_id}' 'on offer' triggers") + # deinitialize colorama deinit() From 2e2a8ebf9a124c71b2b88e99f68d533e689ec41a Mon Sep 17 00:00:00 2001 From: Cromha Date: Sun, 14 Jan 2024 12:59:04 +0100 Subject: [PATCH 4/7] bugifx - fixed logging bugs --- source/logger_sys.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/source/logger_sys.py b/source/logger_sys.py index 91b43e6..71a641c 100644 --- a/source/logger_sys.py +++ b/source/logger_sys.py @@ -1,23 +1,9 @@ -import logging import os import appdirs -from datetime import date +from datetime import * def log_message(message): program_dir = str(appdirs.user_config_dir(appname='Bane-Of-Wargs')) - # Create log file - with open(f'{program_dir}/logs/{date.today()}.log', 'w') as f: - f.write("LOG") - - # Create and configure logger - logging.basicConfig(filename=f'{program_dir}/logs/{date.today()}.log', - format='%(asctime)s %(message)s', - filemode='w' - ) - - - # Let us create an object - logger = logging.getLogger() - - logger.warning(message) + with open(f'{program_dir}/logs/{date.today()}.log', 'a') as f: + f.write(f'{datetime.now()}: {message}\n') From 7577e579e633426ce51c833cca0e2e6d6a14ab5f Mon Sep 17 00:00:00 2001 From: Cromha Date: Wed, 17 Jan 2024 20:42:07 +0100 Subject: [PATCH 5/7] progress[major] - added missions completion checks, and the trigger function to mission handling class + fixed bugs --- data/start.yaml | 5 +- schemas/missions.yaml | 1 + schemas/start.yaml | 1 + source/check_yaml.py | 4 +- source/main.py | 54 ++++++++++++- source/mission_handling.py | 153 ++++++++++++++++++++++++++++++++++++- 6 files changed, 210 insertions(+), 8 deletions(-) diff --git a/data/start.yaml b/data/start.yaml index e2bc74f..3576122 100644 --- a/data/start.yaml +++ b/data/start.yaml @@ -15,8 +15,7 @@ elapsed time seconds: 1 elapsed time game days: .25 attributes: - None -active missions: -- None +active missions: [] done missions: - None offered missions: @@ -58,3 +57,5 @@ defeated enemies: - None met npcs: - None +missions: + None: none diff --git a/schemas/missions.yaml b/schemas/missions.yaml index cc4f186..b58844d 100644 --- a/schemas/missions.yaml +++ b/schemas/missions.yaml @@ -1,5 +1,6 @@ name: str() description: str() +invisible: bool() deadline: int(required=False) stopovers: list(int(required=False)) to offer: any(required=False) diff --git a/schemas/start.yaml b/schemas/start.yaml index 092529e..7d327e1 100644 --- a/schemas/start.yaml +++ b/schemas/start.yaml @@ -37,3 +37,4 @@ map zone: str() taken items: list(int(), str(equals=None)) defeated enemies: list(int(), str(equals=None)) met npcs: list(int(), str(equals=None)) +missions: any() diff --git a/source/check_yaml.py b/source/check_yaml.py index 60ec646..ae87f17 100644 --- a/source/check_yaml.py +++ b/source/check_yaml.py @@ -34,6 +34,8 @@ def check_yaml(file_path): file_type = 'npcs' elif file_path.endswith('start.yaml'): file_type = 'start' + elif file_path.endswith('mission.yaml'): + file_type = 'missions' elif file_path.endswith('zone.yaml'): file_type = 'zones' elif file_path.endswith('preferences.yaml'): @@ -41,7 +43,7 @@ def check_yaml(file_path): elif file_path.startswith('saves/'): file_type = 'saves' file_schema = str(f'{program_dir}/game/schemas/{file_type}.yaml') - if file_type == 'drinks' or file_type == 'mounts' or file_type == 'map' or file_type == 'lists' or file_type == 'npcs' or file_type == 'enemies' or file_type == 'dialogs': + if file_type == 'drinks' or file_type == 'mounts' or file_type == 'map' or file_type == 'lists' or file_type == 'npcs' or file_type == 'enemies' or file_type == 'dialogs' or file_type == 'missions': count = 0 file_len = int(len(list(file))) while count < file_len: diff --git a/source/main.py b/source/main.py index 0d260d9..509ef4b 100644 --- a/source/main.py +++ b/source/main.py @@ -100,7 +100,7 @@ def print_speech_text_effect(text): def exit_game(): time.sleep(1.5) print(COLOR_YELLOW + "Warning: closing game now" + COLOR_RESET_ALL) - logger_sys.log_message("Warning: closing game now") + logger_sys.log_message("WARNING: closing game now") time.sleep(.5) os.system('clear') exit(1) @@ -142,6 +142,7 @@ def exit_game(): print("0/3", end="\r") logger_sys.log_message("INFO: Downloading game yaml schemas files from github") +""" # Download yaml schema files try: destination = program_dir + '/game/schemas' @@ -187,6 +188,7 @@ def exit_game(): print("3/3") print("Done") logger_sys.log_message("INFO: Process of downloading game data to update it completed") +""" # main menu start while menu: @@ -1643,7 +1645,9 @@ def run(play): print(take_item) print("") logger_sys.log_message(f"INFO: Checking if an npc is present at map point 'point{map_location}'") - # Mission detection + # Check if the player can get + # a mission from current map + # location count = 0 while count < len(list(mission)): current_mission_data = mission[list(mission)[count]] @@ -1651,6 +1655,47 @@ def run(play): mission_handling.offer_mission(str(list(mission)[count]), player, mission, dialog, preferences, text_replacements_generic, drinks) count += 1 + + # Check if the player has a mission that + # have a stopover at the current map location + # If he does, at the current map location + # to the player save to let the program + # known that + + count = 0 + while count < len(player["active missions"]): + current_mission_data = mission[str(player["active missions"][count])] + if "stopovers" in current_mission_data: + if map_location in current_mission_data["stopovers"]: + player["missions"][str(player["active missions"][count])]["stopovers went"].append(map_location) + + count += 1 + + # Check if the player has every stopover + # done for one of his mission to complete + # If he does, modify the player save to + # let the program know that + + count = 0 + while count < len(player["active missions"]): + current_mission_data = mission[str(player["active missions"][count])] + if "stopovers" in current_mission_data: + if len(player["missions"][str(player["active missions"][count])]["stopovers went"]) == len(current_mission_data["stopovers"]): + player["missions"][str(player["active missions"][count])]["went to all stopovers"] = True + + count += 1 + + # Check if player has a mission that requires to + # be at current map location to complete + count = 0 + + while count < len(player["active missions"]): + current_mission_data = mission[str(player["active missions"][count])] + if current_mission_data["destination"] == map_location: + mission_handling.mission_completing_checks(str(player["active missions"][count]), mission, player, dialog, preferences, text_replacements_generic, drinks) + + count += 1 + if "npc" in map["point" + str(map_location)] and map_location not in player["met npcs"]: current_npc = str(map["point" + str(map_location)]["npc"]) logger_sys.log_message(f"INFO: Current map point 'point{map_location}' has npc: '{current_npc}'") @@ -2344,7 +2389,8 @@ def run(play): current_task = tasks_list[count] current_task_name = mission[str(current_task)]["name"] tasks_list.remove(current_task) - tasks_list.append(current_task_name) + if not mission[current_task]["invisible"]: + tasks_list.append(current_task_name) count += 1 @@ -2372,7 +2418,7 @@ def run(play): mission_handling.print_description(mission[mission_id], map) destination_point = map["point" + str(mission[mission_id]["destination"])] - destination = str("X:" + COLOR_GREEN + COLOR_STYLE_BRIGHT + str(destination_point["x"]) + COLOR_RESET_ALL + ", Y:" + COLOR_GREEN + COLOR_STYLE_BRIGHT + str(destination_point["x"]) + COLOR_RESET_ALL) + destination = str("X:" + COLOR_GREEN + COLOR_STYLE_BRIGHT + str(destination_point["x"]) + COLOR_RESET_ALL + ", Y:" + COLOR_GREEN + COLOR_STYLE_BRIGHT + str(destination_point["y"]) + COLOR_RESET_ALL) print("") print("DESTINATION: " + destination) diff --git a/source/mission_handling.py b/source/mission_handling.py index 550004e..58f4583 100644 --- a/source/mission_handling.py +++ b/source/mission_handling.py @@ -3,6 +3,7 @@ import logger_sys import os import dialog_handling +import time from colorama import Fore, Back, Style, deinit, init from colors import * @@ -10,6 +11,14 @@ init() +def exit_game(): + time.sleep(1.5) + print(COLOR_YELLOW + "Warning: closing game now" + COLOR_RESET_ALL) + logger_sys.log_message("WARNING: closing game now") + time.sleep(.5) + os.system('clear') + exit(1) + # Functions to handle missions def get_mission_id_from_name(mission_name, mission_data): logger_sys.log_message(f"INFO: Getting mission name '{mission_name}' corresponding id") @@ -92,14 +101,121 @@ def print_description(mission_data, map): new_input = new_input[1:] print(str(new_input)) +def mission_checks(mission_data, player, which_key): + global checks_passed + # Get every checks required + # for running which_key operations + + checks = [] + + # If which_key input is invalid, quit + # the game and output the error to the + # game logs files + if which_key != 'to offer' and which_key != 'to complete' and which_key != 'to fail': + logger_sys.log_message(f"ERROR: Stopping mission checks for mission data '{mission_data}' --> invalid key '{which_key}'") + exit_game() + + #if "stopovers" in list(mission_data): + #checks.append('Stopovers') + if "player attributes" in list(mission_data[which_key]): + checks.append('Player Attributes') + if "visited locations" in list(mission_data[which_key]): + checks.append('Visited Locations') + if "known enemies" in list(mission_data[which_key]): + checks.append('Known Enemies') + if "known zones" in list(mission_data[which_key]): + checks.append('Known Zones') + if "known npcs" in list(mission_data[which_key]): + checks.append('Known Npcs') + if "has items" in list(mission_data[which_key]): + checks.append('Has Items') + + # Check if checks are passing + # and the action can continue + checks_passed = True + count = 0 + + # Player attributes checks + while count < len(mission_data[which_key]["player attributes"]) and checks_passed == True and 'Player Attributes' in checks: + current_attribute = mission_data[which_key]["player attributes"][count] + if str(current_attribute) not in player["attributes"]: + checks_passed = False + + count += 1 + count = 0 + + # Visited locations checks + while count < len(mission_data[which_key]["visited locations"]) and checks_passed == True and 'Visited Locations' in checks: + current_location = mission_data[which_key]["visited locations"][count] + if current_location not in player["visited points"]: + checks_passed = False + + count += 1 + count = 0 + + # Known enemies checks + while count < len(mission_data[which_key]["known enemies"]) and checks_passed == True and 'Known Enemies' in checks: + current_enemy = mission_data[which_key]["known enemies"][count] + if current_enemy not in player["enemies list"]: + checks_passed = False + + count += 1 + count = 0 + + # Known zones checks + while count < len(mission_data[which_key]["known zones"]) and checks_passed == True and 'Known Zones' in checks: + current_enemy = mission_data[which_key]["known zones"][count] + if current_enemy not in player["visited zones"]: + checks_passed = False + + count += 1 + count = 0 + + # Known npcs checks + while count < len(mission_data[which_key]["known npcs"]) and checks_passed == True and 'Known Npcs' in checks: + current_enemy = mission_data[which_key]["known npcs"][count] + if current_enemy not in player["met npcs names"]: + checks_passed = False + + count += 1 + count = 0 + + return checks_passed + +def execute_triggers(mission_data, player, which_key, dialog, preferences, text_replacements_generic, drinks): + # If which_key input is invalid, quit + # the game and output the error to the + # game logs files + if which_key != 'on offer' and which_key != 'on complete' and which_key != 'on fail': + logger_sys.log_message(f"ERROR: Stopping mission checks for mission data '{mission_data}' --> invalid key '{which_key}'") + exit_game() + + if "dialog" in mission_data[which_key]: + dialog_handling.print_dialog(mission_data[which_key]["dialog"], dialog, preferences, text_replacements_generic, player, drinks) + if "payment" in mission_data[which_key]: + player["gold"] += int(mission_data[which_key]["payment"]) + if "fine" in mission_data[which_key]: + player["gold"] -= int(mission_data[which_key]["fine"]) + if "exp addition" in mission_data[which_key]: + player["exp"] += int(mission_data[which_key]["exp addition"]) + def offer_mission(mission_id, player, missions_data, dialog, preferences, text_replacements_generic, drinks): logger_sys.log_message(f"INFO: Offering mission '{mission_id}' to player") data = missions_data[mission_id] # Add the mission ID to the player's - # offered missions list + # offered missions list and add + # the mission data in the player's + # data of its save player["offered missions"].append(mission_id) + mission_dict = { + "went to all stopovers": False, + "stopovers went": [] + } + + player["missions"][mission_id] = mission_dict + # Trigger the mission 'on offer' # triggers if there are @@ -127,5 +243,40 @@ def offer_mission(mission_id, player, missions_data, dialog, preferences, text_r player["exp"] += int(data["on offer"]["exp addition"]) logger_sys.log_message(f"INFO: Finished triggering mission '{mission_id}' 'on offer' triggers") + +def mission_completing_checks(mission_id, missions_data, player, dialog, preferences, text_replacements_generic, drinks): + # Load mission data and check if the + # required attributes to complete the + # mission are here and also check if the + # player has been on every stopovers and + # is on the destination point too + mission_data = missions_data[mission_id] + logger_sys.log_message(f"INFO: Checking if the player can complete mission '{mission_id}'") + + if "to complete" in list(mission_data): + attributes_checks_passed = mission_checks(mission_data, player, 'to complete') + else: + attributes_checks_passed = True + + stopovers_checks_passed = player["missions"][mission_id]["went to all stopovers"] + + # If the player has done everything + # required to complete the mission, then + # execute the 'on complete' triggers and + # remove the mission id from the player + # 'active missions' list and add it to the + # 'done missions' list + if attributes_checks_passed == True and stopovers_checks_passed == True: + logger_sys.log_message(f"INFO: Executing mission '{mission_id}' completing triggers") + + execute_triggers(mission_data, player, 'on complete', dialog, preferences, text_replacements_generic, drinks) + + logger_sys.log_message(f"INFO: Set mission '{mission_id}' as done") + player["active missions"].remove(mission_id) + player["done missions"].append(mission_id) + + + + # deinitialize colorama deinit() From 7635681afacc061d3f6589657771537339a012a7 Mon Sep 17 00:00:00 2001 From: Cromha Date: Thu, 18 Jan 2024 17:08:12 +0100 Subject: [PATCH 6/7] progress[major] - added mission failing and other mission conditions checks + fixes --- schemas/missions.yaml | 2 +- source/main.py | 17 ++++ source/mission_handling.py | 165 ++++++++++++++++++++++--------------- 3 files changed, 116 insertions(+), 68 deletions(-) diff --git a/schemas/missions.yaml b/schemas/missions.yaml index b58844d..1c1094e 100644 --- a/schemas/missions.yaml +++ b/schemas/missions.yaml @@ -2,7 +2,7 @@ name: str() description: str() invisible: bool() deadline: int(required=False) -stopovers: list(int(required=False)) +stopovers: list(int(), required=False) to offer: any(required=False) to complete: any(required=False) to fail: any(required=False) diff --git a/source/main.py b/source/main.py index 509ef4b..60622a1 100644 --- a/source/main.py +++ b/source/main.py @@ -1696,6 +1696,23 @@ def run(play): count += 1 + # Check if player has required attributes to + # fail a mission. If he does, then + # remove the mission id from the player's + # active missions save attribute to let the + # program know that and run the 'on fail' + # mission triggers + count = 0 + + while count < len(player["active missions"]): + current_mission_data = mission[str(player["active missions"][count])] + fail = mission_handling.mission_checks(current_mission_data, player, 'to fail') + if fail == False: + mission_handling.execute_triggers(current_mission_data, player, 'on fail', dialog, preferences, text_replacements_generic, drinks) + player["active missions"].remove(str(player["active missions"][count])) + + count += 1 + if "npc" in map["point" + str(map_location)] and map_location not in player["met npcs"]: current_npc = str(map["point" + str(map_location)]["npc"]) logger_sys.log_message(f"INFO: Current map point 'point{map_location}' has npc: '{current_npc}'") diff --git a/source/mission_handling.py b/source/mission_handling.py index 58f4583..81fbccc 100644 --- a/source/mission_handling.py +++ b/source/mission_handling.py @@ -136,49 +136,69 @@ def mission_checks(mission_data, player, which_key): count = 0 # Player attributes checks - while count < len(mission_data[which_key]["player attributes"]) and checks_passed == True and 'Player Attributes' in checks: - current_attribute = mission_data[which_key]["player attributes"][count] - if str(current_attribute) not in player["attributes"]: - checks_passed = False + if 'Player Attributes' in checks: + while count < len(mission_data[which_key]["player attributes"]) and checks_passed == True: + current_attribute = mission_data[which_key]["player attributes"][count] + if str(current_attribute) not in player["attributes"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 # Visited locations checks - while count < len(mission_data[which_key]["visited locations"]) and checks_passed == True and 'Visited Locations' in checks: - current_location = mission_data[which_key]["visited locations"][count] - if current_location not in player["visited points"]: - checks_passed = False + if 'Visited Locations' in checks: + while count < len(mission_data[which_key]["visited locations"]) and checks_passed == True: + current_location = mission_data[which_key]["visited locations"][count] + if current_location not in player["visited points"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 # Known enemies checks - while count < len(mission_data[which_key]["known enemies"]) and checks_passed == True and 'Known Enemies' in checks: - current_enemy = mission_data[which_key]["known enemies"][count] - if current_enemy not in player["enemies list"]: - checks_passed = False + if 'Known Enemies' in checks: + while count < len(mission_data[which_key]["known enemies"]) and checks_passed == True: + current_enemy = mission_data[which_key]["known enemies"][count] + if current_enemy not in player["enemies list"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 # Known zones checks - while count < len(mission_data[which_key]["known zones"]) and checks_passed == True and 'Known Zones' in checks: - current_enemy = mission_data[which_key]["known zones"][count] - if current_enemy not in player["visited zones"]: - checks_passed = False + if 'Known Zones' in checks: + while count < len(mission_data[which_key]["known zones"]) and checks_passed == True: + current_enemy = mission_data[which_key]["known zones"][count] + if current_enemy not in player["visited zones"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 # Known npcs checks - while count < len(mission_data[which_key]["known npcs"]) and checks_passed == True and 'Known Npcs' in checks: - current_enemy = mission_data[which_key]["known npcs"][count] - if current_enemy not in player["met npcs names"]: - checks_passed = False + if 'Known Npcs' in checks: + while count < len(mission_data[which_key]["known npcs"]) and checks_passed == True: + current_enemy = mission_data[which_key]["known npcs"][count] + if current_enemy not in player["met npcs names"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 + + # Has items checks + if 'Has Items' in checks: + while count < len(mission_data[which_key]["has items"]) and checks_passed == True: + current_item = mission_data[which_key]["has items"][count] + + if which_key == 'to fail': + if current_item in player["inventory"]: + checks_passed = False + else: + if current_item not in player["inventory"]: + checks_passed = False + + count += 1 + count = 0 return checks_passed @@ -190,14 +210,15 @@ def execute_triggers(mission_data, player, which_key, dialog, preferences, text_ logger_sys.log_message(f"ERROR: Stopping mission checks for mission data '{mission_data}' --> invalid key '{which_key}'") exit_game() - if "dialog" in mission_data[which_key]: - dialog_handling.print_dialog(mission_data[which_key]["dialog"], dialog, preferences, text_replacements_generic, player, drinks) - if "payment" in mission_data[which_key]: - player["gold"] += int(mission_data[which_key]["payment"]) - if "fine" in mission_data[which_key]: - player["gold"] -= int(mission_data[which_key]["fine"]) - if "exp addition" in mission_data[which_key]: - player["exp"] += int(mission_data[which_key]["exp addition"]) + if which_key in mission_data: + if "dialog" in mission_data[which_key]: + dialog_handling.print_dialog(mission_data[which_key]["dialog"], dialog, preferences, text_replacements_generic, player, drinks) + if "payment" in mission_data[which_key]: + player["gold"] += int(mission_data[which_key]["payment"]) + if "fine" in mission_data[which_key]: + player["gold"] -= int(mission_data[which_key]["fine"]) + if "exp addition" in mission_data[which_key]: + player["exp"] += int(mission_data[which_key]["exp addition"]) def offer_mission(mission_id, player, missions_data, dialog, preferences, text_replacements_generic, drinks): logger_sys.log_message(f"INFO: Offering mission '{mission_id}' to player") @@ -207,42 +228,52 @@ def offer_mission(mission_id, player, missions_data, dialog, preferences, text_r # offered missions list and add # the mission data in the player's # data of its save - player["offered missions"].append(mission_id) - - mission_dict = { - "went to all stopovers": False, - "stopovers went": [] - } - - player["missions"][mission_id] = mission_dict - # Trigger the mission 'on offer' - # triggers if there are - - logger_sys.log_message(f"INFO: Triggering mission '{mission_id}' 'on offer' triggers") - if "on offer" in list(data): - # Only ask for accepting mission if there is a dialog, - # else, make the player automatically accept it - if "dialog" in list(data["on offer"]): - dialog_handling.print_dialog(data["on offer"]["dialog"], dialog, preferences, text_replacements_generic, player, drinks) - accept = input("Do you want to accept this task? (y/n)") - print("=======================================================") - if accept.startswith('y'): + if 'to offer' in data: + can_offer = mission_checks(data, player, 'to offer') + else: + can_offer = True + + if can_offer == True: + player["offered missions"].append(mission_id) + + mission_dict = { + "went to all stopovers": False, + "stopovers went": [] + } + + player["missions"][mission_id] = mission_dict + + # Trigger the mission 'on offer' + # triggers if there are + + logger_sys.log_message(f"INFO: Triggering mission '{mission_id}' 'on offer' triggers") + if "on offer" in list(data): + # Only ask for accepting mission if there is a dialog, + # else, make the player automatically accept it + if "dialog" in list(data["on offer"]): + dialog_handling.print_dialog(data["on offer"]["dialog"], dialog, preferences, text_replacements_generic, player, drinks) + accept = input("Do you want to accept this task? (y/n)") + print("=======================================================") + if accept.startswith('y'): + if player["active missions"] == None: + player["active missions"] = [] + player["active missions"].append(mission_id) + else: if player["active missions"] == None: player["active missions"] = [] - player["active missions"].append(mission_id) + player["active missions"] += [mission_id] + if "payment" in list(data["on offer"]): + player["gold"] += int(data["on offer"]["payment"]) + if "fine" in list(data["on offer"]): + player["gold"] -= int(data["on offer"]["fine"]) + if "exp addition" in list(data["on offer"]): + player["exp"] += int(data["on offer"]["exp addition"]) else: if player["active missions"] == None: player["active missions"] = [] player["active missions"].append(mission_id) - if "payment" in list(data["on offer"]): - player["gold"] += int(data["on offer"]["payment"]) - if "fine" in list(data["on offer"]): - player["gold"] -= int(data["on offer"]["fine"]) - if "exp addition" in list(data["on offer"]): - player["exp"] += int(data["on offer"]["exp addition"]) - logger_sys.log_message(f"INFO: Finished triggering mission '{mission_id}' 'on offer' triggers") - + logger_sys.log_message(f"INFO: Finished triggering mission '{mission_id}' 'on offer' triggers") def mission_completing_checks(mission_id, missions_data, player, dialog, preferences, text_replacements_generic, drinks): # Load mission data and check if the From 0f03048c857153b50a1f646a4f64254b1fb2ab2e Mon Sep 17 00:00:00 2001 From: Cromha Date: Thu, 18 Jan 2024 20:16:09 +0100 Subject: [PATCH 7/7] progress[major] - added mission enemies --- .github/workflows/cd.yaml | 6 +- compile.sh | 1 + docs/BUILDING.md | 1 + source/enemy_handling.py | 109 +++++++++++++++++++++++ source/main.py | 173 ++++++++++--------------------------- source/mission_handling.py | 144 +++++++++++++++--------------- 6 files changed, 232 insertions(+), 202 deletions(-) create mode 100644 source/enemy_handling.py diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 1d82829..3226d9a 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -42,7 +42,7 @@ jobs: pip install -r requirements.txt pip install PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py source/enemy_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec mv dist/Bane-Of-Wargs Bane-Of-Wargs-Linux - name: Upload artifact uses: actions/upload-artifact@v3 @@ -77,7 +77,7 @@ jobs: pip install -r requirements.txt pip install PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py source/enemy_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs mv dist/Bane-Of-Wargs Bane-Of-Wargs-Mac - name: Upload artifact uses: actions/upload-artifact@v3 @@ -112,7 +112,7 @@ jobs: pip install -r requirements.txt pip install windows-curses PyInstaller - python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec + python -m PyInstaller --console --onefile --name Bane-Of-Wargs source/main.py source/battle.py source/check_yaml.py source/colors.py source/map_item.py source/train.py source/logger_sys.py source/mission_handling.py source/dialog_handling.py source/enemy_handling.py --add-data yamale/VERSION:yamale --collect-submodules fsspec --collect-submodules appdirs --hidden-import appdirs --hidden-import fsspec mv dist/Bane-Of-Wargs.exe Bane-Of-Wargs.exe - name: Upload artifact uses: actions/upload-artifact@v3 diff --git a/compile.sh b/compile.sh index 3b89ee5..a5ea8ab 100755 --- a/compile.sh +++ b/compile.sh @@ -14,6 +14,7 @@ source/logger_sys.py \ source/term_menu.py \ source/mission_handling.py \ source/dialog_handling.py \ +source/enemy_handling.py \ --add-data yamale/VERSION:yamale \ --collect-submodules fsspec \ --collect-submodules appdirs \ diff --git a/docs/BUILDING.md b/docs/BUILDING.md index cf9c728..bacce95 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -55,6 +55,7 @@ source/logger_sys.py \ source/term_menu.py \ source/mission_handling.py \ source/dialog_handling.py \ +source/enemy_handling.py \ --add-data yamale/VERSION:yamale \ --collect-submodules fsspec \ --collect-submodules appdirs \ diff --git a/source/enemy_handling.py b/source/enemy_handling.py new file mode 100644 index 0000000..dc6af48 --- /dev/null +++ b/source/enemy_handling.py @@ -0,0 +1,109 @@ +import battle +import logger_sys +import random +import sys +import colors +import term_menu +from colors import * +from colorama import Fore, Back, Style, init, deinit + +# initialize colorama +init() + +# Basic functions +def print_long_string(text): + new_input = "" + for i, letter in enumerate(text): + if i % 54 == 0: + new_input += '\n' + new_input += letter + + # this is just because at the beginning too a `\n` character gets added + new_input = new_input[1:] + print(str(new_input)) + +def print_separator(character): + count = 0 + + while count < 55: + sys.stdout.write(COLOR_STYLE_BRIGHT + character + COLOR_RESET_ALL) + sys.stdout.flush() + count += 1 + sys.stdout.write('\n') + +def a_an_check(word): + logger_sys.log_message(f"INFO: Checking correct grammar of 'a' in front of '{word}'") + global to_return + vowels = ['a', 'e', 'i', 'o', 'u'] + if word[0] in vowels: + to_return = "an " + word + else: + to_return = "a " + word + logger_sys.log_message(f"INFO: Checking correct grammar of 'a' in front of '{word}': '{to_return}'") + return to_return + +# Handling function + +def spawn_enemy(map_location, list_enemies, enemy_number, enemy, item, lists, start_player, map, player): + enemies_remaining = enemy_number + already_encountered = False + while enemies_remaining > 0: + logger_sys.log_message(f"INFO: Choosing random enemy from the list '{list_enemies}'") + choose_rand_enemy = random.randint(0, len(list_enemies) - 1) + choose_rand_enemy = list_enemies[choose_rand_enemy] + chosen_enemy = enemy[choose_rand_enemy] + + enemy_total_inventory = chosen_enemy["inventory"] + + enemy_items_number = len(enemy_total_inventory) + logger_sys.log_message("INFO: Choosing randomly the item that will drop from the enemies") + chosen_item = enemy_total_inventory[random.randint(0, enemy_items_number - 1)] + logger_sys.log_message("INFO: Calculating battle risk for the player") + defeat_percentage = battle.calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy) + logger_sys.log_message("INFO: Getting enemy stats") + battle.get_enemy_stats(player, item, enemy, map, map_location, lists, choose_rand_enemy, chosen_enemy, chosen_item, enemy_items_number, enemy_total_inventory, enemies_remaining) + if not already_encountered: + logger_sys.log_message("INFO: Display enemy encounter text") + battle.encounter_text_show(player, item, enemy, map, map_location, enemies_remaining, lists, defeat_percentage) + already_encountered = True + logger_sys.log_message("INFO: Starting the fight") + battle.fight(player, item, enemy, map, map_location, enemies_remaining, lists) + enemies_remaining -= 1 + + if player["health"] > 0: + + if random.randint(0, 3) >= 2.5: + chosen_item = "Gold" + + if chosen_item == "Gold": + print("Your enemy dropped some " + chosen_item) + else: + print("Your enemy dropped " + a_an_check(chosen_item)) + options = ['Grab Item', 'Continue'] + drop = term_menu.show_menu(options) + text = '=' + print_separator(text) + if drop == 'Grab Item': + if chosen_item == "Gold": + player["gold"] += round(random.uniform(1.00, 6.30), 2) + else: + if chosen_item in player["inventory"] and item[chosen_item]["type"] == "Utility": + print("You cannot take that item") + elif player["inventory slots remaining"] == 0: + print("You cannot take that item, you don't have enough slots in your inventory") + else: + player["inventory"].append(chosen_item) + print(" ") + player["defeated enemies"].append(map_location) + else: + text = COLOR_RED + COLOR_STYLE_BRIGHT + "You just died and your save have been reset." + COLOR_RESET_ALL + logger_sys.log_message("INFO: Player just died") + print_long_string(text) + finished = input() + logger_sys.log_message("INFO: Resetting player save") + player = start_player + play = 0 + return play + +# deinitialize colorama +deinit() diff --git a/source/main.py b/source/main.py index 60622a1..8ce6ac9 100644 --- a/source/main.py +++ b/source/main.py @@ -7,6 +7,7 @@ import term_menu import mission_handling import dialog_handling +import enemy_handling import os import sys import time @@ -1645,13 +1646,17 @@ def run(play): print(take_item) print("") logger_sys.log_message(f"INFO: Checking if an npc is present at map point 'point{map_location}'") + # Check if the player can get # a mission from current map # location + + logger_sys.log_message(f"INFO: Checking if the player can get a mission from current map location '{map_location}'") count = 0 while count < len(list(mission)): current_mission_data = mission[list(mission)[count]] if int(current_mission_data["source"]) == int(map_location) and str(list(mission)[count]) not in player["offered missions"]: + logger_sys.log_message(f"INFO: Offering mission '{str(list(mission)[count])}' to player") mission_handling.offer_mission(str(list(mission)[count]), player, mission, dialog, preferences, text_replacements_generic, drinks) count += 1 @@ -1661,12 +1666,14 @@ def run(play): # If he does, at the current map location # to the player save to let the program # known that + logger_sys.log_message(f"INFO: Checking if the player has a mission that has a stopover at the current map location '{map_location}'") count = 0 while count < len(player["active missions"]): current_mission_data = mission[str(player["active missions"][count])] if "stopovers" in current_mission_data: if map_location in current_mission_data["stopovers"]: + logger_sys.log_message(f"INFO: Adding current map location '{map_location}' to player active mission data '{current_mission_data}'") player["missions"][str(player["active missions"][count])]["stopovers went"].append(map_location) count += 1 @@ -1675,6 +1682,7 @@ def run(play): # done for one of his mission to complete # If he does, modify the player save to # let the program know that + logger_sys.log_message("INFO: Checking if the player has every stopover done for one of his missions to complete") count = 0 while count < len(player["active missions"]): @@ -1687,11 +1695,13 @@ def run(play): # Check if player has a mission that requires to # be at current map location to complete + logger_sys.log_message(f"INFO: Checking if the player has a mission that requires to be at current map location '{map_location}' to complete") count = 0 while count < len(player["active missions"]): current_mission_data = mission[str(player["active missions"][count])] if current_mission_data["destination"] == map_location: + logger_sys.log_message(f"INFO: Running mission completing checks for mission data '{current_mission_data}'") mission_handling.mission_completing_checks(str(player["active missions"][count]), mission, player, dialog, preferences, text_replacements_generic, drinks) count += 1 @@ -1702,14 +1712,17 @@ def run(play): # active missions save attribute to let the # program know that and run the 'on fail' # mission triggers + logger_sys.log_message("INFO: Checking if a player has all required conditions to fail an active mission") count = 0 while count < len(player["active missions"]): current_mission_data = mission[str(player["active missions"][count])] - fail = mission_handling.mission_checks(current_mission_data, player, 'to fail') - if fail == False: - mission_handling.execute_triggers(current_mission_data, player, 'on fail', dialog, preferences, text_replacements_generic, drinks) - player["active missions"].remove(str(player["active missions"][count])) + if "to fail" in current_mission_data: + fail = mission_handling.mission_checks(current_mission_data, player, 'to fail') + if fail == False: + logger_sys.log_message(f"INFO: Executing failing triggers of mission data '{current_mission_data}'") + mission_handling.execute_triggers(current_mission_data, player, 'on fail', dialog, preferences, text_replacements_generic, drinks) + player["active missions"].remove(str(player["active missions"][count])) count += 1 @@ -1852,138 +1865,44 @@ def run(play): time.sleep(.6) os.system('clear') """ + + # Check if player current missions + # have an enemy at current map point + logger_sys.log_message(f"INFO: Checking if the player has a mission that makes an enemy spawn at current map point 'point{map_location}'") + count = 0 + count2 = 0 + + while count < len(player["active missions"]): + current_mission_id = player["active missions"][count] + current_mission_data = mission[player["active missions"][count]] + if "enemies" in current_mission_data: + while count2 < len(list(current_mission_data["enemies"])): + current_enemy_data = current_mission_data["enemies"][str(list(current_mission_data["enemies"])[count])] + if current_enemy_data["location"] == map_location: + spawning_checks = True + spawning_checks_2 = False + if 'to spawn' in current_enemy_data: + spawning_checks = mission_handling.mission_checks(current_enemy_data, player, 'to spawn') + if 'to despawn' in current_enemy_data: + spawning_checks_2 = mission_handling.mission_checks(current_enemy_data, player, 'to despawn') + if spawning_checks == True and spawning_checks_2 == False: + logger_sys.log_message(f"INFO: Spawning enemy from mission '{current_mission_id}' with mission enemy data '{current_enemy_data}'") + enemy_handling.spawn_enemy(map_location, lists[str(current_enemy_data["enemy category"])], current_enemy_data["enemy number"],enemy, item, lists, start_player, map, player) + + count2 += 1 + count += 1 + logger_sys.log_message(f"INFO: Checking if an enemy at map point 'point{map_location}'") if "enemy" in map["point" + str(map_location)] and map_location not in player["defeated enemies"]: logger_sys.log_message(f"INFO: Found enemies at map point 'point{map_location}'") - enemies_remaining = map["point" + str(map_location)]["enemy"] - already_encountered = False - while enemies_remaining > 0: - list_enemies = lists[ map["point" + str(map_location)]["enemy type"]] - logger_sys.log_message(f"INFO: Choosing random enemy from the list '{list_enemies}'") - choose_rand_enemy = random.randint(0, len(list_enemies) - 1) - choose_rand_enemy = list_enemies[choose_rand_enemy] - chosen_enemy = enemy[choose_rand_enemy] - - enemy_total_inventory = chosen_enemy["inventory"] - - enemy_items_number = len(enemy_total_inventory) - logger_sys.log_message("INFO: Choosing randomly the item that will drop from the enemies") - chosen_item = enemy_total_inventory[random.randint(0, enemy_items_number - 1)] - logger_sys.log_message("INFO: Calculating battle risk for the player") - defeat_percentage = battle.calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy) - logger_sys.log_message("INFO: Getting enemy stats") - battle.get_enemy_stats(player, item, enemy, map, map_location, lists, choose_rand_enemy, chosen_enemy, chosen_item, enemy_items_number, enemy_total_inventory, enemies_remaining) - if not already_encountered: - logger_sys.log_message("INFO: Display enemy encounter text") - battle.encounter_text_show(player, item, enemy, map, map_location, enemies_remaining, lists, defeat_percentage) - already_encountered = True - logger_sys.log_message("INFO: Starting the fight") - battle.fight(player, item, enemy, map, map_location, enemies_remaining, lists) - enemies_remaining -= 1 - # if round(random.uniform(.20, .50), 2) > .35: - list_enemies = lists[ map["point" + str(map_location)]["enemy type"]] - - if player["health"] > 0: - - if random.randint(0, 3) >= 2.5: - chosen_item = "Gold" - - if chosen_item == "Gold": - print("Your enemy dropped some " + chosen_item) - else: - print("Your enemy dropped " + a_an_check(chosen_item)) - options = ['Grab Item', 'Continue'] - drop = term_menu.show_menu(options) - text = '=' - print_separator(text) - if drop == 'Grab Item': - if chosen_item == "Gold": - add_gold(round(random.uniform(1.00, 6.30), 2)) - else: - if chosen_item in player["inventory"] and item[chosen_item]["type"] == "Utility": - print("You cannot take that item") - elif player["inventory slots remaining"] == 0: - print("You cannot take that item, you don't have enough slots in your inventory") - else: - player["inventory"].append(chosen_item) - print(" ") - player["defeated enemies"].append(map_location) - else: - text = COLOR_RED + COLOR_STYLE_BRIGHT + "You just died and your save have been reset." + COLOR_RESET_ALL - logger_sys.log_message("INFO: Player just died") - print_long_string(text) - finished = input() - logger_sys.log_message("INFO: Resetting player save") - player = start_player - play = 0 - return play + enemy_handling.spawn_enemy(map_location, lists[map["point" + str(map_location)]["enemy type"]], map["point" + str(map_location)]["enemy"], enemy, item, lists, start_player, map, player) elif day_time == COLOR_RED + COLOR_STYLE_BRIGHT + "NIGHT" + COLOR_RESET_ALL and round(random.uniform(.20, .80), 3) > .7 and zone[map_zone]["type"] != "hostel" and zone[map_zone]["type"] != "stable" and zone[map_zone]["type"] != "village" and zone[map_zone]["type"] != "blacksmith" and zone[map_zone]["type"] != "forge": logger_sys.log_message("INFO: Checking if it's night time") logger_sys.log_message("INFO: Checking if the player isn't in a village, an hostel, a stable, a blacksmith or a forge") logger_sys.log_message("INFO: Calculating random chance of enemy spawning") logger_sys.log_message("INFO: Spawning enemies") - enemies_remaining = random.randint(1, 4) - already_encountered = False - while enemies_remaining > 0: - list_enemies = lists["generic"] - choose_rand_enemy = random.randint(0, len(list_enemies) - 1) - logger_sys.log_message(f"INFO: Choosing random enemy from the list '{list_enemies}'") - choose_rand_enemy = list_enemies[choose_rand_enemy] - chosen_enemy = enemy[choose_rand_enemy] - - enemy_total_inventory = chosen_enemy["inventory"] - - enemy_items_number = len(enemy_total_inventory) - logger_sys.log_message("INFO: Choosing randomly the item that will drop from the enemies") - chosen_item = enemy_total_inventory[random.randint(0, enemy_items_number - 1)] - logger_sys.log_message("INFO: Calculating battle risk for the player") - defeat_percentage = battle.calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy) - logger_sys.log_message("INFO: Getting enemy stats") - battle.get_enemy_stats(player, item, enemy, map, map_location, lists, choose_rand_enemy, chosen_enemy, chosen_item, enemy_items_number, enemy_total_inventory, enemies_remaining) - if not already_encountered: - logger_sys.log_message("INFO: Display enemy encounter text") - battle.encounter_text_show(player, item, enemy, map, map_location, enemies_remaining, lists, defeat_percentage) - already_encountered = True - logger_sys.log_message("INFO: Starting the fight") - battle.fight(player, item, enemy, map, map_location, enemies_remaining, lists) - enemies_remaining -= 1 - # if round(random.uniform(.20, .50), 2) > .35: - list_enemies = lists["generic"] - - if player["health"] > 0: - - if random.randint(0, 3) >= 2.5: - chosen_item = "Gold" - - if chosen_item == "Gold": - print("Your enemy dropped some " + chosen_item) - else: - print("Your enemy dropped " + a_an_check(chosen_item)) - options = ['Grab Item', 'Continue'] - drop = term_menu.show_menu(options) - text = '=' - print_separator(text) - if drop == 'Grab Item': - if chosen_item == "Gold": - add_gold(round(random.uniform(1.00, 6.30), 2)) - else: - if chosen_item in player["inventory"] and item[chosen_item]["type"] == "Utility": - print("You cannot take that item") - elif player["inventory slots remaining"] == 0: - print("You cannot take that item, you don't have enough slots in your inventory") - else: - player["inventory"].append(chosen_item) - print(" ") - else: - text = COLOR_RED + COLOR_STYLE_BRIGHT + "You just died and your save have been reset." + COLOR_RESET_ALL - logger_sys.log_message("INFO: Player just died") - print_long_string(text) - finished = input() - logger_sys.log_message("INFO: Resetting player save") - player = start_player - play = 0 - return play + enemy_handling.spawn_enemy(map_location, lists['generic'], round(random.uniform(1, 5)), enemy, item, lists, start_player, map, player) command = input(COLOR_GREEN + COLOR_STYLE_BRIGHT + "> " + COLOR_RESET_ALL) print(" ") logger_sys.log_message(f"INFO: Player ran command '{command}'") diff --git a/source/mission_handling.py b/source/mission_handling.py index 81fbccc..333870e 100644 --- a/source/mission_handling.py +++ b/source/mission_handling.py @@ -107,98 +107,98 @@ def mission_checks(mission_data, player, which_key): # for running which_key operations checks = [] + generic_keys = ['to offer', 'to complete', 'to fail', 'to despawn', 'to spawn'] # If which_key input is invalid, quit # the game and output the error to the # game logs files - if which_key != 'to offer' and which_key != 'to complete' and which_key != 'to fail': + if which_key != 'to offer' and which_key != 'to complete' and which_key != 'to fail' and which_key != 'to spawn' and which_key != 'to despawn': logger_sys.log_message(f"ERROR: Stopping mission checks for mission data '{mission_data}' --> invalid key '{which_key}'") exit_game() - #if "stopovers" in list(mission_data): - #checks.append('Stopovers') - if "player attributes" in list(mission_data[which_key]): - checks.append('Player Attributes') - if "visited locations" in list(mission_data[which_key]): - checks.append('Visited Locations') - if "known enemies" in list(mission_data[which_key]): - checks.append('Known Enemies') - if "known zones" in list(mission_data[which_key]): - checks.append('Known Zones') - if "known npcs" in list(mission_data[which_key]): - checks.append('Known Npcs') - if "has items" in list(mission_data[which_key]): - checks.append('Has Items') - - # Check if checks are passing - # and the action can continue - checks_passed = True - count = 0 + if which_key in generic_keys: + if "player attributes" in list(mission_data[which_key]): + checks.append('Player Attributes') + if "visited locations" in list(mission_data[which_key]): + checks.append('Visited Locations') + if "known enemies" in list(mission_data[which_key]): + checks.append('Known Enemies') + if "known zones" in list(mission_data[which_key]): + checks.append('Known Zones') + if "known npcs" in list(mission_data[which_key]): + checks.append('Known Npcs') + if "has items" in list(mission_data[which_key]): + checks.append('Has Items') + + # Check if checks are passing + # and the action can continue + checks_passed = True + count = 0 - # Player attributes checks - if 'Player Attributes' in checks: - while count < len(mission_data[which_key]["player attributes"]) and checks_passed == True: - current_attribute = mission_data[which_key]["player attributes"][count] - if str(current_attribute) not in player["attributes"]: - checks_passed = False + # Player attributes checks + if 'Player Attributes' in checks: + while count < len(mission_data[which_key]["player attributes"]) and checks_passed == True: + current_attribute = mission_data[which_key]["player attributes"][count] + if str(current_attribute) not in player["attributes"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 - # Visited locations checks - if 'Visited Locations' in checks: - while count < len(mission_data[which_key]["visited locations"]) and checks_passed == True: - current_location = mission_data[which_key]["visited locations"][count] - if current_location not in player["visited points"]: - checks_passed = False + # Visited locations checks + if 'Visited Locations' in checks: + while count < len(mission_data[which_key]["visited locations"]) and checks_passed == True: + current_location = mission_data[which_key]["visited locations"][count] + if current_location not in player["visited points"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 - # Known enemies checks - if 'Known Enemies' in checks: - while count < len(mission_data[which_key]["known enemies"]) and checks_passed == True: - current_enemy = mission_data[which_key]["known enemies"][count] - if current_enemy not in player["enemies list"]: - checks_passed = False + # Known enemies checks + if 'Known Enemies' in checks: + while count < len(mission_data[which_key]["known enemies"]) and checks_passed == True: + current_enemy = mission_data[which_key]["known enemies"][count] + if current_enemy not in player["enemies list"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 - # Known zones checks - if 'Known Zones' in checks: - while count < len(mission_data[which_key]["known zones"]) and checks_passed == True: - current_enemy = mission_data[which_key]["known zones"][count] - if current_enemy not in player["visited zones"]: - checks_passed = False + # Known zones checks + if 'Known Zones' in checks: + while count < len(mission_data[which_key]["known zones"]) and checks_passed == True: + current_enemy = mission_data[which_key]["known zones"][count] + if current_enemy not in player["visited zones"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 - # Known npcs checks - if 'Known Npcs' in checks: - while count < len(mission_data[which_key]["known npcs"]) and checks_passed == True: - current_enemy = mission_data[which_key]["known npcs"][count] - if current_enemy not in player["met npcs names"]: - checks_passed = False + # Known npcs checks + if 'Known Npcs' in checks: + while count < len(mission_data[which_key]["known npcs"]) and checks_passed == True: + current_enemy = mission_data[which_key]["known npcs"][count] + if current_enemy not in player["met npcs names"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 - # Has items checks - if 'Has Items' in checks: - while count < len(mission_data[which_key]["has items"]) and checks_passed == True: - current_item = mission_data[which_key]["has items"][count] + # Has items checks + if 'Has Items' in checks: + while count < len(mission_data[which_key]["has items"]) and checks_passed == True: + current_item = mission_data[which_key]["has items"][count] - if which_key == 'to fail': - if current_item in player["inventory"]: - checks_passed = False - else: - if current_item not in player["inventory"]: - checks_passed = False + if which_key == 'to fail': + if current_item in player["inventory"]: + checks_passed = False + else: + if current_item not in player["inventory"]: + checks_passed = False - count += 1 - count = 0 + count += 1 + count = 0 return checks_passed