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

Implement basic battle arena functionality #32

This commit is contained in:
NG (Graham)
2025-08-30 21:36:01 -04:00
parent 1403a6e3d0
commit 7f9ed8bf35
41 changed files with 1836 additions and 327 deletions

View File

@@ -15,7 +15,6 @@ clap.workspace = true
polariton.workspace = true
oj_polariton_auth = { version = "*", path = "../polariton_auth" }
polariton_server.workspace = true
base64 = "0.22"
hex = "0.4"
serde.workspace = true
serde_json.workspace = true

View File

@@ -1,44 +0,0 @@
use polariton::operation::Typed;
use base64::{Engine, engine::general_purpose::STANDARD};
pub struct BattleArenaData {
pub protonium_health: i64,
pub respawn_time_seconds: i64,
pub heal_over_time_per_tower: Vec<u64>,
pub base_machine_map: Vec<u8>, // aka team base model, converted into base64
pub equalizer_model: Vec<u8>, // converted into base64
pub equalizer_health: i64,
pub equalizer_trigger_time_seconds: Vec<u64>,
pub equalizer_warning_seconds: i64,
pub equalizer_duration_seconds: Vec<u64>,
pub capture_time_seconds_per_player: Vec<i64>,
pub num_segments: i32,
pub heal_escalation_time_seconds: i64,
}
fn to_obj_arr_u(slice: &[u64]) -> Typed {
Typed::ObjArr(slice.iter().map(|x| Typed::Long(*x as i64)).collect::<Vec<Typed>>().into())
}
fn to_obj_arr_i(slice: &[i64]) -> Typed {
Typed::ObjArr(slice.iter().map(|x| Typed::Long(*x)).collect::<Vec<Typed>>().into())
}
impl BattleArenaData {
pub fn as_transmissible(&self) -> Typed {
Typed::HashMap(vec![
(Typed::Str("protoniumHealth".into()), Typed::Long(self.protonium_health)),
(Typed::Str("respawnTimeSeconds".into()), Typed::Long(self.respawn_time_seconds)),
(Typed::Str("healOverTimePerTower".into()), to_obj_arr_u(&self.heal_over_time_per_tower)),
(Typed::Str("baseMachineMap".into()), Typed::Str(STANDARD.encode(&self.base_machine_map).into())),
(Typed::Str("equalizerModel".into()), Typed::Str(STANDARD.encode(&self.equalizer_model).into())),
(Typed::Str("equalizerHealth".into()), Typed::Long(self.equalizer_health)),
(Typed::Str("equalizerTriggerTimeSeconds".into()), to_obj_arr_u(&self.equalizer_trigger_time_seconds)),
(Typed::Str("equalizerWarningSeconds".into()), Typed::Long(self.equalizer_warning_seconds)),
(Typed::Str("equalizerDurationSeconds".into()), to_obj_arr_u(&self.equalizer_duration_seconds)),
(Typed::Str("captureTimeSecondsPerPlayer".into()), to_obj_arr_i(&self.capture_time_seconds_per_player)),
(Typed::Str("numSegments".into()), Typed::Int(self.num_segments)),
(Typed::Str("healEscalationTimeSeconds".into()), Typed::Long(self.heal_escalation_time_seconds)),
].into())
}
}

View File

@@ -7,7 +7,7 @@ pub mod crf_config;
pub use oj_rc_core::data::weapon_list;
//pub use oj_rc_core::data::movement_list;
pub mod damage_boost;
pub mod battle_arena_config;
//pub mod battle_arena_config;
pub mod cpu_limits;
pub mod cosmetic_limits;
pub mod taunts_config;

View File

@@ -1,33 +1,38 @@
use polariton_server::operations::SimpleFunc;
use polariton::{operation::{Dict, ParameterTable, Typed}, serdes::TypePrefix};
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
use polariton::operation::ParameterTable;
use crate::data::battle_arena_config::*;
const CODE: u8 = 53;
const PARAM_KEY: u8 = 1;
pub(super) fn battle_arena_config_provider() -> SimpleFunc<53, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
pub(super) struct BattleArenaConfigurer {
factory: std::sync::Arc<oj_rc_core::factory::Factory>,
weapon_list: std::sync::Arc<oj_rc_core::cubes::WeaponListParser>,
cpu_counter: std::sync::Arc<oj_rc_core::cubes::CpuListParser>,
ba_conf: oj_rc_core::persist::config::BattleArenaResolver,
}
#[async_trait::async_trait]
impl <C: Send + 'static> SimpleOperation<C> for BattleArenaConfigurer {
type User = crate::UserTy;
const CODE: u8 = CODE;
async fn handle(&self, params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
let user_info = user.user()?;
let data = self.ba_conf.resolve_typed(user_info.as_ref().as_ref(), self.factory.as_ref(), &self.weapon_list, &self.cpu_counter).await?;
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Dict(Dict {
key_ty: TypePrefix::Str, // str
val_ty: TypePrefix::HashMap, // hashmap
items: vec![
(Typed::Str("BattleArenaSettings".into()), BattleArenaData {
protonium_health: 1_000,
respawn_time_seconds: 10,
heal_over_time_per_tower: vec![10, 10, 10, 10],
base_machine_map: Vec::default(),
equalizer_model: Vec::default(),
equalizer_health: 1_000_000,
equalizer_trigger_time_seconds: vec![10, 10, 10, 10, 10],
equalizer_warning_seconds: 10,
equalizer_duration_seconds: vec![20, 20, 20, 20, 20],
capture_time_seconds_per_player: vec![30, 20, 10, 5, 1],
num_segments: 4,
heal_escalation_time_seconds: 5,
}.as_transmissible())
],
}));
params.insert(PARAM_KEY, data);
Ok(params.into())
}
}
pub(super) fn battle_arena_config_provider<C: Send + 'static>(conf: &oj_rc_core::ConfigImpl, factory: &std::sync::Arc<oj_rc_core::factory::Factory>, weapon_list: std::sync::Arc<oj_rc_core::cubes::WeaponListParser>,
cpu_counter: std::sync::Arc<oj_rc_core::cubes::CpuListParser>) -> SimpleOpImpl<C, crate::UserTy, BattleArenaConfigurer> {
let ba_conf = <oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::ba_settings(conf);
SimpleOpImpl::new(BattleArenaConfigurer {
factory: factory.to_owned(),
weapon_list,
cpu_counter,
ba_conf
})
}

View File

@@ -125,7 +125,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
.add(movement_stats::movement_config_provider(&init_ctx.cubes))
.add(power_bar_stats::power_bar_provider(&init_ctx.cubes))
.add(damage_boost_stats::damage_boost_provider())
.add(battle_arena_config::battle_arena_config_provider())
.add(battle_arena_config::battle_arena_config_provider(&init_ctx.cubes, &init_ctx.factory, init_ctx.parsers.weapon_order(), init_ctx.parsers.cpu_counter()))
.add(cpu_limits_config::cpu_config_provider())
.add(cosmetic_config::cosmetic_limits_config_provider())
.add(taunts_config::taunts_config_provider())