From 19d790dc0e6c10ffcce1fa71a59ded558d0ac0c9 Mon Sep 17 00:00:00 2001 From: David Gay Date: Fri, 28 May 2021 09:52:57 -0400 Subject: Monster drops, with a bunch of relevant data --- app/controllers/game_controller.rb | 58 +++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 886b37a..b785b25 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -65,7 +65,7 @@ class GameController < ApplicationController end if table_roll >= score - give_item_with_xp(table_entry, quantity) + give_item(table_entry, quantity, with_xp: true) table_entry[:titles]&.each do |title_data| title = Title.find_by_gid(title_data[:gid]) @@ -77,8 +77,10 @@ class GameController < ApplicationController end end else - quantity = result[:quantity] || 1 - give_item_with_xp(result, quantity) + min_quantity = result[:min_quantity] || result[:quantity] || 1 + max_quantity = result[:max_quantity] || result[:quantity] || 1 + quantity = rand(min_quantity..max_quantity) + give_item(result, quantity, with_xp: true) end when "hearth_amenity" bhi = current_char.hearth.built_hearth_amenities @@ -132,11 +134,14 @@ class GameController < ApplicationController end private - def give_item_with_xp(data, quantity) + def give_item(data, quantity, with_xp: false) 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)) + xp_awards = [] + if with_xp + 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 end current_char.shift_item(item, quantity) @results.push({ type: "item", item: item, quantity: quantity, xp: xp_awards }) @@ -190,6 +195,45 @@ class GameController < ApplicationController amount = award_data[:base] char.add_skill_xp(skill, amount) @results.push({ type: "xp", skill: skill, xp: amount }) + when "item" + # TODO: This is basically duplicated from earlier + next if rand > (award_data[:chance] || 1) + + if award_data[:table] + table_roll = rand + + award_data[:table].sort_by { |t| -t[:score] }.each do |table_entry| + min_quantity = table_entry[:min_quantity] || table_entry[:quantity] || 1 + max_quantity = table_entry[:max_quantity] || table_entry[:quantity] || 1 + quantity = rand(min_quantity..max_quantity) + + score = table_entry[:score] + table_scaling = award_data[: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 + + if table_roll >= score + give_item(table_entry, quantity) + + table_entry[:titles]&.each do |title_data| + title = Title.find_by_gid(title_data[:gid]) + if current_char.award_title(title) + @results.push({ type: "title", title: title }) + end + end + break + end + end + else + min_quantity = award_data[:min_quantity] || award_data[:quantity] || 1 + max_quantity = award_data[:max_quantity] || award_data[:quantity] || 1 + quantity = rand(min_quantity..max_quantity) + give_item(award_data, quantity) + end else raise "Invalid award type string (#{award_data[:type]})" end -- cgit v1.2.3