Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Revert "Revert "Emp more effects" (space-wizards#16159)" (space-wizar…
Browse files Browse the repository at this point in the history
…ds#16165)

This reverts commit 0da5a78.
  • Loading branch information
metalgearsloth authored and Vordenburg committed May 19, 2023
1 parent a0f86d7 commit 4634d80
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 14 deletions.
24 changes: 24 additions & 0 deletions Content.Client/Emp/EmpSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Content.Shared.Emp;
using Robust.Shared.Random;

namespace Content.Client.Emp;

public sealed class EmpSystem : SharedEmpSystem
{
[Dependency] private readonly IRobustRandom _random = default!;

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<EmpDisabledComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var comp, out var transform))
{
if (Timing.CurTime > comp.TargetTime)
{
comp.TargetTime = Timing.CurTime + _random.NextFloat(0.8f, 1.2f) * TimeSpan.FromSeconds(comp.EffectCooldown);
Spawn(EmpDisabledEffectPrototype, transform.Coordinates);
}
}
}
}
2 changes: 1 addition & 1 deletion Content.Server/Anomaly/Effects/ElectricityAnomalySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void OnSupercritical(EntityUid uid, ElectricityAnomalyComponent componen
}

var empRange = component.MaxElectrocuteRange * 3;
_emp.EmpPulse(Transform(uid).MapPosition, empRange, component.EmpEnergyConsumption);
_emp.EmpPulse(Transform(uid).MapPosition, empRange, component.EmpEnergyConsumption, component.EmpDisabledDuration);
}

public override void Update(float frameTime)
Expand Down
6 changes: 6 additions & 0 deletions Content.Server/Emp/EmpOnTriggerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ public sealed class EmpOnTriggerComponent : Component
/// </summary>
[DataField("energyConsumption"), ViewVariables(VVAccess.ReadWrite)]
public float EnergyConsumption;

/// <summary>
/// How long it disables targets in seconds
/// </summary>
[DataField("disableDuration"), ViewVariables(VVAccess.ReadWrite)]
public float DisableDuration = 60f;
}
80 changes: 74 additions & 6 deletions Content.Server/Emp/EmpSystem.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,107 @@
using Content.Server.Explosion.EntitySystems;
using Content.Server.Power.EntitySystems;
using Content.Server.Radio;
using Content.Server.SurveillanceCamera;
using Content.Shared.Emp;
using Content.Shared.Examine;
using Robust.Shared.Map;

namespace Content.Server.Emp;

public sealed class EmpSystem : EntitySystem
public sealed class EmpSystem : SharedEmpSystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;

public const string EmpPulseEffectPrototype = "EffectEmpPulse";
public const string EmpDisabledEffectPrototype = "EffectEmpDisabled";

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmpDisabledComponent, EntityUnpausedEvent>(OnUnpaused);
SubscribeLocalEvent<EmpDisabledComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<EmpOnTriggerComponent, TriggerEvent>(HandleEmpTrigger);

SubscribeLocalEvent<EmpDisabledComponent, RadioSendAttemptEvent>(OnRadioSendAttempt);
SubscribeLocalEvent<EmpDisabledComponent, RadioReceiveAttemptEvent>(OnRadioReceiveAttempt);
SubscribeLocalEvent<EmpDisabledComponent, ApcToggleMainBreakerAttemptEvent>(OnApcToggleMainBreaker);
SubscribeLocalEvent<EmpDisabledComponent, SurveillanceCameraSetActiveAttemptEvent>(OnCameraSetActive);
}

public void EmpPulse(MapCoordinates coordinates, float range, float energyConsumption)
public void EmpPulse(MapCoordinates coordinates, float range, float energyConsumption, float duration)
{
foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range))
{
var ev = new EmpPulseEvent(energyConsumption, false);
var ev = new EmpPulseEvent(energyConsumption, false, false);
RaiseLocalEvent(uid, ref ev);
if (ev.Affected)
{
Spawn(EmpDisabledEffectPrototype, Transform(uid).Coordinates);
}
if (ev.Disabled)
{
var disabled = EnsureComp<EmpDisabledComponent>(uid);
disabled.DisabledUntil = Timing.CurTime + TimeSpan.FromSeconds(duration);
}
}
Spawn(EmpPulseEffectPrototype, coordinates);
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<EmpDisabledComponent>();
while (query.MoveNext(out var uid, out var comp))
{
if (comp.DisabledUntil < Timing.CurTime)
{
RemComp<EmpDisabledComponent>(uid);
var ev = new EmpDisabledRemoved();
RaiseLocalEvent(uid, ref ev);
}
}
}

private void OnUnpaused(EntityUid uid, EmpDisabledComponent component, ref EntityUnpausedEvent args)
{
component.DisabledUntil += args.PausedTime;
component.TargetTime += args.PausedTime;
}

private void OnExamine(EntityUid uid, EmpDisabledComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString("emp-disabled-comp-on-examine"));
}

private void HandleEmpTrigger(EntityUid uid, EmpOnTriggerComponent comp, TriggerEvent args)
{
EmpPulse(Transform(uid).MapPosition, comp.Range, comp.EnergyConsumption);
EmpPulse(Transform(uid).MapPosition, comp.Range, comp.EnergyConsumption, comp.DisableDuration);
args.Handled = true;
}

private void OnRadioSendAttempt(EntityUid uid, EmpDisabledComponent component, ref RadioSendAttemptEvent args)
{
args.Cancelled = true;
}

private void OnRadioReceiveAttempt(EntityUid uid, EmpDisabledComponent component, ref RadioReceiveAttemptEvent args)
{
args.Cancelled = true;
}

private void OnApcToggleMainBreaker(EntityUid uid, EmpDisabledComponent component, ref ApcToggleMainBreakerAttemptEvent args)
{
args.Cancelled = true;
}

private void OnCameraSetActive(EntityUid uid, EmpDisabledComponent component, ref SurveillanceCameraSetActiveAttemptEvent args)
{
args.Cancelled = true;
}
}

[ByRefEvent]
public record struct EmpPulseEvent(float EnergyConsumption, bool Affected);
public record struct EmpPulseEvent(float EnergyConsumption, bool Affected, bool Disabled);

[ByRefEvent]
public record struct EmpDisabledRemoved();
11 changes: 6 additions & 5 deletions Content.Server/Light/EntitySystems/PoweredLightSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,20 @@ public bool ReplaceBulb(EntityUid uid, EntityUid bulb, PoweredLightComponent? li
/// <summary>
/// Try to break bulb inside light fixture
/// </summary>
public void TryDestroyBulb(EntityUid uid, PoweredLightComponent? light = null)
public bool TryDestroyBulb(EntityUid uid, PoweredLightComponent? light = null)
{
// check bulb state
var bulbUid = GetBulb(uid, light);
if (bulbUid == null || !EntityManager.TryGetComponent(bulbUid.Value, out LightBulbComponent? lightBulb))
return;
return false;
if (lightBulb.State == LightBulbState.Broken)
return;
return false;

// break it
_bulbSystem.SetState(bulbUid.Value, LightBulbState.Broken, lightBulb);
_bulbSystem.PlayBreakSound(bulbUid.Value, lightBulb);
UpdateLight(uid, light);
return true;
}
#endregion

Expand Down Expand Up @@ -439,8 +440,8 @@ private void OnDoAfter(EntityUid uid, PoweredLightComponent component, DoAfterEv

private void OnEmpPulse(EntityUid uid, PoweredLightComponent component, ref EmpPulseEvent args)
{
args.Affected = true;
TryDestroyBulb(uid, component);
if (TryDestroyBulb(uid, component))
args.Affected = true;
}
}
}
13 changes: 13 additions & 0 deletions Content.Server/Power/EntitySystems/ApcSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ private void OnBoundUiOpen(EntityUid uid, ApcComponent component, BoundUIOpenedE
}
private void OnToggleMainBreaker(EntityUid uid, ApcComponent component, ApcToggleMainBreakerMessage args)
{
var attemptEv = new ApcToggleMainBreakerAttemptEvent();
RaiseLocalEvent(uid, ref attemptEv);
if (attemptEv.Cancelled)
{
_popup.PopupCursor(Loc.GetString("apc-component-on-toggle-cancel"),
args.Session, PopupType.Medium);
return;
}

TryComp<AccessReaderComponent>(uid, out var access);
if (args.Session.AttachedEntity == null)
return;
Expand Down Expand Up @@ -183,8 +192,12 @@ private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent
if (component.MainBreakerEnabled)
{
args.Affected = true;
args.Disabled = true;
ApcToggleBreaker(uid, component);
}
}
}

[ByRefEvent]
public record struct ApcToggleMainBreakerAttemptEvent(bool Cancelled);
}
12 changes: 12 additions & 0 deletions Content.Server/Radio/EntitySystems/HeadsetSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Chat.Systems;
using Content.Server.Emp;
using Content.Server.Radio.Components;
using Content.Shared.Inventory.Events;
using Content.Shared.Radio;
Expand All @@ -21,6 +22,8 @@ public override void Initialize()
SubscribeLocalEvent<HeadsetComponent, EncryptionChannelsChangedEvent>(OnKeysChanged);

SubscribeLocalEvent<WearingHeadsetComponent, EntitySpokeEvent>(OnSpeak);

SubscribeLocalEvent<HeadsetComponent, EmpPulseEvent>(OnEmpPulse);
}

private void OnKeysChanged(EntityUid uid, HeadsetComponent component, EncryptionChannelsChangedEvent args)
Expand Down Expand Up @@ -98,4 +101,13 @@ private void OnHeadsetReceive(EntityUid uid, HeadsetComponent component, ref Rad
if (TryComp(Transform(uid).ParentUid, out ActorComponent? actor))
_netMan.ServerSendMessage(args.ChatMsg, actor.PlayerSession.ConnectedClient);
}

private void OnEmpPulse(EntityUid uid, HeadsetComponent component, ref EmpPulseEvent args)
{
if (component.Enabled)
{
args.Affected = true;
args.Disabled = true;
}
}
}
2 changes: 2 additions & 0 deletions Content.Server/Radio/EntitySystems/RadioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void SendRadioMessage(EntityUid messageSource, string message, RadioChann

var sendAttemptEv = new RadioSendAttemptEvent(channel, radioSource);
RaiseLocalEvent(ref sendAttemptEv);
RaiseLocalEvent(radioSource, ref sendAttemptEv);
var canSend = !sendAttemptEv.Cancelled;

var sourceMapId = Transform(radioSource).MapID;
Expand All @@ -105,6 +106,7 @@ public void SendRadioMessage(EntityUid messageSource, string message, RadioChann
// check if message can be sent to specific receiver
var attemptEv = new RadioReceiveAttemptEvent(channel, radioSource, receiver);
RaiseLocalEvent(ref attemptEv);
RaiseLocalEvent(receiver, ref attemptEv);
if (attemptEv.Cancelled)
continue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Emp;
using Content.Server.Power.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.DeviceNetwork;
Expand Down Expand Up @@ -57,6 +58,9 @@ public override void Initialize()
SubscribeLocalEvent<SurveillanceCameraComponent, SurveillanceCameraSetupSetName>(OnSetName);
SubscribeLocalEvent<SurveillanceCameraComponent, SurveillanceCameraSetupSetNetwork>(OnSetNetwork);
SubscribeLocalEvent<SurveillanceCameraComponent, GetVerbsEvent<AlternativeVerb>>(AddVerbs);

SubscribeLocalEvent<SurveillanceCameraComponent, EmpPulseEvent>(OnEmpPulse);
SubscribeLocalEvent<SurveillanceCameraComponent, EmpDisabledRemoved>(OnEmpDisabledRemoved);
}

private void OnPacketReceived(EntityUid uid, SurveillanceCameraComponent component, DeviceNetworkPacketEvent args)
Expand Down Expand Up @@ -271,6 +275,10 @@ public void SetActive(EntityUid camera, bool setting, SurveillanceCameraComponen

if (setting)
{
var attemptEv = new SurveillanceCameraSetActiveAttemptEvent();
RaiseLocalEvent(camera, ref attemptEv);
if (attemptEv.Cancelled)
return;
component.Active = setting;
}
else
Expand Down Expand Up @@ -392,6 +400,21 @@ private void UpdateVisuals(EntityUid uid, SurveillanceCameraComponent? component

_appearance.SetData(uid, SurveillanceCameraVisualsKey.Key, key, appearance);
}

private void OnEmpPulse(EntityUid uid, SurveillanceCameraComponent component, ref EmpPulseEvent args)
{
if (component.Active)
{
args.Affected = true;
args.Disabled = true;
SetActive(uid, false);
}
}

private void OnEmpDisabledRemoved(EntityUid uid, SurveillanceCameraComponent component, ref EmpDisabledRemoved args)
{
SetActive(uid, true);
}
}

public sealed class OnSurveillanceCameraViewerAddEvent : EntityEventArgs
Expand All @@ -414,3 +437,6 @@ public SurveillanceCameraDeactivateEvent(EntityUid camera)
Camera = camera;
}
}

[ByRefEvent]
public record struct SurveillanceCameraSetActiveAttemptEvent(bool Cancelled);
24 changes: 24 additions & 0 deletions Content.Server/VendingMachines/VendingMachineSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using Content.Server.Cargo.Systems;
using Content.Server.Emp;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.UserInterface;
Expand All @@ -12,13 +13,15 @@
using Content.Shared.DoAfter;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Emp;
using Content.Shared.Popups;
using Content.Shared.Throwing;
using Content.Shared.VendingMachines;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;

namespace Content.Server.VendingMachines
{
Expand All @@ -31,6 +34,7 @@ public sealed class VendingMachineSystem : SharedVendingMachineSystem
[Dependency] private readonly PricingSystem _pricing = default!;
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;

private ISawmill _sawmill = default!;

Expand All @@ -44,6 +48,7 @@ public override void Initialize()
SubscribeLocalEvent<VendingMachineComponent, GotEmaggedEvent>(OnEmagged);
SubscribeLocalEvent<VendingMachineComponent, DamageChangedEvent>(OnDamage);
/* SubscribeLocalEvent<VendingMachineComponent, PriceCalculationEvent>(OnVendingPrice); */
SubscribeLocalEvent<VendingMachineComponent, EmpPulseEvent>(OnEmpPulse);

SubscribeLocalEvent<VendingMachineComponent, ActivatableUIOpenAttemptEvent>(OnActivatableUIOpenAttempt);
SubscribeLocalEvent<VendingMachineComponent, BoundUIOpenedEvent>(OnBoundUIOpened);
Expand Down Expand Up @@ -437,6 +442,15 @@ public override void Update(float frameTime)
}
}
}
var disabled = EntityQueryEnumerator<EmpDisabledComponent, VendingMachineComponent>();
while (disabled.MoveNext(out var uid, out _, out var comp))
{
if (comp.NextEmpEject < _timing.CurTime)
{
EjectRandom(uid, true, false, comp);
comp.NextEmpEject += TimeSpan.FromSeconds(5 * comp.EjectDelay);
}
}
}

public void TryRestockInventory(EntityUid uid, VendingMachineComponent? vendComponent = null)
Expand Down Expand Up @@ -473,5 +487,15 @@ private void OnPriceCalculation(EntityUid uid, VendingMachineRestockComponent co

args.Price += priceSets.Max();
}

private void OnEmpPulse(EntityUid uid, VendingMachineComponent component, ref EmpPulseEvent args)
{
if (!component.Broken && this.IsPowered(uid, EntityManager))
{
args.Affected = true;
args.Disabled = true;
component.NextEmpEject = _timing.CurTime;
}
}
}
}
Loading

0 comments on commit 4634d80

Please sign in to comment.