Remove IStartCollide from Recyclers (#4312)
This commit is contained in:
@@ -27,7 +27,7 @@ namespace Content.Server.Recycling.Components
|
||||
{
|
||||
// TODO: Add sound and safe beep
|
||||
[RegisterComponent]
|
||||
public class RecyclerComponent : Component, IStartCollide, ISuicideAct
|
||||
public class RecyclerComponent : Component, ISuicideAct
|
||||
{
|
||||
public override string Name => "Recycler";
|
||||
|
||||
@@ -37,26 +37,18 @@ namespace Content.Server.Recycling.Components
|
||||
/// Whether or not sentient beings will be recycled
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("safe")]
|
||||
private bool _safe = true;
|
||||
internal bool Safe = true;
|
||||
|
||||
/// <summary>
|
||||
/// The percentage of material that will be recovered
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("efficiency")]
|
||||
private float _efficiency = 0.25f;
|
||||
internal float Efficiency = 0.25f;
|
||||
|
||||
private bool Powered =>
|
||||
internal bool Powered =>
|
||||
!Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) ||
|
||||
receiver.Powered;
|
||||
|
||||
private void Bloodstain()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(RecyclerVisuals.Bloody, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Clean()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
@@ -65,35 +57,6 @@ namespace Content.Server.Recycling.Components
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanGib(IEntity entity)
|
||||
{
|
||||
// We suppose this entity has a Recyclable component.
|
||||
return entity.HasComponent<SharedBodyComponent>() && !_safe && Powered;
|
||||
}
|
||||
|
||||
private void Recycle(IEntity entity)
|
||||
{
|
||||
if (!Intersecting.Contains(entity))
|
||||
{
|
||||
Intersecting.Add(entity);
|
||||
}
|
||||
|
||||
// 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.GetComponent<SharedBodyComponent>().Gib(true);
|
||||
Bloodstain();
|
||||
return;
|
||||
}
|
||||
|
||||
recyclable.Recycle(_efficiency);
|
||||
}
|
||||
|
||||
public bool CanRun()
|
||||
{
|
||||
if (Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) &&
|
||||
@@ -141,11 +104,6 @@ namespace Content.Server.Recycling.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
||||
{
|
||||
Recycle(otherFixture.Body.Owner);
|
||||
}
|
||||
|
||||
SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat)
|
||||
{
|
||||
var mind = victim.PlayerSession()?.ContentData()?.Mind;
|
||||
@@ -163,7 +121,7 @@ namespace Content.Server.Recycling.Components
|
||||
body.Gib(true);
|
||||
}
|
||||
|
||||
Bloodstain();
|
||||
EntitySystem.Get<RecyclerSystem>().Bloodstain(this);
|
||||
|
||||
return SuicideKind.Bloodloss;
|
||||
}
|
||||
|
||||
59
Content.Server/Recycling/RecyclerSystem.cs
Normal file
59
Content.Server/Recycling/RecyclerSystem.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Content.Server.Recycling.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Recycling;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Server.Recycling
|
||||
{
|
||||
internal sealed class RecyclerSystem: EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RecyclerComponent, StartCollideEvent>(HandleCollide);
|
||||
}
|
||||
|
||||
private void HandleCollide(EntityUid uid, RecyclerComponent component, StartCollideEvent args)
|
||||
{
|
||||
Recycle(component, args.OtherFixture.Body.Owner);
|
||||
}
|
||||
|
||||
private void Recycle(RecyclerComponent component, IEntity entity)
|
||||
{
|
||||
if (!component.Intersecting.Contains(entity))
|
||||
{
|
||||
component.Intersecting.Add(entity);
|
||||
}
|
||||
|
||||
// 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 && component.Safe) return;
|
||||
|
||||
// Mobs are a special case!
|
||||
if (CanGib(component, entity))
|
||||
{
|
||||
entity.GetComponent<SharedBodyComponent>().Gib(true);
|
||||
Bloodstain(component);
|
||||
return;
|
||||
}
|
||||
|
||||
recyclable.Recycle(component.Efficiency);
|
||||
}
|
||||
|
||||
private bool CanGib(RecyclerComponent component, IEntity entity)
|
||||
{
|
||||
// We suppose this entity has a Recyclable component.
|
||||
return entity.HasComponent<SharedBodyComponent>() && !component.Safe && component.Powered;
|
||||
}
|
||||
|
||||
public void Bloodstain(RecyclerComponent component)
|
||||
{
|
||||
if (component.Owner.TryGetComponent(out SharedAppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(RecyclerVisuals.Bloody, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user