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

Add customisable game mode sequence (mp and sp still broken) #16

This commit is contained in:
NG (Graham)
2025-05-27 22:07:04 -04:00
parent 34b41eff9c
commit 9d9f8a73fc
10 changed files with 534 additions and 71 deletions

View File

@@ -1,38 +1,6 @@
#![allow(dead_code)]
#[repr(u8)]
#[derive(Copy, Clone)]
pub enum GameMode {
BattleArena = 0,
SuddenDeath = 1,
Pit = 2,
TestMode = 3,
SinglePlayer = 4,
TeamDeathmatch = 5,
Campaign = 6,
}
impl GameMode {
pub fn as_str(&self) -> &'static str {
match self {
GameMode::BattleArena => "BattleArena",
GameMode::SuddenDeath => "SuddenDeath",
GameMode::Pit => "Pit",
GameMode::TestMode => "TestMode",
GameMode::SinglePlayer => "SinglePlayerTDM",
GameMode::TeamDeathmatch => "TeamDeathmatch",
GameMode::Campaign => "Campaign",
}
}
}
#[repr(u8)]
#[derive(Copy, Clone)]
pub enum MapVisibility {
Good = 0,
Poor = 1,
Bad = 2, // VeryPoor
}
pub use rc_core::data::game_mode::GameMode;
#[repr(u8)]
#[derive(Copy, Clone)]

View File

@@ -1,7 +1,7 @@
use polariton_server::operations::SimpleFunc;
use polariton::{operation::{Arr, ParameterTable, Typed}, serdes::TypePrefix};
use polariton_server::operations::{Operation, OperationCode};
//use polariton::{operation::{Arr, ParameterTable, Typed}, serdes::TypePrefix};
use crate::data::custom_games::*;
const CODE: u8 = 24;
const MAP_NAMES_PARAM_KEY: u8 = 78;
const VISIBILITY_PARAM_KEY: u8 = 66;
@@ -20,38 +20,40 @@ RC_Planet_Mars_01_CTF
RC_Planet_Neptune_01_CTF
*/
pub(super) fn event_system_params_provider() -> SimpleFunc<24, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
pub struct GameEventsParamsProvider {
sequence: std::sync::Mutex<rc_core::persist::config::GameEventSequence>,
}
#[async_trait::async_trait]
impl Operation<()> for GameEventsParamsProvider {
type User = crate::UserTy;
async fn handle_async(&self, params: polariton::operation::ParameterTable<()>, _user: &Self::User) -> polariton::operation::OperationResponse<()> {
let mut params = params.to_dict();
params.insert(MAP_NAMES_PARAM_KEY, Typed::Arr(Arr {
ty: TypePrefix::Str, // str
items: vec![
Typed::Str("RC_Planet_Neptune_03_BA".into()),
Typed::Str("RC_Planet_Mars_02_BA".into()),
],
}));
params.insert(VISIBILITY_PARAM_KEY, Typed::Arr(Arr {
ty: TypePrefix::Int, // int
items: vec![
Typed::Int(MapVisibility::Good as _),
Typed::Int(MapVisibility::Bad as _),
],
}));
params.insert(MODE_PARAM_KEY, Typed::Arr(Arr {
ty: TypePrefix::Int, // int
items: vec![
Typed::Int(GameMode::SinglePlayer as _),
Typed::Int(GameMode::BattleArena as _),
],
}));
params.insert(AUTO_HEAL_PARAM_KEY, Typed::Arr(Arr {
ty: TypePrefix::Bool, // bool
items: vec![
Typed::Bool(true.into()),
Typed::Bool(false.into()),
],
}));
params.insert(REMAINING_TICKS_PARAM_KEY, Typed::Long(24 * 60 * 60 * 1_000_000 * 10 /* 24 hours in ticks (100ns units) */));
Ok(params.into())
})
let current_mode = self.sequence.lock().unwrap().now();
params.insert(MAP_NAMES_PARAM_KEY, current_mode.maps);
params.insert(VISIBILITY_PARAM_KEY, current_mode.visibilities);
params.insert(MODE_PARAM_KEY, current_mode.modes);
params.insert(AUTO_HEAL_PARAM_KEY, current_mode.auto_heals);
params.insert(REMAINING_TICKS_PARAM_KEY, current_mode.remaining_ticks);
polariton::operation::OperationResponse {
code: Self::op_code(),
return_code: 0,
message: polariton::operation::Typed::Null,
params: params.into(),
}
}
}
impl OperationCode for GameEventsParamsProvider {
fn op_code() -> u8 {
CODE
}
}
pub(super) fn event_system_params_provider(conf: &rc_core::ConfigImpl) -> GameEventsParamsProvider {
let game_seq = <rc_core::ConfigImpl as rc_core::ConfigProvider<()>>::gamemode_events(conf);
GameEventsParamsProvider {
sequence: std::sync::Mutex::new(game_seq),
}
}

View File

@@ -144,7 +144,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
.add(custom_game_session::get_custom_session_provider())
.add(user_xp::get_user_xp_provider())
.add(garage_upgrades::garage_upgrades_provider(&init_ctx.cubes))
.add(game_event_params::event_system_params_provider())
.add(game_event_params::event_system_params_provider(&init_ctx.cubes))
.add(garage_bay_uuid::garage_id_provider())
.add(tech_tree_data::tech_tree_layout_provider(&init_ctx.cubes))
.add(item_shop_bundles::item_bundle_provider())