Move rotting stages and examine to shared (#24183)

This commit is contained in:
DrSmugleaf
2024-01-17 01:49:21 -08:00
committed by GitHub
parent 1f0cdf5af8
commit 8902701271
5 changed files with 81 additions and 46 deletions

View File

@@ -1,3 +1,4 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Atmos.Rotting;
@@ -6,39 +7,43 @@ namespace Content.Shared.Atmos.Rotting;
/// This makes mobs eventually start rotting when they die.
/// It may be expanded to food at some point, but it's just for mobs right now.
/// </summary>
[RegisterComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedRottingSystem))]
public sealed partial class PerishableComponent : Component
{
/// <summary>
/// How long it takes after death to start rotting.
/// </summary>
[DataField("rotAfter"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public TimeSpan RotAfter = TimeSpan.FromMinutes(10);
/// <summary>
/// How much rotting has occured
/// </summary>
[DataField("rotAccumulator"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public TimeSpan RotAccumulator = TimeSpan.Zero;
/// <summary>
/// Gasses are released, this is when the next gas release update will be.
/// </summary>
[DataField("rotNextUpdate", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan NextPerishUpdate = TimeSpan.Zero;
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan RotNextUpdate = TimeSpan.Zero;
/// <summary>
/// How often the rotting ticks.
/// Feel free to tweak this if there are perf concerns.
/// </summary>
[DataField("perishUpdateRate"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public TimeSpan PerishUpdateRate = TimeSpan.FromSeconds(5);
/// <summary>
/// How many moles of gas released per second, per unit of mass.
/// </summary>
[DataField("molsPerSecondPerUnitMass"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float MolsPerSecondPerUnitMass = 0.0025f;
[DataField, AutoNetworkedField]
public int Stage;
}

View File

@@ -6,38 +6,40 @@ namespace Content.Shared.Atmos.Rotting;
/// <summary>
/// Tracking component for stuff that has started to rot.
/// Only the current stage is networked to the client.
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedRottingSystem))]
public sealed partial class RottingComponent : Component
{
/// <summary>
/// Whether or not the rotting should deal damage
/// </summary>
[DataField("dealDamage"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool DealDamage = true;
/// <summary>
/// When the next check will happen for rot progression + effects like damage and ammonia
/// </summary>
[DataField("nextRotUpdate", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextRotUpdate = TimeSpan.Zero;
/// <summary>
/// How long in between each rot update.
/// </summary>
[DataField("rotUpdateRate"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public TimeSpan RotUpdateRate = TimeSpan.FromSeconds(5);
/// <summary>
/// How long has this thing been rotting?
/// </summary>
[DataField("totalRotTime"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public TimeSpan TotalRotTime = TimeSpan.Zero;
/// <summary>
/// The damage dealt by rotting.
/// </summary>
[DataField("damage")]
[DataField]
public DamageSpecifier Damage = new()
{
DamageDict = new()

View File

@@ -0,0 +1,39 @@
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
namespace Content.Shared.Atmos.Rotting;
public abstract class SharedRottingSystem : EntitySystem
{
public const int MaxStages = 3;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RottingComponent, ExaminedEvent>(OnExamined);
}
/// <summary>
/// Return the rot stage, usually from 0 to 2 inclusive.
/// </summary>
public int RotStage(EntityUid uid, RottingComponent? comp = null, PerishableComponent? perishable = null)
{
if (!Resolve(uid, ref comp, ref perishable))
return 0;
return (int) (comp.TotalRotTime.TotalSeconds / perishable.RotAfter.TotalSeconds);
}
private void OnExamined(EntityUid uid, RottingComponent component, ExaminedEvent args)
{
var stage = RotStage(uid, component);
var description = stage switch
{
>= 2 => "rotting-extremely-bloated",
>= 1 => "rotting-bloated",
_ => "rotting-rotting"
};
args.PushMarkup(Loc.GetString(description, ("target", Identity.Entity(uid, EntityManager))));
}
}