def get_player_servants(servant_database):
    player_servants = servant_database
    servant_list = []
    GlobalLibrary.debug(str(player_servants["ActiveServants"]))
    for i in range(0, 3):
        servant = player_servants["Servants"][int(
            player_servants["ActiveServants"][i])]
        file_path = str("Servants/" + servant + ".json")
        with open(file_path, 'r', encoding="utf8") as file_ref:
            json_ref = json.load(file_ref)  # Load file into JSON module
            servant_level = int(player_servants["Levels"][int(
                player_servants["ActiveServants"][i])])
            json_ref["HP"] = int(
                int(json_ref["HP"]) * (1 + (servant_level / 30)))
            json_ref["ATK"] = int(
                int(json_ref["ATK"]) * (1 + (servant_level / 30)))
            json_ref.update({"Level": servant_level})
            json_ref.update({"Allied": True})
            json_ref.update({
                "CurrentHP":
                int(int(json_ref["HP"]) * (1 + (servant_level / 30)))
            })
            json_ref.update({"CurrentNP": 0})
            servant_list.append(json_ref)
    servant1 = servant_list[0]
    servant2 = servant_list[1]
    servant3 = servant_list[2]
    return servant1, servant2, servant3
Exemplo n.º 2
0
    def sync_files(self):
        try:
            for database_document in self.database_servants.find(
            ):  # Iterate through every Document in Servant Database
                file_path = str(
                    "Servants/" + database_document['Name'] +
                    ".json")  # Set relative file path for selected Servant

                if os.path.isfile(
                        path=file_path
                ):  # Check is selected Servant has a local file
                    GlobalLibrary.debug("File Found - " + file_path)

                    with open(file_path, 'r', encoding="utf8") as file_ref:
                        file_json = json.load(
                            file_ref)  # Load file into JSON module

                    database_document['_id'] = str(
                        database_document['_id']
                    )  # Converts the ID value to string

                    if database_document == file_json:  # Checks if files match exactly
                        GlobalLibrary.debug("File Matched - " + file_path)
                    else:
                        GlobalLibrary.debug("File Didn't Match - " + file_path)
                        os.remove(file_path)  # Delete the old file
                        with open(file_path,
                                  'w') as file_ref:  # Create a new file
                            json.dump(obj=database_document,
                                      fp=file_ref,
                                      ensure_ascii=False,
                                      indent=2)  # Write to file
                        GlobalLibrary.debug("File Updated - " + file_path)
                else:
                    GlobalLibrary.debug("File Not Found - " + file_path)
                    database_document['_id'] = str(
                        database_document['_id']
                    )  # Converts the ID value to string
                    with open(file_path, 'w') as file_ref:  # Create a new file
                        json.dump(obj=database_document,
                                  fp=file_ref,
                                  ensure_ascii=False,
                                  indent=2)  # Write to file
                    GlobalLibrary.debug("File Created - " + file_path)
            GlobalLibrary.notice("File Sync Complete!")
        except pymongo.errors.ServerSelectionTimeoutError:  # Error if connection times out
            GlobalLibrary.error("Connection Failed")
            sys.exit()
import socket

from Scripts import CoverGUI, GlobalLibrary

GlobalLibrary.initalise(__file__)

user_device_name = socket.gethostname()
user_IP = socket.gethostbyname(socket.gethostname())
GlobalLibrary.debug(str(user_device_name + " | " + user_IP))
cover_interface = CoverGUI.Main(user_IP)
cover_interface.start_mainloop()