Remove ICollideSpecial

Handled in an ECS way by PreventCollideEvent.
The disposals one doesn't work anyway and would've required a larger refactor of disposals to fix so out of scope.
This commit is contained in:
metalgearsloth
2021-05-30 23:30:44 +10:00
parent 8a6ab624ab
commit d93ebe9409
17 changed files with 119 additions and 107 deletions

View File

@@ -13,14 +13,12 @@ using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Buckle
{
public abstract class SharedBuckleComponent : Component, IActionBlocker, IEffectBlocker, IDraggable, ICollideSpecial
public abstract class SharedBuckleComponent : Component, IActionBlocker, IEffectBlocker, IDraggable
{
public sealed override string Name => "Buckle";
public sealed override uint? NetID => ContentNetIDs.BUCKLE;
[ComponentDependency] protected readonly IPhysBody? Physics;
/// <summary>
/// The range from which this entity can buckle to a <see cref="SharedStrapComponent"/>.
/// </summary>
@@ -41,17 +39,6 @@ namespace Content.Shared.GameObjects.Components.Buckle
public abstract bool TryBuckle(IEntity? user, IEntity to);
bool ICollideSpecial.PreventCollide(IPhysBody collidedwith)
{
if (collidedwith.Owner.Uid == LastEntityBuckledTo)
{
IsOnStrapEntityThisFrame = true;
return Buckled || DontCollide;
}
return false;
}
bool IActionBlocker.CanMove()
{
return !Buckled;

View File

@@ -1,25 +1,20 @@
#nullable enable
using System;
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Mobs.State;
using Content.Shared.GameObjects.Components.Storage;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Disposal
{
public abstract class SharedDisposalUnitComponent : Component, ICollideSpecial, IDragDropOn
public abstract class SharedDisposalUnitComponent : Component, IDragDropOn
{
public override string Name => "DisposalUnit";
private readonly List<IEntity> _intersecting = new();
[ViewVariables]
public bool Anchored =>
!Owner.TryGetComponent(out IPhysBody? physics) ||
@@ -73,44 +68,9 @@ namespace Content.Shared.GameObjects.Components.Disposal
Pressurizing
}
bool ICollideSpecial.PreventCollide(IPhysBody collided)
{
if (IsExiting(collided.Owner)) return true;
if (!Owner.TryGetComponent(out IContainerManager? manager)) return false;
if (manager.ContainsEntity(collided.Owner))
{
if (!_intersecting.Contains(collided.Owner))
{
_intersecting.Add(collided.Owner);
}
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;
// TODO: Yeah look this sucks but we'll fix it someday.
for (var i = _intersecting.Count - 1; i >= 0; i--)
{
var entity = _intersecting[i];
if (IoCManager.Resolve<IEntityLookup>().IsIntersecting(entity, Owner))
_intersecting.RemoveAt(i);
}
return;
}
[Serializable, NetSerializable]

View File

@@ -11,7 +11,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Doors
{
public abstract class SharedDoorComponent : Component, ICollideSpecial
public abstract class SharedDoorComponent : Component
{
public override string Name => "Door";
public override uint? NetID => ContentNetIDs.DOOR;
@@ -94,17 +94,16 @@ namespace Content.Shared.GameObjects.Components.Doors
/// </summary>
protected List<EntityUid> CurrentlyCrushing = new();
public bool IsCrushing(IEntity entity)
{
return CurrentlyCrushing.Contains(entity.Uid);
}
protected void SetAppearance(DoorVisualState state)
{
AppearanceComponent?.SetData(DoorVisuals.VisualState, state);
}
// stops us colliding with people we're crushing, to prevent hitbox clipping and jank
public bool PreventCollide(IPhysBody collidedwith)
{
return CurrentlyCrushing.Contains(collidedwith.Owner.Uid);
}
/// <summary>
/// Called when the door is partially opened.
/// </summary>

View File

@@ -6,13 +6,13 @@ using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Projectiles
{
public abstract class SharedProjectileComponent : Component, ICollideSpecial
public abstract class SharedProjectileComponent : Component
{
private bool _ignoreShooter = true;
public override string Name => "Projectile";
public override uint? NetID => ContentNetIDs.PROJECTILE;
protected abstract EntityUid Shooter { get; }
public EntityUid Shooter { get; protected set; }
public bool IgnoreShooter
{
@@ -29,7 +29,7 @@ namespace Content.Shared.GameObjects.Components.Projectiles
[NetSerializable, Serializable]
protected class ProjectileComponentState : ComponentState
{
public ProjectileComponentState(uint netId, EntityUid shooter, bool ignoreShooter) : base(netId)
public ProjectileComponentState(EntityUid shooter, bool ignoreShooter) : base(ContentNetIDs.PROJECTILE)
{
Shooter = shooter;
IgnoreShooter = ignoreShooter;
@@ -38,10 +38,5 @@ namespace Content.Shared.GameObjects.Components.Projectiles
public EntityUid Shooter { get; }
public bool IgnoreShooter { get; }
}
public bool PreventCollide(IPhysBody collidedwith)
{
return IgnoreShooter && collidedwith.Owner.Uid == Shooter;
}
}
}

View File

@@ -18,7 +18,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Pulling
{
public abstract class SharedPullableComponent : Component, ICollideSpecial, IRelayMoveInput
public abstract class SharedPullableComponent : Component, IRelayMoveInput
{
public override string Name => "Pullable";
public override uint? NetID => ContentNetIDs.PULLABLE;
@@ -358,16 +358,6 @@ namespace Content.Shared.GameObjects.Components.Pulling
base.OnRemove();
}
public bool PreventCollide(IPhysBody collidedWith)
{
if (_puller == null || _physics == null)
{
return false;
}
return (_physics.CollisionLayer & collidedWith.CollisionMask) == (int) CollisionGroup.MobImpassable;
}
// TODO: Need a component bus relay so all entities can use this and not just players
void IRelayMoveInput.MoveInputPressed(ICommonSession session)
{

View File

@@ -0,0 +1,24 @@
using Content.Shared.GameObjects.Components.Projectiles;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Dynamics;
namespace Content.Shared.GameObjects.EntitySystems
{
public sealed class ProjectileSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedProjectileComponent, PreventCollideEvent>(PreventCollision);
}
private void PreventCollision(EntityUid uid, SharedProjectileComponent component, PreventCollideEvent args)
{
if (component.IgnoreShooter && args.BodyB.Owner.Uid == component.Shooter)
{
args.Cancel();
return;
}
}
}
}

View File

@@ -0,0 +1,26 @@
using Content.Shared.GameObjects.Components.Buckle;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Dynamics;
namespace Content.Shared.GameObjects.EntitySystems
{
public abstract class SharedBuckleSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedBuckleComponent, PreventCollideEvent>(PreventCollision);
}
private void PreventCollision(EntityUid uid, SharedBuckleComponent component, PreventCollideEvent args)
{
if (args.BodyB.Owner.Uid != component.LastEntityBuckledTo) return;
component.IsOnStrapEntityThisFrame = true;
if (component.Buckled || component.DontCollide)
{
args.Cancel();
}
}
}
}

View File

@@ -0,0 +1,23 @@
using Content.Shared.GameObjects.Components.Doors;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Dynamics;
namespace Content.Shared.GameObjects.EntitySystems
{
public abstract class SharedDoorSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedDoorComponent, PreventCollideEvent>(PreventCollision);
}
private void PreventCollision(EntityUid uid, SharedDoorComponent component, PreventCollideEvent args)
{
if (component.IsCrushing(args.BodyB.Owner))
{
args.Cancel();
}
}
}
}