Fix issue where controller events aren't processed while mounted. Fix non humanoids being able to climb and glide.

This commit is contained in:
Imbris
2019-12-31 16:37:55 -05:00
parent c9caf14877
commit 1acf08390a
6 changed files with 57 additions and 34 deletions

View File

@ -327,6 +327,24 @@ impl<'a> System<'a> for Sys {
// Or do nothing
continue;
}
// Process controller events
for event in controller.events.drain(..) {
match event {
ControlEvent::Mount(mountee_uid) => {
if let Some(mountee_entity) =
uid_allocator.retrieve_entity_internal(mountee_uid.id())
{
server_emitter.emit(ServerEvent::Mount(entity, mountee_entity));
}
}
ControlEvent::Unmount => server_emitter.emit(ServerEvent::Unmount(entity)),
ControlEvent::InventoryManip(manip) => {
server_emitter.emit(ServerEvent::InventoryManip(entity, manip))
} //ControlEvent::Respawn => server_emitter.emit(ServerEvent::Unmount(entity)),
}
}
// If mounted, character state is controlled by mount
if mount.is_some() {
character.movement = Sit;
@ -394,16 +412,17 @@ impl<'a> System<'a> for Sys {
// Any Action + Falling
(action_state, Fall) => {
character.movement = get_state_from_move_dir(&inputs.move_dir);
if inputs.glide.is_pressed() {
if inputs.glide.is_pressed() && can_glide(body) {
character.movement = Glide;
continue;
}
// Try to climb
if let (true, Some(_wall_dir)) = (
inputs.climb.is_pressed() | inputs.climb_down.is_pressed()
&& body.is_humanoid(),
(inputs.climb.is_pressed() | inputs.climb_down.is_pressed())
&& can_climb(body),
physics.on_wall,
) {
println!("here 1");
character.movement = Climb;
continue;
}
@ -530,10 +549,11 @@ impl<'a> System<'a> for Sys {
// Try to climb
if let (true, Some(_wall_dir)) = (
inputs.climb.is_pressed() | inputs.climb_down.is_pressed()
&& body.is_humanoid(),
(inputs.climb.is_pressed() | inputs.climb_down.is_pressed())
&& can_climb(body),
physics.on_wall,
) {
println!("here 2");
character.movement = Climb;
continue;
}
@ -578,9 +598,7 @@ impl<'a> System<'a> for Sys {
// While not on ground ...
else {
// Try to glide
if physics.on_wall == None
&& inputs.glide.is_pressed()
&& body.is_humanoid()
if physics.on_wall == None && inputs.glide.is_pressed() && can_glide(&body)
{
character.movement = Glide;
continue;
@ -652,7 +670,8 @@ impl<'a> System<'a> for Sys {
if !inputs.glide.is_pressed() {
character.movement = Fall;
} else if let Some(_wall_dir) = physics.on_wall {
} else if let (Some(_wall_dir), true) = (physics.on_wall, can_climb(body)) {
println!("here 3");
character.movement = Climb;
}
@ -681,23 +700,14 @@ impl<'a> System<'a> for Sys {
// character.movement = Fall;
// }
};
// Process other controller events
for event in controller.events.drain(..) {
match event {
ControlEvent::Mount(mountee_uid) => {
if let Some(mountee_entity) =
uid_allocator.retrieve_entity_internal(mountee_uid.id())
{
server_emitter.emit(ServerEvent::Mount(entity, mountee_entity));
}
}
ControlEvent::Unmount => server_emitter.emit(ServerEvent::Unmount(entity)),
ControlEvent::InventoryManip(manip) => {
server_emitter.emit(ServerEvent::InventoryManip(entity, manip))
} //ControlEvent::Respawn => server_emitter.emit(ServerEvent::Unmount(entity)),
}
}
}
}
}
fn can_glide(body: &Body) -> bool {
body.is_humanoid()
}
fn can_climb(body: &Body) -> bool {
body.is_humanoid()
}