* Add BreakOnDropItem, update do afters, remove unnecessary declarations * bola * Changed my mind about the nuke * gennies too * Make the comments more clear. * Sorry for the trailing commas * Revert "Sorry for the trailing commas" This reverts commit e60fd9a30977393df3344948e6d5c0ce035723cd. --------- Co-authored-by: plykiya <plykiya@protonmail.com>
83 lines
2.8 KiB
C#
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;
|
|
}
|
|
}
|
|
|