diff options
author | David Gay <david@davidgay.org> | 2021-05-28 11:26:44 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-28 11:26:54 -0400 |
commit | 5ae89950fb330fd623634b98a77de259ab174b53 (patch) | |
tree | 3ec11fae10758379761f5b824586b1c22bc57c12 /app/models/concerns | |
parent | c522bc8efa0378e0fcbcfdd137d6cd2ae4010d5b (diff) |
Lockbox unlocking, and with it items that start activities when used
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/has_costs_and_requirements.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/models/concerns/has_costs_and_requirements.rb b/app/models/concerns/has_costs_and_requirements.rb new file mode 100644 index 0000000..34ff0f3 --- /dev/null +++ b/app/models/concerns/has_costs_and_requirements.rb @@ -0,0 +1,33 @@ +module HasCostsAndRequirements + extend ActiveSupport::Concern + + included do + def costs + costs = [] + self.whatnot[:cost]&.each do |cost| + case cost[:type] + when "item" + costs.push "#{cost[:quantity]} #{Item.find_by_gid(cost[:gid]).name}" + end + end + costs + end + + def requirements + requirements = [] + self.whatnot[:requirements]&.each do |req| + case req[:type] + when "skill" + requirements.push "level #{req[:level]} #{Skill.find_by_gid(req[:gid]).name}" + when "equipment" + requirements.push "equipped #{Item.find_by_gid(req[:gid]).name}" + when "hearth_amenity" + requirements.push "level #{req[:level]} #{HearthAmenity.find_by_gid(req[:gid]).name}" + else + raise "Invalid requirement type string (#{req[:type]})" + end + end + requirements + end + end +end |