mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Guess weapon order for factory downloads (since they have no weapon order) #6
This commit is contained in:
@@ -9,7 +9,7 @@ const SLOT_PARAM_KEY: u8 = 43; // in; int
|
||||
const FACTORY_ID_PARAM_KEY: u8 = 94; // in; int
|
||||
|
||||
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory: &std::sync::Arc<rc_core::factory::Factory>) -> Result<ParameterTable, i16> {
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory: &std::sync::Arc<rc_core::factory::Factory>, weapon_order: &std::sync::Arc<rc_core::cubes::WeaponListParser>) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
let user_info = user.user()?;
|
||||
let slot = if let Some(Typed::Int(slot)) = params.remove(&SLOT_PARAM_KEY) {
|
||||
@@ -25,12 +25,16 @@ async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory:
|
||||
rc_core::data::error_codes::WebServicesError::DatabaseError as i16
|
||||
})?;
|
||||
if let Some((vehicle_to_copy, vehicle_meta)) = vehicle {
|
||||
// parse cube data for weapon order
|
||||
let mut cursor = std::io::Cursor::new(&vehicle_to_copy.cube_data);
|
||||
let weapons = weapon_order.guess_weapons(&mut cursor);
|
||||
// save to database
|
||||
let to_save = rc_core::persist::user::VehicleData {
|
||||
name: Some(vehicle_meta.name),
|
||||
slot,
|
||||
robot_data: vehicle_to_copy.cube_data,
|
||||
colour_data: vehicle_to_copy.colour_data,
|
||||
weapon_order: Vec::default(), // FIXME calculate this somehow? Or maybe get the factory adapter to calculate this
|
||||
weapon_order: weapons,
|
||||
crf_id: Some(factory_id),
|
||||
};
|
||||
user_info.save_slot(to_save).await?;
|
||||
@@ -46,6 +50,7 @@ async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory:
|
||||
|
||||
pub struct CrfItemPurchaseProvider {
|
||||
factory: std::sync::Arc<rc_core::factory::Factory>,
|
||||
weapon_order: std::sync::Arc<rc_core::cubes::WeaponListParser>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -53,7 +58,7 @@ impl polariton_server::operations::Operation<()> for CrfItemPurchaseProvider {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_handling(params, user, &self.factory).await)
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_handling(params, user, &self.factory, &self.weapon_order).await)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,8 +69,9 @@ impl polariton_server::operations::OperationCode for CrfItemPurchaseProvider {
|
||||
}
|
||||
|
||||
|
||||
pub(super) fn crf_copy_to_bay_provider(factory: &std::sync::Arc<rc_core::factory::Factory>) -> CrfItemPurchaseProvider {
|
||||
pub(super) fn crf_copy_to_bay_provider(factory: &std::sync::Arc<rc_core::factory::Factory>, weapon_order: std::sync::Arc<rc_core::cubes::WeaponListParser>) -> CrfItemPurchaseProvider {
|
||||
CrfItemPurchaseProvider {
|
||||
factory: factory.to_owned(),
|
||||
weapon_order,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,5 +201,5 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(crf_earnings::robot_shop_user_earnings_provider())
|
||||
.add(crf_list_query::crf_item_list_query_provider(&init_ctx.factory))
|
||||
.add(crf_vehicle_data::crf_item_data_provider(&init_ctx.factory))
|
||||
.add(crf_purchase::crf_copy_to_bay_provider(&init_ctx.factory))
|
||||
.add(crf_purchase::crf_copy_to_bay_provider(&init_ctx.factory, init_ctx.parsers.weapon_order()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user