Skip to content

Commit

Permalink
Hybrisa (RMC-14#5518)
Browse files Browse the repository at this point in the history
Co-authored-by: DrSmugleaf <[email protected]>
  • Loading branch information
noctyrnal and DrSmugleaf authored Feb 22, 2025
1 parent 0909e02 commit 8e21f87
Show file tree
Hide file tree
Showing 1,589 changed files with 346,898 additions and 20 deletions.
16 changes: 16 additions & 0 deletions Content.Shared/_RMC14/Light/CMPoweredLightSystem.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using Content.Shared._RMC14.Xenonids;
using Content.Shared.Interaction.Events;
using Content.Shared.Popups;

namespace Content.Shared._RMC14.Light;

public sealed class CMPoweredLightSystem : EntitySystem
{
[Dependency] private readonly SharedPointLightSystem _pointLight = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;

public override void Initialize()
{
SubscribeLocalEvent<LightBurnHandAttemptEvent>(OnLightBurnHandAttempt);

SubscribeLocalEvent<PreventAttackLightOffComponent, GettingAttackedAttemptEvent>(OnPreventAttackLightOffAttackedAttempt);
}

private void OnLightBurnHandAttempt(ref LightBurnHandAttemptEvent ev)
Expand All @@ -18,4 +22,16 @@ private void OnLightBurnHandAttempt(ref LightBurnHandAttemptEvent ev)
if (!HasComp<XenoComponent>(ev.User))
_popup.PopupClient(Loc.GetString("cm-light-failed"), ev.Light, ev.User);
}

private void OnPreventAttackLightOffAttackedAttempt(Entity<PreventAttackLightOffComponent> ent, ref GettingAttackedAttemptEvent args)
{
if (args.Cancelled)
return;

if (!_pointLight.TryGetLight(ent, out var pointLight) ||
!pointLight.Enabled)
{
args.Cancelled = true;
}
}
}
7 changes: 7 additions & 0 deletions Content.Shared/_RMC14/Light/PreventAttackLightOffComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Robust.Shared.GameStates;

namespace Content.Shared._RMC14.Light;

[RegisterComponent, NetworkedComponent]
[Access(typeof(CMPoweredLightSystem))]
public sealed partial class PreventAttackLightOffComponent : Component;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Robust.Shared.GameStates;

namespace Content.Shared._RMC14.Power;

[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedRMCPowerSystem))]
public sealed partial class RMCReactorPoweredLightComponent : Component;
75 changes: 75 additions & 0 deletions Content.Shared/_RMC14/Power/SharedRMCPowerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
using Content.Shared.UserInterface;
using Content.Shared.Weapons.Melee;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using static Content.Shared.Popups.PopupType;

namespace Content.Shared._RMC14.Power;
Expand All @@ -33,13 +35,17 @@ public abstract class SharedRMCPowerSystem : EntitySystem
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedPointLightSystem _pointLight = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SkillsSystem _skills = default!;
[Dependency] private readonly SharedRMCSpriteSystem _sprite = default!;
[Dependency] private readonly SharedToolSystem _tool = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

protected readonly HashSet<EntityUid> ToUpdate = new();
private readonly Dictionary<MapId, List<EntityUid>> _reactorPoweredLights = new();
private readonly HashSet<MapId> _reactorsUpdated = new();

private EntityQuery<RMCApcComponent> _apcQuery;
private EntityQuery<RMCAreaPowerComponent> _areaPowerQuery;
Expand Down Expand Up @@ -75,6 +81,8 @@ public override void Initialize()
SubscribeLocalEvent<RMCFusionReactorComponent, RMCFusionReactorDestroyDoAfterEvent>(OnFusionReactorDestroyDoAfter);
SubscribeLocalEvent<RMCFusionReactorComponent, ExaminedEvent>(OnFusionReactorExamined);

SubscribeLocalEvent<RMCReactorPoweredLightComponent, MapInitEvent>(OnReactorPoweredLightMapInit);

Subs.BuiEvents<RMCApcComponent>(RMCApcUiKey.Key,
subs =>
{
Expand Down Expand Up @@ -335,6 +343,7 @@ private void OnFusionReactorMapInit(Entity<RMCFusionReactorComponent> ent, ref M
}

UpdateAppearance(ent);
ReactorUpdated(ent);
}

private void OnFusionReactorInteractUsing(Entity<RMCFusionReactorComponent> ent, ref InteractUsingEvent args)
Expand Down Expand Up @@ -476,6 +485,7 @@ private void OnFusionReactorRepairWeldingDoAfter(Entity<RMCFusionReactorComponen

Dirty(ent);
UpdateAppearance(ent);
ReactorUpdated(ent);
}

private void OnFusionReactorInteractHand(Entity<RMCFusionReactorComponent> ent, ref InteractHandEvent args)
Expand Down Expand Up @@ -528,6 +538,8 @@ private void OnFusionReactorDestroyDoAfter(Entity<RMCFusionReactorComponent> ent

if (ent.Comp.State != RMCFusionReactorState.Weld)
args.Repeat = true;

ReactorUpdated(ent);
}

private void OnFusionReactorExamined(Entity<RMCFusionReactorComponent> ent, ref ExaminedEvent args)
Expand Down Expand Up @@ -560,6 +572,12 @@ private void OnFusionReactorExamined(Entity<RMCFusionReactorComponent> ent, ref
}
}

private void OnReactorPoweredLightMapInit(Entity<RMCReactorPoweredLightComponent> ent, ref MapInitEvent args)
{
if (TryComp(ent, out TransformComponent? xform))
_reactorPoweredLights.GetOrNew(xform.MapID).Add(ent);
}

private void OnApcSetChannelBuiMsg(Entity<RMCApcComponent> ent, ref RMCApcSetChannelBuiMsg args)
{
return;
Expand Down Expand Up @@ -727,14 +745,71 @@ public bool IsAreaPowered(Entity<RMCAreaPowerComponent?> area, RMCPowerChannel c

public abstract bool IsPowered(EntityUid ent);

private bool AnyReactorsOn(MapId map)
{
var reactors = EntityQueryEnumerator<RMCFusionReactorComponent, TransformComponent>();
while (reactors.MoveNext(out var comp, out var xform))
{
if (comp.State == RMCFusionReactorState.Working && xform.MapID == map)
return true;
}

return false;
}

private void ReactorUpdated(Entity<RMCFusionReactorComponent> ent)
{
var mapId = _transform.GetMapId(ent.Owner);
_reactorsUpdated.Add(mapId);
}

public override void Update(float frameTime)
{
if (_net.IsClient)
{
ToUpdate.Clear();
_reactorPoweredLights.Clear();
_reactorsUpdated.Clear();
return;
}

if (_reactorPoweredLights.Count > 0)
{
try
{
foreach (var (map, lights) in _reactorPoweredLights)
{
var powered = AnyReactorsOn(map);
foreach (var light in lights)
{
_pointLight.SetEnabled(light, powered);
}
}
}
finally
{
_reactorPoweredLights.Clear();
}
}

try
{
foreach (var map in _reactorsUpdated)
{
var powered = AnyReactorsOn(map);
var lights = EntityQueryEnumerator<RMCReactorPoweredLightComponent, TransformComponent>();
while (lights.MoveNext(out var uid, out _, out var xform))
{
if (xform.MapID == map)
_pointLight.SetEnabled(uid, powered);
}
}
}
finally
{
_reactorsUpdated.Clear();
}

try
{
foreach (var update in ToUpdate)
Expand Down
Loading

0 comments on commit 8e21f87

Please sign in to comment.