From: Studio Fae-Wilds Date: Thu, 14 Aug 2025 07:39:54 +0000 (+1000) Subject: Add trigger-refactor components and systems: Batch 1 (#39391) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=770dc68a48ad0d2135bba8103428713cf9243f7c;p=space-station-14.git Add trigger-refactor components and systems: Batch 1 (#39391) * Adds the following batch of trigger refactor components and their associated systems: TriggerOnLand: LandEvent TriggerOnExamined: ExaminedEvent TriggerOnUnbuckle: UnbuckledEvent TriggerOnBuckle: BuckledEvent TriggerOnStrap: StrappedEvent TriggerOnUnstrapped: UnstrappedEvent * Removes unnecessary lines from comment * Fix comment formatting, corrects grammar and increases comment clarity. * adds last forgotten edit to comments * Update Content.Shared/Trigger/Systems/TriggerOnStrappedOrBuckledSystem.cs Removes unnecessary comments Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnBuckledComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnExaminedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnLandComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnStrappedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUnbuckledComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUnstrappedComponent.cs Increases comment clarity Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * refactored TriggerOnStrappedOrBuckledSystem.cs removed TriggerOnExaminedSystem.cs and moved it into TriggerSystem.Interaction.cs Changes currently untested, not sure how to make it so modders can change what method they want sending out the appropriate trigger key but want to save progress working on it and get feedback from maintainers * Removed component which already exists as part of TriggerSystem.Interaction.cs * Restores accidentally removed component * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --- diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnBuckledComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnBuckledComponent.cs new file mode 100644 index 0000000000..b6f3506f64 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnBuckledComponent.cs @@ -0,0 +1,11 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when the owning entity is buckled. +/// This is intended to be used on buckle-able entities like mobs. +/// The user is the strap entity (a chair or similar). +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnBuckledComponent : BaseTriggerOnXComponent; diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnExaminedComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnExaminedComponent.cs new file mode 100644 index 0000000000..8ceb755933 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnExaminedComponent.cs @@ -0,0 +1,10 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when the entity is being examined. +/// The user is the player doing the examination. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnExaminedComponent : BaseTriggerOnXComponent; diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnLandComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnLandComponent.cs new file mode 100644 index 0000000000..48d048886a --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnLandComponent.cs @@ -0,0 +1,10 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when the entity exits a floating or thrown state and lands on a surface. +/// The user is the thrower. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnLandComponent : BaseTriggerOnXComponent; diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnStrappedComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnStrappedComponent.cs new file mode 100644 index 0000000000..b5a60b6a03 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnStrappedComponent.cs @@ -0,0 +1,11 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when something is strapped to the entity. +/// This is intended to be used on objects like chairs or beds. +/// The user is the entity strapped to the component owner. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnStrappedComponent : BaseTriggerOnXComponent; diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnUnbuckledComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnUnbuckledComponent.cs new file mode 100644 index 0000000000..47092f4b69 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnUnbuckledComponent.cs @@ -0,0 +1,11 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when the owning entity is unbuckled. +/// This is intended to be used on buckle-able entities like mobs. +/// The user is the strap entity (a chair or similar). +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnUnbuckledComponent : BaseTriggerOnXComponent; diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnUnstrappedComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnUnstrappedComponent.cs new file mode 100644 index 0000000000..c9ff41282e --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnUnstrappedComponent.cs @@ -0,0 +1,11 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when something is unstrapped from the entity. +/// This is intended to be used on objects like chairs or beds. +/// The user is the entity unstrapped from the component owner. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnUnstrappedComponent : BaseTriggerOnXComponent; diff --git a/Content.Shared/Trigger/Systems/TriggerOnLandSystem.cs b/Content.Shared/Trigger/Systems/TriggerOnLandSystem.cs new file mode 100644 index 0000000000..754f285753 --- /dev/null +++ b/Content.Shared/Trigger/Systems/TriggerOnLandSystem.cs @@ -0,0 +1,21 @@ +using Content.Shared.Throwing; +using Content.Shared.Trigger.Components.Triggers; + +namespace Content.Shared.Trigger.Systems; + +public sealed partial class TriggerOnLandSystem : EntitySystem +{ + [Dependency] private readonly TriggerSystem _trigger = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnLand); + } + + private void OnLand(Entity ent, ref LandEvent args) + { + _trigger.Trigger(ent.Owner, args.User, ent.Comp.KeyOut); + } +} diff --git a/Content.Shared/Trigger/Systems/TriggerOnStrappedOrBuckledSystem.cs b/Content.Shared/Trigger/Systems/TriggerOnStrappedOrBuckledSystem.cs new file mode 100644 index 0000000000..d4960ff70c --- /dev/null +++ b/Content.Shared/Trigger/Systems/TriggerOnStrappedOrBuckledSystem.cs @@ -0,0 +1,49 @@ +using Content.Shared.Buckle.Components; +using Content.Shared.Trigger.Components.Triggers; + +namespace Content.Shared.Trigger.Systems; + +/// +/// This is a system covering all trigger interactions involving strapping or buckling objects. +/// The users of strap components are the objects having an entity strapped to them (IE: Chairs) +/// The users of buckle components are entities being buckled to an object. (IE: Mobs and players) +/// +public sealed partial class TriggerOnStrappedOrBuckledSystem : EntitySystem +{ + [Dependency] private readonly TriggerSystem _trigger = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnStrapped); + SubscribeLocalEvent(OnUnstrapped); + SubscribeLocalEvent(OnBuckled); + SubscribeLocalEvent(OnUnbuckled); + } + + + #region Class Methods + // Called by objects entities can be buckled to. (Chairs, surgical tables/) + private void OnStrapped(Entity ent, ref StrappedEvent args) + { + _trigger.Trigger(ent.Owner, args.Strap, ent.Comp.KeyOut); + } + + private void OnUnstrapped(Entity ent, ref UnstrappedEvent args) + { + _trigger.Trigger(ent.Owner, args.Strap, ent.Comp.KeyOut); + } + + // Called by entities that are buckled to an object. (Mobs, players.) + private void OnBuckled(Entity ent, ref BuckledEvent args) + { + _trigger.Trigger(ent.Owner, args.Buckle, ent.Comp.KeyOut); + } + + private void OnUnbuckled(Entity ent, ref UnbuckledEvent args) + { + _trigger.Trigger(ent.Owner, args.Buckle, ent.Comp.KeyOut); + } + #endregion +} diff --git a/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs b/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs index 035ef4ec91..230b628663 100644 --- a/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs +++ b/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs @@ -1,4 +1,5 @@ -using Content.Shared.Interaction; +using Content.Shared.Examine; +using Content.Shared.Interaction; using Content.Shared.Interaction.Events; using Content.Shared.Item.ItemToggle.Components; using Content.Shared.Trigger.Components.Triggers; @@ -10,6 +11,8 @@ public sealed partial class TriggerSystem { private void InitializeInteraction() { + SubscribeLocalEvent(OnExamined); + SubscribeLocalEvent(OnActivate); SubscribeLocalEvent(OnUse); SubscribeLocalEvent(OnInteractHand); @@ -19,6 +22,11 @@ public sealed partial class TriggerSystem SubscribeLocalEvent(HandleUseDelayOnTrigger); } + private void OnExamined(Entity ent, ref ExaminedEvent args) + { + Trigger(ent.Owner, args.Examiner, ent.Comp.KeyOut); + } + private void OnActivate(Entity ent, ref ActivateInWorldEvent args) { if (args.Handled)