From 2dd5608409f0a506cd2a682107d9be302cec8079 Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 20 May 2021 19:01:25 -0400 Subject: Implement learning activities from other activities --- app/controllers/game_controller.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'app/controllers') 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 -- cgit v1.2.3