Skip to content

Commit

Permalink
[Port] Laying System (space-syndicate#83)
Browse files Browse the repository at this point in the history
* [Port] Laying System

Barebones port of Rxup/space-station-14#745

* aaa

* Update GhostSystem.cs

* Update GhostSystem.cs

* Feature: Back in Round Button

* Update CCVars.cs

* up1

* up2

* upd

* update test

---------

Co-authored-by: Zack Backmen <[email protected]>
Co-authored-by: Trest <[email protected]>

* all fixes of laying system at once

---------

Co-authored-by: Zack Backmen <[email protected]>
Co-authored-by: Trest <[email protected]>
Co-authored-by: Roudenn <[email protected]>

* backmen to _CorvaxNext and move to appropriate folders

* laying system hotkey on Shift C

* let me pass tests

---------

Co-authored-by: Trest <[email protected]>
Co-authored-by: Zack Backmen <[email protected]>
Co-authored-by: Roudenn <[email protected]>
  • Loading branch information
4 people authored Nov 25, 2024
1 parent 744d490 commit 6bae52d
Show file tree
Hide file tree
Showing 20 changed files with 890 additions and 151 deletions.
3 changes: 2 additions & 1 deletion Content.Client/Buckle/BuckleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref Ap
!buckled ||
args.Sprite == null)
{
_rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation);
// _CorvaxNext: Laying System
//_rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation);
return;
}

Expand Down
1 change: 1 addition & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.TargetLeftLeg); // _CorvaxNext: surgery
human.AddFunction(ContentKeyFunctions.TargetRightLeg); // _CorvaxNext: surgery
human.AddFunction(ContentKeyFunctions.OfferItem); // Corvax-Next-Offer
human.AddFunction(ContentKeyFunctions.ToggleStanding); // CorvaxNext: laying system toggle standing

// actions should be common (for ghosts, mobs, etc)
common.AddFunction(ContentKeyFunctions.OpenActionsMenu);
Expand Down
10 changes: 10 additions & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
KeybindsContainer.AddChild(newCheckBox);
}

// start-_CorvaxNext: Laying System
void HandleToggleAutoGetUp(BaseButton.ButtonToggledEventArgs args) // WD EDIT
{
_cfg.SetCVar(Shared._CorvaxNext.NextVars.NextVars.AutoGetUp, args.Pressed);
_cfg.SaveToFile();
}
// end-_CorvaxNext: Laying System

AddHeader("ui-options-header-general");
AddCheckBox("ui-options-hotkey-keymap", _cfg.GetCVar(CVars.DisplayUSQWERTYHotkeys), HandleToggleUSQWERTYCheckbox);

Expand All @@ -161,6 +169,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(EngineKeyFunctions.MoveRight);
AddButton(EngineKeyFunctions.Walk);
AddCheckBox("ui-options-hotkey-toggle-walk", _cfg.GetCVar(CCVars.ToggleWalk), HandleToggleWalk);
AddCheckBox("ui-options-hotkey-auto-up", _cfg.GetCVar(Shared._CorvaxNext.NextVars.NextVars.AutoGetUp), HandleToggleAutoGetUp); // _CorvaxNext: Laying System
InitToggleWalk();

AddHeader("ui-options-header-camera");
Expand All @@ -185,6 +194,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.RotateStoredItem);
AddButton(ContentKeyFunctions.SaveItemLocation);
AddButton(ContentKeyFunctions.OfferItem); // Corvax-Next-Offer
AddButton(ContentKeyFunctions.ToggleStanding); // _CorvaxNext: Laying System
AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack);
AddButton(ContentKeyFunctions.SmartEquipBelt);
Expand Down
155 changes: 155 additions & 0 deletions Content.Client/_CorvaxNext/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using Content.Shared.ActionBlocker;
using Content.Shared._CorvaxNext.NextVars;
using Content.Shared._CorvaxNext.Standing;
using Content.Shared.Buckle;
using Content.Shared.Rotation;
using Content.Shared.Standing;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Configuration;
using Robust.Shared.Player;
using Robust.Shared.Timing;

namespace Content.Client._CorvaxNext.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!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedRotationVisualsSystem _rotationVisuals = default!;

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

SubscribeLocalEvent<LayingDownComponent, MoveEvent>(OnMovementInput);
SubscribeLocalEvent<LayingDownComponent, AfterAutoHandleStateEvent>(OnChangeDraw);
SubscribeLocalEvent<StandingStateComponent, AfterAutoHandleStateEvent>(OnChangeStanding);

_cfg.OnValueChanged(NextVars.AutoGetUp, b => _autoGetUp = b, true);

//SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp);
}

private void OnChangeStanding(Entity<StandingStateComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (_animation.HasRunningAnimation(ent, "rotate"))
return;

if (!TryComp<SpriteComponent>(ent, out var sprite))
{
return;
}

if (ent.Comp.Standing)
{
sprite.Rotation = Angle.Zero;
return;
}

if (sprite.Rotation != Angle.FromDegrees(270) && sprite.Rotation != Angle.FromDegrees(90))
{
sprite.Rotation = Angle.FromDegrees(270);
}
}

private void OnChangeDraw(Entity<LayingDownComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (!TryComp<SpriteComponent>(ent, out var sprite))
return;

if (ent.Comp.DrawDowned)
{
sprite.DrawDepth = (int)Shared.DrawDepth.DrawDepth.SmallMobs;
}
else if (!ent.Comp.DrawDowned && sprite.DrawDepth == (int)Shared.DrawDepth.DrawDepth.SmallMobs)
{
sprite.DrawDepth = (int)Shared.DrawDepth.DrawDepth.Mobs;
}
}

private bool _autoGetUp;

protected override bool GetAutoGetUp(Entity<LayingDownComponent> ent, ICommonSession session)
{
return _autoGetUp;
}

private void OnMovementInput(EntityUid uid, LayingDownComponent component, MoveEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
if (!_standing.IsDown(uid) || _animation.HasRunningAnimation(uid, "rotate") || _buckle.IsBuckled(uid))
return;
if (TerminatingOrDeleted(uid))
return;

if (!TryComp<SpriteComponent>(uid, out var sprite)
|| !TryComp<RotationVisualsComponent>(uid, out var rotationVisuals))
{
return;
}

ProcessVisuals((uid, Transform(uid), sprite, rotationVisuals));
}

private void ProcessVisuals(Entity<TransformComponent, SpriteComponent?, RotationVisualsComponent> entity)
{
var rotation = entity.Comp1.LocalRotation + (_eyeManager.CurrentEye.Rotation - (entity.Comp1.LocalRotation - _transform.GetWorldRotation(entity.Comp1)));

if (rotation.GetDir() is Direction.SouthEast or Direction.East or Direction.NorthEast or Direction.North)
{
_rotationVisuals.SetHorizontalAngle((entity.Owner, entity.Comp3), Angle.FromDegrees(270));
if (entity.Comp2 != null)
entity.Comp2.Rotation = Angle.FromDegrees(270);
return;
}

_rotationVisuals.ResetHorizontalAngle((entity.Owner, entity.Comp3));
if (entity.Comp2 != null)
entity.Comp2.Rotation = entity.Comp3.DefaultRotation;
}

public override void AutoGetUp(Entity<LayingDownComponent> ent)
{
if (!_timing.IsFirstTimePredicted)
return;

if (TerminatingOrDeleted(ent))
return;

var transform = Transform(ent);

if (!TryComp<RotationVisualsComponent>(ent, out var rotationVisuals))
return;

ProcessVisuals((ent.Owner, transform, null, rotationVisuals));
}

/*
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);
}*/
}
16 changes: 13 additions & 3 deletions Content.IntegrationTests/Tests/Buckle/BuckleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Body.Systems;
using Content.Shared.Buckle;
using Content.Shared.ActionBlocker;
using Content.Shared._CorvaxNext.Standing;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Buckle.Components;
Expand Down Expand Up @@ -34,6 +35,7 @@ public sealed partial class BuckleTest
- type: Body
prototype: Human
- type: StandingState
- type: LayingDown # _CorvaxNext
- type: entity
name: {StrapDummyId}
Expand Down Expand Up @@ -297,7 +299,6 @@ await server.WaitAssertion(() =>
{
Assert.That(hand.HeldEntity, Is.Not.Null);
}

var bodySystem = entityManager.System<BodySystem>();
var legs = bodySystem.GetBodyChildrenOfType(human, BodyPartType.Leg, body);

Expand All @@ -310,20 +311,29 @@ await server.WaitAssertion(() =>

await server.WaitRunTicks(10);

// start-_CorvaxNext: Laying System
await server.WaitAssertion(() =>
{
// Still buckled
Assert.That(buckle.Buckled);
// Unbuckled and laydown
Assert.That(buckle.Buckled, Is.True);

// Now with no item in any hand
foreach (var hand in hands.Hands.Values)
{
Assert.That(hand.HeldEntity, Is.Null);
}

var comp = entityManager.GetComponentOrNull<StandingStateComponent>(human);
Assert.That(comp, Is.Not.Null);
Assert.That(comp.CurrentState, Is.EqualTo(StandingState.Standing));
buckleSystem.Unbuckle(human, human);
Assert.That(buckle.Buckled, Is.False);
Assert.That(comp.CurrentState, Is.EqualTo(StandingState.Lying));
Assert.That(comp.Standing, Is.False);
entityManager.System<StandingStateSystem>().Stand(human);
Assert.That(comp.CurrentState, Is.EqualTo(StandingState.Lying));
});
// end-_CorvaxNext: Laying System

await pair.CleanReturnAsync();
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void UpdateRanged(float frameTime)
{
return;
}

_gun.SetTarget(gun, comp.Target); // _CorvaxNext: Laying System
_gun.AttemptShoot(uid, gunUid, gun, targetCordinates);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Robust.Shared.Random;
using Content.Shared._CorvaxNext.Footprints;
using Content.Shared._CorvaxNext.Footprints.Components;
using Content.Shared._CorvaxNext.Standing;

namespace Content.Server._CorvaxNext.Footprints.EntitySystems;

Expand All @@ -24,12 +25,14 @@ public sealed class FootprintsSystem : EntitySystem
private EntityQuery<TransformComponent> _transformQuery;
private EntityQuery<MobThresholdsComponent> _mobThresholdQuery;
private EntityQuery<AppearanceComponent> _appearanceQuery;
private EntityQuery<LayingDownComponent> _layingQuery;

public override void Initialize()
{
_transformQuery = GetEntityQuery<TransformComponent>();
_mobThresholdQuery = GetEntityQuery<MobThresholdsComponent>();
_appearanceQuery = GetEntityQuery<AppearanceComponent>();
_layingQuery = GetEntityQuery<LayingDownComponent>();

SubscribeLocalEvent<FootprintVisualizerComponent, ComponentStartup>(OnStartupComponent);
SubscribeLocalEvent<FootprintVisualizerComponent, MoveEvent>(OnMove);
Expand All @@ -54,7 +57,7 @@ private void OnMove(EntityUid uid, FootprintVisualizerComponent component, ref M
if (!_map.TryFindGridAt(_transform.GetMapCoordinates((uid, transform)), out var gridUid, out _))
return;

var dragging = mobThreshHolds.CurrentThresholdState is MobState.Critical or MobState.Dead;
var dragging = mobThreshHolds.CurrentThresholdState is MobState.Critical or MobState.Dead || _layingQuery.TryComp(uid, out var laying) && laying.DrawDowned;
var distance = (transform.LocalPosition - component.StepPos).Length();
var stepSize = dragging ? component.DragSize : component.StepSize;

Expand Down
77 changes: 77 additions & 0 deletions Content.Server/_CorvaxNext/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Content.Shared._CorvaxNext.NextVars;
using Content.Shared._CorvaxNext.Standing;
using Content.Shared.Rotation;
using Content.Shared.Standing;
using Robust.Shared.Configuration;
using Robust.Shared.Player;

namespace Content.Server._CorvaxNext.Standing;

public sealed class LayingDownSystem : SharedLayingDownSystem // WD EDIT
{
[Dependency] private readonly INetConfigurationManager _cfg = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedRotationVisualsSystem _rotationVisuals = default!;

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

//SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp);
SubscribeLocalEvent<LayingDownComponent, StoodEvent>(OnStoodEvent);
SubscribeLocalEvent<LayingDownComponent, DownedEvent>(OnDownedEvent);
}
private void OnDownedEvent(Entity<LayingDownComponent> ent, ref DownedEvent args)
{
// Raising this event will lower the entity's draw depth to the same as a small mob.
if (CrawlUnderTables)
{
ent.Comp.DrawDowned = true;
Dirty(ent, ent.Comp);
}
}

private void OnStoodEvent(Entity<LayingDownComponent> ent, ref StoodEvent args)
{
if (CrawlUnderTables)
{
ent.Comp.DrawDowned = false;
Dirty(ent, ent.Comp);
}
}

public override void AutoGetUp(Entity<LayingDownComponent> ent)
{
if (!TryComp<EyeComponent>(ent, out var eyeComp) || !TryComp<RotationVisualsComponent>(ent, out var rotationVisualsComp))
return;

var xform = Transform(ent);

var rotation = xform.LocalRotation + (eyeComp.Rotation - (xform.LocalRotation - _transform.GetWorldRotation(xform)));

if (rotation.GetDir() is Direction.SouthEast or Direction.East or Direction.NorthEast or Direction.North)
{
_rotationVisuals.SetHorizontalAngle((ent, rotationVisualsComp), Angle.FromDegrees(270));
return;
}

_rotationVisuals.ResetHorizontalAngle((ent, rotationVisualsComp));
}

protected override bool GetAutoGetUp(Entity<LayingDownComponent> ent, ICommonSession session)
{
return _cfg.GetClientCVar(session.Channel, NextVars.AutoGetUp);
}
/*
private void OnCheckAutoGetUp(CheckAutoGetUpEvent ev, EntitySessionEventArgs args)
{
var uid = GetEntity(ev.User);
if (!TryComp(uid, out LayingDownComponent? layingDown))
return;
layingDown.AutoGetUp = _cfg.GetClientCVar(args.SenderSession.Channel, CCVars.AutoGetUp);
Dirty(uid, layingDown);
}
*/
}
4 changes: 3 additions & 1 deletion Content.Shared/Body/Systems/SharedBodySystem.Body.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Events;
using Content.Shared.Inventory;
using Content.Shared.Rejuvenate;
using Content.Shared.Silicons.Borgs.Components;
using Content.Shared.Standing;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
Expand Down Expand Up @@ -140,7 +142,7 @@ private void OnBodyCanDrag(Entity<BodyComponent> ent, ref CanDragEvent args)
// start-_CorvaxNext: surgery
private void OnStandAttempt(Entity<BodyComponent> ent, ref StandAttemptEvent args)
{
if (ent.Comp.LegEntities.Count == 0)
if (!HasComp<BorgChassisComponent>(ent) && ent.Comp.LegEntities.Count == 0)
args.Cancel();
}
// end-_CorvaxNext: surgery
Expand Down
Loading

0 comments on commit 6bae52d

Please sign in to comment.