diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/game_controller.rb | 29 |
2 files changed, 33 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0fc78a8..f28d30b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,6 +17,10 @@ class ApplicationController < ActionController::Base private def start_activity(activity) + if current_char.resting? + flash[:alert] = "You can't do anything while you're resting. Go to the Character page to stop resting." + redirect_to character_path(current_char) and return + end if current_char.start_activity(activity, queued_actions: params[:queued_actions]) redirect_to look_path else 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| |