Add emp grenade (#14393)

This commit is contained in:
Slava0135
2023-03-06 22:05:12 +03:00
committed by GitHub
parent 58becca060
commit b2972c1d2c
16 changed files with 243 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
namespace Content.Server.Emp;
/// <summary>
/// Upon being triggered will EMP area around it.
/// </summary>
[RegisterComponent]
sealed class EmpOnTriggerComponent : Component
{
[DataField("range"), ViewVariables(VVAccess.ReadWrite)]
public float Range = 1.0f;
/// <summary>
/// How much energy will be consumed per battery in range
/// </summary>
[DataField("energyConsumption"), ViewVariables(VVAccess.ReadWrite)]
public float EnergyConsumption;
}

View File

@@ -0,0 +1,39 @@
using Content.Server.Explosion.EntitySystems;
using Robust.Shared.Map;
namespace Content.Server.Emp;
public sealed class EmpSystem : EntitySystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
public const string EmpPulseEffectPrototype = "EffectEmpPulse";
public const string EmpDisabledEffectPrototype = "EffectEmpDisabled";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmpOnTriggerComponent, TriggerEvent>(HandleEmpTrigger);
}
public void EmpPulse(MapCoordinates coordinates, float range, float energyConsumption)
{
foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range))
{
var ev = new EmpPulseEvent(energyConsumption, false);
RaiseLocalEvent(uid, ref ev);
if (ev.Affected)
Spawn(EmpDisabledEffectPrototype, Transform(uid).Coordinates);
}
Spawn(EmpPulseEffectPrototype, coordinates);
}
private void HandleEmpTrigger(EntityUid uid, EmpOnTriggerComponent comp, TriggerEvent args)
{
EmpPulse(Transform(uid).Coordinates.ToMap(EntityManager), comp.Range, comp.EnergyConsumption);
args.Handled = true;
}
}
[ByRefEvent]
public record struct EmpPulseEvent(float EnergyConsumption, bool Affected);

View File

@@ -22,6 +22,7 @@ using Robust.Shared.Containers;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using Content.Shared.DoAfter;
using Content.Server.Emp;
namespace Content.Server.Light.EntitySystems
{
@@ -63,6 +64,8 @@ namespace Content.Server.Light.EntitySystems
SubscribeLocalEvent<PoweredLightComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<PoweredLightComponent, DoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<PoweredLightComponent, EmpPulseEvent>(OnEmpPulse);
}
private void OnInit(EntityUid uid, PoweredLightComponent light, ComponentInit args)
@@ -421,5 +424,11 @@ namespace Content.Server.Light.EntitySystems
args.Handled = true;
}
private void OnEmpPulse(EntityUid uid, PoweredLightComponent component, ref EmpPulseEvent args)
{
args.Affected = true;
TryDestroyBulb(uid, component);
}
}
}

View File

@@ -1,3 +1,4 @@
using Content.Server.Emp;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Shared.Access.Components;
@@ -44,6 +45,8 @@ namespace Content.Server.Power.EntitySystems
SubscribeLocalEvent<ApcToolFinishedEvent>(OnToolFinished);
SubscribeLocalEvent<ApcComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<ApcComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<ApcComponent, EmpPulseEvent>(OnEmpPulse);
}
// Change the APC's state only when the battery state changes, or when it's first created.
@@ -247,5 +250,14 @@ namespace Content.Server.Power.EntitySystems
? "apc-component-on-examine-panel-open"
: "apc-component-on-examine-panel-closed"));
}
private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent args)
{
if (component.MainBreakerEnabled)
{
args.Affected = true;
ApcToggleBreaker(uid, component);
}
}
}
}

View File

@@ -1,4 +1,5 @@
using Content.Server.Cargo.Systems;
using Content.Server.Emp;
using Content.Server.Power.Components;
using Content.Shared.Examine;
using Content.Shared.Rejuvenate;
@@ -17,6 +18,7 @@ namespace Content.Server.Power.EntitySystems
SubscribeLocalEvent<PowerNetworkBatteryComponent, RejuvenateEvent>(OnNetBatteryRejuvenate);
SubscribeLocalEvent<BatteryComponent, RejuvenateEvent>(OnBatteryRejuvenate);
SubscribeLocalEvent<BatteryComponent, PriceCalculationEvent>(CalculateBatteryPrice);
SubscribeLocalEvent<BatteryComponent, EmpPulseEvent>(OnEmpPulse);
SubscribeLocalEvent<NetworkBatteryPreSync>(PreSync);
SubscribeLocalEvent<NetworkBatteryPostSync>(PostSync);
@@ -87,5 +89,11 @@ namespace Content.Server.Power.EntitySystems
{
args.Price += component.CurrentCharge * component.PricePerJoule;
}
private void OnEmpPulse(EntityUid uid, BatteryComponent component, ref EmpPulseEvent args)
{
args.Affected = true;
component.UseCharge(args.EnergyConsumption);
}
}
}