This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
forked from estacaoespacialpirata/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Emp more effects" (space-wizards#16159)" (space-wizar…
- Loading branch information
1 parent
a0f86d7
commit 4634d80
Showing
18 changed files
with
245 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.