Files
OldThink/Content.Server/Botany/Systems/BotanySwabSystem.cs

84 lines
2.8 KiB
C#
Raw Normal View History

2022-10-15 23:25:41 -07:00
using Content.Server.Botany.Components;
using Content.Server.Popups;
using Content.Shared.DoAfter;
2022-10-15 23:25:41 -07:00
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Swab;
2022-10-15 23:25:41 -07:00
namespace Content.Server.Botany.Systems;
public sealed class BotanySwabSystem : EntitySystem
2022-10-15 23:25:41 -07:00
{
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly MutationSystem _mutationSystem = default!;
2022-10-15 23:25:41 -07:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BotanySwabComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<BotanySwabComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<BotanySwabComponent, BotanySwabDoAfterEvent>(OnDoAfter);
}
2022-10-15 23:25:41 -07:00
/// <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)
2022-10-15 23:25:41 -07:00
{
if (swab.SeedData != null)
args.PushMarkup(Loc.GetString("swab-used"));
else
args.PushMarkup(Loc.GetString("swab-unused"));
2022-10-15 23:25:41 -07:00
}
}
2022-10-15 23:25:41 -07:00
/// <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;
2022-10-15 23:25:41 -07:00
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, swab.SwabDelay, new BotanySwabDoAfterEvent(), uid, target: args.Target, used: uid)
2022-10-15 23:25:41 -07:00
{
Broadcast = true,
BreakOnTargetMove = true,
BreakOnUserMove = true,
NeedHand = true
});
}
2022-10-15 23:25:41 -07:00
/// <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;
2022-10-15 23:25:41 -07:00
if (swab.SeedData == null)
2022-10-15 23:25:41 -07:00
{
// Pick up pollen
swab.SeedData = plant.Seed;
_popupSystem.PopupEntity(Loc.GetString("botany-swab-from"), args.Args.Target.Value, args.Args.User);
2022-10-15 23:25:41 -07:00
}
else
2022-10-15 23:25:41 -07:00
{
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);
2022-10-15 23:25:41 -07:00
}
args.Handled = true;
2022-10-15 23:25:41 -07:00
}
}