GridWeapon decides if it is mainhand or not

This commit is contained in:
Justin Edmund 2023-02-01 21:45:57 -08:00
parent 2dd6dbae57
commit 260ca449a7
2 changed files with 12 additions and 0 deletions

View file

@ -167,6 +167,7 @@ module Api
output = render_conflict_view([conflict_weapon], incoming_weapon, weapon_params[:position])
render json: output
else
ap "Moving weapon to new position..."
# Move the original grid weapon to the new position
# to preserve keys and other modifications
old_position = conflict_weapon.position

View file

@ -13,6 +13,8 @@ class GridWeapon < ApplicationRecord
validate :compatible_with_position, on: :create
validate :no_conflicts, on: :create
before_save :is_mainhand
##### Amoeba configuration
amoeba do
nullify :ax_modifier1
@ -71,4 +73,13 @@ class GridWeapon < ApplicationRecord
# Check if the grid weapon conflicts with any of the other grid weapons in the party
errors.add(:series, 'must not conflict with existing weapons') unless conflicts(party).nil?
end
# Checks if the weapon should be a mainhand before saving the model
def is_mainhand
if self.position == -1
self.mainhand = true
else
self.mainhand = false
end
end
end