summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-06-02 22:15:02 -0400
committerDavid Gay <david@davidgay.org>2021-06-02 22:15:02 -0400
commit4c96893a114059dc4e748307c6d046ec1faa778f (patch)
tree10e3af95e7a3749e6bd0d1ab63fffebf5b567258 /app/controllers
parent6ec57509c6f1d44fb80a1cb2ae020b8a033dd370 (diff)
Magiculture
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/characters/hearth/hearth_plantings_controller.rb39
-rw-r--r--app/controllers/game_controller.rb12
2 files changed, 51 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
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb
index 2de342a..04d743c 100644
--- a/app/controllers/game_controller.rb
+++ b/app/controllers/game_controller.rb
@@ -129,6 +129,15 @@ class GameController < ApplicationController
.find_or_initialize_by(hearth_amenity: HearthAmenity.find_by_gid(result[:gid]))
bhi.update(level: result[:level])
@results.push({ type: type, hearth_amenity: bhi.hearth_amenity })
+ when "hearth_planting"
+ unless current_char.hearth.available_planting_spots > 0
+ @results.replace([{ type: "error", message: "You're out of space to plant seeds." }])
+ current_char.stop_activity
+ return
+ end
+ item = Item.find_by_gid(result[:gid])
+ hp = current_char.hearth.hearth_plantings.create(item: item)
+ @results.push({ type: type, hearth_planting: hp })
when "activity"
next if rand > (result[:chance] || 1)
table_roll = rand
@@ -174,6 +183,9 @@ class GameController < ApplicationController
rescue ItemQuantityError
current_char.stop_activity
@results.replace([{ type: "error", message: "You don't have enough items to complete this activity." }])
+ rescue HearthPlantingError
+ current_char.stop_activity
+ @results.replace([{ type: "error", message: "You don't have that crop planted." }])
rescue TooManyWoundsError
current_char.stop_activity
@results.replace([{ type: "error",