update models for weapon_stat_modifier fks and befoulments
This commit is contained in:
parent
9074f7301f
commit
7647f5f1d6
3 changed files with 58 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Reference in a new issue