Skip to content
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
15 changes: 15 additions & 0 deletions Content.Shared/Movement/Components/JetpackComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,19 @@ public sealed partial class JetpackComponent : Component

[ViewVariables(VVAccess.ReadWrite), DataField("weightlessModifier")]
public float WeightlessModifier = 1.2f;

// DeltaV Start - Jetpacks automatically toggle on.
/// <summary>
/// When toggling the jetpack, this will turn true/false.
/// Upon leaving a grid, this will determine if the jetpack activates.
/// </summary>
[DataField, AutoNetworkedField]
public bool AutomaticMode;

/// <summary>
/// The user whose jetpack is waiting to activate.
/// </summary>
[DataField, AutoNetworkedField]
public EntityUid? AutomaticUser;
// DeltaV End - Jetpacks automatically toggle on.
}
38 changes: 24 additions & 14 deletions Content.Shared/Movement/Systems/SharedJetpackSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared._DVA.Movement.Components; // DeltaV - Jetpacks automatically toggle on.
using Content.Shared.Actions;
using Content.Shared.Gravity;
using Content.Shared.Interaction.Events;
Expand Down Expand Up @@ -36,6 +37,7 @@ public override void Initialize()

SubscribeLocalEvent<GravityChangedEvent>(OnJetpackUserGravityChanged);
SubscribeLocalEvent<JetpackComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<DVAutomaticJetpackUserComponent, EntParentChangedMessage>(OnAutomaticJetpackEntParentChanged); // DeltaV - Jetpacks automatically toggle on.
}

private void OnJetpackUserWeightlessMovement(Entity<JetpackUserComponent> ent, ref RefreshWeightlessModifiersEvent args)
Expand Down Expand Up @@ -71,13 +73,17 @@ private void OnJetpackUserGravityChanged(ref GravityChangedEvent ev)

private void OnJetpackDropped(EntityUid uid, JetpackComponent component, DroppedEvent args)
{
RemoveAutomaticJetpack((uid, component)); // DeltaV - Jetpacks automatically toggle on.
SetEnabled(uid, component, false, args.User);
}

private void OnJetpackMoved(Entity<JetpackComponent> ent, ref EntGotInsertedIntoContainerMessage args)
{
if (args.Container.Owner != ent.Comp.JetpackUser)
{
RemoveAutomaticJetpack(ent); // DeltaV - Jetpacks automatically toggle on.
SetEnabled(ent, ent.Comp, false, ent.Comp.JetpackUser);
}
}

private void OnJetpackUserCanWeightless(EntityUid uid, JetpackUserComponent component, ref CanWeightlessMoveEvent args)
Expand Down Expand Up @@ -125,20 +131,22 @@ private void RemoveUser(EntityUid uid, JetpackComponent component)
_movementSpeedModifier.RefreshWeightlessModifiers(uid);
}

private void OnJetpackToggle(EntityUid uid, JetpackComponent component, ToggleJetpackEvent args)
{
if (args.Handled)
return;

if (TryComp(uid, out TransformComponent? xform) && !CanEnableOnGrid(xform.GridUid))
{
_popup.PopupEntity(Loc.GetString("jetpack-no-station"), uid, args.Performer);

return;
}

SetEnabled(uid, component, !IsEnabled(uid));
}
/// DeltaV Start - Replaced with DeltaV method in <see cref="SharedJetpackSystem"/>
// private void OnJetpackToggle(EntityUid uid, JetpackComponent component, ToggleJetpackEvent args)
// {
// if (args.Handled)
// return;
//
// if (TryComp(uid, out TransformComponent? xform) && !CanEnableOnGrid(xform.GridUid))
// {
// _popup.PopupClient(Loc.GetString("jetpack-no-station"), uid, args.Performer);
//
// return;
// }
//
// SetEnabled(uid, component, !IsEnabled(uid));
// }
// DeltaV End - Replaced with DeltaV method.

private bool CanEnableOnGrid(EntityUid? gridUid)
{
Expand Down Expand Up @@ -171,6 +179,8 @@ public void SetEnabled(EntityUid uid, JetpackComponent component, bool enabled,
user = container.Owner;
}

RefreshAutomaticJetpack((uid, component), user.Value, enabled); // DeltaV - Jetpacks automatically turn on when toggled.

if (enabled)
{
// If the user is already using another jetpack, disable it first
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Robust.Shared.GameStates;

namespace Content.Shared._DVA.Movement.Components;

/// <summary>
/// Added when someone holds a jetpack that is toggled active and waits to turn on.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class DVAutomaticJetpackUserComponent : Component
{
/// <summary>
/// The jetpack that will automatically activate.
/// </summary>
[DataField, AutoNetworkedField]
public EntityUid Jetpack;
}
76 changes: 76 additions & 0 deletions Content.Shared/_DVA/Movement/Systems/SharedJetpackSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Content.Shared._DVA.Movement.Components;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;

namespace Content.Shared.Movement.Systems;

public abstract partial class SharedJetpackSystem
{
[Dependency] private SharedTransformSystem _transform = default!;

private void OnJetpackToggle(Entity<JetpackComponent> jetpack, ref ToggleJetpackEvent args)
{
Comment on lines +7 to +12

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole thing should be its own system

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't make this. This is a port. You'd need to pull in the original author @SirWarock if you want to have major changes :P

if (args.Handled)
return;

jetpack.Comp.AutomaticMode = !jetpack.Comp.AutomaticMode;
jetpack.Comp.AutomaticUser = args.Performer;
Dirty(jetpack);

if (!CanEnableOnGrid(_transform.GetGrid(jetpack.Owner)))
{
if (jetpack.Comp.AutomaticMode)
{
var autoUser = EnsureComp<DVAutomaticJetpackUserComponent>(args.Performer);
autoUser.Jetpack = jetpack;
Dirty(args.Performer, autoUser);
}
else
{
RemComp<DVAutomaticJetpackUserComponent>(args.Performer);
Comment thread
sowelipililimute marked this conversation as resolved.
}

var message = jetpack.Comp.AutomaticMode ? "jetpack-activated-on-grid" : "jetpack-deactivated";
_popup.PopupEntity(Loc.GetString(message), jetpack, args.Performer);
return;
Comment thread
sowelipililimute marked this conversation as resolved.
}

var messageOffGrid = jetpack.Comp.AutomaticMode ? "jetpack-activated-off-grid" : "jetpack-deactivated";
_popup.PopupEntity(Loc.GetString(messageOffGrid), jetpack, args.Performer);

SetEnabled(jetpack.Owner, jetpack.Comp, !IsEnabled(jetpack.Owner));
}

private void OnAutomaticJetpackEntParentChanged(Entity<DVAutomaticJetpackUserComponent> jetpackUser, ref EntParentChangedMessage args)
{
if (!TryComp<JetpackComponent>(jetpackUser.Comp.Jetpack, out var jetpack)
|| args.Transform.GridUid != null)
return;

SetEnabled(jetpackUser.Comp.Jetpack, jetpack, true, args.Entity);
_popup.PopupEntity(Loc.GetString("jetpack-activates-automatically"), args.Entity, args.Entity);
}

private void RemoveAutomaticJetpack(Entity<JetpackComponent> jetpack)
{
jetpack.Comp.AutomaticMode = false;
if (jetpack.Comp.AutomaticUser.HasValue)
RemComp<DVAutomaticJetpackUserComponent>(jetpack.Comp.AutomaticUser.Value);
jetpack.Comp.AutomaticUser = null;
}

private void RefreshAutomaticJetpack(Entity<JetpackComponent> jetpack, EntityUid user, bool jetpackEnabled)
{
if (jetpackEnabled)
{
RemComp<DVAutomaticJetpackUserComponent>(user);
}
else if (jetpack.Comp.AutomaticMode)
{
var pack = EnsureComp<DVAutomaticJetpackUserComponent>(user);
pack.Jetpack = jetpack;
Dirty(user, pack);
}

}
}
4 changes: 4 additions & 0 deletions Resources/Locale/en-US/_DVA/movement/jetpacks.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jetpack-activated-on-grid = The jetpack will automatically turn on when leaving the station.
jetpack-activated-off-grid = The jetpack turns on.
jetpack-activates-automatically = The jetpack automatically turns on.
jetpack-deactivated = The jetpack will no longer turn on.
Loading