From 4cbec5d93c83a06d57360bfae64f20ee2c66e8f0 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 21 Jan 2024 17:57:05 +0000 Subject: [PATCH] Interaction distance check, better text --- assets/voxygen/i18n/en/hud/misc.ftl | 1 + common/src/consts.rs | 1 + server/src/events/interaction.rs | 29 +++++++++++++++-------------- voxygen/src/hud/mod.rs | 4 ++-- voxygen/src/session/interactable.rs | 7 ++++--- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/assets/voxygen/i18n/en/hud/misc.ftl b/assets/voxygen/i18n/en/hud/misc.ftl index e1307e867e..8b72eb73dd 100644 --- a/assets/voxygen/i18n/en/hud/misc.ftl +++ b/assets/voxygen/i18n/en/hud/misc.ftl @@ -40,6 +40,7 @@ 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-deactivate = Deactivate hud-collect = Collect hud-pick_up = Pick up hud-open = Open diff --git a/common/src/consts.rs b/common/src/consts.rs index ea0017acdd..c03aa987f3 100644 --- a/common/src/consts.rs +++ b/common/src/consts.rs @@ -4,6 +4,7 @@ pub const MAX_MOUNT_RANGE: f32 = 5.0; pub const MAX_SPRITE_MOUNT_RANGE: f32 = 2.0; pub const MAX_TRADE_RANGE: f32 = 20.0; pub const MAX_NPCINTERACT_RANGE: f32 = 30.0; +pub const MAX_INTERACT_RANGE: f32 = 5.0; pub const GRAVITY: f32 = 25.0; pub const FRIC_GROUND: f32 = 0.15; diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index f5c5ef3bff..cc7923ffd6 100755 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -16,7 +16,7 @@ use common::{ Inventory, LootOwner, Pos, SkillGroupKind, }, consts::{ - MAX_MOUNT_RANGE, MAX_NPCINTERACT_RANGE, MAX_SPRITE_MOUNT_RANGE, + MAX_INTERACT_RANGE, MAX_MOUNT_RANGE, MAX_NPCINTERACT_RANGE, MAX_SPRITE_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME, }, event::EventBus, @@ -473,23 +473,24 @@ pub fn handle_tame_pet(server: &mut Server, pet_entity: EcsEntity, owner_entity: pub fn handle_block_interaction( server: &mut Server, - _entity: EcsEntity, + entity: EcsEntity, pos: VolumePos, interaction: BlockInteraction, ) { let state = server.state_mut(); - if matches!(&pos.kind, Volume::Terrain) { - if state.can_set_block(pos.pos) { - if let Some(new_block) = state - .terrain() - .get(pos.pos) - .ok() - .and_then(|block| block.apply_interaction(interaction)) - { - state.set_block(pos.pos, new_block); - } + // TODO: Implement toggling lights on volume entities + if let Some(entity_pos) = state.ecs().read_storage::().get(entity) + && matches!(&pos.kind, Volume::Terrain) + && entity_pos.0.distance_squared(pos.pos.as_()) < MAX_INTERACT_RANGE.powi(2) + && state.can_set_block(pos.pos) + { + if let Some(new_block) = state + .terrain() + .get(pos.pos) + .ok() + .and_then(|block| block.apply_interaction(interaction)) + { + state.set_block(pos.pos, new_block); } - } else { - // TODO: Handle toggling lights on entities } } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 3ba340f078..94151b2ccc 100755 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2162,9 +2162,9 @@ impl Hud { i18n.get_msg("hud-read").to_string(), )], // TODO: change to turn on/turn off? - BlockInteraction::LightToggle(_) => vec![( + BlockInteraction::LightToggle(enable) => vec![( Some(GameInput::Interact), - i18n.get_msg("hud-activate").to_string(), + i18n.get_msg(if *enable { "hud-activate" } else { "hud-deactivate" }).to_string(), )], }; diff --git a/voxygen/src/session/interactable.rs b/voxygen/src/session/interactable.rs index 05061d7c27..a2e0a5a9ca 100644 --- a/voxygen/src/session/interactable.rs +++ b/voxygen/src/session/interactable.rs @@ -10,7 +10,7 @@ use client::Client; use common::{ comp, comp::{ship::figuredata::VOXEL_COLLIDER_MANIFEST, tool::ToolKind, Collider, Content}, - consts::{MAX_PICKUP_RANGE, MAX_SPRITE_MOUNT_RANGE, TELEPORTER_RADIUS}, + consts::{MAX_INTERACT_RANGE, MAX_PICKUP_RANGE, MAX_SPRITE_MOUNT_RANGE, TELEPORTER_RADIUS}, link::Is, mounting::{Mount, Rider, VolumePos, VolumeRider}, terrain::{Block, TerrainGrid, UnlockKind}, @@ -343,8 +343,9 @@ pub(super) fn select_interactable( .filter(|(wpos, volume_pos, interaction)| { match interaction { Interaction::Mount => !is_volume_rider.contains(player_entity) - && wpos.distance_squared(player_pos) < MAX_SPRITE_MOUNT_RANGE * MAX_SPRITE_MOUNT_RANGE - && !is_volume_rider.join().any(|is_volume_rider| is_volume_rider.pos == *volume_pos), + && wpos.distance_squared(player_pos) < MAX_SPRITE_MOUNT_RANGE.powi(2) + && !is_volume_rider.join().any(|is_volume_rider| is_volume_rider.pos == *volume_pos), + Interaction::LightToggle(_) => wpos.distance_squared(player_pos) < MAX_INTERACT_RANGE.powi(2), _ => true, } })