diff options
author | David Gay <david@davidgay.org> | 2021-05-25 22:02:33 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-25 22:02:33 -0400 |
commit | c4ba54f606c0c4cc5eaa78e108f6529187de3d78 (patch) | |
tree | 775adc8b06a7f04fd5cc2df58e83c985cb6dcbb2 | |
parent | 4d68d3dc80138e6cc6a3cbec001dbd77e85649cc (diff) |
Improve hearth crafting selection
-rw-r--r-- | app/controllers/characters/hearth_controller.rb | 21 | ||||
-rw-r--r-- | app/models/hearth.rb | 6 | ||||
-rw-r--r-- | app/views/characters/hearth/index.html.erb | 4 | ||||
-rw-r--r-- | data/activities.yml | 12 |
4 files changed, 40 insertions, 3 deletions
diff --git a/app/controllers/characters/hearth_controller.rb b/app/controllers/characters/hearth_controller.rb index abe8232..02b8446 100644 --- a/app/controllers/characters/hearth_controller.rb +++ b/app/controllers/characters/hearth_controller.rb @@ -2,6 +2,25 @@ class Characters::HearthController < ApplicationController def index @all_amenities = HearthAmenity.all @construct_activities = Activity.where("gid like ?", "construct_%") - @forge_activities = Activity.where("gid like ?", "craft_%") + + @amenity_activities = { + forge: [], + labratory: [], + } + + Activity.where("gid like ?", "craft_%").each do |activity| + activity.whatnot[:requirements]&.each do |requirement_data| + if requirement_data[:type] == "hearth_amenity" + case requirement_data[:gid] + when "forge" + @amenity_activities[:forge].push(activity) && next + when "labratory" + @amenity_activities[:labratory].push(activity) && next + else + raise "Invalid amenity gid (#{requirement_data[:gid]}" + end + end + end + end end end diff --git a/app/models/hearth.rb b/app/models/hearth.rb index 5d244ec..1bd54a5 100644 --- a/app/models/hearth.rb +++ b/app/models/hearth.rb @@ -9,4 +9,10 @@ class Hearth < ApplicationRecord return false unless bhi bhi.level >= level end + + def amenity_level(hearth_amenity) + hearth_amenity = HearthAmenity.find_by_gid(hearth_amenity) if hearth_amenity.is_a? String + bhi = self.built_hearth_amenities.find_by(hearth_amenity: hearth_amenity) + bhi ? bhi.level : 0 + end end diff --git a/app/views/characters/hearth/index.html.erb b/app/views/characters/hearth/index.html.erb index c95977e..7baf2bf 100644 --- a/app/views/characters/hearth/index.html.erb +++ b/app/views/characters/hearth/index.html.erb @@ -14,9 +14,9 @@ <% if built_amenity %> <p class="mb-2">Level <%= built_amenity.level %></p> <p class="mb-2"><%= ha.description %></p> - <% if ha.gid == "forge" %> + <% if @amenity_activities[ha.gid.to_sym] %> <%= form_with url: start_activity_path, method: :post do |f| %> - <%= f.select :id, @forge_activities.map { |a| [a.name, a.id] } %> + <%= f.select :id, @amenity_activities[ha.gid.to_sym].map { |a| [a.name, a.id] } %> <%= f.submit "Go" %> <% end %> <% end %> diff --git a/data/activities.yml b/data/activities.yml index f455017..8f64132 100644 --- a/data/activities.yml +++ b/data/activities.yml @@ -87,6 +87,10 @@ craft_pig_iron_ingot: description: "Smelt a pig iron ingot." innate: true whatnot: + requirements: + - type: "hearth_amenity" + gid: "forge" + level: 1 duration: base: 70 minimum: 35 @@ -113,6 +117,10 @@ craft_iron_ingot: name: "Smelt Iron Ingot" description: "Smelt an iron ingot." whatnot: + requirements: + - type: "hearth_amenity" + gid: "forge" + level: 1 duration: base: 80 minimum: 35 @@ -134,6 +142,10 @@ craft_mending_salve: name: "Mix mending salve" description: "Mix a mending salve." whatnot: + requirements: + - type: "hearth_amenity" + gid: "labratory" + level: 1 duration: base: 90 minimum: 35 |