From a904423a832ce254505ac7cff5dbd592f7cc5270 Mon Sep 17 00:00:00 2001 From: "NG (Graham)" Date: Tue, 22 Jul 2025 22:39:38 -0400 Subject: [PATCH] Use elimination config from file instead of hardcoded #30 --- rc_core/src/persist/config/cubes_json.rs | 4 ++++ rc_core/src/persist/config/traits.rs | 1 + rc_multiplayer/src/main.rs | 2 +- rc_multiplayer/src/matches/aggregate.rs | 9 +++++++-- rc_multiplayer/src/matches/modes/elimination.rs | 16 ++++++++++------ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/rc_core/src/persist/config/cubes_json.rs b/rc_core/src/persist/config/cubes_json.rs index 08e9bff..d290554 100644 --- a/rc_core/src/persist/config/cubes_json.rs +++ b/rc_core/src/persist/config/cubes_json.rs @@ -304,6 +304,10 @@ impl super::ConfigProvider for CubeConfig { } } + fn gamemodes(&self) -> crate::data::game_mode::GameModeConfigs { + self.battle.games.clone().into() + } + fn singleplayer_details(&self) -> super::SingleplayerConfig { self.battle.singleplayer.into_singleplayer_conf() } diff --git a/rc_core/src/persist/config/traits.rs b/rc_core/src/persist/config/traits.rs index 58ac340..b99bde0 100644 --- a/rc_core/src/persist/config/traits.rs +++ b/rc_core/src/persist/config/traits.rs @@ -25,6 +25,7 @@ pub trait ConfigProvider { fn cubes(&self) -> &'_ std::collections::HashMap; fn chat_system_config(&self) -> ChatSystemConfig; fn gamemode_events(&self) -> GameEventSequence; + fn gamemodes(&self) -> crate::data::game_mode::GameModeConfigs; // FIXME fn singleplayer_details(&self) -> SingleplayerConfig; fn players_per_game(&self) -> usize; fn is_multiplayer_enabled(&self) -> bool; diff --git a/rc_multiplayer/src/main.rs b/rc_multiplayer/src/main.rs index e28663c..c5063da 100644 --- a/rc_multiplayer/src/main.rs +++ b/rc_multiplayer/src/main.rs @@ -26,7 +26,7 @@ async fn main() -> std::io::Result<()> { let users = std::sync::Arc::new(oj_rc_core::persist::user::UserImpl::load(&args.data, &config).await.expect("Bad user data")); users.multiplayer_init().await.expect("Multiplayer init task failed"); let parsers = oj_rc_core::cubes::CubeParsers::new(&config); - let matches = matches::GameMatches::new(); + let matches = matches::GameMatches::new(&config); let matches_chann = matches.spawn(); let init_ctx = InitConfig { diff --git a/rc_multiplayer/src/matches/aggregate.rs b/rc_multiplayer/src/matches/aggregate.rs index 37a54a2..151be6d 100644 --- a/rc_multiplayer/src/matches/aggregate.rs +++ b/rc_multiplayer/src/matches/aggregate.rs @@ -1,13 +1,15 @@ pub struct GameMatches { matches: std::collections::HashMap>, routing: std::collections::HashMap, // user id to game guid + mode_configs: oj_rc_core::data::game_mode::GameModeConfigs, } impl GameMatches { - pub fn new() -> Self { + pub fn new(conf: &oj_rc_core::persist::config::ConfigImpl) -> Self { Self { matches: std::collections::HashMap::new(), routing: std::collections::HashMap::new(), + mode_configs: >::gamemodes(conf), } } @@ -19,7 +21,10 @@ impl GameMatches { async fn start_new_match_engine(&self, _user: &Box, guid: &str) -> tokio::sync::mpsc::Sender { // TODO figure out gamemode and act accordingly - let engine = super::GenericGamemodeEngine::new(guid.to_owned(), super::modes::EliminationLogic::new()); + let engine = super::GenericGamemodeEngine::new( + guid.to_owned(), + super::modes::EliminationLogic::new(&self.mode_configs.elimination) + ); engine.spawn() } diff --git a/rc_multiplayer/src/matches/modes/elimination.rs b/rc_multiplayer/src/matches/modes/elimination.rs index aa74d05..45f92a4 100644 --- a/rc_multiplayer/src/matches/modes/elimination.rs +++ b/rc_multiplayer/src/matches/modes/elimination.rs @@ -49,19 +49,23 @@ impl PlayerTracker { pub struct EliminationLogic { tracked: PlayerTracker, game_duration: std::time::Duration, + respawn_full_heal_duration: f32, + respawn_heal_duration: f32, game_end: std::sync::atomic::AtomicI64, timer_task: tokio::sync::Mutex>>, } impl EliminationLogic { - pub fn new() -> Self { - let dur = std::time::Duration::from_secs(300); + pub fn new(config: &oj_rc_core::data::game_mode::GameModeConfig) -> Self { + let dur = std::time::Duration::from_secs((config.game_time_minutes as u64) * 60); let fake_end = (chrono::Utc::now() + dur).timestamp(); Self { tracked: PlayerTracker { alive: tokio::sync::Mutex::new(std::collections::HashMap::new()), }, game_duration: dur, + respawn_full_heal_duration: config.respawn_full_heal_duration, + respawn_heal_duration: config.respawn_heal_duration, game_end: std::sync::atomic::AtomicI64::new(fake_end), timer_task: tokio::sync::Mutex::new(None), } @@ -186,15 +190,15 @@ impl CustomGameLogic for EliminationLogic { crate::matches::RlnlPacket { event: rlnl::event_code::NetworkEvent::GameModeSettings, property: literustlib::packet::Property::ReliableOrdered, - data: Box::new(rlnl::events::sync::UpdateGameModeSettings { // FIXME use value from config - respawn_heal_duration: 10.0, - respawn_full_heal_duration: 10.0, + data: Box::new(rlnl::events::sync::UpdateGameModeSettings { + respawn_heal_duration: self.respawn_heal_duration, + respawn_full_heal_duration: self.respawn_full_heal_duration, }), }, crate::matches::RlnlPacket { event: rlnl::event_code::NetworkEvent::CurrentGameTime, property: literustlib::packet::Property::ReliableOrdered, - data: Box::new(rlnl::events::GameTime(self.game_duration.as_millis() as f32 / 1000.0)), // FIXME use value from config + data: Box::new(rlnl::events::GameTime(self.game_duration.as_millis() as f32 / 1000.0)), }, ] }