summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/game_controller.rb49
1 files changed, 28 insertions, 21 deletions
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb
index d3d3ce2..43e6522 100644
--- a/app/controllers/game_controller.rb
+++ b/app/controllers/game_controller.rb
@@ -14,34 +14,41 @@ class GameController < ApplicationController
type = result[:type]
case type
when "item"
- next if rand > result[:chance]
- table_roll = rand
+ next if rand > (result[:chance] || 1)
- result[:table].sort_by { |_, v| -v[:score] }.each do |item_gid, item_data|
- quantity = item_data[:quantity] || 1
+ if result[:table]
+ table_roll = rand
- score = item_data[:score]
- if result[:table_scaling]
- result[:table_scaling][:skills]&.each do |skill_gid, scale_value|
- score = score**(1 + (scale_value * current_char.skill_level(skill_gid)))
+ result[:table].sort_by { |t| -t[:score] }.each do |table_entry|
+ quantity = table_entry[:quantity] || 1
+
+ score = table_entry[:score]
+ table_scaling = result[:table_scaling]
+ table_scaling&.each do |scale_entry|
+ case scale_entry[:type]
+ when "skill"
+ score = score**(1 + (scale_entry[:scale_value] * current_char.skill_level(scale_entry[:gid])))
+ end
end
- end
- if table_roll >= score
- item = Item.find_by_gid(item_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])
+ 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 })
+ break
end
- current_char.shift_item(item_gid, quantity)
- @results.push({ type: type, item: Item.find_by_gid(item_gid), quantity: quantity,
- xp: xp_awards })
- break
end
+ else
+ # TODO: add for no table
end
when "hearth_amenity"
bhi = current_char.hearth.built_hearth_amenities