diff options
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | app/lib/activity_processor.rb | 11 | ||||
-rw-r--r-- | app/models/character.rb | 44 | ||||
-rw-r--r-- | app/models/equipment.rb | 19 | ||||
-rw-r--r-- | app/models/item_infix.rb | 8 |
5 files changed, 47 insertions, 42 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d43ea..85684df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### General +- Equipment and infix breakage changes + - All threatened equipment and infixes are no longer checked individually for breakage. Instead, a single breakage + roll occurs, and may cause equipment and/or infix breakage depending on its result. This means, at most, only + one piece of equipment and one infix can break per timer. It also means that in many cases, fewer breakage rolls + are happening per timer. + ### Items - Apprentice wand can now be equipped in mainhand or offhand. diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb index d995e06..cca2185 100644 --- a/app/lib/activity_processor.rb +++ b/app/lib/activity_processor.rb @@ -125,11 +125,13 @@ class ActivityProcessor required_skill_gids = @activity.whatnot[:requirements].select { |r| r[:type] == "skill" }.map { |r| r[:gid] }.uniq required_skill_gids.each do |required_skill_gid| skill = Skill.find_by_gid(required_skill_gid) - @character.do_skill_based_equipment_break_checks(skill).each do |broken_item| + broken_item = @character.do_equipment_break_check(skill: skill) + if broken_item @results.push({ type: "warning", message: "Your #{broken_item.name} was damaged beyond repair!" }) end - @character.do_skill_based_item_infix_break_checks(skill).each do |broken_item| - @results.push({ type: "warning", message: "Your #{broken_item.name} omen faded away." }) + broken_infix_item = @character.do_item_infix_break_check(skill: skill) + if broken_infix_item + @results.push({ type: "warning", message: "Your #{broken_infix_item.name} omen faded away." }) end end end @@ -317,7 +319,8 @@ class ActivityProcessor end if char_hp < 1 || mon_hp < 1 - @character.do_equipment_break_checks.each do |broken_item| + broken_item = @character.do_equipment_break_check + if broken_item @results.push({ type: "warning", message: "Your #{broken_item.name} was damaged beyond repair!" }) end diff --git a/app/models/character.rb b/app/models/character.rb index a7d5829..2669626 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -117,38 +117,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 = [] + def do_equipment_break_check(skill: nil) + skill = Skill.find_by_gid(skill) if skill&.is_a? String # 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 + if skill + threatened_equipment = equipment.all.select { |eq| eq.effects&.select { |ef| ef[:gid] == "#{skill.gid}_speed" }&.any? } + else + threatened_equipment = equipment.all end - broken_items + break_slot = Equipment.random_break_slot + return nil unless break_slot + broken_equipment = threatened_equipment.find { |eq| eq.slot == break_slot } + return nil unless broken_equipment + broken_equipment.destroy + broken_equipment.item end - def do_skill_based_item_infix_break_checks(skill) + def do_item_infix_break_check(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| - if equipment.break_check - broken_items.push(equipment.item) - end - end - broken_items + return nil unless ItemInfix.break_check + broken_ii = item_infixes.where(skill: skill).sample + return nil unless broken_ii + broken_ii.destroy + broken_ii.item end def has_item?(item, quantity = 1) diff --git a/app/models/equipment.rb b/app/models/equipment.rb index e1dc7a3..f5dd530 100644 --- a/app/models/equipment.rb +++ b/app/models/equipment.rb @@ -5,6 +5,17 @@ class Equipment < ApplicationRecord :left_ring, :right_ring, :waist, :legs, :feet, :curio] validates :slot, presence: true, uniqueness: { scope: :character } + def self.random_break_slot + roll = rand + if roll >= 0.9998 + [:neck, :left_ring, :right_ring].sample + elsif roll >= 0.9996 + [:back, :waist, :curio].sample + elsif roll >= 0.999 + [:mainhand, :offhand, :head, :torso, :grip, :legs, :feet].sample + end + end + def slot self[:slot].to_sym end @@ -14,14 +25,6 @@ class Equipment < ApplicationRecord 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/models/item_infix.rb b/app/models/item_infix.rb index b59ccdb..40b2339 100644 --- a/app/models/item_infix.rb +++ b/app/models/item_infix.rb @@ -5,12 +5,12 @@ class ItemInfix < ApplicationRecord before_create :check_max_infixes - def effects - self.item.whatnot[:infix_effects] + def self.break_check + rand > 0.998 end - def break_check - rand > 0.998 ? destroy : false + def effects + self.item.whatnot[:infix_effects] end private |