fixes bug (float precision) by using f64

This commit is contained in:
2019-10-18 21:39:23 +02:00
parent 61c9a4e6d4
commit b0441f3402
4 changed files with 38 additions and 33 deletions

View File

@@ -50,13 +50,13 @@ pub fn sell_item_transaction(
conn: &DbConnection,
id: i32,
loot_id: i32,
price_mod: Option<f32>,
price_mod: Option<f64>,
) -> QueryResult<(Item, Wealth)> {
conn.transaction(|| {
let deleted = LootManager(conn, id)
.remove(loot_id)?;
let mut sell_value =
deleted.base_price as f32 / 2.0;
deleted.base_price as f64 / 2.0;
if let Some(modifier) = price_mod {
sell_value *= modifier;
}
@@ -75,15 +75,15 @@ pub fn buy_item_from_inventory(
conn: &DbConnection,
id: i32,
item_id: i32,
price_mod: Option<f32>,
price_mod: Option<f64>,
) -> QueryResult<(Item, Wealth)> {
conn.transaction(|| {
// Find item in inventory
let item = Inventory(conn).find(item_id)?;
let new_item = LootManager(conn, id).add_from(&item)?;
let sell_price = match price_mod {
Some(modifier) => item.base_price as f32 * modifier,
None => item.base_price as f32,
Some(modifier) => item.base_price as f64 * modifier,
None => item.base_price as f64,
};
AsPlayer(conn, id)
.update_wealth(-sell_price)