Better ChangeAvatarReq handling
This commit is contained in:
parent
574aaa5469
commit
97068a5be2
1 changed files with 18 additions and 2 deletions
|
@ -1,10 +1,12 @@
|
|||
use common::net::tools::Packet;
|
||||
use data::math_def::Vector3;
|
||||
use proto::{ChangeAvatarRsp, Retcode, SetUpAvatarTeamRsp};
|
||||
|
||||
use crate::player::Player;
|
||||
|
||||
use super::get_proto;
|
||||
use std::{error::Error, rc::Rc};
|
||||
use crate::entity::Entity;
|
||||
use std::{cell::RefCell, error::Error, rc::Rc};
|
||||
|
||||
pub fn on_set_up_avatar_team_req(
|
||||
player: &Rc<Player>,
|
||||
|
@ -88,12 +90,25 @@ pub fn on_change_avatar_req(player: &Rc<Player>, packet: Packet) -> Result<(), B
|
|||
rsp.retcode = Retcode::RetSucc.into();
|
||||
} else {
|
||||
let avatar_comp = player.player_avatar_comp.borrow();
|
||||
println!("{req:?}");
|
||||
if let Err(ret) = avatar_comp.check_change_cur_avatar(req.guid) {
|
||||
tracing::info!("check_change_cur_avatar ret:{ret:?}, guid:{}", req.guid);
|
||||
rsp.retcode = ret.into();
|
||||
} else {
|
||||
if req.is_move {
|
||||
// TODO!
|
||||
if let Some(move_pos) = req.move_pos.as_ref() {
|
||||
let cur_avatar_ptr =
|
||||
player.player_avatar_comp.borrow().get_cur_avatar().unwrap();
|
||||
let cur_rot = cur_avatar_ptr.borrow().rotation().clone();
|
||||
// TODO: Entity::checkMoveSpeed
|
||||
let scene_ptr =
|
||||
player.player_scene_comp.borrow().get_cur_scene().unwrap();
|
||||
scene_ptr.borrow_mut().entity_move_to(
|
||||
cur_avatar_ptr as Rc<RefCell<dyn Entity>>,
|
||||
Vector3::from_client(move_pos),
|
||||
cur_rot,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let _ = avatar_comp.change_cur_avatar(req.guid, true);
|
||||
|
@ -113,5 +128,6 @@ pub fn on_change_avatar_req(player: &Rc<Player>, packet: Packet) -> Result<(), B
|
|||
rsp.retcode = Retcode::RetFail.into();
|
||||
}
|
||||
|
||||
player.send_proto(rsp);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue