diff options
author | David Gay <david@davidgay.org> | 2021-06-15 21:11:10 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-06-15 21:11:38 -0400 |
commit | f637f622af2d9b891271344ef23402c41419b3fe (patch) | |
tree | db30ef8a6153e0df367630711d72ed837464e938 /app/models | |
parent | 90812578cc643011db9ad6b688ece1ca9eda900e (diff) |
Add breakage to all equipment items that give a skill speed increase, and to omens
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 24 | ||||
-rw-r--r-- | app/models/item_infix.rb | 4 |
2 files changed, 28 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index 5ff067c..0f2c5b3 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -116,6 +116,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 = [] + # 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 + end + broken_items + end + + def do_skill_based_item_infix_break_checks(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| diff --git a/app/models/item_infix.rb b/app/models/item_infix.rb index 3167320..47b6aa4 100644 --- a/app/models/item_infix.rb +++ b/app/models/item_infix.rb @@ -9,6 +9,10 @@ class ItemInfix < ApplicationRecord self.item.whatnot[:infix_effects] end + def break_check + rand > 0.999 ? destroy : false + end + private def check_max_infixes current_infixes = character.item_infixes.where(skill: skill) |