2023-06-30 18:57:28 -04:00
|
|
|
using Content.Server.Chemistry.Components;
|
2023-10-14 09:45:28 -07:00
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2023-06-30 18:57:28 -04:00
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2024-06-16 15:38:53 -04:00
|
|
|
using Content.Shared.NameModifier.EntitySystems;
|
2023-06-30 18:57:28 -04:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Chemistry.EntitySystems;
|
|
|
|
|
|
|
|
|
|
public sealed class TransformableContainerSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2024-09-02 06:26:04 -05:00
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionsSystem = default!;
|
2023-06-30 18:57:28 -04:00
|
|
|
[Dependency] private readonly MetaDataSystem _metadataSystem = default!;
|
2024-06-16 15:38:53 -04:00
|
|
|
[Dependency] private readonly NameModifierSystem _nameMod = default!;
|
2023-06-30 18:57:28 -04:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<TransformableContainerComponent, MapInitEvent>(OnMapInit);
|
2023-12-29 04:47:43 -08:00
|
|
|
SubscribeLocalEvent<TransformableContainerComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
2024-06-16 15:38:53 -04:00
|
|
|
SubscribeLocalEvent<TransformableContainerComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
|
2023-06-30 18:57:28 -04:00
|
|
|
}
|
|
|
|
|
|
2024-06-16 15:38:53 -04:00
|
|
|
private void OnMapInit(Entity<TransformableContainerComponent> entity, ref MapInitEvent args)
|
2023-06-30 18:57:28 -04:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
var meta = MetaData(entity.Owner);
|
|
|
|
|
if (string.IsNullOrEmpty(entity.Comp.InitialDescription))
|
2023-06-30 18:57:28 -04:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
entity.Comp.InitialDescription = meta.EntityDescription;
|
2023-06-30 18:57:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnSolutionChange(Entity<TransformableContainerComponent> entity, ref SolutionContainerChangedEvent args)
|
2023-06-30 18:57:28 -04:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
if (!_solutionsSystem.TryGetFitsInDispenser(entity.Owner, out _, out var solution))
|
2023-06-30 18:57:28 -04:00
|
|
|
return;
|
2023-12-29 04:47:43 -08:00
|
|
|
|
2023-06-30 18:57:28 -04:00
|
|
|
//Transform container into initial state when emptied
|
2023-12-29 04:47:43 -08:00
|
|
|
if (entity.Comp.CurrentReagent != null && solution.Contents.Count == 0)
|
2023-06-30 18:57:28 -04:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
CancelTransformation(entity);
|
2023-06-30 18:57:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//the biggest reagent in the solution decides the appearance
|
|
|
|
|
var reagentId = solution.GetPrimaryReagentId();
|
|
|
|
|
|
2025-07-14 17:03:41 -04:00
|
|
|
//If biggest reagent didn't change - don't change anything at all
|
|
|
|
|
if (entity.Comp.CurrentReagent != null && entity.Comp.CurrentReagent == reagentId?.Prototype)
|
2023-06-30 18:57:28 -04:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Only reagents with spritePath property can change appearance of transformable containers!
|
2023-09-05 09:55:10 +12:00
|
|
|
if (!string.IsNullOrWhiteSpace(reagentId?.Prototype)
|
|
|
|
|
&& _prototypeManager.TryIndex(reagentId.Value.Prototype, out ReagentPrototype? proto))
|
2023-06-30 18:57:28 -04:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
var metadata = MetaData(entity.Owner);
|
|
|
|
|
_metadataSystem.SetEntityDescription(entity.Owner, proto.LocalizedDescription, metadata);
|
|
|
|
|
entity.Comp.CurrentReagent = proto;
|
|
|
|
|
entity.Comp.Transformed = true;
|
2023-06-30 18:57:28 -04:00
|
|
|
}
|
2024-06-16 15:38:53 -04:00
|
|
|
|
|
|
|
|
_nameMod.RefreshNameModifiers(entity.Owner);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRefreshNameModifiers(Entity<TransformableContainerComponent> entity, ref RefreshNameModifiersEvent args)
|
|
|
|
|
{
|
2025-09-09 18:17:56 +02:00
|
|
|
if (_prototypeManager.Resolve(entity.Comp.CurrentReagent, out var currentReagent))
|
2024-06-16 15:38:53 -04:00
|
|
|
{
|
|
|
|
|
args.AddModifier("transformable-container-component-glass", priority: -1, ("reagent", currentReagent.LocalizedName));
|
|
|
|
|
}
|
2023-06-30 18:57:28 -04:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void CancelTransformation(Entity<TransformableContainerComponent> entity)
|
2023-06-30 18:57:28 -04:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
entity.Comp.CurrentReagent = null;
|
|
|
|
|
entity.Comp.Transformed = false;
|
2023-06-30 18:57:28 -04:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
var metadata = MetaData(entity);
|
2023-06-30 18:57:28 -04:00
|
|
|
|
2024-06-16 15:38:53 -04:00
|
|
|
_nameMod.RefreshNameModifiers(entity.Owner);
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
if (!string.IsNullOrEmpty(entity.Comp.InitialDescription))
|
2023-06-30 18:57:28 -04:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
_metadataSystem.SetEntityDescription(entity.Owner, entity.Comp.InitialDescription, metadata);
|
2023-06-30 18:57:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|