From 1ac73bc45933a610f436c246aff6e72fce75d641 Mon Sep 17 00:00:00 2001 From: user424242420 <142989209+user424242420@users.noreply.github.com> Date: Sun, 23 Jun 2024 14:44:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9B=D1=8F=D0=B6=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BF=D0=BE=D0=BF=D1=8B?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20-=20=D0=94=D0=9E=D0=94=D0=95=D0=9B=D0=90?= =?UTF-8?q?=D0=9D=D0=9D=D0=9E=D0=95,=20=D0=A0=D0=90=D0=91=D0=9E=D0=A7?= =?UTF-8?q?=D0=95=D0=95=20=D0=93=D0=90=D0=92=D0=9D=D0=9E=20(#325)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Не рабочее гавно в процессе * Не фикс говна * Update Content.Shared/Standing/StandingStateComponent.cs Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> * Update Content.Shared/LieDown/LyingDownComponent.cs Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> * Update Content.Shared/LieDown/SharedLieDownSystem.cs Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> * Revert "Update Content.Shared/LieDown/SharedLieDownSystem.cs" This reverts commit a133d9eaf469e43074daacc4f84d2c37e2a5ded7. * fix * Эта хуйня работает * Final fix --------- Co-authored-by: Ivan Rubinov Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> --- 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 | 171 ++++++++++++++++++ .../Standing/StandingStateComponent.cs | 59 ++++-- .../Standing/StandingStateSystem.cs | 46 ++++- .../Locale/en-US/actions/actions/lie-down.ftl | 5 + Resources/Prototypes/Actions/liedown.yml | 19 ++ .../Interface/Actions/lie-down-state.png | Bin 0 -> 440 bytes .../Interface/Actions/stand-up-state.png | Bin 0 -> 461 bytes Resources/keybinds.yml | 6 +- 12 files changed, 313 insertions(+), 21 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/Prototypes/Actions/liedown.yml create mode 100644 Resources/Textures/Interface/Actions/lie-down-state.png create mode 100644 Resources/Textures/Interface/Actions/stand-up-state.png 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] + public EntProtoId? 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..9db46ed0c41 --- /dev/null +++ b/Content.Shared/LieDown/SharedLieDownSystem.cs @@ -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(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(0f, 0f); + } + else + { + args.ModifySpeed(1f, 1f); + } + } + + /// + /// Change available to player actions. + /// + private void SwitchActions(EntityUid uid) + { + var standingComponent = Comp(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); + } + } + + /// + /// 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; + + RemCompDeferred(uid); + } + + public void TryLieDown(EntityUid uid) + { + if (_standing.IsDown(uid) || !_standing.Down(uid, false, false)) + return; + + EnsureComp(uid); + } +} + diff --git a/Content.Shared/Standing/StandingStateComponent.cs b/Content.Shared/Standing/StandingStateComponent.cs index 5d7bb0a59fd..b4516dd6157 100644 --- a/Content.Shared/Standing/StandingStateComponent.cs +++ b/Content.Shared/Standing/StandingStateComponent.cs @@ -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; - - /// - /// List of fixtures that had their collision mask changed when the entity was downed. - /// Required for re-adding the collision mask. - /// - [DataField, AutoNetworkedField] - public List ChangedFixtures = new(); - } + [ViewVariables(VVAccess.ReadWrite)] + [DataField] + public SoundSpecifier DownSound { get; private set; } = new SoundCollectionSpecifier("BodyFall"); + + [DataField, AutoNetworkedField] + public bool Standing = true; + + /// + /// List of fixtures that had their collision mask changed when the entity was downed. + /// Required for re-adding the collision mask. + /// + [DataField, AutoNetworkedField] + public List 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 {} + diff --git a/Content.Shared/Standing/StandingStateSystem.cs b/Content.Shared/Standing/StandingStateSystem.cs index ed586e970dc..1a3f59f8f02 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,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(OnComponentInit); + SubscribeLocalEvent(OnLieDownAction); + SubscribeLocalEvent(OnStandUpAction); + SubscribeLocalEvent(OnMapInit); + } public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null) { if (!Resolve(uid, ref standingState, false)) @@ -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); + } + + /// + /// When component is added to player, add an action. + /// + private void OnComponentInit(EntityUid uid, StandingStateComponent component, ComponentStartup args) + { + _actions.AddAction(uid, ref component.LieDownActionEntity, component.LieDownAction); + } + + /// + /// 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/Prototypes/Actions/liedown.yml b/Resources/Prototypes/Actions/liedown.yml new file mode 100644 index 00000000000..aee3b552bc1 --- /dev/null +++ b/Resources/Prototypes/Actions/liedown.yml @@ -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 {} 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|(