The disposals pushing and pulling update (#1875)

* Add collision to disposal unit and pipes
Make disposal unit and pipes pullable
Implement proper handling of collisions in disposals

* Implement IsExiting
Move DisposalSystem to shared

* Change SharedDisosalUnitComponent to call manager.ContainsEntity directly

* Update saltern.yml

Co-authored-by: Julian Giebel <j.giebel@netrocks.info>
This commit is contained in:
Julian Giebel
2020-08-24 20:41:15 +02:00
committed by GitHub
parent 9019079d79
commit d9f02a6a0a
8 changed files with 374 additions and 554 deletions

View File

@@ -4,6 +4,7 @@ using Robust.Shared.GameObjects;
namespace Content.Client.GameObjects.Components.Disposal
{
[RegisterComponent]
[ComponentReference(typeof(SharedDisposalUnitComponent))]
public class DisposalUnitComponent : SharedDisposalUnitComponent
{
}

View File

@@ -24,7 +24,6 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Disposal
{
// TODO: Make unanchored pipes pullable
public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent, IBreakAct
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
@@ -182,6 +181,8 @@ namespace Content.Server.GameObjects.Components.Disposal
return;
}
collidable.CanCollide = !collidable.Anchored;
if (collidable.Anchored)
{
OnAnchor();
@@ -220,6 +221,8 @@ namespace Content.Server.GameObjects.Components.Disposal
var collidable = Owner.EnsureComponent<CollidableComponent>();
collidable.AnchoredChanged += AnchoredChanged;
collidable.CanCollide = !collidable.Anchored;
}
protected override void Startup()

View File

@@ -29,6 +29,7 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using Timer = Robust.Shared.Timers.Timer;
@@ -36,6 +37,7 @@ using Timer = Robust.Shared.Timers.Timer;
namespace Content.Server.GameObjects.Components.Disposal
{
[RegisterComponent]
[ComponentReference(typeof(SharedDisposalUnitComponent))]
[ComponentReference(typeof(IInteractUsing))]
public class DisposalUnitComponent : SharedDisposalUnitComponent, IInteractHand, IInteractUsing, IDragDropOn
{
@@ -429,8 +431,9 @@ namespace Content.Server.GameObjects.Components.Disposal
: LightState.Ready);
}
public void Update(float frameTime)
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!Powered)
{
return;
@@ -512,10 +515,15 @@ namespace Content.Server.GameObjects.Components.Disposal
{
base.Startup();
Owner.EnsureComponent<AnchorableComponent>();
if(!Owner.HasComponent<AnchorableComponent>())
{
Logger.WarningS("VitalComponentMissing", $"Disposal unit {Owner.Uid} is missing an anchorable component");
}
var collidable = Owner.EnsureComponent<CollidableComponent>();
collidable.AnchoredChanged += UpdateVisualState;
if (Owner.TryGetComponent(out CollidableComponent? collidable))
{
collidable.AnchoredChanged += UpdateVisualState;
}
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{

View File

@@ -1,18 +0,0 @@
using Content.Server.GameObjects.Components.Disposal;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
internal sealed class DisposalUnitSystem : EntitySystem
{
public override void Update(float frameTime)
{
foreach (var comp in ComponentManager.EntityQuery<DisposalUnitComponent>())
{
comp.Update(frameTime);
}
}
}
}

View File

@@ -1,14 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Disposal
{
public abstract class SharedDisposalUnitComponent : Component
public abstract class SharedDisposalUnitComponent : Component, ICollideSpecial
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "DisposalUnit";
private readonly List<IEntity> _intersecting = new List<IEntity>();
[Serializable, NetSerializable]
public enum Visuals
{
@@ -57,6 +68,46 @@ namespace Content.Shared.GameObjects.Components.Disposal
Pressurizing
}
bool ICollideSpecial.PreventCollide(IPhysBody collided)
{
if (IsExiting(collided.Entity)) return true;
if (!Owner.TryGetComponent(out IContainerManager manager)) return false;
if (manager.ContainsEntity(collided.Entity))
{
if (!_intersecting.Contains(collided.Entity))
{
_intersecting.Add(collided.Entity);
}
return true;
}
return false;
}
public virtual void Update(float frameTime)
{
UpdateIntersecting();
}
private bool IsExiting(IEntity entity)
{
return _intersecting.Contains(entity);
}
private void UpdateIntersecting()
{
if(_intersecting.Count == 0) return;
var intersectingEntities = _entityManager.GetEntitiesIntersecting(Owner);
for (var i = _intersecting.Count - 1; i >= 0; i--)
{
if (!intersectingEntities.Contains(_intersecting[i]))
{
_intersecting.RemoveAt(i);
}
}
}
[Serializable, NetSerializable]
public class DisposalUnitBoundUserInterfaceState : BoundUserInterfaceState, IEquatable<DisposalUnitBoundUserInterfaceState>
{

View File

@@ -0,0 +1,18 @@
using Content.Shared.GameObjects.Components.Disposal;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Shared.GameObjects.EntitySystems
{
[UsedImplicitly]
public sealed class SharedDisposalUnitSystem : EntitySystem
{
public override void Update(float frameTime)
{
foreach (var comp in ComponentManager.EntityQuery<SharedDisposalUnitComponent>())
{
comp.Update(frameTime);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -8,13 +8,28 @@
components:
- type: Clickable
- type: InteractionOutline
- type: Physics
- type: Collidable
anchored: true
shapes:
- !type:PhysShapeAabb
bounds: "-0.3,-0.3,0.3,0.3"
mask:
- Impassable
- MobImpassable
- VaultImpassable
- SmallImpassable
layer:
- Opaque
- Impassable
- MobImpassable
- VaultImpassable
- SmallImpassable
- type: SnapGrid
offset: Center
- type: Anchorable
- type: Breakable
- type: Rotatable
- type: Pullable
- type: entity
id: DisposalHolder
@@ -117,22 +132,22 @@
flushTime: 2
- type: Clickable
- type: InteractionOutline
- type: Physics
anchored: true
shapes:
- !type:PhysShapeAabb
bounds: "-0.3,-0.3,0.3,0.3"
layer:
- Impassable
- MobImpassable
- type: Collidable
anchored: true
shapes:
- !type:PhysShapeAabb
bounds: "-0.3,-0.3,0.3,0.3"
layer:
bounds: "-0.35,-0.3,0.35,0.3"
mask:
- Impassable
- MobImpassable
- VaultImpassable
- SmallImpassable
layer:
- Opaque
- Impassable
- MobImpassable
- VaultImpassable
- SmallImpassable
- type: SnapGrid
offset: Center
- type: Anchorable
@@ -155,6 +170,7 @@
interfaces:
- key: enum.DisposalUnitUiKey.Key
type: DisposalUnitBoundUserInterface
- type: Pullable
- type: entity
id: DisposalRouter