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(OnExamined); SubscribeLocalEvent(OnAfterInteract); SubscribeLocalEvent(OnDoAfter); } /// /// This handles swab examination text /// so you can tell if they are used or not. /// 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")); } } /// /// Handles swabbing a plant. /// private void OnAfterInteract(EntityUid uid, BotanySwabComponent swab, AfterInteractEvent args) { if (args.Target == null || !args.CanReach || !HasComp(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, }); } /// /// Save seed data or cross-pollenate. /// private void OnDoAfter(EntityUid uid, BotanySwabComponent swab, DoAfterEvent args) { if (args.Cancelled || args.Handled || !TryComp(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; } }