mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Move common components to shared lib
This commit is contained in:
202
rc_core/src/persist/combat.rs
Normal file
202
rc_core/src/persist/combat.rs
Normal file
@@ -0,0 +1,202 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct BattleConfig {
|
||||
pub regen: AutoRegenHealth,
|
||||
pub votes: HashMap<Vote, Vec<VoteThreshold>>,
|
||||
#[serde(default = "default_game_modes")]
|
||||
pub games: GameModes,
|
||||
#[serde(default = "default_campaigns")]
|
||||
pub singleplayer: super::Campaigns,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct AutoRegenHealth {
|
||||
pub wait_for_heal_s: f32,
|
||||
pub wait_full_heal_s: f32,
|
||||
pub sound_start_s: f32,
|
||||
pub auto_heal: bool,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::auto_regen::AutoRegenHealthConfig> for AutoRegenHealth {
|
||||
fn into(self) -> crate::data::auto_regen::AutoRegenHealthConfig {
|
||||
crate::data::auto_regen::AutoRegenHealthConfig {
|
||||
seconds_to_wait_for_heal: self.wait_for_heal_s,
|
||||
seconds_to_full_heal: self.wait_full_heal_s,
|
||||
threshold_to_start_sound: self.sound_start_s,
|
||||
enable_auto_heal: self.auto_heal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct VoteThreshold {
|
||||
pub name: String,
|
||||
pub localised_name: String,
|
||||
pub color: String,
|
||||
pub votes_required: i32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::voting::VoteThresholdData> for VoteThreshold {
|
||||
fn into(self) -> crate::data::voting::VoteThresholdData {
|
||||
crate::data::voting::VoteThresholdData {
|
||||
name: self.name,
|
||||
localised_name: self.localised_name,
|
||||
color: self.color,
|
||||
votes_required: self.votes_required,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Vote {
|
||||
BestPlayed,
|
||||
BestLooking,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::voting::Vote> for Vote {
|
||||
fn into(self) -> crate::data::voting::Vote {
|
||||
match self {
|
||||
Self::BestPlayed => crate::data::voting::Vote::BestPlayed,
|
||||
Self::BestLooking => crate::data::voting::Vote::BestLooking,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Copy)]
|
||||
pub struct GameMode {
|
||||
pub respawn_heal_duration: f32,
|
||||
pub respawn_full_heal_duration: f32,
|
||||
pub kill_limit: i32,
|
||||
pub game_time_m: i32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::game_mode::GameModeConfig> for GameMode {
|
||||
fn into(self) -> crate::data::game_mode::GameModeConfig {
|
||||
crate::data::game_mode::GameModeConfig {
|
||||
respawn_heal_duration: self.respawn_heal_duration,
|
||||
respawn_full_heal_duration: self.respawn_full_heal_duration,
|
||||
kill_limit: self.kill_limit,
|
||||
game_time_minutes: self.game_time_m,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Copy)]
|
||||
pub struct GameModes {
|
||||
pub battle_arena: GameMode,
|
||||
pub elimination: GameMode,
|
||||
pub pit: GameMode,
|
||||
pub team_deathmatch: GameMode,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::game_mode::GameModeConfigs> for GameModes {
|
||||
fn into(self) -> crate::data::game_mode::GameModeConfigs {
|
||||
crate::data::game_mode::GameModeConfigs {
|
||||
battle_arena: self.battle_arena.into(),
|
||||
elimination: self.elimination.into(),
|
||||
the_pit: self.pit.into(),
|
||||
team_deathmatch: self.team_deathmatch.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_game_modes() -> GameModes {
|
||||
GameModes {
|
||||
battle_arena: GameMode {
|
||||
respawn_heal_duration: 10.0,
|
||||
respawn_full_heal_duration: 10.0,
|
||||
kill_limit: 0,
|
||||
game_time_m: 20,
|
||||
},
|
||||
elimination: GameMode {
|
||||
respawn_heal_duration: 10.0,
|
||||
respawn_full_heal_duration: 10.0,
|
||||
kill_limit: 10,
|
||||
game_time_m: 10,
|
||||
},
|
||||
pit: GameMode {
|
||||
respawn_heal_duration: 20.0,
|
||||
respawn_full_heal_duration: 20.0,
|
||||
kill_limit: 15,
|
||||
game_time_m: 15,
|
||||
},
|
||||
team_deathmatch: GameMode {
|
||||
respawn_heal_duration: 10.0,
|
||||
respawn_full_heal_duration: 10.0,
|
||||
kill_limit: 10,
|
||||
game_time_m: 10,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn default_campaigns() -> super::Campaigns {
|
||||
super::Campaigns {
|
||||
campaigns: vec![
|
||||
super::Campaign {
|
||||
id: "strCampaignModeBattle".to_owned(),
|
||||
excluded_cubes: Vec::default(),
|
||||
categories: vec![super::ItemCategory::Wheel],
|
||||
min_cpu: 0,
|
||||
max_cpu: 2_000,
|
||||
name: "strCampaignModeBattle".to_owned(),
|
||||
description: "strCampaignsDesc".to_owned(),
|
||||
image: "RE_singleplayer_campaign_image_asset_TODO".to_owned(),
|
||||
rules: Vec::default(),
|
||||
parameters: Vec::default(),
|
||||
difficulties: vec![
|
||||
super::CampaignDifficulty {
|
||||
level: 0,
|
||||
lives: 5,
|
||||
auto_heal: true,
|
||||
single_wave_bonus: 1_000,
|
||||
initial_health_boost: 0.0,
|
||||
health_boost_wave_increase: 0.0,
|
||||
initial_damage_boost: 0.0,
|
||||
damage_boost_wave_increase: 0.0,
|
||||
}
|
||||
],
|
||||
completed: vec![
|
||||
super::CampaignCompletion {
|
||||
wave: 0,
|
||||
difficulty: false,
|
||||
}
|
||||
],
|
||||
map: "RC_Planet_Neptune_03_BA".to_owned(),
|
||||
campaign_type: super::CampaignType::Elimination,
|
||||
waves: vec![
|
||||
super::Wave {
|
||||
player_spawn_location: 0,
|
||||
robots_in_wave: vec![
|
||||
super::WaveRobot {
|
||||
name: "strCampaignAnimalName".to_owned(),
|
||||
weapon: "strT5PlasmaGoldenName".to_owned(),
|
||||
movement: "strT5SteeringWheelGoldenName".to_owned(),
|
||||
rank: "strT0".to_owned(),
|
||||
count: 5,
|
||||
robot_data: super::VALID_ROBOT.into(),
|
||||
colour_data: super::VALID_COLOUR.into(),
|
||||
time_to_spawn: 1,
|
||||
kills_to_spawn: 0,
|
||||
time_to_despawn: 60,
|
||||
kills_to_despawn: 1,
|
||||
initial_robot_amount: 0,
|
||||
periodic_robot_amount: 3,
|
||||
spawn_interval: 1,
|
||||
min_robot_amount: 1,
|
||||
max_robot_amount: 5,
|
||||
is_boss: false,
|
||||
is_kill_requirement: true,
|
||||
}
|
||||
],
|
||||
kill_target: 1,
|
||||
time_min: 1,
|
||||
time_max: 1 * 60,
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
234
rc_core/src/persist/config/cubes_json.rs
Normal file
234
rc_core/src/persist/config/cubes_json.rs
Normal file
@@ -0,0 +1,234 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use polariton::operation::{Typed, Dict};
|
||||
use polariton::serdes::TypePrefix;
|
||||
|
||||
use super::super::{MovementCategoryData, MovementData, Cube, ItemCategory, ItemTier, BattleConfig};
|
||||
|
||||
const CUBE_CONFIG_FILENAME: &str = "config.json";
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct CubeConfig {
|
||||
cubes: HashMap<String, Cube>,
|
||||
movement: HashMap<ItemCategory, MovementCategoryData>,
|
||||
lerp_value: f32,
|
||||
battle: BattleConfig,
|
||||
}
|
||||
|
||||
impl CubeConfig {
|
||||
pub fn load(root: impl AsRef<std::path::Path>) -> std::io::Result<Self> {
|
||||
let file = std::fs::File::open(root.as_ref().join(CUBE_CONFIG_FILENAME))?;
|
||||
let buffered = std::io::BufReader::new(file);
|
||||
let result = serde_json::from_reader(buffered)?;
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
impl <C: Clone> super::ConfigProvider<C> for CubeConfig {
|
||||
fn cube_list(&self) -> Typed<C> {
|
||||
Typed::Dict(Dict {
|
||||
key_ty: TypePrefix::Str,
|
||||
val_ty: TypePrefix::HashMap,
|
||||
items: self.cubes.values().map(|cube| {
|
||||
let cube_d: crate::data::cube_list::CubeInfo<C> = cube.info.clone().into();
|
||||
cube_d.as_transmissible_key_val(cube.id)
|
||||
}).collect(),
|
||||
})
|
||||
}
|
||||
|
||||
fn movement_list(&self) -> Typed<C> {
|
||||
let mut movements_stats = HashMap::<ItemCategory, HashMap<ItemTier, MovementData>>::new();
|
||||
for cube in self.cubes.values() {
|
||||
if let Some(movement_data) = &cube.movement {
|
||||
let category_map = if let Some(x) = movements_stats.get_mut(&cube.info.category) {
|
||||
x
|
||||
} else {
|
||||
movements_stats.insert(cube.info.category, HashMap::new());
|
||||
movements_stats.get_mut(&cube.info.category).unwrap()
|
||||
};
|
||||
category_map.insert(cube.info.size, movement_data.to_owned());
|
||||
}
|
||||
}
|
||||
let mut movement_cat_stats = Vec::with_capacity(self.movement.len());
|
||||
for (k, v) in self.movement.iter() {
|
||||
let stats: Vec<_> = if let Some(stats) = movements_stats.get(&k) {
|
||||
stats.iter().map(|(k, v)| (k.to_owned(), v.to_owned())).collect()
|
||||
} else {
|
||||
Vec::default()
|
||||
};
|
||||
let key: crate::data::weapon_list::ItemCategory = k.to_owned().into();
|
||||
let key_typed = Typed::<C>::Str(key.as_str().into());
|
||||
|
||||
let value_data = v.to_owned().into_data(stats);
|
||||
movement_cat_stats.push((key_typed, value_data.as_transmissible()));
|
||||
}
|
||||
Typed::Dict(Dict {
|
||||
key_ty: TypePrefix::Str,
|
||||
val_ty: TypePrefix::HashMap,
|
||||
items: vec![
|
||||
(Typed::Str("Global".into()), Typed::HashMap(vec![
|
||||
(Typed::Str("lerpValue".into()), Typed::Float(self.lerp_value)),
|
||||
].into())),
|
||||
(Typed::Str("Movements".into()), Typed::HashMap(movement_cat_stats.into())),
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
fn weapon_list(&self) -> Typed<C> {
|
||||
let mut weapon_stats = HashMap::new();
|
||||
for cube in self.cubes.values() {
|
||||
if let Some(weapon_data) = &cube.weapon {
|
||||
let category_map = if let Some(x) = weapon_stats.get_mut(&cube.info.category) {
|
||||
x
|
||||
} else {
|
||||
weapon_stats.insert(cube.info.category, HashMap::new());
|
||||
weapon_stats.get_mut(&cube.info.category).unwrap()
|
||||
};
|
||||
category_map.insert(cube.info.size, weapon_data.to_owned());
|
||||
}
|
||||
}
|
||||
let mut weapons_vec: Vec<(Typed<C>, Typed<C>)> = Vec::with_capacity(weapon_stats.len());
|
||||
for (k, v) in weapon_stats {
|
||||
let cat_data: crate::data::weapon_list::ItemCategory = k.into();
|
||||
let mut tiers_vec = Vec::with_capacity(v.len());
|
||||
for (k, v) in v {
|
||||
let tier_data: crate::data::cube_list::ItemTier = k.into();
|
||||
let val_data: crate::data::weapon_list::WeaponData = v.into();
|
||||
tiers_vec.push((Typed::Str(tier_data.as_str().into()), val_data.as_transmissible()));
|
||||
}
|
||||
weapons_vec.push((Typed::Str(cat_data.as_str().into()), Typed::HashMap(tiers_vec.into())));
|
||||
}
|
||||
Typed::Dict(Dict {
|
||||
key_ty: TypePrefix::Str,
|
||||
val_ty: TypePrefix::HashMap,
|
||||
items: weapons_vec,
|
||||
})
|
||||
}
|
||||
|
||||
fn weapon_upgrade_list(&self) -> Typed<C> {
|
||||
let mut seen_keys = std::collections::HashSet::new();
|
||||
let mut weapon_upgrades = Vec::new();
|
||||
for cube in self.cubes.values() {
|
||||
if let Some(weapon_up) = &cube.weapon_upgrade {
|
||||
let key = (cube.info.category, cube.info.size);
|
||||
if seen_keys.contains(&key) {
|
||||
log::warn!("Weapon upgrade info for {:?} already exists, skipping", key);
|
||||
} else {
|
||||
seen_keys.insert(key);
|
||||
let weapon_upgrade_data = weapon_up.to_owned().into_data(cube.info.size, cube.info.category);
|
||||
weapon_upgrades.push(weapon_upgrade_data.as_transmissible());
|
||||
}
|
||||
}
|
||||
}
|
||||
Typed::ObjArr(weapon_upgrades.into())
|
||||
}
|
||||
|
||||
fn weapon_keys(&self) -> Typed<C> {
|
||||
let mut seen_keys = std::collections::HashSet::new();
|
||||
for cube in self.cubes.values() {
|
||||
if cube.weapon.is_some() {
|
||||
let key = crate::data::cube_list::item_key(cube.info.category.into(), cube.info.size.into());
|
||||
seen_keys.insert(key);
|
||||
}
|
||||
}
|
||||
let keys_vec: Vec<i32> = seen_keys.into_iter().collect();
|
||||
Typed::IntArr(keys_vec.into())
|
||||
}
|
||||
|
||||
fn tech_tree_nodes(&self, unlocked_cubes: &std::collections::HashSet<u32>) -> Typed<C> {
|
||||
let mut seen_cubes = std::collections::HashSet::with_capacity(self.cubes.len());
|
||||
let mut needed_cubes = std::collections::HashSet::with_capacity(self.cubes.len());
|
||||
let mut typed_nodes = Vec::new();
|
||||
for cube in self.cubes.values() {
|
||||
if let Some(tree_data) = &cube.tree {
|
||||
let is_unlocked = unlocked_cubes.contains(&cube.id);
|
||||
let is_unlockable = tree_data.requires.iter().all(|id| unlocked_cubes.contains(id));
|
||||
tree_data.neighbours.iter().for_each(|id| { needed_cubes.insert(*id); });
|
||||
seen_cubes.insert(cube.id);
|
||||
let node_data = tree_data.to_owned().into_data(cube.id, is_unlocked, is_unlockable);
|
||||
typed_nodes.push(node_data.as_transmissible_key_val());
|
||||
}
|
||||
}
|
||||
for needed_cube_id in needed_cubes {
|
||||
if !seen_cubes.contains(&needed_cube_id) {
|
||||
log::warn!("Tech tree needs cube {} but it doesn't have tree info", needed_cube_id);
|
||||
}
|
||||
}
|
||||
Typed::Dict(Dict {
|
||||
key_ty: TypePrefix::Str,
|
||||
val_ty: TypePrefix::HashMap,
|
||||
items: typed_nodes,
|
||||
})
|
||||
}
|
||||
|
||||
fn ids(&self) -> Vec<u32> {
|
||||
self.cubes.values().map(|cube| cube.id).collect()
|
||||
}
|
||||
|
||||
fn regen_config(&self) -> Typed<C> {
|
||||
let regen_data: crate::data::auto_regen::AutoRegenHealthConfig = self.battle.regen.clone().into();
|
||||
regen_data.as_transmissible()
|
||||
}
|
||||
|
||||
fn after_battle_vote_config(&self) -> Typed<C> {
|
||||
let mut vote_data = Vec::with_capacity(self.battle.votes.len()); // probably len() == 2
|
||||
for (key, val) in self.battle.votes.iter() {
|
||||
let key_data: crate::data::voting::Vote = key.to_owned().into();
|
||||
let mut val_data = Vec::with_capacity(val.len());
|
||||
for item in val {
|
||||
let vote_data: crate::data::voting::VoteThresholdData = item.to_owned().into();
|
||||
val_data.push(vote_data.as_transmissible());
|
||||
}
|
||||
vote_data.push((Typed::Str(key_data.as_str().into()), Typed::ObjArr(val_data.into())));
|
||||
}
|
||||
Typed::Dict(Dict {
|
||||
key_ty: TypePrefix::Str,
|
||||
val_ty: TypePrefix::Any,
|
||||
items: vote_data,
|
||||
})
|
||||
}
|
||||
|
||||
fn game_mode_config(&self) -> Typed<C> {
|
||||
let game_mode_data: crate::data::game_mode::GameModeConfigs = self.battle.games.into();
|
||||
game_mode_data.as_transmissible()
|
||||
}
|
||||
|
||||
fn campaigns_parameters(&self) -> Typed<C> {
|
||||
self.battle.singleplayer.clone().into_campaign_params().as_transmissible()
|
||||
}
|
||||
|
||||
fn campaign_waves(&self) -> Typed<C> {
|
||||
self.battle.singleplayer.clone().into_waves().as_transmissible()
|
||||
}
|
||||
|
||||
fn campaign_version(&self) -> Typed<C> {
|
||||
let mut locked_map = std::collections::HashMap::with_capacity(self.battle.singleplayer.campaigns.len());
|
||||
for campaign in self.battle.singleplayer.campaigns.iter() {
|
||||
locked_map.insert(campaign.id.clone(), true);
|
||||
}
|
||||
crate::data::campaign::GameModeVersionParameters {
|
||||
current_version: 0,
|
||||
is_locked: locked_map,
|
||||
}.as_transmissible()
|
||||
}
|
||||
|
||||
fn campaign_details(&self) -> super::CompleteCampaignProvider {
|
||||
let mut map = std::collections::HashMap::with_capacity(self.battle.singleplayer.campaigns.len());
|
||||
for campaign in self.battle.singleplayer.campaigns.iter() {
|
||||
//let waves_data: Vec<crate::data::campaign::CompleteWaveData> = campaign.waves.iter().map(|x| x.clone().into()).collect();
|
||||
let mut difficulty_map = std::collections::HashMap::with_capacity(campaign.difficulties.len());
|
||||
for difficulty in campaign.difficulties.iter() {
|
||||
let difficulty_data: crate::data::campaign::CampaignDifficultyData = difficulty.clone().into();
|
||||
let complete_campaign = crate::data::campaign::CampaignWavesDifficultyData {
|
||||
difficulty: difficulty_data,
|
||||
waves: campaign.waves.iter().map(|x| x.clone().into()).collect(),
|
||||
};
|
||||
difficulty_map.insert(difficulty.level, complete_campaign);
|
||||
}
|
||||
map.insert(campaign.id.clone(), difficulty_map);
|
||||
}
|
||||
super::CompleteCampaignProvider::new(map)
|
||||
}
|
||||
}
|
||||
13
rc_core/src/persist/config/mod.rs
Normal file
13
rc_core/src/persist/config/mod.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
mod cubes_json;
|
||||
pub use cubes_json::CubeConfig;
|
||||
|
||||
mod traits;
|
||||
pub use traits::{ConfigProvider, CompleteCampaignProvider};
|
||||
|
||||
pub type ConfigImpl = CubeConfig;
|
||||
|
||||
fn __must_impl<T: ConfigProvider<()>>() {}
|
||||
|
||||
fn __test_impl() {
|
||||
__must_impl::<ConfigImpl>();
|
||||
}
|
||||
42
rc_core/src/persist/config/traits.rs
Normal file
42
rc_core/src/persist/config/traits.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use polariton::operation::Typed;
|
||||
|
||||
pub trait ConfigProvider<C> {
|
||||
fn cube_list(&self) -> Typed<C>;
|
||||
fn movement_list(&self) -> Typed<C>;
|
||||
fn weapon_list(&self) -> Typed<C>;
|
||||
fn weapon_upgrade_list(&self) -> Typed<C>;
|
||||
fn weapon_keys(&self) -> Typed<C>;
|
||||
fn tech_tree_nodes(&self, unlocked_cubes: &std::collections::HashSet<u32>) -> Typed<C>;
|
||||
fn ids(&self) -> Vec<u32>;
|
||||
fn regen_config(&self) -> Typed<C>;
|
||||
fn after_battle_vote_config(&self) -> Typed<C>;
|
||||
fn game_mode_config(&self) -> Typed<C>;
|
||||
fn campaigns_parameters(&self) -> Typed<C>;
|
||||
fn campaign_waves(&self) -> Typed<C>;
|
||||
fn campaign_version(&self) -> Typed<C>;
|
||||
fn campaign_details(&self) -> CompleteCampaignProvider;
|
||||
}
|
||||
|
||||
pub struct CompleteCampaignProvider {
|
||||
map: std::collections::HashMap<String, std::collections::HashMap<i32, crate::data::campaign::CampaignWavesDifficultyData>>,
|
||||
}
|
||||
|
||||
impl CompleteCampaignProvider {
|
||||
pub fn new(map: std::collections::HashMap<String, std::collections::HashMap<i32, crate::data::campaign::CampaignWavesDifficultyData>>) -> Self {
|
||||
Self { map }
|
||||
}
|
||||
|
||||
pub fn get<C>(&self, id: &str, difficulty: &i32) -> Result<Typed<C>, i16> {
|
||||
if let Some(campaign) = self.map.get(id) {
|
||||
if let Some(details) = campaign.get(difficulty) {
|
||||
Ok(details.as_transmissible())
|
||||
} else {
|
||||
log::warn!("Couldn't find difficulty {} in campaign `{}`", difficulty, id);
|
||||
Err(crate::data::error_codes::WebServicesError::DatabaseError as i16)
|
||||
}
|
||||
} else {
|
||||
log::warn!("Couldn't find campaign {} (ignoring difficulty {})", id, difficulty);
|
||||
Err(crate::data::error_codes::WebServicesError::DatabaseError as i16)
|
||||
}
|
||||
}
|
||||
}
|
||||
246
rc_core/src/persist/cube_data.rs
Normal file
246
rc_core/src/persist/cube_data.rs
Normal file
@@ -0,0 +1,246 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use polariton::operation::Typed;
|
||||
|
||||
use super::{WeaponData, WeaponUpgradeInfo, TechTreeData, MovementData};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Cube {
|
||||
pub id: u32,
|
||||
pub info: CubeInfo,
|
||||
pub weapon: Option<WeaponData>,
|
||||
pub weapon_upgrade: Option<WeaponUpgradeInfo>,
|
||||
pub movement: Option<MovementData>,
|
||||
pub tree: Option<TechTreeData>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct CubeInfo {
|
||||
#[serde(default = "default_1")]
|
||||
pub cpu: u32,
|
||||
#[serde(default = "default_1")]
|
||||
pub health: u32,
|
||||
#[serde(default)]
|
||||
pub health_boost: f32,
|
||||
#[serde(default)]
|
||||
pub grey_out_in_tutorial: bool,
|
||||
#[serde(default)]
|
||||
pub visibility: VisibilityMode,
|
||||
#[serde(default)]
|
||||
pub indestructible: bool,
|
||||
#[serde(default)]
|
||||
pub category: ItemCategory,
|
||||
#[serde(default = "default_63")]
|
||||
pub placements: u32,
|
||||
#[serde(default)]
|
||||
pub protonium: bool,
|
||||
#[serde(default)]
|
||||
pub unlocked_by_league: bool,
|
||||
#[serde(default)]
|
||||
pub league_unlock_index: i32,
|
||||
pub stats: HashMap<String, serde_json::Value>,
|
||||
pub description: String,
|
||||
pub size: ItemTier,
|
||||
#[serde(rename = "type", alias = "type_")]
|
||||
pub type_: ItemType,
|
||||
#[serde(default)]
|
||||
pub ranking: i32,
|
||||
#[serde(default)]
|
||||
pub cosmetic: bool,
|
||||
#[serde(default)]
|
||||
pub variant_of: u32, // cube id (in hex)
|
||||
#[serde(default = "default_true")]
|
||||
pub ignore_in_weapon_list: bool,
|
||||
}
|
||||
|
||||
fn default_1() -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn default_63() -> u32 {
|
||||
63
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl <C: Clone> std::convert::Into<crate::data::cube_list::CubeInfo<C>> for CubeInfo {
|
||||
fn into(self) -> crate::data::cube_list::CubeInfo<C> {
|
||||
crate::data::cube_list::CubeInfo {
|
||||
cpu: self.cpu,
|
||||
health: self.health,
|
||||
health_boost: self.health_boost,
|
||||
grey_out_in_tutorial: self.grey_out_in_tutorial,
|
||||
visibility: self.visibility.into(),
|
||||
indestructible: self.indestructible,
|
||||
category: self.category.into(),
|
||||
placements: self.placements, // default 63
|
||||
protonium: self.protonium,
|
||||
unlocked_by_league: self.unlocked_by_league,
|
||||
league_unlock_index: self.league_unlock_index,
|
||||
stats: self.stats.into_iter().map(|(k, v)| {
|
||||
let new_v = match v {
|
||||
serde_json::Value::Bool(b) => Typed::Bool(b),
|
||||
serde_json::Value::Number(n) => if let Some(n_i64) = n.as_i64() {
|
||||
Typed::Long(n_i64)
|
||||
} else if let Some(n_f64) = n.as_f64() {
|
||||
Typed::Double(n_f64)
|
||||
} else {
|
||||
panic!("Invalid json number")
|
||||
},
|
||||
serde_json::Value::String(s) => Typed::Str(s.into()),
|
||||
_ => panic!("Unsupported stats type"), // TODO is support for Object/Array/Null necessary?
|
||||
};
|
||||
(k, new_v)
|
||||
}).collect(),
|
||||
description: self.description,
|
||||
size: self.size.into(),
|
||||
type_: self.type_.into(),
|
||||
ranking: self.ranking,
|
||||
cosmetic: self.cosmetic,
|
||||
variant_of: hex::encode(self.variant_of.to_be_bytes()).into(),
|
||||
ignore_in_weapon_list: self.ignore_in_weapon_list,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Default)]
|
||||
pub enum VisibilityMode {
|
||||
#[default]
|
||||
Mothership,
|
||||
All,
|
||||
Tutorial,
|
||||
None,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::cube_list::VisibilityMode> for VisibilityMode {
|
||||
fn into(self) -> crate::data::cube_list::VisibilityMode {
|
||||
match self {
|
||||
Self::Mothership => crate::data::cube_list::VisibilityMode::Mothership,
|
||||
Self::All => crate::data::cube_list::VisibilityMode::All,
|
||||
Self::Tutorial => crate::data::cube_list::VisibilityMode::Tutorial,
|
||||
Self::None => crate::data::cube_list::VisibilityMode::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Default, Hash, PartialEq, Eq)]
|
||||
pub enum ItemTier {
|
||||
#[default]
|
||||
NoTier = 0,
|
||||
T0 = 100,
|
||||
T1 = 200,
|
||||
T2 = 300,
|
||||
T3 = 400,
|
||||
T4 = 500,
|
||||
T5 = 600,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::cube_list::ItemTier> for ItemTier {
|
||||
fn into(self) -> crate::data::cube_list::ItemTier {
|
||||
match self {
|
||||
Self::NoTier => crate::data::cube_list::ItemTier::NoTier,
|
||||
Self::T0 => crate::data::cube_list::ItemTier::T0,
|
||||
Self::T1 => crate::data::cube_list::ItemTier::T1,
|
||||
Self::T2 => crate::data::cube_list::ItemTier::T2,
|
||||
Self::T3 => crate::data::cube_list::ItemTier::T3,
|
||||
Self::T4 => crate::data::cube_list::ItemTier::T4,
|
||||
Self::T5 => crate::data::cube_list::ItemTier::T5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Default)]
|
||||
pub enum ItemType {
|
||||
#[default]
|
||||
NotAFunctionalItem,
|
||||
Weapon,
|
||||
Module,
|
||||
Movement,
|
||||
Cosmetic,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::cube_list::ItemType> for ItemType {
|
||||
fn into(self) -> crate::data::cube_list::ItemType {
|
||||
match self {
|
||||
Self::NotAFunctionalItem => crate::data::cube_list::ItemType::NoFunction,
|
||||
Self::Weapon => crate::data::cube_list::ItemType::Weapon,
|
||||
Self::Module => crate::data::cube_list::ItemType::Module,
|
||||
Self::Movement => crate::data::cube_list::ItemType::Movement,
|
||||
Self::Cosmetic => crate::data::cube_list::ItemType::Cosmetic,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Default, Hash, PartialEq, Eq)]
|
||||
pub enum ItemCategory {
|
||||
#[default]
|
||||
NotAFunctionalItem = 0,
|
||||
Wheel = 1,
|
||||
Hover = 2,
|
||||
Wing = 3,
|
||||
Rudder = 4,
|
||||
Thruster = 5,
|
||||
InsectLeg = 6,
|
||||
MechLeg = 7,
|
||||
Ski = 8,
|
||||
TankTrack = 9,
|
||||
Rotor = 10,
|
||||
SprinterLeg = 11,
|
||||
Propeller = 12,
|
||||
Laser = 100,
|
||||
Plasma = 200,
|
||||
Mortar = 250,
|
||||
Rail = 300,
|
||||
Nano = 400,
|
||||
Tesla = 500,
|
||||
Aeroflak = 600,
|
||||
Ion = 650,
|
||||
Seeker = 701,
|
||||
Chaingun = 750,
|
||||
ShieldModule = 800,
|
||||
GhostModule = 801,
|
||||
BlinkModule = 802,
|
||||
EmpModule = 803,
|
||||
WindowmakerModule = 804,
|
||||
EnergyModule = 900,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::weapon_list::ItemCategory> for ItemCategory {
|
||||
fn into(self) -> crate::data::weapon_list::ItemCategory {
|
||||
match self {
|
||||
Self::NotAFunctionalItem => crate::data::weapon_list::ItemCategory::NoFunction,
|
||||
Self::Wheel => crate::data::weapon_list::ItemCategory::Wheel,
|
||||
Self::Hover => crate::data::weapon_list::ItemCategory::Hover,
|
||||
Self::Wing => crate::data::weapon_list::ItemCategory::Wing,
|
||||
Self::Rudder => crate::data::weapon_list::ItemCategory::Rudder,
|
||||
Self::Thruster => crate::data::weapon_list::ItemCategory::Thruster,
|
||||
Self::InsectLeg => crate::data::weapon_list::ItemCategory::InsectLeg,
|
||||
Self::MechLeg => crate::data::weapon_list::ItemCategory::MechLeg,
|
||||
Self::Ski => crate::data::weapon_list::ItemCategory::Ski,
|
||||
Self::TankTrack => crate::data::weapon_list::ItemCategory::TankTrack,
|
||||
Self::Rotor => crate::data::weapon_list::ItemCategory::Rotor,
|
||||
Self::SprinterLeg => crate::data::weapon_list::ItemCategory::SprinterLeg,
|
||||
Self::Propeller => crate::data::weapon_list::ItemCategory::Propeller,
|
||||
Self::Laser => crate::data::weapon_list::ItemCategory::Laser,
|
||||
Self::Plasma => crate::data::weapon_list::ItemCategory::Plasma,
|
||||
Self::Mortar => crate::data::weapon_list::ItemCategory::Mortar,
|
||||
Self::Rail => crate::data::weapon_list::ItemCategory::Rail,
|
||||
Self::Nano => crate::data::weapon_list::ItemCategory::Nano,
|
||||
Self::Tesla => crate::data::weapon_list::ItemCategory::Tesla,
|
||||
Self::Aeroflak => crate::data::weapon_list::ItemCategory::Aeroflak,
|
||||
Self::Ion => crate::data::weapon_list::ItemCategory::Ion,
|
||||
Self::Seeker => crate::data::weapon_list::ItemCategory::Seeker,
|
||||
Self::Chaingun => crate::data::weapon_list::ItemCategory::Chaingun,
|
||||
Self::ShieldModule => crate::data::weapon_list::ItemCategory::ShieldModule,
|
||||
Self::GhostModule => crate::data::weapon_list::ItemCategory::GhostModule,
|
||||
Self::BlinkModule => crate::data::weapon_list::ItemCategory::BlinkModule,
|
||||
Self::EmpModule => crate::data::weapon_list::ItemCategory::EmpModule,
|
||||
Self::WindowmakerModule => crate::data::weapon_list::ItemCategory::WindowmakerModule,
|
||||
Self::EnergyModule => crate::data::weapon_list::ItemCategory::EnergyModule,
|
||||
}
|
||||
}
|
||||
}
|
||||
135
rc_core/src/persist/garage.rs
Normal file
135
rc_core/src/persist/garage.rs
Normal file
@@ -0,0 +1,135 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::ItemCategory;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct GarageSlot {
|
||||
#[serde(default)]
|
||||
pub slot: u32,
|
||||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub cubes: u32,
|
||||
#[serde(default)]
|
||||
pub crf_id: u32, // 0 means not uploaded
|
||||
#[serde(default = "default_false")]
|
||||
pub was_rated: bool,
|
||||
#[serde(default)]
|
||||
pub movement_categories: Vec<ItemCategory>,
|
||||
#[serde(default)]
|
||||
pub uuid: (u32, u32),
|
||||
pub thumbnail_version: u32,
|
||||
#[serde(default)]
|
||||
pub total_robot_cpu: u32,
|
||||
#[serde(default)]
|
||||
pub total_cosmetic_cpu: u32,
|
||||
#[serde(default)]
|
||||
pub total_robot_ranking: u32,
|
||||
#[serde(default)]
|
||||
pub bay_cpu: u32,
|
||||
#[serde(default = "default_false")]
|
||||
pub tutorial_robot: bool,
|
||||
#[serde(default = "default_neg_1")]
|
||||
pub starter_robot_index: i32,
|
||||
#[serde(default)]
|
||||
pub control_type: ControlType,
|
||||
#[serde(default)]
|
||||
pub control_options: GarageControls,
|
||||
#[serde(default)]
|
||||
pub mastery_level: i32,
|
||||
#[serde(default)]
|
||||
pub bay_skin_id: String,
|
||||
#[serde(default)]
|
||||
pub weapon_order: Vec<i32>,
|
||||
#[serde(default = "default_robot_bytes")]
|
||||
pub robot_data: Vec<u8>,
|
||||
#[serde(default = "default_robot_bytes")]
|
||||
pub colour_data: Vec<u8>,
|
||||
}
|
||||
|
||||
fn default_false() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn default_neg_1() -> i32 {
|
||||
-1
|
||||
}
|
||||
|
||||
fn default_robot_bytes() -> Vec<u8> {
|
||||
vec![0u8, 0u8, 0u8, 0u8]
|
||||
}
|
||||
|
||||
impl GarageSlot {
|
||||
pub fn load(filepath: impl AsRef<std::path::Path>) -> std::io::Result<Self> {
|
||||
let file = std::fs::File::open(filepath)?;
|
||||
let buffered = std::io::BufReader::new(file);
|
||||
let result = serde_json::from_reader(buffered)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn save(&self, filepath: impl AsRef<std::path::Path>) -> std::io::Result<()> {
|
||||
let file = std::fs::File::create(filepath)?;
|
||||
let buffered = std::io::BufWriter::new(file);
|
||||
serde_json::to_writer_pretty(buffered, self)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::garage_bay::GarageSlotInfo> for GarageSlot {
|
||||
fn into(self) -> crate::data::garage_bay::GarageSlotInfo {
|
||||
crate::data::garage_bay::GarageSlotInfo {
|
||||
name: self.name,
|
||||
cubes: self.cubes,
|
||||
crf_id: self.crf_id,
|
||||
was_rated: self.was_rated,
|
||||
movement_categories: self.movement_categories.into_iter().map(|x| x.into()).collect(),
|
||||
uuid: self.uuid,
|
||||
thumbnail_version: self.thumbnail_version,
|
||||
total_robot_cpu: self.total_robot_cpu,
|
||||
total_cosmetic_cpu: self.total_cosmetic_cpu,
|
||||
total_robot_ranking: self.total_robot_ranking,
|
||||
bay_cpu: self.bay_cpu,
|
||||
tutorial_robot: self.tutorial_robot,
|
||||
starter_robot_index: self.starter_robot_index,
|
||||
control_type: self.control_type.into(),
|
||||
control_options: self.control_options.into(),
|
||||
mastery_level: self.mastery_level,
|
||||
bay_skin_id: self.bay_skin_id,
|
||||
weapon_order: self.weapon_order,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Default)]
|
||||
pub enum ControlType {
|
||||
#[default]
|
||||
Camera,
|
||||
Keyboard,
|
||||
Count,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::garage_bay::ControlType> for ControlType {
|
||||
fn into(self) -> crate::data::garage_bay::ControlType {
|
||||
match self {
|
||||
Self::Camera => crate::data::garage_bay::ControlType::Camera,
|
||||
Self::Keyboard => crate::data::garage_bay::ControlType::Keyboard,
|
||||
Self::Count => crate::data::garage_bay::ControlType::Count,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct GarageControls {
|
||||
pub vertical_strafing: bool,
|
||||
pub sideways_driving: bool,
|
||||
pub tracks_turn_on_spot: bool,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::garage_bay::ControlOptions> for GarageControls {
|
||||
fn into(self) -> crate::data::garage_bay::ControlOptions {
|
||||
crate::data::garage_bay::ControlOptions {
|
||||
vertical_strafing: self.vertical_strafing,
|
||||
sideways_driving: self.sideways_driving,
|
||||
tracks_turn_on_spot: self.tracks_turn_on_spot,
|
||||
}
|
||||
}
|
||||
}
|
||||
804
rc_core/src/persist/mod.rs
Normal file
804
rc_core/src/persist/mod.rs
Normal file
@@ -0,0 +1,804 @@
|
||||
pub mod config;
|
||||
pub mod user;
|
||||
|
||||
mod cube_data;
|
||||
pub use cube_data::{Cube, ItemTier, ItemCategory};
|
||||
//pub use cube_data::{VisibilityMode, ItemType};
|
||||
|
||||
mod garage;
|
||||
pub use garage::{GarageSlot, GarageControls, ControlType};
|
||||
|
||||
mod movement;
|
||||
pub use movement::{MovementCategoryData, MovementData};
|
||||
|
||||
mod weapon;
|
||||
pub use weapon::{WeaponData, WeaponUpgradeInfo};
|
||||
|
||||
mod tech_tree;
|
||||
pub use tech_tree::TechTreeData;
|
||||
|
||||
mod combat;
|
||||
pub use combat::BattleConfig;
|
||||
|
||||
mod singleplayer;
|
||||
pub use singleplayer::{Campaigns, Campaign, CampaignDifficulty, CampaignCompletion, CampaignType, Wave, WaveRobot};
|
||||
|
||||
// TODO put this in core lib
|
||||
|
||||
pub(self) const VALID_ROBOT: &[u8] = &[64,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
38,
|
||||
190,
|
||||
25,
|
||||
77,
|
||||
24,
|
||||
6,
|
||||
29,
|
||||
0,
|
||||
80,
|
||||
135,
|
||||
103,
|
||||
211,
|
||||
27,
|
||||
4,
|
||||
27,
|
||||
6,
|
||||
80,
|
||||
135,
|
||||
103,
|
||||
211,
|
||||
21,
|
||||
4,
|
||||
27,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
26,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
27,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
28,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
25,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
28,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
27,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
26,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
25,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
27,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
28,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
26,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
25,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
28,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
27,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
26,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
25,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
25,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
26,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
27,
|
||||
23,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
28,
|
||||
23,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
5,
|
||||
29,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
5,
|
||||
29,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
5,
|
||||
29,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
5,
|
||||
28,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
5,
|
||||
28,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
5,
|
||||
26,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
5,
|
||||
26,
|
||||
0,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
24,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
23,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
22,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
21,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
20,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
19,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
18,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
17,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
16,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
15,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
24,
|
||||
4,
|
||||
14,
|
||||
22,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
17,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
17,
|
||||
6,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
16,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
16,
|
||||
6,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
15,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
15,
|
||||
6,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
23,
|
||||
4,
|
||||
14,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
25,
|
||||
4,
|
||||
14,
|
||||
6,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
17,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
17,
|
||||
6,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
16,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
16,
|
||||
6,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
15,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
15,
|
||||
6,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
22,
|
||||
4,
|
||||
14,
|
||||
12,
|
||||
198,
|
||||
224,
|
||||
138,
|
||||
13,
|
||||
26,
|
||||
4,
|
||||
14,
|
||||
6,
|
||||
240,
|
||||
75,
|
||||
110,
|
||||
137,
|
||||
21,
|
||||
4,
|
||||
15,
|
||||
12,
|
||||
240,
|
||||
75,
|
||||
110,
|
||||
137,
|
||||
27,
|
||||
4,
|
||||
15,
|
||||
6];
|
||||
|
||||
pub(self) const VALID_COLOUR: &[u8] = &[64,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
24,
|
||||
6,
|
||||
29,
|
||||
0,
|
||||
27,
|
||||
4,
|
||||
27,
|
||||
0,
|
||||
21,
|
||||
4,
|
||||
27,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
26,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
27,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
28,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
25,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
28,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
27,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
26,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
25,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
27,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
28,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
26,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
25,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
29,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
28,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
27,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
26,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
25,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
25,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
26,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
27,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
28,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
29,
|
||||
1,
|
||||
25,
|
||||
5,
|
||||
29,
|
||||
1,
|
||||
23,
|
||||
5,
|
||||
29,
|
||||
1,
|
||||
24,
|
||||
5,
|
||||
29,
|
||||
1,
|
||||
22,
|
||||
5,
|
||||
28,
|
||||
1,
|
||||
26,
|
||||
5,
|
||||
28,
|
||||
1,
|
||||
25,
|
||||
5,
|
||||
26,
|
||||
1,
|
||||
23,
|
||||
5,
|
||||
26,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
24,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
23,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
22,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
21,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
20,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
19,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
18,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
17,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
16,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
15,
|
||||
0,
|
||||
24,
|
||||
4,
|
||||
14,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
17,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
17,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
16,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
16,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
15,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
15,
|
||||
0,
|
||||
23,
|
||||
4,
|
||||
14,
|
||||
0,
|
||||
25,
|
||||
4,
|
||||
14,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
17,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
17,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
16,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
16,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
15,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
15,
|
||||
0,
|
||||
22,
|
||||
4,
|
||||
14,
|
||||
0,
|
||||
26,
|
||||
4,
|
||||
14,
|
||||
0,
|
||||
21,
|
||||
4,
|
||||
15,
|
||||
0,
|
||||
27,
|
||||
4,
|
||||
15];
|
||||
456
rc_core/src/persist/movement.rs
Normal file
456
rc_core/src/persist/movement.rs
Normal file
@@ -0,0 +1,456 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::ItemTier;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct MovementCategoryData {
|
||||
pub horizontal_top_speed: Option<f32>,
|
||||
pub vertical_top_speed: Option<f32>,
|
||||
pub min_required_items: Option<i32>,
|
||||
pub min_item_modifier: Option<f32>,
|
||||
pub max_hover_height: Option<f32>,
|
||||
pub light_machine_mass: Option<f32>,
|
||||
pub heavy_machine_mass: Option<f32>,
|
||||
#[serde(flatten)]
|
||||
pub specifics: MovementCategorySpecificData,
|
||||
}
|
||||
|
||||
impl MovementCategoryData {
|
||||
pub fn into_data(self, stats: Vec<(ItemTier, MovementData)>) -> crate::data::movement_list::MovementCategoryData {
|
||||
crate::data::movement_list::MovementCategoryData {
|
||||
horizontal_top_speed: self.horizontal_top_speed,
|
||||
vertical_top_speed: self.vertical_top_speed,
|
||||
min_required_items: self.min_required_items,
|
||||
min_item_modifier: self.min_item_modifier,
|
||||
max_hover_height: self.max_hover_height,
|
||||
light_machine_mass: self.light_machine_mass,
|
||||
heavy_machine_mass: self.heavy_machine_mass,
|
||||
specifics: self.specifics.into(),
|
||||
stats: stats.into_iter().map(|(t, m)| (t.into(), m.into())).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
#[serde(tag = "movement_enum_variant")]
|
||||
pub enum MovementCategorySpecificData {
|
||||
#[default]
|
||||
Wheel,
|
||||
Hover(HoverCategoryData),
|
||||
Wing,
|
||||
Rudder, // same as wing
|
||||
Thruster,
|
||||
Propeller, // same as thruster
|
||||
InsectLeg,
|
||||
MechLeg(MechLegCategoryData),
|
||||
SprinterLeg(MechLegCategoryData), // same as mech leg
|
||||
TankTrack,
|
||||
Rotor(RotorCategoryData),
|
||||
Ski,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::MovementCategorySpecificData> for MovementCategorySpecificData {
|
||||
fn into(self) -> crate::data::movement_list::MovementCategorySpecificData {
|
||||
match self {
|
||||
Self::Wheel => crate::data::movement_list::MovementCategorySpecificData::Wheel,
|
||||
Self::Hover(x) => crate::data::movement_list::MovementCategorySpecificData::Hover(x.into()),
|
||||
Self::Wing => crate::data::movement_list::MovementCategorySpecificData::Wing,
|
||||
Self::Rudder => crate::data::movement_list::MovementCategorySpecificData::Rudder,
|
||||
Self::Thruster => crate::data::movement_list::MovementCategorySpecificData::Thruster,
|
||||
Self::Propeller => crate::data::movement_list::MovementCategorySpecificData::Propeller,
|
||||
Self::InsectLeg => crate::data::movement_list::MovementCategorySpecificData::InsectLeg,
|
||||
Self::MechLeg(x) => crate::data::movement_list::MovementCategorySpecificData::MechLeg(x.into()),
|
||||
Self::SprinterLeg(x) => crate::data::movement_list::MovementCategorySpecificData::SprinterLeg(x.into()),
|
||||
Self::TankTrack => crate::data::movement_list::MovementCategorySpecificData::TankTrack,
|
||||
Self::Rotor(x) => crate::data::movement_list::MovementCategorySpecificData::Rotor(x.into()),
|
||||
Self::Ski => crate::data::movement_list::MovementCategorySpecificData::Ski,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct HoverCategoryData {
|
||||
pub height_tolerance: f32,
|
||||
pub force_y_offset: f32,
|
||||
pub turning_scale: f32,
|
||||
pub small_angle_turning_scale: f32,
|
||||
pub max_vertical_velocity: f32,
|
||||
pub hover_damping: f32,
|
||||
pub angular_damping: f32,
|
||||
pub deceleration_multiplier: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::HoverCategoryData> for HoverCategoryData {
|
||||
fn into(self) -> crate::data::movement_list::HoverCategoryData {
|
||||
crate::data::movement_list::HoverCategoryData {
|
||||
height_tolerance: self.height_tolerance,
|
||||
force_y_offset: self.force_y_offset,
|
||||
turning_scale: self.turning_scale,
|
||||
small_angle_turning_scale: self.small_angle_turning_scale,
|
||||
max_vertical_velocity: self.max_vertical_velocity,
|
||||
hover_damping: self.hover_damping,
|
||||
angular_damping: self.angular_damping,
|
||||
deceleration_multiplier: self.deceleration_multiplier,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct MechLegCategoryData {
|
||||
pub deceleration_multiplier: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::MechLegCategoryData> for MechLegCategoryData {
|
||||
fn into(self) -> crate::data::movement_list::MechLegCategoryData {
|
||||
crate::data::movement_list::MechLegCategoryData {
|
||||
deceleration_multiplier: self.deceleration_multiplier,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct RotorCategoryData {
|
||||
pub max_turn_rate: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::RotorCategoryData> for RotorCategoryData {
|
||||
fn into(self) -> crate::data::movement_list::RotorCategoryData {
|
||||
crate::data::movement_list::RotorCategoryData {
|
||||
max_turn_rate: self.max_turn_rate,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct MovementData {
|
||||
pub speed_boost: Option<f32>,
|
||||
pub max_carry_mass: Option<f32>,
|
||||
pub horizontal_top_speed: Option<f32>,
|
||||
pub vertical_top_speed: Option<f32>,
|
||||
#[serde(flatten)]
|
||||
pub specifics: MovementSpecificData,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::MovementData> for MovementData {
|
||||
fn into(self) -> crate::data::movement_list::MovementData {
|
||||
crate::data::movement_list::MovementData {
|
||||
speed_boost: self.speed_boost,
|
||||
max_carry_mass: self.max_carry_mass,
|
||||
horizontal_top_speed: self.horizontal_top_speed,
|
||||
vertical_top_speed: self.vertical_top_speed,
|
||||
specifics: self.specifics.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(tag = "movement_enum_variant")]
|
||||
pub enum MovementSpecificData {
|
||||
Wheel(WheelData),
|
||||
Hover(HoverData),
|
||||
Wing(AerofoilData),
|
||||
Rudder(AerofoilData), // same as wing
|
||||
Thruster(ThrusterData),
|
||||
Propeller(ThrusterData), // same as thruster
|
||||
InsectLeg(InsectLegData),
|
||||
MechLeg(MechLegData),
|
||||
SprinterLeg(MechLegData), // same as mech leg
|
||||
TankTrack(TankTrackData),
|
||||
Rotor(RotorData),
|
||||
Ski,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::MovementSpecificData> for MovementSpecificData {
|
||||
fn into(self) -> crate::data::movement_list::MovementSpecificData {
|
||||
match self {
|
||||
Self::Wheel(x) => crate::data::movement_list::MovementSpecificData::Wheel(x.into()),
|
||||
Self::Hover(x) => crate::data::movement_list::MovementSpecificData::Hover(x.into()),
|
||||
Self::Wing(x) => crate::data::movement_list::MovementSpecificData::Wing(x.into()),
|
||||
Self::Rudder(x) => crate::data::movement_list::MovementSpecificData::Rudder(x.into()),
|
||||
Self::Thruster(x) => crate::data::movement_list::MovementSpecificData::Thruster(x.into()),
|
||||
Self::Propeller(x) => crate::data::movement_list::MovementSpecificData::Propeller(x.into()),
|
||||
Self::InsectLeg(x) => crate::data::movement_list::MovementSpecificData::InsectLeg(x.into()),
|
||||
Self::MechLeg(x) => crate::data::movement_list::MovementSpecificData::MechLeg(x.into()),
|
||||
Self::SprinterLeg(x) => crate::data::movement_list::MovementSpecificData::SprinterLeg(x.into()),
|
||||
Self::TankTrack(x) => crate::data::movement_list::MovementSpecificData::TankTrack(x.into()),
|
||||
Self::Rotor(x) => crate::data::movement_list::MovementSpecificData::Rotor(x.into()),
|
||||
Self::Ski=> crate::data::movement_list::MovementSpecificData::Ski,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct WheelData {
|
||||
pub steering_speed_light: f32,
|
||||
pub steering_speed_heavy: f32,
|
||||
pub steering_force_multiplier_light: f32,
|
||||
pub steering_force_multiplier_heavy: f32,
|
||||
pub lateral_acceleration_light: f32,
|
||||
pub lateral_acceleration_heavy: f32,
|
||||
pub time_to_max_acceleration_light: f32,
|
||||
pub time_to_max_acceleration_heavy: f32,
|
||||
pub brake_force_light: f32,
|
||||
pub brake_force_heavy: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::WheelData> for WheelData {
|
||||
fn into(self) -> crate::data::movement_list::WheelData {
|
||||
crate::data::movement_list::WheelData {
|
||||
steering_speed_light: self.steering_speed_light,
|
||||
steering_speed_heavy: self.steering_speed_heavy,
|
||||
steering_force_multiplier_light: self.steering_force_multiplier_light,
|
||||
steering_force_multiplier_heavy: self.steering_force_multiplier_heavy,
|
||||
lateral_acceleration_light: self.lateral_acceleration_light,
|
||||
lateral_acceleration_heavy: self.lateral_acceleration_heavy,
|
||||
time_to_max_acceleration_light: self.time_to_max_acceleration_light,
|
||||
time_to_max_acceleration_heavy: self.time_to_max_acceleration_heavy,
|
||||
brake_force_light: self.brake_force_light,
|
||||
brake_force_heavy: self.brake_force_heavy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct HoverData {
|
||||
pub max_hover_height_light: f32,
|
||||
pub max_hover_height_heavy: f32,
|
||||
pub height_change_speed_light: f32,
|
||||
pub height_change_speed_heavy: f32,
|
||||
pub turn_torque_light: f32,
|
||||
pub turn_torque_heavy: f32,
|
||||
pub acceleration_light: f32,
|
||||
pub acceleration_heavy: f32,
|
||||
pub max_angular_velocity_light: f32,
|
||||
pub max_angular_velocity_heavy: f32,
|
||||
pub lateral_damping_light: f32,
|
||||
pub lateral_damping_heavy: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::HoverData> for HoverData {
|
||||
fn into(self) -> crate::data::movement_list::HoverData {
|
||||
crate::data::movement_list::HoverData {
|
||||
max_hover_height_light: self.max_hover_height_light,
|
||||
max_hover_height_heavy: self.max_hover_height_heavy,
|
||||
height_change_speed_light: self.height_change_speed_light,
|
||||
height_change_speed_heavy: self.height_change_speed_heavy,
|
||||
turn_torque_light: self.turn_torque_light,
|
||||
turn_torque_heavy: self.turn_torque_heavy,
|
||||
acceleration_light: self.acceleration_light,
|
||||
acceleration_heavy: self.acceleration_heavy,
|
||||
max_angular_velocity_light: self.max_angular_velocity_light,
|
||||
max_angular_velocity_heavy: self.max_angular_velocity_heavy,
|
||||
lateral_damping_light: self.lateral_damping_light,
|
||||
lateral_damping_heavy: self.lateral_damping_heavy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct AerofoilData {
|
||||
pub barrel_speed_light: f32,
|
||||
pub barrel_speed_heavy: f32,
|
||||
pub bank_speed_light: f32,
|
||||
pub bank_speed_heavy: f32,
|
||||
pub elevation_speed_light: f32,
|
||||
pub elevation_speed_heavy: f32,
|
||||
pub rudder_speed_light: f32,
|
||||
pub rudder_speed_heavy: f32,
|
||||
pub thrust_light: f32,
|
||||
pub thrust_heavy: f32,
|
||||
pub vtol_velocity_light: f32,
|
||||
pub vtol_velocity_heavy: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::AerofoilData> for AerofoilData {
|
||||
fn into(self) -> crate::data::movement_list::AerofoilData {
|
||||
crate::data::movement_list::AerofoilData {
|
||||
barrel_speed_light: self.barrel_speed_light,
|
||||
barrel_speed_heavy: self.barrel_speed_heavy,
|
||||
bank_speed_light: self.bank_speed_light,
|
||||
bank_speed_heavy: self.bank_speed_heavy,
|
||||
elevation_speed_light: self.elevation_speed_light,
|
||||
elevation_speed_heavy: self.elevation_speed_heavy,
|
||||
rudder_speed_light: self.rudder_speed_light,
|
||||
rudder_speed_heavy: self.rudder_speed_heavy,
|
||||
thrust_light: self.thrust_light,
|
||||
thrust_heavy: self.thrust_heavy,
|
||||
vtol_velocity_light: self.vtol_velocity_light,
|
||||
vtol_velocity_heavy: self.vtol_velocity_heavy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct ThrusterData {
|
||||
pub acceleration_delay_light: f32,
|
||||
pub acceleration_delay_heavy: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::ThrusterData> for ThrusterData {
|
||||
fn into(self) -> crate::data::movement_list::ThrusterData {
|
||||
crate::data::movement_list::ThrusterData {
|
||||
acceleration_delay_light: self.acceleration_delay_light,
|
||||
acceleration_delay_heavy: self.acceleration_delay_heavy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct InsectLegData {
|
||||
pub ideal_height_light: f32,
|
||||
pub ideal_height_heavy: f32,
|
||||
pub ideal_crouching_height_light: f32,
|
||||
pub ideal_crouching_height_heavy: f32,
|
||||
pub ideal_height_range_light: f32,
|
||||
pub ideal_height_range_heavy: f32,
|
||||
pub jump_height_light: f32,
|
||||
pub jump_height_heavy: f32,
|
||||
pub max_upwards_force_light: f32,
|
||||
pub max_upwards_force_heavy: f32,
|
||||
pub max_lateral_force_light: f32,
|
||||
pub max_lateral_force_heavy: f32,
|
||||
pub max_turning_force_light: f32,
|
||||
pub max_turning_force_heavy: f32,
|
||||
pub max_damping_force_light: f32,
|
||||
pub max_damping_force_heavy: f32,
|
||||
pub max_stopped_force_light: f32,
|
||||
pub max_stopped_force_heavy: f32,
|
||||
pub max_new_stopped_force_light: f32,
|
||||
pub max_new_stopped_force_heavy: f32,
|
||||
pub upwards_damping_force_light: f32,
|
||||
pub upwards_damping_force_heavy: f32,
|
||||
pub lateral_damp_force_light: f32,
|
||||
pub lateral_damp_force_heavy: f32,
|
||||
pub swagger_force_light: f32,
|
||||
pub swagger_force_heavy: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::InsectLegData> for InsectLegData {
|
||||
fn into(self) -> crate::data::movement_list::InsectLegData {
|
||||
crate::data::movement_list::InsectLegData {
|
||||
ideal_height_light: self.ideal_height_light,
|
||||
ideal_height_heavy: self.ideal_height_heavy,
|
||||
ideal_crouching_height_light: self.ideal_crouching_height_light,
|
||||
ideal_crouching_height_heavy: self.ideal_crouching_height_heavy,
|
||||
ideal_height_range_light: self.ideal_height_range_light,
|
||||
ideal_height_range_heavy: self.ideal_height_range_heavy,
|
||||
jump_height_light: self.jump_height_light,
|
||||
jump_height_heavy: self.jump_height_heavy,
|
||||
max_upwards_force_light: self.max_upwards_force_light,
|
||||
max_upwards_force_heavy: self.max_upwards_force_heavy,
|
||||
max_lateral_force_light: self.max_lateral_force_light,
|
||||
max_lateral_force_heavy: self.max_lateral_force_heavy,
|
||||
max_turning_force_light: self.max_turning_force_light,
|
||||
max_turning_force_heavy: self.max_turning_force_heavy,
|
||||
max_damping_force_light: self.max_damping_force_light,
|
||||
max_damping_force_heavy: self.max_damping_force_heavy,
|
||||
max_stopped_force_light: self.max_stopped_force_light,
|
||||
max_stopped_force_heavy: self.max_stopped_force_heavy,
|
||||
max_new_stopped_force_light: self.max_new_stopped_force_light,
|
||||
max_new_stopped_force_heavy: self.max_new_stopped_force_heavy,
|
||||
upwards_damping_force_light: self.upwards_damping_force_light,
|
||||
upwards_damping_force_heavy: self.upwards_damping_force_heavy,
|
||||
lateral_damp_force_light: self.lateral_damp_force_light,
|
||||
lateral_damp_force_heavy: self.lateral_damp_force_heavy,
|
||||
swagger_force_light: self.swagger_force_light,
|
||||
swagger_force_heavy: self.swagger_force_heavy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct MechLegData {
|
||||
pub time_grounded_after_jump_light: f32,
|
||||
pub time_grounded_after_jump_heavy: f32,
|
||||
pub jump_height_light: f32,
|
||||
pub jump_height_heavy: f32,
|
||||
pub turn_acceleration_light: f32,
|
||||
pub turn_acceleration_heavy: f32,
|
||||
pub legacy_turn_acceleration_light: f32,
|
||||
pub legacy_turn_acceleration_heavy: f32,
|
||||
pub long_jump_speed_scale_light: f32,
|
||||
pub long_jump_speed_scale_heavy: f32,
|
||||
pub max_lateral_force_light: f32,
|
||||
pub max_lateral_force_heavy: f32,
|
||||
pub max_damping_force_light: f32,
|
||||
pub max_damping_force_heavy: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::MechLegData> for MechLegData {
|
||||
fn into(self) -> crate::data::movement_list::MechLegData {
|
||||
crate::data::movement_list::MechLegData {
|
||||
time_grounded_after_jump_light: self.time_grounded_after_jump_light,
|
||||
time_grounded_after_jump_heavy: self.time_grounded_after_jump_heavy,
|
||||
jump_height_light: self.jump_height_light,
|
||||
jump_height_heavy: self.jump_height_heavy,
|
||||
turn_acceleration_light: self.turn_acceleration_light,
|
||||
turn_acceleration_heavy: self.turn_acceleration_heavy,
|
||||
legacy_turn_acceleration_light: self.legacy_turn_acceleration_light,
|
||||
legacy_turn_acceleration_heavy: self.legacy_turn_acceleration_heavy,
|
||||
long_jump_speed_scale_light: self.long_jump_speed_scale_light,
|
||||
long_jump_speed_scale_heavy: self.long_jump_speed_scale_heavy,
|
||||
max_lateral_force_light: self.max_lateral_force_light,
|
||||
max_lateral_force_heavy: self.max_lateral_force_heavy,
|
||||
max_damping_force_light: self.max_damping_force_light,
|
||||
max_damping_force_heavy: self.max_damping_force_heavy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct TankTrackData {
|
||||
pub max_turn_rate_moving_light: f32,
|
||||
pub max_turn_rate_moving_heavy: f32,
|
||||
pub max_turn_rate_stopped_light: f32,
|
||||
pub max_turn_rate_stopped_heavy: f32,
|
||||
pub turn_acceleration_light: f32,
|
||||
pub turn_acceleration_heavy: f32,
|
||||
pub lateral_acceleration_light: f32,
|
||||
pub lateral_acceleration_heavy: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::TankTrackData> for TankTrackData {
|
||||
fn into(self) -> crate::data::movement_list::TankTrackData {
|
||||
crate::data::movement_list::TankTrackData {
|
||||
max_turn_rate_moving_light: self.max_turn_rate_moving_light,
|
||||
max_turn_rate_moving_heavy: self.max_turn_rate_moving_heavy,
|
||||
max_turn_rate_stopped_light: self.max_turn_rate_stopped_light,
|
||||
max_turn_rate_stopped_heavy: self.max_turn_rate_stopped_heavy,
|
||||
turn_acceleration_light: self.turn_acceleration_light,
|
||||
turn_acceleration_heavy: self.turn_acceleration_heavy,
|
||||
lateral_acceleration_light: self.lateral_acceleration_light,
|
||||
lateral_acceleration_heavy: self.lateral_acceleration_heavy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct RotorData {
|
||||
pub height_acceleration_light: f32,
|
||||
pub height_acceleration_heavy: f32,
|
||||
pub strafe_acceleration_light: f32,
|
||||
pub strafe_acceleration_heavy: f32,
|
||||
pub turn_acceleration_light: f32,
|
||||
pub turn_acceleration_heavy: f32,
|
||||
pub height_max_change_speed_light: f32,
|
||||
pub height_max_change_speed_heavy: f32,
|
||||
pub level_acceleration_light: f32,
|
||||
pub level_acceleration_heavy: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::movement_list::RotorData> for RotorData {
|
||||
fn into(self) -> crate::data::movement_list::RotorData {
|
||||
crate::data::movement_list::RotorData {
|
||||
height_acceleration_light: self.height_acceleration_light,
|
||||
height_acceleration_heavy: self.height_acceleration_heavy,
|
||||
strafe_acceleration_light: self.strafe_acceleration_light,
|
||||
strafe_acceleration_heavy: self.strafe_acceleration_heavy,
|
||||
turn_acceleration_light: self.turn_acceleration_light,
|
||||
turn_acceleration_heavy: self.turn_acceleration_heavy,
|
||||
height_max_change_speed_light: self.height_max_change_speed_light,
|
||||
height_max_change_speed_heavy: self.height_max_change_speed_heavy,
|
||||
level_acceleration_light: self.level_acceleration_light,
|
||||
level_acceleration_heavy: self.level_acceleration_heavy,
|
||||
}
|
||||
}
|
||||
}
|
||||
224
rc_core/src/persist/singleplayer.rs
Normal file
224
rc_core/src/persist/singleplayer.rs
Normal file
@@ -0,0 +1,224 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Campaigns {
|
||||
pub campaigns: Vec<Campaign>,
|
||||
}
|
||||
|
||||
impl Campaigns {
|
||||
pub fn into_campaign_params(self) -> crate::data::campaign::CampaignsGameParameters {
|
||||
crate::data::campaign::CampaignsGameParameters { campaigns: self.campaigns.into_iter().map(|x| x.into_campaign_params()).collect() }
|
||||
}
|
||||
|
||||
pub fn into_waves(self) -> crate::data::campaign::LiveCampaignWaves {
|
||||
crate::data::campaign::LiveCampaignWaves { waves: self.campaigns.into_iter().map(|x| x.into_waves()).collect() }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Campaign {
|
||||
pub id: String,
|
||||
pub excluded_cubes: Vec<u32>, // encoded to hex strings
|
||||
pub categories: Vec<super::ItemCategory>,
|
||||
pub min_cpu: i32,
|
||||
pub max_cpu: i32,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub image: String,
|
||||
pub rules: Vec<String>,
|
||||
pub parameters: Vec<Vec<String>>,
|
||||
pub difficulties: Vec<CampaignDifficulty>,
|
||||
pub completed: Vec<CampaignCompletion>,
|
||||
pub map: String,
|
||||
pub campaign_type: CampaignType,
|
||||
pub waves: Vec<Wave>,
|
||||
}
|
||||
|
||||
impl Campaign {
|
||||
pub fn into_campaign_params(self) -> crate::data::campaign::CampaignParameters {
|
||||
crate::data::campaign::CampaignParameters {
|
||||
id: self.id,
|
||||
excluded_cubes: self.excluded_cubes,
|
||||
categories: self.categories.into_iter().map(|x| x.into()).collect(),
|
||||
min_cpu: self.min_cpu,
|
||||
max_cpu: self.max_cpu,
|
||||
name: self.name,
|
||||
description: self.description,
|
||||
image: self.image,
|
||||
rules: self.rules,
|
||||
parameters: self.parameters,
|
||||
difficulties: self.difficulties.into_iter().map(|x| x.into()).collect(),
|
||||
completed: self.completed.into_iter().enumerate().map(|(i, x)| x.into_data(i as _)).collect(),
|
||||
map: self.map,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_waves(self) -> crate::data::campaign::WavesData {
|
||||
crate::data::campaign::WavesData {
|
||||
id: self.id,
|
||||
waves: self.waves.into_iter().map(|x| x.into()).collect(),
|
||||
campaign_type: self.campaign_type.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct CampaignDifficulty {
|
||||
pub level: i32,
|
||||
pub lives: i32,
|
||||
pub auto_heal: bool,
|
||||
pub single_wave_bonus: i32,
|
||||
pub initial_health_boost: f32,
|
||||
pub health_boost_wave_increase: f32,
|
||||
pub initial_damage_boost: f32,
|
||||
pub damage_boost_wave_increase: f32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::campaign::CampaignDifficultyData> for CampaignDifficulty {
|
||||
fn into(self) -> crate::data::campaign::CampaignDifficultyData {
|
||||
crate::data::campaign::CampaignDifficultyData {
|
||||
level: self.level,
|
||||
lives: self.lives,
|
||||
auto_heal: self.auto_heal,
|
||||
single_wave_bonus: self.single_wave_bonus,
|
||||
initial_health_boost: self.initial_health_boost,
|
||||
health_boost_wave_increase: self.health_boost_wave_increase,
|
||||
initial_damage_boost: self.initial_damage_boost,
|
||||
damage_boost_wave_increase: self.damage_boost_wave_increase,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct CampaignCompletion {
|
||||
pub wave: i32,
|
||||
pub difficulty: bool,
|
||||
}
|
||||
|
||||
impl CampaignCompletion {
|
||||
pub fn into_data(self, index: i32) -> crate::data::campaign::CampaignCompletionData {
|
||||
crate::data::campaign::CampaignCompletionData {
|
||||
index,
|
||||
wave: self.wave,
|
||||
difficulty: self.difficulty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Wave {
|
||||
#[serde(default)]
|
||||
pub player_spawn_location: i32,
|
||||
pub robots_in_wave: Vec<WaveRobot>,
|
||||
pub kill_target: i32,
|
||||
#[serde(default)]
|
||||
pub time_min: i32,
|
||||
pub time_max: i32,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::campaign::WaveData> for Wave {
|
||||
fn into(self) -> crate::data::campaign::WaveData {
|
||||
crate::data::campaign::WaveData {
|
||||
robots_in_wave: self.robots_in_wave.into_iter().map(|x| x.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::campaign::CompleteWaveData> for Wave {
|
||||
fn into(self) -> crate::data::campaign::CompleteWaveData {
|
||||
crate::data::campaign::CompleteWaveData {
|
||||
player_spawn_location: self.player_spawn_location,
|
||||
robots_in_wave: self.robots_in_wave.into_iter().map(|x| x.into()).collect(),
|
||||
kill_target: self.kill_target,
|
||||
time_min: self.time_min,
|
||||
time_max: self.time_max,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct WaveRobot { // times appear to be in seconds
|
||||
pub name: String,
|
||||
pub weapon: String,
|
||||
pub movement: String,
|
||||
pub rank: String,
|
||||
pub count: i32,
|
||||
pub robot_data: Vec<u8>,
|
||||
pub colour_data: Vec<u8>,
|
||||
#[serde(default)]
|
||||
pub time_to_spawn: i32,
|
||||
#[serde(default)]
|
||||
pub kills_to_spawn: i32,
|
||||
#[serde(default)]
|
||||
pub time_to_despawn: i32,
|
||||
#[serde(default)]
|
||||
pub kills_to_despawn: i32,
|
||||
#[serde(default = "default_1")]
|
||||
pub initial_robot_amount: i32,
|
||||
#[serde(default)]
|
||||
pub periodic_robot_amount: i32,
|
||||
#[serde(default = "default_1")]
|
||||
pub spawn_interval: i32,
|
||||
#[serde(default = "default_1")]
|
||||
pub min_robot_amount: i32,
|
||||
#[serde(default)]
|
||||
pub max_robot_amount: i32,
|
||||
#[serde(default)]
|
||||
pub is_boss: bool,
|
||||
#[serde(default)]
|
||||
pub is_kill_requirement: bool,
|
||||
}
|
||||
|
||||
fn default_1() -> i32 {
|
||||
1
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::campaign::WaveRobotData> for WaveRobot {
|
||||
fn into(self) -> crate::data::campaign::WaveRobotData {
|
||||
crate::data::campaign::WaveRobotData {
|
||||
name: self.name,
|
||||
weapon: self.weapon,
|
||||
movement: self.movement,
|
||||
rank: self.rank,
|
||||
count: self.count,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::campaign::CompleteWaveRobotData> for WaveRobot {
|
||||
fn into(self) -> crate::data::campaign::CompleteWaveRobotData {
|
||||
crate::data::campaign::CompleteWaveRobotData {
|
||||
name: self.name,
|
||||
robot_data: self.robot_data,
|
||||
colour_data: self.colour_data,
|
||||
time_to_spawn: self.time_to_spawn,
|
||||
kills_to_spawn: self.kills_to_spawn,
|
||||
time_to_despawn: self.time_to_despawn,
|
||||
kills_to_despawn: self.kills_to_despawn,
|
||||
initial_robot_amount: self.initial_robot_amount,
|
||||
periodic_robot_amount: self.periodic_robot_amount,
|
||||
spawn_interval: self.spawn_interval,
|
||||
min_robot_amount: self.min_robot_amount,
|
||||
max_robot_amount: self.max_robot_amount,
|
||||
is_boss: self.is_boss,
|
||||
is_kill_requirement: self.is_kill_requirement,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Copy)]
|
||||
pub enum CampaignType {
|
||||
TimedElimination = 0,
|
||||
Survival = 1,
|
||||
Elimination = 2,
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::campaign::CampaignType> for CampaignType {
|
||||
fn into(self) -> crate::data::campaign::CampaignType {
|
||||
match self {
|
||||
Self::TimedElimination => crate::data::campaign::CampaignType::TimedElimination,
|
||||
Self::Survival => crate::data::campaign::CampaignType::Survival,
|
||||
Self::Elimination => crate::data::campaign::CampaignType::Elimination,
|
||||
}
|
||||
}
|
||||
}
|
||||
25
rc_core/src/persist/tech_tree.rs
Normal file
25
rc_core/src/persist/tech_tree.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
#[serde(default)]
|
||||
pub struct TechTreeData {
|
||||
pub position_x: i32,
|
||||
pub position_y: i32,
|
||||
pub tech_points: u32,
|
||||
pub neighbours: Vec<u32>, // cube IDs
|
||||
pub requires: Vec<u32>,
|
||||
}
|
||||
|
||||
impl TechTreeData {
|
||||
pub fn into_data(self, self_id: u32, self_is_unlocked: bool, self_is_unlockable: bool) -> crate::data::tech_tree::TechTreeNode {
|
||||
crate::data::tech_tree::TechTreeNode {
|
||||
main_cube_id: self_id as i32,
|
||||
position_x: self.position_x,
|
||||
position_y: self.position_y,
|
||||
is_unlocked: self_is_unlocked,
|
||||
is_unlockable: self_is_unlockable,
|
||||
tech_points: self.tech_points,
|
||||
neighbours: self.neighbours.into_iter().map(|x| x as i32).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
261
rc_core/src/persist/user/account_json.rs
Normal file
261
rc_core/src/persist/user/account_json.rs
Normal file
@@ -0,0 +1,261 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::persist::config::ConfigProvider;
|
||||
|
||||
pub struct AccountProvider {
|
||||
root: std::path::PathBuf,
|
||||
cubes: std::sync::Arc<Vec<u32>>,
|
||||
}
|
||||
|
||||
impl AccountProvider {
|
||||
pub fn load(root: impl AsRef<std::path::Path>, cubes: &crate::persist::config::ConfigImpl) -> std::io::Result<Self> {
|
||||
let root = root.as_ref().join(super::USERS_DIR);
|
||||
std::fs::create_dir_all(&root)?;
|
||||
Ok(Self {
|
||||
root,
|
||||
cubes: std::sync::Arc::new(<crate::persist::config::ConfigImpl as ConfigProvider<()>>::ids(cubes)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl <C: Clone> super::UserProvider<C> for AccountProvider {
|
||||
fn authenticate(&self, token: super::UserToken) -> Result<Box<dyn super::User<C> + Send + Sync>, String> {
|
||||
let new_root = self.root.join(&token.uuid);
|
||||
if !new_root.exists() {
|
||||
std::fs::create_dir(&new_root).map_err(|e| e.to_string())?;
|
||||
log::info!("New user {}", token.uuid);
|
||||
super::setup_directory(&new_root).map_err(|e| e.to_string())?;
|
||||
}
|
||||
let account_info = AccountInfo::load(&new_root).map_err(|e| e.to_string())?;
|
||||
Ok(Box::new(UserData {
|
||||
root: new_root,
|
||||
token,
|
||||
account: account_info,
|
||||
cubes: self.cubes.clone(),
|
||||
}))
|
||||
//Err("Unable to authenticate".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct UserData {
|
||||
root: std::path::PathBuf,
|
||||
token: super::UserToken,
|
||||
account: AccountInfo,
|
||||
cubes: std::sync::Arc<Vec<u32>>,
|
||||
}
|
||||
|
||||
impl UserData {
|
||||
fn load_garage_by_id(&self, id: u32) -> std::io::Result<crate::persist::GarageSlot> {
|
||||
let path = self.root.join(super::GARAGE_DIR).join(format!("{}.json", id));
|
||||
crate::persist::GarageSlot::load(&path)
|
||||
}
|
||||
|
||||
fn save_garage(&self, slot: &crate::persist::GarageSlot) -> std::io::Result<()> {
|
||||
let path = self.root.join(super::GARAGE_DIR).join(format!("{}.json", slot.slot));
|
||||
slot.save(path)
|
||||
}
|
||||
|
||||
fn all_vehicles(&self) -> std::io::Result<Vec<crate::persist::GarageSlot>> {
|
||||
let path = self.root.join(super::GARAGE_DIR);
|
||||
let mut slots = Vec::new();
|
||||
for entry in std::fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
let filepath = entry.path();
|
||||
if filepath.is_file() {
|
||||
let slot = crate::persist::GarageSlot::load(&filepath)?;
|
||||
slots.push(slot);
|
||||
} else {
|
||||
log::warn!("Ignoring non-file {} in {} dir", filepath.display(), super::GARAGE_DIR);
|
||||
}
|
||||
}
|
||||
slots.sort_by_key(|slot| slot.slot);
|
||||
Ok(slots)
|
||||
}
|
||||
}
|
||||
|
||||
const INVALID_ROBOT_ERR: i16 = 140;
|
||||
const DATABASE_ERR: i16 = 8;
|
||||
|
||||
impl <C: Clone> super::User<C> for UserData {
|
||||
fn token(&self) -> &'_ super::UserToken {
|
||||
&self.token
|
||||
}
|
||||
|
||||
fn is_mod(&self) -> bool {
|
||||
self.account.is_mod
|
||||
}
|
||||
|
||||
fn is_admin(&self) -> bool {
|
||||
self.account.is_admin
|
||||
}
|
||||
|
||||
fn is_dev(&self) -> bool {
|
||||
self.account.is_dev
|
||||
}
|
||||
|
||||
fn unlocked_parts(&self) -> Vec<u32> {
|
||||
match self.account.inventory.override_ {
|
||||
super::inventory::UnlockOverride::Normal => self.account.inventory.unlocked.clone(),
|
||||
super::inventory::UnlockOverride::UnlockNone => Vec::default(),
|
||||
super::inventory::UnlockOverride::UnlockAll => self.cubes.as_ref().to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn selected_garage_uuid(&self) -> String {
|
||||
self.account.garage.uuid_str()
|
||||
}
|
||||
|
||||
fn selected_garage_slot(&self) -> u32 {
|
||||
self.account.garage.slot
|
||||
}
|
||||
|
||||
fn all_slots_by_id(&self) -> super::UserSlots<C> {
|
||||
let slots = match self.all_vehicles() {
|
||||
Ok(slots) => slots,
|
||||
Err(e) => {
|
||||
log::error!("Failed to load all vehicles: {}", e);
|
||||
Vec::default()
|
||||
}
|
||||
};
|
||||
let slot_order = polariton::operation::Typed::ObjArr(slots.iter().map(|slot| polariton::operation::Typed::Int(slot.slot as _)).collect::<Vec<_>>().into());
|
||||
let slot_info = polariton::operation::Typed::Dict(polariton::operation::Dict {
|
||||
key_ty: polariton::serdes::TypePrefix::Int,
|
||||
val_ty: polariton::serdes:: TypePrefix::HashMap,
|
||||
items: slots.into_iter().map(|slot| {
|
||||
let slot_index = slot.slot;
|
||||
let garage_data: crate::data::garage_bay::GarageSlotInfo = slot.into();
|
||||
(polariton::operation::Typed::Int(slot_index as _), garage_data.as_transmissible())
|
||||
}).collect(),
|
||||
});
|
||||
super::UserSlots {
|
||||
slot_info, slot_order,
|
||||
}
|
||||
}
|
||||
|
||||
fn slot_by_id(&self, id: i32) -> Result<crate::persist::user::UserSlotData<C>, i16> {
|
||||
match self.load_garage_by_id(id as _) {
|
||||
Ok(slot) => {
|
||||
let control_ty: crate::data::garage_bay::ControlType = slot.control_type.into();
|
||||
let control_options: crate::data::garage_bay::ControlOptions = slot.control_options.into();
|
||||
Ok(crate::persist::user::UserSlotData {
|
||||
data: polariton::operation::Typed::Bytes(slot.robot_data.into()),
|
||||
colour_data: polariton::operation::Typed::Bytes(slot.colour_data.into()),
|
||||
cube_count: polariton::operation::Typed::Int(slot.cubes as _),
|
||||
weapon_order: polariton::operation::Typed::IntArr(slot.weapon_order.clone().into()),
|
||||
movement_categories: polariton::operation::Typed::IntArr(slot.movement_categories.into_iter().map(|cat| {
|
||||
let cat: crate::data::weapon_list::ItemCategory = cat.into();
|
||||
cat.but_bigger()
|
||||
}).collect::<Vec<_>>().into()),
|
||||
control_type: polariton::operation::Typed::Int(control_ty as _),
|
||||
control_options: control_options.as_transmissible(),
|
||||
mastery_level: polariton::operation::Typed::Int(0), // TODO
|
||||
robot_rank: polariton::operation::Typed::Int(slot.total_robot_ranking as _),
|
||||
cpu: polariton::operation::Typed::Int(slot.total_robot_cpu as _),
|
||||
cosmetic_cpu: polariton::operation::Typed::Int(slot.total_cosmetic_cpu as _),
|
||||
uuid: polariton::operation::Typed::Str(format!("{}_{}", slot.uuid.0, slot.uuid.1).into()),
|
||||
})
|
||||
},
|
||||
Err(e) => {
|
||||
log::error!("Failed to load vehicle {}: {}", id, e);
|
||||
Err(INVALID_ROBOT_ERR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn save_slot(&self, vehicle: crate::persist::user::VehicleData) -> Result<(), i16> {
|
||||
let id = vehicle.id as u32;
|
||||
let mut existing_data = self.load_garage_by_id(id).map_err(|e| {
|
||||
log::error!("Failed to load vehicle {}: {}", id, e);
|
||||
INVALID_ROBOT_ERR
|
||||
})?;
|
||||
existing_data.slot = id;
|
||||
existing_data.robot_data = vehicle.robot_data;
|
||||
existing_data.colour_data = vehicle.colour_data;
|
||||
log::debug!("weapon order: {:?}", vehicle.weapon_order);
|
||||
existing_data.weapon_order = vehicle.weapon_order;
|
||||
self.save_garage(&existing_data).map_err(|e| {
|
||||
log::error!("Failed to save vehicle {}: {}", id, e);
|
||||
DATABASE_ERR
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn signup_date(&self) -> i64 {
|
||||
match self.root.metadata() {
|
||||
Ok(meta) => {
|
||||
match meta.created() {
|
||||
Ok(created) => {
|
||||
match created.duration_since(std::time::SystemTime::UNIX_EPOCH) {
|
||||
Ok(dur) => {
|
||||
return super::since_windows_epoch(dur.as_secs() as i64);
|
||||
},
|
||||
Err(e) => log::error!("could not get duration since unix epoch of {}: {}", self.root.display(), e),
|
||||
}
|
||||
},
|
||||
Err(e) => log::error!("could not read creation time of {}: {}", self.root.display(), e),
|
||||
}
|
||||
},
|
||||
Err(e) => log::error!("could not retrieve metadata of {}: {}", self.root.display(), e),
|
||||
}
|
||||
super::since_windows_epoch(0)
|
||||
}
|
||||
|
||||
fn singleplayer_robots(&self) -> Result<polariton::operation::Typed<C>, i16> {
|
||||
let current_slot = self.load_garage_by_id(self.account.garage.slot).map_err(|e| {
|
||||
log::error!("Failed to load current vehicle: {}", e);
|
||||
INVALID_ROBOT_ERR
|
||||
})?;
|
||||
let user_uuid = self.token.uuid.clone();
|
||||
Ok(crate::data::player_data::PlayerDatas {
|
||||
players: vec![
|
||||
crate::data::player_data::PlayerData {
|
||||
name: user_uuid.clone(),
|
||||
display_name: user_uuid,
|
||||
mastery: current_slot.mastery_level,
|
||||
tier: 1, // FIXME
|
||||
robot_name: current_slot.name,
|
||||
robot_map: current_slot.robot_data,
|
||||
team: 0,
|
||||
has_premium: true, // FIXME
|
||||
robot_uuid: format!("{}_{}", current_slot.uuid.0, current_slot.uuid.1),
|
||||
cpu: current_slot.total_robot_cpu as i32,
|
||||
weapon_order: current_slot.weapon_order.clone(),
|
||||
colour_map: current_slot.colour_data,
|
||||
is_ai: false,
|
||||
spawn_effect: "Spawn_Warp".to_owned(), // FIXME
|
||||
death_effect: "Explosion_Warp".to_owned(), // FIXME
|
||||
player_rank: 1, // FIXME
|
||||
weapon_rank: current_slot.weapon_order.into_iter().map(|x| (x, if x == 0 { 0 } else { 1 })).collect(),
|
||||
}
|
||||
],
|
||||
}.as_transmissible())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct AccountInfo {
|
||||
pub is_mod: bool,
|
||||
pub is_admin: bool,
|
||||
pub is_dev: bool,
|
||||
pub inventory: super::UnlockedParts,
|
||||
pub garage: super::SelectedGarage,
|
||||
}
|
||||
|
||||
impl AccountInfo {
|
||||
fn load(root: impl AsRef<std::path::Path>) -> std::io::Result<AccountInfo> {
|
||||
let file = std::fs::File::open(root.as_ref().join(super::USER_FILE))?;
|
||||
let buffered = std::io::BufReader::new(file);
|
||||
let result = serde_json::from_reader(buffered)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn save(&self, root: impl AsRef<std::path::Path>) -> std::io::Result<()> {
|
||||
let file = std::fs::File::create(root.as_ref().join(super::USER_FILE))?;
|
||||
let buffered = std::io::BufWriter::new(file);
|
||||
serde_json::to_writer_pretty(buffered, self)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
13
rc_core/src/persist/user/garage_data.rs
Normal file
13
rc_core/src/persist/user/garage_data.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct SelectedGarage {
|
||||
pub uuid: (u32, u32),
|
||||
pub slot: u32,
|
||||
}
|
||||
|
||||
impl SelectedGarage {
|
||||
pub fn uuid_str(&self) -> String {
|
||||
format!("{}_{}", self.uuid.0, self.uuid.1)
|
||||
}
|
||||
}
|
||||
88
rc_core/src/persist/user/initial_data.rs
Normal file
88
rc_core/src/persist/user/initial_data.rs
Normal file
@@ -0,0 +1,88 @@
|
||||
const REFERENCE_DIR: &str = "layout folder";
|
||||
|
||||
fn build_reference_directory(root: impl AsRef<std::path::Path>) -> std::io::Result<()> {
|
||||
std::fs::create_dir(&root)?;
|
||||
let garage_dir = root.as_ref().join(super::GARAGE_DIR);
|
||||
std::fs::create_dir(&garage_dir)?;
|
||||
default_user_data().save(&root)?;
|
||||
for slot in default_garage_slots() {
|
||||
let filepath = garage_dir.join(format!("{}.json", slot.slot));
|
||||
slot.save(filepath)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn setup_directory(new_dir: impl AsRef<std::path::Path>) -> std::io::Result<()> {
|
||||
let ref_path = new_dir.as_ref().parent().unwrap().join(REFERENCE_DIR);
|
||||
if !ref_path.exists() {
|
||||
log::debug!("Initialising reference directory {}", ref_path.display());
|
||||
build_reference_directory(&ref_path)?;
|
||||
}
|
||||
log::debug!("Copying reference directory for new user: {}", new_dir.as_ref().display());
|
||||
so::copy_dir_all(ref_path, new_dir)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn default_user_data() -> super::AccountInfo {
|
||||
super::AccountInfo {
|
||||
is_mod: false,
|
||||
is_admin: false,
|
||||
is_dev: false,
|
||||
inventory: super::UnlockedParts {
|
||||
unlocked: vec![],
|
||||
override_: super::inventory::UnlockOverride::Normal,
|
||||
},
|
||||
garage: super::SelectedGarage {
|
||||
uuid: (0, 0),
|
||||
slot: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn default_garage_slots() -> Vec<crate::persist::GarageSlot> {
|
||||
vec![
|
||||
crate::persist::GarageSlot {
|
||||
slot: 0,
|
||||
name: "Reverse-engineer great success! slot_name".to_owned(),
|
||||
cubes: 1,
|
||||
crf_id: 0,
|
||||
was_rated: false,
|
||||
movement_categories: vec![crate::persist::ItemCategory::Wheel],
|
||||
uuid: (0, 0),
|
||||
thumbnail_version: 0,
|
||||
total_robot_cpu: 1,
|
||||
total_cosmetic_cpu: 0,
|
||||
total_robot_ranking: 1,
|
||||
bay_cpu: 2_000,
|
||||
tutorial_robot: false,
|
||||
starter_robot_index: -1,
|
||||
control_type: crate::persist::ControlType::Camera,
|
||||
control_options: crate::persist::GarageControls { vertical_strafing: false, sideways_driving: false, tracks_turn_on_spot: false, },
|
||||
mastery_level: 1,
|
||||
bay_skin_id: "RC_MothershipSkin_Neptune_01".to_owned(), // TODO get the rest of the names
|
||||
weapon_order: vec![],
|
||||
robot_data: vec![0; 4],
|
||||
colour_data: vec![0; 4],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
mod so {
|
||||
// from https://stackoverflow.com/questions/26958489/how-to-copy-a-folder-recursively-in-rust
|
||||
use std::path::Path;
|
||||
use std::{io, fs};
|
||||
|
||||
pub(super) fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
|
||||
fs::create_dir_all(&dst)?;
|
||||
for entry in fs::read_dir(src)? {
|
||||
let entry = entry?;
|
||||
let ty = entry.file_type()?;
|
||||
if ty.is_dir() {
|
||||
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
||||
} else {
|
||||
fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
16
rc_core/src/persist/user/inventory.rs
Normal file
16
rc_core/src/persist/user/inventory.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct UnlockedParts {
|
||||
pub unlocked: Vec<u32>,
|
||||
#[serde(rename = "override", default)]
|
||||
pub override_: UnlockOverride,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub enum UnlockOverride {
|
||||
#[default]
|
||||
Normal,
|
||||
UnlockAll,
|
||||
UnlockNone,
|
||||
}
|
||||
34
rc_core/src/persist/user/mod.rs
Normal file
34
rc_core/src/persist/user/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
mod account_json;
|
||||
pub use account_json::{AccountProvider, AccountInfo};
|
||||
|
||||
mod garage_data;
|
||||
pub use garage_data::SelectedGarage;
|
||||
|
||||
mod initial_data;
|
||||
pub use initial_data::setup_directory;
|
||||
|
||||
mod inventory;
|
||||
pub use inventory::UnlockedParts;
|
||||
|
||||
mod traits;
|
||||
pub use traits::{UserProvider, User, UserToken, UserSlots, UserSlotData, VehicleData};
|
||||
|
||||
pub const USERS_DIR: &str = "accounts";
|
||||
pub const USER_FILE: &str = "user.json";
|
||||
pub const GARAGE_DIR: &str = "vehicles";
|
||||
|
||||
pub type UserImpl = AccountProvider;
|
||||
|
||||
fn __must_impl<T: UserProvider<()>>() {}
|
||||
|
||||
fn __test_impl() {
|
||||
__must_impl::<UserImpl>();
|
||||
}
|
||||
|
||||
pub fn since_windows_epoch(since_unix_epoch: i64) -> i64 {
|
||||
use chrono::TimeZone;
|
||||
let windows_epoch = chrono::Utc.from_utc_datetime(&chrono::NaiveDateTime::parse_from_str("1601-01-01 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap());
|
||||
let time_in = chrono::DateTime::<chrono::Utc>::from_timestamp(since_unix_epoch, 0).unwrap();
|
||||
//let time_in = chrono::Utc.from_utc_datetime(&chrono::NaiveDateTime::from_timestamp(since_unix_epoch, 0));
|
||||
time_in.signed_duration_since(windows_epoch).num_milliseconds() * 10_000
|
||||
}
|
||||
53
rc_core/src/persist/user/traits.rs
Normal file
53
rc_core/src/persist/user/traits.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct UserToken {
|
||||
pub uuid: String,
|
||||
pub token: String,
|
||||
pub refresh_token: String,
|
||||
}
|
||||
|
||||
pub trait UserProvider<C> {
|
||||
fn authenticate(&self, user: UserToken) -> Result<Box<dyn User<C> + Send + Sync>, String>;
|
||||
}
|
||||
|
||||
pub trait User<C> {
|
||||
fn token(&self) -> &'_ super::UserToken;
|
||||
fn is_mod(&self) -> bool;
|
||||
fn is_admin(&self) -> bool;
|
||||
fn is_dev(&self) -> bool;
|
||||
fn unlocked_parts(&self) -> Vec<u32>;
|
||||
fn selected_garage_uuid(&self) -> String;
|
||||
fn selected_garage_slot(&self) -> u32;
|
||||
fn all_slots_by_id(&self) -> UserSlots<C>;
|
||||
fn slot_by_id(&self, id: i32) -> Result<UserSlotData<C>, i16>;
|
||||
fn save_slot(&self, vehicle: VehicleData) -> Result<(), i16>;
|
||||
fn signup_date(&self) -> i64;
|
||||
fn singleplayer_robots(&self) -> Result<polariton::operation::Typed<C>, i16>;
|
||||
}
|
||||
|
||||
pub struct UserSlots<C> {
|
||||
pub slot_info: polariton::operation::Typed<C>,
|
||||
pub slot_order: polariton::operation::Typed<C>,
|
||||
}
|
||||
|
||||
pub struct UserSlotData<C> {
|
||||
pub data: polariton::operation::Typed<C>,
|
||||
pub colour_data: polariton::operation::Typed<C>,
|
||||
pub cube_count: polariton::operation::Typed<C>,
|
||||
pub weapon_order: polariton::operation::Typed<C>,
|
||||
pub movement_categories: polariton::operation::Typed<C>,
|
||||
pub control_type: polariton::operation::Typed<C>,
|
||||
pub control_options: polariton::operation::Typed<C>,
|
||||
pub mastery_level: polariton::operation::Typed<C>,
|
||||
pub robot_rank: polariton::operation::Typed<C>,
|
||||
pub cpu: polariton::operation::Typed<C>,
|
||||
pub cosmetic_cpu: polariton::operation::Typed<C>,
|
||||
pub uuid: polariton::operation::Typed<C>,
|
||||
}
|
||||
|
||||
pub struct VehicleData {
|
||||
pub id: i32,
|
||||
pub robot_data: Vec<u8>,
|
||||
pub colour_data: Vec<u8>,
|
||||
pub weapon_order: Vec<i32>,
|
||||
}
|
||||
176
rc_core/src/persist/weapon.rs
Normal file
176
rc_core/src/persist/weapon.rs
Normal file
@@ -0,0 +1,176 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
#[serde(default)]
|
||||
pub struct WeaponData {
|
||||
pub damage_inflicted: Option<i32>,
|
||||
pub protonium_damage_scale: Option<f32>,
|
||||
pub projectile_speed: Option<f32>,
|
||||
pub projectile_range: Option<f32>,
|
||||
pub base_inaccuracy: Option<f32>,
|
||||
pub base_air_inaccuracy: Option<f32>,
|
||||
pub movement_inaccuracy: Option<f32>,
|
||||
#[serde(alias="movement_max_threshold_speed")]
|
||||
pub movement_max_speed: Option<f32>,
|
||||
#[serde(alias="movement_min_threshold_speed")]
|
||||
pub movement_min_speed: Option<f32>,
|
||||
#[serde(alias="gun_rotation_threshold_slow")]
|
||||
pub gun_rotation_slow: Option<f32>,
|
||||
#[serde(alias="movement_inaccuracy_decay_time")]
|
||||
pub movement_inaccuracy_decay: Option<f32>,
|
||||
#[serde(alias="slow_rotation_inaccuracy_decay_time")]
|
||||
pub slow_rotation_decay: Option<f32>,
|
||||
#[serde(alias="quick_rotation_inaccuracy_decay_time")]
|
||||
pub quick_rotation_decay: Option<f32>,
|
||||
#[serde(alias="movement_inaccuracy_recovery_time")]
|
||||
pub movement_inaccuracy_recovery: Option<f32>,
|
||||
pub repeat_fire_inaccuracy_total_degrees: Option<f32>,
|
||||
#[serde(alias="repeat_fire_inaccuracy_decay_time")]
|
||||
pub repeat_fire_inaccuracy_decay: Option<f32>,
|
||||
#[serde(alias="repeat_fire_inaccuracy_recovery_time")]
|
||||
pub repeat_fire_innaccuracy_recovery: Option<f32>,
|
||||
pub fire_instant_accuracy_decay: Option<f32>, // degrees
|
||||
pub accuracy_non_recover_time: Option<f32>,
|
||||
#[serde(alias="accuracy_decay_time")]
|
||||
pub accuracy_decay: Option<f32>,
|
||||
pub damage_radius: Option<f32>,
|
||||
pub plasma_time_to_full_damage: Option<f32>,
|
||||
pub plasma_starting_radius_scale: Option<f32>,
|
||||
pub nano_dps: Option<f32>,
|
||||
pub nano_hps: Option<f32>,
|
||||
pub tesla_damage: Option<f32>,
|
||||
pub tesla_charges: Option<f32>,
|
||||
pub aeroflak_proximity_damage: Option<f32>,
|
||||
pub aeroflak_damage_radius: Option<f32>,
|
||||
pub aeroflak_explosion_radius: Option<f32>,
|
||||
pub aeroflak_ground_clearance: Option<f32>,
|
||||
pub aeroflak_max_stacks: Option<i32>,
|
||||
pub aeroflak_damage_per_stack: Option<i32>,
|
||||
#[serde(alias="aeroflak_buff_time_to_expire")]
|
||||
pub aeroflak_stack_expire: Option<f32>,
|
||||
#[serde(alias="cooldown_between_shots")]
|
||||
pub shot_cooldown: Option<f32>,
|
||||
pub smart_rotation_cooldown: Option<f32>,
|
||||
#[serde(alias="smart_rotation_extra_cooldown_time")]
|
||||
pub smart_rotation_cooldown_extra: Option<f32>,
|
||||
pub smart_rotation_max_stacks: Option<f32>,
|
||||
pub spin_up_time: Option<f32>,
|
||||
pub spin_down_time: Option<f32>,
|
||||
pub spin_initial_cooldown: Option<f32>,
|
||||
#[serde(default = "group_fire_scales_default")]
|
||||
pub group_fire_scales: Vec<f32>,
|
||||
pub mana_cost: Option<f32>,
|
||||
pub lock_time: Option<f32>,
|
||||
pub full_lock_release: Option<f32>,
|
||||
pub change_lock_time: Option<f32>,
|
||||
pub max_rotation_speed: Option<f32>,
|
||||
pub initial_rotation_speed: Option<f32>,
|
||||
pub rotation_acceleration: Option<f32>,
|
||||
pub nano_healing_priority_time: Option<f32>,
|
||||
pub module_range: Option<f32>,
|
||||
pub shield_lifetime: Option<f32>,
|
||||
pub teleport_time: Option<f32>,
|
||||
pub camera_time: Option<f32>,
|
||||
pub camera_delay: Option<f32>,
|
||||
pub to_invisible_speed: Option<f32>,
|
||||
pub to_invisible_duration: Option<f32>,
|
||||
pub to_visible_duration: Option<f32>,
|
||||
pub countdown_time: Option<f32>,
|
||||
pub stun_time: Option<f32>,
|
||||
pub stun_radius: Option<f32>,
|
||||
pub effect_duration: Option<f32>,
|
||||
}
|
||||
|
||||
fn group_fire_scales_default() -> Vec<f32> {
|
||||
vec![1.0]
|
||||
}
|
||||
|
||||
impl std::convert::Into<crate::data::weapon_list::WeaponData> for WeaponData {
|
||||
fn into(self) -> crate::data::weapon_list::WeaponData {
|
||||
crate::data::weapon_list::WeaponData {
|
||||
damage_inflicted: self.damage_inflicted,
|
||||
protonium_damage_scale: self.protonium_damage_scale,
|
||||
projectile_speed: self.projectile_speed,
|
||||
projectile_range: self.projectile_range,
|
||||
base_inaccuracy: self.base_inaccuracy,
|
||||
base_air_inaccuracy: self.base_air_inaccuracy,
|
||||
movement_inaccuracy: self.movement_inaccuracy,
|
||||
movement_max_speed: self.movement_max_speed,
|
||||
movement_min_speed: self.movement_min_speed,
|
||||
gun_rotation_slow: self.gun_rotation_slow,
|
||||
movement_inaccuracy_decay: self.movement_inaccuracy_decay,
|
||||
slow_rotation_decay: self.slow_rotation_decay,
|
||||
quick_rotation_decay: self.quick_rotation_decay,
|
||||
movement_inaccuracy_recovery: self.movement_inaccuracy_recovery,
|
||||
repeat_fire_inaccuracy_total_degrees: self.repeat_fire_inaccuracy_total_degrees,
|
||||
repeat_fire_inaccuracy_decay: self.repeat_fire_inaccuracy_decay,
|
||||
repeat_fire_innaccuracy_recovery: self.repeat_fire_innaccuracy_recovery,
|
||||
fire_instant_accuracy_decay: self.fire_instant_accuracy_decay, // degrees
|
||||
accuracy_non_recover_time: self.accuracy_non_recover_time,
|
||||
accuracy_decay: self.accuracy_decay,
|
||||
damage_radius: self.damage_radius,
|
||||
plasma_time_to_full_damage: self.plasma_time_to_full_damage,
|
||||
plasma_starting_radius_scale: self.plasma_starting_radius_scale,
|
||||
nano_dps: self.nano_dps,
|
||||
nano_hps: self.nano_hps,
|
||||
tesla_damage: self.tesla_damage,
|
||||
tesla_charges: self.tesla_charges,
|
||||
aeroflak_proximity_damage: self.aeroflak_proximity_damage,
|
||||
aeroflak_damage_radius: self.aeroflak_damage_radius,
|
||||
aeroflak_explosion_radius: self.aeroflak_explosion_radius,
|
||||
aeroflak_ground_clearance: self.aeroflak_ground_clearance,
|
||||
aeroflak_max_stacks: self.aeroflak_max_stacks,
|
||||
aeroflak_damage_per_stack: self.aeroflak_damage_per_stack,
|
||||
aeroflak_stack_expire: self.aeroflak_stack_expire,
|
||||
shot_cooldown: self.shot_cooldown,
|
||||
smart_rotation_cooldown: self.smart_rotation_cooldown,
|
||||
smart_rotation_cooldown_extra: self.smart_rotation_cooldown_extra,
|
||||
smart_rotation_max_stacks: self.smart_rotation_max_stacks,
|
||||
spin_up_time: self.spin_up_time,
|
||||
spin_down_time: self.spin_down_time,
|
||||
spin_initial_cooldown: self.spin_initial_cooldown,
|
||||
group_fire_scales: self.group_fire_scales,
|
||||
mana_cost: self.mana_cost,
|
||||
lock_time: self.lock_time,
|
||||
full_lock_release: self.full_lock_release,
|
||||
change_lock_time: self.change_lock_time,
|
||||
max_rotation_speed: self.max_rotation_speed,
|
||||
initial_rotation_speed: self.initial_rotation_speed,
|
||||
rotation_acceleration: self.rotation_acceleration,
|
||||
nano_healing_priority_time: self.nano_healing_priority_time,
|
||||
module_range: self.module_range,
|
||||
shield_lifetime: self.shield_lifetime,
|
||||
teleport_time: self.teleport_time,
|
||||
camera_time: self.camera_time,
|
||||
camera_delay: self.camera_delay,
|
||||
to_invisible_speed: self.to_invisible_speed,
|
||||
to_invisible_duration: self.to_invisible_duration,
|
||||
to_visible_duration: self.to_visible_duration,
|
||||
countdown_time: self.countdown_time,
|
||||
stun_time: self.stun_time,
|
||||
stun_radius: self.stun_radius,
|
||||
effect_duration: self.effect_duration,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
pub struct WeaponUpgradeInfo {
|
||||
pub xp: f64,
|
||||
pub rating: i32,
|
||||
pub rank: i32,
|
||||
pub power: i32,
|
||||
}
|
||||
|
||||
impl WeaponUpgradeInfo {
|
||||
pub fn into_data(self, tier: super::ItemTier, type_: super::ItemCategory) -> crate::data::weapon_upgrade::WeaponUpgradeInfo {
|
||||
crate::data::weapon_upgrade::WeaponUpgradeInfo {
|
||||
tier: tier.into(),
|
||||
type_: type_.into(),
|
||||
xp: self.xp,
|
||||
rating: self.rating,
|
||||
rank: self.rank,
|
||||
power: self.power,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user