Recycler improvements, add RecyclableComponent as a tag.

This commit is contained in:
Vera Aguilera Puerto
2021-01-01 15:28:58 +01:00
parent f8d4d4b8d7
commit b5fd2ffd6d
3 changed files with 64 additions and 23 deletions

View File

@@ -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)