diff --git a/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs b/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs
index 3b87beba1a..075192a76f 100644
--- a/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs
+++ b/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs
@@ -20,13 +20,14 @@ public class AmmoComponent : Component, IShootable
///
/// Spawns another prototype to be shot instead of itself.
///
-[RegisterComponent, NetworkedComponent, ComponentReference(typeof(AmmoComponent))]
-public sealed class CartridgeAmmoComponent : AmmoComponent
+[RegisterComponent, NetworkedComponent, ComponentReference(typeof(AmmoComponent)), AutoGenerateComponentState]
+public sealed partial class CartridgeAmmoComponent : AmmoComponent
{
[ViewVariables(VVAccess.ReadWrite), DataField("proto", required: true, customTypeSerializer: typeof(PrototypeIdSerializer))]
public string Prototype = default!;
[ViewVariables(VVAccess.ReadWrite), DataField("spent")]
+ [AutoNetworkedField]
public bool Spent = false;
///
diff --git a/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs
index 0fb661aaaa..9c4b9045cc 100644
--- a/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs
+++ b/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs
@@ -7,8 +7,8 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
namespace Content.Shared.Weapons.Ranged.Components;
-[RegisterComponent, NetworkedComponent]
-public sealed class BallisticAmmoProviderComponent : Component
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class BallisticAmmoProviderComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("soundRack")]
public SoundSpecifier? SoundRack = new SoundPathSpecifier("/Audio/Weapons/Guns/Cock/smg_cock.ogg");
@@ -23,6 +23,7 @@ public sealed class BallisticAmmoProviderComponent : Component
public int Capacity = 30;
[ViewVariables(VVAccess.ReadWrite), DataField("unspawnedCount")]
+ [AutoNetworkedField]
public int UnspawnedCount;
[ViewVariables(VVAccess.ReadWrite), DataField("whitelist")]
@@ -32,6 +33,7 @@ public sealed class BallisticAmmoProviderComponent : Component
// TODO: Make this use stacks when the typeserializer is done.
[DataField("entities")]
+ [AutoNetworkedField(true)]
public List Entities = new();
///
@@ -44,6 +46,7 @@ public sealed class BallisticAmmoProviderComponent : Component
/// Is the gun ready to shoot; if AutoCycle is true then this will always stay true and not need to be manually done.
///
[ViewVariables(VVAccess.ReadWrite), DataField("cycled")]
+ [AutoNetworkedField]
public bool Cycled = true;
///
diff --git a/Content.Shared/Weapons/Ranged/Components/BasicEntityAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/BasicEntityAmmoProviderComponent.cs
index d032b07555..d0c6c4487e 100644
--- a/Content.Shared/Weapons/Ranged/Components/BasicEntityAmmoProviderComponent.cs
+++ b/Content.Shared/Weapons/Ranged/Components/BasicEntityAmmoProviderComponent.cs
@@ -1,4 +1,5 @@
-using Robust.Shared.Prototypes;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
@@ -8,8 +9,8 @@ namespace Content.Shared.Weapons.Ranged.Components;
/// Simply provides a certain capacity of entities that cannot be reloaded through normal means and have
/// no special behavior like cycling, magazine
///
-[RegisterComponent]
-public sealed class BasicEntityAmmoProviderComponent : AmmoProviderComponent
+[RegisterComponent, AutoGenerateComponentState]
+public sealed partial class BasicEntityAmmoProviderComponent : AmmoProviderComponent
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("proto", required: true, customTypeSerializer:typeof(PrototypeIdSerializer))]
@@ -20,6 +21,7 @@ public sealed class BasicEntityAmmoProviderComponent : AmmoProviderComponent
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("capacity")]
+ [AutoNetworkedField]
public int? Capacity = null;
///
@@ -27,18 +29,6 @@ public sealed class BasicEntityAmmoProviderComponent : AmmoProviderComponent
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("count")]
+ [AutoNetworkedField]
public int? Count = null;
}
-
-[Serializable, NetSerializable]
-public sealed class BasicEntityAmmoProviderComponentState : ComponentState
-{
- public int? Capacity;
- public int? Count;
-
- public BasicEntityAmmoProviderComponentState(int? capacity, int? count)
- {
- Capacity = capacity;
- Count = count;
- }
-}
diff --git a/Content.Shared/Weapons/Ranged/Components/FlyBySoundComponent.cs b/Content.Shared/Weapons/Ranged/Components/FlyBySoundComponent.cs
index 9375027470..a915a8c1a5 100644
--- a/Content.Shared/Weapons/Ranged/Components/FlyBySoundComponent.cs
+++ b/Content.Shared/Weapons/Ranged/Components/FlyBySoundComponent.cs
@@ -6,8 +6,8 @@ namespace Content.Shared.Weapons.Ranged.Components;
///
/// Plays a sound when its non-hard fixture collides with a player.
///
-[RegisterComponent, NetworkedComponent]
-public sealed class FlyBySoundComponent : Component
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class FlyBySoundComponent : Component
{
///
/// Probability that the sound plays
@@ -16,10 +16,13 @@ public sealed class FlyBySoundComponent : Component
public float Prob = 0.10f;
[ViewVariables(VVAccess.ReadWrite), DataField("sound")]
+ [AutoNetworkedField]
public SoundSpecifier Sound = new SoundCollectionSpecifier("BulletMiss")
{
Params = AudioParams.Default,
};
- [DataField("range")] public float Range = 1.5f;
+ [DataField("range")]
+ [AutoNetworkedField]
+ public float Range = 1.5f;
}
diff --git a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs
index 061798e86e..07f84f3252 100644
--- a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs
+++ b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs
@@ -7,7 +7,8 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Weapons.Ranged.Components;
[RegisterComponent, NetworkedComponent, Virtual]
-public class GunComponent : Component
+[AutoGenerateComponentState]
+public partial class GunComponent : Component
{
#region Sound
@@ -40,6 +41,7 @@ public class GunComponent : Component
/// What the current spread is for shooting. This gets changed every time the gun fires.
///
[DataField("currentAngle")]
+ [AutoNetworkedField]
public Angle CurrentAngle;
///
@@ -58,12 +60,14 @@ public class GunComponent : Component
/// The maximum angle allowed for
///
[ViewVariables(VVAccess.ReadWrite), DataField("maxAngle")]
+ [AutoNetworkedField]
public Angle MaxAngle = Angle.FromDegrees(2);
///
/// The minimum angle allowed for
///
[ViewVariables(VVAccess.ReadWrite), DataField("minAngle")]
+ [AutoNetworkedField]
public Angle MinAngle = Angle.FromDegrees(1);
#endregion
@@ -78,12 +82,14 @@ public class GunComponent : Component
/// Used for tracking semi-auto / burst
///
[ViewVariables]
+ [AutoNetworkedField]
public int ShotCounter = 0;
///
/// How many times it shoots per second.
///
[ViewVariables(VVAccess.ReadWrite), DataField("fireRate")]
+ [AutoNetworkedField]
public float FireRate = 8f;
///
@@ -97,18 +103,21 @@ public class GunComponent : Component
/// Can be set multiple times in a single tick due to guns firing faster than a single tick time.
///
[DataField("nextFire", customTypeSerializer:typeof(TimeOffsetSerializer))]
+ [AutoNetworkedField]
public TimeSpan NextFire = TimeSpan.Zero;
///
/// What firemodes can be selected.
///
[ViewVariables(VVAccess.ReadWrite), DataField("availableModes")]
+ [AutoNetworkedField]
public SelectiveFire AvailableModes = SelectiveFire.SemiAuto;
///
/// What firemode is currently selected.
///
[ViewVariables(VVAccess.ReadWrite), DataField("selectedMode")]
+ [AutoNetworkedField]
public SelectiveFire SelectedMode = SelectiveFire.SemiAuto;
[DataField("selectModeAction")]
diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs
index c2fd397e42..6aec5e9db3 100644
--- a/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs
+++ b/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs
@@ -20,8 +20,6 @@ public abstract class SharedFlyBySoundSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
- SubscribeLocalEvent(OnGetState);
- SubscribeLocalEvent(OnHandleState);
SubscribeLocalEvent(OnStartup);
SubscribeLocalEvent(OnShutdown);
}
@@ -46,28 +44,4 @@ public abstract class SharedFlyBySoundSystem : EntitySystem
_fixtures.DestroyFixture(uid, FlyByFixture, body: body);
}
-
- private void OnHandleState(EntityUid uid, FlyBySoundComponent component, ref ComponentHandleState args)
- {
- if (args.Current is not FlyBySoundComponentState state) return;
-
- component.Sound = state.Sound;
- component.Range = state.Range;
- }
-
- private void OnGetState(EntityUid uid, FlyBySoundComponent component, ref ComponentGetState args)
- {
- args.State = new FlyBySoundComponentState()
- {
- Sound = component.Sound,
- Range = component.Range,
- };
- }
-
- [Serializable, NetSerializable]
- private sealed class FlyBySoundComponentState : ComponentState
- {
- public SoundSpecifier Sound = default!;
- public float Range;
- }
}
diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
index 2b5b330fb5..b529a978fa 100644
--- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
+++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
@@ -19,8 +19,6 @@ public abstract partial class SharedGunSystem
SubscribeLocalEvent(OnBallisticMapInit);
SubscribeLocalEvent(OnBallisticTakeAmmo);
SubscribeLocalEvent(OnBallisticAmmoCount);
- SubscribeLocalEvent(OnBallisticGetState);
- SubscribeLocalEvent(OnBallisticHandleState);
SubscribeLocalEvent(OnBallisticExamine);
SubscribeLocalEvent>(OnBallisticVerb);
@@ -175,32 +173,6 @@ public abstract partial class SharedGunSystem
protected abstract void Cycle(BallisticAmmoProviderComponent component, MapCoordinates coordinates);
- private void OnBallisticGetState(EntityUid uid, BallisticAmmoProviderComponent component, ref ComponentGetState args)
- {
- args.State = new BallisticAmmoProviderComponentState()
- {
- UnspawnedCount = component.UnspawnedCount,
- Entities = component.Entities,
- Cycled = component.Cycled,
- };
- }
-
- private void OnBallisticHandleState(EntityUid uid, BallisticAmmoProviderComponent component, ref ComponentHandleState args)
- {
- if (args.Current is not BallisticAmmoProviderComponentState state)
- return;
-
- component.Cycled = state.Cycled;
- component.UnspawnedCount = state.UnspawnedCount;
-
- component.Entities.Clear();
-
- foreach (var ent in state.Entities)
- {
- component.Entities.Add(ent);
- }
- }
-
private void OnBallisticInit(EntityUid uid, BallisticAmmoProviderComponent component, ComponentInit args)
{
component.Container = Containers.EnsureContainer(uid, "ballistic-ammo");
@@ -292,12 +264,4 @@ public abstract partial class SharedGunSystem
Appearance.SetData(uid, AmmoVisuals.AmmoCount, GetBallisticShots(component), appearance);
Appearance.SetData(uid, AmmoVisuals.AmmoMax, component.Capacity, appearance);
}
-
- [Serializable, NetSerializable]
- private sealed class BallisticAmmoProviderComponentState : ComponentState
- {
- public int UnspawnedCount;
- public List Entities = default!;
- public bool Cycled;
- }
}
diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs
index 58c3f01d16..e530b21e32 100644
--- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs
+++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs
@@ -11,23 +11,6 @@ public abstract partial class SharedGunSystem
SubscribeLocalEvent(OnBasicEntityInit);
SubscribeLocalEvent(OnBasicEntityTakeAmmo);
SubscribeLocalEvent(OnBasicEntityAmmoCount);
-
- SubscribeLocalEvent(OnBasicEntityGetState);
- SubscribeLocalEvent(OnBasicEntityHandleState);
- }
-
- private void OnBasicEntityGetState(EntityUid uid, BasicEntityAmmoProviderComponent component, ref ComponentGetState args)
- {
- args.State = new BasicEntityAmmoProviderComponentState(component.Capacity, component.Count);
- }
-
- private void OnBasicEntityHandleState(EntityUid uid, BasicEntityAmmoProviderComponent component, ref ComponentHandleState args)
- {
- if (args.Current is BasicEntityAmmoProviderComponentState state)
- {
- component.Capacity = state.Capacity;
- component.Count = state.Count;
- }
}
private void OnBasicEntityInit(EntityUid uid, BasicEntityAmmoProviderComponent component, ComponentInit args)
diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs
index 14ed2df950..b28b4b7508 100644
--- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs
+++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs
@@ -6,31 +6,8 @@ namespace Content.Shared.Weapons.Ranged.Systems;
public abstract partial class SharedGunSystem
{
+ // needed for server system
protected virtual void InitializeCartridge()
{
- SubscribeLocalEvent(OnCartridgeGetState);
- SubscribeLocalEvent(OnCartridgeHandleState);
- }
-
- private void OnCartridgeHandleState(EntityUid uid, CartridgeAmmoComponent component, ref ComponentHandleState args)
- {
- if (args.Current is not CartridgeAmmoComponentState state)
- return;
-
- component.Spent = state.Spent;
- }
-
- private void OnCartridgeGetState(EntityUid uid, CartridgeAmmoComponent component, ref ComponentGetState args)
- {
- args.State = new CartridgeAmmoComponentState()
- {
- Spent = component.Spent,
- };
- }
-
- [Serializable, NetSerializable]
- private sealed class CartridgeAmmoComponentState : ComponentState
- {
- public bool Spent;
}
}
diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
index 13179a24d2..fdae26dcc1 100644
--- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
+++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
@@ -67,10 +67,8 @@ public abstract partial class SharedGunSystem : EntitySystem
{
Sawmill = Logger.GetSawmill("gun");
Sawmill.Level = LogLevel.Info;
- SubscribeLocalEvent(OnGetState);
SubscribeAllEvent(OnShootRequest);
SubscribeAllEvent(OnStopShootRequest);
- SubscribeLocalEvent(OnHandleState);
SubscribeLocalEvent(OnGunMeleeAttempt);
// Ammo providers
@@ -144,37 +142,6 @@ public abstract partial class SharedGunSystem : EntitySystem
StopShooting(ev.Gun, gun);
}
- private void OnGetState(EntityUid uid, GunComponent component, ref ComponentGetState args)
- {
- args.State = new GunComponentState
- {
- FireRate = component.FireRate,
- CurrentAngle = component.CurrentAngle,
- MinAngle = component.MinAngle,
- MaxAngle = component.MaxAngle,
- NextFire = component.NextFire,
- ShotCounter = component.ShotCounter,
- SelectiveFire = component.SelectedMode,
- AvailableSelectiveFire = component.AvailableModes,
- };
- }
-
- private void OnHandleState(EntityUid uid, GunComponent component, ref ComponentHandleState args)
- {
- if (args.Current is not GunComponentState state)
- return;
-
- Sawmill.Debug($"Handle state: setting shot count from {component.ShotCounter} to {state.ShotCounter}");
- component.FireRate = state.FireRate;
- component.CurrentAngle = state.CurrentAngle;
- component.MinAngle = state.MinAngle;
- component.MaxAngle = state.MaxAngle;
- component.NextFire = state.NextFire;
- component.ShotCounter = state.ShotCounter;
- component.SelectedMode = state.SelectiveFire;
- component.AvailableModes = state.AvailableSelectiveFire;
- }
-
public bool CanShoot(GunComponent component)
{
if (component.NextFire > Timing.CurTime)
@@ -418,19 +385,6 @@ public abstract partial class SharedGunSystem : EntitySystem
}
protected abstract void CreateEffect(EntityUid uid, MuzzleFlashEvent message, EntityUid? user = null);
- [Serializable, NetSerializable]
- protected sealed class GunComponentState : ComponentState
- {
- public Angle CurrentAngle;
- public Angle MinAngle;
- public Angle MaxAngle;
- public TimeSpan NextFire;
- public float FireRate;
- public int ShotCounter;
- public SelectiveFire SelectiveFire;
- public SelectiveFire AvailableSelectiveFire;
- }
-
///
/// Used for animated effects on the client.
///