diff --git a/Content.Server/Stunnable/Systems/StunbatonSystem.cs b/Content.Server/Stunnable/Systems/StunbatonSystem.cs index fc97c86ad2..2b10aa3cc1 100644 --- a/Content.Server/Stunnable/Systems/StunbatonSystem.cs +++ b/Content.Server/Stunnable/Systems/StunbatonSystem.cs @@ -40,10 +40,7 @@ public override void Initialize() private void OnStaminaHitAttempt(Entity entity, ref StaminaDamageOnHitAttemptEvent args) { // WD EDIT START - if (!_itemToggle.IsActivated(entity.Owner) - || !_battery.TryGetBatteryComponent(entity, out var battery, out var batteryUid) - || battery.CurrentCharge < entity.Comp.EnergyPerUse - || !_battery.TryUseCharge(batteryUid.Value, entity.Comp.EnergyPerUse / 2, battery)) + if (!_itemToggle.IsActivated(entity.Owner) || TryUseCharge(entity)) args.Cancelled = true; // WD EDIT END } @@ -51,10 +48,7 @@ private void OnStaminaHitAttempt(Entity entity, ref StaminaD // WD EDIT START private void OnKnockdownHitAttempt(Entity entity, ref KnockdownOnHitAttemptEvent args) { - if (!_itemToggle.IsActivated(entity.Owner) - || !_battery.TryGetBatteryComponent(entity, out var battery, out var batteryUid) - || battery.CurrentCharge < entity.Comp.EnergyPerUse - || !_battery.TryUseCharge(batteryUid.Value, entity.Comp.EnergyPerUse / 2, battery)) + if (!_itemToggle.IsActivated(entity.Owner) || TryUseCharge(entity)) args.Cancelled = true; } // WD EDIT END @@ -141,6 +135,13 @@ private void CheckCharge(Entity entity) || battery.CurrentCharge < entity.Comp.EnergyPerUse) _itemToggle.TryDeactivate(entity.Owner, predicted: false); } + + private bool TryUseCharge(Entity entity) + { + return _battery.TryGetBatteryComponent(entity, out var battery, out var batteryUid) + && battery.CurrentCharge >= entity.Comp.EnergyPerUse + && _battery.TryUseCharge(batteryUid.Value, entity.Comp.EnergyPerUse / 2, battery); + } // WD EDIT END } }