diff --git a/Content.Server/Armor/ArmorSystem.cs b/Content.Server/Armor/ArmorSystem.cs index 2fd6ce532e..edef28b1f1 100644 --- a/Content.Server/Armor/ArmorSystem.cs +++ b/Content.Server/Armor/ArmorSystem.cs @@ -1,7 +1,8 @@ -using Content.Shared.Damage; +using Content.Shared.Damage; using Content.Server.Examine; using Content.Shared.Verbs; using Robust.Shared.Utility; +using Content.Shared.Inventory; namespace Content.Server.Armor { @@ -14,13 +15,13 @@ namespace Content.Server.Armor { base.Initialize(); - SubscribeLocalEvent(OnDamageModify); + SubscribeLocalEvent>(OnDamageModify); SubscribeLocalEvent>(OnArmorVerbExamine); } - private void OnDamageModify(EntityUid uid, ArmorComponent component, DamageModifyEvent args) + private void OnDamageModify(EntityUid uid, ArmorComponent component, InventoryRelayedEvent args) { - args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, component.Modifiers); + args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers); } private void OnArmorVerbExamine(EntityUid uid, ArmorComponent component, GetVerbsEvent args) diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs index 81f50dbd8f..21e45aef93 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs @@ -8,6 +8,7 @@ using Content.Shared.Damage; using Content.Shared.Database; using Content.Shared.Explosion; using Content.Shared.GameTicking; +using Content.Shared.Inventory; using Content.Shared.Throwing; using Robust.Server.Player; using Robust.Shared.Audio; @@ -63,6 +64,10 @@ public sealed partial class ExplosionSystem : EntitySystem SubscribeLocalEvent(OnGridRemoved); SubscribeLocalEvent(OnGridStartup); SubscribeLocalEvent(OnGetResistance); + + // as long as explosion-resistance mice are never added, this should be fine (otherwise a mouse-hat will transfer it's power to the wearer). + SubscribeLocalEvent>((e, c, ev) => OnGetResistance(e, c, ev.Args)); + SubscribeLocalEvent(OnTileChanged); SubscribeLocalEvent(OnReset); diff --git a/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs b/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs index 6288d8e826..80b6132e17 100644 --- a/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs +++ b/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs @@ -1,4 +1,5 @@ -using Content.Shared.Examine; +using Content.Shared.Examine; +using Content.Shared.Inventory; using Content.Shared.Movement.Systems; using Content.Shared.Verbs; using Robust.Shared.Containers; @@ -19,7 +20,7 @@ public sealed class ClothingSpeedModifierSystem : EntitySystem SubscribeLocalEvent(OnGetState); SubscribeLocalEvent(OnHandleState); - SubscribeLocalEvent(OnRefreshMoveSpeed); + SubscribeLocalEvent>(OnRefreshMoveSpeed); SubscribeLocalEvent>(OnClothingVerbExamine); } @@ -65,12 +66,12 @@ public sealed class ClothingSpeedModifierSystem : EntitySystem } } - private void OnRefreshMoveSpeed(EntityUid uid, ClothingSpeedModifierComponent component, RefreshMovementSpeedModifiersEvent args) + private void OnRefreshMoveSpeed(EntityUid uid, ClothingSpeedModifierComponent component, InventoryRelayedEvent args) { if (!component.Enabled) return; - args.ModifySpeed(component.WalkModifier, component.SprintModifier); + args.Args.ModifySpeed(component.WalkModifier, component.SprintModifier); } private void OnClothingVerbExamine(EntityUid uid, ClothingSpeedModifierComponent component, GetVerbsEvent args) diff --git a/Content.Shared/Clothing/SharedMagbootsSystem.cs b/Content.Shared/Clothing/SharedMagbootsSystem.cs index f0304a7f9c..d346308908 100644 --- a/Content.Shared/Clothing/SharedMagbootsSystem.cs +++ b/Content.Shared/Clothing/SharedMagbootsSystem.cs @@ -24,7 +24,7 @@ public abstract class SharedMagbootsSystem : EntitySystem base.Initialize(); SubscribeLocalEvent>(AddToggleVerb); - SubscribeLocalEvent(OnSlipAttempt); + SubscribeLocalEvent>(OnSlipAttempt); SubscribeLocalEvent(OnGetActions); SubscribeLocalEvent(OnToggleAction); } @@ -72,10 +72,10 @@ public abstract class SharedMagbootsSystem : EntitySystem args.Verbs.Add(verb); } - private void OnSlipAttempt(EntityUid uid, MagbootsComponent component, SlipAttemptEvent args) + private void OnSlipAttempt(EntityUid uid, MagbootsComponent component, InventoryRelayedEvent args) { if (component.On) - args.Cancel(); + args.Args.Cancel(); } private void OnGetActions(EntityUid uid, MagbootsComponent component, GetItemActionsEvent args) diff --git a/Content.Shared/Electrocution/SharedElectrocutionSystem.cs b/Content.Shared/Electrocution/SharedElectrocutionSystem.cs index 315b4c4078..f1a17ba9d3 100644 --- a/Content.Shared/Electrocution/SharedElectrocutionSystem.cs +++ b/Content.Shared/Electrocution/SharedElectrocutionSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.Inventory; using Robust.Shared.GameStates; namespace Content.Shared.Electrocution @@ -9,6 +10,8 @@ namespace Content.Shared.Electrocution base.Initialize(); SubscribeLocalEvent(OnInsulatedElectrocutionAttempt); + // as long as legally distinct electric-mice are never added, this should be fine (otherwise a mouse-hat will transfer it's power to the wearer). + SubscribeLocalEvent>((e, c, ev) => OnInsulatedElectrocutionAttempt(e, c, ev.Args)); SubscribeLocalEvent(OnInsulatedGetState); SubscribeLocalEvent(OnInsulatedHandleState); } diff --git a/Content.Shared/IdentityManagement/SharedIdentitySystem.cs b/Content.Shared/IdentityManagement/SharedIdentitySystem.cs index 54d50d0a5e..a671884089 100644 --- a/Content.Shared/IdentityManagement/SharedIdentitySystem.cs +++ b/Content.Shared/IdentityManagement/SharedIdentitySystem.cs @@ -1,4 +1,5 @@ -using Content.Shared.IdentityManagement.Components; +using Content.Shared.IdentityManagement.Components; +using Content.Shared.Inventory; using Robust.Shared.Containers; namespace Content.Shared.IdentityManagement; @@ -14,6 +15,7 @@ public abstract class SharedIdentitySystem : EntitySystem SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnSeeIdentity); + SubscribeLocalEvent>((e, c, ev) => OnSeeIdentity(e, c, ev.Args)); } private void OnSeeIdentity(EntityUid uid, IdentityBlockerComponent component, SeeIdentityAttemptEvent args) diff --git a/Content.Shared/Inventory/InventorySystem.Relay.cs b/Content.Shared/Inventory/InventorySystem.Relay.cs index bd38228e9c..c6bfd2fc41 100644 --- a/Content.Shared/Inventory/InventorySystem.Relay.cs +++ b/Content.Shared/Inventory/InventorySystem.Relay.cs @@ -23,15 +23,38 @@ public partial class InventorySystem protected void RelayInventoryEvent(EntityUid uid, InventoryComponent component, T args) where T : EntityEventArgs, IInventoryRelayEvent { + if (args.TargetSlots == SlotFlags.NONE) + return; + var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots); - while(containerEnumerator.MoveNext(out var container)) + var ev = new InventoryRelayedEvent(args); + while (containerEnumerator.MoveNext(out var container)) { - if(!container.ContainedEntity.HasValue) continue; - RaiseLocalEvent(container.ContainedEntity.Value, args, false); + if (!container.ContainedEntity.HasValue) continue; + RaiseLocalEvent(container.ContainedEntity.Value, ev, false); } } } +/// +/// Event wrapper for relayed events. +/// +/// +/// 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 +/// InventoryRelayedEvent +/// +public sealed class InventoryRelayedEvent : EntityEventArgs where TEvent : EntityEventArgs, IInventoryRelayEvent +{ + public readonly TEvent Args; + + public InventoryRelayedEvent(TEvent args) + { + Args = args; + } +} + /// /// Events that should be relayed to inventory slots should implement this interface. /// diff --git a/Content.Shared/Slippery/SlipperySystem.cs b/Content.Shared/Slippery/SlipperySystem.cs index aeac09f72c..0bf3274125 100644 --- a/Content.Shared/Slippery/SlipperySystem.cs +++ b/Content.Shared/Slippery/SlipperySystem.cs @@ -30,6 +30,8 @@ namespace Content.Shared.Slippery SubscribeLocalEvent(HandleAttemptCollide); SubscribeLocalEvent(HandleStepTrigger); SubscribeLocalEvent(OnNoSlipAttempt); + // as long as slip-resistant mice are never added, this should be fine (otherwise a mouse-hat will transfer it's power to the wearer). + SubscribeLocalEvent>((e, c, ev) => OnNoSlipAttempt(e, c, ev.Args)); SubscribeLocalEvent(OnSlipperyGetState); SubscribeLocalEvent(OnSlipperyHandleState); } diff --git a/Content.Shared/Strip/ThievingSystem.cs b/Content.Shared/Strip/ThievingSystem.cs index 9203833f29..51c5f381f6 100644 --- a/Content.Shared/Strip/ThievingSystem.cs +++ b/Content.Shared/Strip/ThievingSystem.cs @@ -11,6 +11,7 @@ public sealed class ThievingSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnBeforeStrip); + SubscribeLocalEvent>((e, c, ev) => OnBeforeStrip(e, c, ev.Args)); } private void OnBeforeStrip(EntityUid uid, ThievingComponent component, BeforeStripEvent args)