Refined selecting skills based on job
* Bugfix: You can now select a third subskill on Rows 1, 2 and 3 * Edgecase: When switching from a Row 1, 2 or 3 class to Row 4, 5 or EX2, the third EMP skill set is removed
This commit is contained in:
parent
8c1d51fb4f
commit
874c20245d
1 changed files with 12 additions and 5 deletions
|
|
@ -13,6 +13,7 @@ module Api
|
|||
raise NoJobProvidedError unless job_params[:job_id].present?
|
||||
|
||||
# Extract job and find its main skills
|
||||
old_job = @party.job
|
||||
job = Job.find(job_params[:job_id])
|
||||
main_skills = JobSkill.where(job: job.id, main: true)
|
||||
|
||||
|
|
@ -27,6 +28,13 @@ module Api
|
|||
@party[key] = nil if @party[key] && mismatched_skill(@party.job, JobSkill.find(@party[key]))
|
||||
end
|
||||
|
||||
# Remove extra subskills if necessary
|
||||
if %w[1 2 3].include?(old_job.row) &&
|
||||
%w[4 5 ex2].include?(job.row) &&
|
||||
@party.skill1.sub && @party.skill2.sub && @party.skill3.sub
|
||||
@party['skill3_id'] = nil
|
||||
end
|
||||
|
||||
render json: PartyBlueprint.render(@party, view: :jobs) if @party.save!
|
||||
end
|
||||
|
||||
|
|
@ -122,16 +130,15 @@ module Api
|
|||
end
|
||||
|
||||
def can_add_skill_of_type(skills, position, type)
|
||||
if skills.values.compact.length.positive?
|
||||
if %w[4 5 ex2].include?(@party.job.row) && skills.values.compact.length.positive?
|
||||
max_skill_of_type = 2
|
||||
skills_to_check = skills.compact.reject { |key, _| key == position }
|
||||
|
||||
sum = skills_to_check.values.count { |value| value.send(type) }
|
||||
|
||||
sum + 1 <= max_skill_of_type
|
||||
else
|
||||
true
|
||||
return sum + 1 <= max_skill_of_type
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def mismatched_skill(job, skill)
|
||||
|
|
|
|||
Loading…
Reference in a new issue