From e941a28056142ee239bbba623f03537aab0ae039 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 19 May 2021 20:33:10 -0400 Subject: Implement awarding items for results with no table entry --- app/controllers/game_controller.rb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'app/controllers/game_controller.rb') diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 43e6522..02684fe 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -32,23 +32,13 @@ class GameController < ApplicationController end if table_roll >= score - item = Item.find_by_gid(table_entry[:gid]) - xp_awards = {} - if item.whatnot && item.whatnot.key?(:xp_value) - xp_awards = item.whatnot[:xp_value] - .map { |gid, amount| { skill: Skill.find_by_gid(gid.to_s), amount: amount } } - xp_awards.each do |award| - current_char.add_skill_xp(award[:skill], award[:amount]) - end - end - current_char.shift_item(table_entry[:gid], quantity) - @results.push({ type: type, item: Item.find_by_gid(table_entry[:gid]), quantity: quantity, - xp: xp_awards }) + give_item_with_xp(table_entry[:gid], quantity) break end end else - # TODO: add for no table + quantity = result[:quantity] || 1 + give_item_with_xp(result[:gid], quantity) end when "hearth_amenity" bhi = current_char.hearth.built_hearth_amenities @@ -63,4 +53,19 @@ class GameController < ApplicationController rescue ItemQuantityError @results.replace({ type: "error", message: "You don't have enough items to complete this activity." }) end + + private + def give_item_with_xp(item, quantity) + item = Item.find_by_gid(item) if item.is_a? String + xp_awards = {} + if item.whatnot && item.whatnot.key?(:xp_value) + xp_awards = item.whatnot[:xp_value] + .map { |gid, amount| { skill: Skill.find_by_gid(gid.to_s), amount: amount } } + xp_awards.each do |award| + current_char.add_skill_xp(award[:skill], (award[:amount] * quantity)) + end + end + current_char.shift_item(item, quantity) + @results.push({ type: "item", item: item, quantity: quantity, xp: xp_awards }) + end end -- cgit v1.2.3