CatStation/Content.Shared/Botany/Systems/PlantWeedPestSystem.cs
Pok 6f6a5694c8
Botany refactor (#44576)
* Restarting files from scratch

* reduce file count, more progress

* Additional partial work

* update 1

* update 2

* TODO execution

* fix

* Update PlantGrowthComponent.cs

* fix 1

* growth correction

* PlantGrowthComponent

* update 99

* last update

* oops

* Update vegan-meatball.yml

* Data loss

* ToxinsComponent

* Default components

* minor fix

* PlantTraitsComponent

* fix error

* fix error 2

* Copy growth components

* last update within this PR

* AutoHarvestGrowth remote

* Viable

* fix

* Fix growth rate

* Improvements to the YAML

* merge update

* fix

* code cleanup

* TODO

* fix

* oops

* oops 2

* more TODO

* fix names

* fix names oops

* Harvest bug fixes

* fix tests

* refactor: cleanup after mering master

* Update ConsumeExudeGasGrowthSystem.cs

* refactor: make this piece of happiness and ponies work

* review

* oops

* fix <summary>

* Separation of plant components into PlantComponent and PlantTraitsComponent and cleaning

* EnsureUniqueSeed

* refactor: change Resolve to TryComp where appropriate

* refactor: review comments - try get for components, clenaups

* refactor: minor yaml cleanups

* fixing trifles

* botany-rework-part-3

* API and mutations

* minor fixes

* Update WeedPestGrowthSystem.cs

* Update plants.yml

* PlantChemicals

* YAMLLinter

* review and some lost code

* YAMLLinter part 2

* plants.yml

* Aaaa tests

* seedId

* clone plant component

* Update clone.yml

* refactor: remove suppress possible null reference exception

* refactor: changed HasPlantAlive to TryGetAlivePlant, minor cleanup

* Separation of tray and plant

* oops

* PlantingPlant

* a little more cleaning

* oops 2

* botany-rework-part-4

* predict and API

* Field OldAgeDamage

* oops

* YMAL

* YMAL 2

* YMAAAAAL

* Update PlantToxinsSystem.cs

* review

* Update randomMutations.yml

* minor fix design

* Updates the plants visuals not every frame

* bug fixes

* some fixes

* bugfix and renames

* Dirty

* Replace ComponentRegistry

* unnecessary API

* fix merge

* build

* build 2

* Review by AJCM

* del PlantDataComponent and fix harvest

* fix all

* final review

* Update PlantTrayVisualizerSystem.cs

* fix merge

* Update PlantTraitsComponent.cs

* Traits LocId fix

* Update SpawnEntitiesBehavior.cs

* aaaaaaaaa

* fix all part 2

* PlantDataComponent revert

* aoao

* fix all part 3

* Update PlantTraitsComponent.cs

* Update clone.yml

* Reviews

---------

Co-authored-by: PraxisMapper <praxismapper@gmail.com>
Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
2026-08-08 21:58:01 +00:00

70 lines
2.5 KiB
C#

using JetBrains.Annotations;
using Content.Shared.Botany.Components;
using Content.Shared.Botany.Events;
using Robust.Shared.Random;
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 BotanySystem _botany = default!;
[Dependency] private IRobustRandom _random = default!;
[Dependency] private PlantMutationSystem _mutation = default!;
[Dependency] private PlantHolderSystem _plantHolder = default!;
[Dependency] private PlantTraySystem _plantTray = default!;
[SubscribeLocalEvent]
private void OnCrossPollinate(Entity<PlantWeedPestComponent> ent, ref PlantCrossPollinateEvent args)
{
if (!_botany.TryGetPlantComponent<PlantWeedPestComponent>(args.PollenData, args.PollenProtoId, out var pollenData))
return;
_mutation.CrossFloat(ent, ref ent.Comp.WeedTolerance, pollenData.WeedTolerance);
_mutation.CrossFloat(ent, ref ent.Comp.PestTolerance, pollenData.PestTolerance);
Dirty(ent);
}
[SubscribeLocalEvent]
private void OnPlantGrow(Entity<PlantWeedPestComponent> ent, ref PlantGrowEvent args)
{
var trayUid = GetEntity(args.Tray);
if (!TryComp<PlantTrayComponent>(trayUid, out var tray))
return;
if (_random.Prob(ent.Comp.PestGrowthChance))
_plantTray.AdjustPest((trayUid, tray), ent.Comp.PestGrowthAmount);
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));
}
}