summaryrefslogtreecommitdiff
path: root/app/controllers/characters/hearth
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/characters/hearth')
-rw-r--r--app/controllers/characters/hearth/hearth_plantings_controller.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/controllers/characters/hearth/hearth_plantings_controller.rb b/app/controllers/characters/hearth/hearth_plantings_controller.rb
new file mode 100644
index 0000000..198943f
--- /dev/null
+++ b/app/controllers/characters/hearth/hearth_plantings_controller.rb
@@ -0,0 +1,39 @@
+class Characters::Hearth::HearthPlantingsController < ApplicationController
+ before_action :redirect_unless_character_has_loamspire, :set_hearth
+
+ def index
+ @hearth_plantings = @hearth.hearth_plantings
+ @planting_activities = Activity.where("gid like ?", "plant_%")
+ end
+
+ def create
+ item = Item.find(params[:item_id])
+ unless item.tags&.include?("seed")
+ flash[:alert] = "You can only plant seeds here."
+ redirect_to character_hearth_loamspire_path and return
+ end
+
+ quantity = [params[:quantity], @hearth.available_planting_spots].min
+ if quantity < 1
+ flash[:alert] = "You don't have any available planting slots."
+ redirect_to character_hearth_loamspire_path and return
+ end
+
+ @hearth_planting = @hearth.hearth_plantings.new(item: item, quantity: quantity)
+ if @hearth_planting.save
+ flash[:notice] = "Planted #{quantity} #{item.name}."
+ else
+ flash[:alert] = "Failed to plant seeds."
+ end
+ redirect_to character_hearth_loamspire_path
+ end
+
+ private
+ def redirect_unless_character_has_loamspire
+ redirect_to character_hearth_path(current_char) unless current_char.hearth.has_amenity?("loamspire", 1)
+ end
+
+ def set_hearth
+ @hearth = current_char.hearth
+ end
+end