From d2a31e04d19796a600a932a3491e056fe2c89af2 Mon Sep 17 00:00:00 2001 From: David Gay Date: Tue, 15 Jun 2021 19:54:29 -0400 Subject: Basic spellcasting --- app/controllers/characters/spells_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/controllers/characters/spells_controller.rb (limited to 'app/controllers/characters/spells_controller.rb') diff --git a/app/controllers/characters/spells_controller.rb b/app/controllers/characters/spells_controller.rb new file mode 100644 index 0000000..9694856 --- /dev/null +++ b/app/controllers/characters/spells_controller.rb @@ -0,0 +1,5 @@ +class Characters::SpellsController < ApplicationController + def index + @spell_activities = Activity.where("gid like ?", "havencast_%").order(:name) + end +end -- cgit v1.2.3 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 +- data/activities.yml | 16 ++++++++++------ data/items.yml | 8 ++++---- 5 files changed, 21 insertions(+), 16 deletions(-) (limited to 'app/controllers/characters/spells_controller.rb') 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 %>

diff --git a/data/activities.yml b/data/activities.yml index 66b7765..3202e7f 100644 --- a/data/activities.yml +++ b/data/activities.yml @@ -2904,9 +2904,9 @@ havencast_dazzle: - type: "xp" gid: "havencast" base: 5 -havencast_decipher_magicscript: - name: "Cast Decipher Magicscript" - description: "Cast the Decipher Magicscript cantrip." +havencast_decipher_simple_magicscript: + name: "Cast Decipher Simple Magicscript" + description: "Cast the Decipher Simple Magicscript cantrip." whatnot: tags: - "spell" @@ -2927,13 +2927,17 @@ havencast_decipher_magicscript: value: 1 cost: - type: "item" - gid: "spellpage" + gid: "simple_spellpage" quantity: 1 results: - type: "xp" gid: "havencast" - base: 7 - - type: "decipher_magicscript" + base: 10 + - type: "activity" + chance: 1 + table: + - gid: "havencast_stinging_rays" + score: 0 havencast_enchant_apprentice_wand: name: "Cast Enchant Apprentice Wand" description: "Cast the Enchant Apprentice Wand spell." diff --git a/data/items.yml b/data/items.yml index b20ab34..a89591e 100644 --- a/data/items.yml +++ b/data/items.yml @@ -1134,9 +1134,9 @@ faint_mana: - type: "stat_change" gid: "mana" modifier: 1 -spellpage: - name: "spellpage" - description: "A piece of parchment covered in magical script. Deciphering it can yield knowledge of a spell." +simple_spellpage: + name: "simple spellpage" + description: "An old piece of parchment covered in magical script. Deciphering it can yield knowledge of a spell." whatnot: tags: - - "materials" + - "material" -- cgit v1.2.3