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-disable = Camera zoom unlocked
hud-activate = Activate
hud-deactivate = Deactivate
hud-collect = Collect
hud-pick_up = Pick up
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_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;

View File

@ -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,13 +473,17 @@ 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) {
// TODO: Implement toggling lights on volume entities
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
.terrain()
.get(pos.pos)
@ -489,7 +493,4 @@ pub fn handle_block_interaction(
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(),
)],
// 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(),
)],
};

View File

@ -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
&& 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,
}
})