From 5afdcd12f04102b5cf5d5a310981bc576a992119 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 19 May 2021 21:16:15 -0400 Subject: Implement crafting from the hearth forge --- app/controllers/activities_controller.rb | 2 +- app/controllers/characters/hearth_controller.rb | 1 + app/views/activities/show.html.erb | 5 ++++- app/views/characters/hearth/index.html.erb | 24 +++++++++++++++++++----- config/routes.rb | 5 ++--- data/activities.yml | 16 ++++++++++++++++ data/items.yml | 6 ++++++ 7 files changed, 49 insertions(+), 10 deletions(-) diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index f72bc3a..934f617 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -7,7 +7,7 @@ class ActivitiesController < ApplicationController @activity = Activity.find(params[:id]) if current_char.can_do_activity?(@activity) current_char.start_activity(@activity) - redirect_to action: :show + redirect_to activity_path(@activity) else flash[:alert] = "You can't do that. Make sure you have the items and meet the requirements." redirect_to character_path(current_char) diff --git a/app/controllers/characters/hearth_controller.rb b/app/controllers/characters/hearth_controller.rb index f2d2bf7..abe8232 100644 --- a/app/controllers/characters/hearth_controller.rb +++ b/app/controllers/characters/hearth_controller.rb @@ -2,5 +2,6 @@ class Characters::HearthController < ApplicationController def index @all_amenities = HearthAmenity.all @construct_activities = Activity.where("gid like ?", "construct_%") + @forge_activities = Activity.where("gid like ?", "craft_%") end end diff --git a/app/views/activities/show.html.erb b/app/views/activities/show.html.erb index 6db2fb2..84c19a4 100644 --- a/app/views/activities/show.html.erb +++ b/app/views/activities/show.html.erb @@ -9,4 +9,7 @@ <%= render "timer" %> -<%= link_to "Start", start_activity_path(@activity), method: :post %> +<%= form_with url: start_activity_path do |f| %> + <%= f.hidden_field :id, value: @activity.id %> + <%= f.submit "Start" %> +<% end %> diff --git a/app/views/characters/hearth/index.html.erb b/app/views/characters/hearth/index.html.erb index 487bd46..6f2c444 100644 --- a/app/views/characters/hearth/index.html.erb +++ b/app/views/characters/hearth/index.html.erb @@ -8,8 +8,13 @@ @@ -17,14 +22,23 @@ <% current_char.hearth.built_hearth_amenities.each do |bhi| %>

<%= bhi.hearth_amenity.name %>

-

Level <%= bhi.level %>

-

<%= bhi.hearth_amenity.description %>

+

Level <%= bhi.level %>

+

<%= bhi.hearth_amenity.description %>

+ <% if bhi.hearth_amenity.gid == "forge" %> + <%= form_with url: start_activity_path, method: :post do |f| %> + <%= f.select :id, @forge_activities.map { |a| [a.name, a.id] } %> + <%= f.submit "Go" %> + <% end %> + <% end %>
<% end %> <% else %>

You haven't built your hearth yet. First, you'll need to start with a foundation.

<% construct_activity = foundation.construct_activity(1) %> - <%= link_to construct_activity.name, start_activity_path(construct_activity), method: :post %> + <%= form_with url: start_activity_path do |f| %> + <%= f.hidden_field :id, value: construct_activity.id %> + <%= f.submit construct_activity.name %> + <% end %> (costs <%= construct_activity.cost_string %>) <% end %> diff --git a/config/routes.rb b/config/routes.rb index 21230a8..f3096f7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,9 +11,7 @@ Rails.application.routes.draw do put "users", to: "devise/registrations#update", as: "user_registration" end - resources :activities, only: [:show] do - post "start", on: :member - end + resources :activities, only: [:show] resources :characters, only: [:show, :new, :create] do scope module: :characters do @@ -24,5 +22,6 @@ Rails.application.routes.draw do resources :locations, only: [:index, :show] + post "/start_activity", to: "activities#start" post "/finish_activity", to: "game#finish_activity" end diff --git a/data/activities.yml b/data/activities.yml index cf494c1..2395f82 100644 --- a/data/activities.yml +++ b/data/activities.yml @@ -33,6 +33,22 @@ construct_forge_level1: - type: "hearth_amenity" gid: "forge" level: 1 +craft_pig_iron_ingot: + name: "Smelt Pig Iron Ingot" + description: "Smelt a pig iron ingot." + whatnot: + duration: + base: 70 + minimum: 35 + scaling: + otherforge: 2 + cost: + - type: "item" + gid: "crude_iron_ore" + quantity: 10 + results: + - type: "item" + gid: "pig_iron_ingot" quarry_floret_mines: name: "Quarry Floret Mines" description: "Planequarry at the Floret Mines." diff --git a/data/items.yml b/data/items.yml index 06bd627..3d1adef 100644 --- a/data/items.yml +++ b/data/items.yml @@ -43,6 +43,12 @@ yellow_beryl: whatnot: xp_value: planequarry: 50 +pig_iron_ingot: + name: "pig iron ingot" + description: "Low quality iron ingot meant to be remelted for further use." + whatnot: + xp_value: + otherforge: 15 iron_short_sword: name: "Iron short sword" description: "A short sword made of iron." -- cgit v1.2.3