validate mainhand weapon proficiency matches job
This commit is contained in:
parent
3afee9463f
commit
5ea5388bed
1 changed files with 21 additions and 0 deletions
|
|
@ -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.
|
||||
#
|
||||
|
|
|
|||
Loading…
Reference in a new issue