From adbb5b6c7d390a6c8f533c2e4d611f4feadb7a79 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 25 Dec 2022 00:23:27 -0800 Subject: [PATCH] Disallow adding arbitrary weapons to Extra slots --- app/controllers/api/v1/api_controller.rb | 1 + .../api/v1/grid_weapons_controller.rb | 4 +++ .../incompatible_weapon_for_position_error.rb | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 app/errors/api/v1/incompatible_weapon_for_position_error.rb diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index 73c51a1..087b455 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -20,6 +20,7 @@ module Api rescue_from Api::V1::FavoriteAlreadyExistsError, with: :render_unprocessable_entity_response rescue_from Api::V1::NoJobProvidedError, with: :render_unprocessable_entity_response rescue_from Api::V1::TooManySkillsOfTypeError, with: :render_unprocessable_entity_response + rescue_from Api::V1::IncompatibleWeaponForPositionError, with: :render_unprocessable_entity_response rescue_from Api::V1::UnauthorizedError, with: :render_unauthorized_response rescue_from ActionController::ParameterMissing, with: :render_unprocessable_entity_response diff --git a/app/controllers/api/v1/grid_weapons_controller.rb b/app/controllers/api/v1/grid_weapons_controller.rb index 5f09416..8ecb573 100644 --- a/app/controllers/api/v1/grid_weapons_controller.rb +++ b/app/controllers/api/v1/grid_weapons_controller.rb @@ -16,6 +16,10 @@ module Api # Set up conflict_position in case it is used conflict_position = nil + if [9, 10, 11].include?(weapon_params[:position].to_i) && ![11, 16, 17, 28, 29].include?(incoming_weapon.series) + raise Api::V1::IncompatibleWeaponForPositionError.new(weapon: incoming_weapon) + end + # 1. If the weapon has a limit # 2. If the weapon does not match a weapon already in grid # 3. If the incoming weapon has a limit and other weapons of the same series are in grid diff --git a/app/errors/api/v1/incompatible_weapon_for_position_error.rb b/app/errors/api/v1/incompatible_weapon_for_position_error.rb new file mode 100644 index 0000000..48ab067 --- /dev/null +++ b/app/errors/api/v1/incompatible_weapon_for_position_error.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Api + module V1 + class IncompatibleWeaponForPositionError < GranblueError + def http_status + 422 + end + + def code + 'incompatible_weapon_for_position' + end + + def message + 'A weapon of this series cannot be added to Additional Weapons' + end + + def to_hash + { + message: message, + code: code, + weapon: @data[:weapon] + } + end + end + end +end