diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.AutoFire.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.AutoFire.cs index 39cd2486ed..1a635147f2 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.AutoFire.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.AutoFire.cs @@ -1,4 +1,9 @@ using Content.Shared.Weapons.Ranged.Components; +using Content.Server.Power.Components; // Frontier +using Content.Server.Power.EntitySystems; // Frontier +using Content.Shared.Interaction; // Frontier +using Content.Shared.Examine; // Frontier +using Content.Shared.Power; // Frontier namespace Content.Server.Weapons.Ranged.Systems; @@ -26,4 +31,111 @@ public sealed partial class GunSystem AttemptShoot(uid, gun); } } + + // New Frontiers - Shuttle Gun Power Draw - makes shuttle guns require power if they + // have an ApcPowerReceiverComponent + // This code is licensed under AGPLv3. See AGPLv3.txt + private void OnGunExamine(EntityUid uid, AutoShootGunComponent component, ExaminedEvent args) + { + if (!HasComp(uid)) + return; + + // Powered is already handled by other power components + var enabled = Loc.GetString(component.On ? "gun-comp-enabled" : "gun-comp-disabled"); + + args.PushMarkup(enabled); + } + + private void OnActivateGun(EntityUid uid, AutoShootGunComponent component, ActivateInWorldEvent args) + { + if (args.Handled || !args.Complex) + return; + + component.On ^= true; + + if (!component.On) + { + if (TryComp(uid, out var apcPower) && component.OriginalLoad != 0) + apcPower.Load = 1; + + DisableGun(uid, component); + args.Handled = true; + } + else if (CanEnable(uid, component)) + { + if (TryComp(uid, out var apcPower) && component.OriginalLoad != apcPower.Load) + apcPower.Load = component.OriginalLoad; + + EnableGun(uid, component); + args.Handled = true; + } + } + + /// + /// Tries to disable the AutoShootGun. + /// + public void DisableGun(EntityUid uid, AutoShootGunComponent component) + { + if (component.CanFire) + component.CanFire = false; + } + + public bool CanEnable(EntityUid uid, AutoShootGunComponent component) + { + var xform = Transform(uid); + + // Must be anchored to fire. + if (!xform.Anchored) + return false; + + // No power needed? Always works. + if (!HasComp(uid)) + return true; + + // Not switched on? Won't work. + if (!component.On) + return false; + + return this.IsPowered(uid, EntityManager); + } + + public void EnableGun(EntityUid uid, AutoShootGunComponent component, TransformComponent? xform = null) + { + if (!component.CanFire) + component.CanFire = true; + } + + private void OnAnchorChange(EntityUid uid, AutoShootGunComponent component, ref AnchorStateChangedEvent args) + { + if (args.Anchored && CanEnable(uid, component)) + EnableGun(uid, component); + else + DisableGun(uid, component); + } + + private void OnGunInit(EntityUid uid, AutoShootGunComponent component, ComponentInit args) + { + if (TryComp(uid, out var apcPower) && component.OriginalLoad == 0) + component.OriginalLoad = apcPower.Load; + + if (!component.On) + return; + + if (CanEnable(uid, component)) + EnableGun(uid, component); + } + + private void OnGunShutdown(EntityUid uid, AutoShootGunComponent component, ComponentShutdown args) + { + DisableGun(uid, component); + } + + private void OnPowerChange(EntityUid uid, AutoShootGunComponent component, ref PowerChangedEvent args) + { + if (args.Powered && CanEnable(uid, component)) + EnableGun(uid, component); + else + DisableGun(uid, component); + } + // End of Frontier modified code } diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs index fb111e11fe..29504d5a76 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs @@ -25,6 +25,9 @@ using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Utility; using Robust.Shared.Containers; +using Content.Shared.Interaction; // Frontier +using Content.Shared.Examine; // Frontier +using Content.Shared.Power; // Frontier namespace Content.Server.Weapons.Ranged.Systems; @@ -48,6 +51,12 @@ public sealed partial class GunSystem : SharedGunSystem { base.Initialize(); SubscribeLocalEvent(OnBallisticPrice); + SubscribeLocalEvent(OnActivateGun); // Frontier + SubscribeLocalEvent(OnGunInit); // Frontier + SubscribeLocalEvent(OnGunShutdown); // Frontier + SubscribeLocalEvent(OnGunExamine); // Frontier + SubscribeLocalEvent(OnPowerChange); // Frontier + SubscribeLocalEvent(OnAnchorChange); // Frontier } private void OnBallisticPrice(EntityUid uid, BallisticAmmoProviderComponent component, ref PriceCalculationEvent args) diff --git a/Content.Shared/Weapons/Ranged/Components/AutoShootGunComponent.cs b/Content.Shared/Weapons/Ranged/Components/AutoShootGunComponent.cs index 16b3110b85..d7c4012f46 100644 --- a/Content.Shared/Weapons/Ranged/Components/AutoShootGunComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/AutoShootGunComponent.cs @@ -11,4 +11,21 @@ public sealed partial class AutoShootGunComponent : Component { [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public bool Enabled; + + /// + /// Frontier - Whether the gun is switched on (e.g. through user interaction) + /// + [DataField, ViewVariables(VVAccess.ReadWrite)] + public bool On { get; set; } = true; + + /// + /// Frontier - Whether or not the gun can actually fire (i.e. switched on and receiving power if needed) + /// + [ViewVariables(VVAccess.ReadWrite)] + public bool CanFire; + + /// + /// Frontier - Amount of power this gun needs from an APC in Watts to function. + /// + public float OriginalLoad { get; set; } = 0; } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index 248fe0a2cd..2ba462008c 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -228,6 +228,9 @@ public abstract partial class SharedGunSystem : EntitySystem private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun) { + if (TryComp(gunUid, out var auto) && !auto.CanFire) // Frontier + return; // Frontier + if (gun.FireRateModified <= 0f || !_actionBlockerSystem.CanAttack(user)) return; diff --git a/Resources/Locale/en-US/_NF/weapons/gun.ftl b/Resources/Locale/en-US/_NF/weapons/gun.ftl new file mode 100644 index 0000000000..9197a627c7 --- /dev/null +++ b/Resources/Locale/en-US/_NF/weapons/gun.ftl @@ -0,0 +1,2 @@ +gun-comp-enabled = The gun is turned [color=green]on[/color]. +gun-comp-disabled = The gun is turned [color=red]off[/color]. diff --git a/Resources/Prototypes/Entities/Structures/Shuttles/cannons.yml b/Resources/Prototypes/Entities/Structures/Shuttles/cannons.yml index f0e6dd0155..086a708453 100644 --- a/Resources/Prototypes/Entities/Structures/Shuttles/cannons.yml +++ b/Resources/Prototypes/Entities/Structures/Shuttles/cannons.yml @@ -363,3 +363,6 @@ count: 5 - type: Machine board: ShuttleGunKineticCircuitboard + - type: ExtensionCableReceiver # Frontier + - type: ApcPowerReceiver # Frontier + powerLoad: 1500 # Frontier