summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/game_controller.rb49
-rw-r--r--data/activities.yml21
2 files changed, 39 insertions, 31 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
diff --git a/data/activities.yml b/data/activities.yml
index e9bad7d..cf494c1 100644
--- a/data/activities.yml
+++ b/data/activities.yml
@@ -47,28 +47,29 @@ quarry_floret_mines:
- type: "item"
chance: 1
table:
- stone:
+ - gid: "stone"
score: 0
- type: "item"
chance: 1
table:
- crude_iron_ore:
+ - gid: "crude_iron_ore"
score: 0
- iron_ore:
+ - gid: "iron_ore"
score: 0.98
- pure_iron_ore:
+ - gid: "pure_iron_ore"
score: 0.996
table_scaling:
- skills:
- planequarry: 1.25
+ - type: "skill"
+ gid: "planequarry"
+ scale_value: 1.25
- type: "item"
chance: 0.02
table:
- red_beryl:
+ - gid: "red_beryl"
score: 0
- tourmaline:
+ - gid: "tourmaline"
score: 0.45
- yellow_beryl:
+ - gid: "yellow_beryl"
score: 0.90
- paraiba_tourmaline:
+ - gid: "paraiba_tourmaline"
score: 0.95