using Content.Shared.Xenoarchaeology.Artifact.XAE.Components;
using Robust.Shared.Timing;
namespace Content.Shared.Xenoarchaeology.Artifact.XAE;
///
/// System for applying component-registry when artifact effect is activated.
///
public sealed class XAEApplyComponentsSystem : BaseXAESystem
{
[Dependency] private readonly IGameTiming _timing = default!;
///
protected override void OnActivated(Entity ent, ref XenoArtifactNodeActivatedEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
var artifact = args.Artifact;
foreach (var registry in ent.Comp.Components)
{
var componentType = registry.Value.Component.GetType();
if (!ent.Comp.ApplyIfAlreadyHave && HasComp(artifact, componentType))
{
continue;
}
if (ent.Comp.RefreshOnReactivate)
{
RemComp(artifact, componentType);
}
var clone = EntityManager.ComponentFactory.GetComponent(registry.Value);
AddComp(artifact, clone);
}
}
}