blob: 34ff0f352cb3f4c7045f52267ac4599272101ce8 (
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
|
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
|