From: Artxmisery <78118840+Artxmisery@users.noreply.github.com> Date: Sat, 16 Aug 2025 13:50:32 +0000 (+0000) Subject: Equip and unequip triggers (#39675) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=71f5c2d665b124845d6e0b73f969d70d995999bd;p=space-station-14.git Equip and unequip triggers (#39675) * added equip and unequip triggers for equipment and equipee * Update Content.Shared/Trigger/Components/Triggers/TriggerOnDidEquipComponent.cs --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --- diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnDidEquipComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnDidEquipComponent.cs new file mode 100644 index 0000000000..3c970eb855 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnDidEquipComponent.cs @@ -0,0 +1,18 @@ +using Content.Shared.Inventory; +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when an entity equips another entity. +/// The user is the entity being equipped. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnDidEquipComponent : BaseTriggerOnXComponent +{ + /// + /// The slots entities being equipped to will trigger the entity. + /// + [DataField, AutoNetworkedField] + public SlotFlags SlotFlags; +} diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnDidUnequipComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnDidUnequipComponent.cs new file mode 100644 index 0000000000..c6ec3821b1 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnDidUnequipComponent.cs @@ -0,0 +1,18 @@ +using Content.Shared.Inventory; +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when an entity unequips another entity. +/// The user is the entity being unequipped. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnDidUnequipComponent : BaseTriggerOnXComponent +{ + /// + /// The slots that entities being unequipped from will trigger the entity. + /// + [DataField, AutoNetworkedField] + public SlotFlags SlotFlags; +} diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnGotEquippedComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnGotEquippedComponent.cs new file mode 100644 index 0000000000..c3bb62fa80 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnGotEquippedComponent.cs @@ -0,0 +1,18 @@ +using Content.Shared.Inventory; +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when an entity is equipped to another entity. +/// The user is the entity being equipped to (i.e. the equipee). +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnGotEquippedComponent : BaseTriggerOnXComponent +{ + /// + /// The slots that being equipped to will trigger the entity. + /// + [DataField, AutoNetworkedField] + public SlotFlags SlotFlags; +} diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnGotUnequippedComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnGotUnequippedComponent.cs new file mode 100644 index 0000000000..2b6663e1f0 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnGotUnequippedComponent.cs @@ -0,0 +1,18 @@ +using Content.Shared.Inventory; +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when an entity is unequipped from another entity. +/// The user is the entity being unequipped from (i.e. the (un)equipee). +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnGotUnequippedComponent : BaseTriggerOnXComponent +{ + /// + /// The slots that being unequipped from will trigger the entity. + /// + [DataField, AutoNetworkedField] + public SlotFlags SlotFlags; +} diff --git a/Content.Shared/Trigger/Systems/TriggerOnEquipmentSystem.cs b/Content.Shared/Trigger/Systems/TriggerOnEquipmentSystem.cs new file mode 100644 index 0000000000..bc097ae831 --- /dev/null +++ b/Content.Shared/Trigger/Systems/TriggerOnEquipmentSystem.cs @@ -0,0 +1,70 @@ +using Content.Shared.Trigger.Components.Triggers; +using Robust.Shared.Timing; +using Content.Shared.Inventory.Events; + +namespace Content.Shared.Trigger.Systems; + +/// +/// System for creating triggers when entities are equipped or unequipped from inventory slots. +/// +public sealed class TriggerOnEquipmentSystem : EntitySystem +{ + [Dependency] private readonly TriggerSystem _trigger = default!; + [Dependency] private readonly IGameTiming _timing = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnDidEquip); + SubscribeLocalEvent(OnDidUnequip); + SubscribeLocalEvent(OnGotEquipped); + SubscribeLocalEvent(OnGotUnequipped); + } + + // Used by entities when equipping or unequipping other entities + private void OnDidEquip(Entity ent, ref DidEquipEvent args) + { + if (_timing.ApplyingState) + return; + + if ((ent.Comp.SlotFlags & args.SlotFlags) == 0) + return; + + _trigger.Trigger(ent.Owner, args.Equipment, ent.Comp.KeyOut); + } + + private void OnDidUnequip(Entity ent, ref DidUnequipEvent args) + { + if (_timing.ApplyingState) + return; + + if ((ent.Comp.SlotFlags & args.SlotFlags) == 0) + return; + + _trigger.Trigger(ent.Owner, args.Equipment, ent.Comp.KeyOut); + } + + // Used by entities when they get equipped or unequipped + private void OnGotEquipped(Entity ent, ref GotEquippedEvent args) + { + if (_timing.ApplyingState) + return; + + if ((ent.Comp.SlotFlags & args.SlotFlags) == 0) + return; + + _trigger.Trigger(ent.Owner, args.Equipee, ent.Comp.KeyOut); + } + + private void OnGotUnequipped(Entity ent, ref GotUnequippedEvent args) + { + if (_timing.ApplyingState) + return; + + if ((ent.Comp.SlotFlags & args.SlotFlags) == 0) + return; + + _trigger.Trigger(ent.Owner, args.Equipee, ent.Comp.KeyOut); + } +}