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 {
OnStart,
OnEnd,
OnBro,
OnSis,
#[serde(other)]
Unknown,
}

View file

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

View file

@ -12,21 +12,34 @@ pub async fn on_rpc_run_event_graph(
session: &NetworkSession,
arg: &RpcRunEventGraphArg,
) -> Result<RpcRunEventGraphRet> {
tracing::info!("RunEventGraph requested");
let unit = session.context.scene_unit_manager.get(arg.owner_uid).await;
let SceneUnitProtocolInfo::NpcProtocolInfo { tag, id, .. } = unit;
let interact_id = match unit {
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 {
owner_type: EventGraphOwnerType::SceneUnit,
owner_type: arg.owner_type,
owner_uid: arg.owner_uid,
updated_events: pdkhashmap![],
};
ptc_sync_event_info.updated_events.insert(
*main_city_object.default_interact_ids.first().unwrap(),
interact_id,
100,
EventInfo {
id: 100,
@ -52,8 +65,6 @@ pub async fn on_rpc_finish_event_graph_perform_show(
session: &NetworkSession,
arg: &RpcFinishEventGraphPerformShowArg,
) -> Result<RpcFinishEventGraphPerformShowRet> {
tracing::info!("FinishEventGraphPerformShow");
let mut ptc_sync_event_info = PtcSyncEventInfoArg {
owner_type: EventGraphOwnerType::SceneUnit,
owner_uid: arg.owner_uid,
@ -87,13 +98,36 @@ pub async fn on_rpc_interact_with_unit(
session: &NetworkSession,
arg: &RpcInteractWithUnitArg,
) -> 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 SceneUnitProtocolInfo::NpcProtocolInfo { tag, id, .. } = unit;
let interact_id = match unit {
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(RpcInteractWithUnitRet::error(
ErrorCode::EntityNotExist,
Vec::new(),
))
}
};
// 0 - ServerInteractiveSystem::TriggerEnterEvent
// 1 - ServerInteractiveSystem::TriggerExitEvent
// 2 - ServerInteractiveSystem::TriggerInteractDirectly
if arg.interaction == 2 {
let mut ptc_sync_event_info = PtcSyncEventInfoArg {
owner_type: EventGraphOwnerType::SceneUnit,
owner_uid: arg.unit_uid,
@ -101,7 +135,7 @@ pub async fn on_rpc_interact_with_unit(
};
ptc_sync_event_info.updated_events.insert(
*main_city_object.default_interact_ids.first().unwrap(),
interact_id,
100,
EventInfo {
id: 100,
@ -119,6 +153,8 @@ pub async fn on_rpc_interact_with_unit(
session
.send_rpc_arg(PTC_SYNC_EVENT_INFO_ID, &ptc_sync_event_info)
.await?;
}
Ok(RpcInteractWithUnitRet::new())
}
@ -141,8 +177,6 @@ pub async fn on_rpc_save_pos_in_main_city(
_session: &NetworkSession,
_arg: &RpcSavePosInMainCityArg,
) -> Result<RpcSavePosInMainCityRet> {
tracing::info!("MainCity pos updated");
Ok(RpcSavePosInMainCityRet::new())
}

View file

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