summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/game_controller.rb19
-rw-r--r--app/views/activities/_results.html.erb2
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 %>