fix tethering

This commit is contained in:
Isse 2023-11-23 01:01:31 +01:00
parent 51c67d7394
commit 5a3e6316a5
5 changed files with 65 additions and 19 deletions

View File

@ -91,4 +91,8 @@ command-unimplemented-teleporter-spawn = Teleporter spawning is not implemented
command-kit-inventory-unavailable = Could not get inventory
command-inventory-cant-fit-item = Can't fit item to inventory
# Emitted by /disconnect_all when you dont exist (?)
command-you-dont-exist = You do not exist, so you cannot use this command
command-you-dont-exist = You do not exist, so you cannot use this command
command-destroyed-tethers = All tethers destroyed! You are now free
command-destroyed-no-tethers = You're not connected to any tethers
command-dismounted = Dismounted
command-no-dismount = You're not riding or being ridden

View File

@ -279,6 +279,14 @@ pub struct VolumeRiders {
riders: HashSet<Vec3<i32>>,
}
impl VolumeRiders {
pub fn clear(&mut self) -> bool {
let res = !self.riders.is_empty();
self.riders.clear();
res
}
}
impl Component for VolumeRiders {
type Storage = DenseVecStorage<Self>;
}

View File

@ -4581,22 +4581,36 @@ fn handle_tether(
fn handle_destroy_tethers(
server: &mut Server,
_client: EcsEntity,
client: EcsEntity,
target: EcsEntity,
_args: Vec<String>,
_action: &ServerChatCommand,
) -> CmdResult<()> {
server
let mut destroyed = false;
destroyed |= server
.state
.ecs()
.write_storage::<Is<common::tether::Leader>>()
.remove(target);
server
.remove(target)
.is_some();
destroyed |= server
.state
.ecs()
.write_storage::<Is<common::tether::Follower>>()
.remove(target);
Ok(())
.remove(target)
.is_some();
if destroyed {
server.notify_client(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::localized("command-destroyed-tethers"),
),
);
Ok(())
} else {
Err(Content::localized("command-destroyed-no-tethers"))
}
}
fn handle_mount(
@ -4616,7 +4630,7 @@ fn handle_mount(
server
.state
.link(common::mounting::Mounting { mount, rider })
.map_err(|_| "Failed to tether entities".into())
.map_err(|_| "Failed to mount entities".into())
} else {
Err("Mount and/or rider doesn't have an Uid component.".into())
}
@ -4627,30 +4641,47 @@ fn handle_mount(
fn handle_dismount(
server: &mut Server,
_client: EcsEntity,
client: EcsEntity,
target: EcsEntity,
_args: Vec<String>,
_action: &ServerChatCommand,
) -> CmdResult<()> {
server
let mut destroyed = false;
destroyed |= server
.state
.ecs()
.write_storage::<Is<common::mounting::Rider>>()
.remove(target);
server
.remove(target)
.is_some();
destroyed |= server
.state
.ecs()
.write_storage::<Is<common::mounting::VolumeRider>>()
.remove(target);
server
.remove(target)
.is_some();
destroyed |= server
.state
.ecs()
.write_storage::<Is<common::mounting::Mount>>()
.remove(target);
server
.remove(target)
.is_some();
destroyed |= server
.state
.ecs()
.write_storage::<common::mounting::VolumeRiders>()
.remove(target);
Ok(())
.get_mut(target)
.map_or(false, |volume_riders| volume_riders.clear());
if destroyed {
server.notify_client(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::localized("command-dismounted"),
),
);
Ok(())
} else {
Err(Content::localized("command-no-dismount"))
}
}

View File

@ -31,6 +31,7 @@ use common::{
resources::{Secs, Time, TimeOfDay},
rtsim::{Actor, RtSimEntity},
slowjob::SlowJobPool,
tether::Tethered,
uid::{IdMaps, Uid},
util::Dir,
LoadoutBuilder, ViewDistances,
@ -1164,6 +1165,7 @@ impl StateExt for State {
maintain_link::<Mounting>(self);
maintain_link::<VolumeMounting>(self);
maintain_link::<Tethered>(self);
}
fn delete_entity_recorded(

View File

@ -216,7 +216,8 @@ pub fn run_command(
.ok_or("No player entity")?,
ident => {
return Err(format!(
"Expected target/selected/viewpoint/mount/rider found {ident}"
"Expected target/selected/viewpoint/mount/rider/self after '@' found \
{ident}"
));
},
};