summaryrefslogtreecommitdiff
path: root/app/controllers/game_controller.rb
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-31 16:51:47 -0400
committerDavid Gay <david@davidgay.org>2021-05-31 16:51:47 -0400
commitdcbb8efcde93af6452af77fea6b1038784db477e (patch)
tree476f1ccde46a663f27a3183e5fa9b202fce89f39 /app/controllers/game_controller.rb
parent99e2507bea007e4aac17cf562139f53f7f9da9bf (diff)
Character resting
Diffstat (limited to 'app/controllers/game_controller.rb')
-rw-r--r--app/controllers/game_controller.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb
index 9de6e8f..f6bb7b8 100644
--- a/app/controllers/game_controller.rb
+++ b/app/controllers/game_controller.rb
@@ -1,4 +1,21 @@
class GameController < ApplicationController
+ def toggle_resting
+ if current_char.resting?
+ if current_char.stop_resting
+ flash[:notice] = "You stop resting. You now have #{current_char.rested_duration} seconds of rest."
+ else
+ flash[:alert] = "Failed to stop resting. Are you sure you're resting?"
+ end
+ else
+ if current_char.start_resting
+ flash[:notice] = "You are now resting."
+ else
+ flash[:alert] = "Failed to start resting. Are you already resting?"
+ end
+ end
+ redirect_to character_path(current_char)
+ end
+
def stop_activity
current_char.stop_activity
redirect_to locations_path
@@ -9,6 +26,13 @@ class GameController < ApplicationController
return unless current_char.activity_time_remaining <= 0
activity = current_char.activity
+ if current_char.resting?
+ @results.replace([{ type: "error", message: "You can't do anything while you're resting. Go to the Character" \
+ " page to stop resting." }])
+ current_char.stop_activity
+ return
+ end
+
unless current_char.can_do_activity?(activity)
message = "You can't do this right now."
message += " (requires #{activity.requirements&.join(", ")})" if activity.requirements.any?
@@ -19,6 +43,11 @@ class GameController < ApplicationController
end
Character.transaction do
+ if current_char.rested_duration > 0
+ remaining_rested_duration = current_char.rested_duration - current_char.rested_duration_to_spend_on_activity
+ current_char.update!(rested_duration: remaining_rested_duration)
+ end
+
current_char.pay_cost_for(activity)
activity.whatnot[:results].each do |result|