Files
tbd-station-14/Content.Server/Botany/Systems/BotanySwabSystem.cs
nikthechampiongr 362d56981f Simplify DoAfterArgs behavior for movement and distance checks (#25226)
* Merge BreakOnWeightlessMove and BreakOnMove. Provide different theshold for weightless movement.

* Adjust WeightlessMovementThresholds. Put a thing I forgot to put in the doafterargs.

* Make DoAfterArgs only use OnMove to determine whether to check for
movement and MoveThreshold to determine the threshold regardless of
weightlessness. Gave DistanceThreshold a default value which will always
be checked now.

* Fix issue introduced by merge.

* Use interaction system for determining whether a distance is within range

* Fix incorrect doafter args introduced by previous merge.
Forgor to commit these.

* Exorcise ghost.

The execution system should have been deleted when I merged previously.
For a reason I cannot comprehend it came back, but only the execution
system.

* Exorcise ghost Pt. 2

* Allow for movement check to be overriden in zero g and adjust doafter args where needed.

You can now override checking for movement in zero g with the BreakOnWeightlessMove bool. By default it will check.
The following doafters were made to ignore the movement check in zero g:
- Healing yourself with healing items,
- Removing embedded projectiles,
- Using tools like welders and crowbars

* Adjust distance for cuffing/uncuffing to work. Make injections not break on weightless movement.

* Fix evil incorrect and uneeded comments
2024-03-19 21:09:00 +11:00

83 lines
2.8 KiB
C#

using Content.Server.Botany.Components;
using Content.Server.Popups;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Swab;
namespace Content.Server.Botany.Systems;
public sealed class BotanySwabSystem : EntitySystem
{
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly MutationSystem _mutationSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BotanySwabComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<BotanySwabComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<BotanySwabComponent, BotanySwabDoAfterEvent>(OnDoAfter);
}
/// <summary>
/// This handles swab examination text
/// so you can tell if they are used or not.
/// </summary>
private void OnExamined(EntityUid uid, BotanySwabComponent swab, ExaminedEvent args)
{
if (args.IsInDetailsRange)
{
if (swab.SeedData != null)
args.PushMarkup(Loc.GetString("swab-used"));
else
args.PushMarkup(Loc.GetString("swab-unused"));
}
}
/// <summary>
/// Handles swabbing a plant.
/// </summary>
private void OnAfterInteract(EntityUid uid, BotanySwabComponent swab, AfterInteractEvent args)
{
if (args.Target == null || !args.CanReach || !HasComp<PlantHolderComponent>(args.Target))
return;
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, swab.SwabDelay, new BotanySwabDoAfterEvent(), uid, target: args.Target, used: uid)
{
Broadcast = true,
BreakOnMove = true,
NeedHand = true
});
}
/// <summary>
/// Save seed data or cross-pollenate.
/// </summary>
private void OnDoAfter(EntityUid uid, BotanySwabComponent swab, DoAfterEvent args)
{
if (args.Cancelled || args.Handled || !TryComp<PlantHolderComponent>(args.Args.Target, out var plant))
return;
if (swab.SeedData == null)
{
// Pick up pollen
swab.SeedData = plant.Seed;
_popupSystem.PopupEntity(Loc.GetString("botany-swab-from"), args.Args.Target.Value, args.Args.User);
}
else
{
var old = plant.Seed;
if (old == null)
return;
plant.Seed = _mutationSystem.Cross(swab.SeedData, old); // Cross-pollenate
swab.SeedData = old; // Transfer old plant pollen to swab
_popupSystem.PopupEntity(Loc.GetString("botany-swab-to"), args.Args.Target.Value, args.Args.User);
}
args.Handled = true;
}
}