diff options
Diffstat (limited to 'app/models/character.rb')
-rw-r--r-- | app/models/character.rb | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index a7d5829..2669626 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -117,38 +117,30 @@ class Character < ApplicationRecord end end - def do_skill_based_equipment_break_checks(skill) - skill = Skill.find_by_gid(skill) if skill.is_a? String - broken_items = [] + def do_equipment_break_check(skill: nil) + skill = Skill.find_by_gid(skill) if skill&.is_a? String # TODO: HACK: Should check other stats besides speed stat in the future. # TODO: HACK: May not want a chance to break if speed is _reduced_. Though no equipment does this yet. - equipment.all.select { |eq| eq.effects&.select { |ef| ef[:gid] == "#{skill.gid}_speed" }&.any? }.each do |equipment| - if equipment.break_check - broken_items.push(equipment.item) - end + if skill + threatened_equipment = equipment.all.select { |eq| eq.effects&.select { |ef| ef[:gid] == "#{skill.gid}_speed" }&.any? } + else + threatened_equipment = equipment.all end - broken_items + break_slot = Equipment.random_break_slot + return nil unless break_slot + broken_equipment = threatened_equipment.find { |eq| eq.slot == break_slot } + return nil unless broken_equipment + broken_equipment.destroy + broken_equipment.item end - def do_skill_based_item_infix_break_checks(skill) + def do_item_infix_break_check(skill:) skill = Skill.find_by_gid(skill) if skill.is_a? String - broken_items = [] - item_infixes.where(skill: skill).each do |ii| - if ii.break_check - broken_items.push(ii.item) - end - end - broken_items - end - - def do_equipment_break_checks(exclude_slots: []) - broken_items = [] - equipment.where.not(slot: exclude_slots).each do |equipment| - if equipment.break_check - broken_items.push(equipment.item) - end - end - broken_items + return nil unless ItemInfix.break_check + broken_ii = item_infixes.where(skill: skill).sample + return nil unless broken_ii + broken_ii.destroy + broken_ii.item end def has_item?(item, quantity = 1) |