Make recyclers great again (#6653)

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-02-21 14:39:24 +11:00
committed by GitHub
parent 1cacaebf2d
commit f9c853f100
39 changed files with 181 additions and 66 deletions

View File

@@ -1,24 +1,20 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Recycling.Components
{
[RegisterComponent]
[RegisterComponent, Friend(typeof(RecyclerSystem))]
public sealed class RecyclableComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
/// <summary>
/// The prototype that will be spawned on recycle.
/// </summary>
[DataField("prototype")] private string? _prototype;
[DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))] public string? Prototype;
/// <summary>
/// The amount of things that will be spawned on recycle.
/// </summary>
[DataField("amount")] private int _amount = 1;
[DataField("amount")] public int Amount = 1;
/// <summary>
/// Whether this is "safe" to recycle or not.
@@ -26,19 +22,5 @@ namespace Content.Server.Recycling.Components
/// </summary>
[DataField("safe")]
public bool Safe { get; set; } = true;
public void Recycle(float efficiency = 1f)
{
if(!string.IsNullOrEmpty(_prototype))
{
for (var i = 0; i < Math.Max(_amount * efficiency, 1); i++)
{
_entMan.SpawnEntity(_prototype, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
}
}
_entMan.QueueDeleteEntity(Owner);
}
}
}