def __init__(self, GUI, grid_size): GlobalLibrary.initalise(Battle.__name__) # INTERFACE ASSETS GUI.logo_image = self.image_resize("Pictures/Logo.png", int(GUI.monitor_resolution_x / 10), int(GUI.monitor_resolution_y / 10)) GUI.ui_servant_select_stats_bg = self.image( "Pictures/UI/ServantSelectStats.png") GUI.ui_turn_order_bg = self.image("Pictures/UI/TurnOrder.png") GUI.ui_move_icon = self.image_resize("Pictures/UI/MoveIcon.png", grid_size, grid_size) GUI.ui_attack_icon = self.image_resize("Pictures/UI/AttackIcon.png", grid_size, grid_size) # CLASS LOGOS GUI.ui_class_saber = self.image("Pictures/Classes/Saber.png") GUI.ui_class_archer = self.image("Pictures/Classes/Archer.png") GUI.ui_class_lancer = self.image("Pictures/Classes/Lancer.png") GUI.ui_class_caster = self.image("Pictures/Classes/Caster.png") GUI.ui_class_rider = self.image("Pictures/Classes/Rider.png") GUI.ui_class_assassin = self.image("Pictures/Classes/Assassin.png") GUI.ui_class_ruler = self.image("Pictures/Classes/Ruler.png") GUI.ui_class_shielder = self.image("Pictures/Classes/Shielder.png") GUI.ui_class_berserker = self.image("Pictures/Classes/Berserker.png") GlobalLibrary.notice("Battle Graphical Assets Imported")
def start_enemy_turn(self, entity, x, y): GlobalLibrary.notice( str("Enemy " + entity['Name'] + "'s turn has started!")) target_list = [] for pos_y in range(len(self.grid_manager.grid)): for pos_x in range(len(self.grid_manager.grid[pos_y])): pos = self.grid_manager.grid[pos_y][pos_x] if isinstance(pos, dict): if pos['Allied']: distance = int(abs(x - pos_x) + abs(y - pos_y) / 2) strength = int(((pos['HP'] + pos['ATK']) / 1000) + (pos['Range'])) level_gap = entity['Level'] - pos['Level'] danger_value = 10 + int(( (-distance + strength) - (int(pos['CurrentHP'] / 5000))) + (level_gap / 2)) target = [pos, pos_x, pos_y, danger_value] target_list.append(target) if len(target_list) > 0: current_target = target_list[0] for target in target_list: if target[3] > current_target[3]: current_target = target if int(abs(x - current_target[1])) <= entity['Range'] and int( abs(y - current_target[2])) <= entity['Range']: self.GUI.servant_selected_attack(entity, current_target[0], current_target[1], current_target[2]) elif int(abs(x - current_target[1])) <= int( entity['Move'] * 2) and int( abs(y - current_target[2])) <= int(entity['Move'] * 2): new_x = (x - current_target[1]) % entity['Move'] if new_x == 0 and current_target[1] < x: new_x = (x - entity['Move']) + 1 elif new_x == 0 and current_target[1] > x: new_x = (x + entity['Move']) - 1 elif new_x != 0 and current_target[1] < x: new_x = x - new_x elif new_x != 0 and current_target[1] > x: new_x = x + new_x else: new_x = x new_y = (y - current_target[2]) % entity['Move'] if new_y == 0 and current_target[2] < y: new_y = (y - entity['Move']) + 1 elif new_y == 0 and current_target[2] > y: new_y = (y + entity['Move']) - 1 elif new_y != 0 and current_target[2] < y: new_y = y - new_y elif new_y != 0 and current_target[2] > y: new_y = y + new_y else: new_y = y self.grid_manager.move_grid_pos(x, y, new_x, new_y, True)
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"
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()
def __init__(self, GUI): GlobalLibrary.initalise(Cover.__name__) image_reference = Image.open( str("Pictures/Wallpapers/" + random.choice(os.listdir("Pictures/Wallpapers")))) image_reference = image_reference.resize( (GUI.monitor_resolution_x, GUI.monitor_resolution_y), Image.ANTIALIAS) GUI.wallpaper = ImageTk.PhotoImage(image_reference) GUI.logo_image = self.image_resize("Pictures/Logo.png", int(GUI.monitor_resolution_x / 4), int(GUI.monitor_resolution_y / 4)) GUI.ui_click_to_start = self.image_scale( "Pictures/UI/ClickToStart.png", 0.5) GlobalLibrary.notice("Menu Graphical Assets Imported")
def __init__(self, GUI): GlobalLibrary.initalise(Menu.__name__) # INTERFACE ASSETS GUI.logo_image = self.image_resize("Pictures/Logo.png", int(GUI.monitor_resolution_x / 10), int(GUI.monitor_resolution_y / 10)) GUI.ui_servant_list = self.image("Pictures/UI/ServantList.png") GUI.ui_servant_list_button = self.image( "Pictures/UI/ServantListButton.png") GUI.ui_servant_list_title = self.image( "Pictures/UI/ServantListTitle.png") GUI.ui_servant_bio = self.image("Pictures/UI/ServantBio.png") GUI.ui_fight_button = self.image("Pictures/UI/FightButton.png") GUI.ui_team_list = self.image("Pictures/UI/TeamList.png") # GENERIC ICONS GUI.ui_right_arrow = self.image_resize("Pictures/UI/RightArrow.png", 20, 20) GUI.ui_left_arrow = self.image_resize("Pictures/UI/LeftArrow.png", 20, 20) GUI.ui_refresh = self.image_resize("Pictures/UI/Refresh.png", 20, 20) # CLASS LOGOS GUI.ui_class_saber = self.image_scale("Pictures/Classes/Saber.png", 0.7) GUI.ui_class_archer = self.image_scale("Pictures/Classes/Archer.png", 0.7) GUI.ui_class_lancer = self.image_scale("Pictures/Classes/Lancer.png", 0.7) GUI.ui_class_caster = self.image_scale("Pictures/Classes/Caster.png", 0.7) GUI.ui_class_rider = self.image_scale("Pictures/Classes/Rider.png", 0.7) GUI.ui_class_assassin = self.image_scale( "Pictures/Classes/Assassin.png", 0.7) GUI.ui_class_ruler = self.image_scale("Pictures/Classes/Ruler.png", 0.7) GUI.ui_class_shielder = self.image_scale( "Pictures/Classes/Shielder.png", 0.7) GUI.ui_class_berserker = self.image_scale( "Pictures/Classes/Berserker.png", 0.7) GlobalLibrary.notice("Menu Graphical Assets Imported")
def next_turn(self): allies_remaining = False for servant in self.TurnCounterList: servant_data, servant_x, servant_y = self.grid_manager.find_servant( servant) if servant_data['Allied'] == True: allies_remaining = True if allies_remaining == False: self.GUI.open_main_menu("") self.CurrentTurnCounter += 1 if self.CurrentTurnCounter > len(self.TurnCounterList) - 1: self.CurrentTurnCounter = 0 self.OverallTurnCounter += 1 GlobalLibrary.notice(str("Turn: " + str(self.OverallTurnCounter))) self.display_current_turn() servant_data, servant_x, servant_y = self.grid_manager.find_servant( self.TurnCounterList[self.CurrentTurnCounter]) if not servant_data["Allied"]: self.enemy_AI.start_enemy_turn(servant_data, servant_x, servant_y) self.next_turn()
def servant_selected_attack(self, attacking_servant, target_servant, x, y): if random.randint(0, 20) == 30: damage = int(attacking_servant['ATK'] / 2 * (random.randint(7, 10) / 10)) target_servant['CurrentHP'] -= damage GlobalLibrary.notice( str(attacking_servant['Name'] + " critted " + target_servant['Name'] + " for " + str(damage))) else: damage = int(attacking_servant['ATK'] * (random.randint(7, 10) / 10)) target_servant['CurrentHP'] -= damage GlobalLibrary.notice( str(attacking_servant['Name'] + " attacked " + target_servant['Name'] + " for " + str(damage))) if target_servant['CurrentHP'] <= 0: self.grid_manager.set_grid_pos(x, y, "#", True) for image in self.image_ref_array: if image['Name'] == target_servant['Name']: image_ref = image['Image'] self.canvas.delete(image_ref) GlobalLibrary.notice(str(target_servant['Name'] + " has died!")) self.turn_tracker.TurnCounterList.remove(target_servant['Name']) self.turn_tracker.CurrentTurnCounter -= 1
def load_tileset(tileset, grid_size, GUI): # TERRAIN TILES GUI.ui_tiles = {} for tile in tileset: GUI.ui_tiles.update( {tile[0]: image_resize(tile[1], grid_size, grid_size)}) GlobalLibrary.notice("Tileset Imported")
def servant_selected_both(self, click_selection): GlobalLibrary.notice(click_selection['Name'] + " selected.") self.selected_servant = click_selection selected_servant_move = (self.selected_servant['Move'] * 2) + 1 selected_servant_move_start_x = ( (self.grid_clicked_x * self.grid_size) - (self.selected_servant['Move'] * self.grid_size)) selected_servant_move_start_y = ( (self.grid_clicked_y * self.grid_size) - (self.selected_servant['Move'] * self.grid_size)) for row in range(selected_servant_move): for column in range(selected_servant_move): x = int(column + (selected_servant_move_start_x / self.grid_size)) y = int(row + (selected_servant_move_start_y / self.grid_size)) if 0 <= x < self.grid_amount and 0 <= y < self.grid_amount: if self.grid_manager.get_grid_pos(x, y) == "#": x_start = selected_servant_move_start_x + ( column * self.grid_size) + self.grid_origin_x y_start = selected_servant_move_start_y + ( row * self.grid_size) + self.grid_origin_y selection_box = self.canvas.create_image( x_start, y_start, image=self.ui_move_icon, anchor="nw", tags="move_selection_box") self.selection_array.append(selection_box) self.canvas.tag_bind("move_selection_box", "<Button-1>", self.servant_selected_move_click) selected_servant_attack = (self.selected_servant['Range'] * 2) + 1 selected_servant_attack_start_x = ( (self.grid_clicked_x * self.grid_size) - (self.selected_servant['Range'] * self.grid_size)) selected_servant_attack_start_y = ( (self.grid_clicked_y * self.grid_size) - (self.selected_servant['Range'] * self.grid_size)) for row in range(selected_servant_attack): for column in range(selected_servant_attack): x = int(column + (selected_servant_attack_start_x / self.grid_size)) y = int(row + (selected_servant_attack_start_y / self.grid_size)) if 0 <= x < (self.grid_amount - 2) and 0 <= y < (self.grid_amount - 2): grid_pos_ref = self.grid_manager.get_grid_pos(x, y) if not isinstance(grid_pos_ref, str): if grid_pos_ref['Allied'] is False: x_start = (selected_servant_attack_start_x + (column * self.grid_size) + self.grid_origin_x) y_start = (selected_servant_attack_start_y + (row * self.grid_size) + self.grid_origin_y) selection_box = self.canvas.create_image( x_start, y_start, image=self.ui_attack_icon, anchor="nw", tags="attack_selection_box") self.selection_array.append(selection_box) self.canvas.tag_bind("attack_selection_box", "<Button-1>", self.servant_selected_attack_event) self.display_servant_stats()