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

75 lines
2.4 KiB
C#

using Content.Shared.Botany.Components;
using Content.Shared.Botany.Events;
using Content.Shared.Botany.Systems;
using Content.Shared.Burial.Components;
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 using a shovel on a plant.
/// </summary>
public sealed partial class BotanyShovelSystem : EntitySystem
{
[Dependency] private PlantSystem _plant = default!;
[Dependency] private PlantTraySystem _plantTray = default!;
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private EntityQuery<PlantComponent> _plantQuery;
[Dependency] private EntityQuery<PlantTrayComponent> _trayQuery;
[SubscribeLocalEvent]
private void OnAfterInteract(Entity<ShovelComponent> ent, ref AfterInteractEvent args)
{
if (args.Target == null || args.Handled || !args.CanReach)
return;
// Allow interacting with either the plant or the tray.
var target = args.Target.Value;
if (_plantQuery.HasComp(target))
{
if (!_plant.TryGetTray(target, out var tray))
return;
target = tray.Owner;
}
else if (!_trayQuery.HasComp(target))
return;
var ev = new TrayShovelAttemptEvent(ent, args.User);
RaiseLocalEvent(target, ref ev);
args.Handled = true;
}
[SubscribeLocalEvent]
private void OnTrayShovelAttempt(Entity<PlantTrayComponent> ent, ref TrayShovelAttemptEvent args)
{
if (args.Cancelled)
return;
if (!_plantTray.TryGetPlant(ent.AsNullable(), out var plantUid))
{
_popup.PopupCursor(
Loc.GetString("plant-shovel-component-no-plant-popup", ("name", ent.Owner)),
args.User);
return;
}
_popup.PopupCursor(
Loc.GetString("plant-shovel-component-remove-plant-popup", ("name", ent.Owner)),
args.User,
PopupType.Medium);
_popup.PopupEntity(
Loc.GetString("plant-shovel-component-remove-plant-others-popup",
("name", Identity.Entity(args.User, EntityManager))),
ent.Owner,
Filter.PvsExcept(args.User),
true);
_plant.RemovePlant(plantUid.Value);
}
}