Better ChangeAvatarReq handling

This commit is contained in:
xeon 2024-09-02 13:59:11 +03:00
parent 574aaa5469
commit 97068a5be2

View file

@ -1,10 +1,12 @@
use common::net::tools::Packet; use common::net::tools::Packet;
use data::math_def::Vector3;
use proto::{ChangeAvatarRsp, Retcode, SetUpAvatarTeamRsp}; use proto::{ChangeAvatarRsp, Retcode, SetUpAvatarTeamRsp};
use crate::player::Player; use crate::player::Player;
use super::get_proto; 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( pub fn on_set_up_avatar_team_req(
player: &Rc<Player>, 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(); rsp.retcode = Retcode::RetSucc.into();
} else { } else {
let avatar_comp = player.player_avatar_comp.borrow(); let avatar_comp = player.player_avatar_comp.borrow();
println!("{req:?}");
if let Err(ret) = avatar_comp.check_change_cur_avatar(req.guid) { if let Err(ret) = avatar_comp.check_change_cur_avatar(req.guid) {
tracing::info!("check_change_cur_avatar ret:{ret:?}, guid:{}", req.guid); tracing::info!("check_change_cur_avatar ret:{ret:?}, guid:{}", req.guid);
rsp.retcode = ret.into(); rsp.retcode = ret.into();
} else { } else {
if req.is_move { 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); 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(); rsp.retcode = Retcode::RetFail.into();
} }
player.send_proto(rsp);
Ok(()) Ok(())
} }