CatStation/Content.Shared/Botany/Systems/PlantWeedPestSystem.cs
ahandleman c46f74c355
Various small botany bugfixes and reverts to prior behavior (#45842)
* Various small botany bugfixes and reverts to prior behavior

* oops rainbow cannabis needs it too

* oops, need to keep remove around for stuff like phal and plant-b-gone

* fix comment

* Fixed to make it selectable

* No need for plantPhalaxEntityEffect

* Ok moving removing this to its own PR because actually the guidebook stuff is weird and I wanna get this out the door.

* endless fixes to the botany

* renaming methods

* Refactored to remove PlantPhalanximineEntityEffectSystem because it's just a trait.

* removed the actual file

* renamed to noun/description for clarity

---------

Co-authored-by: Pok245 <113675512+Pok27@users.noreply.github.com>
2026-09-06 17:46:38 +00:00

76 lines
2.8 KiB
C#

using Content.Shared.Botany.Components;
using Content.Shared.Botany.Events;
using Content.Shared.Random.Helpers;
using JetBrains.Annotations;
using Robust.Shared.Timing;
namespace Content.Shared.Botany.Systems;
/// <summary>
/// Manages weed growth and pest damage per growth tick, and handles tray-level
/// weed spawning.
/// </summary>
public sealed partial class PlantWeedPestSystem : EntitySystem
{
[Dependency] private IGameTiming _timing = default!;
[Dependency] private BotanySystem _botany = default!;
[Dependency] private PlantMutationSystem _mutation = default!;
[Dependency] private PlantHolderSystem _plantHolder = default!;
[Dependency] private PlantTraySystem _plantTray = default!;
[Dependency] private EntityQuery<PlantTrayComponent> _trayQuery;
[SubscribeLocalEvent]
private void OnCrossPollinate(Entity<PlantWeedPestComponent> ent, ref PlantCrossPollinateEvent args)
{
if (!_botany.TryGetPlantComponent<PlantWeedPestComponent>(args.PollenData, args.PollenProtoId, out var pollenData))
return;
_mutation.CrossFloat(ref ent.Comp.WeedTolerance, pollenData.WeedTolerance);
_mutation.CrossFloat(ref ent.Comp.PestTolerance, pollenData.PestTolerance);
Dirty(ent);
}
[SubscribeLocalEvent]
private void OnPlantGrow(Entity<PlantWeedPestComponent> ent, ref PlantGrowEvent args)
{
var trayUid = args.Tray;
if (!_trayQuery.TryComp(trayUid, out var tray))
return;
if (SharedRandomExtensions.PredictedProb(_timing, ent.Comp.PestGrowthChance, GetNetEntity(ent)))
_plantTray.AdjustPest((trayUid, tray), ent.Comp.PestGrowthAmount);
if (tray.WeedLevel > ent.Comp.WeedTolerance)
_plantHolder.AdjustsHealth(ent.Owner, -ent.Comp.WeedDamageAmount);
if (tray.PestLevel > ent.Comp.PestTolerance)
_plantHolder.AdjustsHealth(ent.Owner, -ent.Comp.PestDamageAmount);
}
/// <summary>
/// Adjusts maximum weed level the plant can tolerate before taking damage.
/// </summary>
[PublicAPI]
public void AdjustWeedTolerance(Entity<PlantWeedPestComponent?> ent, float amount)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
ent.Comp.WeedTolerance = MathF.Max(0f, ent.Comp.WeedTolerance + amount);
DirtyField(ent, nameof(ent.Comp.WeedTolerance));
}
/// <summary>
/// Adjusts maximum pest level the plant can tolerate before taking damage.
/// </summary>
[PublicAPI]
public void AdjustPestTolerance(Entity<PlantWeedPestComponent?> ent, float amount)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
ent.Comp.PestTolerance = MathF.Max(0f, ent.Comp.PestTolerance + amount);
DirtyField(ent, nameof(ent.Comp.PestTolerance));
}
}