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 | |
parent | 4e89b79597f87057b866b715173c0a6da77c8cfa (diff) |
Chance for equipment to break after combat
Diffstat (limited to 'app')
-rw-r--r-- | app/lib/activity_processor.rb | 3 | ||||
-rw-r--r-- | app/models/character.rb | 10 | ||||
-rw-r--r-- | app/models/equipment.rb | 12 | ||||
-rw-r--r-- | app/views/application/_results.html.erb | 2 |
4 files changed, 27 insertions, 0 deletions
diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb index 004f8de..d8004f6 100644 --- a/app/lib/activity_processor.rb +++ b/app/lib/activity_processor.rb @@ -251,6 +251,9 @@ class ActivityProcessor end end end + @character.do_equipment_break_checks.each do |broken_item| + @results.push({ type: "warning", message: "Your #{broken_item.name} was damaged beyond repair!" }) + end break end end 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 diff --git a/app/views/application/_results.html.erb b/app/views/application/_results.html.erb index 1da0af7..31fb93e 100644 --- a/app/views/application/_results.html.erb +++ b/app/views/application/_results.html.erb @@ -23,6 +23,8 @@ <p>You earned the title <%= render "application/components/text/title", title: result[:title] %>!</p> <% when "message" %> <p><%= result[:body] %></p> + <% when "warning" %> + <p class="text-yellow-500"><%= result[:message] %></p> <% when "error" %> <p class="text-red-500"><%= result[:message] %></p> <% when "br" %> |