Files
OldThink/Content.Shared/Chemistry/EntitySystems/RehydratableSystem.cs

50 lines
1.7 KiB
C#
Raw Normal View History

using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
2023-03-24 05:00:38 +00:00
using Content.Shared.Popups;
using Robust.Shared.Random;
namespace Content.Shared.Chemistry.EntitySystems;
2023-03-24 05:00:38 +00:00
public sealed class RehydratableSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[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()
{
2023-03-24 05:00:38 +00:00
base.Initialize();
SubscribeLocalEvent<RehydratableComponent, SolutionContainerChangedEvent>(OnSolutionChange);
2023-03-24 05:00:38 +00:00
}
private void OnSolutionChange(Entity<RehydratableComponent> ent, ref SolutionContainerChangedEvent args)
2023-03-24 05:00:38 +00:00
{
var quantity = _solutions.GetTotalPrototypeQuantity(ent, ent.Comp.CatalystPrototype);
if (quantity != FixedPoint2.Zero && quantity >= ent.Comp.CatalystMinimum)
{
Expand(ent);
}
2023-03-24 05:00:38 +00:00
}
2023-03-24 05:00:38 +00:00
// Try not to make this public if you can help it.
private void Expand(Entity<RehydratableComponent> ent)
2023-03-24 05:00:38 +00:00
{
var (uid, comp) = ent;
2023-03-24 05:00:38 +00:00
var randomMob = _random.Pick(comp.PossibleSpawns);
var target = Spawn(randomMob, Transform(uid).Coordinates);
_popup.PopupEntity(Loc.GetString("rehydratable-component-expands-message", ("owner", uid)), target);
_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);
}
}