Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the removel of gravity generator and anchors while they are on #2723

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Content.Server/Gravity/GravityGeneratorSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using Content.Server.Emp; // Frontier: Upstream - #28984
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Construction.Components; // Frontier
using Content.Shared.Gravity;
using Content.Shared.Tools.Components; // Frontier
using Content.Shared.Popups; // Frontier

namespace Content.Server.Gravity;

Expand All @@ -10,6 +14,8 @@ public sealed class GravityGeneratorSystem : EntitySystem
[Dependency] private readonly GravitySystem _gravitySystem = default!;
[Dependency] private readonly SharedPointLightSystem _lights = default!;

[Dependency] private readonly PopupSystem _popupSystem = default!; // Frontier

public override void Initialize()
{
base.Initialize();
Expand All @@ -18,6 +24,8 @@ public override void Initialize()
SubscribeLocalEvent<GravityGeneratorComponent, ChargedMachineActivatedEvent>(OnActivated);
SubscribeLocalEvent<GravityGeneratorComponent, ChargedMachineDeactivatedEvent>(OnDeactivated);
// SubscribeLocalEvent<GravityGeneratorComponent, EmpPulseEvent>(OnEmpPulse); // Frontier: Upstream - #28984
SubscribeLocalEvent<GravityGeneratorComponent, UnanchorAttemptEvent>(OnUnanchorAttempt); // Frontier
SubscribeLocalEvent<GravityGeneratorComponent, ToolUseAttemptEvent>(OnToolUseAttempt); // Frontier
}

public override void Update(float frameTime)
Expand Down Expand Up @@ -59,6 +67,48 @@ private void OnDeactivated(Entity<GravityGeneratorComponent> ent, ref ChargedMac
}
}

/// <summary>
/// Frontier: Prevent unanchoring when anchor is active
/// </summary>
private void OnUnanchorAttempt(Entity<GravityGeneratorComponent> ent, ref UnanchorAttemptEvent args)
{
if (!ent.Comp.GravityActive)
return;

_popupSystem.PopupEntity(
Loc.GetString("gravity-generator-unanchoring-failed"),
ent,
args.User,
PopupType.Medium);

args.Cancel();
}

/// <summary>
/// Frontier: Prevent disassembly when anchor is active
/// </summary>
private void OnToolUseAttempt(Entity<GravityGeneratorComponent> ent, ref ToolUseAttemptEvent args)
{
if (!ent.Comp.GravityActive)
return;

foreach (var quality in args.Qualities)
{
// prevent reconstruct
if (quality == "Prying")
{
_popupSystem.PopupEntity(
Loc.GetString("gravity-generator-unanchoring-failed"),
ent,
args.User,
PopupType.Medium);

args.Cancel();
return;
}
}
}

private void OnParentChanged(EntityUid uid, GravityGeneratorComponent component, ref EntParentChangedMessage args)
{
if (component.GravityActive && TryComp(args.OldParent, out GravityComponent? gravity))
Expand Down
30 changes: 29 additions & 1 deletion Content.Server/Shuttles/Systems/StationAnchorSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Content.Server.Popups;
using Content.Server.Popups;
using Content.Server.Power.EntitySystems;
using Content.Server.Shuttles.Components;
using Content.Shared.Construction.Components;
using Content.Shared.Popups;
using Content.Shared.Tools.Components; // Frontier

namespace Content.Server.Shuttles.Systems;

Expand All @@ -21,6 +22,8 @@ public override void Initialize()
SubscribeLocalEvent<StationAnchorComponent, ChargedMachineDeactivatedEvent>(OnDeactivated);

SubscribeLocalEvent<StationAnchorComponent, MapInitEvent>(OnMapInit);

SubscribeLocalEvent<StationAnchorComponent, ToolUseAttemptEvent>(OnToolUseAttempt); // Frontier
}

private void OnMapInit(Entity<StationAnchorComponent> ent, ref MapInitEvent args)
Expand Down Expand Up @@ -58,6 +61,31 @@ private void OnUnanchorAttempt(Entity<StationAnchorComponent> ent, ref UnanchorA
args.Cancel();
}

/// <summary>
/// Frontier: Prevent disassembly when anchor is active
/// </summary>
private void OnToolUseAttempt(Entity<StationAnchorComponent> ent, ref ToolUseAttemptEvent args)
{
if (!ent.Comp.SwitchedOn)
return;

foreach (var quality in args.Qualities)
{
// prevent reconstruct
if (quality == "Prying")
{
_popupSystem.PopupEntity(
Loc.GetString("station-anchor-unanchoring-failed"),
ent,
args.User,
PopupType.Medium);

args.Cancel();
return;
}
}
}

private void OnAnchorStationChange(Entity<StationAnchorComponent> ent, ref AnchorStateChangedEvent args)
{
if (!args.Anchored)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Gravity Generator

gravity-generator-unanchoring-failed = Can't unanchor an active gravity generator
Loading