Fix attacking bug

This commit is contained in:
timokoesters 2019-07-04 20:14:14 +02:00
parent e267ac7ed4
commit 203b3d4e76
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097

View File

@ -102,16 +102,13 @@ impl PlayState for SessionState {
return PlayStateResult::Shutdown;
}
Event::InputUpdate(GameInput::Attack, state) => {
self.controller.respawn = state; // TODO: Move this into separate GameInput
// Check the existence of CanBuild component. If it's here, use LMB to
// place blocks, if not, use it to attack
if state {
// Check if the player is dead or not
if current_client_state != ClientState::Character {
self.controller.respawn = state;
}
let mut client = self.client.borrow_mut();
if client
if state
&& client
.state()
.read_storage::<comp::CanBuild>()
.get(client.entity())
@ -123,8 +120,7 @@ impl PlayState for SessionState {
let (d, b) = {
let terrain = client.state().terrain();
let ray =
terrain.ray(cam_pos, cam_pos + cam_dir * 100.0).cast();
let ray = terrain.ray(cam_pos, cam_pos + cam_dir * 100.0).cast();
(ray.0, if let Ok(Some(_)) = ray.1 { true } else { false })
};
@ -134,15 +130,10 @@ impl PlayState for SessionState {
client.place_block(pos, Block::new(1, Rgb::broadcast(255))); // TODO: Handle block color with a command
}
} else {
if let ClientState::Character = current_client_state {
self.controller.attack = state
}
}
} else {
self.controller.attack = state;
self.controller.respawn = state;
}
}
Event::InputUpdate(GameInput::SecondAttack, state) => {
if state {
let mut client = self.client.borrow_mut();