From 5ae89950fb330fd623634b98a77de259ab174b53 Mon Sep 17 00:00:00 2001 From: David Gay Date: Fri, 28 May 2021 11:26:44 -0400 Subject: Lockbox unlocking, and with it items that start activities when used --- app/controllers/activities_controller.rb | 10 +--------- app/controllers/application_controller.rb | 13 +++++++++++++ app/controllers/characters/items_controller.rb | 2 ++ app/controllers/game_controller.rb | 5 +++++ 4 files changed, 21 insertions(+), 9 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index c115abb..8e18ec9 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -5,14 +5,6 @@ class ActivitiesController < ApplicationController def start @activity = Activity.find(params[:id]) - if current_char.start_activity(@activity, queued_actions: params[:queued_actions]) - redirect_to look_path - else - message = "You can't do that." - message += " (requires #{@activity.requirements&.join(", ")})" if @activity.requirements.any? - message += " (costs #{@activity.costs&.join(", ")})" if @activity.costs.any? - flash[:alert] = message - redirect_back(fallback_location: character_path(current_char)) - end + start_activity(@activity) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 94859d1..0fc78a8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,4 +14,17 @@ class ApplicationController < ActionController::Base def roll(sides) rand(sides) + 1 end + + private + def start_activity(activity) + if current_char.start_activity(activity, queued_actions: params[:queued_actions]) + redirect_to look_path + else + message = "You can't do that." + message += " (requires #{activity.requirements&.join(", ")})" if activity.requirements.any? + message += " (costs #{activity.costs&.join(", ")})" if activity.costs.any? + flash[:alert] = message + redirect_back(fallback_location: character_path(current_char)) + end + end end diff --git a/app/controllers/characters/items_controller.rb b/app/controllers/characters/items_controller.rb index e1dfd5c..93dc683 100644 --- a/app/controllers/characters/items_controller.rb +++ b/app/controllers/characters/items_controller.rb @@ -45,6 +45,8 @@ class Characters::ItemsController < ApplicationController heal_or_gain = wounds_change.positive? ? "gain" : "heal" flash[:notice] += " You #{heal_or_gain} #{wounds_change.abs} wound(s)." end + when "activity" + start_activity(Activity.find_by_gid(effect[:gid])) and return else raise "Invalid use effect type string (#{effect[:type]})" end diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 8b92222..bf45973 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -24,6 +24,11 @@ class GameController < ApplicationController activity.whatnot[:results].each do |result| type = result[:type] case type + when "xp" + skill = Skill.find_by_gid(result[:gid]) + amount = result[:base] + current_char.add_skill_xp(skill, amount) + @results.push({ type: "xp", skill: skill, xp: amount }) when "monster" raise TooManyWoundsError unless current_char.can_fight? next if rand > (result[:chance] || 1) -- cgit v1.2.3