This commit is contained in:
2025-06-23 07:01:22 +02:00
parent 1be11822ed
commit bc298fe0fa
2 changed files with 31 additions and 0 deletions
+30
View File
@@ -31,3 +31,33 @@ pub fn buy_cloak(session: &Session, cloak: String) -> Result {
)) ))
} }
} }
pub fn buy_hat(session: &Session, hat: String) -> Result {
let filter = doc! {
"uuid": session.local_player.id.clone()
};
if let Some(doc) = session.database.players.find_one(filter.clone()).run()? {
if doc.coins >= 50 {
session
.database
.players
.update_one(
filter,
doc! { "$inc": { "coins": -50 }, "$push": { "hats": hat.clone() } },
)
.run()?;
Ok(crate::response::Response::SuccessfulTransaction(format!(
"hat={hat}"
)))
} else {
Err(crate::response::Error::TransactionError(
"Not enough coins".to_string(),
))
}
} else {
Err(crate::response::Error::DatabaseError(
"Player not found".to_string(),
))
}
}
+1
View File
@@ -128,6 +128,7 @@ impl Session {
} }
"buy_cloak" => buy::buy_cloak(self, params.parse_param("cloak")?), "buy_cloak" => buy::buy_cloak(self, params.parse_param("cloak")?),
"buy_hat" => buy::buy_hat(self, params.parse_param("hat")?),
_ => Err(crate::response::Error::InvalidMethod(method.to_string())), _ => Err(crate::response::Error::InvalidMethod(method.to_string())),
} }