diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index eff07c5868..30ae903e9c 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -46,6 +46,11 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.4); handle_jump(data, &mut update); + if unwrap_tool_data(data).is_none() { + update.character = CharacterState::Idle; + return update; + } + if self.buildup_duration != Duration::default() { // Build up update.character = CharacterState::BasicBeam(Data { diff --git a/common/src/sys/beam.rs b/common/src/sys/beam.rs index 7b8f62fc88..43b5b9f970 100644 --- a/common/src/sys/beam.rs +++ b/common/src/sys/beam.rs @@ -189,36 +189,44 @@ impl<'a> System<'a> for Sys { damage.modify_damage(block, loadout); } - if damage.healthchange != 0.0 { - let cause = if is_heal { - HealthSource::Healing { by: beam.owner } - } else { - HealthSource::Energy { owner: beam.owner } - }; + if is_damage { server_emitter.emit(ServerEvent::Damage { uid: *uid_b, change: HealthChange { amount: damage.healthchange as i32, - cause, + cause: HealthSource::Energy { owner: beam.owner }, }, }); - if is_damage && beam.lifesteal_eff > 0.0 { - server_emitter.emit(ServerEvent::Damage { - uid: beam.owner.unwrap_or(*uid), - change: HealthChange { - amount: (-damage.healthchange * beam.lifesteal_eff) as i32, - cause: HealthSource::Healing { by: beam.owner }, - }, - }); + server_emitter.emit(ServerEvent::Damage { + uid: beam.owner.unwrap_or(*uid), + change: HealthChange { + amount: (-damage.healthchange * beam.lifesteal_eff) as i32, + cause: HealthSource::Healing { by: beam.owner }, + }, + }); + if let Some(energy_mut) = beam + .owner + .and_then(|o| uid_allocator.retrieve_entity_internal(o.into())) + .and_then(|o| energies.get_mut(o)) + { + energy_mut + .change_by(beam.energy_regen as i32, EnergySource::HitEnemy); } - if is_damage || stats_b.health.current() != stats_b.health.maximum() { - if let Some(energy_mut) = beam - .owner - .and_then(|o| uid_allocator.retrieve_entity_internal(o.into())) - .and_then(|o| energies.get_mut(o)) - { - energy_mut - .change_by(beam.energy_regen as i32, EnergySource::HitEnemy); + } + if is_heal { + if let Some(energy_mut) = beam + .owner + .and_then(|o| uid_allocator.retrieve_entity_internal(o.into())) + .and_then(|o| energies.get_mut(o)) + { + if energy_mut.try_change_by(-(beam.energy_regen as i32), EnergySource::Ability).is_ok() { + server_emitter.emit(ServerEvent::Damage { + uid: *uid_b, + change: HealthChange { + amount: damage.healthchange as i32, + cause: HealthSource::Healing { by: beam.owner }, + }, + }); } } }