summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/game_controller.rb18
-rw-r--r--app/views/activities/_results.html.erb2
2 files changed, 8 insertions, 12 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 })
diff --git a/app/views/activities/_results.html.erb b/app/views/activities/_results.html.erb
index 42f22a3..0e540dd 100644
--- a/app/views/activities/_results.html.erb
+++ b/app/views/activities/_results.html.erb
@@ -3,7 +3,7 @@
<% case result[:type] %>
<% when "item" %>
<p>You got <%= result[:quantity] %> <%= result[:item].name %>
- <% if result[:xp].any? %>
+ <% if result[:xp]&.any? %>
(<%= result[:xp].map { |award| "#{award[:amount]} xp #{award[:skill].name}" }.join(", ") %>)
<% end %>
</p>