From 361acfad2162e08a962c63c4443641fbbd812089 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 16 Jun 2021 19:20:17 -0400 Subject: Learn spells from spellpages --- app/controllers/characters/spells_controller.rb | 6 +++++- app/lib/activity_processor.rb | 5 +---- app/views/application/_results.html.erb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/controllers/characters/spells_controller.rb b/app/controllers/characters/spells_controller.rb index 9694856..a0e6913 100644 --- a/app/controllers/characters/spells_controller.rb +++ b/app/controllers/characters/spells_controller.rb @@ -1,5 +1,9 @@ class Characters::SpellsController < ApplicationController def index - @spell_activities = Activity.where("gid like ?", "havencast_%").order(:name) + @spell_activities = Activity.where("gid like ?", "havencast_%").where(innate: true).order(:name) + # TODO: Don't load into memory + @spell_activities = @spell_activities.to_a + current_char.learned_activities + .map { |la| la.activity } + .select { |a| a.gid.start_with?("havencast_") } end end diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb index fb0b13d..18fdece 100644 --- a/app/lib/activity_processor.rb +++ b/app/lib/activity_processor.rb @@ -97,10 +97,6 @@ class ActivityProcessor @results.push({ type: "message", body: result[:message] }) @results.push({ type: type, condition: condition }) end - when "decipher_magicscript" - Character.transaction do - # TODO: Add functionality - end when "activity" next if rand > (result[:chance] || 1) table_roll = rand @@ -108,6 +104,7 @@ class ActivityProcessor score = table_entry[:score] if table_roll >= score new_activity = Activity.find_by_gid(table_entry[:gid]) + raise "Invalid activity gid (#{table_entry[:gid]})" unless new_activity unless @character.learned_activities.exists?(activity: new_activity) @character.learned_activities.create(activity: new_activity) @results.push({ type: type, activity: new_activity }) diff --git a/app/views/application/_results.html.erb b/app/views/application/_results.html.erb index 691f1d5..a7dc002 100644 --- a/app/views/application/_results.html.erb +++ b/app/views/application/_results.html.erb @@ -13,7 +13,7 @@

You planted <%= link_to result[:hearth_planting].item.name, item_path(result[:hearth_planting].item) %> in the loam.

<% when "activity" %> -

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

+

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

<% when "monster" %>

You encountered a <%= result[:monster].name %>.

<%= result[:monster].description %>

-- cgit v1.2.3