From 250733a123530482464ba67a6bef15c2d5121af7 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 18 Apr 2021 18:11:00 +0100 Subject: [PATCH] Better price rationalisation --- assets/common/item_price_calculation.ron | 23 ++++++++++--------- .../loot_tables/food/wild_ingredients.ron | 1 - assets/common/loot_tables/trading.ron | 5 ++++ world/src/site/economy.rs | 21 ++++++++++------- 4 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 assets/common/loot_tables/trading.ron diff --git a/assets/common/item_price_calculation.ron b/assets/common/item_price_calculation.ron index 39c3dde145..92efc6bba2 100644 --- a/assets/common/item_price_calculation.ron +++ b/assets/common/item_price_calculation.ron @@ -7,9 +7,9 @@ loot_tables: [ (4.0, "common.loot_tables.weapons.tier-1"), (2.0, "common.loot_tables.weapons.tier-2"), (1.0, "common.loot_tables.weapons.tier-3"), - (0.5, "common.loot_tables.weapons.tier-4"), - (0.125, "common.loot_tables.weapons.tier-5"), - //(0.125, "common.loot_tables.weapons.cultist"), + (0.25, "common.loot_tables.weapons.tier-4"), + //(0.125, "common.loot_tables.weapons.tier-5"), + //(0.05, "common.loot_tables.weapons.cultist"), (0.125, "common.loot_tables.weapons.cave"), //(0.0625, "common.loot_tables.weapons.legendary"), // Armor @@ -17,9 +17,9 @@ loot_tables: [ (6.0, "common.loot_tables.armor.agile"), (3.0, "common.loot_tables.armor.swift"), (6.0, "common.loot_tables.armor.druid"), - (2.0, "common.loot_tables.armor.twigs"), - (2.0, "common.loot_tables.armor.twigsflowers"), - (2.0, "common.loot_tables.armor.twigsleaves"), + (1.0, "common.loot_tables.armor.twigs"), + (1.0, "common.loot_tables.armor.twigsflowers"), + (1.0, "common.loot_tables.armor.twigsleaves"), (0.5, "common.loot_tables.armor.plate"), (0.25, "common.loot_tables.armor.steel"), //(0.075, "common.loot_tables.armor.cultist"), @@ -28,18 +28,19 @@ loot_tables: [ (8.0, "common.loot_tables.materials.underground"), // Food (0.3, "common.loot_tables.food.farm_ingredients"), - (0.5, "common.loot_tables.food.wild_ingredients"), + (0.4, "common.loot_tables.food.wild_ingredients"), (0.2, "common.loot_tables.food.prepared"), // TODO: Change consumables when they are split up later (1.0, "common.loot_tables.consumables"), + (0.5, "common.loot_tables.trading"), ], // this is the amount of that good the most common item represents // so basically this table balances the goods against each other (higher=less valuable) good_scaling: [ - (Potions, 0.2), // common.items.consumable.potion_minor - (Food, 3.0), // common.items.food.mushroom + (Potions, 0.005), // common.items.consumable.potion_minor + (Food, 0.1), // common.items.food.mushroom (Coin, 1.0), // common.items.utility.coins - (Armor, 0.2), // common.items.armor.misc.pants.worker_blue - (Tools, 0.2), // common.items.weapons.staff.starter_staff + (Armor, 0.05), // common.items.armor.misc.pants.worker_blue + (Tools, 0.1), // common.items.weapons.staff.starter_staff (Ingredients, 0.25), // common.items.crafting_ing.leather_scraps ]) diff --git a/assets/common/loot_tables/food/wild_ingredients.ron b/assets/common/loot_tables/food/wild_ingredients.ron index 5a620b9a70..6af4f656da 100644 --- a/assets/common/loot_tables/food/wild_ingredients.ron +++ b/assets/common/loot_tables/food/wild_ingredients.ron @@ -3,5 +3,4 @@ (0.3, Item("common.items.food.cheese")), (1.0, Item("common.items.food.coconut")), (1.5, Item("common.items.food.mushroom")), - (0.5, Item("common.items.crafting_ing.honey")), ] diff --git a/assets/common/loot_tables/trading.ron b/assets/common/loot_tables/trading.ron new file mode 100644 index 0000000000..17b7bb0a68 --- /dev/null +++ b/assets/common/loot_tables/trading.ron @@ -0,0 +1,5 @@ +// Loot table that exists purely for price rationalisation +[ + (1.0, Item("common.items.crafting_ing.honey")), + (0.5, Item("common.items.crafting_ing.icy_fang")), +] diff --git a/world/src/site/economy.rs b/world/src/site/economy.rs index c5b7e4b018..a40d600525 100644 --- a/world/src/site/economy.rs +++ b/world/src/site/economy.rs @@ -326,19 +326,24 @@ impl Economy { } pub fn get_site_prices(&self) -> SitePrices { + let normalize = |xs: MapVec>| { + let sum = xs + .iter() + .map(|(_, x)| (*x).unwrap_or(0.0)) + .sum::() + .max(0.001); + xs.map(|_, x| Some(x? / sum)) + }; + SitePrices { values: { + let labor_values = normalize(self.labor_values.clone()); // Use labor values as prices. Not correct (doesn't care about exchange value) - let prices = self.labor_values.clone(); - // Normalized values. Note: not correct, but better than nothing - let sum = prices - .iter() - .map(|(_, price)| (*price).unwrap_or(0.0)) - .sum::() - .max(0.001); + let prices = normalize(self.values.clone()) + .map(|good, value| Some((labor_values[good]? + value?) * 0.5)); prices .iter() - .map(|(g, v)| (g, v.map(|v| v / sum).unwrap_or(Economy::MINIMUM_PRICE))) + .map(|(g, v)| (g, v.unwrap_or(Economy::MINIMUM_PRICE))) .collect() }, }