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/lib/activity_processor.rb | 3 +++ app/models/character.rb | 10 ++++++++++ app/models/equipment.rb | 12 ++++++++++++ app/views/application/_results.html.erb | 2 ++ 4 files changed, 27 insertions(+) (limited to 'app') 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 @@

You earned the title <%= render "application/components/text/title", title: result[:title] %>!

<% when "message" %>

<%= result[:body] %>

+ <% when "warning" %> +

<%= result[:message] %>

<% when "error" %>

<%= result[:message] %>

<% when "br" %> -- cgit v1.2.3