Skip to content

Commit

Permalink
Mods: Traders: ability to configure prive as number. Relates to lord-…
Browse files Browse the repository at this point in the history
  • Loading branch information
alek13 committed Sep 28, 2023
1 parent da83a1a commit f044f05
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 61 deletions.
120 changes: 60 additions & 60 deletions mods/lord/Entities/lord_traders/src/traders/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ trader_config.common_goods = {
--- @type traders.config
trader_config.dwarf = {
goods = table.merge(trader_config.common_goods, {
["lottthrowing:crossbow_silver 1"] = { price = "lord_money:silver_coin 9", chance = 15, stock = 1 },
["lottarmor:chestplate_mithril 1"] = { price = "lord_money:silver_coin 75", chance = 50, stock = 1 },
["default:steel_ingot 99"] = { price = "lord_money:silver_coin 20", chance = 12, stock = 1 },
["tools:sword_silver 1"] = { price = "lord_money:silver_coin 7", chance = 10, stock = 1 },
["default:bronze_ingot 25"] = { price = "lord_money:silver_coin 5", chance = 15, stock = 1 },
["lottblocks:small_lamp_pine 6"] = { price = "lord_money:silver_coin 2", chance = 6, stock = 1 },
["lottblocks:dwarf_harp 1"] = { price = "lord_money:silver_coin 15", chance = 10, stock = 1 },
["tools:dagger_mithril 1"] = { price = "lord_money:silver_coin 15", chance = 20, stock = 1 },
["tools:sword_mithril 1"] = { price = "lord_money:silver_coin 35", chance = 30, stock = 1 },
["tools:sword_steel 1"] = { price = "lord_money:silver_coin 5", chance = 10, stock = 1 },
["tools:battleaxe_silver 1"] = { price = "lord_money:silver_coin 10", chance = 18, stock = 1 },
["lottblocks:dwarfstone_stripe 50"] = { price = "lord_money:silver_coin 17", chance = 12, stock = 1 },
["lottblocks:dwarfstone_black 99"] = { price = "lord_money:silver_coin 33", chance = 17, stock = 1 },
["default:stonebrick 99"] = { price = "lord_money:silver_coin 25", chance = 14, stock = 1 },
["lottblocks:dwarfstone_white 99"] = { price = "lord_money:silver_coin 33", chance = 17, stock = 1 },
["lottthrowing:crossbow_silver 1"] = { price = 90, chance = 15, stock = 1 },
["lottarmor:chestplate_mithril 1"] = { price = 750, chance = 50, stock = 1 },
["default:steel_ingot 99"] = { price = 200, chance = 12, stock = 1 },
["tools:sword_silver 1"] = { price = 70, chance = 10, stock = 1 },
["default:bronze_ingot 25"] = { price = 50, chance = 15, stock = 1 },
["lottblocks:small_lamp_pine 6"] = { price = 20, chance = 6, stock = 1 },
["lottblocks:dwarf_harp 1"] = { price = 150, chance = 10, stock = 1 },
["tools:dagger_mithril 1"] = { price = 150, chance = 20, stock = 1 },
["tools:sword_mithril 1"] = { price = 350, chance = 30, stock = 1 },
["tools:sword_steel 1"] = { price = 50, chance = 10, stock = 1 },
["tools:battleaxe_silver 1"] = { price = 100, chance = 18, stock = 1 },
["lottblocks:dwarfstone_stripe 50"] = { price = 170, chance = 12, stock = 1 },
["lottblocks:dwarfstone_black 99"] = { price = 330, chance = 17, stock = 1 },
["default:stonebrick 99"] = { price = 250, chance = 14, stock = 1 },
["lottblocks:dwarfstone_white 99"] = { price = 330, chance = 17, stock = 1 },
}),
names = {
"Azaghâl", "Balbrin", "Borin", "Farin", "Flói", "Frerin",
Expand All @@ -56,21 +56,21 @@ trader_config.dwarf = {
--- @type traders.config
trader_config.elf = {
goods = table.merge(trader_config.common_goods, {
["lottplants:mallorntree 10"] = { price = "lord_money:silver_coin 4", chance = 5, stock = 1 },
["lottores:rough_rock 4"] = { price = "lord_money:silver_coin 30", chance = 17, stock = 1 },
["lottother:blue_torch 10"] = { price = "lord_money:silver_coin 20", chance = 15, stock = 1 },
["tools:spear_galvorn 1"] = { price = "lord_money:silver_coin 25", chance = 20, stock = 1 },
["tools:battleaxe_silver 1"] = { price = "lord_money:silver_coin 18", chance = 14, stock = 1 },
["tools:sword_galvorn 1"] = { price = "lord_money:silver_coin 25", chance = 25, stock = 1 },
["lottplants:elanor 10"] = { price = "lord_money:silver_coin 2", chance = 22, stock = 1 },
["lottarmor:chestplate_galvorn 1"] = { price = "lord_money:silver_coin 40", chance = 25, stock = 1 },
["lottarmor:helmet_galvorn 1"] = { price = "lord_money:silver_coin 30", chance = 25, stock = 1 },
["lottarmor:boots_galvorn 1"] = { price = "lord_money:silver_coin 25", chance = 25, stock = 1 },
["lottarmor:leggings_galvorn 1"] = { price = "lord_money:silver_coin 35", chance = 25, stock = 1 },
["lottplants:niphredil 12"] = { price = "lord_money:silver_coin 3", chance = 14, stock = 1 },
["lottblocks:mallorn_pillar 30"] = { price = "lord_money:silver_coin 7", chance = 4, stock = 1 },
["lottplants:mallornsapling 3"] = { price = "lord_money:silver_coin 2", chance = 17, stock = 1 },
["lottplants:mallornwood 99"] = { price = "lord_money:silver_coin 10", chance = 5, stock = 1 },
["lottplants:mallorntree 10"] = { price = 40, chance = 5, stock = 1 },
["lottores:rough_rock 4"] = { price = 300, chance = 17, stock = 1 },
["lottother:blue_torch 10"] = { price = 200, chance = 15, stock = 1 },
["tools:spear_galvorn 1"] = { price = 250, chance = 20, stock = 1 },
["tools:battleaxe_silver 1"] = { price = 180, chance = 14, stock = 1 },
["tools:sword_galvorn 1"] = { price = 250, chance = 25, stock = 1 },
["lottplants:elanor 10"] = { price = 20, chance = 22, stock = 1 },
["lottarmor:chestplate_galvorn 1"] = { price = 400, chance = 25, stock = 1 },
["lottarmor:helmet_galvorn 1"] = { price = 300, chance = 25, stock = 1 },
["lottarmor:boots_galvorn 1"] = { price = 250, chance = 25, stock = 1 },
["lottarmor:leggings_galvorn 1"] = { price = 350, chance = 25, stock = 1 },
["lottplants:niphredil 12"] = { price = 30, chance = 14, stock = 1 },
["lottblocks:mallorn_pillar 30"] = { price = 70, chance = 4, stock = 1 },
["lottplants:mallornsapling 3"] = { price = 20, chance = 17, stock = 1 },
["lottplants:mallornwood 99"] = { price = 100, chance = 5, stock = 1 },
}),
names = {
"Annael", "Anairë", "Curufin", "Erestor", "Gwindor", "Irimë",
Expand All @@ -88,21 +88,21 @@ trader_config.elf = {
--- @type traders.config
trader_config.hobbit = {
goods = table.merge(trader_config.common_goods, {
["lottfarming:pipe 1"] = { price = "lord_money:silver_coin 2", chance = 5, stock = 1 },
["lottfarming:pipeweed_cooked 50"] = { price = "lord_money:silver_coin 17", chance = 10, stock = 1 },
["lottpotion:beer 10"] = { price = "lord_money:silver_coin 7", chance = 8, stock = 1 },
["lottpotion:cider 15"] = { price = "lord_money:silver_coin 11", chance = 13, stock = 1 },
["lottpotion:wine 8"] = { price = "lord_money:silver_coin 18", chance = 14, stock = 1 },
["lottfarming:tomatoes 25"] = { price = "lord_money:silver_coin 23", chance = 25, stock = 1 },
["lottfarming:potato 30"] = { price = "lord_money:silver_coin 10", chance = 22, stock = 1 },
["lottfarming:brown_mushroom 40"] = { price = "lord_money:silver_coin 40", chance = 25, stock = 1 },
["lottfarming:corn_seed 12"] = { price = "lord_money:silver_coin 30", chance = 25, stock = 1 },
["farming:hoe_bronze 1"] = { price = "lord_money:silver_coin 25", chance = 25, stock = 1 },
["lord_books:brewing_book 1"] = { price = "lord_money:silver_coin 35", chance = 25, stock = 1 },
["lottfarming:barley_seed 5"] = { price = "lord_money:silver_coin 3", chance = 14, stock = 1 },
["lottfarming:berries 15"] = { price = "lord_money:silver_coin 7", chance = 4, stock = 1 },
["lottplants:firsapling 2"] = { price = "lord_money:silver_coin 2", chance = 17, stock = 1 },
["default:apple 10"] = { price = "lord_money:silver_coin 10", chance = 5, stock = 1 },
["lottfarming:pipe 1"] = { price = 20, chance = 5, stock = 1 },
["lottfarming:pipeweed_cooked 50"] = { price = 170, chance = 10, stock = 1 },
["lottpotion:beer 10"] = { price = 70, chance = 8, stock = 1 },
["lottpotion:cider 15"] = { price = 110, chance = 13, stock = 1 },
["lottpotion:wine 8"] = { price = 180, chance = 14, stock = 1 },
["lottfarming:tomatoes 25"] = { price = 230, chance = 25, stock = 1 },
["lottfarming:potato 30"] = { price = 100, chance = 22, stock = 1 },
["lottfarming:brown_mushroom 40"] = { price = 400, chance = 25, stock = 1 },
["lottfarming:corn_seed 12"] = { price = 300, chance = 25, stock = 1 },
["farming:hoe_bronze 1"] = { price = 250, chance = 25, stock = 1 },
["lord_books:brewing_book 1"] = { price = 350, chance = 25, stock = 1 },
["lottfarming:barley_seed 5"] = { price = 30, chance = 14, stock = 1 },
["lottfarming:berries 15"] = { price = 70, chance = 4, stock = 1 },
["lottplants:firsapling 2"] = { price = 20, chance = 17, stock = 1 },
["default:apple 10"] = { price = 100, chance = 5, stock = 1 },
}),
names = {
"Adalgrim", "Bodo", "Cotman", "Doderic", "Falco", "Gormadoc",
Expand All @@ -120,21 +120,21 @@ trader_config.hobbit = {
--- @type traders.config
trader_config.man = {
goods = table.merge(trader_config.common_goods, {
["default:sandstone 40"] = { price = "lord_money:silver_coin 10", chance = 12, stock = 1 },
["boats:sail_boat 1"] = { price = "lord_money:silver_coin 4", chance = 14, stock = 1 },
["lottarmor:shield_bronze 1"] = { price = "lord_money:silver_coin 20", chance = 20, stock = 1 },
["farming:bread 12"] = { price = "lord_money:silver_coin 2", chance = 5, stock = 1 },
["lottblocks:marble_brick 35"] = { price = "lord_money:silver_coin 12", chance = 10, stock = 1 },
["default:desert_stone 30"] = { price = "lord_money:silver_coin 8", chance = 12, stock = 1 },
["lottblocks:lamp_alder 5"] = { price = "lord_money:silver_coin 4", chance = 8, stock = 1 },
["lottarmor:chestplate_bronze 1"] = { price = "lord_money:silver_coin 30", chance = 30, stock = 1 },
["lottarmor:boots_bronze 1"] = { price = "lord_money:silver_coin 12", chance = 18, stock = 1 },
["lottblocks:lamp_lebethron 7"] = { price = "lord_money:silver_coin 6", chance = 11, stock = 1 },
["lottblocks:door_alder 6"] = { price = "lord_money:silver_coin 2", chance = 18, stock = 1 },
["lottores:marble 99"] = { price = "lord_money:silver_coin 33", chance = 18, stock = 1 },
["lottarmor:helmet_bronze 1"] = { price = "lord_money:silver_coin 20", chance = 24, stock = 1 },
["default:brick 30"] = { price = "lord_money:silver_coin 10", chance = 17, stock = 1 },
["lottarmor:leggings_bronze 1"] = { price = "lord_money:silver_coin 25", chance = 34, stock = 1 },
["default:sandstone 40"] = { price = 100, chance = 12, stock = 1 },
["boats:sail_boat 1"] = { price = 40, chance = 14, stock = 1 },
["lottarmor:shield_bronze 1"] = { price = 200, chance = 20, stock = 1 },
["farming:bread 12"] = { price = 20, chance = 5, stock = 1 },
["lottblocks:marble_brick 35"] = { price = 120, chance = 10, stock = 1 },
["default:desert_stone 30"] = { price = 80, chance = 12, stock = 1 },
["lottblocks:lamp_alder 5"] = { price = 40, chance = 8, stock = 1 },
["lottarmor:chestplate_bronze 1"] = { price = 300, chance = 30, stock = 1 },
["lottarmor:boots_bronze 1"] = { price = 120, chance = 18, stock = 1 },
["lottblocks:lamp_lebethron 7"] = { price = 60, chance = 11, stock = 1 },
["lottblocks:door_alder 6"] = { price = 20, chance = 18, stock = 1 },
["lottores:marble 99"] = { price = 330, chance = 18, stock = 1 },
["lottarmor:helmet_bronze 1"] = { price = 200, chance = 24, stock = 1 },
["default:brick 30"] = { price = 100, chance = 17, stock = 1 },
["lottarmor:leggings_bronze 1"] = { price = 250, chance = 34, stock = 1 },
}),
names = {
"Aratan", "Arvegil", "Belegorn", "Celepharn", "Dúnhere", "Elatan",
Expand Down
14 changes: 13 additions & 1 deletion mods/lord/Entities/lord_traders/src/traders/trader/Inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,26 @@ local function get_discount(price, same_race)
return price
end

--- @param price string|number
--- @return string stack string (for ex.: "lord_money:silver_coin 9")
local function price_to_stack_string(price)
if type(price) == "string" then return price end

if price % 1000 == 0 then return "lord_money:diamond_coin " .. (price / 1000) end
if price % 100 == 0 then return "lord_money:gold_coin " .. (price / 100 ) end
if price % 10 == 0 then return "lord_money:silver_coin " .. (price / 10 ) end
return "lord_money:copper_coin " .. price
end

--- @param good_stack_string string
--- @param goods_config traders.config.good[]
--- @param same_race boolean
--- @return string|nil stack string (for ex.: "lord_money:silver_coin 9")
local function get_price_for(good_stack_string, goods_config, same_race)
local good = goods_config[good_stack_string]
if not good then return nil end

return good and get_discount(good.price, same_race) or nil
return price_to_stack_string(get_discount(good.price, same_race))
end

------------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit f044f05

Please sign in to comment.