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

48 lines
1.5 KiB
C#
Raw Normal View History

2023-03-24 05:00:38 +00:00
using Content.Server.Chemistry.Components;
using Content.Shared.FixedPoint;
2023-03-24 05:00:38 +00:00
using Content.Shared.Popups;
using Robust.Shared.Random;
2023-03-24 05:00:38 +00:00
namespace Content.Server.Chemistry.EntitySystems;
public sealed class RehydratableSystem : EntitySystem
{
2023-03-24 05:00:38 +00:00
[Dependency] private readonly SharedPopupSystem _popups = default!;
[Dependency] private readonly SolutionContainerSystem _solutions = default!;
[Dependency] private readonly IRobustRandom _random = default!;
2023-03-24 05:00:38 +00:00
public override void Initialize()
{
2023-03-24 05:00:38 +00:00
base.Initialize();
2023-03-24 05:00:38 +00:00
SubscribeLocalEvent<RehydratableComponent, SolutionChangedEvent>(OnSolutionChange);
}
2023-03-24 05:00:38 +00:00
private void OnSolutionChange(EntityUid uid, RehydratableComponent comp, SolutionChangedEvent args)
{
var quantity = _solutions.GetReagentQuantity(uid, comp.CatalystPrototype);
if (quantity != FixedPoint2.Zero && quantity >= comp.CatalystMinimum)
{
2023-03-24 05:00:38 +00:00
Expand(uid, comp);
}
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(EntityUid uid, RehydratableComponent comp)
{
_popups.PopupEntity(Loc.GetString("rehydratable-component-expands-message", ("owner", uid)), uid);
var randomMob = _random.Pick(comp.PossibleSpawns);
var target = Spawn(randomMob, Transform(uid).Coordinates);
2023-03-24 05:00:38 +00:00
Transform(target).AttachToGridOrMap();
var ev = new GotRehydratedEvent(target);
RaiseLocalEvent(uid, ref ev);
// prevent double hydration while queued
RemComp<RehydratableComponent>(uid);
QueueDel(uid);
}
}