CatStation/Content.Shared/Botany/Items/Systems/BotanyProduceSystem.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

80 lines
3.3 KiB
C#

using Content.Shared.Botany.Components;
using Content.Shared.Botany.Events;
using Content.Shared.Botany.Items.Components;
using Content.Shared.Botany.Systems;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.FixedPoint;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Robust.Shared.Player;
namespace Content.Shared.Botany.Items.Systems;
/// <summary>
/// System for taking a sample of a plant.
/// </summary>
public sealed partial class BotanyProduceSystem : EntitySystem
{
[Dependency] private BotanySystem _botany = default!;
[Dependency] private PlantSystem _plant = default!;
[Dependency] private PlantTraySystem _plantTray = default!;
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private EntityQuery<PlantTrayComponent> _trayQuery;
[SubscribeLocalEvent]
private void OnAfterInteract(Entity<ProduceComponent> ent, ref AfterInteractEvent args)
{
if (args.Target == null || args.Handled || !args.CanReach || !_trayQuery.HasComp(args.Target))
return;
var ev = new CompostingProduceAttemptEvent(ent, args.User);
RaiseLocalEvent(args.Target.Value, ref ev);
args.Handled = true;
}
[SubscribeLocalEvent]
private void OnCompostingProduceAttempt(Entity<PlantTrayComponent> ent, ref CompostingProduceAttemptEvent args)
{
if (args.Cancelled)
return;
_popup.PopupCursor(Loc.GetString("plant-produce-component-compost-popup",
("owner", ent.Owner),
("usingItem", args.Produce.Owner)),
args.User,
PopupType.Medium);
_popup.PopupEntity(Loc.GetString("plant-produce-component-compost-others-popup",
("user", Identity.Entity(args.User, EntityManager)),
("usingItem", args.Produce.Owner),
("owner", ent.Owner)),
ent.Owner,
Filter.PvsExcept(args.User),
true);
if (_solutionContainer.TryGetSolution(args.Produce.Owner, args.Produce.Comp.TargetSolution, out var soln2, out var solution2))
{
if (_solutionContainer.ResolveSolution(ent.Owner, ent.Comp.SoilSolutionName, ref ent.Comp.SoilSolution, out var solution1))
{
// We try to fit as much of the composted plant's contained solution into the hydroponics tray as we can,
// since the plant will be consumed anyway.
var fillAmount = FixedPoint2.Min(solution2.Volume, solution1.AvailableVolume);
_solutionContainer.TryAddSolution(ent.Comp.SoilSolution.Value, _solutionContainer.SplitSolution(soln2.Value, fillAmount));
if (_plantTray.TryGetPlant(ent.AsNullable(), out var plantUid))
_plant.ForceUpdate(plantUid.Value);
}
}
if (_botany.TryGetPlantComponent<PlantComponent>(args.Produce.Comp.PlantData, args.Produce.Comp.PlantProtoId, out var compostPlant))
{
var nutrientBonus = compostPlant.Potency / args.Produce.Comp.NutrientDivider;
_plantTray.AdjustNutrient(ent.AsNullable(), nutrientBonus);
}
PredictedQueueDel(args.Produce.Owner);
}
}