summaryrefslogtreecommitdiff
path: root/app/controllers/game_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/game_controller.rb')
-rw-r--r--app/controllers/game_controller.rb19
1 files changed, 19 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