validate mainhand weapon proficiency matches job

This commit is contained in:
Justin Edmund 2025-12-20 02:13:28 -08:00
parent 3afee9463f
commit 5ea5388bed

View file

@ -44,6 +44,7 @@ class GridWeapon < ApplicationRecord
validates :transcendence_step, numericality: { only_integer: true }, allow_nil: true
validate :compatible_with_position, on: :create
validate :compatible_with_job_proficiency, on: :create
validate :no_conflicts, on: :create
before_save :assign_mainhand
@ -190,6 +191,26 @@ class GridWeapon < ApplicationRecord
errors.add(:series, 'must not conflict with existing weapons') if conflicting.any?
end
##
# Validates that mainhand weapon proficiency matches the job's proficiency.
#
# For position -1 (mainhand), the weapon's proficiency must match either
# the party's job proficiency1 or proficiency2.
#
# @return [void]
def compatible_with_job_proficiency
return unless position == -1 # Only validate mainhand
return unless weapon.present? && party&.job.present?
job = party.job
weapon_prof = weapon.proficiency
# Weapon proficiency must match one of the job's proficiencies
unless [job.proficiency1, job.proficiency2].include?(weapon_prof)
errors.add(:weapon, 'proficiency must match job proficiency for mainhand')
end
end
##
# Determines if the grid weapon should be marked as mainhand based on its position.
#