mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Complete factory rating support
This commit is contained in:
@@ -265,4 +265,38 @@ impl crate::VehicleFactoryAdapter for ArcAdapter {
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
async fn rate_vehicle(&self, id: i32, combat: i32, cosmetic: i32) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if self.is_readonly {
|
||||
return Ok(());
|
||||
}
|
||||
// TODO this should probably be a transaction
|
||||
if let Some(meta) = super::entities::robot_metadata::Entity::find_by_id(id as u32).one(&self.orm).await? {
|
||||
let total_ratings = (meta.buy_count + meta.rent_count) as f64; // idk why/how these are different
|
||||
let next_combat_rating = meta.combat_rating + (((combat as f64) - meta.combat_rating) / total_ratings);
|
||||
let next_cosmetic_rating = meta.cosmetic_rating + (((cosmetic as f64) - meta.cosmetic_rating) / total_ratings);
|
||||
super::entities::robot_metadata::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Set(id as u32),
|
||||
cosmetic_rating: sea_orm::ActiveValue::Set(next_cosmetic_rating),
|
||||
combat_rating: sea_orm::ActiveValue::Set(next_combat_rating),
|
||||
..Default::default()
|
||||
}.update(&self.orm).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn purchase(&self, id: i32) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if self.is_readonly {
|
||||
return Ok(());
|
||||
}
|
||||
// TODO this should probably be a transaction
|
||||
if let Some(meta) = super::entities::robot_metadata::Entity::find_by_id(id as u32).one(&self.orm).await? {
|
||||
super::entities::robot_metadata::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Set(id as u32),
|
||||
buy_count: sea_orm::ActiveValue::Set(meta.buy_count + 1),
|
||||
..Default::default()
|
||||
}.update(&self.orm).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ pub trait VehicleFactoryAdapter: Send + Sync + 'static {
|
||||
async fn vehicle(&self, id: u32) -> Result<Option<(VehicleInfo, VehicleQueryInfo)>, Box<dyn std::error::Error>>;
|
||||
async fn list(&self, query: libfj::robocraft::ListQuery) -> Result<Vec<VehicleQueryInfo>, Box<dyn std::error::Error>>;
|
||||
async fn upload(&self, vehicle: VehicleUploadInfo) -> Result<VehicleThumbnailInfo, Box<dyn std::error::Error>>;
|
||||
async fn rate_vehicle(&self, id: i32, combat: i32, cosmetic: i32) -> Result<(), Box<dyn std::error::Error>>;
|
||||
/// Just update any purchase trackers
|
||||
async fn purchase(&self, id: i32) -> Result<(), Box<dyn std::error::Error>>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user