Update trivial components to use auto comp states (#20539)

This commit is contained in:
DrSmugleaf
2023-09-28 16:20:29 -07:00
committed by GitHub
parent 14cfe44ece
commit a44fa86b68
158 changed files with 806 additions and 2866 deletions

View File

@@ -2,7 +2,6 @@ using System.Numerics;
using Content.Shared.Damage;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Anomaly.Components;
@@ -14,7 +13,8 @@ namespace Content.Shared.Anomaly.Components;
///
/// Anomalies and their related components were designed here: https://hackmd.io/@ss14-design/r1sQbkJOs
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedAnomalySystem))]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedAnomalySystem))]
public sealed partial class AnomalyComponent : Component
{
/// <summary>
@@ -27,7 +27,7 @@ public sealed partial class AnomalyComponent : Component
/// Note that this doesn't refer to stability as a percentage: This is an arbitrary
/// value that only matters in relation to the <see cref="GrowthThreshold"/> and <see cref="DecayThreshold"/>
/// </remarks>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float Stability = 0f;
/// <summary>
@@ -39,7 +39,7 @@ public sealed partial class AnomalyComponent : Component
/// <remarks>
/// Wacky-Stability scale lives on in my heart. - emo
/// </remarks>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float Severity = 0f;
#region Health
@@ -49,7 +49,7 @@ public sealed partial class AnomalyComponent : Component
/// When the health of an anomaly reaches 0, it is destroyed without ever
/// reaching a supercritical point.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float Health = 1f;
/// <summary>
@@ -85,25 +85,26 @@ public sealed partial class AnomalyComponent : Component
/// <summary>
/// The time at which the next artifact pulse will occur.
/// </summary>
[DataField("nextPulseTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan NextPulseTime = TimeSpan.Zero;
/// <summary>
/// The minimum interval between pulses.
/// </summary>
[DataField("minPulseLength")]
[DataField]
public TimeSpan MinPulseLength = TimeSpan.FromMinutes(1);
/// <summary>
/// The maximum interval between pulses.
/// </summary>
[DataField("maxPulseLength")]
[DataField]
public TimeSpan MaxPulseLength = TimeSpan.FromMinutes(2);
/// <summary>
/// A percentage by which the length of a pulse might vary.
/// </summary>
[DataField("pulseVariation")]
[DataField]
public float PulseVariation = 0.1f;
/// <summary>
@@ -112,19 +113,19 @@ public sealed partial class AnomalyComponent : Component
/// <remarks>
/// This is more likely to trend upwards than donwards, because that's funny
/// </remarks>
[DataField("pulseStabilityVariation")]
[DataField]
public Vector2 PulseStabilityVariation = new(-0.1f, 0.15f);
/// <summary>
/// The sound played when an anomaly pulses
/// </summary>
[DataField("pulseSound")]
[DataField]
public SoundSpecifier? PulseSound = new SoundCollectionSpecifier("RadiationPulse");
/// <summary>
/// The sound plays when an anomaly goes supercritical
/// </summary>
[DataField("supercriticalSound")]
[DataField]
public SoundSpecifier? SupercriticalSound = new SoundCollectionSpecifier("explosion");
#endregion
@@ -134,7 +135,7 @@ public sealed partial class AnomalyComponent : Component
/// <remarks>
/// +/- 0.2 from perfect stability (0.5)
/// </remarks>
[DataField("initialStabilityRange")]
[DataField]
public (float, float) InitialStabilityRange = (0.4f, 0.6f);
/// <summary>
@@ -143,25 +144,25 @@ public sealed partial class AnomalyComponent : Component
/// <remarks>
/// Between 0 and 0.5, which should be all mild effects
/// </remarks>
[DataField("initialSeverityRange")]
[DataField]
public (float, float) InitialSeverityRange = (0.1f, 0.5f);
/// <summary>
/// The particle type that increases the severity of the anomaly.
/// </summary>
[DataField("severityParticleType")]
[DataField]
public AnomalousParticleType SeverityParticleType;
/// <summary>
/// The particle type that destabilizes the anomaly.
/// </summary>
[DataField("destabilizingParticleType")]
[DataField]
public AnomalousParticleType DestabilizingParticleType;
/// <summary>
/// The particle type that weakens the anomalys health.
/// </summary>
[DataField("weakeningParticleType")]
[DataField]
public AnomalousParticleType WeakeningParticleType;
#region Points and Vessels
@@ -197,14 +198,14 @@ public sealed partial class AnomalyComponent : Component
/// The amount of damage dealt when either a player touches the anomaly
/// directly or by hitting the anomaly.
/// </summary>
[DataField("anomalyContactDamage", required: true)]
[DataField(required: true)]
public DamageSpecifier AnomalyContactDamage = default!;
/// <summary>
/// The sound effect played when a player
/// burns themselves on an anomaly via contact.
/// </summary>
[DataField("anomalyContactDamageSound")]
[DataField]
public SoundSpecifier AnomalyContactDamageSound = new SoundPathSpecifier("/Audio/Effects/lightburn.ogg");
#region Floating Animation
@@ -226,23 +227,6 @@ public sealed partial class AnomalyComponent : Component
#endregion
}
[Serializable, NetSerializable]
public sealed class AnomalyComponentState : ComponentState
{
public float Severity;
public float Stability;
public float Health;
public TimeSpan NextPulseTime;
public AnomalyComponentState(float severity, float stability, float health, TimeSpan nextPulseTime)
{
Severity = severity;
Stability = stability;
Health = health;
NextPulseTime = nextPulseTime;
}
}
/// <summary>
/// Event raised at regular intervals on an anomaly to do whatever its effect is.
/// </summary>

View File

@@ -1,5 +1,4 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Anomaly.Components;
@@ -7,31 +6,27 @@ namespace Content.Shared.Anomaly.Components;
/// <summary>
/// Tracks anomalies going supercritical
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedAnomalySystem))]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedAnomalySystem))]
public sealed partial class AnomalySupercriticalComponent : Component
{
/// <summary>
/// The time when the supercritical animation ends and it does whatever effect.
/// </summary>
[DataField("endTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan EndTime;
/// <summary>
/// The length of the animation before it goes supercritical.
/// </summary>
[AutoNetworkedField]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan SupercriticalDuration = TimeSpan.FromSeconds(10);
/// <summary>
/// The maximum size the anomaly scales to while going supercritical
/// </summary>
[DataField("maxScaleAmount")]
[DataField]
public float MaxScaleAmount = 3;
}
[Serializable, NetSerializable]
public sealed class AnomalySupercriticalComponentState : ComponentState
{
public TimeSpan EndTime;
public TimeSpan Duration;
}

View File

@@ -5,7 +5,6 @@ using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
using Robust.Shared.Random;
using Robust.Shared.Timing;
@@ -30,10 +29,6 @@ public abstract class SharedAnomalySystem : EntitySystem
{
base.Initialize();
SubscribeLocalEvent<AnomalyComponent, ComponentGetState>(OnAnomalyGetState);
SubscribeLocalEvent<AnomalyComponent, ComponentHandleState>(OnAnomalyHandleState);
SubscribeLocalEvent<AnomalySupercriticalComponent, ComponentGetState>(OnSupercriticalGetState);
SubscribeLocalEvent<AnomalySupercriticalComponent, ComponentHandleState>(OnSupercriticalHandleState);
SubscribeLocalEvent<AnomalyComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<AnomalyComponent, AttackedEvent>(OnAttacked);
@@ -44,43 +39,6 @@ public abstract class SharedAnomalySystem : EntitySystem
_sawmill = Logger.GetSawmill("anomaly");
}
private void OnAnomalyGetState(EntityUid uid, AnomalyComponent component, ref ComponentGetState args)
{
args.State = new AnomalyComponentState(
component.Severity,
component.Stability,
component.Health,
component.NextPulseTime);
}
private void OnAnomalyHandleState(EntityUid uid, AnomalyComponent component, ref ComponentHandleState args)
{
if (args.Current is not AnomalyComponentState state)
return;
component.Severity = state.Severity;
component.Stability = state.Stability;
component.Health = state.Health;
component.NextPulseTime = state.NextPulseTime;
}
private void OnSupercriticalGetState(EntityUid uid, AnomalySupercriticalComponent component, ref ComponentGetState args)
{
args.State = new AnomalySupercriticalComponentState
{
EndTime = component.EndTime,
Duration = component.SupercriticalDuration
};
}
private void OnSupercriticalHandleState(EntityUid uid, AnomalySupercriticalComponent component, ref ComponentHandleState args)
{
if (args.Current is not AnomalySupercriticalComponentState state)
return;
component.EndTime = state.EndTime;
component.SupercriticalDuration = state.Duration;
}
private void OnInteractHand(EntityUid uid, AnomalyComponent component, InteractHandEvent args)
{
DoAnomalyBurnDamage(uid, args.User, component);