summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/activities_controller.rb3
-rw-r--r--app/controllers/game_controller.rb12
-rw-r--r--app/models/character.rb12
-rw-r--r--app/views/characters/hearth/index.html.erb2
-rw-r--r--db/migrate/20210526000349_add_queued_actions_to_characters.rb5
-rw-r--r--db/schema.rb3
6 files changed, 31 insertions, 6 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." }])
diff --git a/app/models/character.rb b/app/models/character.rb
index 040c89b..970ede1 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -138,8 +138,16 @@ class Character < ApplicationRecord
true
end
- def start_activity(activity)
- self.update(activity: activity, activity_started_at: Time.now) if self.can_do_activity?(activity)
+ def start_activity(activity, queued_actions: nil)
+ if self.can_do_activity?(activity)
+ self.update(activity: activity, activity_started_at: Time.now, queued_actions: queued_actions)
+ else
+ false
+ end
+ end
+
+ def stop_activity
+ self.update(activity: nil, activity_started_at: nil, queued_actions: nil)
end
def equipment_stats
diff --git a/app/views/characters/hearth/index.html.erb b/app/views/characters/hearth/index.html.erb
index e425fee..c95977e 100644
--- a/app/views/characters/hearth/index.html.erb
+++ b/app/views/characters/hearth/index.html.erb
@@ -27,6 +27,7 @@
<div class="my-3">
<%= form_with url: start_activity_path do |f| %>
<%= f.hidden_field :id, value: construct_activity.id %>
+ <%= f.hidden_field :queued_actions, value: 0 %>
<%= f.submit construct_activity.name %>
<% end %>
<div class="text-sm">(costs <%= construct_activity.cost_string %>)</div>
@@ -40,6 +41,7 @@
<% construct_activity = foundation.construct_activity(1) %>
<%= form_with url: start_activity_path do |f| %>
<%= f.hidden_field :id, value: construct_activity.id %>
+ <%= f.hidden_field :queued_actions, value: 0 %>
<%= f.submit construct_activity.name %>
<% end %>
(costs <%= construct_activity.cost_string %>)
diff --git a/db/migrate/20210526000349_add_queued_actions_to_characters.rb b/db/migrate/20210526000349_add_queued_actions_to_characters.rb
new file mode 100644
index 0000000..cb6fdf7
--- /dev/null
+++ b/db/migrate/20210526000349_add_queued_actions_to_characters.rb
@@ -0,0 +1,5 @@
+class AddQueuedActionsToCharacters < ActiveRecord::Migration[6.1]
+ def change
+ add_column :characters, :queued_actions, :integer
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 87f3473..bd2b95b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2021_05_23_232805) do
+ActiveRecord::Schema.define(version: 2021_05_26_000349) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -80,6 +80,7 @@ ActiveRecord::Schema.define(version: 2021_05_23_232805) do
t.datetime "updated_at", precision: 6, null: false
t.bigint "active_title_id"
t.integer "wounds"
+ t.integer "queued_actions"
t.index ["active_title_id"], name: "index_characters_on_active_title_id"
t.index ["activity_id"], name: "index_characters_on_activity_id"
t.index ["user_id"], name: "index_characters_on_user_id"