Files
space-station-14/Content.Server/Botany/Systems/PlantToxinsSystem.cs
2025-12-14 20:30:06 +02:00

38 lines
1.2 KiB
C#

using Content.Server.Botany.Components;
namespace Content.Server.Botany.Systems;
/// <summary>
/// Handles toxin accumulation and tolerance for plants, applying health damage
/// and decrementing toxins based on per-tick uptake.
/// </summary>
public sealed class ToxinsSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<PlantToxinsComponent, OnPlantGrowEvent>(OnPlantGrow);
}
private void OnPlantGrow(Entity<PlantToxinsComponent> ent, ref OnPlantGrowEvent args)
{
var (uid, component) = ent;
if (!TryComp(uid, out PlantHolderComponent? holder ))
return;
if (holder.Toxins < 0)
return;
var toxinUptake = MathF.Max(1, MathF.Round(holder.Toxins / component.ToxinUptakeDivisor));
if (holder.Toxins > component.ToxinsTolerance)
holder.Health -= toxinUptake;
// there is a possibility that it will remove more toxin than amount of damage it took on plant health (and killed it).
// TODO: get min out of health left and toxin uptake - would work better, probably.
holder.Toxins -= toxinUptake;
if (holder.DrawWarnings)
holder.UpdateSpriteAfterUpdate = true;
}
}