1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Implement tech tree cube unlock

This commit is contained in:
NG (Graham)
2026-01-12 18:48:28 -05:00
parent 6bcd812738
commit 59b253dc52
7 changed files with 130 additions and 25 deletions

View File

@@ -105,6 +105,7 @@ mod crf_rate_vehicle;
mod crf_shift_vehicle;
mod crf_make_featured;
mod crf_unmake_featured;
mod tech_tree_unlock_cube;
use polariton_server::operations::OperationsHandler;
@@ -234,4 +235,5 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
.add(crf_make_featured::factory_featured_provider(&init_ctx.factory))
.add(crf_unmake_featured::factory_featured_provider(&init_ctx.factory))
.add(polariton_server::operations::Ack::<101, _>::default()) // RestoreCRFFeaturedRobot unused and also redundant???
.add(tech_tree_unlock_cube::tech_tree_cube_unlock_provider(&init_ctx.cubes))
}

View File

@@ -1,17 +1,19 @@
use polariton_server::operations::Immediate;
use oj_rc_core::ConfigProvider;
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
use polariton::operation::ParameterTable;
const PARAM_KEY: u8 = 210;
const CODE: u8 = 183;
pub(super) fn tech_tree_layout_provider(cubes: &oj_rc_core::ConfigImpl) -> Immediate<183, crate::UserTy> {
const NODES_PARAM_KEY: u8 = 210;
/*pub(super) fn tech_tree_layout_provider(cubes: &oj_rc_core::ConfigImpl) -> Immediate<183, crate::UserTy> {
Immediate::new(|| {
let mut params = std::collections::HashMap::with_capacity(2);
params.insert(PARAM_KEY, cubes.tech_tree_nodes(&vec![
params.insert(NODES_PARAM_KEY, cubes.tech_tree_nodes(&vec![
227205318,
227917916,
1931676396,
].into_iter().collect()));
/*params.insert(PARAM_KEY, Typed::Dict(Dict {
/*params.insert(NODES_PARAM_KEY, Typed::Dict(Dict {
key_ty: TypePrefix::Str, // str
val_ty: TypePrefix::HashMap, // hashmap
items: vec![
@@ -28,4 +30,29 @@ pub(super) fn tech_tree_layout_provider(cubes: &oj_rc_core::ConfigImpl) -> Immed
}));*/
params.into()
})
}*/
pub(super) struct TechTreeNoder {
nodes: oj_rc_core::persist::config::TechTreeNodeProvider,
}
#[async_trait::async_trait]
impl <C: Send + 'static> SimpleOperation<C> for TechTreeNoder {
type User = crate::UserTy;
const CODE: u8 = CODE;
async fn handle(&self, params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
let mut params = params.to_dict();
let user_info = user.user()?;
let unlocked = user_info.unlocked_parts().await;
let nodes = self.nodes.tech_tree_nodes(&unlocked.into_iter().collect());
params.insert(NODES_PARAM_KEY, nodes);
Ok(params.into())
}
}
pub(super) fn tech_tree_layout_provider<C: Send + 'static>(cubes: &oj_rc_core::ConfigImpl) -> SimpleOpImpl<C, crate::UserTy, TechTreeNoder> {
SimpleOpImpl::new(TechTreeNoder {
nodes: <oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::tech_tree_nodes(cubes),
})
}

View File

@@ -0,0 +1,41 @@
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
use polariton::operation::{ParameterTable, Typed};
const CODE: u8 = 184;
const CUBE_PARAM_KEY: u8 = 211; // str (hex); in
const NODES_PARAM_KEY: u8 = 210;
pub(super) struct TechTreeUnlocker {
cost_map: std::collections::HashMap<String, u32>,
nodes: oj_rc_core::persist::config::TechTreeNodeProvider,
}
#[async_trait::async_trait]
impl <C: Send + 'static> SimpleOperation<C> for TechTreeUnlocker {
type User = crate::UserTy;
const CODE: u8 = CODE;
async fn handle(&self, params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
let mut params = params.to_dict();
if let Some(Typed::Str(cube_hex)) = params.remove(&CUBE_PARAM_KEY) {
if let Some(cost) = self.cost_map.get(&cube_hex.string) {
let user_info = user.user()?;
let bytes = hex::decode(cube_hex.string).unwrap();
user_info.currency_debit(oj_rc_core::persist::user::CurrencyType::TechPoints, *cost as u64).await?;
user_info.unlock_parts(&[u32::from_be_bytes([bytes[0], bytes[1], bytes[2], bytes[3]])]).await?;
let unlocked = user_info.unlocked_parts().await;
let nodes = self.nodes.tech_tree_nodes(&unlocked.into_iter().collect());
params.insert(NODES_PARAM_KEY, nodes);
}
}
Ok(params.into())
}
}
pub(super) fn tech_tree_cube_unlock_provider<C: Send + 'static>(cubes: &oj_rc_core::ConfigImpl) -> SimpleOpImpl<C, crate::UserTy, TechTreeUnlocker> {
SimpleOpImpl::new(TechTreeUnlocker {
cost_map: <oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::tech_tree_costs(cubes),
nodes: <oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::tech_tree_nodes(cubes),
})
}