2025-02-10 10:51:44 -04:00
|
|
|
using Content.Shared.Armor;
|
2025-04-14 11:00:47 +02:00
|
|
|
using Content.Shared.Atmos;
|
2024-11-15 15:46:01 -08:00
|
|
|
using Content.Shared.Chat;
|
2023-08-02 03:57:22 +08:00
|
|
|
using Content.Shared.Chemistry;
|
2024-11-15 15:46:01 -08:00
|
|
|
using Content.Shared.Chemistry.Hypospray.Events;
|
|
|
|
|
using Content.Shared.Climbing.Events;
|
2025-04-27 00:06:34 +03:00
|
|
|
using Content.Shared.Contraband;
|
2022-04-01 15:39:26 +13:00
|
|
|
using Content.Shared.Damage;
|
2025-04-14 17:27:26 +02:00
|
|
|
using Content.Shared.Damage.Events;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Electrocution;
|
2025-07-11 10:18:15 -07:00
|
|
|
using Content.Shared.Emoting;
|
2022-04-01 15:39:26 +13:00
|
|
|
using Content.Shared.Explosion;
|
2023-04-29 17:32:14 +12:00
|
|
|
using Content.Shared.Eye.Blinding.Systems;
|
2025-06-23 13:32:56 +02:00
|
|
|
using Content.Shared.Flash;
|
2024-06-14 23:43:23 -04:00
|
|
|
using Content.Shared.Gravity;
|
2022-07-10 18:36:53 -07:00
|
|
|
using Content.Shared.IdentityManagement.Components;
|
2025-05-30 03:07:25 -07:00
|
|
|
using Content.Shared.Implants;
|
2023-08-01 23:17:03 +02:00
|
|
|
using Content.Shared.Inventory.Events;
|
2024-08-23 11:59:51 +02:00
|
|
|
using Content.Shared.Movement.Events;
|
2022-06-24 17:44:30 +10:00
|
|
|
using Content.Shared.Movement.Systems;
|
2024-06-16 15:38:53 -04:00
|
|
|
using Content.Shared.NameModifier.EntitySystems;
|
2023-08-01 23:17:03 +02:00
|
|
|
using Content.Shared.Overlays;
|
2025-04-30 16:10:54 +02:00
|
|
|
using Content.Shared.Projectiles;
|
2023-02-19 06:27:56 +13:00
|
|
|
using Content.Shared.Radio;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Slippery;
|
2022-06-27 20:14:51 -04:00
|
|
|
using Content.Shared.Strip.Components;
|
2022-10-25 13:06:00 +13:00
|
|
|
using Content.Shared.Temperature;
|
2023-03-06 06:12:08 +13:00
|
|
|
using Content.Shared.Verbs;
|
2024-11-15 15:46:01 -08:00
|
|
|
using Content.Shared.Weapons.Ranged.Events;
|
2025-05-26 05:50:30 +02:00
|
|
|
using Content.Shared.Wieldable;
|
2025-04-16 19:21:45 +01:00
|
|
|
using Content.Shared.Zombies;
|
2021-12-30 22:56:10 +01:00
|
|
|
|
|
|
|
|
namespace Content.Shared.Inventory;
|
|
|
|
|
|
|
|
|
|
public partial class InventorySystem
|
|
|
|
|
{
|
|
|
|
|
public void InitializeRelay()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, DamageModifyEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, ElectrocutionAttemptEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, SlipAttemptEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshMovementSpeedModifiersEvent>(RelayInventoryEvent);
|
2022-06-27 20:14:51 -04:00
|
|
|
SubscribeLocalEvent<InventoryComponent, BeforeStripEvent>(RelayInventoryEvent);
|
2022-07-10 18:36:53 -07:00
|
|
|
SubscribeLocalEvent<InventoryComponent, SeeIdentityAttemptEvent>(RelayInventoryEvent);
|
2022-10-25 13:06:00 +13:00
|
|
|
SubscribeLocalEvent<InventoryComponent, ModifyChangedTemperatureEvent>(RelayInventoryEvent);
|
2023-02-19 06:27:56 +13:00
|
|
|
SubscribeLocalEvent<InventoryComponent, GetDefaultRadioChannelEvent>(RelayInventoryEvent);
|
2024-06-16 15:38:53 -04:00
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshNameModifiersEvent>(RelayInventoryEvent);
|
2024-09-26 09:55:59 -07:00
|
|
|
SubscribeLocalEvent<InventoryComponent, TransformSpeakerNameEvent>(RelayInventoryEvent);
|
2024-11-15 15:46:01 -08:00
|
|
|
SubscribeLocalEvent<InventoryComponent, SelfBeforeHyposprayInjectsEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, TargetBeforeHyposprayInjectsEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, SelfBeforeGunShotEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, SelfBeforeClimbEvent>(RelayInventoryEvent);
|
2025-02-10 10:51:44 -04:00
|
|
|
SubscribeLocalEvent<InventoryComponent, CoefficientQueryEvent>(RelayInventoryEvent);
|
2025-04-16 19:21:45 +01:00
|
|
|
SubscribeLocalEvent<InventoryComponent, ZombificationResistanceQueryEvent>(RelayInventoryEvent);
|
2025-05-12 20:35:42 +03:00
|
|
|
SubscribeLocalEvent<InventoryComponent, IsEquippingTargetAttemptEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, IsUnequippingTargetAttemptEvent>(RelayInventoryEvent);
|
2025-05-30 03:07:25 -07:00
|
|
|
SubscribeLocalEvent<InventoryComponent, ChameleonControllerOutfitSelectedEvent>(RelayInventoryEvent);
|
2025-07-11 10:18:15 -07:00
|
|
|
SubscribeLocalEvent<InventoryComponent, BeforeEmoteEvent>(RelayInventoryEvent);
|
2023-03-06 06:12:08 +13:00
|
|
|
|
2023-10-12 03:31:10 +11:00
|
|
|
// by-ref events
|
2025-05-02 01:18:08 -07:00
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshFrictionModifiersEvent>(RefRelayInventoryEvent);
|
2025-04-14 17:27:26 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, BeforeStaminaDamageEvent>(RefRelayInventoryEvent);
|
2023-10-12 03:31:10 +11:00
|
|
|
SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
|
2024-06-14 23:43:23 -04:00
|
|
|
SubscribeLocalEvent<InventoryComponent, IsWeightlessEvent>(RefRelayInventoryEvent);
|
2024-08-23 11:59:51 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, GetSpeedModifierContactCapEvent>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, GetSlowedOverSlipperyModifierEvent>(RefRelayInventoryEvent);
|
2024-08-22 10:56:46 -04:00
|
|
|
SubscribeLocalEvent<InventoryComponent, ModifySlowOnDamageSpeedEvent>(RefRelayInventoryEvent);
|
2025-04-14 11:00:47 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, ExtinguishEvent>(RefRelayInventoryEvent);
|
2025-04-30 16:10:54 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, ProjectileReflectAttemptEvent>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, HitScanReflectAttemptEvent>(RefRelayInventoryEvent);
|
2025-04-27 00:06:34 +03:00
|
|
|
SubscribeLocalEvent<InventoryComponent, GetContrabandDetailsEvent>(RefRelayInventoryEvent);
|
2025-06-23 13:32:56 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, FlashAttemptEvent>(RefRelayInventoryEvent);
|
2025-05-26 05:50:30 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, WieldAttemptEvent>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, UnwieldAttemptEvent>(RefRelayInventoryEvent);
|
2023-10-12 03:31:10 +11:00
|
|
|
|
2023-04-29 17:32:14 +12:00
|
|
|
// Eye/vision events
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, CanSeeAttemptEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, GetEyeProtectionEvent>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, GetBlurEvent>(RelayInventoryEvent);
|
2023-08-02 03:57:22 +08:00
|
|
|
SubscribeLocalEvent<InventoryComponent, SolutionScanEvent>(RelayInventoryEvent);
|
2023-04-29 17:32:14 +12:00
|
|
|
|
2023-08-01 23:17:03 +02:00
|
|
|
// ComponentActivatedClientSystems
|
2025-01-30 06:09:25 +01:00
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowJobIconsComponent>>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthBarsComponent>>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthIconsComponent>>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowMindShieldIconsComponent>>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSyndicateIconsComponent>>(RefRelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowCriminalRecordIconsComponent>>(RefRelayInventoryEvent);
|
2025-05-02 00:07:47 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<BlackAndWhiteOverlayComponent>>(RefRelayInventoryEvent);
|
2025-06-02 18:16:10 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<NoirOverlayComponent>>(RefRelayInventoryEvent);
|
2023-08-01 23:17:03 +02:00
|
|
|
|
2023-10-12 03:31:10 +11:00
|
|
|
SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetEquipmentVerbs);
|
2025-03-30 19:27:08 -07:00
|
|
|
SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<InnateVerb>>(OnGetInnateVerbs);
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-17 19:04:04 +10:00
|
|
|
protected void RefRelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, ref T args) where T : IInventoryRelayEvent
|
|
|
|
|
{
|
2023-12-07 18:51:45 +00:00
|
|
|
RelayEvent((uid, component), ref args);
|
2023-12-06 00:01:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent
|
|
|
|
|
{
|
|
|
|
|
RelayEvent((uid, component), args);
|
|
|
|
|
}
|
2023-10-12 03:31:10 +11:00
|
|
|
|
2023-12-06 00:01:31 -07:00
|
|
|
public void RelayEvent<T>(Entity<InventoryComponent> inventory, ref T args) where T : IInventoryRelayEvent
|
|
|
|
|
{
|
2023-12-07 16:20:51 -05:00
|
|
|
if (args.TargetSlots == SlotFlags.NONE)
|
|
|
|
|
return;
|
2023-12-06 00:01:31 -07:00
|
|
|
|
|
|
|
|
// this copies the by-ref event if it is a struct
|
2023-09-17 19:04:04 +10:00
|
|
|
var ev = new InventoryRelayedEvent<T>(args);
|
2023-12-07 16:20:51 -05:00
|
|
|
var enumerator = new InventorySlotEnumerator(inventory, args.TargetSlots);
|
|
|
|
|
while (enumerator.NextItem(out var item))
|
2023-09-17 19:04:04 +10:00
|
|
|
{
|
2023-12-07 16:20:51 -05:00
|
|
|
RaiseLocalEvent(item, ev);
|
2023-09-17 19:04:04 +10:00
|
|
|
}
|
2023-10-12 03:31:10 +11:00
|
|
|
|
|
|
|
|
// and now we copy it back
|
|
|
|
|
args = ev.Args;
|
2023-09-17 19:04:04 +10:00
|
|
|
}
|
|
|
|
|
|
2023-12-06 00:01:31 -07:00
|
|
|
public void RelayEvent<T>(Entity<InventoryComponent> inventory, T args) where T : IInventoryRelayEvent
|
2021-12-30 22:56:10 +01:00
|
|
|
{
|
2022-10-25 13:06:00 +13:00
|
|
|
if (args.TargetSlots == SlotFlags.NONE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var ev = new InventoryRelayedEvent<T>(args);
|
2023-12-07 16:20:51 -05:00
|
|
|
var enumerator = new InventorySlotEnumerator(inventory, args.TargetSlots);
|
|
|
|
|
while (enumerator.NextItem(out var item))
|
2021-12-30 22:56:10 +01:00
|
|
|
{
|
2023-12-07 16:20:51 -05:00
|
|
|
RaiseLocalEvent(item, ev);
|
2021-12-30 22:56:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-06 06:12:08 +13:00
|
|
|
|
2023-10-12 03:31:10 +11:00
|
|
|
private void OnGetEquipmentVerbs(EntityUid uid, InventoryComponent component, GetVerbsEvent<EquipmentVerb> args)
|
2023-03-06 06:12:08 +13:00
|
|
|
{
|
|
|
|
|
// Automatically relay stripping related verbs to all equipped clothing.
|
|
|
|
|
var ev = new InventoryRelayedEvent<GetVerbsEvent<EquipmentVerb>>(args);
|
2023-12-07 16:20:51 -05:00
|
|
|
var enumerator = new InventorySlotEnumerator(component);
|
|
|
|
|
while (enumerator.NextItem(out var item, out var slotDef))
|
2023-03-06 06:12:08 +13:00
|
|
|
{
|
2024-11-21 18:56:05 -08:00
|
|
|
if (!_strippable.IsStripHidden(slotDef, args.User) || args.User == uid)
|
2023-12-07 16:20:51 -05:00
|
|
|
RaiseLocalEvent(item, ev);
|
2023-03-06 06:12:08 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-30 19:27:08 -07:00
|
|
|
private void OnGetInnateVerbs(EntityUid uid, InventoryComponent component, GetVerbsEvent<InnateVerb> args)
|
|
|
|
|
{
|
|
|
|
|
// Automatically relay stripping related verbs to all equipped clothing.
|
|
|
|
|
var ev = new InventoryRelayedEvent<GetVerbsEvent<InnateVerb>>(args);
|
|
|
|
|
var enumerator = new InventorySlotEnumerator(component, SlotFlags.WITHOUT_POCKET);
|
|
|
|
|
while (enumerator.NextItem(out var item))
|
|
|
|
|
{
|
|
|
|
|
RaiseLocalEvent(item, ev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
}
|
2022-01-10 17:37:20 +13:00
|
|
|
|
2022-10-25 13:06:00 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Event wrapper for relayed events.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This avoids nested inventory relays, and makes it easy to have certain events only handled by the initial
|
|
|
|
|
/// target entity. E.g. health based movement speed modifiers should not be handled by a hat, even if that hat
|
|
|
|
|
/// happens to be a dead mouse. Clothing that wishes to modify movement speed must subscribe to
|
2023-01-19 03:56:45 +01:00
|
|
|
/// InventoryRelayedEvent<RefreshMovementSpeedModifiersEvent>
|
2022-10-25 13:06:00 +13:00
|
|
|
/// </remarks>
|
2023-09-17 19:04:04 +10:00
|
|
|
public sealed class InventoryRelayedEvent<TEvent> : EntityEventArgs
|
2022-10-25 13:06:00 +13:00
|
|
|
{
|
2023-10-12 03:31:10 +11:00
|
|
|
public TEvent Args;
|
2022-10-25 13:06:00 +13:00
|
|
|
|
|
|
|
|
public InventoryRelayedEvent(TEvent args)
|
|
|
|
|
{
|
|
|
|
|
Args = args;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 00:11:46 -07:00
|
|
|
public interface IClothingSlots
|
|
|
|
|
{
|
|
|
|
|
SlotFlags Slots { get; }
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 17:37:20 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Events that should be relayed to inventory slots should implement this interface.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface IInventoryRelayEvent
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// What inventory slots should this event be relayed to, if any?
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// In general you may want to exclude <see cref="SlotFlags.POCKET"/>, given that those items are not truly
|
|
|
|
|
/// "equipped" by the user.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public SlotFlags TargetSlots { get; }
|
|
|
|
|
}
|