From 92ab8dab9ac8f9463efc131c827aac2c51df14cc Mon Sep 17 00:00:00 2001 From: Maxicarlos08 Date: Tue, 1 Aug 2023 20:56:55 +0200 Subject: [PATCH] require interaction to start teleportation --- assets/voxygen/i18n/en/hud/misc.ftl | 1 + client/src/lib.rs | 6 ++++ common/src/comp/controller.rs | 1 + common/src/comp/teleport.rs | 1 - common/src/event.rs | 4 +++ common/systems/src/controller.rs | 8 +++++ server/src/events/entity_manipulation.rs | 39 ++++++++++++++++++---- server/src/events/mod.rs | 7 ++-- server/src/sys/teleporter.rs | 21 ++++-------- voxygen/src/hud/mod.rs | 2 +- voxygen/src/session/mod.rs | 41 +++++++++++++----------- 11 files changed, 87 insertions(+), 44 deletions(-) diff --git a/assets/voxygen/i18n/en/hud/misc.ftl b/assets/voxygen/i18n/en/hud/misc.ftl index b8644d3436..cc99b03fe2 100644 --- a/assets/voxygen/i18n/en/hud/misc.ftl +++ b/assets/voxygen/i18n/en/hud/misc.ftl @@ -39,6 +39,7 @@ hud-auto_walk_indicator = Auto walk/swim active hud-zoom_lock_indicator-remind = Zoom locked hud-zoom_lock_indicator-enable = Camera zoom locked hud-zoom_lock_indicator-disable = Camera zoom unlocked +hud-activate = Activate hud-collect = Collect hud-pick_up = Pick up hud-open = Open diff --git a/client/src/lib.rs b/client/src/lib.rs index cd07e42870..122ec37837 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1625,6 +1625,12 @@ impl Client { } } + pub fn activate_portal(&mut self, portal: Uid) { + self.send_msg(ClientGeneral::ControlEvent(ControlEvent::ActivatePortal( + portal, + ))); + } + fn control_action(&mut self, control_action: ControlAction) { if let Some(controller) = self .state diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index c0e1e82159..fe84c1f642 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -158,6 +158,7 @@ pub enum ControlEvent { auxiliary_key: ability::AuxiliaryKey, new_ability: ability::AuxiliaryAbility, }, + ActivatePortal(Uid), } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/src/comp/teleport.rs b/common/src/comp/teleport.rs index 63fbd4c2aa..816aabb1e1 100644 --- a/common/src/comp/teleport.rs +++ b/common/src/comp/teleport.rs @@ -17,7 +17,6 @@ impl Component for Teleporter { #[derive(Copy, Clone, Debug, PartialEq)] pub struct Teleporting { - pub teleport_start: Time, pub portal: Entity, pub end_time: Time, } diff --git a/common/src/event.rs b/common/src/event.rs index 7b23bcc33e..0090f7d9a8 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -336,6 +336,10 @@ pub enum ServerEvent { entity: EcsEntity, position: Vec3, }, + StartTeleporting { + entity: EcsEntity, + portal: EcsEntity, + } } pub struct EventBus { diff --git a/common/systems/src/controller.rs b/common/systems/src/controller.rs index 9da0652d13..7d713ca4cc 100644 --- a/common/systems/src/controller.rs +++ b/common/systems/src/controller.rs @@ -138,6 +138,14 @@ impl<'a> System<'a> for Sys { stance: Stance::None, }); }, + ControlEvent::ActivatePortal(portal_uid) => { + if let Some(portal) = read_data.id_maps.uid_entity(portal_uid) { + server_emitter.emit(ServerEvent::StartTeleporting { + entity, + portal, + }); + } + } } } } diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 533d0b0d86..3d6672135e 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -8,7 +8,7 @@ use crate::{ BuffKind, BuffSource, PhysicsState, }, rtsim, - sys::terrain::SAFE_ZONE_RADIUS, + sys::{teleporter::TELEPORT_RADIUS, terrain::SAFE_ZONE_RADIUS}, Server, SpawnPoint, StateExt, }; use authc::Uuid; @@ -1657,11 +1657,7 @@ pub fn handle_remove_light_emitter(server: &mut Server, entity: EcsEntity) { .remove(entity); } -pub fn handle_teleport_to_position_event( - server: &mut Server, - entity: EcsEntity, - position: Vec3, -) { +pub fn handle_teleport_to_position(server: &mut Server, entity: EcsEntity, position: Vec3) { let ecs = server.state.ecs(); ecs.write_storage::() @@ -1673,3 +1669,34 @@ pub fn handle_teleport_to_position_event( .get_mut(entity) .map(|forced_update| forced_update.update()); } + +pub fn handle_start_teleporting(server: &mut Server, entity: EcsEntity, portal: EcsEntity) { + let ecs = server.state.ecs(); + let positions = ecs.read_storage::(); + let mut teleportings = ecs.write_storage::(); + let now = ecs.read_resource::