Interaction distance check, better text

This commit is contained in:
Joshua Barretto 2024-01-21 17:57:05 +00:00
parent e231b8f9c1
commit 4cbec5d93c
5 changed files with 23 additions and 19 deletions

View File

@ -40,6 +40,7 @@ hud-zoom_lock_indicator-remind = Zoom locked
hud-zoom_lock_indicator-enable = Camera zoom locked hud-zoom_lock_indicator-enable = Camera zoom locked
hud-zoom_lock_indicator-disable = Camera zoom unlocked hud-zoom_lock_indicator-disable = Camera zoom unlocked
hud-activate = Activate hud-activate = Activate
hud-deactivate = Deactivate
hud-collect = Collect hud-collect = Collect
hud-pick_up = Pick up hud-pick_up = Pick up
hud-open = Open hud-open = Open

View File

@ -4,6 +4,7 @@ pub const MAX_MOUNT_RANGE: f32 = 5.0;
pub const MAX_SPRITE_MOUNT_RANGE: f32 = 2.0; pub const MAX_SPRITE_MOUNT_RANGE: f32 = 2.0;
pub const MAX_TRADE_RANGE: f32 = 20.0; pub const MAX_TRADE_RANGE: f32 = 20.0;
pub const MAX_NPCINTERACT_RANGE: f32 = 30.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 GRAVITY: f32 = 25.0;
pub const FRIC_GROUND: f32 = 0.15; pub const FRIC_GROUND: f32 = 0.15;

View File

@ -16,7 +16,7 @@ use common::{
Inventory, LootOwner, Pos, SkillGroupKind, Inventory, LootOwner, Pos, SkillGroupKind,
}, },
consts::{ 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, SOUND_TRAVEL_DIST_PER_VOLUME,
}, },
event::EventBus, event::EventBus,
@ -473,13 +473,17 @@ pub fn handle_tame_pet(server: &mut Server, pet_entity: EcsEntity, owner_entity:
pub fn handle_block_interaction( pub fn handle_block_interaction(
server: &mut Server, server: &mut Server,
_entity: EcsEntity, entity: EcsEntity,
pos: VolumePos, pos: VolumePos,
interaction: BlockInteraction, interaction: BlockInteraction,
) { ) {
let state = server.state_mut(); let state = server.state_mut();
if matches!(&pos.kind, Volume::Terrain) { // TODO: Implement toggling lights on volume entities
if state.can_set_block(pos.pos) { if let Some(entity_pos) = state.ecs().read_storage::<Pos>().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 if let Some(new_block) = state
.terrain() .terrain()
.get(pos.pos) .get(pos.pos)
@ -489,7 +493,4 @@ pub fn handle_block_interaction(
state.set_block(pos.pos, new_block); state.set_block(pos.pos, new_block);
} }
} }
} else {
// TODO: Handle toggling lights on entities
}
} }

View File

@ -2162,9 +2162,9 @@ impl Hud {
i18n.get_msg("hud-read").to_string(), i18n.get_msg("hud-read").to_string(),
)], )],
// TODO: change to turn on/turn off? // TODO: change to turn on/turn off?
BlockInteraction::LightToggle(_) => vec![( BlockInteraction::LightToggle(enable) => vec![(
Some(GameInput::Interact), Some(GameInput::Interact),
i18n.get_msg("hud-activate").to_string(), i18n.get_msg(if *enable { "hud-activate" } else { "hud-deactivate" }).to_string(),
)], )],
}; };

View File

@ -10,7 +10,7 @@ use client::Client;
use common::{ use common::{
comp, comp,
comp::{ship::figuredata::VOXEL_COLLIDER_MANIFEST, tool::ToolKind, Collider, Content}, 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, link::Is,
mounting::{Mount, Rider, VolumePos, VolumeRider}, mounting::{Mount, Rider, VolumePos, VolumeRider},
terrain::{Block, TerrainGrid, UnlockKind}, terrain::{Block, TerrainGrid, UnlockKind},
@ -343,8 +343,9 @@ pub(super) fn select_interactable(
.filter(|(wpos, volume_pos, interaction)| { .filter(|(wpos, volume_pos, interaction)| {
match interaction { match interaction {
Interaction::Mount => !is_volume_rider.contains(player_entity) Interaction::Mount => !is_volume_rider.contains(player_entity)
&& wpos.distance_squared(player_pos) < MAX_SPRITE_MOUNT_RANGE * MAX_SPRITE_MOUNT_RANGE && 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), && !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, _ => true,
} }
}) })