diff options
author | David Gay <david@davidgay.org> | 2021-05-25 20:31:22 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-25 20:31:22 -0400 |
commit | ca9d189e51b7467f539d906a6e891fa4a7caa2fc (patch) | |
tree | 2904645ffce5290ef2aa8303a14f4683e30197b3 /app/controllers | |
parent | 0dd10a2297cc9b3d2a0fe991c1d597b8a1d5fcc2 (diff) |
Queued actions, allowing for non-infinite activity repeat and one-time activities
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/activities_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/game_controller.rb | 12 |
2 files changed, 12 insertions, 3 deletions
diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index 934f617..43ee1b0 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -5,8 +5,7 @@ class ActivitiesController < ApplicationController def start @activity = Activity.find(params[:id]) - if current_char.can_do_activity?(@activity) - current_char.start_activity(@activity) + if current_char.start_activity(@activity, queued_actions: params[:queued_actions]) redirect_to activity_path(@activity) else flash[:alert] = "You can't do that. Make sure you have the items and meet the requirements." diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 39bb940..f1387e0 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -5,7 +5,6 @@ class GameController < ApplicationController activity = current_char.activity return unless current_char.can_do_activity?(activity) # TODO: Add error message - current_char.update(activity_started_at: Time.now) Character.transaction do current_char.pay_cost_for(activity) @@ -88,6 +87,17 @@ class GameController < ApplicationController raise "Invalid result type (#{type})" # TODO: Improve this. end end + + if current_char.queued_actions + if current_char.queued_actions > 0 + current_char.queued_actions -= 1 + current_char.activity_started_at = Time.now + current_char.save + else + current_char.stop_activity + @results.push({ type: "message", body: "You have finished your work." }) + end + end end rescue ItemQuantityError @results.replace([{ type: "error", message: "You don't have enough items to complete this activity." }]) |