works on selling group items

This commit is contained in:
2019-10-20 22:03:06 +02:00
parent 05a08ea337
commit 74ee4a831b
3 changed files with 41 additions and 6 deletions

View File

@@ -118,6 +118,21 @@ pub fn resolve_claims(conn: &DbConnection) -> QueryResult<()> {
Ok(())
}
/// Split up and share group money among selected players
pub fn split_and_share(conn: &DbConnection, amount: i32, players: Vec<i32>) -> QueryResult<Wealth> {
let share = (
amount / (players.len() + 1) as i32 // +1 share for the group
) as f64;
conn.transaction(|| {
for p in players.into_iter() {
AsPlayer(conn, p).update_wealth(share)?;
AsPlayer(conn, 0).update_wealth(-share)?;
}
Ok(Wealth::from_gp(share))
})
}
#[cfg(none)]
mod tests_old {