mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description IPCs were ported from a codebase that didn't necessarily follow all of our repo's coding standards. And while I had done my part to cleanup as much of the system as was practical within the bounds of a Maintainer Review, there were a lot of things that I felt were inappropriate to leave to review, and wished to go over with a fine lense. Thus, here is my Refactor of IPC code. Do not merge this without first testing that nothing was broken. Because I haven't tested it myself yet.
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Content.Server.Electrocution;
|
|
using Content.Server.Popups;
|
|
using Content.Server.Power.Components;
|
|
using Content.Server.Power.EntitySystems;
|
|
using Content.Shared.Electrocution;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Power.Systems;
|
|
|
|
public sealed class BatteryElectrocuteChargeSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
[Dependency] private readonly BatterySystem _battery = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<BatteryComponent, ElectrocutedEvent>(OnElectrocuted);
|
|
}
|
|
|
|
private void OnElectrocuted(EntityUid uid, BatteryComponent battery, ElectrocutedEvent args)
|
|
{
|
|
if (args.ShockDamage == null || args.ShockDamage <= 0)
|
|
return;
|
|
|
|
var charge = Math.Min(args.ShockDamage.Value * args.SiemensCoefficient
|
|
/ ElectrocutionSystem.ElectrifiedDamagePerWatt * 2,
|
|
battery.MaxCharge * 0.25f)
|
|
* _random.NextFloat(0.75f, 1.25f);
|
|
|
|
_battery.SetCharge(uid, battery.CurrentCharge + charge);
|
|
|
|
_popup.PopupEntity(Loc.GetString("battery-electrocute-charge"), uid, uid);
|
|
}
|
|
}
|