-
Notifications
You must be signed in to change notification settings - Fork 450
Better Lying Down System (From White Dream) #815
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
Merged
VMSolidus
merged 13 commits into
Simple-Station:master
from
VMSolidus:Port-Better-Lying-Down-System
Sep 19, 2024
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2f179d3
Cherry-Pick Lying Down System
Spatison bb20169
Cleanup
VMSolidus 6af7bce
Merge branch 'master' into Port-Better-Lying-Down-System
VMSolidus b9fcf5a
Moving more things
VMSolidus 839b1ce
Merge branch 'Port-Better-Lying-Down-System' of https://github.com/VM…
VMSolidus 54960b7
Small fixes.
VMSolidus 09e1bc3
aaaaaaaaaaa
VMSolidus 8560c3d
[Port] Telescope System / Система Прицеливания (#8)
Spatison c4e7545
aaaaaaaaaa
VMSolidus 2b87187
Little cleanup
VMSolidus 5b98cde
Merge branch 'master' into Port-Better-Lying-Down-System
VMSolidus 68fcd8c
Merge branch 'master' into Port-Better-Lying-Down-System
VMSolidus 4847961
Apply suggestions from code review
VMSolidus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| using Content.Shared.Buckle; | ||
| using Content.Shared.Rotation; | ||
| using Content.Shared.Standing; | ||
| using Robust.Client.GameObjects; | ||
| using Robust.Client.Graphics; | ||
| using Robust.Shared.Timing; | ||
|
|
||
| namespace Content.Client._White.Standing; | ||
|
|
||
| public sealed class LayingDownSystem : SharedLayingDownSystem | ||
| { | ||
| [Dependency] private readonly IGameTiming _timing = default!; | ||
| [Dependency] private readonly IEyeManager _eyeManager = default!; | ||
| [Dependency] private readonly StandingStateSystem _standing = default!; | ||
| [Dependency] private readonly AnimationPlayerSystem _animation = default!; | ||
| [Dependency] private readonly SharedBuckleSystem _buckle = default!; | ||
|
|
||
| public override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
|
|
||
| SubscribeLocalEvent<LayingDownComponent, MoveEvent>(OnMovementInput); | ||
|
|
||
| SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp); | ||
| } | ||
|
|
||
| private void OnMovementInput(EntityUid uid, LayingDownComponent component, MoveEvent args) | ||
| { | ||
| if (!_timing.IsFirstTimePredicted | ||
| || !_standing.IsDown(uid) | ||
| || _buckle.IsBuckled(uid) | ||
| || _animation.HasRunningAnimation(uid, "rotate") | ||
| || !TryComp<TransformComponent>(uid, out var transform) | ||
| || !TryComp<SpriteComponent>(uid, out var sprite) | ||
| || !TryComp<RotationVisualsComponent>(uid, out var rotationVisuals)) | ||
| return; | ||
|
|
||
| var rotation = transform.LocalRotation + (_eyeManager.CurrentEye.Rotation - (transform.LocalRotation - transform.WorldRotation)); | ||
|
|
||
| if (rotation.GetDir() is Direction.SouthEast or Direction.East or Direction.NorthEast or Direction.North) | ||
| { | ||
| rotationVisuals.HorizontalRotation = Angle.FromDegrees(270); | ||
| sprite.Rotation = Angle.FromDegrees(270); | ||
| return; | ||
| } | ||
|
|
||
| rotationVisuals.HorizontalRotation = Angle.FromDegrees(90); | ||
| sprite.Rotation = Angle.FromDegrees(90); | ||
| } | ||
|
|
||
| private void OnCheckAutoGetUp(CheckAutoGetUpEvent ev, EntitySessionEventArgs args) | ||
| { | ||
| if (!_timing.IsFirstTimePredicted) | ||
| return; | ||
|
|
||
| var uid = GetEntity(ev.User); | ||
|
|
||
| if (!TryComp<TransformComponent>(uid, out var transform) || !TryComp<RotationVisualsComponent>(uid, out var rotationVisuals)) | ||
| return; | ||
|
|
||
| var rotation = transform.LocalRotation + (_eyeManager.CurrentEye.Rotation - (transform.LocalRotation - transform.WorldRotation)); | ||
|
|
||
| if (rotation.GetDir() is Direction.SouthEast or Direction.East or Direction.NorthEast or Direction.North) | ||
| { | ||
| rotationVisuals.HorizontalRotation = Angle.FromDegrees(270); | ||
| return; | ||
| } | ||
|
|
||
| rotationVisuals.HorizontalRotation = Angle.FromDegrees(90); | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,101 +1,27 @@ | ||
| 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; | ||
| using Robust.Shared.Configuration; | ||
|
|
||
| namespace Content.Server.Standing; | ||
|
|
||
| /// <remarks>Unfortunately cannot be shared because some standing conditions are server-side only</remarks> | ||
| public sealed class LayingDownSystem : EntitySystem | ||
| public sealed class LayingDownSystem : SharedLayingDownSystem | ||
| { | ||
| [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; | ||
| [Dependency] private readonly MovementSpeedModifierSystem _movement = default!; | ||
| [Dependency] private readonly SharedPopupSystem _popups = default!; | ||
| [Dependency] private readonly Shared.Standing.StandingStateSystem _standing = default!; // WHY IS THERE TWO DIFFERENT STANDING SYSTEMS?! | ||
| [Dependency] private readonly IGameTiming _timing = default!; | ||
|
|
||
| [Dependency] private readonly INetConfigurationManager _cfg = 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); | ||
| SubscribeLocalEvent<LayingDownComponent, EntParentChangedMessage>(OnParentChanged); | ||
| } | ||
|
|
||
| public override void Shutdown() | ||
| { | ||
| base.Shutdown(); | ||
|
|
||
| CommandBinds.Unregister<LayingDownSystem>(); | ||
| } | ||
| base.Initialize(); | ||
|
|
||
| private void DoRefreshMovementSpeed(EntityUid uid, LayingDownComponent component, object args) | ||
| { | ||
| _movement.RefreshMovementSpeedModifiers(uid); | ||
| SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp); | ||
| } | ||
|
|
||
| private void OnRefreshMovementSpeed(EntityUid uid, LayingDownComponent component, RefreshMovementSpeedModifiersEvent args) | ||
| private void OnCheckAutoGetUp(CheckAutoGetUpEvent ev, EntitySessionEventArgs args) | ||
| { | ||
| if (TryComp<StandingStateComponent>(uid, out var standingState) && standingState.Standing) | ||
| return; | ||
| var uid = GetEntity(ev.User); | ||
|
|
||
| args.ModifySpeed(component.DownedSpeedMultiplier, component.DownedSpeedMultiplier, bypassImmunity: true); | ||
| } | ||
|
|
||
| private void OnParentChanged(EntityUid uid, LayingDownComponent component, EntParentChangedMessage args) | ||
| { | ||
| // If the entity is not on a grid, try to make it stand up to avoid issues | ||
| if (!TryComp<StandingStateComponent>(uid, out var standingState) | ||
| || standingState.Standing | ||
| || Transform(uid).GridUid != null) | ||
| if (!TryComp(uid, out LayingDownComponent? layingDown)) | ||
| return; | ||
|
|
||
| _standing.Stand(uid, standingState); | ||
| } | ||
|
|
||
| private void ToggleStanding(ICommonSession? session) | ||
| { | ||
| if (session is not { AttachedEntity: { Valid: true } uid } playerSession | ||
| || !Exists(uid) | ||
| || !TryComp<StandingStateComponent>(uid, out var standingState) | ||
| || !TryComp<LayingDownComponent>(uid, out var layingDown)) | ||
| return; | ||
|
|
||
| // If successful, show popup to self and others. Otherwise, only to self. | ||
| if (ToggleStandingImpl(uid, standingState, layingDown, out var popupBranch)) | ||
| { | ||
| _popups.PopupEntity(Loc.GetString($"laying-comp-{popupBranch}-other", ("entity", uid)), uid, Filter.PvsExcept(uid), true); | ||
| layingDown.NextToggleAttempt = _timing.CurTime + layingDown.Cooldown; | ||
| } | ||
|
|
||
| _popups.PopupEntity(Loc.GetString($"laying-comp-{popupBranch}-self", ("entity", uid)), uid, uid); | ||
| } | ||
|
|
||
| private bool ToggleStandingImpl(EntityUid uid, StandingStateComponent standingState, LayingDownComponent layingDown, out string popupBranch) | ||
| { | ||
| var success = layingDown.NextToggleAttempt <= _timing.CurTime; | ||
|
|
||
| if (_standing.IsDown(uid, standingState)) | ||
| { | ||
| success = success && _standing.Stand(uid, standingState, force: false); | ||
| popupBranch = success ? "stand-success" : "stand-fail"; | ||
| } | ||
| else | ||
| { | ||
| success = success && Transform(uid).GridUid != null; // Do not allow laying down when not on a surface. | ||
| success = success && _standing.Down(uid, standingState: standingState, playSound: true, dropHeldItems: false); | ||
| popupBranch = success ? "lay-success" : "lay-fail"; | ||
| } | ||
|
|
||
| return success; | ||
| layingDown.AutoGetUp = _cfg.GetClientCVar(args.SenderSession.Channel, WhiteCVars.AutoGetUp); | ||
| Dirty(uid, layingDown); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using Robust.Shared.GameStates; | ||
| using Robust.Shared.Serialization; | ||
|
|
||
| namespace Content.Shared.Standing; | ||
|
|
||
| [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
| public sealed partial class LayingDownComponent : Component | ||
| { | ||
| [DataField, AutoNetworkedField] | ||
| public float StandingUpTime { get; set; } = 1f; | ||
|
|
||
| [DataField, AutoNetworkedField] | ||
| public float SpeedModify { get; set; } = 0.4f; | ||
|
|
||
| [DataField, AutoNetworkedField] | ||
| public bool AutoGetUp; | ||
| } | ||
|
|
||
| [Serializable, NetSerializable] | ||
| public sealed class ChangeLayingDownEvent : CancellableEntityEventArgs; | ||
|
|
||
| [Serializable, NetSerializable] | ||
| public sealed class CheckAutoGetUpEvent(NetEntity user) : CancellableEntityEventArgs | ||
| { | ||
| public NetEntity User = user; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.