From 71f15b6534ffa7ba159d5e4076d59bb7961089a9 Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 20 May 2021 18:09:11 -0400 Subject: Refactor item xp awards data structure --- app/controllers/game_controller.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'app/controllers') 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 }) -- cgit v1.2.3