2024-03-05 03:13:50 +00:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2021-11-03 16:48:03 -07:00
|
|
|
using Content.Shared.FixedPoint;
|
2023-03-24 05:00:38 +00:00
|
|
|
using Content.Shared.Popups;
|
2023-07-09 21:24:30 +02:00
|
|
|
using Robust.Shared.Random;
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2024-03-05 03:13:50 +00:00
|
|
|
namespace Content.Shared.Chemistry.EntitySystems;
|
2023-03-24 05:00:38 +00:00
|
|
|
|
|
|
|
|
public sealed class RehydratableSystem : EntitySystem
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2023-07-09 21:24:30 +02:00
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
2024-03-05 03:13:50 +00:00
|
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutions = default!;
|
|
|
|
|
[Dependency] private readonly SharedTransformSystem _xform = default!;
|
2023-03-24 05:00:38 +00:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2023-03-24 05:00:38 +00:00
|
|
|
base.Initialize();
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
SubscribeLocalEvent<RehydratableComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
2023-03-24 05:00:38 +00:00
|
|
|
}
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2024-03-05 03:13:50 +00:00
|
|
|
private void OnSolutionChange(Entity<RehydratableComponent> ent, ref SolutionContainerChangedEvent args)
|
2023-03-24 05:00:38 +00:00
|
|
|
{
|
2024-03-05 03:13:50 +00:00
|
|
|
var quantity = _solutions.GetTotalPrototypeQuantity(ent, ent.Comp.CatalystPrototype);
|
|
|
|
|
if (quantity != FixedPoint2.Zero && quantity >= ent.Comp.CatalystMinimum)
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2024-03-05 03:13:50 +00:00
|
|
|
Expand(ent);
|
2021-09-06 15:49:44 +02:00
|
|
|
}
|
2023-03-24 05:00:38 +00:00
|
|
|
}
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2023-03-24 05:00:38 +00:00
|
|
|
// Try not to make this public if you can help it.
|
2024-03-05 03:13:50 +00:00
|
|
|
private void Expand(Entity<RehydratableComponent> ent)
|
2023-03-24 05:00:38 +00:00
|
|
|
{
|
2024-03-05 03:13:50 +00:00
|
|
|
var (uid, comp) = ent;
|
2023-03-24 05:00:38 +00:00
|
|
|
|
2023-07-09 21:24:30 +02:00
|
|
|
var randomMob = _random.Pick(comp.PossibleSpawns);
|
|
|
|
|
|
|
|
|
|
var target = Spawn(randomMob, Transform(uid).Coordinates);
|
2024-03-05 03:13:50 +00:00
|
|
|
_popup.PopupEntity(Loc.GetString("rehydratable-component-expands-message", ("owner", uid)), target);
|
2023-07-09 21:24:30 +02:00
|
|
|
|
2024-03-05 03:13:50 +00:00
|
|
|
_xform.AttachToGridOrMap(target);
|
2023-03-24 05:00:38 +00:00
|
|
|
var ev = new GotRehydratedEvent(target);
|
|
|
|
|
RaiseLocalEvent(uid, ref ev);
|
|
|
|
|
|
|
|
|
|
// prevent double hydration while queued
|
|
|
|
|
RemComp<RehydratableComponent>(uid);
|
|
|
|
|
QueueDel(uid);
|
2021-09-06 15:49:44 +02:00
|
|
|
}
|
|
|
|
|
}
|