Files
tbd-station-14/Content.Server/GameObjects/Components/Disposal/DisposalEntryComponent.cs
Julian Giebel 45b610f933 Disposal mailing (#2194)
* Implement device networking

* Implement device configuration menu

* Fix device network

* Implement disposal mailing unit

* Implement base network connection
Implement wired and wireless network connection
Implement device network metadata

* Fix dereference null error

* Fix wired network null checks

* Change BaseNetworks enum to NetworkUtils class
Add PingResponse function to NetworkUtils
Change device network file structure

* Add doc comments

* Apply suggestions from code review

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

* Add tag validation to disposal mailing unit

* Add tag validation to the mailing unit component

* Address reviews
Change WiredNetwork can connect check
Change device networking string literals to constants

* Address reviews
Revert changes to PowerProvider and PowerReceiver
Add new NodeGroup
WELP

* Fix recursive access to Owner property

* Integrate suggested changes

* Fix TryGetWireNet acting on NullPowerProvider
Fix network connections not checking if their owner has been deleted

* Close device network connection when the owning entity got deleted
Fix mailing unit not closing the device network connection on remove

* Remove GetWireNet from NullPowerProvider

Co-authored-by: Julian Giebel <j.giebel@netrocks.info>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
2020-10-30 01:16:26 +01:00

70 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
namespace Content.Server.GameObjects.Components.Disposal
{
[RegisterComponent]
[ComponentReference(typeof(IDisposalTubeComponent))]
public class DisposalEntryComponent : DisposalTubeComponent
{
[Dependency] private readonly IRobustRandom _random = default!;
private const string HolderPrototypeId = "DisposalHolder";
public override string Name => "DisposalEntry";
public bool TryInsert(IReadOnlyCollection<IEntity> entities)
{
var holder = Owner.EntityManager.SpawnEntity(HolderPrototypeId, Owner.Transform.MapPosition);
var holderComponent = holder.GetComponent<DisposalHolderComponent>();
foreach (var entity in entities)
{
holderComponent.TryInsert(entity);
}
return TryInsert(holderComponent);
}
public bool TryInsert(DisposalHolderComponent holder)
{
if (!Contents.Insert(holder.Owner))
{
return false;
}
holder.EnterTube(this);
return true;
}
protected override Direction[] ConnectableDirections()
{
return new[] {Owner.Transform.LocalRotation.GetDir()};
}
/// <summary>
/// Ejects contents when they come from the same direction the entry is facing.
/// </summary>
public override Direction NextDirection(DisposalHolderComponent holder)
{
if (holder.PreviousTube != null && DirectionTo(holder.PreviousTube) == ConnectableDirections()[0])
{
var invalidDirections = new Direction[] { ConnectableDirections()[0], Direction.Invalid };
var directions = Enum.GetValues(typeof(Direction))
.Cast<Direction>().Except(invalidDirections).ToList();
return _random.Pick<Direction>(directions);
}
return ConnectableDirections()[0];
}
}
}