From 874c20245dc288891b0bfd76af09ad60431dde51 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 22 Dec 2022 23:27:24 -0800 Subject: [PATCH] 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 --- app/controllers/api/v1/jobs_controller.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index f404337..2bf21a0 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -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)