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 +++++++++++++++++++ app/views/activities/_results.html.erb | 2 ++ data/activities.yml | 30 ++++++++++++++++++++++++++++++ data/items.yml | 11 +++-------- 4 files changed, 54 insertions(+), 8 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 @@

<% when "hearth_amenity" %>

You constructed <%= result[:hearth_amenity].name %>.

+ <% when "activity" %> +

You realized how to <%= result[:activity].name %>!

<% when "error" %>

<%= result[:message] %>

<% end %> diff --git a/data/activities.yml b/data/activities.yml index 01a4c88..26f4535 100644 --- a/data/activities.yml +++ b/data/activities.yml @@ -57,6 +57,36 @@ craft_pig_iron_ingot: xp: - gid: "otherforge" value: 15 + - type: "activity" + chance: 0.05 + table: + - gid: "craft_iron_ingot" + score: 0 + table_scaling: + - type: "skill" + gid: "otherforge" + scale_value: 1.25 +craft_iron_ingot: + name: "Smelt Iron Ingot" + description: "Smelt an iron ingot." + whatnot: + duration: + base: 80 + minimum: 35 + scaling: + - type: "skill" + gid: "otherforge" + scale_value: 2 + cost: + - type: "item" + gid: "iron_ore" + quantity: 10 + results: + - type: "item" + gid: "iron_ingot" + xp: + - gid: "otherforge" + value: 20 quarry_floret_mines: name: "Quarry Floret Mines" description: "Planequarry at the Floret Mines." diff --git a/data/items.yml b/data/items.yml index b36ec25..5b5bc3b 100644 --- a/data/items.yml +++ b/data/items.yml @@ -4,35 +4,30 @@ stone: crude_iron_ore: name: "Crude iron ore" description: "A chunk of very impure iron ore." - whatnot: iron_ore: name: "Iron ore" description: "A chunk of unrefined iron ore." - whatnot: pure_iron_ore: name: "Pure iron ore" description: "A chunk of naturally rich and pure iron ore." - whatnot: paraiba_tourmaline: name: "Paraiba tourmaline" description: "A rare and beautiful turquoise gem." - whatnot: red_beryl: name: "Red beryl" description: "A simple red gem." - whatnot: tourmaline: name: "Tourmaline" description: "A crude pink-blue gem." - whatnot: yellow_beryl: name: "Yellow beryl" description: "A rare and beautiful yellow gem." - whatnot: pig_iron_ingot: name: "pig iron ingot" description: "Low quality iron ingot meant to be remelted for further use." - whatnot: +iron_ingot: + name: "iron ingot" + description: "A simple bar of iron." iron_short_sword: name: "Iron short sword" description: "A short sword made of iron." -- cgit v1.2.3