* added triggers for when an entity is inserted or removed from a container, for both the entity and the container
* removed unnecessary comments
* consolidated into one shared system for all four triggers
* consolidated into one shared system for all four triggers
* named it right this time
* made container owner user of got triggers and added guard statements
* container id
* Update Content.Shared/Trigger/Components/Triggers/TriggerOnRemovedFromContainerComponent.cs
---------
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Triggers;
+
+/// <summary>
+/// Triggers an entity when it gets inserted into a container.
+/// The user is the owner of the container the entity is being inserted into.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class TriggerOnGotInsertedIntoContainerComponent : BaseTriggerOnXComponent
+{
+ /// <summary>
+ /// The container to the entity has to be inserted into.
+ /// Null will allow all containers.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public string? ContainerId;
+}
--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Triggers;
+
+/// <summary>
+/// Triggers an entity when it gets removed from a container.
+/// The user is the owner of the container the entity is being removed from.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class TriggerOnGotRemovedFromContainerComponent : BaseTriggerOnXComponent
+{
+ /// <summary>
+ /// The container to the entity has to be removed from.
+ /// Null will allow all containers.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public string? ContainerId;
+}
--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Triggers;
+
+/// <summary>
+/// Triggers an entity when something is inserted into it.
+/// The user is the entity being inserted into the container.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class TriggerOnInsertedIntoContainerComponent : BaseTriggerOnXComponent
+{
+ /// <summary>
+ /// The container to the entity has to be inserted into.
+ /// Null will allow all containers.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public string? ContainerId;
+}
--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Triggers;
+
+/// <summary>
+/// Triggers an entity when something is removed from it.
+/// The user is the entity being removed from the container.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class TriggerOnRemovedFromContainerComponent : BaseTriggerOnXComponent
+{
+ /// <summary>
+ /// The container to the entity has to be removed from.
+ /// Null will allow all containers.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public string? ContainerId;
+}
--- /dev/null
+using Content.Shared.Trigger.Components.Triggers;
+using Robust.Shared.Containers;
+using Robust.Shared.Timing;
+
+namespace Content.Shared.Trigger.Systems;
+
+/// <summary>
+/// System for creating triggers when entities are inserted into or removed from containers.
+/// </summary>
+public sealed class TriggerOnContainerInteractionSystem : EntitySystem
+{
+ [Dependency] private readonly TriggerSystem _trigger = default!;
+ [Dependency] private readonly IGameTiming _timing = default!;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+
+ SubscribeLocalEvent<TriggerOnInsertedIntoContainerComponent, EntInsertedIntoContainerMessage>(OnInsertedIntoContainer);
+ SubscribeLocalEvent<TriggerOnRemovedFromContainerComponent, EntRemovedFromContainerMessage>(OnRemovedFromContainer);
+ SubscribeLocalEvent<TriggerOnGotInsertedIntoContainerComponent, EntGotInsertedIntoContainerMessage>(OnGotInsertedIntoContainer);
+ SubscribeLocalEvent<TriggerOnGotRemovedFromContainerComponent, EntGotRemovedFromContainerMessage>(OnGotRemovedFromContainer);
+ }
+
+ // Used by containers to trigger when entities are inserted into or removed from them
+ private void OnInsertedIntoContainer(Entity<TriggerOnInsertedIntoContainerComponent> ent, ref EntInsertedIntoContainerMessage args)
+ {
+ if (_timing.ApplyingState)
+ return;
+
+ if (ent.Comp.ContainerId != null && ent.Comp.ContainerId != args.Container.ID)
+ return;
+
+ _trigger.Trigger(ent.Owner, args.Entity, ent.Comp.KeyOut);
+ }
+
+ private void OnRemovedFromContainer(Entity<TriggerOnRemovedFromContainerComponent> ent, ref EntRemovedFromContainerMessage args)
+ {
+ if (_timing.ApplyingState)
+ return;
+
+ if (ent.Comp.ContainerId != null && ent.Comp.ContainerId != args.Container.ID)
+ return;
+
+ _trigger.Trigger(ent.Owner, args.Entity, ent.Comp.KeyOut);
+ }
+
+ // Used by entities to trigger when they are inserted into or removed from a container
+ private void OnGotInsertedIntoContainer(Entity<TriggerOnGotInsertedIntoContainerComponent> ent, ref EntGotInsertedIntoContainerMessage args)
+ {
+ if (_timing.ApplyingState)
+ return;
+
+ if (ent.Comp.ContainerId != null && ent.Comp.ContainerId != args.Container.ID)
+ return;
+
+ _trigger.Trigger(ent.Owner, args.Container.Owner, ent.Comp.KeyOut);
+ }
+
+ private void OnGotRemovedFromContainer(Entity<TriggerOnGotRemovedFromContainerComponent> ent, ref EntGotRemovedFromContainerMessage args)
+ {
+ if (_timing.ApplyingState)
+ return;
+
+ if (ent.Comp.ContainerId != null && ent.Comp.ContainerId != args.Container.ID)
+ return;
+
+ _trigger.Trigger(ent.Owner, args.Container.Owner, ent.Comp.KeyOut);
+ }
+}