mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-15 03:31:30 +01:00
38 lines
1.2 KiB
C#
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;
|
|
}
|
|
}
|