diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/game_controller.rb | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 02684fe..9a40fb2 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -32,13 +32,13 @@ class GameController < ApplicationController end if table_roll >= score - give_item_with_xp(table_entry[:gid], quantity) + give_item_with_xp(table_entry, quantity) break end end else quantity = result[:quantity] || 1 - give_item_with_xp(result[:gid], quantity) + give_item_with_xp(result, quantity) end when "hearth_amenity" bhi = current_char.hearth.built_hearth_amenities @@ -55,15 +55,11 @@ class GameController < ApplicationController 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 + def give_item_with_xp(data, quantity) + item = Item.find_by_gid(data[:gid]) + xp_awards = data[:xp]&.map { |xpe| { skill: Skill.find_by_gid(xpe[:gid]), amount: xpe[:value] } } + xp_awards&.each do |award| + current_char.add_skill_xp(award[:skill], (award[:amount] * quantity)) end current_char.shift_item(item, quantity) @results.push({ type: "item", item: item, quantity: quantity, xp: xp_awards }) |