works on selling group items
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user