Recycler improvements, add RecyclableComponent as a tag.
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.GameObjects.Components.Conveyor;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.GameObjects.Components.Body;
|
||||
using Content.Shared.GameObjects.Components.Recycling;
|
||||
using Content.Shared.Physics;
|
||||
@@ -31,14 +29,14 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
/// <summary>
|
||||
/// Whether or not sentient beings will be recycled
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private bool _safe;
|
||||
|
||||
/// <summary>
|
||||
/// The percentage of material that will be recovered
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private int _efficiency; // TODO
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private float _efficiency;
|
||||
|
||||
private bool Powered =>
|
||||
!Owner.TryGetComponent(out PowerReceiverComponent? receiver) ||
|
||||
@@ -62,18 +60,10 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
|
||||
private bool CanGib(IEntity entity)
|
||||
{
|
||||
// We suppose this entity has a Recyclable component.
|
||||
return entity.HasComponent<IBody>() && !_safe && Powered;
|
||||
}
|
||||
|
||||
private bool CanRecycle(IEntity entity, [NotNullWhen(true)] out ConstructionPrototype? prototype)
|
||||
{
|
||||
prototype = null;
|
||||
|
||||
// TODO CONSTRUCTION fix this
|
||||
|
||||
return Powered;
|
||||
}
|
||||
|
||||
private void Recycle(IEntity entity)
|
||||
{
|
||||
if (!_intersecting.Contains(entity))
|
||||
@@ -82,6 +72,11 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
}
|
||||
|
||||
// TODO: Prevent collision with recycled items
|
||||
|
||||
// Can only recycle things that are recyclable... And also check the safety of the thing to recycle.
|
||||
if (!entity.TryGetComponent(out RecyclableComponent? recyclable) || !recyclable.Safe && _safe) return;
|
||||
|
||||
// Mobs are a special case!
|
||||
if (CanGib(entity))
|
||||
{
|
||||
entity.Delete(); // TODO: Gib
|
||||
@@ -89,14 +84,7 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CanRecycle(entity, out var prototype))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO CONSTRUCTION fix this
|
||||
|
||||
entity.Delete();
|
||||
recyclable.Recycle(_efficiency);
|
||||
}
|
||||
|
||||
private bool CanRun()
|
||||
@@ -179,7 +167,7 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _safe, "safe", true);
|
||||
serializer.DataField(ref _efficiency, "efficiency", 25);
|
||||
serializer.DataField(ref _efficiency, "efficiency", 0.25f);
|
||||
}
|
||||
|
||||
void ICollideBehavior.CollideWith(IEntity collidedWith)
|
||||
|
||||
Reference in New Issue
Block a user