Better interact handling (fixes Nicole dialogue) (still temporary impl)

This commit is contained in:
xeon 2024-05-30 22:26:18 +03:00
parent 27ca664829
commit 1a41d4b07b
4 changed files with 76 additions and 40 deletions

View file

@ -27,6 +27,8 @@ pub enum ConfigValue {
pub enum ConfigEventType { pub enum ConfigEventType {
OnStart, OnStart,
OnEnd, OnEnd,
OnBro,
OnSis,
#[serde(other)] #[serde(other)]
Unknown, Unknown,
} }

View file

@ -42,8 +42,8 @@ impl SceneUnitManager {
uid uid
} }
pub async fn get(&self, uid: u64) -> SceneUnitProtocolInfo { pub async fn get(&self, uid: u64) -> Option<SceneUnitProtocolInfo> {
self.units.read().await.get(&uid).unwrap().clone() self.units.read().await.get(&uid).map(|u| u.clone())
} }
pub async fn sync(&self, scene_uid: u64, section_id: i32) -> PtcSyncSceneUnitArg { pub async fn sync(&self, scene_uid: u64, section_id: i32) -> PtcSyncSceneUnitArg {
@ -113,7 +113,7 @@ impl SceneUnitManager {
1002, 1002,
0, 0,
phashmap![( phashmap![(
19900062, 10000009,
create_interact( create_interact(
0, 0,
1, 1,

View file

@ -12,21 +12,34 @@ pub async fn on_rpc_run_event_graph(
session: &NetworkSession, session: &NetworkSession,
arg: &RpcRunEventGraphArg, arg: &RpcRunEventGraphArg,
) -> Result<RpcRunEventGraphRet> { ) -> Result<RpcRunEventGraphRet> {
tracing::info!("RunEventGraph requested");
let unit = session.context.scene_unit_manager.get(arg.owner_uid).await; let unit = session.context.scene_unit_manager.get(arg.owner_uid).await;
let SceneUnitProtocolInfo::NpcProtocolInfo { tag, id, .. } = unit; let interact_id = match unit {
let main_city_object = data::get_main_city_object(tag, id).unwrap(); Some(SceneUnitProtocolInfo::NpcProtocolInfo { interacts_info, .. })
if interacts_info.len() != 0 =>
{
*interacts_info.iter().next().unwrap().0
}
Some(SceneUnitProtocolInfo::NpcProtocolInfo { tag, id, .. }) => {
let main_city_object = data::get_main_city_object(tag, id).unwrap();
*main_city_object.default_interact_ids.first().unwrap()
}
None => {
return Ok(RpcRunEventGraphRet::error(
ErrorCode::EntityNotExist,
Vec::new(),
))
}
};
let mut ptc_sync_event_info = PtcSyncEventInfoArg { let mut ptc_sync_event_info = PtcSyncEventInfoArg {
owner_type: EventGraphOwnerType::SceneUnit, owner_type: arg.owner_type,
owner_uid: arg.owner_uid, owner_uid: arg.owner_uid,
updated_events: pdkhashmap![], updated_events: pdkhashmap![],
}; };
ptc_sync_event_info.updated_events.insert( ptc_sync_event_info.updated_events.insert(
*main_city_object.default_interact_ids.first().unwrap(), interact_id,
100, 100,
EventInfo { EventInfo {
id: 100, id: 100,
@ -52,8 +65,6 @@ pub async fn on_rpc_finish_event_graph_perform_show(
session: &NetworkSession, session: &NetworkSession,
arg: &RpcFinishEventGraphPerformShowArg, arg: &RpcFinishEventGraphPerformShowArg,
) -> Result<RpcFinishEventGraphPerformShowRet> { ) -> Result<RpcFinishEventGraphPerformShowRet> {
tracing::info!("FinishEventGraphPerformShow");
let mut ptc_sync_event_info = PtcSyncEventInfoArg { let mut ptc_sync_event_info = PtcSyncEventInfoArg {
owner_type: EventGraphOwnerType::SceneUnit, owner_type: EventGraphOwnerType::SceneUnit,
owner_uid: arg.owner_uid, owner_uid: arg.owner_uid,
@ -87,38 +98,63 @@ pub async fn on_rpc_interact_with_unit(
session: &NetworkSession, session: &NetworkSession,
arg: &RpcInteractWithUnitArg, arg: &RpcInteractWithUnitArg,
) -> Result<RpcInteractWithUnitRet> { ) -> Result<RpcInteractWithUnitRet> {
tracing::info!("InteractWithUnit"); tracing::info!(
"InteractWithUnit: unit_uid: {}, interaction: {}",
arg.unit_uid,
arg.interaction
);
let unit = session.context.scene_unit_manager.get(arg.unit_uid).await; let unit = session.context.scene_unit_manager.get(arg.unit_uid).await;
let SceneUnitProtocolInfo::NpcProtocolInfo { tag, id, .. } = unit; let interact_id = match unit {
let main_city_object = data::get_main_city_object(tag, id).unwrap(); Some(SceneUnitProtocolInfo::NpcProtocolInfo { interacts_info, .. })
if interacts_info.len() != 0 =>
let mut ptc_sync_event_info = PtcSyncEventInfoArg { {
owner_type: EventGraphOwnerType::SceneUnit, *interacts_info.iter().next().unwrap().0
owner_uid: arg.unit_uid, }
updated_events: pdkhashmap![], Some(SceneUnitProtocolInfo::NpcProtocolInfo { tag, id, .. }) => {
let main_city_object = data::get_main_city_object(tag, id).unwrap();
*main_city_object.default_interact_ids.first().unwrap()
}
None => {
return Ok(RpcInteractWithUnitRet::error(
ErrorCode::EntityNotExist,
Vec::new(),
))
}
}; };
ptc_sync_event_info.updated_events.insert( // 0 - ServerInteractiveSystem::TriggerEnterEvent
*main_city_object.default_interact_ids.first().unwrap(), // 1 - ServerInteractiveSystem::TriggerExitEvent
100, // 2 - ServerInteractiveSystem::TriggerInteractDirectly
EventInfo { if arg.interaction == 2 {
id: 100, let mut ptc_sync_event_info = PtcSyncEventInfoArg {
cur_action_id: 101, owner_type: EventGraphOwnerType::SceneUnit,
action_move_path: Vec::from([101]), owner_uid: arg.unit_uid,
state: EventState::WaitingClient, updated_events: pdkhashmap![],
prev_state: EventState::Running, };
cur_action_info: ActionInfo::None {},
cur_action_state: ActionState::Init, ptc_sync_event_info.updated_events.insert(
predicated_failed_actions: phashset![], interact_id,
stack_frames: Vec::new(), 100,
}, EventInfo {
); id: 100,
cur_action_id: 101,
action_move_path: Vec::from([101]),
state: EventState::WaitingClient,
prev_state: EventState::Running,
cur_action_info: ActionInfo::None {},
cur_action_state: ActionState::Init,
predicated_failed_actions: phashset![],
stack_frames: Vec::new(),
},
);
session
.send_rpc_arg(PTC_SYNC_EVENT_INFO_ID, &ptc_sync_event_info)
.await?;
}
session
.send_rpc_arg(PTC_SYNC_EVENT_INFO_ID, &ptc_sync_event_info)
.await?;
Ok(RpcInteractWithUnitRet::new()) Ok(RpcInteractWithUnitRet::new())
} }
@ -141,8 +177,6 @@ pub async fn on_rpc_save_pos_in_main_city(
_session: &NetworkSession, _session: &NetworkSession,
_arg: &RpcSavePosInMainCityArg, _arg: &RpcSavePosInMainCityArg,
) -> Result<RpcSavePosInMainCityRet> { ) -> Result<RpcSavePosInMainCityRet> {
tracing::info!("MainCity pos updated");
Ok(RpcSavePosInMainCityRet::new()) Ok(RpcSavePosInMainCityRet::new())
} }

View file

@ -683,7 +683,7 @@ pub enum InteractTarget {
TriggerBox = 1, TriggerBox = 1,
} }
#[derive(OctData, Clone, Debug)] #[derive(OctData, Clone, Copy, Debug)]
#[repr(i16)] #[repr(i16)]
pub enum EventGraphOwnerType { pub enum EventGraphOwnerType {
Scene = 0, Scene = 0,