def get_all_player_servants(servant_database):
    servant_list = []
    servant_list_master = []
    for i in range(len(servant_database["Servants"])):
        try:
            servant = servant_database["Servants"][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(servant_database["Levels"][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)
            if len(servant_list) == 10:
                servant_list_master.append(servant_list)
                servant_list = []
        except KeyError:
            GlobalLibrary.error("Servant File Error")

    servant_list_master.append(servant_list)
    return servant_list_master
示例#2
0
 def __init__(self):
     GlobalLibrary.initalise(ServantDatabase.__name__)
     GlobalLibrary.notice("Connecting to Mongo Server!")
     try:
         self.server_ref = pymongo.MongoClient(
             "mongodb+srv://FateGameClient:[email protected]/test?retryWrites=true&w"
             "=majority")
     except pymongo.errors.AutoReconnect:
         GlobalLibrary.error("Connection Failed, Reconnecting!")
     except pymongo.errors.ConnectionFailure:
         GlobalLibrary.error("Connection Failed!")
     self.collection_ref = self.server_ref[
         'fate']  # Open the Collection "fate"
     self.database_servants = self.collection_ref[
         'servants']  # Open the Database "servants"
示例#3
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()
示例#4
0
 def update_servant_list(self):
     list_pos_y = 252
     for i in range(len(self.canvas_servant_list_bg)):
         self.canvas_servant_list.delete(self.canvas_servant_list_bg[i])
         self.canvas_servant_list.delete(
             self.canvas_servant_list_text_name[i])
         self.canvas_servant_list.delete(self.canvas_servant_list_image[i])
         self.canvas_servant_list.delete(
             self.canvas_servant_list_image_ref[i])
     for servant in self.servant_list[self.servant_list_page]:
         self.canvas_servant_list_bg.append(
             self.canvas_servant_list.create_rectangle(
                 123,
                 list_pos_y - 27,
                 580,
                 list_pos_y + 27,
                 fill="#2c2303",
                 tags=(servant['Name'], "servant_list")))
         self.canvas_servant_list_text_name.append(
             self.canvas_servant_list.create_text(180,
                                                  list_pos_y,
                                                  text=servant['Name'],
                                                  fill="#cccccc",
                                                  font=("Coolvetica Rg",
                                                        25),
                                                  anchor="w",
                                                  tags=(servant['Name'],
                                                        "servant_list")))
         try:
             servant_image = UIAssetImport.get_servant_icon(servant, 50, 50)
         except FileNotFoundError:
             GlobalLibrary.error(
                 str("Servant needs icon: " + servant['Name']))
             servant_image = UIAssetImport.image_resize(
                 "Pictures/Class-Shielder-Gold.png", 50, 50)
         self.canvas_servant_list_image_ref.append(servant_image)
         self.canvas_servant_list_image.append(
             self.canvas_servant_list.create_image(150,
                                                   list_pos_y,
                                                   image=servant_image,
                                                   anchor="c",
                                                   tags=(servant['Name'],
                                                         "servant_list")))
         list_pos_y += 55
     self.canvas_servant_list.tag_bind("servant_list", "<Button-1>",
                                       self.select_servant)
示例#5
0
    def show_servant_bio(self):
        for servant in self.servant_list[self.servant_list_page]:
            if servant['Name'] == self.selected_servant:
                self.servant_data = servant
        base_servant_data = Servants.get_servant(self.servant_data['Name'])
        self.canvas_servant_bio.create_image(415,
                                             500,
                                             image=self.ui_servant_bio,
                                             anchor="c",
                                             tags="servant_bio")
        self.canvas_servant_bio.create_text(220,
                                            280,
                                            text=self.servant_data['Name'],
                                            fill="#cccccc",
                                            font=("Coolvetica Rg", 30),
                                            anchor="w",
                                            tags="servant_bio")
        try:
            self.selected_servant_image = UIAssetImport.get_servant_icon(
                self.servant_data, 125, 125)
        except FileNotFoundError:
            GlobalLibrary.error("REMEMBER TO ADD ICON PATHS TO SERVANTS!!!")
            self.selected_servant_image = UIAssetImport.image_resize(
                "Pictures/Class-Shielder-Gold.png", 125, 125)
        self.canvas_servant_bio.create_image(107,
                                             315,
                                             image=self.selected_servant_image,
                                             anchor="c",
                                             tags="servant_bio")
        self.canvas_servant_bio.create_text(
            220,
            320,
            text=str("HP: " + str(self.servant_data['HP']) + " (" +
                     str(base_servant_data['HP']) + ")"),
            fill="#888888",
            font=("Coolvetica Rg", 15),
            anchor="w",
            tags="servant_bio")
        self.canvas_servant_bio.create_text(
            400,
            320,
            text=str("HP: " + str(self.servant_data['ATK']) + " (" +
                     str(base_servant_data['ATK']) + ")"),
            fill="#888888",
            font=("Coolvetica Rg", 15),
            anchor="w",
            tags="servant_bio")
        self.canvas_servant_bio.create_text(
            580,
            320,
            text=str("Move: " + str(self.servant_data['Move'])),
            fill="#888888",
            font=("Coolvetica Rg", 15),
            anchor="w",
            tags="servant_bio")
        self.canvas_servant_bio.create_rectangle(215,
                                                 340,
                                                 780,
                                                 370,
                                                 fill="#2c2303",
                                                 tags="servant_bio")

        self.canvas_servant_bio.create_rectangle(220,
                                                 345,
                                                 (self.servant_data['Level'] *
                                                  ((775 - 215) / 100)) + 215,
                                                 365,
                                                 fill="#433607",
                                                 tags="servant_bio")
        self.canvas_servant_bio.create_text(
            ((self.servant_data['Level'] * ((775 - 215) / 100)) / 2) + 215,
            355,
            text=str(self.servant_data['Level']),
            fill="#888888",
            font=("Coolvetica Rg", 12),
            anchor="c",
            tags="servant_bio")
        try:
            if self.servant_data['Class'] == "Saber":
                servant_class = self.ui_class_saber
            elif self.servant_data['Class'] == "Archer":
                servant_class = self.ui_class_archer
            elif self.servant_data['Class'] == "Lancer":
                servant_class = self.ui_class_lancer
            elif self.servant_data['Class'] == "Caster":
                servant_class = self.ui_class_caster
            elif self.servant_data['Class'] == "Rider":
                servant_class = self.ui_class_rider
            elif self.servant_data['Class'] == "Assassin":
                servant_class = self.ui_class_assassin
            elif self.servant_data['Class'] == "Ruler":
                servant_class = self.ui_class_ruler
            elif self.servant_data['Class'] == "Shielder":
                servant_class = self.ui_class_shielder
            elif self.servant_data['Class'] == "Berserker":
                servant_class = self.ui_class_berserker
            self.canvas_servant_bio.create_image(740,
                                                 290,
                                                 image=servant_class,
                                                 anchor="c",
                                                 tags="servant_bio")
        except KeyError:
            GlobalLibrary.error("REMEMBER TO ADD CLASSES TO SERVANTS")
        except UnboundLocalError:
            GlobalLibrary.error("REMEMBER TO ADD CLASSES TO SERVANTS")

        try:
            self.canvas_servant_bio.create_text(55,
                                                425,
                                                text=str(
                                                    self.servant_data['Desc']),
                                                fill="#888888",
                                                font=("Coolvetica Rg", 15),
                                                anchor="nw",
                                                justify="left",
                                                width=725,
                                                tags="servant_bio")
        except KeyError:
            GlobalLibrary.error("REMEMBER TO ADD DESCRIPTIONS TO SERVANTS")
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) - 160,
            image=self.ui_servant_list_button,
            anchor="c",
            tags=("servant_bio", "team_slot1"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) - 160,
            image=self.ui_right_arrow,
            anchor="c",
            tags=("servant_bio", "team_slot1"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) - 30,
            image=self.ui_servant_list_button,
            anchor="c",
            tags=("servant_bio", "team_slot2"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) - 30,
            image=self.ui_right_arrow,
            anchor="c",
            tags=("servant_bio", "team_slot2"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) + 100,
            image=self.ui_servant_list_button,
            anchor="c",
            tags=("servant_bio", "team_slot3"))
        self.canvas_team_list.create_image(
            100, (int(self.canvas_team_list.cget("height")) / 2) + 100,
            image=self.ui_right_arrow,
            anchor="c",
            tags=("servant_bio", "team_slot3"))
        self.canvas_team_list.tag_bind("team_slot1", "<Button-1>",
                                       self.set_player_servant)
        self.canvas_team_list.tag_bind("team_slot2", "<Button-1>",
                                       self.set_player_servant)
        self.canvas_team_list.tag_bind("team_slot3", "<Button-1>",
                                       self.set_player_servant)