parent
a430ec6fdd
commit
b1941efa97
|
|
@ -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<ApcPowerReceiverComponent>(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<ApcPowerReceiverComponent>(uid, out var apcPower) && component.OriginalLoad != 0)
|
||||
apcPower.Load = 1;
|
||||
|
||||
DisableGun(uid, component);
|
||||
args.Handled = true;
|
||||
}
|
||||
else if (CanEnable(uid, component))
|
||||
{
|
||||
if (TryComp<ApcPowerReceiverComponent>(uid, out var apcPower) && component.OriginalLoad != apcPower.Load)
|
||||
apcPower.Load = component.OriginalLoad;
|
||||
|
||||
EnableGun(uid, component);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to disable the AutoShootGun.
|
||||
/// </summary>
|
||||
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<ApcPowerReceiverComponent>(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<ApcPowerReceiverComponent>(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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<BallisticAmmoProviderComponent, PriceCalculationEvent>(OnBallisticPrice);
|
||||
SubscribeLocalEvent<AutoShootGunComponent, ActivateInWorldEvent>(OnActivateGun); // Frontier
|
||||
SubscribeLocalEvent<AutoShootGunComponent, ComponentInit>(OnGunInit); // Frontier
|
||||
SubscribeLocalEvent<AutoShootGunComponent, ComponentShutdown>(OnGunShutdown); // Frontier
|
||||
SubscribeLocalEvent<AutoShootGunComponent, ExaminedEvent>(OnGunExamine); // Frontier
|
||||
SubscribeLocalEvent<AutoShootGunComponent, PowerChangedEvent>(OnPowerChange); // Frontier
|
||||
SubscribeLocalEvent<AutoShootGunComponent, AnchorStateChangedEvent>(OnAnchorChange); // Frontier
|
||||
}
|
||||
|
||||
private void OnBallisticPrice(EntityUid uid, BallisticAmmoProviderComponent component, ref PriceCalculationEvent args)
|
||||
|
|
|
|||
|
|
@ -11,4 +11,21 @@ public sealed partial class AutoShootGunComponent : Component
|
|||
{
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool Enabled;
|
||||
|
||||
/// <summary>
|
||||
/// Frontier - Whether the gun is switched on (e.g. through user interaction)
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool On { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Frontier - Whether or not the gun can actually fire (i.e. switched on and receiving power if needed)
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool CanFire;
|
||||
|
||||
/// <summary>
|
||||
/// Frontier - Amount of power this gun needs from an APC in Watts to function.
|
||||
/// </summary>
|
||||
public float OriginalLoad { get; set; } = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,6 +228,9 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
|
||||
private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun)
|
||||
{
|
||||
if (TryComp<AutoShootGunComponent>(gunUid, out var auto) && !auto.CanFire) // Frontier
|
||||
return; // Frontier
|
||||
|
||||
if (gun.FireRateModified <= 0f ||
|
||||
!_actionBlockerSystem.CanAttack(user))
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -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].
|
||||
|
|
@ -363,3 +363,6 @@
|
|||
count: 5
|
||||
- type: Machine
|
||||
board: ShuttleGunKineticCircuitboard
|
||||
- type: ExtensionCableReceiver # Frontier
|
||||
- type: ApcPowerReceiver # Frontier
|
||||
powerLoad: 1500 # Frontier
|
||||
|
|
|
|||
Loading…
Reference in New Issue