Clean Code

Remove option to mount if pet is told to stay
This commit is contained in:
TelepathicWalrus 2023-05-06 10:14:42 +01:00 committed by Maxicarlos08
parent 25f1f8f6cb
commit 0648ba1bc6
No known key found for this signature in database
3 changed files with 19 additions and 16 deletions

View File

@ -132,7 +132,13 @@ pub fn handle_mount(server: &mut Server, rider: EcsEntity, mount: EcsEntity) {
is_mountable(mount_body, state.ecs().read_storage().get(rider)) is_mountable(mount_body, state.ecs().read_storage().get(rider))
}); });
if (is_pet_of(mount, rider_uid) || is_pet_of(rider, mount_uid)) && can_ride { let is_stay = state
.ecs()
.read_storage::<PetState>()
.get(mount)
.and_then(|x| x.stay_pos).is_some();
if (is_pet_of(mount, rider_uid) || is_pet_of(rider, mount_uid)) && can_ride && !is_stay {
drop(uids); drop(uids);
let _ = state.link(Mounting { let _ = state.link(Mounting {
mount: mount_uid, mount: mount_uid,

View File

@ -2426,23 +2426,23 @@ impl Hud {
)); ));
if !client.is_riding() if !client.is_riding()
&& is_mountable(body, bodies.get(client.entity())) && is_mountable(body, bodies.get(client.entity()))
&& pet_state.get(entity).and_then(|st| st.stay_pos).is_none()
{ {
options.push(( options.push((
GameInput::Mount, GameInput::Mount,
i18n.get_msg("hud-mount").to_string(), i18n.get_msg("hud-mount").to_string(),
)); ));
} }
let pet_stay = if pet_state.get(entity).and_then(|st| st.stay_pos).is_some() {
pet_state.get(entity).and_then(|st| st.stay_pos).is_some(); options.push((
match pet_stay {
false => options.push((
GameInput::StayFollow,
i18n.get_msg("hud-stay").to_string(),
)),
true => options.push((
GameInput::StayFollow, GameInput::StayFollow,
i18n.get_msg("hud-follow").to_string(), i18n.get_msg("hud-follow").to_string(),
)), ));
} else {
options.push((
GameInput::StayFollow,
i18n.get_msg("hud-stay").to_string(),
));
} }
} }
options options

View File

@ -949,17 +949,14 @@ impl PlayState for SessionState {
let mut close_pet = None; let mut close_pet = None;
if let Some(player_pos) = player_pos { if let Some(player_pos) = player_pos {
let alignment = close_pet = client.state().ecs().read_resource::<CachedSpatialGrid>().0
client.state().ecs().read_storage::<comp::Alignment>();
let spatial_grid =
client.state().ecs().read_resource::<CachedSpatialGrid>();
close_pet = spatial_grid.0
.in_circle_aabr(player_pos.0.xy(), MAX_MOUNT_RANGE) .in_circle_aabr(player_pos.0.xy(), MAX_MOUNT_RANGE)
.filter(|e| .filter(|e|
*e != client.entity() *e != client.entity()
) )
.filter(|e| .filter(|e|
matches!(alignment.get(*e), Some(comp::Alignment::Owned(owner)) if Some(*owner) == client.uid()) matches!(client.state().ecs().read_storage::<comp::Alignment>().get(*e),
Some(comp::Alignment::Owned(owner)) if Some(*owner) == client.uid())
) )
.min_by_key(|e| { .min_by_key(|e| {
OrderedFloat(client OrderedFloat(client