Фикс лежания (#430)

* Fix

* commit

* clear

* commit

* / WD EDIT
This commit is contained in:
Spatison
2024-07-10 16:26:50 +03:00
committed by GitHub
parent 0b374ebd7c
commit 8deece0091
12 changed files with 145 additions and 26 deletions

View File

@@ -2,6 +2,7 @@ using System.Numerics;
using Content.Client.Stylesheets; using Content.Client.Stylesheets;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.Input; using Content.Shared.Input;
using Content.Shared._White;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Input; using Robust.Client.Input;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
@@ -97,6 +98,12 @@ namespace Content.Client.Options.UI.Tabs
_deferCommands.Add(_inputManager.SaveToUserData); _deferCommands.Add(_inputManager.SaveToUserData);
} }
private void HandleToggleAutoGetUp(BaseButton.ButtonToggledEventArgs args) // WD EDIT
{
_cfg.SetCVar(WhiteCVars.AutoGetUp, args.Pressed);
_cfg.SaveToFile();
}
private void HandleStaticStorageUI(BaseButton.ButtonToggledEventArgs args) private void HandleStaticStorageUI(BaseButton.ButtonToggledEventArgs args)
{ {
_cfg.SetCVar(CCVars.StaticStorageUI, args.Pressed); _cfg.SetCVar(CCVars.StaticStorageUI, args.Pressed);
@@ -185,6 +192,7 @@ namespace Content.Client.Options.UI.Tabs
AddButton(ContentKeyFunctions.RotateStoredItem); AddButton(ContentKeyFunctions.RotateStoredItem);
AddButton(ContentKeyFunctions.SaveItemLocation); AddButton(ContentKeyFunctions.SaveItemLocation);
AddButton(ContentKeyFunctions.LieDown); // WD EDIT AddButton(ContentKeyFunctions.LieDown); // WD EDIT
AddCheckBox("ui-options-function-auto-get-up", _cfg.GetCVar(WhiteCVars.AutoGetUp), HandleToggleAutoGetUp); // WD EDIT
AddHeader("ui-options-header-interaction-adv"); AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack); AddButton(ContentKeyFunctions.SmartEquipBackpack);

View File

@@ -0,0 +1,41 @@
using Content.Shared.Rotation;
using Robust.Client.GameObjects;
namespace Content.Client._White.Rotation;
public sealed class RotationVisualizerSystem : EntitySystem
{
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
SubscribeLocalEvent<RotationVisualsComponent, MoveEvent>(OnMove);
}
private void OnMove(EntityUid uid, RotationVisualsComponent component, ref MoveEvent args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite) ||
!TryComp<AppearanceComponent>(uid, out var appearance))
return;
_appearance.TryGetData<RotationState>(uid, RotationVisuals.RotationState, out var state, appearance);
var rotation = _transform.GetWorldRotation(uid);
if (rotation.GetDir() is Direction.East or Direction.North or Direction.NorthEast or Direction.SouthEast)
{
if (state == RotationState.Horizontal &&
sprite.Rotation == component.DefaultRotation)
{
sprite.Rotation = Angle.FromDegrees(270);
}
return;
}
if (state == RotationState.Horizontal &&
sprite.Rotation == Angle.FromDegrees(270))
{
sprite.Rotation = component.DefaultRotation;
}
}
}

View File

@@ -10,8 +10,6 @@ using Content.Shared.Interaction;
using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Events; using Content.Shared.Movement.Events;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Standing;
using Content.Shared.Standing.Systems;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using Content.Shared.Throwing; using Content.Shared.Throwing;
@@ -35,8 +33,6 @@ public abstract partial class SharedBuckleSystem
SubscribeLocalEvent<BuckleComponent, InsertIntoEntityStorageAttemptEvent>(OnBuckleInsertIntoEntityStorageAttempt); SubscribeLocalEvent<BuckleComponent, InsertIntoEntityStorageAttemptEvent>(OnBuckleInsertIntoEntityStorageAttempt);
SubscribeLocalEvent<BuckleComponent, PreventCollideEvent>(OnBucklePreventCollide); SubscribeLocalEvent<BuckleComponent, PreventCollideEvent>(OnBucklePreventCollide);
SubscribeLocalEvent<BuckleComponent, DownAttemptEvent>(OnBuckleDownAttempt);
SubscribeLocalEvent<BuckleComponent, StandAttemptEvent>(OnBuckleStandAttempt);
SubscribeLocalEvent<BuckleComponent, ThrowPushbackAttemptEvent>(OnBuckleThrowPushbackAttempt); SubscribeLocalEvent<BuckleComponent, ThrowPushbackAttemptEvent>(OnBuckleThrowPushbackAttempt);
SubscribeLocalEvent<BuckleComponent, UpdateCanMoveEvent>(OnBuckleUpdateCanMove); SubscribeLocalEvent<BuckleComponent, UpdateCanMoveEvent>(OnBuckleUpdateCanMove);
} }
@@ -114,18 +110,6 @@ public abstract partial class SharedBuckleSystem
args.Cancelled = true; args.Cancelled = true;
} }
private void OnBuckleDownAttempt(EntityUid uid, BuckleComponent component, DownAttemptEvent args)
{
if (component.Buckled)
args.Cancel();
}
private void OnBuckleStandAttempt(EntityUid uid, BuckleComponent component, StandAttemptEvent args)
{
if (component.Buckled)
args.Cancel();
}
private void OnBuckleThrowPushbackAttempt(EntityUid uid, BuckleComponent component, ThrowPushbackAttemptEvent args) private void OnBuckleThrowPushbackAttempt(EntityUid uid, BuckleComponent component, ThrowPushbackAttemptEvent args)
{ {
if (component.Buckled) if (component.Buckled)

View File

@@ -1,11 +1,12 @@
using Content.Shared.Standing.Systems; using Content.Shared.Standing.Systems;
using Content.Shared._White.Standing;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Shared.Standing namespace Content.Shared.Standing
{ {
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedStandingStateSystem))] [RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedStandingStateSystem), typeof(StandingStateSystem))]
public sealed partial class StandingStateComponent : Component public sealed partial class StandingStateComponent : Component
{ {
[ViewVariables(VVAccess.ReadWrite), DataField] [ViewVariables(VVAccess.ReadWrite), DataField]
@@ -24,6 +25,10 @@ namespace Content.Shared.Standing
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] [DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public bool CanLieDown = false; public bool CanLieDown = false;
// WD EDIT
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public bool AutoGetUp = false;
/// <summary> /// <summary>
/// List of fixtures that had their collision mask changed when the entity was downed. /// List of fixtures that had their collision mask changed when the entity was downed.
/// Required for re-adding the collision mask. /// Required for re-adding the collision mask.
@@ -35,7 +40,13 @@ namespace Content.Shared.Standing
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class ChangeStandingStateEvent : EntityEventArgs public sealed class ChangeStandingStateEvent : CancellableEntityEventArgs
{
}
// WD EDIT
[Serializable, NetSerializable]
public sealed class CheckAutoGetUpEvent : CancellableEntityEventArgs
{ {
} }

View File

@@ -7,6 +7,9 @@ using Content.Shared.Physics;
using Content.Shared.Rotation; using Content.Shared.Rotation;
using Content.Shared.Slippery; using Content.Shared.Slippery;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using Content.Shared._White.Wizard.Timestop;
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Robust.Shared.Audio.Systems; using Robust.Shared.Audio.Systems;
using Robust.Shared.Input.Binding; using Robust.Shared.Input.Binding;
using Robust.Shared.Physics; using Robust.Shared.Physics;
@@ -14,6 +17,7 @@ using Robust.Shared.Physics.Systems;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Shared.Standing.Systems; namespace Content.Shared.Standing.Systems;
public abstract partial class SharedStandingStateSystem : EntitySystem public abstract partial class SharedStandingStateSystem : EntitySystem
@@ -25,6 +29,9 @@ public abstract partial class SharedStandingStateSystem : EntitySystem
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!; // WD EDIT [Dependency] private readonly MovementSpeedModifierSystem _movement = default!; // WD EDIT
[Dependency] private readonly SharedStunSystem _stun = default!; // WD EDIT [Dependency] private readonly SharedStunSystem _stun = default!; // WD EDIT
[Dependency] private readonly MobStateSystem _mobState = default!; // WD EDIT [Dependency] private readonly MobStateSystem _mobState = default!; // WD EDIT
[Dependency] private readonly SharedBuckleSystem _buckle = default!; // WD EDIT
[Dependency] private readonly SharedTransformSystem _transform = default!; // WD EDIT
[Dependency] private readonly SharedRotationVisualsSystem _rotation = default!; // WD EDIT
// If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited. // If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited.
private const int StandingCollisionLayer = (int)CollisionGroup.MidImpassable; private const int StandingCollisionLayer = (int)CollisionGroup.MidImpassable;
@@ -53,6 +60,9 @@ public abstract partial class SharedStandingStateSystem : EntitySystem
private void OnChangeState(ChangeStandingStateEvent ev, EntitySessionEventArgs args) private void OnChangeState(ChangeStandingStateEvent ev, EntitySessionEventArgs args)
{ {
if (TryComp<FrozenComponent>(args.SenderSession.AttachedEntity, out _)) // WD EDIT
return;
if (!args.SenderSession.AttachedEntity.HasValue) if (!args.SenderSession.AttachedEntity.HasValue)
{ {
return; return;
@@ -60,6 +70,11 @@ public abstract partial class SharedStandingStateSystem : EntitySystem
var uid = args.SenderSession.AttachedEntity.Value; var uid = args.SenderSession.AttachedEntity.Value;
if (!TryComp(uid, out StandingStateComponent? standing)) // WD EDIT
return;
RaiseNetworkEvent(new CheckAutoGetUpEvent());
if (_stun.IsParalyzed(uid)) if (_stun.IsParalyzed(uid))
{ {
return; return;
@@ -70,18 +85,23 @@ public abstract partial class SharedStandingStateSystem : EntitySystem
return; return;
} }
if (IsDown(uid)) if (IsDown(uid, standing))
{ {
TryStandUp(uid); TryStandUp(uid, standing);
} }
else else
{ {
TryLieDown(uid); TryLieDown(uid, standing);
} }
} }
private void OnStandingUpDoAfter(EntityUid uid, StandingStateComponent component, StandingUpDoAfterEvent args) private void OnStandingUpDoAfter(EntityUid uid, StandingStateComponent component, StandingUpDoAfterEvent args)
{ {
if (args.Handled) // WD EDIT
{
component.CurrentState = StandingState.Lying;
return;
}
Stand(uid); Stand(uid);
} }
@@ -192,6 +212,9 @@ public abstract partial class SharedStandingStateSystem : EntitySystem
// Optional component. // Optional component.
Resolve(uid, ref appearance, ref hands, false); Resolve(uid, ref appearance, ref hands, false);
if (TryComp(uid, out BuckleComponent? buckle) && buckle.Buckled && !_buckle.TryUnbuckle(uid, uid, buckleComp: buckle)) // WD EDIT
return false;
// This is just to avoid most callers doing this manually saving boilerplate // This is just to avoid most callers doing this manually saving boilerplate
// 99% of the time you'll want to drop items but in some scenarios (e.g. buckling) you don't want to. // 99% of the time you'll want to drop items but in some scenarios (e.g. buckling) you don't want to.
// We do this BEFORE downing because something like buckle may be blocking downing but we want to drop hand items anyway // We do this BEFORE downing because something like buckle may be blocking downing but we want to drop hand items anyway
@@ -212,6 +235,14 @@ public abstract partial class SharedStandingStateSystem : EntitySystem
standingState.CurrentState = StandingState.Lying; standingState.CurrentState = StandingState.Lying;
Dirty(uid, standingState); Dirty(uid, standingState);
var rotation = _transform.GetWorldRotation(uid);
if (rotation.GetDir() is Direction.East or Direction.North or Direction.NorthEast or Direction.SouthEast)
_rotation.SetHorizontalAngle(uid, Angle.FromDegrees(270));
else
_rotation.ResetHorizontalAngle(uid);
RaiseLocalEvent(uid, new DownedEvent()); RaiseLocalEvent(uid, new DownedEvent());
// Seemed like the best place to put it // Seemed like the best place to put it

View File

@@ -104,6 +104,7 @@ public abstract class SharedStunSystem : EntitySystem
private void OnKnockInit(EntityUid uid, KnockedDownComponent component, ComponentInit args) private void OnKnockInit(EntityUid uid, KnockedDownComponent component, ComponentInit args)
{ {
RaiseNetworkEvent(new CheckAutoGetUpEvent()); // WD EDIT
_standingState.Down(uid); _standingState.Down(uid);
} }
@@ -111,7 +112,7 @@ public abstract class SharedStunSystem : EntitySystem
{ {
// WD EDIT START // WD EDIT START
// Don't stand up if we can lie down via keybind // Don't stand up if we can lie down via keybind
if (!TryComp(uid, out StandingStateComponent? standing) || standing.CanLieDown) if (!TryComp(uid, out StandingStateComponent? standing) || !(!standing.CanLieDown || standing.AutoGetUp)) // WD EDIT
return; return;
_standingState.Stand(uid, standing); _standingState.Stand(uid, standing);

View File

@@ -0,0 +1,29 @@
using Content.Shared.Standing;
using Robust.Shared.Configuration;
namespace Content.Shared._White.Standing;
public sealed class StandingStateSystem : EntitySystem
{
[Dependency] private readonly INetConfigurationManager _cfg = default!;
public override void Initialize()
{
SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp);
}
private void OnCheckAutoGetUp(CheckAutoGetUpEvent ev, EntitySessionEventArgs args)
{
if (!args.SenderSession.AttachedEntity.HasValue)
return;
var uid = args.SenderSession.AttachedEntity.Value;
if (!TryComp(uid, out StandingStateComponent? standing))
return;
standing.AutoGetUp = _cfg.GetClientCVar(args.SenderSession.Channel, WhiteCVars.AutoGetUp);
Dirty(args.SenderSession.AttachedEntity.Value, standing);
}
}

View File

@@ -307,6 +307,12 @@ public sealed class WhiteCVars
public static readonly CVarDef<bool> LogChatActions = public static readonly CVarDef<bool> LogChatActions =
CVarDef.Create("white.log_to_chat", true, CVar.CLIENT | CVar.ARCHIVE | CVar.REPLICATED); CVarDef.Create("white.log_to_chat", true, CVar.CLIENT | CVar.ARCHIVE | CVar.REPLICATED);
/// <summary>
/// Determines whether automatic get up is required
/// </summary>
public static readonly CVarDef<bool> AutoGetUp =
CVarDef.Create("white.auto_get_up", true, CVar.CLIENT | CVar.ARCHIVE | CVar.REPLICATED);
/* /*
* Aspects * Aspects
*/ */

View File

@@ -36,6 +36,7 @@ public sealed class FreezeContactsSystem : EntitySystem
SubscribeLocalEvent<FrozenComponent, ComponentRemove>(OnRemove); SubscribeLocalEvent<FrozenComponent, ComponentRemove>(OnRemove);
SubscribeLocalEvent<FrozenComponent, PreventCollideEvent>(OnPreventCollide); SubscribeLocalEvent<FrozenComponent, PreventCollideEvent>(OnPreventCollide);
SubscribeLocalEvent<FrozenComponent, EntGotInsertedIntoContainerMessage>(OnGetInserted); SubscribeLocalEvent<FrozenComponent, EntGotInsertedIntoContainerMessage>(OnGetInserted);
SubscribeLocalEvent<FrozenComponent, StandingUpDoAfterEvent>(OnStandingUpDoAfter);
SubscribeLocalEvent<FrozenComponent, StandAttemptEvent>(OnAttempt); SubscribeLocalEvent<FrozenComponent, StandAttemptEvent>(OnAttempt);
SubscribeLocalEvent<FrozenComponent, DownAttemptEvent>(OnAttempt); SubscribeLocalEvent<FrozenComponent, DownAttemptEvent>(OnAttempt);
@@ -61,6 +62,11 @@ public sealed class FreezeContactsSystem : EntitySystem
args.Cancel(); args.Cancel();
} }
private void OnStandingUpDoAfter(EntityUid uid, FrozenComponent component, StandingUpDoAfterEvent args)
{
args.Handled = true;
}
private void OnAttempt(EntityUid uid, FrozenComponent component, CancellableEntityEventArgs args) private void OnAttempt(EntityUid uid, FrozenComponent component, CancellableEntityEventArgs args)
{ {
args.Cancel(); args.Cancel();

View File

@@ -137,6 +137,7 @@ ui-options-function-swap-hands = Swap hands
ui-options-function-move-stored-item = Move stored item ui-options-function-move-stored-item = Move stored item
ui-options-function-rotate-stored-item = Rotate stored item ui-options-function-rotate-stored-item = Rotate stored item
ui-options-function-lie-down = Lie down/Get up ui-options-function-lie-down = Lie down/Get up
ui-options-function-auto-get-up = Automatically get up when falling
ui-options-function-save-item-location = Save item location ui-options-function-save-item-location = Save item location
ui-options-static-storage-ui = Lock storage window to hotbar ui-options-static-storage-ui = Lock storage window to hotbar

View File

@@ -139,6 +139,7 @@ ui-options-function-swap-hands = Поменять руки
ui-options-function-move-stored-item = Переместить хранящийся объект ui-options-function-move-stored-item = Переместить хранящийся объект
ui-options-function-rotate-stored-item = Повернуть хранящийся объект ui-options-function-rotate-stored-item = Повернуть хранящийся объект
ui-options-function-lie-down = Лечь/встать ui-options-function-lie-down = Лечь/встать
ui-options-function-auto-get-up = Автоматически вставать при падении
ui-options-function-save-item-location = Сохранить позицию предмета ui-options-function-save-item-location = Сохранить позицию предмета
ui-options-static-storage-ui = Закрепить интерфейс хранилища на хотбаре ui-options-static-storage-ui = Закрепить интерфейс хранилища на хотбаре