summaryrefslogtreecommitdiff
path: root/app/controllers/game_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/game_controller.rb')
-rw-r--r--app/controllers/game_controller.rb31
1 files changed, 18 insertions, 13 deletions
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