Merge pull request #60 from jedmund/fix-yatima
Fix limit when adding summons
This commit is contained in:
commit
651a7ff5f6
2 changed files with 8 additions and 16 deletions
|
|
@ -16,10 +16,8 @@ module Api
|
||||||
summon.attributes = summon_params.merge(party_id: party.id, summon_id: incoming_summon.id)
|
summon.attributes = summon_params.merge(party_id: party.id, summon_id: incoming_summon.id)
|
||||||
|
|
||||||
if summon.validate
|
if summon.validate
|
||||||
ap 'Validating'
|
|
||||||
save_summon(summon)
|
save_summon(summon)
|
||||||
else
|
else
|
||||||
ap 'Handling conflict'
|
|
||||||
handle_conflict(summon)
|
handle_conflict(summon)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -48,6 +46,7 @@ module Api
|
||||||
|
|
||||||
def handle_conflict(summon)
|
def handle_conflict(summon)
|
||||||
conflict_summon = summon.conflicts(party)
|
conflict_summon = summon.conflicts(party)
|
||||||
|
ap conflict_summon
|
||||||
return unless conflict_summon.summon.id == incoming_summon.id
|
return unless conflict_summon.summon.id == incoming_summon.id
|
||||||
|
|
||||||
old_position = conflict_summon.position
|
old_position = conflict_summon.position
|
||||||
|
|
@ -91,8 +90,8 @@ module Api
|
||||||
|
|
||||||
def render_grid_summon_view(grid_summon, conflict_position = nil)
|
def render_grid_summon_view(grid_summon, conflict_position = nil)
|
||||||
GridSummonBlueprint.render(grid_summon, view: :nested,
|
GridSummonBlueprint.render(grid_summon, view: :nested,
|
||||||
root: :grid_summon,
|
root: :grid_summon,
|
||||||
meta: { replaced: conflict_position })
|
meta: { replaced: conflict_position })
|
||||||
end
|
end
|
||||||
|
|
||||||
def set
|
def set
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,9 @@ class GridSummon < ApplicationRecord
|
||||||
def conflicts(party)
|
def conflicts(party)
|
||||||
return unless summon.limit
|
return unless summon.limit
|
||||||
|
|
||||||
party.summons.find do |party_summon|
|
party.summons.find do |grid_summon|
|
||||||
ap 'Normal summon:'
|
return unless grid_summon.id
|
||||||
ap summon
|
grid_summon if summon.id == grid_summon.summon.id
|
||||||
ap 'Party summon:'
|
|
||||||
ap party_summon
|
|
||||||
|
|
||||||
summon if summon.id == party_summon.summon.id
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -35,15 +31,12 @@ class GridSummon < ApplicationRecord
|
||||||
|
|
||||||
# Validates whether there is a conflict with the party
|
# Validates whether there is a conflict with the party
|
||||||
def no_conflicts
|
def no_conflicts
|
||||||
ap conflicts(party)
|
# Check if the grid summon conflicts with any of the other grid summons in the party
|
||||||
|
|
||||||
# Check if the grid weapon conflicts with any of the other grid weapons in the party
|
|
||||||
errors.add(:series, 'must not conflict with existing summons') unless conflicts(party).nil?
|
errors.add(:series, 'must not conflict with existing summons') unless conflicts(party).nil?
|
||||||
end
|
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
|
def compatible_with_position
|
||||||
ap [4, 5].include?(position.to_i) && !summon.subaura
|
|
||||||
return unless [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')
|
errors.add(:position, 'must have subaura for position')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue