From d58346df32cd8f6934b7cf068637eb8896456977 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sat, 5 Jun 2021 18:08:06 -0400 Subject: Chance for equipment to break after combat --- app/models/character.rb | 10 ++++++++++ app/models/equipment.rb | 12 ++++++++++++ 2 files changed, 22 insertions(+) (limited to 'app/models') 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 -- cgit v1.2.3