use AvatarBaseID instead of raw integer in more places
This commit is contained in:
parent
a7da14c109
commit
d3cd213d27
6 changed files with 44 additions and 23 deletions
|
@ -27,7 +27,7 @@ pub async fn avatar(
|
|||
|
||||
let should_save = {
|
||||
let mut player = player_lock.lock().await;
|
||||
player.basic_data_model.frontend_avatar_id = avatar_id.value() as i32;
|
||||
player.basic_data_model.frontend_avatar_id = Some(avatar_id);
|
||||
player.current_session_id().is_none()
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use data::tables::AvatarBaseID;
|
||||
|
||||
use crate::logic::game::{GameInstance, LogicError};
|
||||
use crate::logic::procedure::ProcedureAction;
|
||||
|
||||
|
@ -20,6 +22,8 @@ pub async fn on_create_role(
|
|||
player: &mut Player,
|
||||
req: CreateRoleCsReq,
|
||||
) -> NetResult<CreateRoleScRsp> {
|
||||
let avatar_id = AvatarBaseID::new(req.avatar_id).ok_or(Retcode::RetFail)?;
|
||||
|
||||
let GameInstance::Fresh(fresh_game) = &mut player.game_instance else {
|
||||
return Err(NetError::from(Retcode::RetFail));
|
||||
};
|
||||
|
@ -29,7 +33,7 @@ pub async fn on_create_role(
|
|||
.on_action(ProcedureAction::SelectRole)
|
||||
.map_err(LogicError::from)?;
|
||||
|
||||
player.set_frontend_avatar(req.avatar_id as i32)?;
|
||||
player.set_frontend_avatar(avatar_id)?;
|
||||
|
||||
session
|
||||
.notify(PlayerSyncScNotify {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use data::tables::SectionConfigID;
|
||||
use data::tables::{AvatarBaseID, SectionConfigID};
|
||||
use proto::*;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -8,7 +8,7 @@ use super::NapGameMode;
|
|||
|
||||
pub struct FrontendGame {
|
||||
section_id: SectionConfigID,
|
||||
frontend_avatar_id: i32,
|
||||
frontend_avatar_id: AvatarBaseID,
|
||||
camera_x: u32,
|
||||
camera_y: u32,
|
||||
born_pos: String,
|
||||
|
@ -18,12 +18,15 @@ pub struct FrontendGame {
|
|||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum FrontendGameError {}
|
||||
pub enum FrontendGameError {
|
||||
#[error("player's frontend avatar is None")]
|
||||
NoFrontendAvatar,
|
||||
}
|
||||
|
||||
impl FrontendGame {
|
||||
pub fn new(
|
||||
section_id: SectionConfigID,
|
||||
avatar_id: i32,
|
||||
avatar_id: AvatarBaseID,
|
||||
main_city_time: MainCityTime,
|
||||
avatar_pos: Vector3f,
|
||||
avatar_rot: Vector3f,
|
||||
|
@ -50,7 +53,7 @@ impl NapGameMode for FrontendGame {
|
|||
scene_type: self.scene_type() as u32,
|
||||
hall_scene_info: Some(HallSceneInfo {
|
||||
section_id: self.section_id.value(),
|
||||
frontend_avatar_id: self.frontend_avatar_id as u32,
|
||||
frontend_avatar_id: self.frontend_avatar_id.value(),
|
||||
camera_x: self.camera_x,
|
||||
camera_y: self.camera_y,
|
||||
born_pos: self
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use data::tables::ProcedureConfigID;
|
||||
use data::tables::{AvatarBaseID, ProcedureConfigID};
|
||||
use proto::{BasicDataModelBin, PlayerBasicInfo};
|
||||
|
||||
pub struct BasicDataModel {
|
||||
|
@ -6,7 +6,7 @@ pub struct BasicDataModel {
|
|||
pub exp: u32,
|
||||
pub profile_icon: u32,
|
||||
pub nick_name: Option<String>,
|
||||
pub frontend_avatar_id: i32,
|
||||
pub frontend_avatar_id: Option<AvatarBaseID>,
|
||||
pub beginner_procedure_id: Option<ProcedureConfigID>,
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ impl Default for BasicDataModel {
|
|||
exp: 0,
|
||||
profile_icon: 3200000,
|
||||
nick_name: None,
|
||||
frontend_avatar_id: 0,
|
||||
frontend_avatar_id: None,
|
||||
beginner_procedure_id: Some(ProcedureConfigID::new_unchecked(1)),
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,17 @@ impl Default for BasicDataModel {
|
|||
|
||||
impl BasicDataModel {
|
||||
pub fn player_basic_info(&self) -> PlayerBasicInfo {
|
||||
let avatar_id = self
|
||||
.frontend_avatar_id
|
||||
.map(|i| i.value())
|
||||
.unwrap_or_default();
|
||||
|
||||
PlayerBasicInfo {
|
||||
nick_name: self.nick_name.clone().unwrap_or_default(),
|
||||
exp: self.exp,
|
||||
level: self.level,
|
||||
avatar_id: self.frontend_avatar_id as u32,
|
||||
frontend_avatar_id: self.frontend_avatar_id as u32,
|
||||
avatar_id,
|
||||
frontend_avatar_id: avatar_id,
|
||||
kbjleelonfe: self.profile_icon,
|
||||
..Default::default()
|
||||
}
|
||||
|
@ -41,7 +46,10 @@ impl BasicDataModel {
|
|||
level: bin.level,
|
||||
exp: bin.exp,
|
||||
profile_icon: bin.profile_icon,
|
||||
frontend_avatar_id: bin.frontend_avatar_id,
|
||||
frontend_avatar_id: match bin.frontend_avatar_id {
|
||||
1.. => AvatarBaseID::new(bin.frontend_avatar_id as u32),
|
||||
_ => None,
|
||||
},
|
||||
beginner_procedure_id: match bin.beginner_procedure_id {
|
||||
1.. => ProcedureConfigID::new(bin.beginner_procedure_id as u32),
|
||||
_ => None,
|
||||
|
@ -58,7 +66,10 @@ impl BasicDataModel {
|
|||
level: self.level,
|
||||
exp: self.exp,
|
||||
profile_icon: self.profile_icon,
|
||||
frontend_avatar_id: self.frontend_avatar_id,
|
||||
frontend_avatar_id: self
|
||||
.frontend_avatar_id
|
||||
.map(|i| i.value() as i32)
|
||||
.unwrap_or(-1),
|
||||
nick_name: self.nick_name.clone().unwrap_or_default(),
|
||||
beginner_procedure_id: self
|
||||
.beginner_procedure_id
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use data::tables::{self, AvatarBaseID};
|
||||
use proto::{ItemStatic, PlayerDataBin, Retcode};
|
||||
|
||||
use super::game::{FrontendGame, GameInstance, LogicError};
|
||||
use super::game::{FrontendGame, FrontendGameError, GameInstance, LogicError};
|
||||
use super::item::{ItemModel, ItemUID};
|
||||
use super::main_city_model::MainCityModel;
|
||||
use super::role::RoleModel;
|
||||
|
@ -19,7 +19,7 @@ pub struct Player {
|
|||
}
|
||||
|
||||
impl Player {
|
||||
const MAIN_AVATAR_IDS: [i32; 2] = [2011, 2021];
|
||||
const MAIN_AVATAR_IDS: [u32; 2] = [2011, 2021];
|
||||
|
||||
pub fn save_to_bin(&self) -> PlayerDataBin {
|
||||
PlayerDataBin {
|
||||
|
@ -62,11 +62,15 @@ impl Player {
|
|||
}
|
||||
|
||||
pub fn init_frontend_game(&mut self) -> Result<(), LogicError> {
|
||||
let Some(frontend_avatar_id) = self.basic_data_model.frontend_avatar_id else {
|
||||
return Err(LogicError::from(FrontendGameError::NoFrontendAvatar));
|
||||
};
|
||||
|
||||
let main_city = &self.main_city_model;
|
||||
self.game_instance = GameInstance::Frontend(
|
||||
FrontendGame::new(
|
||||
main_city.section_id,
|
||||
self.basic_data_model.frontend_avatar_id,
|
||||
frontend_avatar_id,
|
||||
main_city.main_city_time.clone(),
|
||||
main_city.position.clone(),
|
||||
main_city.rotation.clone(),
|
||||
|
@ -77,16 +81,16 @@ impl Player {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_frontend_avatar(&mut self, id: i32) -> Result<(), Retcode> {
|
||||
(self.basic_data_model.frontend_avatar_id == 0)
|
||||
pub fn set_frontend_avatar(&mut self, id: AvatarBaseID) -> Result<(), Retcode> {
|
||||
(self.basic_data_model.frontend_avatar_id.is_none())
|
||||
.then_some(())
|
||||
.ok_or(Retcode::RetFail)?;
|
||||
|
||||
(Self::MAIN_AVATAR_IDS.contains(&id))
|
||||
(Self::MAIN_AVATAR_IDS.contains(&id.value()))
|
||||
.then_some(())
|
||||
.ok_or(Retcode::RetFail)?;
|
||||
|
||||
self.basic_data_model.frontend_avatar_id = id;
|
||||
self.basic_data_model.frontend_avatar_id = Some(id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
config,
|
||||
});
|
||||
|
||||
let command_mgr = CommandManager::new(state.clone());
|
||||
|
||||
if let Some((rl, out)) = rl {
|
||||
let command_mgr = CommandManager::new(state.clone());
|
||||
tokio::spawn(async move { command_mgr.run(rl, out).await });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue