2023-08-02 03:57:22 +08:00
|
|
|
using Content.Shared.Chemistry;
|
2022-04-01 15:39:26 +13:00
|
|
|
using Content.Shared.Damage;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Electrocution;
|
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;
|
2022-07-10 18:36:53 -07:00
|
|
|
using Content.Shared.IdentityManagement.Components;
|
2023-08-01 23:17:03 +02:00
|
|
|
using Content.Shared.Inventory.Events;
|
2022-06-24 17:44:30 +10:00
|
|
|
using Content.Shared.Movement.Systems;
|
2023-08-01 23:17:03 +02:00
|
|
|
using Content.Shared.Overlays;
|
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;
|
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);
|
2023-03-06 06:12:08 +13:00
|
|
|
|
2023-10-12 03:31:10 +11:00
|
|
|
// by-ref events
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
|
|
|
|
|
|
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
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSecurityIconsComponent>>(RelayInventoryEvent);
|
2024-01-04 17:48:57 +01:00
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthBarsComponent>>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthIconsComponent>>(RelayInventoryEvent);
|
2023-09-23 15:14:06 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RelayInventoryEvent);
|
|
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RelayInventoryEvent);
|
2023-11-06 05:36:08 +03:00
|
|
|
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSyndicateIconsComponent>>(RelayInventoryEvent);
|
2023-08-01 23:17:03 +02:00
|
|
|
|
2023-10-12 03:31:10 +11:00
|
|
|
SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetEquipmentVerbs);
|
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
|
|
|
{
|
2023-12-07 16:20:51 -05:00
|
|
|
if (!slotDef.StripHidden || args.User == uid)
|
|
|
|
|
RaiseLocalEvent(item, ev);
|
2023-03-06 06:12:08 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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; }
|
|
|
|
|
}
|