Body code cleanup (#24946)

* Fix test

* Kill float accumulators

* Use entity proxy methods

* DataField auto name generation where possible

* Kill comp properties

* Clean up server comps

* Make events record structs

* Clean up shared body code

* Clean up server body code

* Rename organ events to be same names as in med refactor
This commit is contained in:
0x6273
2024-03-28 01:48:37 +01:00
committed by GitHub
parent 527c2c42ed
commit 37b8d78dac
32 changed files with 916 additions and 820 deletions

View File

@@ -1,11 +1,7 @@
namespace Content.Server.Body.Components;
public sealed class BeingGibbedEvent : EntityEventArgs
{
public readonly HashSet<EntityUid> GibbedParts;
public BeingGibbedEvent(HashSet<EntityUid> gibbedParts)
{
GibbedParts = gibbedParts;
}
}
/// <summary>
/// Raised when a body gets gibbed, before it is deleted.
/// </summary>
[ByRefEvent]
public readonly record struct BeingGibbedEvent(HashSet<EntityUid> GibbedParts);

View File

@@ -1,11 +1,13 @@
using Content.Server.Body.Systems;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Body.Components
{
@@ -16,7 +18,17 @@ namespace Content.Server.Body.Components
public static string DefaultBloodSolutionName = "bloodstream";
public static string DefaultBloodTemporarySolutionName = "bloodstreamTemporary";
public float AccumulatedFrametime = 0.0f;
/// <summary>
/// The next time that blood level will be updated and bloodloss damage dealt.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate;
/// <summary>
/// The interval at which this component updates.
/// </summary>
[DataField]
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(3);
/// <summary>
/// How much is this entity currently bleeding?
@@ -32,7 +44,7 @@ namespace Content.Server.Body.Components
public float BleedAmount;
/// <summary>
/// How much should bleeding should be reduced every update interval?
/// How much should bleeding be reduced every update interval?
/// </summary>
[DataField]
public float BleedReductionAmount = 0.33f;
@@ -63,18 +75,12 @@ namespace Content.Server.Body.Components
[DataField(required: true)]
public DamageSpecifier BloodlossHealDamage = new();
/// <summary>
/// How frequently should this bloodstream update, in seconds?
/// </summary>
[DataField]
public float UpdateInterval = 3.0f;
// TODO shouldn't be hardcoded, should just use some organ simulation like bone marrow or smth.
/// <summary>
/// How much reagent of blood should be restored each update interval?
/// </summary>
[DataField]
public float BloodRefreshAmount = 1.0f;
public FixedPoint2 BloodRefreshAmount = 1.0f;
/// <summary>
/// How much blood needs to be in the temporary solution in order to create a puddle?
@@ -89,8 +95,8 @@ namespace Content.Server.Body.Components
/// <remarks>
/// For example, piercing damage is increased while poison damage is nullified entirely.
/// </remarks>
[DataField(customTypeSerializer:typeof(PrototypeIdSerializer<DamageModifierSetPrototype>))]
public string DamageBleedModifiers = "BloodlossHuman";
[DataField]
public ProtoId<DamageModifierSetPrototype> DamageBleedModifiers = "BloodlossHuman";
/// <summary>
/// The sound to be played when a weapon instantly deals blood loss damage.
@@ -126,7 +132,7 @@ namespace Content.Server.Body.Components
/// Slime-people might use slime as their blood or something like that.
/// </remarks>
[DataField]
public string BloodReagent = "Blood";
public ProtoId<ReagentPrototype> BloodReagent = "Blood";
/// <summary>Name/Key that <see cref="BloodSolution"/> is indexed by.</summary>
[DataField]
@@ -164,6 +170,6 @@ namespace Content.Server.Body.Components
/// Variable that stores the amount of status time added by having a low blood level.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float StatusTime;
public TimeSpan StatusTime;
}
}

View File

@@ -1,4 +1,3 @@
using System.Threading;
namespace Content.Server.Body.Components
{
/// <summary>
@@ -7,14 +6,17 @@ namespace Content.Server.Body.Components
[RegisterComponent]
public sealed partial class InternalsComponent : Component
{
[ViewVariables] public EntityUid? GasTankEntity { get; set; }
[ViewVariables] public EntityUid? BreathToolEntity { get; set; }
[ViewVariables]
public EntityUid? GasTankEntity;
[ViewVariables]
public EntityUid? BreathToolEntity;
/// <summary>
/// Toggle Internals delay (seconds) when the target is not you.
/// Toggle Internals delay when the target is not you.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("delay")]
public float Delay = 3;
[DataField]
public TimeSpan Delay = TimeSpan.FromSeconds(3);
}
}

View File

@@ -1,4 +1,4 @@
using Content.Server.Atmos;
using Content.Server.Atmos;
using Content.Server.Body.Systems;
using Content.Shared.Alert;
using Content.Shared.Atmos;
@@ -11,7 +11,7 @@ public sealed partial class LungComponent : Component
{
[DataField]
[Access(typeof(LungSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
public GasMixture Air { get; set; } = new()
public GasMixture Air = new()
{
Volume = 6,
Temperature = Atmospherics.NormalBodyTemperature

View File

@@ -1,8 +1,8 @@
using Content.Server.Body.Systems;
using Content.Server.Body.Systems;
using Content.Shared.Body.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Body.Components
{
@@ -12,20 +12,24 @@ namespace Content.Server.Body.Components
[RegisterComponent, Access(typeof(MetabolizerSystem))]
public sealed partial class MetabolizerComponent : Component
{
public float AccumulatedFrametime = 0.0f;
/// <summary>
/// The next time that reagents will be metabolized.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate;
/// <summary>
/// How often to metabolize reagents, in seconds.
/// How often to metabolize reagents.
/// </summary>
/// <returns></returns>
[DataField]
public float UpdateFrequency = 1.0f;
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(1);
/// <summary>
/// From which solution will this metabolizer attempt to metabolize chemicals
/// </summary>
[DataField("solution")]
public string SolutionName { get; set; } = BloodstreamComponent.DefaultChemicalsSolutionName;
public string SolutionName = BloodstreamComponent.DefaultChemicalsSolutionName;
/// <summary>
/// Does this component use a solution on it's parent entity (the body) or itself
@@ -39,9 +43,9 @@ namespace Content.Server.Body.Components
/// <summary>
/// List of metabolizer types that this organ is. ex. Human, Slime, Felinid, w/e.
/// </summary>
[DataField(customTypeSerializer:typeof(PrototypeIdHashSetSerializer<MetabolizerTypePrototype>))]
[DataField]
[Access(typeof(MetabolizerSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
public HashSet<string>? MetabolizerTypes = null;
public HashSet<ProtoId<MetabolizerTypePrototype>>? MetabolizerTypes = null;
/// <summary>
/// Should this metabolizer remove chemicals that have no metabolisms defined?
@@ -72,8 +76,8 @@ namespace Content.Server.Body.Components
[DataDefinition]
public sealed partial class MetabolismGroupEntry
{
[DataField(required: true, customTypeSerializer:typeof(PrototypeIdSerializer<MetabolismGroupPrototype>))]
public string Id = default!;
[DataField(required: true)]
public ProtoId<MetabolismGroupPrototype> Id = default!;
[DataField("rateModifier")]
public FixedPoint2 MetabolismRateModifier = 1.0;

View File

@@ -1,5 +1,6 @@
using Content.Server.Body.Systems;
using Content.Shared.Damage;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Body.Components
{
@@ -7,36 +8,49 @@ namespace Content.Server.Body.Components
public sealed partial class RespiratorComponent : Component
{
/// <summary>
/// Saturation level. Reduced by CycleDelay each tick.
/// The next time that this body will inhale or exhale.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate;
/// <summary>
/// The interval between updates. Each update is either inhale or exhale,
/// so a full cycle takes twice as long.
/// </summary>
[DataField]
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(2);
/// <summary>
/// Saturation level. Reduced by UpdateInterval each tick.
/// Can be thought of as 'how many seconds you have until you start suffocating' in this configuration.
/// </summary>
[DataField("saturation")]
[DataField]
public float Saturation = 5.0f;
/// <summary>
/// At what level of saturation will you begin to suffocate?
/// </summary>
[DataField("suffocationThreshold")]
[DataField]
public float SuffocationThreshold;
[DataField("maxSaturation")]
[DataField]
public float MaxSaturation = 5.0f;
[DataField("minSaturation")]
[DataField]
public float MinSaturation = -2.0f;
// TODO HYPEROXIA?
[DataField("damage", required: true)]
[DataField(required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier Damage = default!;
[DataField("damageRecovery", required: true)]
[DataField(required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier DamageRecovery = default!;
[DataField("gaspPopupCooldown")]
public TimeSpan GaspPopupCooldown { get; private set; } = TimeSpan.FromSeconds(8);
[DataField]
public TimeSpan GaspPopupCooldown = TimeSpan.FromSeconds(8);
[ViewVariables]
public TimeSpan LastGaspPopupTime;
@@ -55,11 +69,6 @@ namespace Content.Server.Body.Components
[ViewVariables]
public RespiratorStatus Status = RespiratorStatus.Inhaling;
[DataField("cycleDelay")]
public float CycleDelay = 2.0f;
public float AccumulatedFrametime;
}
}

View File

@@ -1,21 +1,26 @@
using Content.Server.Body.Systems;
using Content.Server.Body.Systems;
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Whitelist;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Body.Components
{
[RegisterComponent, Access(typeof(StomachSystem), typeof(FoodSystem))]
public sealed partial class StomachComponent : Component
{
public float AccumulatedFrameTime;
/// <summary>
/// The next time that the stomach will try to digest its contents.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate;
/// <summary>
/// How fast should this component update, in seconds?
/// The interval at which this stomach digests its contents.
/// </summary>
[DataField]
public float UpdateInterval = 1.0f;
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(1);
/// <summary>
/// The solution inside of this stomach this transfers reagents to the body.
@@ -30,11 +35,11 @@ namespace Content.Server.Body.Components
public string BodySolutionName = BloodstreamComponent.DefaultChemicalsSolutionName;
/// <summary>
/// Time in seconds between reagents being ingested and them being
/// Time between reagents being ingested and them being
/// transferred to <see cref="BloodstreamComponent"/>
/// </summary>
[DataField]
public float DigestionDelay = 20;
public TimeSpan DigestionDelay = TimeSpan.FromSeconds(20);
/// <summary>
/// A whitelist for what special-digestible-required foods this stomach is capable of eating.
@@ -54,15 +59,15 @@ namespace Content.Server.Body.Components
public sealed class ReagentDelta
{
public readonly ReagentQuantity ReagentQuantity;
public float Lifetime { get; private set; }
public TimeSpan Lifetime { get; private set; }
public ReagentDelta(ReagentQuantity reagentQuantity)
{
ReagentQuantity = reagentQuantity;
Lifetime = 0.0f;
Lifetime = TimeSpan.Zero;
}
public void Increment(float delta) => Lifetime += delta;
public void Increment(TimeSpan delta) => Lifetime += delta;
}
}
}

View File

@@ -1,4 +1,5 @@
using Content.Server.Body.Systems;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Body.Components;
@@ -6,48 +7,58 @@ namespace Content.Server.Body.Components;
[Access(typeof(ThermalRegulatorSystem))]
public sealed partial class ThermalRegulatorComponent : Component
{
/// <summary>
/// The next time that the body will regulate its heat.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate;
/// <summary>
/// The interval at which thermal regulation is processed.
/// </summary>
[DataField]
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(1);
/// <summary>
/// Heat generated due to metabolism. It's generated via metabolism
/// </summary>
[DataField("metabolismHeat")]
public float MetabolismHeat { get; private set; }
[DataField]
public float MetabolismHeat;
/// <summary>
/// Heat output via radiation.
/// </summary>
[DataField("radiatedHeat")]
public float RadiatedHeat { get; private set; }
[DataField]
public float RadiatedHeat;
/// <summary>
/// Maximum heat regulated via sweat
/// </summary>
[DataField("sweatHeatRegulation")]
public float SweatHeatRegulation { get; private set; }
[DataField]
public float SweatHeatRegulation;
/// <summary>
/// Maximum heat regulated via shivering
/// </summary>
[DataField("shiveringHeatRegulation")]
public float ShiveringHeatRegulation { get; private set; }
[DataField]
public float ShiveringHeatRegulation;
/// <summary>
/// Amount of heat regulation that represents thermal regulation processes not
/// explicitly coded.
/// </summary>
[DataField("implicitHeatRegulation")]
public float ImplicitHeatRegulation { get; private set; }
[DataField]
public float ImplicitHeatRegulation;
/// <summary>
/// Normal body temperature
/// </summary>
[DataField("normalBodyTemperature")]
public float NormalBodyTemperature { get; private set; }
[DataField]
public float NormalBodyTemperature;
/// <summary>
/// Deviation from normal temperature for body to start thermal regulation
/// </summary>
[DataField("thermalRegulationTemperatureThreshold")]
public float ThermalRegulationTemperatureThreshold { get; private set; }
public float AccumulatedFrametime;
[DataField]
public float ThermalRegulationTemperatureThreshold;
}