From dcbb8efcde93af6452af77fea6b1038784db477e Mon Sep 17 00:00:00 2001 From: David Gay Date: Mon, 31 May 2021 16:51:47 -0400 Subject: Character resting --- app/controllers/game_controller.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'app/controllers/game_controller.rb') 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| -- cgit v1.2.3