Door collision fixes (#6836)

This commit is contained in:
Leon Friedrich
2022-02-22 18:01:37 +13:00
committed by GitHub
parent 4ca57ca474
commit 8d111c8959
2 changed files with 15 additions and 9 deletions

View File

@@ -140,7 +140,7 @@ public sealed class DoorComponent : Component, ISerializationHooks
/// List of EntityUids of entities we're currently crushing. Cleared in OnPartialOpen().
/// </summary>
[DataField("currentlyCrushing")]
public List<EntityUid> CurrentlyCrushing = new();
public HashSet<EntityUid> CurrentlyCrushing = new();
#endregion
#region Serialization
@@ -238,7 +238,7 @@ public enum DoorVisuals
public sealed class DoorComponentState : ComponentState
{
public readonly DoorState DoorState;
public readonly List<EntityUid> CurrentlyCrushing;
public readonly HashSet<EntityUid> CurrentlyCrushing;
public readonly TimeSpan? NextStateChange;
public readonly bool Partial;

View File

@@ -99,7 +99,7 @@ public abstract class SharedDoorSystem : EntitySystem
if (args.Current is not DoorComponentState state)
return;
door.CurrentlyCrushing = state.CurrentlyCrushing;
door.CurrentlyCrushing = new(state.CurrentlyCrushing);
door.State = state.DoorState;
door.NextStateChange = state.NextStateChange;
door.Partial = state.Partial;
@@ -337,7 +337,6 @@ public abstract class SharedDoorSystem : EntitySystem
if (!Resolve(uid, ref door, ref physics))
return false;
SetCollidable(uid, true, door, physics);
door.Partial = true;
door.Dirty();
@@ -350,6 +349,7 @@ public abstract class SharedDoorSystem : EntitySystem
return false;
}
SetCollidable(uid, true, door, physics);
door.NextStateChange = GameTiming.CurTime + door.CloseTimeTwo;
_activeDoors.Add(door);
@@ -421,16 +421,22 @@ public abstract class SharedDoorSystem : EntitySystem
// TODO SLOTH fix electro's code.
var doorAABB = physics.GetWorldAABB();
foreach (var body in _physicsSystem.GetCollidingEntities(Transform(uid).MapID, doorAABB))
foreach (var otherPhysics in _physicsSystem.GetCollidingEntities(Transform(uid).MapID, doorAABB))
{
// static bodies (e.g., furniture) shouldn't stop airlocks/windoors from closing.
if (body.BodyType == BodyType.Static)
if (otherPhysics == physics)
continue;
if (body.GetWorldAABB().IntersectPercentage(doorAABB) < IntersectPercentage)
if (!otherPhysics.CanCollide)
continue;
yield return body.Owner;
if ((physics.CollisionMask & otherPhysics.CollisionLayer) == 0
&& (otherPhysics.CollisionMask & physics.CollisionLayer) == 0)
continue;
if (otherPhysics.GetWorldAABB().IntersectPercentage(doorAABB) < IntersectPercentage)
continue;
yield return otherPhysics.Owner;
}
}