Skip to content

Commit

Permalink
rewiew
Browse files Browse the repository at this point in the history
  • Loading branch information
Spatison committed Nov 29, 2024
1 parent d435c27 commit 6a359d0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Content.Server/Stunnable/Systems/StunbatonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,15 @@ public override void Initialize()
private void OnStaminaHitAttempt(Entity<StunbatonComponent> 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
}

// WD EDIT START
private void OnKnockdownHitAttempt(Entity<StunbatonComponent> 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
Expand Down Expand Up @@ -141,6 +135,13 @@ private void CheckCharge(Entity<StunbatonComponent> entity)
|| battery.CurrentCharge < entity.Comp.EnergyPerUse)
_itemToggle.TryDeactivate(entity.Owner, predicted: false);
}

private bool TryUseCharge(Entity<StunbatonComponent> 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
}
}

0 comments on commit 6a359d0

Please sign in to comment.