diff options
author | David Gay <david@davidgay.org> | 2021-05-19 20:33:10 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-19 20:33:10 -0400 |
commit | e941a28056142ee239bbba623f03537aab0ae039 (patch) | |
tree | 6c6a916dc129ca793b6c26609f6597715fb90775 | |
parent | d8684281c69b76be39ff41fba71c0c62c6fab6c4 (diff) |
Implement awarding items for results with no table entry
-rw-r--r-- | app/controllers/game_controller.rb | 31 |
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 |