def parse(self, dbr, dbr_file, result): file_name = os.path.basename(dbr_file).split('_') difficulty = self.DIFFICULTIES_LIST[int(file_name[0][1:]) - 1] result.update({ # The act it starts dropping in is also listed in the file name 'act': file_name[1], # Bitmap has a different key name than items here. 'bitmap': dbr.get('relicBitmap', None), # Difficulty classification is based on the file name 'classification': texts.get(difficulty).strip(), # Ironically the itemText holds the actual description tag 'description': texts.get(dbr['itemText']), # For relics the tag is in the Actor.tpl variable 'description' 'name': texts.get(dbr['description']), 'tag': dbr['description'], }) # The possible completion bonuses are in bonusTableName: bonuses = {} try: bonuses = DBRParser.parse(dbr['bonusTableName']) except InvalidItemError as e: logging.debug("Could not parse relic completion bonus information " f"for {result['name']} in {dbr_file}. {e}") result['bonus'] = bonuses.get('table', []) # Find how many pieces this relic has max_pieces = TQDBParser.highest_tier( result['properties'], result['properties'].keys()) # Initialize a list of tiers properties = [{} for i in range(max_pieces)] # Setup properties as list to correspond to adding pieces of a relic: for key, values in result['properties'].items(): if not isinstance(values, list): # This property is just repeated for all tiers: for i in range(max_pieces): properties[i][key] = values continue for index, value in enumerate(values): properties[index][key] = value result['properties'] = properties
def parse(self, dbr, dbr_file, result): file_name = os.path.basename(dbr_file).split('_') difficulty = self.DIFFICULTIES_LIST[int(file_name[0][1:]) - 1] result.update({ # The act it starts dropping in is also listed in the file name 'act': file_name[1], # Bitmap has a different key name than items here. 'bitmap': dbr.get('relicBitmap', None), # Difficulty classification is based on the file name 'classification': texts.get(difficulty).strip(), # Ironically the itemText holds the actual description tag 'description': texts.get(dbr['itemText']), # For relics the tag is in the Actor.tpl variable 'description' 'name': texts.get(dbr['description']), 'tag': dbr['description'], }) # The possible completion bonuses are in bonusTableName: bonuses = DBRParser.parse(dbr['bonusTableName']) result['bonus'] = bonuses.get('table', []) # Find how many pieces this relic has max_pieces = TQDBParser.highest_tier( result['properties'], result['properties'].keys()) # Initialize a list of tiers properties = [{} for i in range(max_pieces)] # Setup properties as list to correspond to adding pieces of a relic: for key, values in result['properties'].items(): if not isinstance(values, list): # This property is just repeated for all tiers: for i in range(max_pieces): properties[i][key] = values continue for index, value in enumerate(values): properties[index][key] = value result['properties'] = properties
def parse(self, dbr, dbr_file, result): """ Parse the base properties of a skill. These properties include the skillDisplayName, its friendly display name (the property returns a tag), and the maximum level of a skill. """ # Store the path to this skill, it is used in tqdb.storage to ensure # all tags are unique. result['path'] = dbr_file if self.NAME in dbr: # The tag is the skillDisplayName property result['tag'] = self.FORMATTER.sub('', dbr[self.NAME]) # Now try to find a friendly name for the tag: result['name'] = texts.get(result['tag']) if result['name'] == result['tag']: # If the tag wasn't returned, a friendly name weas found: logging.debug(f'No skill name found for {result["tag"]}') else: logging.debug(f'No skillDisplayName found in {dbr_file}') if self.DESC in dbr and texts.has(dbr[self.DESC]): # Also load the description, if it's known: result['description'] = texts.get(dbr[self.DESC]) elif self.FILE in dbr: # Use the FileDescription instead: result['description'] = dbr['FileDescription'] # Check the skill base fields: base_tiers = TQDBParser.highest_tier(dbr, self.FIELDS) for field in self.FIELDS: for index in range(base_tiers): itr_dbr = TQDBParser.extract_values(dbr, field, index) if field not in itr_dbr or itr_dbr[field] <= 0.01: continue # Insert this skill property value = texts.get(field).format(itr_dbr[field]) TQDBParser.insert_value(field, value, result) # Check the damage absorption skill properties: abs_tiers = TQDBParser.highest_tier(dbr, self.ABSORPTIONS) for field in self.ABSORPTIONS: for index in range(abs_tiers): itr_dbr = TQDBParser.extract_values(dbr, field, index) if field not in itr_dbr: continue # Add 'skill' prefix and capitalize first letter: field_prefixed = 'skill' + field[:1].upper() + field[1:] value = itr_dbr[field] # Find qualifier damage type(s): damage_types = ', '.join([ texts.get(text_key) for dmg_type, text_key in self.QUALIFIERS.items() if dmg_type in dbr ]) if damage_types: TQDBParser.insert_value( field_prefixed, f'{texts.get(field_prefixed).format(value)} ' f'({damage_types})', result) else: # If there is no qualifier, it's all damage: TQDBParser.insert_value( field_prefixed, texts.get(field_prefixed).format(value), result) # Prepare two variables to determine the max number of tiers: skill_cap = dbr.get('skillUltimateLevel', dbr.get('skillMaxLevel')) or 99 props = result['properties'] # The maximum number of properties is now the minimum between the skill # cap and the highest number of tiers available in the properties: max_tiers = min(TQDBParser.highest_tier(props, props.keys()), skill_cap) # After all skill properties have been set, index them by level: properties = [{} for i in range(max_tiers)] # Insert the existing properties by adding them to the correct tier: for field, values in result['properties'].items(): for index in range(max_tiers): # Each value is either a list or a flat value to repeat: if isinstance(values, list): # Properties that are capped before this tier repeat their # last value: if index >= len(values): properties[index][field] = values[len(values) - 1] else: properties[index][field] = values[index] else: properties[index][field] = values # For summoned skills it's very likely a lot of extraneous empty # property tiers were added, filter those out: properties = [tier for tier in properties if tier] # Now set the reindexed properties: result['properties'] = properties
def parse(self, dbr, dbr_file, result): """ Parse the base properties of a skill. These properties include the skillDisplayName, its friendly display name (the property returns a tag), and the maximum level of a skill. """ # Store the path to this skill, it is used in tqdb.storage to ensure # all tags are unique. result['path'] = dbr_file if self.NAME in dbr: # The tag is the skillDisplayName property result['tag'] = self.FORMATTER.sub('', dbr[self.NAME]) # Now try to find a friendly name for the tag: result['name'] = texts.get(result['tag']) if result['name'] == result['tag']: # If the tag wasn't returned, a friendly name weas found: logging.debug(f'No skill name found for {result["tag"]}') else: logging.debug(f'No skillDisplayName found in {dbr_file}') if self.DESC in dbr and texts.has(dbr[self.DESC]): # Also load the description, if it's known: result['description'] = texts.get(dbr[self.DESC]) elif self.FILE in dbr: # Use the FileDescription instead: result['description'] = dbr['FileDescription'] # Check the skill base fields: base_tiers = TQDBParser.highest_tier(dbr, self.FIELDS) for field in self.FIELDS: for index in range(base_tiers): itr_dbr = TQDBParser.extract_values(dbr, field, index) if field not in itr_dbr or itr_dbr[field] <= 0.01: continue # Insert this skill property value = texts.get(field).format(itr_dbr[field]) TQDBParser.insert_value(field, value, result) # Check the damage absorption skill properties: abs_tiers = TQDBParser.highest_tier(dbr, self.ABSORPTIONS) for field in self.ABSORPTIONS: for index in range(abs_tiers): itr_dbr = TQDBParser.extract_values(dbr, field, index) if field not in itr_dbr: continue # Add 'skill' prefix and capitalize first letter: field_prefixed = 'skill' + field[:1].upper() + field[1:] value = itr_dbr[field] # Find qualifier damage type(s): damage_types = ', '.join([ texts.get(text_key) for dmg_type, text_key in self.QUALIFIERS.items() if dmg_type in dbr]) if damage_types: TQDBParser.insert_value( field_prefixed, f'{texts.get(field_prefixed).format(value)} ' f'({damage_types})', result) else: # If there is no qualifier, it's all damage: TQDBParser.insert_value( field_prefixed, texts.get(field_prefixed).format(value), result) # Prepare two variables to determine the max number of tiers: skill_cap = dbr.get('skillUltimateLevel', dbr.get('skillMaxLevel')) props = result['properties'] # The maximum number of properties is now the minimum between the skill # cap and the highest number of tiers available in the properties: max_tiers = min( TQDBParser.highest_tier(props, props.keys()), skill_cap) # After all skill properties have been set, index them by level: properties = [{} for i in range(max_tiers)] # Insert the existing properties by adding them to the correct tier: for field, values in result['properties'].items(): for index in range(max_tiers): # Each value is either a list or a flat value to repeat: if isinstance(values, list): # Properties that are capped before this tier repeat their # last value: if index >= len(values): properties[index][field] = values[len(values) - 1] else: properties[index][field] = values[index] else: properties[index][field] = values # For summoned skills it's very likely a lot of extraneous empty # property tiers were added, filter those out: properties = [tier for tier in properties if tier] # Now set the reindexed properties: result['properties'] = properties