Skip to content

Commit

Permalink
[Port] Laying System (#745)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
trest100 and Rxup authored Sep 17, 2024
1 parent ce1d6e3 commit 99f231e
Show file tree
Hide file tree
Showing 24 changed files with 539 additions and 72 deletions.
124 changes: 124 additions & 0 deletions Content.Client/Backmen/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using Content.Shared.Backmen.CCVar;
using Content.Shared.Backmen.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.Backmen.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!;

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

SubscribeLocalEvent<LayingDownComponent, MoveEvent>(OnMovementInput);

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

//SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp);
}

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))
return;

if (_buckle.IsBuckled(uid))
return;

if (_animation.HasRunningAnimation(uid, "rotate"))
return;

if(TerminatingOrDeleted(uid))
return;

var transform = Transform(uid);

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

ProcessVisuals((uid, transform, 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)
{
entity.Comp3.HorizontalRotation = Angle.FromDegrees(270);
if(entity.Comp2 != null)
entity.Comp2.Rotation = Angle.FromDegrees(270);
return;
}

entity.Comp3.HorizontalRotation = Angle.FromDegrees(90);
if(entity.Comp2 != null)
entity.Comp2.Rotation = Angle.FromDegrees(90);
}

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);
}*/
}
3 changes: 2 additions & 1 deletion Content.Client/Buckle/BuckleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref Ap
!buckled ||
args.Sprite == null)
{
_rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation);
// backmen: Laying System
//_rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation);
return;
}

Expand Down
11 changes: 2 additions & 9 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.Arcade1);
human.AddFunction(ContentKeyFunctions.Arcade2);
human.AddFunction(ContentKeyFunctions.Arcade3);
human.AddFunction(ContentKeyFunctions.ToggleStanding); // Ataraxia
human.AddFunction(ContentKeyFunctions.LookUp); // WD EDIT
human.AddFunction(CMKeyFunctions.CMUniqueAction); // backmen

// actions should be common (for ghosts, mobs, etc)
common.AddFunction(ContentKeyFunctions.OpenActionsMenu);
Expand Down Expand Up @@ -125,15 +127,6 @@ public static void SetupContexts(IInputContextContainer contexts)
common.AddFunction(ContentKeyFunctions.OpenDecalSpawnWindow);
common.AddFunction(ContentKeyFunctions.OpenAdminMenu);
common.AddFunction(ContentKeyFunctions.OpenGuidebook);


CMFunctions(contexts);
}

private static void CMFunctions(IInputContextContainer contexts)
{
var human = contexts.GetContext("human");
human.AddFunction(CMKeyFunctions.CMUniqueAction);
}
}
}
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 @@ -159,6 +159,14 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
KeybindsContainer.AddChild(newCheckBox);
}

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

AddHeader("ui-options-header-rmc");
AddButton(CMKeyFunctions.CMUniqueAction);

Expand All @@ -172,6 +180,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.Backmen.CCVar.CCVars.AutoGetUp), HandleToggleAutoGetUp); // backmen: Laying System
InitToggleWalk();

AddHeader("ui-options-header-camera");
Expand All @@ -195,6 +204,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.MoveStoredItem);
AddButton(ContentKeyFunctions.RotateStoredItem);
AddButton(ContentKeyFunctions.SaveItemLocation);
AddButton(ContentKeyFunctions.ToggleStanding); // backmen: Laying System
AddButton(ContentKeyFunctions.LookUp); // WD EDIT
AddCheckBox("ui-options-function-hold-look-up", _cfg.GetCVar(WhiteCVars.HoldLookUp), HandleHoldLookUp); // WD EDIT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public sealed partial class GhostGui : UIWidget
public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed;

public event Action? ReturnToRoundPressed;


public GhostGui()
{
RobustXamlLoader.Load(this);
Expand All @@ -26,6 +29,7 @@ public GhostGui()
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
ReturnToRound.OnPressed += _ => ReturnToRoundPressed?.Invoke();
}

public void Hide()
Expand Down
20 changes: 16 additions & 4 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.Backmen.Standing;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Buckle.Components;
Expand Down Expand Up @@ -297,7 +298,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 +310,32 @@ await server.WaitAssertion(() =>

await server.WaitRunTicks(10);

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

var comp = entityManager.GetComponentOrNull<StandingStateComponent>(human);
Assert.That(comp, Is.Not.Null);

Assert.That(comp.CurrentState, Is.EqualTo(StandingState.Lying));

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

buckleSystem.Unbuckle(human, human);
entityManager.System<StandingStateSystem>().Stand(human);

Assert.That(comp.CurrentState, Is.EqualTo(StandingState.Standing));
//buckleSystem.Unbuckle(human, human);
Assert.That(buckle.Buckled, Is.False);


});
// end-backmen: Laying System

await pair.CleanReturnAsync();
}
Expand Down
27 changes: 11 additions & 16 deletions Content.Server/Backmen/Ghost/GhostReJoinSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private CompletionResult ReturnToRoundCompletion(IConsoleShell shell, string[] a
[AnyCommand]
private void ReturnToRoundCommand(IConsoleShell shell, string argstr, string[] args)
{
if (shell.Player?.AttachedEntity is not { } entity || !TryComp<GhostComponent>(entity, out var ghostComponent))
if (shell.Player?.AttachedEntity is not { } ghost || !TryComp<GhostComponent>(ghost, out var ghostComponent))
{
shell.WriteError("This command can only be ran by a player with an attached entity.");
return;
Expand All @@ -282,6 +282,12 @@ private void ReturnToRoundCommand(IConsoleShell shell, string argstr, string[] a
deathTime = ghostComponent.TimeOfDeath;
}

if (deathTime != ghostComponent.TimeOfDeath)
{
_ghostSystem.SetTimeOfDeath(ghost, deathTime, ghostComponent);
Dirty(ghost, ghostComponent);
}

var timeOffset = _gameTiming.CurTime - deathTime;

if (timeOffset >= _ghostRespawnTime)
Expand All @@ -291,21 +297,10 @@ private void ReturnToRoundCommand(IConsoleShell shell, string argstr, string[] a
_euiManager.CloseEui(_eUi[userId]);
_eUi.Remove(userId);
}
_eUi.Add(userId, new GhostReJoinEui(this, (entity, ghostComponent)));
_eUi.Add(userId, new GhostReJoinEui(this, (ghost, ghostComponent)));
_euiManager.OpenEui(_eUi[userId], shell.Player);
_eUi[userId].StateDirty();
/*
_deathTime.Remove(userId);

_adminLogger.Add(LogType.Mind,
LogImpact.Extreme,
$"{shell.Player.Channel.UserName} вернулся в лобби посредством гост респавна.");
SendChatMsg(shell.Player,
Loc.GetString("ghost-respawn-window-rules-footer")
);
_gameTicker.Respawn(shell.Player);
*/
return;
}

Expand Down Expand Up @@ -337,7 +332,7 @@ private void SendChatMsg(ICommonSession sess, string message)
Color.Red);
}

public void AttachGhost(EntityUid? ghost, ICommonSession? mindSession)
public void AttachGhost(EntityUid ghost, ICommonSession? mindSession)
{
if(mindSession == null)
return;
Expand All @@ -349,8 +344,8 @@ public void AttachGhost(EntityUid? ghost, ICommonSession? mindSession)

if (TryComp<GhostComponent>(ghost, out var ghostComponent))
{
_ghostSystem.SetTimeOfDeath(ghost.Value, _deathTime[mindSession.UserId], ghostComponent);
Dirty(ghost.Value, ghostComponent);
_ghostSystem.SetTimeOfDeath(ghost, _deathTime[mindSession.UserId], ghostComponent);
Dirty(ghost, ghostComponent);
}
}
}
55 changes: 55 additions & 0 deletions Content.Server/Backmen/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Content.Shared.Backmen.CCVar;
using Content.Shared.Backmen.Standing;
using Content.Shared.Rotation;
using Robust.Shared.Configuration;
using Robust.Shared.Player;

namespace Content.Server.Backmen.Standing;

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

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

//SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp);
}

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)
{
rotationVisualsComp.HorizontalRotation = Angle.FromDegrees(270);
return;
}

rotationVisualsComp.HorizontalRotation = Angle.FromDegrees(90);
}

protected override bool GetAutoGetUp(Entity<LayingDownComponent> ent, ICommonSession session)
{
return _cfg.GetClientCVar(session.Channel, CCVars.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);
}
*/
}
2 changes: 1 addition & 1 deletion Content.Server/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public bool OnGhostAttempt(EntityUid mindId, bool canReturnGlobal, bool viaComma
if (ghost == null)
return false;

EntityManager.SystemOrNull<Backmen.Ghost.GhostReJoinSystem>()?.AttachGhost(ghost, mind.Session); // backmen: ReturnToRound
EntityManager.SystemOrNull<Backmen.Ghost.GhostReJoinSystem>()?.AttachGhost(ghost.Value, mind.Session); // backmen: ReturnToRound

return true;
}
Expand Down
Loading

0 comments on commit 99f231e

Please sign in to comment.