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

@ -48,6 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed the bow fire rate - Fixed the bow fire rate
- Healthbars now flash on critical health - Healthbars now flash on critical health
- Fixed ghosts when going back to character screen - Fixed ghosts when going back to character screen
- Fixed not being able to unmount
- Fixed non-humanoids being able to climb and glide
### Removed ### Removed

View File

@ -44,7 +44,7 @@ opt-level = 2
inherits= 'dev' inherits= 'dev'
debug = true debug = true
# this profil is used for veloren releases, compile time doesn't matter # this profile is used for veloren releases, compile time doesn't matter
# we need stacktraces, light debug information, as much checks as possible # we need stacktraces, light debug information, as much checks as possible
# I would like to put it in a seperate `official_release` target, but that doesnt share caches with `cargo test` and `cargo bench` # I would like to put it in a seperate `official_release` target, but that doesnt share caches with `cargo test` and `cargo bench`
[profile.release] [profile.release]

View File

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

View File

@ -24,8 +24,8 @@ const CLEANUP_SYS: &str = "cleanup_sys";
pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) {
dispatch_builder.add(agent::Sys, AGENT_SYS, &[]); dispatch_builder.add(agent::Sys, AGENT_SYS, &[]);
dispatch_builder.add(controller::Sys, CONTROLLER_SYS, &[AGENT_SYS]); dispatch_builder.add(mount::Sys, MOUNT_SYS, &[AGENT_SYS]);
dispatch_builder.add(mount::Sys, MOUNT_SYS, &[CONTROLLER_SYS]); dispatch_builder.add(controller::Sys, CONTROLLER_SYS, &[AGENT_SYS, MOUNT_SYS]);
dispatch_builder.add(movement::Sys, MOVEMENT_SYS, &[]); dispatch_builder.add(movement::Sys, MOVEMENT_SYS, &[]);
dispatch_builder.add(combat::Sys, COMBAT_SYS, &[CONTROLLER_SYS]); dispatch_builder.add(combat::Sys, COMBAT_SYS, &[CONTROLLER_SYS]);
dispatch_builder.add(stats::Sys, STATS_SYS, &[COMBAT_SYS]); dispatch_builder.add(stats::Sys, STATS_SYS, &[COMBAT_SYS]);

View File

@ -40,9 +40,15 @@ impl<'a> System<'a> for Sys {
match mount_states.get_unchecked() { match mount_states.get_unchecked() {
MountState::Unmounted => {} MountState::Unmounted => {}
MountState::MountedBy(mounter_uid) => { MountState::MountedBy(mounter_uid) => {
if let Some((controller, mounter)) = uid_allocator // Note: currently controller events are not passed through since none of them
// are currently relevant to controlling the mounted entity
if let Some((inputs, mounter)) = uid_allocator
.retrieve_entity_internal(mounter_uid.id()) .retrieve_entity_internal(mounter_uid.id())
.and_then(|mounter| controllers.get(mounter).cloned().map(|x| (x, mounter))) .and_then(|mounter| {
controllers
.get(mounter)
.map(|c| (c.inputs.clone(), mounter))
})
{ {
// TODO: consider joining on these? (remember we can use .maybe()) // TODO: consider joining on these? (remember we can use .maybe())
let pos = positions.get(entity).copied(); let pos = positions.get(entity).copied();
@ -53,7 +59,13 @@ impl<'a> System<'a> for Sys {
let _ = orientations.insert(mounter, ori); let _ = orientations.insert(mounter, ori);
let _ = velocities.insert(mounter, vel); let _ = velocities.insert(mounter, vel);
} }
let _ = controllers.insert(entity, controller); let _ = controllers.insert(
entity,
Controller {
inputs,
..Default::default()
},
);
} else { } else {
*(mount_states.get_mut_unchecked()) = MountState::Unmounted; *(mount_states.get_mut_unchecked()) = MountState::Unmounted;
} }

View File

@ -209,8 +209,7 @@ impl<'a> System<'a> for Sys {
// Climb // Climb
if let (true, Some(_wall_dir)) = ( if let (true, Some(_wall_dir)) = (
(inputs.climb.is_pressed() | inputs.climb_down.is_pressed()) character.movement == Climb && vel.0.z <= CLIMB_SPEED,
&& vel.0.z <= CLIMB_SPEED,
physics.on_wall, physics.on_wall,
) { ) {
if inputs.climb_down.is_pressed() && !inputs.climb.is_pressed() { if inputs.climb_down.is_pressed() && !inputs.climb.is_pressed() {