summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-20 18:09:11 -0400
committerDavid Gay <david@davidgay.org>2021-05-20 18:09:26 -0400
commit71f15b6534ffa7ba159d5e4076d59bb7961089a9 (patch)
treec762e4e7044f2daf97642e239397955789687635 /app/controllers
parentfea8b6bb7aef2d69c0641b19abc0f05eb89e789e (diff)
Refactor item xp awards data structure
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/game_controller.rb18
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 })