summaryrefslogtreecommitdiff
path: root/app/controllers/characters/hearth_controller.rb
blob: ab9676eb47b49249d2179d593e750a30f32f6217 (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
class Characters::HearthController < ApplicationController
  def index
    @all_amenities = HearthAmenity.all.order(:id)
    @construct_activities = Activity.where("gid like ?", "construct_%")

    @amenity_activities = {
      forge: [],
      laboratory: [],
      spicebench: [],
      binding_array: [],
      aetherloom: [],
    }

    Activity.where("gid like ?", "craft_%").each do |activity|
      next unless current_char.can_do_activity?(activity, ignore_cost: true, ignore_requirements: true)
      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 "laboratory"
            @amenity_activities[:laboratory].push(activity) && next
          when "spicebench"
            @amenity_activities[:spicebench].push(activity) && next
          when "binding_array"
            @amenity_activities[:binding_array].push(activity) && next
          when "aetherloom"
            @amenity_activities[:aetherloom].push(activity) && next
          else
            raise "Invalid amenity gid (#{requirement_data[:gid]}"
          end
        end
      end
    end
  end
end