From 18c8dfcf83667d59e2c519bf3834a9600318e542 Mon Sep 17 00:00:00 2001 From: Ivan Rubinov Date: Mon, 17 Jun 2024 12:09:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B5=D0=B5=20=D0=B3=D0=B0=D0=B2=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content.Client/Input/ContentContexts.cs | 1 + .../Options/UI/Tabs/KeyRebindTab.xaml.cs | 1 + Content.Shared/Input/ContentKeyFunctions.cs | 1 + Content.Shared/LieDown/LyingDownComponent.cs | 25 + Content.Shared/LieDown/SharedLieDownSystem.cs | 167 +++++ .../Standing/StandingStateComponent.cs | 18 +- .../Standing/StandingStateSystem.cs | 39 ++ .../Locale/en-US/actions/actions/lie-down.ftl | 5 + .../Locale/ru-RU/actions/actions/lie-down.ftl | 5 + .../Prototypes/Entities/Mobs/Species/base.yml | 18 +- .../Interface/Actions/lie-down-state.png | Bin 0 -> 440 bytes .../Interface/Actions/stand-up-state.png | Bin 0 -> 461 bytes Resources/keybinds.yml | 6 +- Resources/keybinds.yml.orig | 589 ++++++++++++++++++ 14 files changed, 872 insertions(+), 3 deletions(-) create mode 100644 Content.Shared/LieDown/LyingDownComponent.cs create mode 100644 Content.Shared/LieDown/SharedLieDownSystem.cs create mode 100644 Resources/Locale/en-US/actions/actions/lie-down.ftl create mode 100644 Resources/Locale/ru-RU/actions/actions/lie-down.ftl create mode 100644 Resources/Textures/Interface/Actions/lie-down-state.png create mode 100644 Resources/Textures/Interface/Actions/stand-up-state.png create mode 100644 Resources/keybinds.yml.orig diff --git a/Content.Client/Input/ContentContexts.cs b/Content.Client/Input/ContentContexts.cs index 7a8a9938545..afe9ed60656 100644 --- a/Content.Client/Input/ContentContexts.cs +++ b/Content.Client/Input/ContentContexts.cs @@ -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); diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index a575f1ba51c..1ecf44235d1 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -181,6 +181,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action +/// Makes the target to lie down. +/// +[Access(typeof(SharedLieDownSystem))] +[RegisterComponent, NetworkedComponent()] +public sealed partial class LyingDownComponent : Component +{ + /// + /// The action to lie down or stand up. + /// + [DataField("make-to-stand-up-action", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string? MakeToStandUpAction = "action-name-make-standup"; +} + +[Serializable, NetSerializable] +public sealed class ChangeStandingStateEvent : EntityEventArgs {} diff --git a/Content.Shared/LieDown/SharedLieDownSystem.cs b/Content.Shared/LieDown/SharedLieDownSystem.cs new file mode 100644 index 00000000000..3e60286fbe4 --- /dev/null +++ b/Content.Shared/LieDown/SharedLieDownSystem.cs @@ -0,0 +1,167 @@ +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.IoC; +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(OnInteractHand); + SubscribeLocalEvent>(AddStandUpVerb); + SubscribeLocalEvent(OnExamined); + SubscribeLocalEvent(OnRefresh); + + SubscribeLocalEvent(OnComponentStartup); + SubscribeLocalEvent(OnComponentShutdown); + + // Bind keybinds to lie down action + SubscribeNetworkEvent(OnChangeAction); + CommandBinds.Builder + .Bind(ContentKeyFunctions.LieDownStandUp, InputCmdHandler.FromDelegate(ChangeLyingState)) + .Register(); + } + + 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); + } + + /// + /// Send an update event when player pressed keybind. + /// + private void ChangeLyingState(ICommonSession? session) + { + RaiseNetworkEvent(new ChangeStandingStateEvent()); + } + + /// + /// Process player event, that pressed keybind. + /// + 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); + } + } + + /// + /// Update movement speed according to the lying state. + /// + private void OnRefresh(EntityUid uid, LyingDownComponent component, RefreshMovementSpeedModifiersEvent args) + { + if (_standing.IsDown(uid)) + { + args.ModifySpeed(0.4f, 0.4f); + } + else + { + args.ModifySpeed(1f, 1f); + } + } + + /// + /// Change available to player actions. + /// + private void SwitchActions(EntityUid uid) + { + var standingComponent = Comp(uid); + _actions.AddAction(uid, ref standingComponent.ToggleActionEntity, standingComponent.ToggleAction); + } + + /// + /// When interacting with a lying down person, add ability to make him stand up. + /// + private void OnInteractHand(EntityUid uid, LyingDownComponent component, InteractHandEvent args) + { + TryStandUp(args.Target); + } + + /// + /// Add a verb to player menu to make him stand up. + /// + private void AddStandUpVerb(EntityUid uid, LyingDownComponent component, GetVerbsEvent 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); + } + + /// + /// If somebody examined a lying down person, add description. + /// + 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; + + Logger.Debug("{uid} tried to stand up", uid); + + RemCompDeferred(uid); + } + + public void TryLieDown(EntityUid uid) + { + if (_standing.IsDown(uid) || !_standing.Down(uid, false, false)) + return; + + Logger.Debug("{uid} tried to lie down", uid); + + EnsureComp(uid); + } + } +} diff --git a/Content.Shared/Standing/StandingStateComponent.cs b/Content.Shared/Standing/StandingStateComponent.cs index 5d7bb0a59fd..cd43405f25b 100644 --- a/Content.Shared/Standing/StandingStateComponent.cs +++ b/Content.Shared/Standing/StandingStateComponent.cs @@ -1,9 +1,12 @@ +using Content.Shared.Actions; using Robust.Shared.Audio; using Robust.Shared.GameStates; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Shared.Standing { - [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] + [RegisterComponent, NetworkedComponent(), AutoGenerateComponentState] [Access(typeof(StandingStateSystem))] public sealed partial class StandingStateComponent : Component { @@ -20,5 +23,18 @@ public sealed partial class StandingStateComponent : Component /// [DataField, AutoNetworkedField] public List ChangedFixtures = new(); + + [DataField] + public EntProtoId ToggleAction = "ActionToggleLieDown"; + + [DataField, AutoNetworkedField] + public EntityUid? ToggleActionEntity; + + + [DataField("IsDown"), AutoNetworkedField] + public bool IsDown = false; } + + public sealed partial class LieDownActionEvent : InstantActionEvent {} + public sealed partial class StandUpActionEvent : InstantActionEvent {} } diff --git a/Content.Shared/Standing/StandingStateSystem.cs b/Content.Shared/Standing/StandingStateSystem.cs index ed586e970dc..eca7afb04b7 100644 --- a/Content.Shared/Standing/StandingStateSystem.cs +++ b/Content.Shared/Standing/StandingStateSystem.cs @@ -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; @@ -13,18 +16,54 @@ 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!; // If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited. private const int StandingCollisionLayer = (int) CollisionGroup.MidImpassable; + public override void Initialize() + { + SubscribeLocalEvent(OnComponentInit); + + SubscribeLocalEvent(OnLieDownAction); + SubscribeLocalEvent(OnStandUpAction); + } public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null) { if (!Resolve(uid, ref standingState, false)) return false; + if (HasComp(uid)) + RemComp(uid); + return !standingState.Standing; } + /// + /// When component is added to player, add an action. + /// + private void OnComponentInit(EntityUid uid, StandingStateComponent component, ComponentStartup args) + { + _actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction); + } + + /// + /// Event that being risen on lie down attempt. + /// + private void OnLieDownAction(EntityUid uid, StandingStateComponent component, LieDownActionEvent args) + { + _lieDown.TryLieDown(uid); + } + + /// + /// Event that being risen on stand up attempt. + /// + 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, diff --git a/Resources/Locale/en-US/actions/actions/lie-down.ftl b/Resources/Locale/en-US/actions/actions/lie-down.ftl new file mode 100644 index 00000000000..2160f49afc2 --- /dev/null +++ b/Resources/Locale/en-US/actions/actions/lie-down.ftl @@ -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 diff --git a/Resources/Locale/ru-RU/actions/actions/lie-down.ftl b/Resources/Locale/ru-RU/actions/actions/lie-down.ftl new file mode 100644 index 00000000000..2160f49afc2 --- /dev/null +++ b/Resources/Locale/ru-RU/actions/actions/lie-down.ftl @@ -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 diff --git a/Resources/Prototypes/Entities/Mobs/Species/base.yml b/Resources/Prototypes/Entities/Mobs/Species/base.yml index 347964a6a0c..5ddee672191 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/base.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/base.yml @@ -174,6 +174,22 @@ - type: SleepEmitSound - type: SSDIndicator - type: StandingState + lie-down-action: + type: instantAction + id: LieDown + icon: Interface/Actions/lie-down-state.png + name: action-name-liedown + itemIconStyle: NoItem + event: !type:LieDownActionEvent + checkCanInteract: true + stand-up-action: + type: instantAction + id: StandUp + icon: Interface/Actions/stand-up-state.png + name: action-name-standup + itemIconStyle: NoItem + event: !type:StandUpActionEvent + checkCanInteract: true - type: Fingerprint - type: Dna - type: MindContainer @@ -216,7 +232,7 @@ - type: MobPrice price: 1500 # Kidnapping a living person and selling them for cred is a good move. deathPenalty: 0.01 # However they really ought to be living and intact, otherwise they're worth 100x less. - - type: CanEscapeInventory # Carrying system from nyanotrasen. + - type: CanEscapeInventory # Carrying system from nyanotrasen. - type: Tag tags: - CanPilot diff --git a/Resources/Textures/Interface/Actions/lie-down-state.png b/Resources/Textures/Interface/Actions/lie-down-state.png new file mode 100644 index 0000000000000000000000000000000000000000..436ff4ee198c01b7d72c2f89cce0e809f30ff2fb GIT binary patch literal 440 zcmV;p0Z0CcP)Px$a!Eu%R9Hvdm!S^AFc5}23z}y@V^AanL%?F^v6DOla+U;%#X>NIWC}xq<3Rv9 zaw9j6%XPagTSu5FG;RN{*Xw_qXBvJyq8~eENwg6l?kxgyS%yv+h?bWEfbw`cw*o|K z-*m&R>0F=b7}^KF@!{k6qKDlIyQ&4q6GqkA06;(kQ5%3p93V>r@H2Lr165uRRRnBV zjr|yIemn60EtsYGz{jWoxQMhU?Sm-&6ad}|4p~bCP(*6^^;82$&c<^<6LwV&G+hf| zBaK!=GuUsO0z?!4Q;tFWemtA@s9&YuSl2==fJi8C_pR`hOyVX4nJw8c&2DbX;33jH znDYpRZygChs{1t4;eEg+rZFy z2y6x<6`(BdFO>r>u7UapI82dD&)P`k0Je7n8^r$sNJ(4E5l9|kGp@n_jn)EM4_sVB itOL-}uVYu*Upg;Gif=y{82Ksy0000Px$hezS)CHB5HG9{LJOg9aN*%j)rD8#qm{^e5 z`XIDpDqrH%IKG@gmrF$k5{`@iFL%G~keHs21ofvMZ$(U&{ZneS?FWdTcL($EIEli5 zS^!Z4fbt;!bOP*OQ!~on&G7V7&!J;*jR&8{gMMc-I}{wiCyXGS0f2x8qB8)EI6&SE z!1p++2STQYY6V=b#&KM3o*nr8D_hon;B(XfTto^=$82g<>H04KFe^A@Co6y=(wV2H z8bGRS+yk0rS9ze^^YQW>W1=4Babh;$#^v)#O4xF&$q_o>t2eZVEADO_-WD*#;q+TA2k3WHCJ zPfpJq+6#c|(>>>>>> Moved stuff to standing system for ease of use. Fixed some edge cases with KnockedDownComponent.