From 7647f5f1d6af72c1fe049ef2d858c7038a15d303 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Tue, 30 Dec 2025 22:45:33 -0800 Subject: [PATCH] update models for weapon_stat_modifier fks and befoulments --- app/models/collection_weapon.rb | 37 +++++++++++++++++++++++++++++++-- app/models/grid_weapon.rb | 25 ++++++++++++++++------ app/models/weapon_series.rb | 5 ++++- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/app/models/collection_weapon.rb b/app/models/collection_weapon.rb index a9c97e9..3b35146 100644 --- a/app/models/collection_weapon.rb +++ b/app/models/collection_weapon.rb @@ -8,15 +8,21 @@ class CollectionWeapon < ApplicationRecord belongs_to :weapon_key3, class_name: 'WeaponKey', optional: true belongs_to :weapon_key4, class_name: 'WeaponKey', optional: true + belongs_to :ax_modifier1, class_name: 'WeaponStatModifier', optional: true + belongs_to :ax_modifier2, class_name: 'WeaponStatModifier', optional: true + belongs_to :befoulment_modifier, class_name: 'WeaponStatModifier', optional: true + # Set defaults before validation so database defaults don't cause validation failures attribute :awakening_level, :integer, default: 1 validates :uncap_level, inclusion: { in: 0..5 } validates :transcendence_step, inclusion: { in: 0..10 } validates :awakening_level, inclusion: { in: 1..20 } + validates :exorcism_level, inclusion: { in: 0..5 }, allow_nil: true validate :validate_weapon_keys validate :validate_ax_skills + validate :validate_befoulment validate :validate_element_change validate :validate_awakening_compatibility validate :validate_awakening_level @@ -25,7 +31,7 @@ class CollectionWeapon < ApplicationRecord scope :by_weapon, ->(weapon_id) { where(weapon_id: weapon_id) } scope :by_series, ->(series_id) { joins(:weapon).where(weapons: { weapon_series_id: series_id }) } scope :with_keys, -> { where.not(weapon_key1_id: nil) } - scope :with_ax, -> { where.not(ax_modifier1: nil) } + scope :with_ax, -> { where.not(ax_modifier1_id: nil) } scope :by_element, ->(element) { joins(:weapon).where(weapons: { element: element }) } scope :by_rarity, ->(rarity) { joins(:weapon).where(weapons: { rarity: rarity }) } scope :by_proficiency, ->(proficiency) { joins(:weapon).where(weapons: { proficiency: proficiency }) } @@ -83,16 +89,43 @@ class CollectionWeapon < ApplicationRecord end def validate_ax_skills - # Check for incomplete AX skills regardless of weapon.ax + # AX skill 1: must have both modifier and strength if (ax_modifier1.present? && ax_strength1.blank?) || (ax_modifier1.blank? && ax_strength1.present?) errors.add(:base, "AX skill 1 must have both modifier and strength") end + # AX skill 2: must have both modifier and strength if (ax_modifier2.present? && ax_strength2.blank?) || (ax_modifier2.blank? && ax_strength2.present?) errors.add(:base, "AX skill 2 must have both modifier and strength") end + + # Validate category is 'ax' + if ax_modifier1.present? && ax_modifier1.category != 'ax' + errors.add(:ax_modifier1, "must be an AX skill modifier") + end + if ax_modifier2.present? && ax_modifier2.category != 'ax' + errors.add(:ax_modifier2, "must be an AX skill modifier") + end + end + + def validate_befoulment + # Befoulment: must have both modifier and strength + if (befoulment_modifier.present? && befoulment_strength.blank?) || + (befoulment_modifier.blank? && befoulment_strength.present?) + errors.add(:base, "Befoulment must have both modifier and strength") + end + + # Validate category is 'befoulment' + if befoulment_modifier.present? && befoulment_modifier.category != 'befoulment' + errors.add(:befoulment_modifier, "must be a befoulment modifier") + end + + # Exorcism level only makes sense with befoulment + if exorcism_level.present? && exorcism_level > 0 && befoulment_modifier.blank? + errors.add(:exorcism_level, "cannot be set without a befoulment") + end end def validate_element_change diff --git a/app/models/grid_weapon.rb b/app/models/grid_weapon.rb index e9bc7a4..921acc8 100644 --- a/app/models/grid_weapon.rb +++ b/app/models/grid_weapon.rb @@ -39,6 +39,10 @@ class GridWeapon < ApplicationRecord belongs_to :awakening, optional: true belongs_to :collection_weapon, optional: true + belongs_to :ax_modifier1, class_name: 'WeaponStatModifier', optional: true + belongs_to :ax_modifier2, class_name: 'WeaponStatModifier', optional: true + belongs_to :befoulment_modifier, class_name: 'WeaponStatModifier', optional: true + # Validate that uncap_level is present and numeric, transcendence_step is optional but must be numeric if present. validates :uncap_level, presence: true, numericality: { only_integer: true } validates :transcendence_step, numericality: { only_integer: true }, allow_nil: true @@ -51,10 +55,13 @@ class GridWeapon < ApplicationRecord ##### Amoeba configuration amoeba do - nullify :ax_modifier1 - nullify :ax_modifier2 + nullify :ax_modifier1_id + nullify :ax_modifier2_id nullify :ax_strength1 nullify :ax_strength2 + nullify :befoulment_modifier_id + nullify :befoulment_strength + nullify :exorcism_level end ## @@ -80,10 +87,13 @@ class GridWeapon < ApplicationRecord weapon_key2_id: collection_weapon.weapon_key2_id, weapon_key3_id: collection_weapon.weapon_key3_id, weapon_key4_id: collection_weapon.weapon_key4_id, - ax_modifier1: collection_weapon.ax_modifier1, + ax_modifier1_id: collection_weapon.ax_modifier1_id, ax_strength1: collection_weapon.ax_strength1, - ax_modifier2: collection_weapon.ax_modifier2, + ax_modifier2_id: collection_weapon.ax_modifier2_id, ax_strength2: collection_weapon.ax_strength2, + befoulment_modifier_id: collection_weapon.befoulment_modifier_id, + befoulment_strength: collection_weapon.befoulment_strength, + exorcism_level: collection_weapon.exorcism_level, awakening_id: collection_weapon.awakening_id, awakening_level: collection_weapon.awakening_level ) @@ -104,10 +114,13 @@ class GridWeapon < ApplicationRecord weapon_key2_id != collection_weapon.weapon_key2_id || weapon_key3_id != collection_weapon.weapon_key3_id || weapon_key4_id != collection_weapon.weapon_key4_id || - ax_modifier1 != collection_weapon.ax_modifier1 || + ax_modifier1_id != collection_weapon.ax_modifier1_id || ax_strength1 != collection_weapon.ax_strength1 || - ax_modifier2 != collection_weapon.ax_modifier2 || + ax_modifier2_id != collection_weapon.ax_modifier2_id || ax_strength2 != collection_weapon.ax_strength2 || + befoulment_modifier_id != collection_weapon.befoulment_modifier_id || + befoulment_strength != collection_weapon.befoulment_strength || + exorcism_level != collection_weapon.exorcism_level || awakening_id != collection_weapon.awakening_id || awakening_level != collection_weapon.awakening_level end diff --git a/app/models/weapon_series.rb b/app/models/weapon_series.rb index 54cd116..bc8f9a2 100644 --- a/app/models/weapon_series.rb +++ b/app/models/weapon_series.rb @@ -5,6 +5,8 @@ class WeaponSeries < ApplicationRecord has_many :weapon_key_series, dependent: :destroy has_many :weapon_keys, through: :weapon_key_series + enum :augment_type, { none: 0, ax: 1, befoulment: 2 }, default: :none + validates :name_en, presence: true validates :name_jp, presence: true validates :slug, presence: true, uniqueness: true @@ -15,7 +17,8 @@ class WeaponSeries < ApplicationRecord scope :element_changeable, -> { where(element_changeable: true) } scope :with_weapon_keys, -> { where(has_weapon_keys: true) } scope :with_awakening, -> { where(has_awakening: true) } - scope :with_ax_skills, -> { where(has_ax_skills: true) } + scope :with_ax_skills, -> { where(augment_type: :ax) } + scope :with_befoulments, -> { where(augment_type: :befoulment) } # Slug constants for commonly referenced series DARK_OPUS = 'dark-opus'