From 7844ee0da8c362c886ed6e05d6673a508d14b027 Mon Sep 17 00:00:00 2001 From: Mor-Dast <136860710+Mor-Dast@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:58:40 +0300 Subject: [PATCH] Add files via upload --- .../Equipment/EntitySystems/MechGunSystem.cs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Content.Server/Mech/Equipment/EntitySystems/MechGunSystem.cs diff --git a/Content.Server/Mech/Equipment/EntitySystems/MechGunSystem.cs b/Content.Server/Mech/Equipment/EntitySystems/MechGunSystem.cs new file mode 100644 index 00000000000..8ed55e7462a --- /dev/null +++ b/Content.Server/Mech/Equipment/EntitySystems/MechGunSystem.cs @@ -0,0 +1,61 @@ +using Content.Server.Mech.Systems; +using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; +using Content.Shared.Mech.Components; +using Content.Shared.Mech.Equipment.Components; +using Content.Shared.Throwing; +using Content.Shared.Weapons.Ranged.Systems; +using Robust.Shared.Random; + +namespace Content.Server.Mech.Equipment.EntitySystems; +public sealed class MechGunSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly ThrowingSystem _throwing = default!; + [Dependency] private readonly MechSystem _mech = default!; + [Dependency] private readonly BatterySystem _battery = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(MechGunShot); + } + + private void MechGunShot(EntityUid uid, MechEquipmentComponent component, ref GunShotEvent args) + { + if (!component.EquipmentOwner.HasValue) + return; + + if (!TryComp(component.EquipmentOwner.Value, out var mech)) + return; + + if (TryComp(uid, out var battery)) + { + ChargeGunBattery(uid, battery); + return; + } + } + + private void ChargeGunBattery(EntityUid uid, BatteryComponent component) + { + if (!TryComp(uid, out var mechEquipment) || !mechEquipment.EquipmentOwner.HasValue) + return; + + if (!TryComp(mechEquipment.EquipmentOwner.Value, out var mech)) + return; + + var maxCharge = component.MaxCharge; + var currentCharge = component.CurrentCharge; + + var chargeDelta = maxCharge - currentCharge; + + // TODO: The battery charge of the mech would be spent directly when fired. + if (chargeDelta <= 0 || mech.Energy - chargeDelta < 0) + return; + + if (!_mech.TryChangeEnergy(mechEquipment.EquipmentOwner.Value, -chargeDelta, mech)) + return; + + _battery.SetCharge(uid, component.MaxCharge, component); + } +} \ No newline at end of file