diff options
author | David Gay <david@davidgay.org> | 2021-06-05 18:08:06 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-06-05 18:08:37 -0400 |
commit | d58346df32cd8f6934b7cf068637eb8896456977 (patch) | |
tree | 16dc0b472917fa1d69a86990a77f3835a1d159f1 /app/models | |
parent | 4e89b79597f87057b866b715173c0a6da77c8cfa (diff) |
Chance for equipment to break after combat
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 10 | ||||
-rw-r--r-- | app/models/equipment.rb | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index 91f0a66..f4c9bc2 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -115,6 +115,16 @@ class Character < ApplicationRecord end 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 + end + def has_item?(item, quantity = 1) item = Item.find_by_gid(item) if item.is_a? String ci = self.character_items.find_by(item: item) diff --git a/app/models/equipment.rb b/app/models/equipment.rb index ce3822c..e1dc7a3 100644 --- a/app/models/equipment.rb +++ b/app/models/equipment.rb @@ -12,4 +12,16 @@ class Equipment < ApplicationRecord def effects self.item.whatnot[:equip_effects] end + + def break_check + roll = rand + if [:neck, :left_ring, :right_ring].include?(slot) + destroy and return true if roll > 0.9998 + elsif [:back, :waist, :curio].include?(slot) + destroy and return true if roll > 0.9996 + else + destroy and return true if roll > 0.999 + end + false + end end |