Files
space-station-14/Content.Server/Botany/Systems/UnviableGrowthSystem.cs

29 lines
880 B
C#

using Content.Server.Botany.Components;
namespace Content.Server.Botany.Systems;
/// <summary>
/// Applies a death chance and damage to unviable plants each growth tick, updating visuals when necessary.
/// </summary>
public sealed class UnviableGrowthSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<UnviableGrowthComponent, OnPlantGrowEvent>(OnPlantGrow);
}
private void OnPlantGrow(Entity<UnviableGrowthComponent> ent, ref OnPlantGrowEvent args)
{
var (uid, component) = ent;
if (!TryComp(uid, out PlantHolderComponent? holder)
|| !BotanySystem.TryGetPlantTraits(holder.Seed, out var traits)
|| traits.Viable)
return;
holder.Health -= component.UnviableDamage;
if (holder.DrawWarnings)
holder.UpdateSpriteAfterUpdate = true;
}
}