chore: impl methods for PlayerUID

This commit is contained in:
xeon 2024-05-31 20:41:19 +03:00
parent 7ef2b76a32
commit c59fe85e67
5 changed files with 31 additions and 14 deletions

View file

@ -59,7 +59,7 @@ where
pub async fn send_changes(&mut self, session: &NetworkSession) -> Result<&T> { pub async fn send_changes(&mut self, session: &NetworkSession) -> Result<&T> {
if self.player_info_changes.is_some() { if self.player_info_changes.is_some() {
let ptc_player_info_changed = PtcPlayerInfoChangedArg { let ptc_player_info_changed = PtcPlayerInfoChangedArg {
player_uid: session.player_uid().0, player_uid: session.player_uid().raw(),
player_info: self.player_info_changes.take().unwrap(), player_info: self.player_info_changes.take().unwrap(),
}; };

View file

@ -37,7 +37,7 @@ pub async fn on_rpc_hollow_move(
} }
let pos = PtcPositionInHollowChangedArg { let pos = PtcPositionInHollowChangedArg {
player_uid: session.player_uid().0, player_uid: session.player_uid().raw(),
hollow_level: arg.hollow_level, hollow_level: arg.hollow_level,
position: destination_pos, position: destination_pos,
}; };
@ -58,7 +58,7 @@ pub async fn on_rpc_end_battle(
) -> Result<RpcEndBattleRet> { ) -> Result<RpcEndBattleRet> {
tracing::info!("RpcEndBattle: {:?}", &arg); tracing::info!("RpcEndBattle: {:?}", &arg);
let player_uid = session.player_uid().0; let player_uid = session.player_uid().raw();
let (sync_event, hollow_finished) = session.context.hollow_grid_manager.battle_finished().await; let (sync_event, hollow_finished) = session.context.hollow_grid_manager.battle_finished().await;
if !hollow_finished { if !hollow_finished {
@ -219,7 +219,7 @@ pub async fn on_rpc_run_hollow_event_graph(
.await?; .await?;
let ptc_dungeon_quest_finished = PtcDungeonQuestFinishedArg { let ptc_dungeon_quest_finished = PtcDungeonQuestFinishedArg {
player_uid: session.player_uid().0, player_uid: session.player_uid().raw(),
quest_id: 1001000101, quest_id: 1001000101,
success: true, success: true,
reward_items: phashmap![], reward_items: phashmap![],
@ -249,7 +249,7 @@ pub async fn on_rpc_run_hollow_event_graph(
.await?; .await?;
let ptc_position_in_hollow_changed = PtcPositionInHollowChangedArg { let ptc_position_in_hollow_changed = PtcPositionInHollowChangedArg {
player_uid: session.player_uid().0, player_uid: session.player_uid().raw(),
hollow_level: 1, hollow_level: 1,
position: session position: session
.context .context
@ -371,13 +371,13 @@ pub async fn on_rpc_start_hollow_quest(
&session &session
.context .context
.hollow_grid_manager .hollow_grid_manager
.sync_hollow_maps(session.player_uid().0, scene_uid) .sync_hollow_maps(session.player_uid().raw(), scene_uid)
.await, .await,
) )
.await?; .await?;
let ptc_position_in_hollow_changed = PtcPositionInHollowChangedArg { let ptc_position_in_hollow_changed = PtcPositionInHollowChangedArg {
player_uid: session.player_uid().0, player_uid: session.player_uid().raw(),
hollow_level: 1, hollow_level: 1,
position: session position: session
.context .context

View file

@ -1,7 +1,10 @@
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use super::*; use super::*;
use crate::{game::util, net::session::AccountUID}; use crate::{
game::util,
net::session::{AccountUID, PlayerUID},
};
const DEFAULT_ACCOUNT_ID: u64 = 1; const DEFAULT_ACCOUNT_ID: u64 = 1;
@ -35,9 +38,9 @@ pub async fn on_rpc_create_player(
.players .players
.as_ref() .as_ref()
.unwrap() .unwrap()
.len() as u64; .len();
let player_uid = account_uid.0 * 100 + player_count + 1; let player_uid = PlayerUID::new(account_uid, player_count + 1);
session session
.ns_prop_mgr .ns_prop_mgr
.account_info .account_info
@ -46,9 +49,9 @@ pub async fn on_rpc_create_player(
.players .players
.as_mut() .as_mut()
.unwrap() .unwrap()
.push(player_uid); .push(player_uid.raw());
Ok(RpcCreatePlayerRet::new(player_uid)) Ok(RpcCreatePlayerRet::new(player_uid.raw()))
} }
pub async fn on_ptc_get_server_timestamp( pub async fn on_ptc_get_server_timestamp(

View file

@ -254,7 +254,7 @@ pub async fn on_rpc_enter_world(
let player_uid = *account.players.as_ref().unwrap().first().unwrap(); // get first id from list let player_uid = *account.players.as_ref().unwrap().first().unwrap(); // get first id from list
session session
.set_cur_player(PlayerUID(player_uid), create_player(player_uid)) .set_cur_player(PlayerUID::from(player_uid), create_player(player_uid))
.await?; .await?;
let item_manager = &session.context.item_manager; let item_manager = &session.context.item_manager;

View file

@ -17,7 +17,21 @@ use super::{Packet, RequestBody, ResponseBody};
pub struct AccountUID(pub u64); pub struct AccountUID(pub u64);
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct PlayerUID(pub u64); pub struct PlayerUID(u64);
impl PlayerUID {
pub const fn new(account_uid: AccountUID, index: usize) -> Self {
Self(account_uid.0 * 100 + index as u64)
}
pub const fn from(raw: u64) -> Self {
Self(raw)
}
pub const fn raw(&self) -> u64 {
self.0
}
}
pub struct NetworkSession { pub struct NetworkSession {
client_socket: Arc<Mutex<TcpStream>>, client_socket: Arc<Mutex<TcpStream>>,