2022-04-16 17:32:35 +12:00
|
|
|
using Content.Server.Botany.Components;
|
2022-02-06 13:14:41 -07:00
|
|
|
using Content.Server.Popups;
|
2022-05-27 10:36:12 +10:00
|
|
|
using Content.Server.Power.EntitySystems;
|
2022-02-06 13:14:41 -07:00
|
|
|
using Content.Shared.Interaction;
|
2022-07-09 02:09:52 -07:00
|
|
|
using Content.Shared.Popups;
|
2022-02-06 13:14:41 -07:00
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Botany.Systems;
|
|
|
|
|
|
|
|
|
|
public sealed class SeedExtractorSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
|
|
|
[Dependency] private readonly BotanySystem _botanySystem = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<SeedExtractorComponent, InteractUsingEvent>(OnInteractUsing);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 00:26:02 +02:00
|
|
|
private void OnInteractUsing(EntityUid uid, SeedExtractorComponent seedExtractor, InteractUsingEvent args)
|
2022-02-06 13:14:41 -07:00
|
|
|
{
|
2022-05-27 10:36:12 +10:00
|
|
|
if (!this.IsPowered(uid, EntityManager))
|
2022-02-06 13:14:41 -07:00
|
|
|
return;
|
|
|
|
|
|
2024-01-22 17:13:04 -05:00
|
|
|
if (!TryComp(args.Used, out ProduceComponent? produce))
|
|
|
|
|
return;
|
2022-10-15 23:25:41 -07:00
|
|
|
if (!_botanySystem.TryGetSeed(produce, out var seed) || seed.Seedless)
|
|
|
|
|
{
|
|
|
|
|
_popupSystem.PopupCursor(Loc.GetString("seed-extractor-component-no-seeds",("name", args.Used)),
|
2022-12-19 10:41:47 +13:00
|
|
|
args.User, PopupType.MediumCaution);
|
2022-05-27 10:36:12 +10:00
|
|
|
return;
|
2022-10-15 23:25:41 -07:00
|
|
|
}
|
2022-02-06 13:14:41 -07:00
|
|
|
|
2022-05-27 10:36:12 +10:00
|
|
|
_popupSystem.PopupCursor(Loc.GetString("seed-extractor-component-interact-message",("name", args.Used)),
|
2022-12-19 10:41:47 +13:00
|
|
|
args.User, PopupType.Medium);
|
2022-02-06 13:14:41 -07:00
|
|
|
|
2022-05-27 10:36:12 +10:00
|
|
|
QueueDel(args.Used);
|
2022-02-06 13:14:41 -07:00
|
|
|
|
2024-01-22 17:13:04 -05:00
|
|
|
var amount = _random.Next(seedExtractor.BaseMinSeeds, seedExtractor.BaseMaxSeeds + 1);
|
2022-05-27 10:36:12 +10:00
|
|
|
var coords = Transform(uid).Coordinates;
|
2022-02-06 13:14:41 -07:00
|
|
|
|
2022-10-23 00:26:02 +02:00
|
|
|
if (amount > 1)
|
2022-05-27 10:36:12 +10:00
|
|
|
seed.Unique = false;
|
2022-04-16 17:32:35 +12:00
|
|
|
|
2022-10-23 00:26:02 +02:00
|
|
|
for (var i = 0; i < amount; i++)
|
2022-05-27 10:36:12 +10:00
|
|
|
{
|
2023-03-06 02:37:57 +00:00
|
|
|
_botanySystem.SpawnSeedPacket(seed, coords, args.User);
|
2022-02-06 13:14:41 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|