CatStation/Content.Shared/Botany/Systems/SharedPlantAtmosphericSystem.cs
SlothBasket b1323acc43
Botany Refactor Bugfixes and Value adjustments (#45752)
* Fixes Cryoxadone De-Age, properly adjusts lastHarvest. If age would be reduced below 0 reverts plant to seed with current genetics.

* Botany Bugfixes. Cryoxadone De-Age fix. Cryox Regression to seed re-added. Seedless Produce no longer have seeds. Proper Temp tollerance ranges restored. Production no longer clamped to maturation.

* Restore Content Server+Client run configuration

* Fix formatting in Content Server+Client run configuration

* Address botany review feedback

* review

* fix weed

* fix

* fix 2

* Update PlantSystem.cs

* refactor: revert to EntityTerminatingEvent and leave warning for next generations

---------

Co-authored-by: Pok245 <113675512+Pok27@users.noreply.github.com>
Co-authored-by: Fildrance <fildrance@gmail.com>
2026-09-03 14:57:34 +00:00

94 lines
3.9 KiB
C#

using Content.Shared.Botany.Components;
using Content.Shared.Botany.Events;
using JetBrains.Annotations;
namespace Content.Shared.Botany.Systems;
/// <summary>
/// Applies atmospheric temperature and pressure effects to plants during growth ticks.
/// Uses current tile gas mixture to penalize or clear warnings based on tolerances.
/// </summary>
public abstract partial class SharedPlantAtmosphericSystem : EntitySystem
{
[Dependency] private BotanySystem _botany = default!;
[Dependency] private PlantMutationSystem _mutation = default!;
[SubscribeLocalEvent]
private void OnCrossPollinate(Entity<PlantAtmosphericComponent> ent, ref PlantCrossPollinateEvent args)
{
if (!_botany.TryGetPlantComponent<PlantAtmosphericComponent>(args.PollenData, args.PollenProtoId, out var pollenData))
return;
_mutation.CrossFloat(ref ent.Comp.LowHeatTolerance, pollenData.LowHeatTolerance);
_mutation.CrossFloat(ref ent.Comp.HighHeatTolerance, pollenData.HighHeatTolerance);
_mutation.CrossFloat(ref ent.Comp.LowPressureTolerance, pollenData.LowPressureTolerance);
_mutation.CrossFloat(ref ent.Comp.HighPressureTolerance, pollenData.HighPressureTolerance);
Dirty(ent);
}
/// <summary>
/// Adjusts minimum temperature tolerance for plant growth.
/// Ensures low temperature is not greater than high.
/// </summary>
public void AdjustLowHeatTolerance(Entity<PlantAtmosphericComponent?> ent, float amount)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
ent.Comp.LowHeatTolerance = MathF.Max(0f, ent.Comp.LowHeatTolerance + amount);
if (ent.Comp.LowHeatTolerance > ent.Comp.HighHeatTolerance)
ent.Comp.HighHeatTolerance = ent.Comp.LowHeatTolerance;
DirtyFields(ent, null, nameof(ent.Comp.LowHeatTolerance), nameof(ent.Comp.HighHeatTolerance));
}
/// <summary>
/// Adjusts maximum temperature tolerance for plant growth.
/// Ensures low temperature is not less than high.
/// </summary>
public void AdjustHighHeatTolerance(Entity<PlantAtmosphericComponent?> ent, float amount)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
ent.Comp.HighHeatTolerance = MathF.Max(0f, ent.Comp.HighHeatTolerance + amount);
if (ent.Comp.HighHeatTolerance < ent.Comp.LowHeatTolerance)
ent.Comp.LowHeatTolerance = ent.Comp.HighHeatTolerance;
DirtyFields(ent, null, nameof(ent.Comp.HighHeatTolerance), nameof(ent.Comp.LowHeatTolerance));
}
/// <summary>
/// Adjusts minimum pressure tolerance for plant growth.
/// Ensures pressure low is not greater than high.
/// </summary>
[PublicAPI]
public void AdjustLowPressureTolerance(Entity<PlantAtmosphericComponent?> ent, float amount)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
ent.Comp.LowPressureTolerance = MathF.Max(0f, ent.Comp.LowPressureTolerance + amount);
if (ent.Comp.LowPressureTolerance > ent.Comp.HighPressureTolerance)
ent.Comp.HighPressureTolerance = ent.Comp.LowPressureTolerance;
DirtyFields(ent, null, nameof(ent.Comp.LowPressureTolerance), nameof(ent.Comp.HighPressureTolerance));
}
/// <summary>
/// Adjusts maximum pressure tolerance for plant growth.
/// Ensures pressure high is not less than low.
/// </summary>
[PublicAPI]
public void AdjustHighPressureTolerance(Entity<PlantAtmosphericComponent?> ent, float amount)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
ent.Comp.HighPressureTolerance = MathF.Max(0f, ent.Comp.HighPressureTolerance + amount);
if (ent.Comp.HighPressureTolerance < ent.Comp.LowPressureTolerance)
ent.Comp.LowPressureTolerance = ent.Comp.HighPressureTolerance;
DirtyFields(ent, null, nameof(ent.Comp.HighPressureTolerance), nameof(ent.Comp.LowPressureTolerance));
}
}