Gun auto state handlers (#15186)

* battery auto state

* basic entity autostate

* ballistic autostate

* flyby

* cartridge ammo

* gun

* Revert "battery auto state"

This reverts commit 35b7d62f303fddb0edd9eb7a922e3c26b7a5f7fb.

* silly
This commit is contained in:
Kara
2023-04-13 20:08:56 -05:00
committed by GitHub
parent ccf81a6be9
commit 47262a6998
10 changed files with 31 additions and 173 deletions

View File

@@ -20,13 +20,14 @@ public class AmmoComponent : Component, IShootable
/// <summary>
/// Spawns another prototype to be shot instead of itself.
/// </summary>
[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<EntityPrototype>))]
public string Prototype = default!;
[ViewVariables(VVAccess.ReadWrite), DataField("spent")]
[AutoNetworkedField]
public bool Spent = false;
/// <summary>

View File

@@ -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<EntityUid> Entities = new();
/// <summary>
@@ -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.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("cycled")]
[AutoNetworkedField]
public bool Cycled = true;
/// <summary>

View File

@@ -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
/// </summary>
[RegisterComponent]
public sealed class BasicEntityAmmoProviderComponent : AmmoProviderComponent
[RegisterComponent, AutoGenerateComponentState]
public sealed partial class BasicEntityAmmoProviderComponent : AmmoProviderComponent
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("proto", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
@@ -20,6 +21,7 @@ public sealed class BasicEntityAmmoProviderComponent : AmmoProviderComponent
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("capacity")]
[AutoNetworkedField]
public int? Capacity = null;
/// <summary>
@@ -27,18 +29,6 @@ public sealed class BasicEntityAmmoProviderComponent : AmmoProviderComponent
/// </summary>
[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;
}
}

View File

@@ -6,8 +6,8 @@ namespace Content.Shared.Weapons.Ranged.Components;
/// <summary>
/// Plays a sound when its non-hard fixture collides with a player.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class FlyBySoundComponent : Component
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class FlyBySoundComponent : Component
{
/// <summary>
/// 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;
}

View File

@@ -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.
/// </summary>
[DataField("currentAngle")]
[AutoNetworkedField]
public Angle CurrentAngle;
/// <summary>
@@ -58,12 +60,14 @@ public class GunComponent : Component
/// The maximum angle allowed for <see cref="CurrentAngle"/>
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("maxAngle")]
[AutoNetworkedField]
public Angle MaxAngle = Angle.FromDegrees(2);
/// <summary>
/// The minimum angle allowed for <see cref="CurrentAngle"/>
/// </summary>
[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
/// </summary>
[ViewVariables]
[AutoNetworkedField]
public int ShotCounter = 0;
/// <summary>
/// How many times it shoots per second.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("fireRate")]
[AutoNetworkedField]
public float FireRate = 8f;
/// <summary>
@@ -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.
/// </summary>
[DataField("nextFire", customTypeSerializer:typeof(TimeOffsetSerializer))]
[AutoNetworkedField]
public TimeSpan NextFire = TimeSpan.Zero;
/// <summary>
/// What firemodes can be selected.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("availableModes")]
[AutoNetworkedField]
public SelectiveFire AvailableModes = SelectiveFire.SemiAuto;
/// <summary>
/// What firemode is currently selected.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("selectedMode")]
[AutoNetworkedField]
public SelectiveFire SelectedMode = SelectiveFire.SemiAuto;
[DataField("selectModeAction")]