From 2166958bd0c23b7b9fd5c699eaeee910d1db62bf Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Wed, 3 Jan 2024 17:24:02 +1100 Subject: [PATCH] AutoCompState + ItemToggle fixes (#23422) * AutoCompState + ItemToggle fixes Fix a lot of the comp states that are never actually networked and also cleaned up ItemToggle events a bunch. ItemToggle will still need some future work for lights and sounds. * Also catch these --- .../Tools/UI/WelderStatusControl.cs | 1 + .../Weapons/Reflect/ReflectSystem.cs | 7 - .../Interaction/InteractionTest.Helpers.cs | 1 + .../Systems/DamageOnToolInteractSystem.cs | 1 + .../EyeProtection/EyeProtectionSystem.cs | 5 +- .../Item/ItemToggle/ItemToggleSystem.cs | 6 +- .../EntitySystems/ExpendableLightSystem.cs | 6 +- .../Light/EntitySystems/MatchstickSystem.cs | 4 +- .../Stunnable/Systems/StunbatonSystem.cs | 7 +- Content.Server/Tools/ToolSystem.Welder.cs | 1 + .../Weapons/Reflect/ReflectSystem.cs | 20 -- .../Clothing/Components/LoadoutComponent.cs | 2 +- .../Clothing/SharedMagbootsSystem.cs | 2 +- .../ContainerHeld/ContainerHeldComponent.cs | 4 +- .../ContainerHeld/ContainerHeldSystem.cs | 6 +- Content.Shared/Item/ItemComponent.cs | 19 +- .../ItemToggleActiveSoundComponent.cs | 19 +- .../Components/ItemToggleComponent.cs | 55 ++---- .../Components/ItemToggleHotComponent.cs | 6 +- .../ItemToggleMeleeWeaponComponent.cs | 20 +- .../Components/ItemToggleSizeComponent.cs | 15 +- .../Item/ItemToggle/SharedItemToggleSystem.cs | 181 +++++++----------- Content.Shared/Item/SharedItemSystem.cs | 34 ++-- .../Ninja/Components/NinjaSuitComponent.cs | 2 +- .../Sericulture/SericultureComponent.cs | 2 +- .../Components/PortalComponent.cs | 2 +- .../Weapons/Melee/SharedMeleeWeaponSystem.cs | 6 +- ...haredReflectSystem.cs => ReflectSystem.cs} | 16 +- Content.Shared/Wieldable/WieldableSystem.cs | 4 +- 29 files changed, 160 insertions(+), 294 deletions(-) delete mode 100644 Content.Client/Weapons/Reflect/ReflectSystem.cs delete mode 100644 Content.Server/Weapons/Reflect/ReflectSystem.cs rename Content.Shared/Weapons/Reflect/{SharedReflectSystem.cs => ReflectSystem.cs} (96%) diff --git a/Content.Client/Tools/UI/WelderStatusControl.cs b/Content.Client/Tools/UI/WelderStatusControl.cs index 8da7a1448b..f1c5999453 100644 --- a/Content.Client/Tools/UI/WelderStatusControl.cs +++ b/Content.Client/Tools/UI/WelderStatusControl.cs @@ -5,6 +5,7 @@ using Content.Shared.Item; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.Timing; +using ItemToggleComponent = Content.Shared.Item.ItemToggle.Components.ItemToggleComponent; namespace Content.Client.Tools.UI; diff --git a/Content.Client/Weapons/Reflect/ReflectSystem.cs b/Content.Client/Weapons/Reflect/ReflectSystem.cs deleted file mode 100644 index 46f00a4d70..0000000000 --- a/Content.Client/Weapons/Reflect/ReflectSystem.cs +++ /dev/null @@ -1,7 +0,0 @@ -using Content.Shared.Weapons.Reflect; - -namespace Content.Client.Weapons.Reflect; - -public sealed class ReflectSystem : SharedReflectSystem -{ -} diff --git a/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs b/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs index 9aa0157c8a..42d58a88c9 100644 --- a/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs +++ b/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs @@ -23,6 +23,7 @@ using Robust.Shared.Input; using Robust.Shared.Map; using Robust.Shared.Map.Components; using Robust.Shared.Maths; +using ItemToggleComponent = Content.Shared.Item.ItemToggle.Components.ItemToggleComponent; namespace Content.IntegrationTests.Tests.Interaction; diff --git a/Content.Server/Damage/Systems/DamageOnToolInteractSystem.cs b/Content.Server/Damage/Systems/DamageOnToolInteractSystem.cs index c12c71a850..cac59f9b75 100644 --- a/Content.Server/Damage/Systems/DamageOnToolInteractSystem.cs +++ b/Content.Server/Damage/Systems/DamageOnToolInteractSystem.cs @@ -6,6 +6,7 @@ using Content.Shared.Damage; using Content.Shared.Database; using Content.Shared.Interaction; using Content.Shared.Tools.Components; +using ItemToggleComponent = Content.Shared.Item.ItemToggle.Components.ItemToggleComponent; namespace Content.Server.Damage.Systems { diff --git a/Content.Server/Eye/Blinding/EyeProtection/EyeProtectionSystem.cs b/Content.Server/Eye/Blinding/EyeProtection/EyeProtectionSystem.cs index 1b6a5bb930..74ce4dd000 100644 --- a/Content.Server/Eye/Blinding/EyeProtection/EyeProtectionSystem.cs +++ b/Content.Server/Eye/Blinding/EyeProtection/EyeProtectionSystem.cs @@ -5,6 +5,7 @@ using Content.Shared.Eye.Blinding.Components; using Content.Shared.Eye.Blinding.Systems; using Content.Shared.Tools.Components; using Content.Shared.Item.ItemToggle; +using Content.Shared.Item.ItemToggle.Components; namespace Content.Server.Eye.Blinding.EyeProtection { @@ -18,7 +19,7 @@ namespace Content.Server.Eye.Blinding.EyeProtection { base.Initialize(); SubscribeLocalEvent(OnUseAttempt); - SubscribeLocalEvent(OnWelderToggled); + SubscribeLocalEvent(OnWelderToggled); SubscribeLocalEvent(OnGetProtection); SubscribeLocalEvent>(OnGetRelayedProtection); @@ -57,7 +58,7 @@ namespace Content.Server.Eye.Blinding.EyeProtection _statusEffectsSystem.TryAddStatusEffect(args.User, TemporaryBlindnessSystem.BlindingStatusEffect, statusTimeSpan, false, TemporaryBlindnessSystem.BlindingStatusEffect); } - private void OnWelderToggled(EntityUid uid, RequiresEyeProtectionComponent component, ItemToggleDoneEvent args) + private void OnWelderToggled(EntityUid uid, RequiresEyeProtectionComponent component, ItemToggledEvent args) { component.Toggled = _itemToggle.IsActivated(uid); } diff --git a/Content.Server/Item/ItemToggle/ItemToggleSystem.cs b/Content.Server/Item/ItemToggle/ItemToggleSystem.cs index 8a6903dd49..4507ace9d2 100644 --- a/Content.Server/Item/ItemToggle/ItemToggleSystem.cs +++ b/Content.Server/Item/ItemToggle/ItemToggleSystem.cs @@ -2,6 +2,8 @@ using Content.Shared.Item; using Content.Server.CombatMode.Disarm; using Content.Server.Kitchen.Components; using Content.Shared.Item.ItemToggle; +using Content.Shared.Item.ItemToggle.Components; +using ItemToggleComponent = Content.Shared.Item.ItemToggle.Components.ItemToggleComponent; namespace Content.Server.Item; @@ -11,10 +13,10 @@ public sealed class ItemToggleSystem : SharedItemToggleSystem { base.Initialize(); - SubscribeLocalEvent(Toggle); + SubscribeLocalEvent(Toggle); } - private void Toggle(EntityUid uid, ItemToggleComponent comp, ref ItemToggleDoneEvent args) + private void Toggle(EntityUid uid, ItemToggleComponent comp, ref ItemToggledEvent args) { if (args.Activated == true) { diff --git a/Content.Server/Light/EntitySystems/ExpendableLightSystem.cs b/Content.Server/Light/EntitySystems/ExpendableLightSystem.cs index 40d212c6ad..0bbdf88d3c 100644 --- a/Content.Server/Light/EntitySystems/ExpendableLightSystem.cs +++ b/Content.Server/Light/EntitySystems/ExpendableLightSystem.cs @@ -78,7 +78,7 @@ namespace Content.Server.Light.EntitySystems if (TryComp(ent, out var item)) { - _item.SetHeldPrefix(ent, "unlit", item); + _item.SetHeldPrefix(ent, "unlit", component: item); } break; @@ -96,7 +96,7 @@ namespace Content.Server.Light.EntitySystems { if (TryComp(ent, out var item)) { - _item.SetHeldPrefix(ent, "lit", item); + _item.SetHeldPrefix(ent, "lit", component: item); } component.CurrentState = ExpendableLightState.Lit; @@ -163,7 +163,7 @@ namespace Content.Server.Light.EntitySystems { if (TryComp(uid, out var item)) { - _item.SetHeldPrefix(uid, "unlit", item); + _item.SetHeldPrefix(uid, "unlit", component: item); } component.CurrentState = ExpendableLightState.BrandNew; diff --git a/Content.Server/Light/EntitySystems/MatchstickSystem.cs b/Content.Server/Light/EntitySystems/MatchstickSystem.cs index 2195c69b18..96e4695784 100644 --- a/Content.Server/Light/EntitySystems/MatchstickSystem.cs +++ b/Content.Server/Light/EntitySystems/MatchstickSystem.cs @@ -107,10 +107,10 @@ namespace Content.Server.Light.EntitySystems switch (component.CurrentState) { case SmokableState.Lit: - _item.SetHeldPrefix(uid, "lit", item); + _item.SetHeldPrefix(uid, "lit", component: item); break; default: - _item.SetHeldPrefix(uid, "unlit", item); + _item.SetHeldPrefix(uid, "unlit", component: item); break; } } diff --git a/Content.Server/Stunnable/Systems/StunbatonSystem.cs b/Content.Server/Stunnable/Systems/StunbatonSystem.cs index 8064434031..436559e43b 100644 --- a/Content.Server/Stunnable/Systems/StunbatonSystem.cs +++ b/Content.Server/Stunnable/Systems/StunbatonSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Damage.Events; using Content.Shared.Examine; using Content.Shared.Item; using Content.Shared.Item.ItemToggle; +using Content.Shared.Item.ItemToggle.Components; using Content.Shared.Popups; using Content.Shared.Stunnable; @@ -28,7 +29,7 @@ namespace Content.Server.Stunnable.Systems SubscribeLocalEvent(OnSolutionChange); SubscribeLocalEvent(OnStaminaHitAttempt); SubscribeLocalEvent(TryTurnOn); - SubscribeLocalEvent(ToggleDone); + SubscribeLocalEvent(ToggleDone); } private void OnStaminaHitAttempt(Entity entity, ref StaminaDamageOnHitAttemptEvent args) @@ -58,12 +59,12 @@ namespace Content.Server.Stunnable.Systems args.PushMarkup(chargeMessage); } - private void ToggleDone(Entity entity, ref ItemToggleDoneEvent args) + private void ToggleDone(Entity entity, ref ItemToggledEvent args) { if (!TryComp(entity, out var item)) return; - _item.SetHeldPrefix(entity.Owner, args.Activated ? "on" : "off", item); + _item.SetHeldPrefix(entity.Owner, args.Activated ? "on" : "off", component: item); } private void TryTurnOn(Entity entity, ref ItemToggleActivateAttemptEvent args) diff --git a/Content.Server/Tools/ToolSystem.Welder.cs b/Content.Server/Tools/ToolSystem.Welder.cs index 88037cedb4..510dd3bfe0 100644 --- a/Content.Server/Tools/ToolSystem.Welder.cs +++ b/Content.Server/Tools/ToolSystem.Welder.cs @@ -12,6 +12,7 @@ using Content.Shared.Item.ItemToggle; using Content.Shared.Tools.Components; using Robust.Shared.GameStates; using System.Linq; +using Content.Shared.Item.ItemToggle.Components; namespace Content.Server.Tools { diff --git a/Content.Server/Weapons/Reflect/ReflectSystem.cs b/Content.Server/Weapons/Reflect/ReflectSystem.cs deleted file mode 100644 index 5c1939478e..0000000000 --- a/Content.Server/Weapons/Reflect/ReflectSystem.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Content.Shared.Item; -using Content.Shared.Weapons.Reflect; - -namespace Content.Server.Weapons.Reflect; - -public sealed class ReflectSystem : SharedReflectSystem -{ - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent(ToggleReflect); - } - - private void ToggleReflect(EntityUid uid, ReflectComponent comp, ref ItemToggleReflectUpdateEvent args) - { - comp.Enabled = args.Activated; - Dirty(uid, comp); - } -} diff --git a/Content.Shared/Clothing/Components/LoadoutComponent.cs b/Content.Shared/Clothing/Components/LoadoutComponent.cs index e4a02760d3..a3c6efe2a0 100644 --- a/Content.Shared/Clothing/Components/LoadoutComponent.cs +++ b/Content.Shared/Clothing/Components/LoadoutComponent.cs @@ -4,7 +4,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy namespace Content.Shared.Clothing.Components; -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class LoadoutComponent : Component { /// diff --git a/Content.Shared/Clothing/SharedMagbootsSystem.cs b/Content.Shared/Clothing/SharedMagbootsSystem.cs index 7a6da7c992..27fb0c1a50 100644 --- a/Content.Shared/Clothing/SharedMagbootsSystem.cs +++ b/Content.Shared/Clothing/SharedMagbootsSystem.cs @@ -57,7 +57,7 @@ public abstract class SharedMagbootsSystem : EntitySystem if (TryComp(uid, out var item)) { - _item.SetHeldPrefix(uid, magboots.On ? "on" : null, item); + _item.SetHeldPrefix(uid, magboots.On ? "on" : null, component: item); _clothing.SetEquippedPrefix(uid, magboots.On ? "on" : null); } diff --git a/Content.Shared/ContainerHeld/ContainerHeldComponent.cs b/Content.Shared/ContainerHeld/ContainerHeldComponent.cs index cc6d2bf872..3d7643b42c 100644 --- a/Content.Shared/ContainerHeld/ContainerHeldComponent.cs +++ b/Content.Shared/ContainerHeld/ContainerHeldComponent.cs @@ -1,6 +1,8 @@ +using Robust.Shared.GameStates; + namespace Content.Shared.ContainerHeld; -[RegisterComponent] +[RegisterComponent, NetworkedComponent] public sealed partial class ContainerHeldComponent: Component { /// diff --git a/Content.Shared/ContainerHeld/ContainerHeldSystem.cs b/Content.Shared/ContainerHeld/ContainerHeldSystem.cs index db8ad5e5e1..f2ce5b44a5 100644 --- a/Content.Shared/ContainerHeld/ContainerHeldSystem.cs +++ b/Content.Shared/ContainerHeld/ContainerHeldSystem.cs @@ -23,7 +23,7 @@ public sealed class ContainerHeldSystem : EntitySystem private void OnContainerModified(EntityUid uid, ContainerHeldComponent comp, ContainerModifiedMessage args) { - if (!(TryComp(uid, out var storage) + if (!(HasComp(uid) && TryComp(uid, out var appearance) && TryComp(uid, out var item))) { @@ -31,12 +31,12 @@ public sealed class ContainerHeldSystem : EntitySystem } if (_storage.GetCumulativeItemAreas(uid) >= comp.Threshold) { - _item.SetHeldPrefix(uid, "full", item); + _item.SetHeldPrefix(uid, "full", component: item); _appearance.SetData(uid, ToggleVisuals.Toggled, true, appearance); } else { - _item.SetHeldPrefix(uid, "empty", item); + _item.SetHeldPrefix(uid, "empty", component: item); _appearance.SetData(uid, ToggleVisuals.Toggled, false, appearance); } } diff --git a/Content.Shared/Item/ItemComponent.cs b/Content.Shared/Item/ItemComponent.cs index 1cb51b6ea0..1ef6592b08 100644 --- a/Content.Shared/Item/ItemComponent.cs +++ b/Content.Shared/Item/ItemComponent.cs @@ -12,10 +12,10 @@ namespace Content.Shared.Item; /// [RegisterComponent] [NetworkedComponent] -[Access(typeof(SharedItemSystem))] +[Access(typeof(SharedItemSystem)), AutoGenerateComponentState(true)] public sealed partial class ItemComponent : Component { - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] [Access(typeof(SharedItemSystem))] public ProtoId Size = "Small"; @@ -25,7 +25,7 @@ public sealed partial class ItemComponent : Component [Access(typeof(SharedItemSystem))] [ViewVariables(VVAccess.ReadWrite)] - [DataField] + [DataField, AutoNetworkedField] public string? HeldPrefix; /// @@ -56,19 +56,6 @@ public sealed partial class ItemComponent : Component public float StoredRotation = 0; } -[Serializable, NetSerializable] -public sealed class ItemComponentState : ComponentState -{ - public ProtoId Size { get; } - public string? HeldPrefix { get; } - - public ItemComponentState(ProtoId size, string? heldPrefix) - { - Size = size; - HeldPrefix = heldPrefix; - } -} - /// /// Raised when an item's visual state is changed. The event is directed at the entity that contains this item, so /// that it can properly update its hands or inventory sprites and GUI. diff --git a/Content.Shared/Item/ItemToggle/Components/ItemToggleActiveSoundComponent.cs b/Content.Shared/Item/ItemToggle/Components/ItemToggleActiveSoundComponent.cs index eb992975b3..6d53471357 100644 --- a/Content.Shared/Item/ItemToggle/Components/ItemToggleActiveSoundComponent.cs +++ b/Content.Shared/Item/ItemToggle/Components/ItemToggleActiveSoundComponent.cs @@ -1,16 +1,16 @@ using Robust.Shared.Audio; using Robust.Shared.GameStates; -namespace Content.Shared.Item; +namespace Content.Shared.Item.ItemToggle.Components; /// /// Handles the active sound being played continuously with some items that are activated (ie e-sword hum). /// -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class ItemToggleActiveSoundComponent : Component { /// - /// The continuous noise this item makes when it's activated (like an e-sword's hum). This loops. + /// The continuous noise this item makes when it's activated (like an e-sword's hum). /// [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] public SoundSpecifier? ActiveSound; @@ -18,17 +18,6 @@ public sealed partial class ItemToggleActiveSoundComponent : Component /// /// Used when the item emits sound while active. /// - [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] + [ViewVariables(VVAccess.ReadWrite), DataField] public EntityUid? PlayingStream; } - -/// -/// Raised in order to effect changes upon the ActiveSound of the entity. -/// -[ByRefEvent] -public record struct ItemToggleActiveSoundUpdateEvent(bool Activated, bool Predicted, EntityUid? User) -{ - public bool Activated = Activated; - public bool Predicted = Predicted; - public EntityUid? User = User; -} diff --git a/Content.Shared/Item/ItemToggle/Components/ItemToggleComponent.cs b/Content.Shared/Item/ItemToggle/Components/ItemToggleComponent.cs index 6d27d9ee12..3ea80ec735 100644 --- a/Content.Shared/Item/ItemToggle/Components/ItemToggleComponent.cs +++ b/Content.Shared/Item/ItemToggle/Components/ItemToggleComponent.cs @@ -1,7 +1,7 @@ using Robust.Shared.Audio; using Robust.Shared.GameStates; -namespace Content.Shared.Item; +namespace Content.Shared.Item.ItemToggle.Components; /// /// Handles generic item toggles, like a welder turning on and off, or an e-sword. @@ -54,7 +54,7 @@ public sealed partial class ItemToggleComponent : Component public record struct ItemToggleActivateAttemptEvent(EntityUid? User) { public bool Cancelled = false; - public EntityUid? User = User; + public readonly EntityUid? User = User; } /// @@ -64,63 +64,34 @@ public record struct ItemToggleActivateAttemptEvent(EntityUid? User) public record struct ItemToggleDeactivateAttemptEvent(EntityUid? User) { public bool Cancelled = false; - public EntityUid? User = User; + public readonly EntityUid? User = User; } /// /// Raised directed on an entity any sort of toggle is complete. /// [ByRefEvent] -public record struct ItemToggleDoneEvent(bool Activated, EntityUid? User) +public readonly record struct ItemToggledEvent(bool Predicted, bool Activated, EntityUid? User) { - public bool Activated = Activated; - public EntityUid? User = User; + public readonly bool Predicted = Predicted; + public readonly bool Activated = Activated; + public readonly EntityUid? User = User; } /// -/// Raised in order to play a toggle sound effect. +/// Raised directed on an entity when an itemtoggle is activated. /// [ByRefEvent] -public record struct ItemTogglePlayToggleSoundEvent(bool Activated, bool Predicted, EntityUid? User) +public readonly record struct ItemToggleActivatedEvent(EntityUid? User) { - public bool Activated = Activated; - public bool Predicted = Predicted; - public EntityUid? User = User; + public readonly EntityUid? User = User; } /// -/// Raised in order to play a failure to toggle sound effect. +/// Raised directed on an entity when an itemtoggle is deactivated. /// [ByRefEvent] -public record struct ItemTogglePlayFailSoundEvent(bool Predicted, EntityUid? User) +public readonly record struct ItemToggleDeactivatedEvent(EntityUid? User) { - public bool Predicted = Predicted; - public EntityUid? User = User; -} - -/// -/// Raised in order to effect changes upon the Light component of the entity. -/// -[ByRefEvent] -public record struct ItemToggleLightUpdateEvent(bool Activated) -{ - public bool Activated = Activated; -} - -/// -/// Raised in order to effect changes upon the Appearance component of the entity. -/// -[ByRefEvent] -public record struct ItemToggleAppearanceUpdateEvent(bool Activated) -{ - public bool Activated = Activated; -} - -/// -/// Raised in order to effect changes upon the Reflect component of the entity. -/// -[ByRefEvent] -public record struct ItemToggleReflectUpdateEvent(bool Activated) -{ - public bool Activated = Activated; + public readonly EntityUid? User = User; } diff --git a/Content.Shared/Item/ItemToggle/Components/ItemToggleHotComponent.cs b/Content.Shared/Item/ItemToggle/Components/ItemToggleHotComponent.cs index b35adfadac..c3eb1d1e58 100644 --- a/Content.Shared/Item/ItemToggle/Components/ItemToggleHotComponent.cs +++ b/Content.Shared/Item/ItemToggle/Components/ItemToggleHotComponent.cs @@ -1,11 +1,11 @@ using Robust.Shared.GameStates; -namespace Content.Shared.Item; +namespace Content.Shared.Item.ItemToggle.Components; /// -/// Handles whether the item is hot when toggled on. +/// Handles whether the item is hot when toggled on. /// -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class ItemToggleHotComponent : Component { /// diff --git a/Content.Shared/Item/ItemToggle/Components/ItemToggleMeleeWeaponComponent.cs b/Content.Shared/Item/ItemToggle/Components/ItemToggleMeleeWeaponComponent.cs index 5e57491af0..a51e90be60 100644 --- a/Content.Shared/Item/ItemToggle/Components/ItemToggleMeleeWeaponComponent.cs +++ b/Content.Shared/Item/ItemToggle/Components/ItemToggleMeleeWeaponComponent.cs @@ -1,16 +1,16 @@ -using Robust.Shared.GameStates; -using Robust.Shared.Audio; using Content.Shared.Damage; +using Robust.Shared.Audio; +using Robust.Shared.GameStates; -namespace Content.Shared.Item; +namespace Content.Shared.Item.ItemToggle.Components; /// -/// Handles the changes to the melee weapon component when the item is toggled. +/// Handles the changes to the melee weapon component when the item is toggled. /// /// /// You can change the damage, sound on hit, on swing, as well as hidden status while activated. /// -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class ItemToggleMeleeWeaponComponent : Component { /// @@ -67,13 +67,3 @@ public sealed partial class ItemToggleMeleeWeaponComponent : Component [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] public bool DeactivatedSecret = false; } - -/// -/// Raised in order to effect changes upon the MeleeWeaponComponent of the entity. -/// -[ByRefEvent] -public record struct ItemToggleMeleeWeaponUpdateEvent(bool Activated) -{ - public bool Activated = Activated; -} - diff --git a/Content.Shared/Item/ItemToggle/Components/ItemToggleSizeComponent.cs b/Content.Shared/Item/ItemToggle/Components/ItemToggleSizeComponent.cs index f280934f1b..353f3d6fd5 100644 --- a/Content.Shared/Item/ItemToggle/Components/ItemToggleSizeComponent.cs +++ b/Content.Shared/Item/ItemToggle/Components/ItemToggleSizeComponent.cs @@ -1,15 +1,15 @@ using Robust.Shared.GameStates; using Robust.Shared.Prototypes; -namespace Content.Shared.Item; +namespace Content.Shared.Item.ItemToggle.Components; /// -/// Handles the changes to the item size when toggled. +/// Handles the changes to the item size when toggled. /// /// /// You can change the size when activated or not. By default the sizes are copied from the item. /// -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class ItemToggleSizeComponent : Component { /// @@ -24,12 +24,3 @@ public sealed partial class ItemToggleSizeComponent : Component [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] public ProtoId? DeactivatedSize = null; } - -/// -/// Raised in order to effect changes upon the MeleeWeaponComponent of the entity. -/// -[ByRefEvent] -public record struct ItemToggleSizeUpdateEvent(bool Activated) -{ - public bool Activated = Activated; -} diff --git a/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs b/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs index e44d135bf2..c502f845dd 100644 --- a/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs +++ b/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs @@ -1,11 +1,10 @@ using Content.Shared.Interaction.Events; -using Content.Shared.Toggleable; +using Content.Shared.Item.ItemToggle.Components; using Content.Shared.Temperature; +using Content.Shared.Toggleable; using Content.Shared.Wieldable; -using Content.Shared.Wieldable.Components; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; -using Robust.Shared.Prototypes; using Robust.Shared.Network; namespace Content.Shared.Item.ItemToggle; @@ -29,12 +28,10 @@ public abstract class SharedItemToggleSystem : EntitySystem SubscribeLocalEvent(TurnOffonUnwielded); SubscribeLocalEvent(TurnOnonWielded); SubscribeLocalEvent(OnUseInHand); + SubscribeLocalEvent(OnIsHotEvent); - SubscribeLocalEvent(UpdateActiveSound); - SubscribeLocalEvent(UpdateAppearance); - SubscribeLocalEvent(UpdateLight); - SubscribeLocalEvent(PlayToggleSound); - SubscribeLocalEvent(PlayFailToggleSound); + + SubscribeLocalEvent(UpdateActiveSound); } private void OnUseInHand(EntityUid uid, ItemToggleComponent itemToggle, UseInHandEvent args) @@ -48,7 +45,7 @@ public abstract class SharedItemToggleSystem : EntitySystem } /// - /// Used when an item is attempted to be toggled. + /// Used when an item is attempted to be toggled. /// public void Toggle(EntityUid uid, EntityUid? user = null, bool predicted = true, ItemToggleComponent? itemToggle = null) { @@ -81,9 +78,10 @@ public abstract class SharedItemToggleSystem : EntitySystem if (attempt.Cancelled) { - //Raises the event to play the failure to activate noise. - var evPlayFailToggleSound = new ItemTogglePlayFailSoundEvent(Predicted: predicted, user); - RaiseLocalEvent(uid, ref evPlayFailToggleSound); + if (predicted) + _audio.PlayPredicted(itemToggle.SoundFailToActivate, uid, user); + else + _audio.PlayPvs(itemToggle.SoundFailToActivate, uid); return false; } @@ -92,16 +90,7 @@ public abstract class SharedItemToggleSystem : EntitySystem if (predicted == false && _netManager.IsClient) return true; - Activate(uid, itemToggle); - - var evPlayToggleSound = new ItemTogglePlayToggleSoundEvent(Activated: true, Predicted: predicted, user); - RaiseLocalEvent(uid, ref evPlayToggleSound); - - var evActiveSound = new ItemToggleActiveSoundUpdateEvent(Activated: true, Predicted: predicted, user); - RaiseLocalEvent(uid, ref evActiveSound); - - var toggleUsed = new ItemToggleDoneEvent(Activated: true, user); - RaiseLocalEvent(uid, ref toggleUsed); + Activate(uid, itemToggle, predicted, user); return true; } @@ -129,61 +118,78 @@ public abstract class SharedItemToggleSystem : EntitySystem if (predicted == false && _netManager.IsClient) return true; - Deactivate(uid, itemToggle); - - var evPlayToggleSound = new ItemTogglePlayToggleSoundEvent(Activated: false, Predicted: predicted, user); - RaiseLocalEvent(uid, ref evPlayToggleSound); - - var evActiveSound = new ItemToggleActiveSoundUpdateEvent(Activated: false, Predicted: predicted, user); - RaiseLocalEvent(uid, ref evActiveSound); - - var toggleUsed = new ItemToggleDoneEvent(Activated: false, user); - RaiseLocalEvent(uid, ref toggleUsed); - + Deactivate(uid, itemToggle, predicted, user); return true; } - /// - /// Used to make the actual changes to the item's components on activation. - /// - private void Activate(EntityUid uid, ItemToggleComponent itemToggle) + private void Activate(EntityUid uid, ItemToggleComponent itemToggle, bool predicted, EntityUid? user = null) { - UpdateComponents(uid, itemToggle.Activated = true); + // TODO: Fix this hardcoding + TryComp(uid, out AppearanceComponent? appearance); + _appearance.SetData(uid, ToggleableLightVisuals.Enabled, true, appearance); + _appearance.SetData(uid, ToggleVisuals.Toggled, true, appearance); + if (_light.TryGetLight(uid, out var light)) + { + _light.SetEnabled(uid, true, light); + } + + SoundSpecifier? soundToPlay = itemToggle.SoundActivate; + + if (soundToPlay == null) + return; + + if (predicted) + _audio.PlayPredicted(soundToPlay, uid, user); + else + _audio.PlayPvs(soundToPlay, uid); + + // END FIX HARDCODING + + var toggleUsed = new ItemToggledEvent(predicted, Activated: true, user); + RaiseLocalEvent(uid, ref toggleUsed); + + var activev = new ItemToggleActivatedEvent(user); + RaiseLocalEvent(uid, ref activev); + + itemToggle.Activated = true; Dirty(uid, itemToggle); } /// /// Used to make the actual changes to the item's components on deactivation. /// - private void Deactivate(EntityUid uid, ItemToggleComponent itemToggle) + private void Deactivate(EntityUid uid, ItemToggleComponent itemToggle, bool predicted, EntityUid? user = null) { - UpdateComponents(uid, itemToggle.Activated = false); + // TODO: Fix this hardcoding + TryComp(uid, out AppearanceComponent? appearance); + _appearance.SetData(uid, ToggleableLightVisuals.Enabled, false, appearance); + _appearance.SetData(uid, ToggleVisuals.Toggled, false, appearance); + if (_light.TryGetLight(uid, out var light)) + { + _light.SetEnabled(uid, false, light); + } + + var soundToPlay = itemToggle.SoundDeactivate; + + if (predicted) + _audio.PlayPredicted(soundToPlay, uid, user); + else + _audio.PlayPvs(soundToPlay, uid); + + // END FIX HARDCODING + + var toggleUsed = new ItemToggledEvent(predicted, Activated: false, user); + RaiseLocalEvent(uid, ref toggleUsed); + + var activev = new ItemToggleDeactivatedEvent(user); + RaiseLocalEvent(uid, ref activev); + + itemToggle.Activated = false; Dirty(uid, itemToggle); } - /// - /// Used to raise events to update components on toggle. - /// - private void UpdateComponents(EntityUid uid, bool activated) - { - var evSize = new ItemToggleSizeUpdateEvent(activated); - RaiseLocalEvent(uid, ref evSize); - - var evMelee = new ItemToggleMeleeWeaponUpdateEvent(activated); - RaiseLocalEvent(uid, ref evMelee); - - var evAppearance = new ItemToggleAppearanceUpdateEvent(activated); - RaiseLocalEvent(uid, ref evAppearance); - - var evLight = new ItemToggleLightUpdateEvent(activated); - RaiseLocalEvent(uid, ref evLight); - - var evReflect = new ItemToggleReflectUpdateEvent(activated); - RaiseLocalEvent(uid, ref evReflect); - } - /// /// Used for items that require to be wielded in both hands to activate. For instance the dual energy sword will turn off if not wielded. /// @@ -219,30 +225,10 @@ public abstract class SharedItemToggleSystem : EntitySystem args.IsHot = IsActivated(uid); } - /// - /// Used to update item appearance. - /// - private void UpdateAppearance(EntityUid uid, AppearanceComponent appearance, ref ItemToggleAppearanceUpdateEvent args) - { - _appearance.SetData(uid, ToggleableLightVisuals.Enabled, args.Activated, appearance); - _appearance.SetData(uid, ToggleVisuals.Toggled, args.Activated, appearance); - } - - /// - /// Used to update light settings. - /// - private void UpdateLight(EntityUid uid, ItemToggleComponent comp, ref ItemToggleLightUpdateEvent args) - { - if (!_light.TryGetLight(uid, out var light)) - return; - - _light.SetEnabled(uid, args.Activated, light); - } - /// /// Used to update the looping active sound linked to the entity. /// - private void UpdateActiveSound(EntityUid uid, ItemToggleActiveSoundComponent activeSound, ref ItemToggleActiveSoundUpdateEvent args) + private void UpdateActiveSound(EntityUid uid, ItemToggleActiveSoundComponent activeSound, ref ItemToggledEvent args) { if (args.Activated) { @@ -259,35 +245,4 @@ public abstract class SharedItemToggleSystem : EntitySystem activeSound.PlayingStream = _audio.Stop(activeSound.PlayingStream); } } - - /// - /// Used to play a toggle sound. - /// - private void PlayToggleSound(EntityUid uid, ItemToggleComponent itemToggle, ref ItemTogglePlayToggleSoundEvent args) - { - SoundSpecifier? soundToPlay; - if (args.Activated) - soundToPlay = itemToggle.SoundActivate; - else - soundToPlay = itemToggle.SoundDeactivate; - - if (soundToPlay == null) - return; - - if (args.Predicted) - _audio.PlayPredicted(soundToPlay, uid, args.User); - else - _audio.PlayPvs(soundToPlay, uid); - } - - /// - /// Used to play a failure to toggle sound. - /// - private void PlayFailToggleSound(EntityUid uid, ItemToggleComponent itemToggle, ref ItemTogglePlayFailSoundEvent args) - { - if (args.Predicted) - _audio.PlayPredicted(itemToggle.SoundFailToActivate, uid, args.User); - else - _audio.PlayPvs(itemToggle.SoundFailToActivate, uid); - } } diff --git a/Content.Shared/Item/SharedItemSystem.cs b/Content.Shared/Item/SharedItemSystem.cs index fe925c5547..13b98d8533 100644 --- a/Content.Shared/Item/SharedItemSystem.cs +++ b/Content.Shared/Item/SharedItemSystem.cs @@ -2,6 +2,7 @@ using Content.Shared.Hands.EntitySystems; using Content.Shared.Interaction; using Content.Shared.Verbs; using Content.Shared.Examine; +using Content.Shared.Item.ItemToggle.Components; using Content.Shared.Storage; using JetBrains.Annotations; using Robust.Shared.Containers; @@ -21,14 +22,17 @@ public abstract class SharedItemSystem : EntitySystem { base.Initialize(); SubscribeLocalEvent>(AddPickupVerb); - SubscribeLocalEvent(OnHandInteract, before: new []{typeof(SharedItemSystem)}); - - SubscribeLocalEvent(OnGetState); - SubscribeLocalEvent(OnHandleState); + SubscribeLocalEvent(OnHandInteract); + SubscribeLocalEvent(OnItemAutoState); SubscribeLocalEvent(OnExamine); - SubscribeLocalEvent(OnItemToggle); + SubscribeLocalEvent(OnItemToggle); + } + + private void OnItemAutoState(EntityUid uid, ItemComponent component, ref AfterAutoHandleStateEvent args) + { + SetHeldPrefix(uid, component.HeldPrefix, force: true, component); } #region Public API @@ -42,12 +46,12 @@ public abstract class SharedItemSystem : EntitySystem Dirty(uid, component); } - public void SetHeldPrefix(EntityUid uid, string? heldPrefix, ItemComponent? component = null) + public void SetHeldPrefix(EntityUid uid, string? heldPrefix, bool force = false, ItemComponent? component = null) { if (!Resolve(uid, ref component, false)) return; - if (component.HeldPrefix == heldPrefix) + if (!force && component.HeldPrefix == heldPrefix) return; component.HeldPrefix = heldPrefix; @@ -81,20 +85,6 @@ public abstract class SharedItemSystem : EntitySystem args.Handled = _handsSystem.TryPickup(args.User, uid, animateUser: false); } - private void OnHandleState(EntityUid uid, ItemComponent component, ref ComponentHandleState args) - { - if (args.Current is not ItemComponentState state) - return; - - component.Size = state.Size; - SetHeldPrefix(uid, state.HeldPrefix, component); - } - - private void OnGetState(EntityUid uid, ItemComponent component, ref ComponentGetState args) - { - args.State = new ItemComponentState(component.Size, component.HeldPrefix); - } - private void AddPickupVerb(EntityUid uid, ItemComponent component, GetVerbsEvent args) { if (args.Hands == null || @@ -211,7 +201,7 @@ public abstract class SharedItemSystem : EntitySystem /// /// Used to update the Item component on item toggle (specifically size). /// - private void OnItemToggle(EntityUid uid, ItemToggleSizeComponent itemToggleSize, ItemToggleSizeUpdateEvent args) + private void OnItemToggle(EntityUid uid, ItemToggleSizeComponent itemToggleSize, ItemToggledEvent args) { if (!TryComp(uid, out ItemComponent? item)) return; diff --git a/Content.Shared/Ninja/Components/NinjaSuitComponent.cs b/Content.Shared/Ninja/Components/NinjaSuitComponent.cs index 73de252690..381728ae28 100644 --- a/Content.Shared/Ninja/Components/NinjaSuitComponent.cs +++ b/Content.Shared/Ninja/Components/NinjaSuitComponent.cs @@ -13,7 +13,7 @@ namespace Content.Shared.Ninja.Components; /// Component for ninja suit abilities and power consumption. /// As an implementation detail, dashing with katana is a suit action which isn't ideal. /// -[RegisterComponent, NetworkedComponent, Access(typeof(SharedNinjaSuitSystem))] +[RegisterComponent, NetworkedComponent, Access(typeof(SharedNinjaSuitSystem)), AutoGenerateComponentState] public sealed partial class NinjaSuitComponent : Component { /// diff --git a/Content.Shared/Sericulture/SericultureComponent.cs b/Content.Shared/Sericulture/SericultureComponent.cs index c98a2171b0..e0cc2b7d91 100644 --- a/Content.Shared/Sericulture/SericultureComponent.cs +++ b/Content.Shared/Sericulture/SericultureComponent.cs @@ -9,7 +9,7 @@ namespace Content.Shared.Sericulture; /// Should be applied to any mob that you want to be able to produce any material with an action and the cost of hunger. /// TODO: Probably adjust this to utilize organs? /// -[RegisterComponent, NetworkedComponent, Access(typeof(SharedSericultureSystem))] +[RegisterComponent, NetworkedComponent, Access(typeof(SharedSericultureSystem)), AutoGenerateComponentState] public sealed partial class SericultureComponent : Component { /// diff --git a/Content.Shared/Teleportation/Components/PortalComponent.cs b/Content.Shared/Teleportation/Components/PortalComponent.cs index 42fe8e5b70..1e2c2e6428 100644 --- a/Content.Shared/Teleportation/Components/PortalComponent.cs +++ b/Content.Shared/Teleportation/Components/PortalComponent.cs @@ -7,7 +7,7 @@ namespace Content.Shared.Teleportation.Components; /// Marks an entity as being a 'portal' which teleports entities sent through it to linked entities. /// Relies on being set up. /// -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class PortalComponent : Component { /// diff --git a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs index 4824672974..c6adf00113 100644 --- a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs +++ b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs @@ -13,6 +13,7 @@ using Content.Shared.Hands.Components; using Content.Shared.Interaction; using Content.Shared.Inventory; using Content.Shared.Item; +using Content.Shared.Item.ItemToggle.Components; using Content.Shared.Physics; using Content.Shared.Popups; using Content.Shared.Weapons.Melee.Components; @@ -29,6 +30,7 @@ using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Timing; using Robust.Shared.Toolshed.Syntax; +using ItemToggleMeleeWeaponComponent = Content.Shared.Item.ItemToggle.Components.ItemToggleMeleeWeaponComponent; namespace Content.Shared.Weapons.Melee; @@ -74,7 +76,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem SubscribeLocalEvent(OnGetBonusHeavyDamageModifier); SubscribeLocalEvent(OnGetBonusMeleeAttackRate); - SubscribeLocalEvent(OnItemToggle); + SubscribeLocalEvent(OnItemToggle); SubscribeAllEvent(OnHeavyAttack); SubscribeAllEvent(OnLightAttack); @@ -864,7 +866,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem /// /// Used to update the MeleeWeapon component on item toggle. /// - private void OnItemToggle(EntityUid uid, ItemToggleMeleeWeaponComponent itemToggleMelee, ItemToggleMeleeWeaponUpdateEvent args) + private void OnItemToggle(EntityUid uid, ItemToggleMeleeWeaponComponent itemToggleMelee, ItemToggledEvent args) { if (!TryComp(uid, out MeleeWeaponComponent? meleeWeapon)) return; diff --git a/Content.Shared/Weapons/Reflect/SharedReflectSystem.cs b/Content.Shared/Weapons/Reflect/ReflectSystem.cs similarity index 96% rename from Content.Shared/Weapons/Reflect/SharedReflectSystem.cs rename to Content.Shared/Weapons/Reflect/ReflectSystem.cs index b9dead8231..4a7c2f6b6a 100644 --- a/Content.Shared/Weapons/Reflect/SharedReflectSystem.cs +++ b/Content.Shared/Weapons/Reflect/ReflectSystem.cs @@ -6,6 +6,7 @@ using Content.Shared.Database; using Content.Shared.Hands; using Content.Shared.Inventory; using Content.Shared.Inventory.Events; +using Content.Shared.Item.ItemToggle.Components; using Content.Shared.Popups; using Content.Shared.Projectiles; using Content.Shared.Weapons.Ranged.Components; @@ -23,7 +24,7 @@ namespace Content.Shared.Weapons.Reflect; /// /// This handles reflecting projectiles and hitscan shots. /// -public abstract class SharedReflectSystem : EntitySystem +public sealed class ReflectSystem : EntitySystem { [Dependency] private readonly INetManager _netManager = default!; [Dependency] private readonly IRobustRandom _random = default!; @@ -41,13 +42,14 @@ public abstract class SharedReflectSystem : EntitySystem SubscribeLocalEvent(OnReflectCollide); SubscribeLocalEvent(OnReflectHitscan); - SubscribeLocalEvent(OnReflectUserCollide); - SubscribeLocalEvent(OnReflectUserHitscan); - SubscribeLocalEvent(OnReflectEquipped); SubscribeLocalEvent(OnReflectUnequipped); SubscribeLocalEvent(OnReflectHandEquipped); SubscribeLocalEvent(OnReflectHandUnequipped); + SubscribeLocalEvent(OnToggleReflect); + + SubscribeLocalEvent(OnReflectUserCollide); + SubscribeLocalEvent(OnReflectUserHitscan); } private void OnReflectUserHitscan(EntityUid uid, ReflectUserComponent component, ref HitScanReflectAttemptEvent args) @@ -209,6 +211,12 @@ public abstract class SharedReflectSystem : EntitySystem RefreshReflectUser(args.User); } + private void OnToggleReflect(EntityUid uid, ReflectComponent comp, ref ItemToggledEvent args) + { + comp.Enabled = args.Activated; + Dirty(uid, comp); + } + /// /// Refreshes whether someone has reflection potential so we can raise directed events on them. /// diff --git a/Content.Shared/Wieldable/WieldableSystem.cs b/Content.Shared/Wieldable/WieldableSystem.cs index 399d9b5168..72db0c4a3a 100644 --- a/Content.Shared/Wieldable/WieldableSystem.cs +++ b/Content.Shared/Wieldable/WieldableSystem.cs @@ -177,7 +177,7 @@ public sealed class WieldableSystem : EntitySystem if (TryComp(used, out var item)) { component.OldInhandPrefix = item.HeldPrefix; - _itemSystem.SetHeldPrefix(used, component.WieldedInhandPrefix, item); + _itemSystem.SetHeldPrefix(used, component.WieldedInhandPrefix, component: item); } component.Wielded = true; @@ -229,7 +229,7 @@ public sealed class WieldableSystem : EntitySystem if (TryComp(uid, out var item)) { - _itemSystem.SetHeldPrefix(uid, component.OldInhandPrefix, item); + _itemSystem.SetHeldPrefix(uid, component.OldInhandPrefix, component: item); } component.Wielded = false;