From 71f15b6534ffa7ba159d5e4076d59bb7961089a9 Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 20 May 2021 18:09:11 -0400 Subject: Refactor item xp awards data structure --- app/controllers/game_controller.rb | 18 +++++++----------- app/views/activities/_results.html.erb | 2 +- data/activities.yml | 24 ++++++++++++++++++++++++ data/items.yml | 20 -------------------- 4 files changed, 32 insertions(+), 32 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" %>

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 %>

diff --git a/data/activities.yml b/data/activities.yml index e71485d..562e29a 100644 --- a/data/activities.yml +++ b/data/activities.yml @@ -51,6 +51,9 @@ craft_pig_iron_ingot: results: - type: "item" gid: "pig_iron_ingot" + xp: + - gid: "otherforge" + value: 15 quarry_floret_mines: name: "Quarry Floret Mines" description: "Planequarry at the Floret Mines." @@ -74,10 +77,19 @@ quarry_floret_mines: table: - gid: "crude_iron_ore" score: 0 + xp: + - gid: "planequarry" + value: 5 - gid: "iron_ore" score: 0.98 + xp: + - gid: "planequarry" + value: 10 - gid: "pure_iron_ore" score: 0.996 + xp: + - gid: "planequarry" + value: 20 table_scaling: - type: "skill" gid: "planequarry" @@ -87,9 +99,21 @@ quarry_floret_mines: table: - gid: "red_beryl" score: 0 + xp: + - gid: "planequarry" + value: 30 - gid: "tourmaline" score: 0.45 + xp: + - gid: "planequarry" + value: 30 - gid: "yellow_beryl" score: 0.90 + xp: + - gid: "planequarry" + value: 50 - gid: "paraiba_tourmaline" score: 0.95 + xp: + - gid: "planequarry" + value: 50 diff --git a/data/items.yml b/data/items.yml index 3d1adef..b36ec25 100644 --- a/data/items.yml +++ b/data/items.yml @@ -5,64 +5,44 @@ crude_iron_ore: name: "Crude iron ore" description: "A chunk of very impure iron ore." whatnot: - xp_value: - planequarry: 5 iron_ore: name: "Iron ore" description: "A chunk of unrefined iron ore." whatnot: - xp_value: - planequarry: 10 pure_iron_ore: name: "Pure iron ore" description: "A chunk of naturally rich and pure iron ore." whatnot: - xp_value: - planequarry: 20 paraiba_tourmaline: name: "Paraiba tourmaline" description: "A rare and beautiful turquoise gem." whatnot: - xp_value: - planequarry: 50 red_beryl: name: "Red beryl" description: "A simple red gem." whatnot: - xp_value: - planequarry: 30 tourmaline: name: "Tourmaline" description: "A crude pink-blue gem." whatnot: - xp_value: - planequarry: 30 yellow_beryl: name: "Yellow beryl" description: "A rare and beautiful yellow gem." whatnot: - xp_value: - planequarry: 50 pig_iron_ingot: name: "pig iron ingot" description: "Low quality iron ingot meant to be remelted for further use." whatnot: - xp_value: - otherforge: 15 iron_short_sword: name: "Iron short sword" description: "A short sword made of iron." whatnot: - xp_value: - otherforge: 15 equip_slot: "mainhand" iron_longsword: name: "Iron longsword" description: "A longsword made of iron." equip_slot: "mainhand" whatnot: - xp_value: - otherforge: 45 equip_requirements: skills: beastslay: 3 -- cgit v1.2.3