Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Ляжания вторая попытка - ДОДЕЛАННОЕ, РАБОЧЕЕ ГАВНО (#325)
Browse files Browse the repository at this point in the history
* Не рабочее гавно в процессе

* Не фикс говна

* Update Content.Shared/Standing/StandingStateComponent.cs

Co-authored-by: Ed <[email protected]>

* Update Content.Shared/LieDown/LyingDownComponent.cs

Co-authored-by: Ed <[email protected]>

* Update Content.Shared/LieDown/SharedLieDownSystem.cs

Co-authored-by: Ed <[email protected]>

* Revert "Update Content.Shared/LieDown/SharedLieDownSystem.cs"

This reverts commit a133d9e.

* fix

* Эта хуйня работает

* Final fix

---------

Co-authored-by: Ivan Rubinov <[email protected]>
Co-authored-by: Ed <[email protected]>
  • Loading branch information
3 people authored Jun 23, 2024
1 parent d6d587f commit 1ac73bc
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 21 deletions.
1 change: 1 addition & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.Arcade1);
human.AddFunction(ContentKeyFunctions.Arcade2);
human.AddFunction(ContentKeyFunctions.Arcade3);
human.AddFunction(ContentKeyFunctions.LieDownStandUp);

// actions should be common (for ghosts, mobs, etc)
common.AddFunction(ContentKeyFunctions.OpenActionsMenu);
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 @@ -181,6 +181,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.Drop);
AddButton(ContentKeyFunctions.ExamineEntity);
AddButton(ContentKeyFunctions.SwapHands);
AddButton(ContentKeyFunctions.LieDownStandUp);
AddButton(ContentKeyFunctions.MoveStoredItem);
AddButton(ContentKeyFunctions.RotateStoredItem);
AddButton(ContentKeyFunctions.SaveItemLocation);
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction ZoomOut = "ZoomOut";
public static readonly BoundKeyFunction ZoomIn = "ZoomIn";
public static readonly BoundKeyFunction ResetZoom = "ResetZoom";
public static readonly BoundKeyFunction LieDownStandUp = "LieDownStandUp";

public static readonly BoundKeyFunction ArcadeUp = "ArcadeUp";
public static readonly BoundKeyFunction ArcadeDown = "ArcadeDown";
Expand Down
25 changes: 25 additions & 0 deletions Content.Shared/LieDown/LyingDownComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Content.Shared.Actions;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared.LieDown;

/// <summary>
/// Makes the target to lie down.
/// </summary>
[Access(typeof(SharedLieDownSystem))]
[RegisterComponent, NetworkedComponent()]
public sealed partial class LyingDownComponent : Component
{
/// <summary>
/// The action to lie down or stand up.
/// </summary>
[DataField]
public EntProtoId? MakeToStandUpAction = "action-name-make-standup";
}

[Serializable, NetSerializable]
public sealed class ChangeStandingStateEvent : EntityEventArgs {}
171 changes: 171 additions & 0 deletions Content.Shared/LieDown/SharedLieDownSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
using Content.Shared.Actions;
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Input;
using Content.Shared.Interaction;
using Content.Shared.Movement.Systems;
using Content.Shared.Standing;
using Content.Shared.Verbs;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;

namespace Content.Shared.LieDown;

public class SharedLieDownSystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;

public override void Initialize()
{
SubscribeLocalEvent<LyingDownComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<LyingDownComponent, GetVerbsEvent<AlternativeVerb>>(AddStandUpVerb);
SubscribeLocalEvent<LyingDownComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<LyingDownComponent, RefreshMovementSpeedModifiersEvent>(OnRefresh);

SubscribeLocalEvent<LyingDownComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<LyingDownComponent, ComponentShutdown>(OnComponentShutdown);

// Bind keybinds to lie down action
SubscribeNetworkEvent<ChangeStandingStateEvent>(OnChangeAction);
CommandBinds.Builder
.Bind(ContentKeyFunctions.LieDownStandUp, InputCmdHandler.FromDelegate(ChangeLyingState))
.Register<SharedLieDownSystem>();
}

private void OnComponentShutdown(EntityUid uid, LyingDownComponent component, ComponentShutdown args)
{
SwitchActions(uid);
_movement.RefreshMovementSpeedModifiers(uid);
}

private void OnComponentStartup(EntityUid uid, LyingDownComponent component, ComponentStartup args)
{
SwitchActions(uid);
_movement.RefreshMovementSpeedModifiers(uid);
}

/// <summary>
/// Send an update event when player pressed keybind.
/// </summary>
private void ChangeLyingState(ICommonSession? session)
{
RaiseNetworkEvent(new ChangeStandingStateEvent());
}

/// <summary>
/// Process player event, that pressed keybind.
/// </summary>
private void OnChangeAction(ChangeStandingStateEvent msg, EntitySessionEventArgs args)
{
if (!args.SenderSession.AttachedEntity.HasValue)
return;

var uid = args.SenderSession.AttachedEntity.Value;
if (_standing.IsDown(uid))
{
TryStandUp(uid);
}
else
{
TryLieDown(uid);
}
}

/// <summary>
/// Update movement speed according to the lying state.
/// </summary>
private void OnRefresh(EntityUid uid, LyingDownComponent component, RefreshMovementSpeedModifiersEvent args)
{
if (_standing.IsDown(uid))
{
args.ModifySpeed(0f, 0f);
}
else
{
args.ModifySpeed(1f, 1f);
}
}

/// <summary>
/// Change available to player actions.
/// </summary>
private void SwitchActions(EntityUid uid)
{
var standingComponent = Comp<StandingStateComponent>(uid);
if (_standing.IsDown(uid))
{
_actions.AddAction(uid, ref standingComponent.StandUpActionEntity, standingComponent.StandUpAction);
_actions.RemoveAction(uid, standingComponent.LieDownActionEntity);
}
else
{
_actions.AddAction(uid, ref standingComponent.LieDownActionEntity, standingComponent.LieDownAction);
_actions.RemoveAction(uid, standingComponent.StandUpActionEntity);
}
}

/// <summary>
/// When interacting with a lying down person, add ability to make him stand up.
/// </summary>
private void OnInteractHand(EntityUid uid, LyingDownComponent component, InteractHandEvent args)
{
TryStandUp(args.Target);
}

/// <summary>
/// Add a verb to player menu to make him stand up.
/// </summary>
private void AddStandUpVerb(EntityUid uid, LyingDownComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;

if (args.Target == args.User)
return;

if (!_standing.IsDown(uid))
return;

AlternativeVerb verb = new()
{
Act = () =>
{
TryStandUp(uid);
},
Text = Loc.GetString(component.MakeToStandUpAction!),
Priority = 2
};

args.Verbs.Add(verb);
}

/// <summary>
/// If somebody examined a lying down person, add description.
/// </summary>
private void OnExamined(EntityUid uid, LyingDownComponent component, ExaminedEvent args)
{
if (args.IsInDetailsRange && _standing.IsDown(uid))
{
args.PushMarkup(Loc.GetString("lying-down-examined", ("target", Identity.Entity(uid, EntityManager))));
}
}

public void TryStandUp(EntityUid uid)
{
if (!_standing.IsDown(uid) || !_standing.Stand(uid))
return;

RemCompDeferred<LyingDownComponent>(uid);
}

public void TryLieDown(EntityUid uid)
{
if (_standing.IsDown(uid) || !_standing.Down(uid, false, false))
return;

EnsureComp<LyingDownComponent>(uid);
}
}

59 changes: 40 additions & 19 deletions Content.Shared/Standing/StandingStateComponent.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Content.Shared.Actions;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared.Standing
namespace Content.Shared.Standing;


[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(StandingStateSystem))]
public sealed partial class StandingStateComponent : Component
{
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(StandingStateSystem))]
public sealed partial class StandingStateComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public SoundSpecifier DownSound { get; private set; } = new SoundCollectionSpecifier("BodyFall");

[DataField, AutoNetworkedField]
public bool Standing { get; set; } = true;

/// <summary>
/// List of fixtures that had their collision mask changed when the entity was downed.
/// Required for re-adding the collision mask.
/// </summary>
[DataField, AutoNetworkedField]
public List<string> ChangedFixtures = new();
}
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public SoundSpecifier DownSound { get; private set; } = new SoundCollectionSpecifier("BodyFall");

[DataField, AutoNetworkedField]
public bool Standing = true;

/// <summary>
/// List of fixtures that had their collision mask changed when the entity was downed.
/// Required for re-adding the collision mask.
/// </summary>
[DataField, AutoNetworkedField]
public List<string> ChangedFixtures = new();

[DataField]
public EntProtoId LieDownAction = "ActionLieDown";

[DataField, AutoNetworkedField]
public EntityUid? LieDownActionEntity;

[DataField("stand-up-action")]
public EntProtoId StandUpAction = "ActionStandUp";

[DataField, AutoNetworkedField]
public EntityUid? StandUpActionEntity;
}

public sealed partial class LieDownActionEvent : InstantActionEvent {}
public sealed partial class StandUpActionEvent : InstantActionEvent {}

46 changes: 45 additions & 1 deletion Content.Shared/Standing/StandingStateSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Content.Shared.Actions;
using Content.Shared.Hands.Components;
using Content.Shared.LieDown;
using Content.Shared.Movement.Systems;
using Content.Shared.Physics;
using Content.Shared.Rotation;
using Robust.Shared.Audio;
Expand All @@ -13,10 +16,20 @@ public sealed class StandingStateSystem : EntitySystem
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly SharedLieDownSystem _lieDown = default!;
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;

// 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;

public override void Initialize()
{
SubscribeLocalEvent<StandingStateComponent, ComponentStartup>(OnComponentInit);
SubscribeLocalEvent<StandingStateComponent, LieDownActionEvent>(OnLieDownAction);
SubscribeLocalEvent<StandingStateComponent, StandUpActionEvent>(OnStandUpAction);
SubscribeLocalEvent<StandingStateComponent, MapInitEvent>(OnMapInit);
}
public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null)
{
if (!Resolve(uid, ref standingState, false))
Expand All @@ -25,6 +38,37 @@ public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null)
return !standingState.Standing;
}

private void OnMapInit(EntityUid uid, StandingStateComponent component, MapInitEvent args)
{
_actionContainer.EnsureAction(uid, ref component.LieDownActionEntity, component.LieDownAction);
_actionContainer.EnsureAction(uid, ref component.StandUpActionEntity, component.StandUpAction);
Dirty(uid, component);
}

/// <summary>
/// When component is added to player, add an action.
/// </summary>
private void OnComponentInit(EntityUid uid, StandingStateComponent component, ComponentStartup args)
{
_actions.AddAction(uid, ref component.LieDownActionEntity, component.LieDownAction);
}

/// <summary>
/// Event that being risen on lie down attempt.
/// </summary>
private void OnLieDownAction(EntityUid uid, StandingStateComponent component, LieDownActionEvent args)
{
_lieDown.TryLieDown(uid);
}

/// <summary>
/// Event that being risen on stand up attempt.
/// </summary>
private void OnStandUpAction(EntityUid uid, StandingStateComponent component, StandUpActionEvent args)
{
_lieDown.TryStandUp(uid);
}

public bool Down(EntityUid uid, bool playSound = true, bool dropHeldItems = true,
StandingStateComponent? standingState = null,
AppearanceComponent? appearance = null,
Expand Down
5 changes: 5 additions & 0 deletions Resources/Locale/en-US/actions/actions/lie-down.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
action-name-liedown = Lie down
action-name-standup = Stand up
action-name-make-standup = Make to stand up
lying-down-examined = [color=lightblue]{CAPITALIZE(SUBJECT($target))} {CONJUGATE-BE($target)} is lying down.[/color]
ui-options-function-lie-down-stand-up = Lie on the ground
19 changes: 19 additions & 0 deletions Resources/Prototypes/Actions/liedown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- type: entity
id: ActionStandUp
name: Stand Up
description: Toggles all glove actions on left click. Includes your doorjack, draining power, stunning enemies, downloading research and calling in a threat.
noSpawn: true
components:
- type: InstantAction
icon: Interface/Actions/stand-up-state.png
event: !type:StandUpActionEvent {}

- type: entity
id: ActionLieDown
name: Lie Down
description: Toggles all glove actions on left click. Includes your doorjack, draining power, stunning enemies, downloading research and calling in a threat.
noSpawn: true
components:
- type: InstantAction
icon: Interface/Actions/lie-down-state.png
event: !type:LieDownActionEvent {}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion Resources/keybinds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1 # Not used right now, whatever.
version: 1 # Not used right now, whatever.
binds:
- function: UIClick
type: State
Expand Down Expand Up @@ -540,3 +540,7 @@ binds:
- function: Hotbar9
type: State
key: Num9
- function: LieDownStandUp
type: State
key: Z
mod1: Shift

0 comments on commit 1ac73bc

Please sign in to comment.