From 4ace9a9d495a6fac9f014c0f523cc31cd50d32ad Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Tue, 30 Dec 2025 22:49:40 -0800 Subject: [PATCH] update import service for weapon_stat_modifier fks and befoulments --- app/services/weapon_import_service.rb | 84 ++++++++++++++++++++------- 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/app/services/weapon_import_service.rb b/app/services/weapon_import_service.rb index 6923395..3c6a943 100644 --- a/app/services/weapon_import_service.rb +++ b/app/services/weapon_import_service.rb @@ -33,6 +33,7 @@ class WeaponImportService @skipped = [] @errors = [] @awakening_cache = {} + @modifier_cache = {} end ## @@ -146,9 +147,18 @@ class WeaponImportService awakening_attrs = parse_awakening(param['arousal']) attrs.merge!(awakening_attrs) if awakening_attrs - # Parse AX skills if present - ax_attrs = parse_ax_skills(param['augment_skill_info']) - attrs.merge!(ax_attrs) if ax_attrs + # Check if this is an Odiant (befoulment) weapon + odiant = param['odiant'] + if odiant && odiant['is_odiant_weapon'] == true + # Parse befoulment from augment_skill_info + befoulment_attrs = parse_befoulment(param['augment_skill_info']) + attrs.merge!(befoulment_attrs) if befoulment_attrs + attrs[:exorcism_level] = odiant['exorcision_level'].to_i.clamp(0, 5) + else + # Regular weapon - parse AX skills + ax_attrs = parse_ax_skills(param['augment_skill_info']) + attrs.merge!(ax_attrs) if ax_attrs + end attrs end @@ -207,18 +217,18 @@ class WeaponImportService # First AX skill if skills[0].is_a?(Hash) - ax1 = parse_single_ax_skill(skills[0]) + ax1 = parse_single_augment_skill(skills[0]) if ax1 - attrs[:ax_modifier1] = ax1[:modifier] + attrs[:ax_modifier1_id] = ax1[:modifier_id] attrs[:ax_strength1] = ax1[:strength] end end # Second AX skill if skills[1].is_a?(Hash) - ax2 = parse_single_ax_skill(skills[1]) + ax2 = parse_single_augment_skill(skills[1]) if ax2 - attrs[:ax_modifier2] = ax2[:modifier] + attrs[:ax_modifier2_id] = ax2[:modifier_id] attrs[:ax_strength2] = ax2[:strength] end end @@ -227,26 +237,60 @@ class WeaponImportService end ## - # Parses a single AX skill from game data. + # Parses befoulment data from game format. + # Odiant weapons have a single befoulment in augment_skill_info. # - # @param skill [Hash] Single AX skill data with skill_id and effect_value - # @return [Hash, nil] { modifier:, strength: } or nil - def parse_single_ax_skill(skill) - return nil unless skill['skill_id'].present? + # @param augment_skill_info [Array] The game's augment skill data + # @return [Hash, nil] Befoulment attributes or nil if no befoulment + def parse_befoulment(augment_skill_info) + return nil if augment_skill_info.blank? || !augment_skill_info.is_a?(Array) - # The skill_id maps to our AX modifier - modifier = skill['skill_id'].to_i + skills = augment_skill_info.first + return nil if skills.blank? || !skills.is_a?(Array) - # Parse strength from effect_value (may be "3" or "1_3" format) - # or from show_value (may be "3%" format) - strength = parse_ax_strength(skill['effect_value'], skill['show_value']) + skill = skills.first + return nil unless skill.is_a?(Hash) - return nil unless strength + result = parse_single_augment_skill(skill) + return nil unless result - { modifier: modifier, strength: strength } + { + befoulment_modifier_id: result[:modifier_id], + befoulment_strength: result[:strength] + } end - def parse_ax_strength(effect_value, show_value) + ## + # Parses a single augment skill (AX or befoulment) from game data. + # + # @param skill [Hash] Single skill data with skill_id and effect_value + # @return [Hash, nil] { modifier_id:, strength: } or nil + def parse_single_augment_skill(skill) + return nil unless skill['skill_id'].present? + + game_skill_id = skill['skill_id'].to_i + modifier = find_modifier_by_game_skill_id(game_skill_id) + + unless modifier + # Log unknown skill ID with icon for discovery + Rails.logger.warn( + "[WeaponImportService] Unknown augment skill_id=#{game_skill_id} " \ + "icon=#{skill['augment_skill_icon_image']}" + ) + return nil + end + + strength = parse_augment_strength(skill['effect_value'], skill['show_value']) + return nil unless strength + + { modifier_id: modifier.id, strength: strength } + end + + def find_modifier_by_game_skill_id(game_skill_id) + @modifier_cache[game_skill_id] ||= WeaponStatModifier.find_by(game_skill_id: game_skill_id) + end + + def parse_augment_strength(effect_value, show_value) # Try effect_value first if effect_value.present? # Handle "1_3" format (seems to be "tier_value")