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]
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class AddComponentSpecial : JobSpecial
|
2021-09-16 15:17:19 +02:00
|
|
|
{
|
2022-02-16 08:24:38 -06:00
|
|
|
[DataField("components")]
|
|
|
|
|
[AlwaysPushInheritance]
|
2023-08-22 18:14:33 -07:00
|
|
|
public ComponentRegistry Components { get; private set; } = 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-08-05 00:17:16 +02:00
|
|
|
var temp = (object) component;
|
2022-11-27 19:25:55 +01:00
|
|
|
serializationManager.CopyTo(data.Component, ref temp);
|
2024-01-03 19:04:31 -05:00
|
|
|
entityManager.RemoveComponent(mob, temp!.GetType());
|
|
|
|
|
entityManager.AddComponent(mob, (Component) temp);
|
2022-02-16 08:24:38 -06:00
|
|
|
}
|
2021-09-16 15:17:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|