summaryrefslogtreecommitdiff
path: root/app/models/concerns/has_costs_and_requirements.rb
blob: 61ce4616e7f26e1f53b5d0f333007cd2663b3bd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 "stat"
          requirements.push "#{req[:value]} #{req[:gid]}"
        when "equipment"
          if req[:tag]
            requirements.push "equipped #{req[:tag]}"
          else
            requirements.push "equipped #{Item.find_by_gid(req[:gid]).name}"
          end
        when "hearth_amenity"
          requirements.push "level #{req[:level]} #{HearthAmenity.find_by_gid(req[:gid]).name}"
        when "time_of_day"
          requirements.push "a certain time of day (#{req[:times].join(", ")})"
        else
          raise "Invalid requirement type string (#{req[:type]})"
        end
      end
      requirements
    end
  end
end