Sending a mob out of a disposals unit shouldn't push them into a wall anymore (#5411)

* Sending a mob out of a disposals unit shouldn't push them into a wall anymore.

* Something something resolves vs. OnRemove fighting it out

* Disposals yeet reduction: Address reviews and other oddities
This commit is contained in:
20kdc
2021-11-23 23:38:46 +00:00
committed by GitHub
parent 0e98c1c524
commit eb18f7bc1c
5 changed files with 182 additions and 162 deletions

View File

@@ -5,6 +5,7 @@ using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Disposal.Tube.Components;
using Content.Server.Disposal.Tube;
using Content.Server.Disposal.Unit.EntitySystems;
using Content.Server.Items;
using Content.Shared.Atmos;
using Content.Shared.Body.Components;
@@ -24,36 +25,36 @@ namespace Content.Server.Disposal.Unit.Components
{
public override string Name => "DisposalHolder";
private Container _contents = null!;
public Container Container = null!;
/// <summary>
/// The total amount of time that it will take for this entity to
/// be pushed to the next tube
/// </summary>
[ViewVariables]
private float StartingTime { get; set; }
public float StartingTime { get; set; }
/// <summary>
/// Time left until the entity is pushed to the next tube
/// </summary>
[ViewVariables]
private float TimeLeft { get; set; }
public float TimeLeft { get; set; }
[ViewVariables]
public IDisposalTubeComponent? PreviousTube { get; set; }
[ViewVariables]
public Direction PreviousDirection { get; private set; } = Direction.Invalid;
public Direction PreviousDirection { get; set; } = Direction.Invalid;
[ViewVariables]
public Direction PreviousDirectionFrom => (PreviousDirection == Direction.Invalid) ? Direction.Invalid : PreviousDirection.GetOpposite();
[ViewVariables]
public IDisposalTubeComponent? CurrentTube { get; private set; }
public IDisposalTubeComponent? CurrentTube { get; set; }
// CurrentDirection is not null when CurrentTube isn't null.
[ViewVariables]
public Direction CurrentDirection { get; private set; } = Direction.Invalid;
public Direction CurrentDirection { get; set; } = Direction.Invalid;
/// <summary>
/// A list of tags attached to the content, used for sorting
@@ -69,18 +70,12 @@ namespace Content.Server.Disposal.Unit.Components
{
base.Initialize();
_contents = ContainerHelpers.EnsureContainer<Container>(Owner, nameof(DisposalHolderComponent));
}
protected override void OnRemove()
{
base.OnRemove();
ExitDisposals();
Container = ContainerHelpers.EnsureContainer<Container>(Owner, nameof(DisposalHolderComponent));
}
private bool CanInsert(IEntity entity)
{
if (!_contents.CanInsert(entity))
if (!Container.CanInsert(entity))
{
return false;
}
@@ -91,7 +86,7 @@ namespace Content.Server.Disposal.Unit.Components
public bool TryInsert(IEntity entity)
{
if (!CanInsert(entity) || !_contents.Insert(entity))
if (!CanInsert(entity) || !Container.Insert(entity))
{
return false;
}
@@ -103,98 +98,5 @@ namespace Content.Server.Disposal.Unit.Components
return true;
}
public void EnterTube(IDisposalTubeComponent tube)
{
if (CurrentTube != null)
{
PreviousTube = CurrentTube;
PreviousDirection = CurrentDirection;
}
Owner.Transform.Coordinates = tube.Owner.Transform.Coordinates;
CurrentTube = tube;
CurrentDirection = tube.NextDirection(this);
StartingTime = 0.1f;
TimeLeft = 0.1f;
}
public void ExitDisposals()
{
if (Deleted)
return;
PreviousTube = null;
PreviousDirection = Direction.Invalid;
CurrentTube = null;
CurrentDirection = Direction.Invalid;
StartingTime = 0;
TimeLeft = 0;
foreach (var entity in _contents.ContainedEntities.ToArray())
{
if (entity.TryGetComponent(out IPhysBody? physics))
{
physics.CanCollide = true;
}
_contents.ForceRemove(entity);
if (entity.Transform.Parent == Owner.Transform)
{
entity.Transform.AttachParentToContainerOrGrid();
}
}
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
if (atmosphereSystem.GetTileMixture(Owner.Transform.Coordinates, true) is {} environment)
{
atmosphereSystem.Merge(environment, Air);
Air.Clear();
}
Owner.Delete();
}
public void Update(float frameTime)
{
while (frameTime > 0)
{
var time = frameTime;
if (time > TimeLeft)
{
time = TimeLeft;
}
TimeLeft -= time;
frameTime -= time;
if (CurrentTube == null || CurrentTube.Deleted)
{
ExitDisposals();
break;
}
if (TimeLeft > 0)
{
var progress = 1 - TimeLeft / StartingTime;
var origin = CurrentTube.Owner.Transform.Coordinates;
var destination = CurrentDirection.ToVec();
var newPosition = destination * progress;
Owner.Transform.Coordinates = origin.Offset(newPosition);
continue;
}
var nextTube = EntitySystem.Get<DisposalTubeSystem>().NextTubeFor(CurrentTube.Owner.Uid, CurrentDirection);
if (nextTube == null || nextTube.Deleted || !CurrentTube.TransferTo(this, nextTube))
{
CurrentTube.Remove(this);
break;
}
}
}
}
}