2021-09-16 15:17:19 +02:00
|
|
|
using Content.Shared.Roles;
|
|
|
|
|
using JetBrains.Annotations;
|
2022-02-16 08:24:38 -06:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Serialization.Manager;
|
2021-09-16 15:17:19 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Jobs
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class AddComponentSpecial : JobSpecial
|
|
|
|
|
{
|
2022-02-16 08:24:38 -06:00
|
|
|
|
|
|
|
|
[DataField("components")]
|
|
|
|
|
[AlwaysPushInheritance]
|
|
|
|
|
public EntityPrototype.ComponentRegistry Components { get; } = new();
|
2021-09-16 15:17:19 +02:00
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
public override void AfterEquip(EntityUid mob)
|
2021-09-16 15:17:19 +02:00
|
|
|
{
|
2022-02-16 08:24:38 -06:00
|
|
|
// now its a registry of components, still throws i bet.
|
|
|
|
|
// TODO: This is hot garbage and probably needs an engine change to not be a POS.
|
|
|
|
|
var factory = IoCManager.Resolve<IComponentFactory>();
|
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
var serializationManager = IoCManager.Resolve<ISerializationManager>();
|
|
|
|
|
|
|
|
|
|
foreach (var (name, data) in Components)
|
|
|
|
|
{
|
|
|
|
|
var component = (Component) factory.GetComponent(name);
|
|
|
|
|
component.Owner = mob;
|
2021-09-16 15:17:19 +02:00
|
|
|
|
2022-02-16 08:24:38 -06:00
|
|
|
var copied = (Component?) serializationManager.Copy(data, component, null);
|
|
|
|
|
if (copied != null)
|
|
|
|
|
entityManager.AddComponent(mob, copied);
|
|
|
|
|
}
|
2021-09-16 15:17:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|