Add basic validation for various mastery bonuses
* Ensure transcendence is possible on that character * Ensure transcendence_step is in bounds * Ensure Over Mastery Attack is a valid value * Ensure Over Mastery HP is a valid value * Ensure Over Mastery Attack is 2x Over Mastery HP * Ensure Awakening level is in bounds
This commit is contained in:
parent
beb9f5aa0c
commit
5351123aa2
2 changed files with 50 additions and 0 deletions
|
|
@ -14,6 +14,10 @@ module Api
|
|||
field :errors, if: ->(_field_name, _error, options) { options.key?(:exception) } do |_, options|
|
||||
options[:exception]
|
||||
end
|
||||
|
||||
field :errors, if: ->(_field_name, object, options) { options.key?(:errors) } do |_, options|
|
||||
options[:errors]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,42 @@
|
|||
class GridCharacter < ApplicationRecord
|
||||
belongs_to :party
|
||||
|
||||
validate :awakening_level, on: :update
|
||||
validate :transcendence, on: :update
|
||||
validate :over_mastery_attack, on: :update
|
||||
validate :over_mastery_hp, on: :update
|
||||
validate :over_mastery_attack_matches_hp, on: :update
|
||||
|
||||
def awakening_level
|
||||
unless awakening.nil?
|
||||
errors.add(:awakening, 'awakening level too low') if awakening["level"] < 1
|
||||
errors.add(:awakening, 'awakening level too high') if awakening["level"] > 9
|
||||
end
|
||||
end
|
||||
|
||||
def transcendence
|
||||
errors.add(:transcendence_step, 'character has no transcendence') if transcendence_step > 0 && !character.ulb
|
||||
errors.add(:transcendence_step, 'transcendence step too high') if transcendence_step > 5 && character.ulb
|
||||
errors.add(:transcendence_step, 'transcendence step too low') if transcendence_step < 0 && character.ulb
|
||||
|
||||
end
|
||||
|
||||
def over_mastery_attack
|
||||
errors.add(:ring1, 'invalid value') unless ring1["modifier"].nil? || atk_values.include?(ring1["strength"])
|
||||
end
|
||||
|
||||
def over_mastery_hp
|
||||
unless ring2["modifier"].nil?
|
||||
errors.add(:ring2, 'invalid value') unless hp_values.include?(ring2["strength"])
|
||||
end
|
||||
end
|
||||
|
||||
def over_mastery_attack_matches_hp
|
||||
unless ring1[:modifier].nil? && ring2[:modifier].nil?
|
||||
errors.add(:over_mastery, 'over mastery attack and hp values do not match') unless ring2[:strength] == (ring1[:strength] / 2)
|
||||
end
|
||||
end
|
||||
|
||||
def character
|
||||
Character.find(character_id)
|
||||
end
|
||||
|
|
@ -10,4 +46,14 @@ class GridCharacter < ApplicationRecord
|
|||
def blueprint
|
||||
GridCharacterBlueprint
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def atk_values
|
||||
[300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000]
|
||||
end
|
||||
|
||||
def hp_values
|
||||
[150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue