Merge pull request #60 from jedmund/fix-yatima

Fix limit when adding summons
This commit is contained in:
Justin Edmund 2023-01-28 02:38:19 -08:00 committed by GitHub
commit 651a7ff5f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 16 deletions

View file

@ -16,10 +16,8 @@ module Api
summon.attributes = summon_params.merge(party_id: party.id, summon_id: incoming_summon.id)
if summon.validate
ap 'Validating'
save_summon(summon)
else
ap 'Handling conflict'
handle_conflict(summon)
end
end
@ -48,6 +46,7 @@ module Api
def handle_conflict(summon)
conflict_summon = summon.conflicts(party)
ap conflict_summon
return unless conflict_summon.summon.id == incoming_summon.id
old_position = conflict_summon.position
@ -91,8 +90,8 @@ module Api
def render_grid_summon_view(grid_summon, conflict_position = nil)
GridSummonBlueprint.render(grid_summon, view: :nested,
root: :grid_summon,
meta: { replaced: conflict_position })
root: :grid_summon,
meta: { replaced: conflict_position })
end
def set

View file

@ -21,13 +21,9 @@ class GridSummon < ApplicationRecord
def conflicts(party)
return unless summon.limit
party.summons.find do |party_summon|
ap 'Normal summon:'
ap summon
ap 'Party summon:'
ap party_summon
summon if summon.id == party_summon.summon.id
party.summons.find do |grid_summon|
return unless grid_summon.id
grid_summon if summon.id == grid_summon.summon.id
end
end
@ -35,15 +31,12 @@ class GridSummon < ApplicationRecord
# Validates whether there is a conflict with the party
def no_conflicts
ap conflicts(party)
# Check if the grid weapon conflicts with any of the other grid weapons in the party
# Check if the grid summon conflicts with any of the other grid summons in the party
errors.add(:series, 'must not conflict with existing summons') unless conflicts(party).nil?
end
# Validates whether the weapon can be added to the desired position
# Validates whether the summon can be added to the desired position
def compatible_with_position
ap [4, 5].include?(position.to_i) && !summon.subaura
return unless [4, 5].include?(position.to_i) && !summon.subaura
errors.add(:position, 'must have subaura for position')