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

Jetpack Server Configuration (Port From Einstein-Engines) #2077

52 changes: 39 additions & 13 deletions Content.Shared/Movement/Systems/SharedJetpackSystem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Content.Shared.Actions;
using Content.Shared._EE.CCVar; // EE
using Content.Shared.Gravity;
using Content.Shared.Interaction.Events;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Popups;
using Robust.Shared.Configuration; // EE
using Robust.Shared.Containers;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
Expand All @@ -20,6 +22,7 @@ public abstract class SharedJetpackSystem : EntitySystem
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
[Dependency] private readonly IConfigurationManager _config = default!; // EE

public override void Initialize()
{
Expand Down Expand Up @@ -49,6 +52,9 @@ private void OnJetpackCanWeightlessMove(EntityUid uid, JetpackComponent componen

private void OnJetpackUserGravityChanged(ref GravityChangedEvent ev)
{
if (_config.GetCVar(EECCVars.JetpackEnableAnywhere)) // EE
return; // EE

var gridUid = ev.ChangedGridIndex;
var jetpackQuery = GetEntityQuery<JetpackComponent>();

Expand Down Expand Up @@ -77,8 +83,12 @@ private void OnJetpackUserCanWeightless(EntityUid uid, JetpackUserComponent comp

private void OnJetpackUserEntParentChanged(EntityUid uid, JetpackUserComponent component, ref EntParentChangedMessage args)
{
if (TryComp<JetpackComponent>(component.Jetpack, out var jetpack) &&
!CanEnableOnGrid(args.Transform.GridUid))
// Frontier: note - comment from upstream, dead men tell no tales
// No and no again! Do not attempt to activate the jetpack on a grid with gravity disabled. You will not be the first or the last to try this.
// https://discord.com/channels/310555209753690112/310555209753690112/1270067921682694234
if (TryComp<JetpackComponent>(component.Jetpack, out var jetpack)
&& (!CanEnableOnGrid(args.Transform.GridUid)
|| !UserNotParented(uid, jetpack))) // EE
{
SetEnabled(component.Jetpack, jetpack, false, uid);

Expand Down Expand Up @@ -127,8 +137,12 @@ private bool CanEnableOnGrid(EntityUid? gridUid)
{
// No and no again! Do not attempt to activate the jetpack on a grid with gravity disabled. You will not be the first or the last to try this.
// https://discord.com/channels/310555209753690112/310555209753690112/1270067921682694234
return gridUid == null ||
(!HasComp<GravityComponent>(gridUid));
return gridUid == null // EE
//||(!HasComp<GravityComponent>(gridUid)); // EE
|| _config.GetCVar(EECCVars.JetpackEnableAnywhere) // EE
|| _config.GetCVar(EECCVars.JetpackEnableInNoGravity) // EE
&& TryComp<GravityComponent>(gridUid, out var comp) // EE
&& !comp.Enabled; // EE
}

private void OnJetpackGetAction(EntityUid uid, JetpackComponent component, GetItemActionsEvent args)
Expand All @@ -149,15 +163,6 @@ public void SetEnabled(EntityUid uid, JetpackComponent component, bool enabled,
return;
}

if (enabled)
{
EnsureComp<ActiveJetpackComponent>(uid);
}
else
{
RemComp<ActiveJetpackComponent>(uid);
}

if (user == null)
{
Container.TryGetContainingContainer((uid, null, null), out var container);
Expand All @@ -168,6 +173,18 @@ public void SetEnabled(EntityUid uid, JetpackComponent component, bool enabled,
if (user == null && enabled)
return;

// EE: check if user has a parent (e.g. vehicle, duffelbag, bed)
if (enabled && !UserNotParented(user, component))
return;
// End EE

// EE: moved from above user check
if (enabled)
EnsureComp<ActiveJetpackComponent>(uid);
else
RemComp<ActiveJetpackComponent>(uid);
// End EE

if (user != null)
{
if (enabled)
Expand Down Expand Up @@ -195,6 +212,15 @@ protected virtual bool CanEnable(EntityUid uid, JetpackComponent component)
{
return true;
}

// EE: check parent
protected virtual bool UserNotParented(EntityUid? user, JetpackComponent component)
{
return !TryComp(user, out TransformComponent? xform)
|| xform.ParentUid == xform.GridUid
|| xform.ParentUid == xform.MapUid;
}
// End EE
}

[Serializable, NetSerializable]
Expand Down
26 changes: 26 additions & 0 deletions Content.Shared/_EE/CCVar/EECCVars.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Robust.Shared;
using Robust.Shared.Configuration;

namespace Content.Shared._EE.CCVar
{
// ReSharper disable once InconsistentNaming
[CVarDefs]
public sealed class EECCVars : CVars
{
#region Jetpack System

/// <summary>
/// When true, Jetpacks can be enabled anywhere, even in gravity.
/// </summary>
public static readonly CVarDef<bool> JetpackEnableAnywhere =
CVarDef.Create("ee.jetpack.enable_anywhere", false, CVar.REPLICATED);

/// <summary>
/// When true, jetpacks can be enabled on grids that have zero gravity.
/// </summary>
public static readonly CVarDef<bool> JetpackEnableInNoGravity =
CVarDef.Create("ee.jetpack.enable_in_no_gravity", true, CVar.REPLICATED);

#endregion
}
}
Loading