diff options
author | David Gay <david@davidgay.org> | 2021-05-20 19:01:25 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-20 19:01:25 -0400 |
commit | 2dd5608409f0a506cd2a682107d9be302cec8079 (patch) | |
tree | a5f856e5d7bb3a173bd8c5c361a2e7a144c320b5 /app | |
parent | d117dea29052b1ca23b1c848d92f1f9803945304 (diff) |
Implement learning activities from other activities
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/game_controller.rb | 19 | ||||
-rw-r--r-- | app/views/activities/_results.html.erb | 2 |
2 files changed, 21 insertions, 0 deletions
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 9a40fb2..58644a7 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -45,6 +45,25 @@ class GameController < ApplicationController .find_or_initialize_by(hearth_amenity: HearthAmenity.find_by_gid(result[:gid])) bhi.update(level: result[:level]) @results.push({ type: type, hearth_amenity: bhi.hearth_amenity }) + when "activity" + next if rand > (result[:chance] || 1) + table_roll = rand + result[:table].sort_by { |t| -t[:score] }.each do |table_entry| + score = table_entry[:score] + result[:table_scaling]&.each do |scale_entry| + case scale_entry[:type] + when "skill" + score = score**(1 + (scale_entry[:scale_value] * current_char.skill_level(scale_entry[:gid]))) + end + end + if table_roll >= score + activity = Activity.find_by_gid(table_entry[:gid]) + unless current_char.learned_activities.exists?(activity: activity) + current_char.learned_activities.create(activity: activity) + @results.push({ type: type, activity: activity }) + end + end + end else raise "Invalid result type (#{type})" # TODO: Improve this. end diff --git a/app/views/activities/_results.html.erb b/app/views/activities/_results.html.erb index 0e540dd..0fef8fb 100644 --- a/app/views/activities/_results.html.erb +++ b/app/views/activities/_results.html.erb @@ -9,6 +9,8 @@ </p> <% when "hearth_amenity" %> <p>You constructed <%= result[:hearth_amenity].name %>.</p> + <% when "activity" %> + <p>You realized how to <%= result[:activity].name %>!</p> <% when "error" %> <p><%= result[:message] %></p> <% end %> |