mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add upgrade and dismantle vehicle slot functionality for #14
This commit is contained in:
35
rc_services_room/src/operations/garage_slot_dismantle.rs
Normal file
35
rc_services_room/src/operations/garage_slot_dismantle.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const CODE: u8 = 42;
|
||||
|
||||
const SLOT_PARAM_KEY: u8 = 43;
|
||||
|
||||
pub(super) fn garage_slot_dismantler() -> GarageSlotDismantler {
|
||||
GarageSlotDismantler
|
||||
}
|
||||
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Int(slot)) = params.remove(&SLOT_PARAM_KEY) {
|
||||
let user_info = user.user()?;
|
||||
user_info.new_slot(Some(slot)).await?;
|
||||
}
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub struct GarageSlotDismantler;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for GarageSlotDismantler {
|
||||
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).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for GarageSlotDismantler {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
36
rc_services_room/src/operations/garage_slot_upgrade.rs
Normal file
36
rc_services_room/src/operations/garage_slot_upgrade.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const CODE: u8 = 39;
|
||||
|
||||
const CPU_INCREMENT_PARAM_KEY: u8 = 7;
|
||||
const SUCCESS_PARAM_KEY: u8 = 39;
|
||||
|
||||
pub(super) fn garage_slot_upgrage_provider() -> GarageSlotUpgrade {
|
||||
GarageSlotUpgrade
|
||||
}
|
||||
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Int(increments)) = params.remove(&CPU_INCREMENT_PARAM_KEY) {
|
||||
let user_info = user.user()?;
|
||||
params.insert(SUCCESS_PARAM_KEY, user_info.upgrade_slot(increments).await?);
|
||||
}
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub struct GarageSlotUpgrade;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for GarageSlotUpgrade {
|
||||
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).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for GarageSlotUpgrade {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ pub(super) fn garage_slot_order_provider() -> GarageSlotsOrderProvider {
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Arr(order)) = params.remove(&SLOT_ORDER_PARAM_KEY) {
|
||||
log::info!("Slot order is {}", order);
|
||||
//log::info!("Slot order is {}", order);
|
||||
let mut order_i32 = Vec::with_capacity(order.items.len());
|
||||
for item in order.items.iter() {
|
||||
if let Typed::Int(item) = item {
|
||||
|
||||
@@ -1,25 +1,39 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton::{operation::{Dict, ParameterTable, Typed}, serdes::TypePrefix};
|
||||
use polariton::operation::{ParameterTable, OperationResponse};
|
||||
use rc_core::ConfigProvider;
|
||||
|
||||
const CODE: u8 = 1;
|
||||
|
||||
const PARAM_KEY: u8 = 1;
|
||||
|
||||
pub(super) fn garage_upgrades_provider() -> SimpleFunc<1, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, _| {
|
||||
pub(super) fn garage_upgrades_provider(conf: &rc_core::ConfigImpl) -> GarageUpgradesProvider {
|
||||
GarageUpgradesProvider {
|
||||
upgrades: <rc_core::ConfigImpl as ConfigProvider<()>>::garage_upgrades(conf),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GarageUpgradesProvider {
|
||||
upgrades: rc_core::persist::config::GarageUpgrades,
|
||||
}
|
||||
|
||||
impl GarageUpgradesProvider {
|
||||
async fn do_handling(&self, params: ParameterTable) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
params.insert(PARAM_KEY, Typed::HashMap(vec![
|
||||
(Typed::Str("cpuIncreaseCost".into()), Typed::Dict(Dict {
|
||||
key_ty: TypePrefix::Int, // int
|
||||
val_ty: TypePrefix::Int, // int
|
||||
items: vec![
|
||||
// (CPU limit, upgrade cost)
|
||||
(Typed::Int(100), Typed::Int(100)),
|
||||
(Typed::Int(200), Typed::Int(200)),
|
||||
(Typed::Int(1_000), Typed::Int(1_000)),
|
||||
(Typed::Int(2_000), Typed::Int(2_000)), // max regular bot CPU
|
||||
(Typed::Int(10_000), Typed::Int(10_000)), // max mega bot cpu
|
||||
],
|
||||
}))
|
||||
].into()));
|
||||
params.insert(PARAM_KEY, self.upgrades.slot_upgrades());
|
||||
Ok(params.into())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for GarageUpgradesProvider {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, _user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(self.do_handling(params).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for GarageUpgradesProvider {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,8 @@ mod garage_slot_limit;
|
||||
mod garage_slot_add;
|
||||
mod garage_slots_order;
|
||||
mod garage_slot_select;
|
||||
mod garage_slot_dismantle;
|
||||
mod garage_slot_upgrade;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
@@ -132,7 +134,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(avatar_info::get_avatar_provider())
|
||||
.add(custom_game_session::get_custom_session_provider())
|
||||
.add(user_xp::get_user_xp_provider())
|
||||
.add(garage_upgrades::garage_upgrades_provider())
|
||||
.add(garage_upgrades::garage_upgrades_provider(&init_ctx.cubes))
|
||||
.add(game_event_params::event_system_params_provider())
|
||||
.add(garage_bay_uuid::garage_id_provider())
|
||||
.add(tech_tree_data::tech_tree_layout_provider(&init_ctx.cubes))
|
||||
@@ -190,4 +192,6 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(garage_slot_add::garage_slot_add_provider())
|
||||
.add(garage_slots_order::garage_slot_order_provider())
|
||||
.add(garage_slot_select::garage_slot_selector())
|
||||
.add(garage_slot_dismantle::garage_slot_dismantler())
|
||||
.add(garage_slot_upgrade::garage_slot_upgrage_provider())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user