Skip to content

Commit

Permalink
It works
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Jul 9, 2024
1 parent a6073ef commit 57c3e21
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.OpenBackpack);
human.AddFunction(ContentKeyFunctions.OpenBelt);
human.AddFunction(ContentKeyFunctions.OfferItem);
human.AddFunction(ContentKeyFunctions.ToggleStanding);
human.AddFunction(ContentKeyFunctions.MouseMiddle);
human.AddFunction(ContentKeyFunctions.ArcadeUp);
human.AddFunction(ContentKeyFunctions.ArcadeDown);
Expand Down
1 change: 1 addition & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.MoveStoredItem);
AddButton(ContentKeyFunctions.RotateStoredItem);
AddButton(ContentKeyFunctions.OfferItem);
AddButton(ContentKeyFunctions.ToggleStanding);

AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack);
Expand Down
17 changes: 17 additions & 0 deletions Content.Server/Standing/LayingDownComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Content.Server.Standing;

[RegisterComponent]
public sealed partial class LayingDownComponent : Component
{
/// <summary>
/// Movement speed multiplier when not standing.
/// </summary>
[DataField]
public float DownedSpeedMultiplier = 0.15f;

[DataField]
public TimeSpan Cooldown = TimeSpan.FromSeconds(2.5f);

[DataField]
public TimeSpan CooldownUntil = TimeSpan.Zero;
}
94 changes: 94 additions & 0 deletions Content.Server/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Input;
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.Standing;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;
using Robust.Shared.Timing;

namespace Content.Server.Standing;

// Unfortunately cannot be shared because some standing conditions are server-side only
public sealed class LayingDownSystem : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;r
[Dependency] private readonly SharedPopupSystem _popups = default!;

Check failure on line 17 in Content.Server/Standing/LayingDownSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

Member modifier 'private' must precede the member type and name

Check failure on line 17 in Content.Server/Standing/LayingDownSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

Member modifier 'private' must precede the member type and name

Check failure on line 17 in Content.Server/Standing/LayingDownSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Member modifier 'private' must precede the member type and name

Check failure on line 17 in Content.Server/Standing/LayingDownSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Member modifier 'private' must precede the member type and name

Check failure on line 17 in Content.Server/Standing/LayingDownSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Member modifier 'private' must precede the member type and name

Check failure on line 17 in Content.Server/Standing/LayingDownSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Member modifier 'private' must precede the member type and name

Check failure on line 17 in Content.Server/Standing/LayingDownSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Member modifier 'private' must precede the member type and name

Check failure on line 17 in Content.Server/Standing/LayingDownSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Member modifier 'private' must precede the member type and name
[Dependency] private readonly Shared.Standing.StandingStateSystem _standing = default!; // WHY IS THERE TWO DIFFERENT STANDING SYSTEMS?!
[Dependency] private readonly IGameTiming _timing = default!;

public override void Initialize()
{
CommandBinds.Builder
.Bind(ContentKeyFunctions.ToggleStanding, InputCmdHandler.FromDelegate(ToggleStanding, handle: false, outsidePrediction: false))
.Register<LayingDownSystem>();

SubscribeLocalEvent<LayingDownComponent, StoodEvent>(DoRefreshMovementSpeed);
SubscribeLocalEvent<LayingDownComponent, DownedEvent>(DoRefreshMovementSpeed);
SubscribeLocalEvent<LayingDownComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeed);
}

public override void Shutdown()
{
base.Shutdown();

CommandBinds.Unregister<LayingDownSystem>();
}

private void DoRefreshMovementSpeed(EntityUid uid, LayingDownComponent component, object args)
{
_movement.RefreshMovementSpeedModifiers(uid);
}

private void OnRefreshMovementSpeed(EntityUid uid, LayingDownComponent component, RefreshMovementSpeedModifiersEvent args)
{
if (TryComp<StandingStateComponent>(uid, out var standingState) && standingState.Standing)
return;

args.ModifySpeed(component.DownedSpeedMultiplier, component.DownedSpeedMultiplier);
}

private void ToggleStanding(ICommonSession? session)
{
if (session is not { } playerSession)
return;

if ((playerSession.AttachedEntity is not { Valid: true } uid || !Exists(uid)))
return;

if (!TryComp<StandingStateComponent>(uid, out var standingState) || !TryComp<LayingDownComponent>(uid, out var layingDown))
return;

var success = ToggleStandingImpl(uid, standingState, layingDown, out var popupBranch);

// If successful, show popup to self and others. Otherwise, only to self.
_popups.PopupEntity(Loc.GetString($"laying-comp-{popupBranch}-self", ("entity", uid)), uid, uid);

if (success)
{
_popups.PopupEntity(Loc.GetString($"laying-comp-{popupBranch}-other", ("entity", uid)), uid, Filter.PvsExcept(uid), true);

layingDown.CooldownUntil = _timing.CurTime + layingDown.Cooldown;
}
}

private bool ToggleStandingImpl(EntityUid uid, StandingStateComponent standingState, LayingDownComponent layingDown, out string popupBranch)
{
var success = layingDown.CooldownUntil <= _timing.CurTime;

// Note: &= leads to the right-hand side being evaluated regardless of what's on left-hand, so we use normal assignment here instead.
if (_standing.IsDown(uid, standingState))
{
success = success && _standing.Stand(uid, standingState, force: false);
popupBranch = success ? "stand-success" : "stand-fail";
}
else
{
success = success && _standing.Down(uid, standingState: standingState, playSound: true, dropHeldItems: false);
popupBranch = success ? "lay-success" : "lay-fail";
}

return success;
}
}
1 change: 1 addition & 0 deletions Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction ZoomIn = "ZoomIn";
public static readonly BoundKeyFunction ResetZoom = "ResetZoom";
public static readonly BoundKeyFunction OfferItem = "OfferItem";
public static readonly BoundKeyFunction ToggleStanding = "ToggleStanding";

public static readonly BoundKeyFunction ArcadeUp = "ArcadeUp";
public static readonly BoundKeyFunction ArcadeDown = "ArcadeDown";
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ ui-options-function-swap-hands = Swap hands
ui-options-function-move-stored-item = Move stored item
ui-options-function-rotate-stored-item = Rotate stored item
ui-options-function-offer-item = Offer something
ui-options-function-toggle-standing = Toggle standing
ui-options-static-storage-ui = Lock storage window to hotbar
ui-options-function-smart-equip-backpack = Smart-equip to backpack
Expand Down
7 changes: 7 additions & 0 deletions Resources/Locale/en-US/movement/laying.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
laying-comp-lay-success-self = You lay down.
laying-comp-lay-success-other = {THE($entity)} lays down.
laying-comp-lay-fail-self = You can't lay down right now.
laying-comp-stand-success-self = You stand up.
laying-comp-stand-success-other = {THE($entity)} stands up.
laying-comp-stand-fail-self = You can't stand up right now.
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Species/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
- type: FireVisuals
alternateState: Standing
- type: OfferItem
- type: LayingDown

- type: entity
save: false
Expand Down
3 changes: 3 additions & 0 deletions Resources/keybinds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ binds:
- function: OfferItem
type: State
key: F
- function: ToggleStanding
type: State
key: R
- function: ShowDebugConsole
type: State
key: Tilde
Expand Down

0 comments on commit 57c3e21

Please sign in to comment.