diff options
author | David Gay <david@davidgay.org> | 2021-05-04 17:55:28 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-04 17:57:12 -0400 |
commit | 73744a9c6840fb0ba6f285ca81f9fba75ec22d5f (patch) | |
tree | 837333e9e46c5ccc6cf50214a94c2b9b6d0bb7f3 /app/controllers | |
parent | dddbf75428477f5e073584939d098e55d6324be3 (diff) |
Initial draft of timer setup, with results outputting and items being awarded
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/activities_controller.rb | 11 | ||||
-rw-r--r-- | app/controllers/game_controller.rb | 25 |
2 files changed, 36 insertions, 0 deletions
diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb new file mode 100644 index 0000000..a535f99 --- /dev/null +++ b/app/controllers/activities_controller.rb @@ -0,0 +1,11 @@ +class ActivitiesController < ApplicationController + def show + @activity = Activity.find(params[:id]) + end + + def start + @activity = Activity.find(params[:id]) + current_char.update(activity: @activity, activity_started_at: Time.now) + redirect_to action: :show + end +end diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb new file mode 100644 index 0000000..3516056 --- /dev/null +++ b/app/controllers/game_controller.rb @@ -0,0 +1,25 @@ +class GameController < ApplicationController + def finish_activity + @results = [] + return unless current_char.activity_time_remaining <= 0 + current_char.update(activity_started_at: Time.now) + current_char.activity.whatnot["results"].each do |result| + type = result["type"] + case type + when "item" + next if rand > result["chance"] + table_roll = rand + result["table"].sort_by { |_, v| -v["score"] }.each do |item_gid, item_data| + quantity = item_data["quantity"] || 1 + if table_roll >= item_data["score"] + current_char.shift_item(item_gid, quantity) + @results.push({ type: type, item: Item.find_by_gid(item_gid), quantity: quantity }) + break + end + end + else + raise "Invalid result type (#{type})" # TODO: Improve this. + end + end + end +end |